Initial Commit of BatchTag module.
Signed-off-by: Bharat Mediratta <bharat@menalto.com>
This commit is contained in:
parent
b73666e77d
commit
a7fa56d1e5
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 ?>
|
Reference in New Issue
Block a user