2009-07-30 04:27:16 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
/**
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2012-02-27 18:04:35 +00:00
|
|
|
* Copyright (C) 2000-2012 Bharat Mediratta
|
2009-07-30 04:27:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
class keeporiginal_event_Core {
|
2009-07-30 21:12:12 +00:00
|
|
|
static function graphics_rotate($input_file, $output_file, $options) {
|
|
|
|
// Make a copy of the original fullsized image before rotating it.
|
2011-07-28 06:41:23 +00:00
|
|
|
keeporiginal_event_Core::_preserve($input_file);
|
2011-04-24 05:12:35 +00:00
|
|
|
}
|
2009-07-30 21:12:12 +00:00
|
|
|
|
2011-04-24 14:22:32 +00:00
|
|
|
static function _preserve($input_file) {
|
2009-07-30 21:12:12 +00:00
|
|
|
// If $input_file is located in VARPATH/albums/ then assume its a fullsize photo.
|
|
|
|
if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) {
|
|
|
|
// Figure out where the original copy should be stashed at.
|
|
|
|
$temp_path = str_replace(VARPATH . "albums/", "", $input_file);
|
|
|
|
$original_image = VARPATH . "original/" . $temp_path;
|
2011-04-24 04:52:43 +00:00
|
|
|
$individual_dirs = preg_split("|[/\\\\]|", "original/" . $temp_path);
|
2009-07-30 21:12:12 +00:00
|
|
|
// If any original file does not already exist, then create a folder structure
|
|
|
|
// similar to that found in VARPATH/albums/ and copy the photo over before
|
|
|
|
// rotating it.
|
|
|
|
if (!file_exists($original_image)) {
|
2009-08-03 05:58:03 +00:00
|
|
|
$new_img_path = VARPATH;
|
2009-07-30 21:12:12 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-08-03 05:58:03 +00:00
|
|
|
if (!@copy($input_file, $original_image)) {
|
|
|
|
// If the copy failed, display an error message.
|
|
|
|
message::error(t("Your original image was not backed up!"));
|
|
|
|
}
|
2009-07-30 21:12:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-30 04:27:16 +00:00
|
|
|
static function item_before_delete($item) {
|
2009-07-30 04:48:59 +00:00
|
|
|
// If deleting a photo, make sure the original is deleted as well, if it exists.
|
2009-07-30 04:27:16 +00:00
|
|
|
if ($item->is_photo()) {
|
|
|
|
$original_file = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
|
|
|
|
if (file_exists($original_file)) {
|
2009-08-03 05:58:03 +00:00
|
|
|
@unlink($original_file);
|
2009-07-30 04:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-30 17:34:00 +00:00
|
|
|
|
|
|
|
// When deleting an album, make sure its corresponding location in
|
|
|
|
// VARPATH/original/ is deleted as well, if it exists.
|
2009-07-30 04:27:16 +00:00
|
|
|
if ($item->is_album()) {
|
|
|
|
$original_file = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
|
|
|
|
if (file_exists($original_file)) {
|
|
|
|
@dir::unlink($original_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 17:34:00 +00:00
|
|
|
|
2009-07-30 04:27:16 +00:00
|
|
|
static function item_updated($old, $new) {
|
2009-07-30 04:48:59 +00:00
|
|
|
// When updating an item, check and see if the file name is being changed.
|
2009-07-30 17:34:00 +00:00
|
|
|
// If so, check for and modify any corresponding file/folder in
|
2009-07-30 04:48:59 +00:00
|
|
|
// VARPATH/original/ as well.
|
2009-09-30 20:10:33 +00:00
|
|
|
|
2009-07-30 04:27:16 +00:00
|
|
|
if ($old->is_photo() || $old->is_album()) {
|
2011-05-01 00:11:39 +00:00
|
|
|
$data_file = $new->data_file;
|
2011-04-24 14:10:22 +00:00
|
|
|
if (isset($data_file)) {
|
2011-07-28 06:41:23 +00:00
|
|
|
keeporiginal_event_Core::_preserve($old->file_path());
|
2011-04-24 05:12:35 +00:00
|
|
|
}
|
2009-07-30 04:27:16 +00:00
|
|
|
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)) {
|
2009-08-03 05:58:03 +00:00
|
|
|
@rename($old_original, $new_original);
|
2009-07-30 04:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 17:34:00 +00:00
|
|
|
|
2009-08-03 05:58:03 +00:00
|
|
|
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.
|
2009-09-30 20:10:33 +00:00
|
|
|
|
2009-08-03 05:58:03 +00:00
|
|
|
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());
|
2009-09-30 20:10:33 +00:00
|
|
|
|
2009-08-03 05:58:03 +00:00
|
|
|
if (file_exists($old_original)) {
|
2009-09-30 20:10:33 +00:00
|
|
|
|
|
|
|
// 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.
|
2011-04-24 14:53:42 +00:00
|
|
|
// TODO: If the files have different extensions, then the old extension should be preserved.
|
2009-08-03 05:58:03 +00:00
|
|
|
@rename($old_original, $new_original);
|
|
|
|
}
|
|
|
|
}
|
2009-11-17 22:06:04 +00:00
|
|
|
}
|
2009-08-03 05:58:03 +00:00
|
|
|
}
|
2009-07-30 17:34:00 +00:00
|
|
|
|
2009-11-17 22:06:04 +00:00
|
|
|
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());
|
2009-07-30 17:34:00 +00:00
|
|
|
|
2009-11-17 22:06:04 +00:00
|
|
|
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)));
|
|
|
|
}
|
2009-07-30 17:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-28 06:51:00 +00:00
|
|
|
}
|