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 {
|
class date_tag {
|
||||||
static function tag_item($item) {
|
static function tag_item($item) {
|
||||||
|
|
||||||
if ($item->is_photo() && $item->captured) {
|
if (!$item->is_album() && $item->captured) {
|
||||||
tag::add($item, date("F", $item->captured));
|
$date_format = module::get_var("date_tag", "template");
|
||||||
tag::add($item, date("Y", $item->captured));
|
foreach (explode(",", date($date_format, $item->captured)) as $tag_name) {
|
||||||
|
$tag_name = trim($tag_name);
|
||||||
|
if ($tag_name) {
|
||||||
|
tag::add($item, $tag_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,15 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class date_tag_event_Core {
|
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) {
|
static function item_created($item) {
|
||||||
date_tag::tag_item($item);
|
date_tag::tag_item($item);
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,14 @@
|
|||||||
*/
|
*/
|
||||||
class date_tag_installer {
|
class date_tag_installer {
|
||||||
static function install() {
|
static function install() {
|
||||||
module::set_version("date_tag", 1);
|
module::set_version("date_tag", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function upgrade($version) {
|
static function upgrade($version) {
|
||||||
if ($version == 1) {
|
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() {
|
static function deactivate() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,71 +19,71 @@
|
|||||||
*/
|
*/
|
||||||
class date_tag_task_Core {
|
class date_tag_task_Core {
|
||||||
|
|
||||||
static function available_tasks() {
|
static function available_tasks() {
|
||||||
$tasks[] = Task_Definition::factory()
|
$tasks[] = Task_Definition::factory()
|
||||||
->callback("date_tag_task::date_tag_all")
|
->callback("date_tag_task::date_tag_all")
|
||||||
->name(t("Add tags for dates"))
|
->name(t("Add tags for dates"))
|
||||||
->description(t("Add tags for dates of all images that have already been uploaded"))
|
->description(t("Add tags for dates of all images that have already been uploaded"))
|
||||||
->severity(log::SUCCESS);
|
->severity(log::SUCCESS);
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Task_Model the task
|
* @param Task_Model the task
|
||||||
*/
|
*/
|
||||||
static function date_tag_all($task) {
|
static function date_tag_all($task) {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
try {
|
try {
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$last_item_id= $task->get("last_item_id", null);
|
$last_item_id= $task->get("last_item_id", null);
|
||||||
$current = 0;
|
$current = 0;
|
||||||
$total = 0;
|
$total = 0;
|
||||||
|
|
||||||
switch ($task->get("mode", "init")) {
|
switch ($task->get("mode", "init")) {
|
||||||
case "init":
|
case "init":
|
||||||
$task->set("total", ORM::factory("item")->where("type", "=", "photo")->count_all());
|
$task->set("total", ORM::factory("item")->where("type", "=", "photo")->count_all());
|
||||||
$task->set("mode", "date_tag_all");
|
$task->set("mode", "date_tag_all");
|
||||||
$task->set("completed", 0);
|
$task->set("completed", 0);
|
||||||
$task->set("last_item_id", 0);
|
$task->set("last_item_id", 0);
|
||||||
|
|
||||||
case "date_tag_all":
|
case "date_tag_all":
|
||||||
$completed = $task->get("completed");
|
$completed = $task->get("completed");
|
||||||
$total = $task->get("total");
|
$total = $task->get("total");
|
||||||
$last_item_id= $task->get("last_item_id");
|
$last_item_id= $task->get("last_item_id");
|
||||||
$items = ORM::factory("item")
|
$items = ORM::factory("item")
|
||||||
->where("id", ">", $last_item_id)
|
->where("id", ">", $last_item_id)
|
||||||
->and_where("type", "=", "photo")
|
->and_where("type", "=", "photo")
|
||||||
->find_all(5); /* TODO: should we fetch more at a time? Less? */
|
->find_all(5); /* TODO: should we fetch more at a time? Less? */
|
||||||
while ($current < $total && microtime(true) - $start < 1 && $item = $items->current()) {
|
while ($current < $total && microtime(true) - $start < 1 && $item = $items->current()) {
|
||||||
$last_tem_id = $item->id;
|
$last_tem_id = $item->id;
|
||||||
$task->log("Looking at item {$item->name} (id: {$item->id})");
|
$task->log("Looking at item {$item->name} (id: {$item->id})");
|
||||||
date_tag::tag_item($item);
|
date_tag::tag_item($item);
|
||||||
|
|
||||||
$completed++;
|
$completed++;
|
||||||
$items->next();
|
$items->next();
|
||||||
$task->percent_complete = $completed / $total * 100;
|
$task->percent_complete = $completed / $total * 100;
|
||||||
$task->set("completed", $completed);
|
$task->set("completed", $completed);
|
||||||
$task->set("last_item_id", $item->id);
|
$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) {
|
if ($completed == $total) {
|
||||||
$task->done = true;
|
$task->done = true;
|
||||||
$task->state = "success";
|
$task->state = "success";
|
||||||
$task->percent_complete = 100;
|
$task->percent_complete = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Kohana_Log::add("error",(string)$e);
|
Kohana_Log::add("error",(string)$e);
|
||||||
$task->done = true;
|
$task->done = true;
|
||||||
$task->state = "error";
|
$task->state = "error";
|
||||||
$task->status = $e->getMessage();
|
$task->status = $e->getMessage();
|
||||||
$errors[] = (string)$e;
|
$errors[] = (string)$e;
|
||||||
}
|
}
|
||||||
if ($errors) {
|
if ($errors) {
|
||||||
$task->log($errors);
|
$task->log($errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name = "Date Tag"
|
name = "Date Tag"
|
||||||
description = "Automatically add tags with the captured date"
|
description = "Automatically add tags with the captured date"
|
||||||
version = 1
|
version = 2
|
||||||
author_name ="mikeage"
|
author_name ="mikeage"
|
||||||
author_url = "http://mikeage.net"
|
author_url = "http://mikeage.net"
|
||||||
info_url = "http://TODO"
|
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