commit
acf1869434
45
3.0/modules/date_tag/controllers/admin_date_tag.php
Normal file
45
3.0/modules/date_tag/controllers/admin_date_tag.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php defined("SYSPATH") or die("No direct script access.") ?><?php
|
||||
|
||||
class Admin_Date_Tag_Controller extends Admin_Controller {
|
||||
public function index() {
|
||||
$form = $this->_get_form();
|
||||
|
||||
if (request::method() == "post") {
|
||||
access::verify_csrf();
|
||||
|
||||
if ($form->validate()) {
|
||||
module::set_var("date_tag", "template", $_POST['template']);
|
||||
message::success(t("Settings have been saved"));
|
||||
url::redirect("admin/date_tag");
|
||||
} else {
|
||||
message::error(t("There was a problem with the submitted form. Please check your values and try again."));
|
||||
}
|
||||
}
|
||||
|
||||
print $this->_get_view();
|
||||
}
|
||||
|
||||
private function _get_view($form = null) {
|
||||
$v = new Admin_View("admin.html");
|
||||
$v->page_title = t("Gallery 3 :: Set Template for New Item Tags");
|
||||
|
||||
$v->content = new View("admin_date_tag.html");
|
||||
$v->content->form = empty($form) ? $this->_get_form() : $form;
|
||||
|
||||
return $v;
|
||||
}
|
||||
|
||||
private function _get_form() {
|
||||
$form = new Forge("admin/date_tag", "", "post", array("id" => "g-admin-date_tag-form"));
|
||||
|
||||
$group = $form->group("date_tag")->label(t("Default Tag (php's <a href=\"http://php.net/manual/en/function.date.php\">date() format</a>)"));
|
||||
|
||||
$group->input("template")
|
||||
->id("template")
|
||||
->label(t("Template:"))
|
||||
->value(module::get_var("date_tag", "template"));
|
||||
|
||||
$form->submit("submit")->value(t("Save"));
|
||||
return $form;
|
||||
}
|
||||
}
|
|
@ -20,9 +20,14 @@
|
|||
class date_tag {
|
||||
static function tag_item($item) {
|
||||
|
||||
if ($item->is_photo() && $item->captured) {
|
||||
tag::add($item, date("F", $item->captured));
|
||||
tag::add($item, date("Y", $item->captured));
|
||||
if (!$item->is_album() && $item->captured) {
|
||||
$date_format = module::get_var("date_tag", "template");
|
||||
foreach (explode(",", date($date_format, $item->captured)) as $tag_name) {
|
||||
$tag_name = trim($tag_name);
|
||||
if ($tag_name) {
|
||||
tag::add($item, $tag_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,15 @@
|
|||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class date_tag_event_Core {
|
||||
static function admin_menu($menu, $theme) {
|
||||
$menu
|
||||
->get("settings_menu")
|
||||
->append(Menu::factory("link")
|
||||
->id("date_tag_menu")
|
||||
->label(t("Date Tag"))
|
||||
->url(url::site("admin/date_tag")));
|
||||
}
|
||||
|
||||
static function item_created($item) {
|
||||
date_tag::tag_item($item);
|
||||
}
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
*/
|
||||
class date_tag_installer {
|
||||
static function install() {
|
||||
module::set_version("date_tag", 1);
|
||||
module::set_version("date_tag", 2);
|
||||
}
|
||||
|
||||
static function upgrade($version) {
|
||||
if ($version == 1) {
|
||||
module::set_version("date_tag", $version = 1);
|
||||
module::set_var("date_tag", "template", "F, Y");
|
||||
}
|
||||
module::set_version("date_tag", $version = 2);
|
||||
}
|
||||
|
||||
static function deactivate() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2012 Bharat Mediratta
|
||||
* Copyright (C) 2000-2013 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
|
||||
|
@ -19,71 +19,71 @@
|
|||
*/
|
||||
class date_tag_task_Core {
|
||||
|
||||
static function available_tasks() {
|
||||
$tasks[] = Task_Definition::factory()
|
||||
->callback("date_tag_task::date_tag_all")
|
||||
->name(t("Add tags for dates"))
|
||||
->description(t("Add tags for dates of all images that have already been uploaded"))
|
||||
->severity(log::SUCCESS);
|
||||
return $tasks;
|
||||
}
|
||||
static function available_tasks() {
|
||||
$tasks[] = Task_Definition::factory()
|
||||
->callback("date_tag_task::date_tag_all")
|
||||
->name(t("Add tags for dates"))
|
||||
->description(t("Add tags for dates of all images that have already been uploaded"))
|
||||
->severity(log::SUCCESS);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Task_Model the task
|
||||
*/
|
||||
static function date_tag_all($task) {
|
||||
$errors = array();
|
||||
try {
|
||||
$start = microtime(true);
|
||||
$last_item_id= $task->get("last_item_id", null);
|
||||
$current = 0;
|
||||
$total = 0;
|
||||
/**
|
||||
* @param Task_Model the task
|
||||
*/
|
||||
static function date_tag_all($task) {
|
||||
$errors = array();
|
||||
try {
|
||||
$start = microtime(true);
|
||||
$last_item_id= $task->get("last_item_id", null);
|
||||
$current = 0;
|
||||
$total = 0;
|
||||
|
||||
switch ($task->get("mode", "init")) {
|
||||
case "init":
|
||||
$task->set("total", ORM::factory("item")->where("type", "=", "photo")->count_all());
|
||||
$task->set("mode", "date_tag_all");
|
||||
$task->set("completed", 0);
|
||||
$task->set("last_item_id", 0);
|
||||
switch ($task->get("mode", "init")) {
|
||||
case "init":
|
||||
$task->set("total", ORM::factory("item")->where("type", "=", "photo")->count_all());
|
||||
$task->set("mode", "date_tag_all");
|
||||
$task->set("completed", 0);
|
||||
$task->set("last_item_id", 0);
|
||||
|
||||
case "date_tag_all":
|
||||
$completed = $task->get("completed");
|
||||
$total = $task->get("total");
|
||||
$last_item_id= $task->get("last_item_id");
|
||||
$items = ORM::factory("item")
|
||||
->where("id", ">", $last_item_id)
|
||||
->and_where("type", "=", "photo")
|
||||
->find_all(5); /* TODO: should we fetch more at a time? Less? */
|
||||
while ($current < $total && microtime(true) - $start < 1 && $item = $items->current()) {
|
||||
$last_tem_id = $item->id;
|
||||
$task->log("Looking at item {$item->name} (id: {$item->id})");
|
||||
date_tag::tag_item($item);
|
||||
case "date_tag_all":
|
||||
$completed = $task->get("completed");
|
||||
$total = $task->get("total");
|
||||
$last_item_id= $task->get("last_item_id");
|
||||
$items = ORM::factory("item")
|
||||
->where("id", ">", $last_item_id)
|
||||
->and_where("type", "=", "photo")
|
||||
->find_all(5); /* TODO: should we fetch more at a time? Less? */
|
||||
while ($current < $total && microtime(true) - $start < 1 && $item = $items->current()) {
|
||||
$last_tem_id = $item->id;
|
||||
$task->log("Looking at item {$item->name} (id: {$item->id})");
|
||||
date_tag::tag_item($item);
|
||||
|
||||
$completed++;
|
||||
$items->next();
|
||||
$task->percent_complete = $completed / $total * 100;
|
||||
$task->set("completed", $completed);
|
||||
$task->set("last_item_id", $item->id);
|
||||
$completed++;
|
||||
$items->next();
|
||||
$task->percent_complete = $completed / $total * 100;
|
||||
$task->set("completed", $completed);
|
||||
$task->set("last_item_id", $item->id);
|
||||
|
||||
|
||||
$task->status = t2("Examined %count items", "Examined %count items", $completed);
|
||||
$task->status = t2("Examined %count items", "Examined %count items", $completed);
|
||||
|
||||
if ($completed == $total) {
|
||||
$task->done = true;
|
||||
$task->state = "success";
|
||||
$task->percent_complete = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Kohana_Log::add("error",(string)$e);
|
||||
$task->done = true;
|
||||
$task->state = "error";
|
||||
$task->status = $e->getMessage();
|
||||
$errors[] = (string)$e;
|
||||
}
|
||||
if ($errors) {
|
||||
$task->log($errors);
|
||||
}
|
||||
}
|
||||
if ($completed == $total) {
|
||||
$task->done = true;
|
||||
$task->state = "success";
|
||||
$task->percent_complete = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Kohana_Log::add("error",(string)$e);
|
||||
$task->done = true;
|
||||
$task->state = "error";
|
||||
$task->status = $e->getMessage();
|
||||
$errors[] = (string)$e;
|
||||
}
|
||||
if ($errors) {
|
||||
$task->log($errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name = "Date Tag"
|
||||
description = "Automatically add tags with the captured date"
|
||||
version = 1
|
||||
version = 2
|
||||
author_name ="mikeage"
|
||||
author_url = "http://mikeage.net"
|
||||
info_url = "http://TODO"
|
||||
|
|
11
3.0/modules/date_tag/views/admin_date_tag.html.php
Normal file
11
3.0/modules/date_tag/views/admin_date_tag.html.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
|
||||
<div id="g-admin-code-block">
|
||||
<h2><?= t("Default Tagging for new images") ?></h2>
|
||||
|
||||
<p><?= t("Set a template (comma delimited) for date elements to be applied as tags."); ?></p>
|
||||
|
||||
<div class="g-block-content">
|
||||
<?php echo $form; ?>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user