is_photo()) { $original_file = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); if (file_exists($original_file)) { @unlink($original_file); } } // When deleting an album, make sure its corresponding location in // VARPATH/original/ is deleted as well, if it exists. if ($item->is_album()) { $original_file = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); if (file_exists($original_file)) { @dir::unlink($original_file); } } } static function item_updated($old, $new) { // When updating an item, check and see if the file name is being changed. // If so, check for and modify any corresponding file/folder in // VARPATH/original/ as well. if ($old->is_photo() || $old->is_album()) { $data_file = $new->get_data_file(); if (isset($data_file)) { self::_preserve($old->file_path()); } if ($old->file_path() != $new->file_path()) { $old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path()); $new_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $new->file_path()); if (file_exists($old_original)) { @rename($old_original, $new_original); } } } } static function item_moved($item, $old_parent) { // When moving an item, check and see if a corresponding file exists // in VARPATH/original/. If so, move that item to a similar directory // in original as well. if ($item->is_photo() || $item->is_album()) { $old_item_path = $old_parent->file_path() . "/" . $item->name; if ($item->file_path() != $old_item_path) { $old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old_item_path); $new_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); if (file_exists($old_original)) { // Make sure the new folder exists, create it if it doesn't. $individual_dirs = split("[/\]", "original/" . str_replace(VARPATH . "albums/", "", $item->file_path())); $new_img_path = VARPATH; for($i = 0; $i < count($individual_dirs)-1; $i++) { $new_img_path = $new_img_path . "/" . $individual_dirs[$i]; if(!file_exists($new_img_path)) { @mkdir($new_img_path); } } // Move the file to its new location. @rename($old_original, $new_original); } } } } static function site_menu($menu, $theme) { // Create a menu option to restore the original photo. if ($item = $theme->item()) { if ((access::can("view", $item)) && (access::can("edit", $item))) { $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); if ($item->is_photo() && file_exists($original_image)) { $menu->get("options_menu") ->append(Menu::factory("link") ->id("restore") ->label(t("Restore original")) ->css_id("g-keep-originals-link") ->url(url::site("keeporiginal/restore/" . $item->id))); } } } } }