| | 349 | $img_title = ''; |
|---|
| | 350 | // Some reason we're kicking out-of-sync, check explicitly for POSTed value |
|---|
| | 351 | if ( isset($_POST[$this->name]) |
|---|
| | 352 | && is_array($_POST[$this->name]) |
|---|
| | 353 | && isset($_POST[$this->name]["e_exist_{$identifier}_title"])) |
|---|
| | 354 | { |
|---|
| | 355 | $img_title = $_POST[$this->name]["e_exist_{$identifier}_title"]; |
|---|
| | 356 | } |
|---|
| | 357 | // Otherwise use the type title if available |
|---|
| | 358 | elseif (isset($this->_type->titles[$identifier])) |
|---|
| | 359 | { |
|---|
| | 360 | $img_title = $this->_type->titles[$identifier]; |
|---|
| | 361 | } |
|---|
| 469 | | if ($this->_elements['e_new_file']->isUploadedFile()) |
|---|
| 470 | | { |
|---|
| 471 | | $file = $this->_elements['e_new_file']->getValue(); |
|---|
| 472 | | |
|---|
| 473 | | if ( preg_match('/\.(zip|tar(\.gz|\.bz2)?|tgz)$/', strtolower($file['name']), $extension_matches)) |
|---|
| 474 | | { |
|---|
| 475 | | // PHP5-TODO: This must be copy-by-value |
|---|
| 476 | | $copy = $file; |
|---|
| 477 | | unset($file); |
|---|
| 478 | | if (! $this->_type->_batch_handler($extension_matches[1], $copy)) |
|---|
| 479 | | { |
|---|
| 480 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 481 | | debug_add("Failed to add attachments from compressed files to the field '{$this->name}'. Ignoring silently.", MIDCOM_LOG_WARN); |
|---|
| 482 | | debug_pop(); |
|---|
| 483 | | } |
|---|
| 484 | | return; |
|---|
| 485 | | } |
|---|
| 486 | | |
|---|
| 487 | | |
|---|
| 488 | | if ( array_key_exists('e_new_title', $values) |
|---|
| 489 | | && !empty($values['e_new_title'])) |
|---|
| 490 | | { |
|---|
| 491 | | $title = $values['e_new_title']; |
|---|
| 492 | | } |
|---|
| 493 | | else |
|---|
| 494 | | { |
|---|
| 495 | | $title = $file['name']; |
|---|
| 496 | | } |
|---|
| 497 | | |
|---|
| 498 | | if ( array_key_exists('e_new_filename', $values) |
|---|
| 499 | | && !empty($values['e_new_filename'])) |
|---|
| 500 | | { |
|---|
| 501 | | $filename = $values['e_new_filename']; |
|---|
| 502 | | } |
|---|
| 503 | | else |
|---|
| 504 | | { |
|---|
| 505 | | $filename = $file['name']; |
|---|
| 506 | | } |
|---|
| 507 | | |
|---|
| 508 | | if (! $this->_type->add_image($filename, $file['tmp_name'], $title)) |
|---|
| | 482 | if (!$this->_elements['e_new_file']->isUploadedFile()) |
|---|
| | 483 | { |
|---|
| | 484 | // not uploaded file, abort |
|---|
| | 485 | return; |
|---|
| | 486 | } |
|---|
| | 487 | |
|---|
| | 488 | $file = $this->_elements['e_new_file']->getValue(); |
|---|
| | 489 | |
|---|
| | 490 | if ( preg_match('/\.(zip|tar(\.gz|\.bz2)?|tgz)$/', strtolower($file['name']), $extension_matches)) |
|---|
| | 491 | { |
|---|
| | 492 | // PHP5-TODO: This must be copy-by-value |
|---|
| | 493 | $copy = $file; |
|---|
| | 494 | unset($file); |
|---|
| | 495 | if (! $this->_type->_batch_handler($extension_matches[1], $copy)) |
|---|
| | 501 | return; |
|---|
| | 502 | } |
|---|
| | 503 | |
|---|
| | 504 | |
|---|
| | 505 | if ( array_key_exists('e_new_title', $values) |
|---|
| | 506 | && !empty($values['e_new_title'])) |
|---|
| | 507 | { |
|---|
| | 508 | $title = $values['e_new_title']; |
|---|
| | 509 | } |
|---|
| | 510 | else |
|---|
| | 511 | { |
|---|
| | 512 | $title = $file['name']; |
|---|
| | 513 | } |
|---|
| | 514 | |
|---|
| | 515 | if ( array_key_exists('e_new_filename', $values) |
|---|
| | 516 | && !empty($values['e_new_filename'])) |
|---|
| | 517 | { |
|---|
| | 518 | $filename = $values['e_new_filename']; |
|---|
| | 519 | } |
|---|
| | 520 | else |
|---|
| | 521 | { |
|---|
| | 522 | $filename = $file['name']; |
|---|
| | 523 | } |
|---|
| | 524 | |
|---|
| | 525 | if (! $this->_type->add_image($filename, $file['tmp_name'], $title)) |
|---|
| | 526 | { |
|---|
| | 527 | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| | 528 | debug_add("Failed to add an attachment to the field '{$this->name}'. Ignoring silently.", MIDCOM_LOG_WARN); |
|---|
| | 529 | debug_pop(); |
|---|
| 540 | | if (array_key_exists("{$this->name}_e_exist_{$identifier}_delete", $values)) |
|---|
| 541 | | { |
|---|
| 542 | | if (! $this->_type->delete_image($identifier)) |
|---|
| 543 | | { |
|---|
| 544 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 545 | | debug_add("Failed to delete the image {$identifier} on the field '{$this->name}'. Ignoring silently.", MIDCOM_LOG_WARN); |
|---|
| 546 | | debug_pop(); |
|---|
| 547 | | } |
|---|
| 548 | | } |
|---|
| 549 | | else if |
|---|
| 550 | | ( array_key_exists("e_exist_{$identifier}_file", $this->_elements) |
|---|
| 551 | | && $this->_elements["e_exist_{$identifier}_file"]->isUploadedFile()) |
|---|
| 552 | | { |
|---|
| 553 | | $file = $this->_elements["e_exist_{$identifier}_file"]->getValue(); |
|---|
| 554 | | $title = $values["e_exist_{$identifier}_title"]; |
|---|
| 555 | | $filename = $this->_type->images[$identifier]['main']['filename']; |
|---|
| 556 | | |
|---|
| 557 | | if (! $title) |
|---|
| 558 | | { |
|---|
| 559 | | $title = $filename; |
|---|
| 560 | | } |
|---|
| 561 | | |
|---|
| 562 | | if (! $this->_type->update_image($identifier, $filename, $file['tmp_name'], $title)) |
|---|
| 563 | | { |
|---|
| 564 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 565 | | debug_add("Failed to update the image {$identifier} on the field '{$this->name}'. Ignoring silently.", MIDCOM_LOG_WARN); |
|---|
| 566 | | debug_pop(); |
|---|
| 567 | | } |
|---|
| 568 | | } |
|---|
| 569 | | else if |
|---|
| 570 | | ( array_key_exists("e_exist_{$identifier}_title", $values) |
|---|
| 571 | | && isset($this->_type->images[$identifier]['main']) |
|---|
| 572 | | && isset($this->_type->images[$identifier]['main']['description']) |
|---|
| 573 | | && $values["e_exist_{$identifier}_title"] != $this->_type->images[$identifier]['main']['description']) |
|---|
| 574 | | { |
|---|
| 575 | | $this->_type->update_image_title($identifier, $values["e_exist_{$identifier}_title"]); |
|---|
| | 555 | switch(true) |
|---|
| | 556 | { |
|---|
| | 557 | // Image to be deleted |
|---|
| | 558 | case (array_key_exists("{$this->name}_e_exist_{$identifier}_delete", $values)): |
|---|
| | 559 | if (! $this->_type->delete_image($identifier)) |
|---|
| | 560 | { |
|---|
| | 561 | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| | 562 | debug_add("Failed to delete the image {$identifier} on the field '{$this->name}'. Ignoring silently.", MIDCOM_LOG_WARN); |
|---|
| | 563 | debug_pop(); |
|---|
| | 564 | } |
|---|
| | 565 | break; |
|---|
| | 566 | // Image to be updated |
|---|
| | 567 | case ( array_key_exists("e_exist_{$identifier}_file", $this->_elements) |
|---|
| | 568 | && $this->_elements["e_exist_{$identifier}_file"]->isUploadedFile()): |
|---|
| | 569 | $file = $this->_elements["e_exist_{$identifier}_file"]->getValue(); |
|---|
| | 570 | $title = $values["e_exist_{$identifier}_title"]; |
|---|
| | 571 | $filename = $this->_type->images[$identifier]['main']['filename']; |
|---|
| | 572 | |
|---|
| | 573 | if (! $title) |
|---|
| | 574 | { |
|---|
| | 575 | $title = $filename; |
|---|
| | 576 | } |
|---|
| | 577 | |
|---|
| | 578 | if (! $this->_type->update_image($identifier, $filename, $file['tmp_name'], $title)) |
|---|
| | 579 | { |
|---|
| | 580 | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| | 581 | debug_add("Failed to update the image {$identifier} on the field '{$this->name}'. Ignoring silently.", MIDCOM_LOG_WARN); |
|---|
| | 582 | debug_pop(); |
|---|
| | 583 | } |
|---|
| | 584 | break; |
|---|