/** * Saves the main image to the type, doing transformation work if configured to do so. * * @return boolean Indicating success. */ function _save_main_image() { $this->_current_tmpname = $this->_filter->create_tmp_copy($this->_original_tmpname); if (!$this->_filter->set_file($this->_current_tmpname)) { return false; } if (isset($this->_identifier)) { // we come from the image*s* type $blob_identifier = "{$this->_identifier}main"; $title = $this->_title; } else { $blob_identifier = 'main'; $title = $this->title; } $result = true; // Filter if necessary. if ($this->filter_chain && !$this->_filter->process_chain($this->filter_chain)) { $result = false; } if ($result) { if (array_key_exists('main', $this->_pending_attachments)) { unset($this->_pending_attachments['main']); $result = $this->update_attachment($blob_identifier, $this->_filename, $title, $this->_target_mimetype, $this->_current_tmpname, false); } else { if (isset($this->_attachment_map)) { $this->_attachment_map[$blob_identifier] = array($this->_identifier, 'main'); } $result = $this->add_attachment($blob_identifier, $this->_filename, $title, $this->_target_mimetype, $this->_current_tmpname, false); } } @unlink($this->_current_tmpname); return $result; }
function _save_main_video() { $this->_current_tmpname_video = $this->_filter->create_tmp_copy($this->_original_tmpname_video); if (isset($this->_identifier)) { // we come from the video*s* type $blob_identifier = "{$this->_identifier}main_video"; $title = $this->_title_video; } else { $blob_identifier = 'main_video'; $title = $this->title_video; } $result = true; if ($result) { if (array_key_exists('main_video', $this->_pending_attachments_video)) { unset($this->_pending_attachments_video['main_video']); $result = $this->update_attachment($blob_identifier, $this->_filename_video, $title, $this->_target_mimetype_video, $this->_current_tmpname_video, false); } else { $this->delete_attachment($blob_identifier); if (isset($this->_attachment_map)) { $this->_attachment_map[$blob_identifier] = array($this->_identifier, 'main_video'); } $result = $this->add_attachment($blob_identifier, $this->_filename_video, $title, $this->_target_mimetype_video, $this->_current_tmpname_video, false); } } @unlink($this->_current_tmpname_video); return $result; }
/** * Recreates all images from either the "original" or the "main" image */ function recreate_images() { foreach ($this->images as $identifier => $images) { $image = null; if (isset($images['original'])) { $image = $images['original']; } else { if (isset($images['main'])) { $image = $images['main']; } } if (!$image) { debug_add("Image {$identifier} has no 'original' or 'main' image, skipping recreation.", MIDCOM_LOG_INFO); continue; } if (empty($image['object'])) { debug_add("Image {$identifier} has no image object, skipping recreation.", MIDCOM_LOG_INFO); continue; } // Copy the "main image" to a temporary location $filter = new midcom_helper_imagefilter(); $tmp = $filter->create_tmp_copy($image['object']); // Update all derived images if (!$this->update_image($identifier, $image['filename'], $tmp, $this->titles[$identifier])) { debug_add("Failed to recreate image {$identifier}, skipping .", MIDCOM_LOG_INFO); } } return true; }