private static function RenameFileWorker($title) { global $langmessage, $dataDir, $gp_index; //use new_label or new_title if (isset($_POST['new_title'])) { $new_title = \gp\admin\Tools::PostedSlug($_POST['new_title']); } else { $new_title = \gp\admin\Tools::LabelToSlug($_POST['new_label']); } //title unchanged if ($new_title == $title) { return $title; } $special_file = false; if (\gp\tool::SpecialOrAdmin($title) !== false) { $special_file = true; } if (!\gp\admin\Tools::CheckTitle($new_title, $message)) { msg($message); return false; } $old_gp_index = $gp_index; //re-index: make the new title point to the same data index $old_file = \gp\tool\Files::PageFile($title); $file_index = $gp_index[$title]; unset($gp_index[$title]); $gp_index[$new_title] = $file_index; //rename the php file if (!$special_file) { $new_file = \gp\tool\Files::PageFile($new_title); //if the file being renamed doesn't use the index naming convention, then we'll still need to rename it if ($new_file != $old_file) { $new_dir = dirname($new_file); $old_dir = dirname($old_file); if (!\gp\tool\Files::Rename($old_dir, $new_dir)) { msg($langmessage['OOPS'] . ' (N3)'); $gp_index = $old_gp_index; return false; } } //gallery rename \gp\special\Galleries::RenamedGallery($title, $new_title); } //create a 301 redirect if (isset($_POST['add_redirect']) && $_POST['add_redirect'] == 'add') { \gp\admin\Settings\Missing::AddRedirect($title, $new_title); } \gp\tool\Plugins::Action('RenameFileDone', array($file_index, $title, $new_title)); return $new_title; }
/** * Get the content of the file in the trash so we can restore file information * - resized images * - \gp\special\Galleries::UpdateGalleryInfo($title,$content) * */ public static function RestoreFile($title, $file, $title_info) { $file_sections = \gp\tool\Files::Get($file, 'file_sections'); // Restore resized images if (count($file_sections)) { includeFile('image.php'); \gp_resized::SetIndex(); foreach ($file_sections as $section => $section_data) { if (!isset($section_data['resized_imgs'])) { continue; } foreach ($section_data['resized_imgs'] as $image_index => $sizes) { if (!isset(\gp_resized::$index[$image_index])) { continue; } $img = \gp_resized::$index[$image_index]; foreach ($sizes as $size) { list($width, $height) = explode('x', $size); \gp\tool\Editing::CreateImage($img, $width, $height); } } \gp\tool\Editing::ResizedImageUse(array(), $section_data['resized_imgs']); } \gp_resized::SaveIndex(); } // Restore Galleries if (strpos($title_info['type'], 'gallery') !== false) { \gp\special\Galleries::UpdateGalleryInfo($title, $file_sections); } }
/** * Extract information about the gallery from it's html: img_count, icon_src * Call GalleryEdited when a gallery section is removed, edited * */ public function GalleryEdited() { \gp\special\Galleries::UpdateGalleryInfo($this->title, $this->file_sections); }