1
0
This repository has been archived on 2021-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
gallery3-contrib/modules/keeporiginal/controllers/keeporiginal.php

56 lines
1.9 KiB
PHP
Raw Normal View History

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
* Copyright (C) 2000-2009 Bharat Mediratta
*
* 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_Controller extends Controller {
public function restore($id) {
$item = ORM::factory("item", $id);
access::required("view", $item);
access::required("edit", $item);
$original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
if ($item->is_photo() && file_exists($original_image)) {
unlink($item->file_path());
rename($original_image, $item->file_path());
$item_data = model_cache::get("item", $id);
$item_data->resize_dirty= 1;
$item_data->thumb_dirty= 1;
$item_data->save();
graphics::generate($item_data);
$parent = $item_data->parent();
if ($parent->album_cover_item_id == $item_data->id) {
copy($item_data->thumb_path(), $parent->thumb_path());
$parent->thumb_width = $item_data->thumb_width;
$parent->thumb_height = $item_data->thumb_height;
$parent->save();
}
message::success(t("Your Original Image Has Been Restored."));
url::redirect($item->url());
}
}
}