Merge commit 'upstream/master'
This commit is contained in:
commit
d4e345c35c
54
modules/batchtag/controllers/batchtag.php
Normal file
54
modules/batchtag/controllers/batchtag.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?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 BatchTag_Controller extends Controller {
|
||||||
|
public function tagitems() {
|
||||||
|
// Tag all non-album items in the current album with the specified tags.
|
||||||
|
|
||||||
|
// Prevent Cross Site Request Forgery
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
// Generate an array of all non-album items in the current album.
|
||||||
|
$children = ORM::factory("item")
|
||||||
|
->where("parent_id", $this->input->post("item_id"))
|
||||||
|
->where("type !=", "album")
|
||||||
|
->find_all();
|
||||||
|
|
||||||
|
// Loop through each item in the album and make sure the user has
|
||||||
|
// access to view and edit it.
|
||||||
|
foreach ($children as $child) {
|
||||||
|
if (access::can("view", $child) && access::can("edit", $child)) {
|
||||||
|
|
||||||
|
// Assuming the user can view/edit the current item, loop
|
||||||
|
// through each tag that was submitted and apply it to
|
||||||
|
// the current item.
|
||||||
|
foreach (split(",", $this->input->post("name")) as $tag_name) {
|
||||||
|
$tag_name = trim($tag_name);
|
||||||
|
if ($tag_name) {
|
||||||
|
tag::add($child, $tag_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect back to the album.
|
||||||
|
$item = ORM::factory("item", $this->input->post("item_id"));
|
||||||
|
url::redirect(url::abs_site("{$item->type}s/{$item->id}"));
|
||||||
|
}
|
||||||
|
}
|
27
modules/batchtag/helpers/batchtag_installer.php
Normal file
27
modules/batchtag/helpers/batchtag_installer.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?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 batchtag_installer {
|
||||||
|
static function install() {
|
||||||
|
module::set_version("batchtag", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function uninstall() {
|
||||||
|
module::delete("batchtag");
|
||||||
|
}
|
||||||
|
}
|
49
modules/batchtag/helpers/batchtag_theme.php
Normal file
49
modules/batchtag/helpers/batchtag_theme.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?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 batchtag_theme_Core {
|
||||||
|
static function sidebar_blocks($theme) {
|
||||||
|
// Display form for tagging in the album sidebar.
|
||||||
|
|
||||||
|
$item = $theme->item();
|
||||||
|
|
||||||
|
// Only display the form in albums that the user has edit permission in.
|
||||||
|
if ($item->is_album() && access::can("edit", $item)) {
|
||||||
|
|
||||||
|
// Make a new sidebar block.
|
||||||
|
$block = new Block();
|
||||||
|
$block->css_id = "gBatchTag";
|
||||||
|
$block->title = t("Batch Tag");
|
||||||
|
$block->content = new View("batchtag_block.html");
|
||||||
|
|
||||||
|
// Make a new form to place in the sidebar block.
|
||||||
|
$form = new Forge("batchtag/tagitems", "", "post",
|
||||||
|
array("id" => "gBatchTagForm"));
|
||||||
|
$label = t("Tag everything in this album:");
|
||||||
|
$group = $form->group("add_tag")->label("Add Tag");
|
||||||
|
$group->input("name")->label($label)->rules("required|length[1,64]");
|
||||||
|
$group->hidden("item_id")->value($item->id);
|
||||||
|
$group->submit("")->value(t("Add Tag"));
|
||||||
|
$block->content->form = $form;
|
||||||
|
|
||||||
|
// Display the block.
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
modules/batchtag/module.info
Normal file
3
modules/batchtag/module.info
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name = BatchTag
|
||||||
|
description = Automatically apply a tag to the entire contents of an album.
|
||||||
|
version = 1
|
2
modules/batchtag/views/batchtag_block.html.php
Normal file
2
modules/batchtag/views/batchtag_block.html.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<?= $form ?>
|
@ -32,30 +32,40 @@ class keeporiginal_Controller extends Controller {
|
|||||||
|
|
||||||
// Make sure the current item is a photo and that an original exists.
|
// Make sure the current item is a photo and that an original exists.
|
||||||
if ($item->is_photo() && file_exists($original_image)) {
|
if ($item->is_photo() && file_exists($original_image)) {
|
||||||
|
// Delete the modified version of the photo.
|
||||||
|
@unlink($item->file_path());
|
||||||
|
|
||||||
// Delete the modified version and move the original over in place of it.
|
// Copy the original image back over, display an error message if the copy fails.
|
||||||
unlink($item->file_path());
|
if (@rename($original_image, $item->file_path())) {
|
||||||
rename($original_image, $item->file_path());
|
// Re-generate the items resize and thumbnail.
|
||||||
|
$item_data = model_cache::get("item", $id);
|
||||||
|
$item_data->resize_dirty= 1;
|
||||||
|
$item_data->thumb_dirty= 1;
|
||||||
|
$item_data->save();
|
||||||
|
graphics::generate($item_data);
|
||||||
|
|
||||||
// Re-generate the items resize and thumbnail.
|
// If the item is the thumbnail for the parent album,
|
||||||
$item_data = model_cache::get("item", $id);
|
// fix the parent's thumbnail as well.
|
||||||
$item_data->resize_dirty= 1;
|
$parent = $item_data->parent();
|
||||||
$item_data->thumb_dirty= 1;
|
if ($parent->album_cover_item_id == $item_data->id) {
|
||||||
$item_data->save();
|
copy($item_data->thumb_path(), $parent->thumb_path());
|
||||||
graphics::generate($item_data);
|
$parent->thumb_width = $item_data->thumb_width;
|
||||||
|
$parent->thumb_height = $item_data->thumb_height;
|
||||||
|
$parent->save();
|
||||||
|
}
|
||||||
|
|
||||||
// If the item is the thumbnail for the parent album,
|
// Display a success message and redirect to the items page.
|
||||||
// fix the parent's thumbnail as well.
|
message::success(t("Your original image has been restored."));
|
||||||
$parent = $item_data->parent();
|
url::redirect($item->url());
|
||||||
if ($parent->album_cover_item_id == $item_data->id) {
|
|
||||||
copy($item_data->thumb_path(), $parent->thumb_path());
|
} else {
|
||||||
$parent->thumb_width = $item_data->thumb_width;
|
// Display an error message if the copy failed.
|
||||||
$parent->thumb_height = $item_data->thumb_height;
|
message::error(t("Image restore failed!"));
|
||||||
$parent->save();
|
url::redirect($item->url());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// Display a success message and redirect to the items page.
|
// Display an error message if there is not an original photo.
|
||||||
message::success(t("Your Original Image Has Been Restored."));
|
message::error(t("Image restore failed!"));
|
||||||
url::redirect($item->url());
|
url::redirect($item->url());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,19 +26,22 @@ class keeporiginal_event_Core {
|
|||||||
// Figure out where the original copy should be stashed at.
|
// Figure out where the original copy should be stashed at.
|
||||||
$temp_path = str_replace(VARPATH . "albums/", "", $input_file);
|
$temp_path = str_replace(VARPATH . "albums/", "", $input_file);
|
||||||
$original_image = VARPATH . "original/" . $temp_path;
|
$original_image = VARPATH . "original/" . $temp_path;
|
||||||
$individual_dirs = split("[/\]", $temp_path);
|
$individual_dirs = split("[/\]", "original/" . $temp_path);
|
||||||
// If any original file does not already exist, then create a folder structure
|
// 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
|
// similar to that found in VARPATH/albums/ and copy the photo over before
|
||||||
// rotating it.
|
// rotating it.
|
||||||
if (!file_exists($original_image)) {
|
if (!file_exists($original_image)) {
|
||||||
$new_img_path = VARPATH . "original/";
|
$new_img_path = VARPATH;
|
||||||
for($i = 0; $i < count($individual_dirs)-1; $i++) {
|
for($i = 0; $i < count($individual_dirs)-1; $i++) {
|
||||||
$new_img_path = $new_img_path . "/" . $individual_dirs[$i];
|
$new_img_path = $new_img_path . "/" . $individual_dirs[$i];
|
||||||
if(!file_exists($new_img_path)) {
|
if(!file_exists($new_img_path)) {
|
||||||
@mkdir($new_img_path);
|
@mkdir($new_img_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copy($input_file, $original_image);
|
if (!@copy($input_file, $original_image)) {
|
||||||
|
// If the copy failed, display an error message.
|
||||||
|
message::error(t("Your original image was not backed up!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,7 +51,7 @@ class keeporiginal_event_Core {
|
|||||||
if ($item->is_photo()) {
|
if ($item->is_photo()) {
|
||||||
$original_file = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
|
$original_file = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
|
||||||
if (file_exists($original_file)) {
|
if (file_exists($original_file)) {
|
||||||
unlink($original_file);
|
@unlink($original_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +74,23 @@ class keeporiginal_event_Core {
|
|||||||
$old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path());
|
$old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path());
|
||||||
$new_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $new->file_path());
|
$new_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $new->file_path());
|
||||||
if (file_exists($old_original)) {
|
if (file_exists($old_original)) {
|
||||||
rename($old_original, $new_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)) {
|
||||||
|
@rename($old_original, $new_original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +107,7 @@ class keeporiginal_event_Core {
|
|||||||
$menu->get("options_menu")
|
$menu->get("options_menu")
|
||||||
->append(Menu::factory("link")
|
->append(Menu::factory("link")
|
||||||
->id("restore")
|
->id("restore")
|
||||||
->label("Restore Original")
|
->label("Restore original")
|
||||||
->css_id("gKeepOriginalLink")
|
->css_id("gKeepOriginalLink")
|
||||||
->url(url::site("keeporiginal/restore/" . $item->id)));
|
->url(url::site("keeporiginal/restore/" . $item->id)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user