New module to automatically tag items without EXIF information with a
capture date based on the filename (using a user specified template).
This commit is contained in:
parent
4be18155a0
commit
0fc6a6ba01
4
3.0/modules/auto_date/README.md
Normal file
4
3.0/modules/auto_date/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
auto_date
|
||||
========
|
||||
|
||||
Gallery3 module to automatically add extract capture date from the file name in the absense of EXIF information
|
45
3.0/modules/auto_date/controllers/admin_auto_date.php
Normal file
45
3.0/modules/auto_date/controllers/admin_auto_date.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?><?php
|
||||
|
||||
class Admin_Auto_Date_Controller extends Admin_Controller {
|
||||
public function index() {
|
||||
$form = $this->_get_form();
|
||||
|
||||
if (request::method() == "post") {
|
||||
access::verify_csrf();
|
||||
|
||||
if ($form->validate()) {
|
||||
module::set_var("auto_date", "template", $_POST['template']);
|
||||
message::success(t("Settings have been saved"));
|
||||
url::redirect("admin/auto_date");
|
||||
} 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 unknown items");
|
||||
|
||||
$v->content = new View("admin_auto_date.html");
|
||||
$v->content->form = empty($form) ? $this->_get_form() : $form;
|
||||
|
||||
return $v;
|
||||
}
|
||||
|
||||
private function _get_form() {
|
||||
$form = new Forge("admin/auto_date", "", "post", array("id" => "g-admin-auto_date-form"));
|
||||
|
||||
$group = $form->group("auto_date")->label(t("Default filename convention(php's <a href=\"http://php.net/manual/en/function.strptime.php\">strptime() format</a>)"));
|
||||
|
||||
$group->input("template")
|
||||
->id("template")
|
||||
->label(t("Template:"))
|
||||
->value(module::get_var("auto_date", "template"));
|
||||
|
||||
$form->submit("submit")->value(t("Save"));
|
||||
return $form;
|
||||
}
|
||||
}
|
34
3.0/modules/auto_date/helpers/auto_date.php
Normal file
34
3.0/modules/auto_date/helpers/auto_date.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* 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
|
||||
* 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 auto_date {
|
||||
static function set_auto_date($item) {
|
||||
|
||||
if (!$item->is_album() && !$item->captured) {
|
||||
$base_name = str_ireplace(array(".flv", ".jpg", ".gif"), "", $item->name);
|
||||
$date_format = module::get_var("auto_date", "template");
|
||||
$time = strptime($base_name, $date_format);
|
||||
if ($time) {
|
||||
$item->captured = mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon']+1, $time['tm_mday'], ($time['tm_year'] + 1900));
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
34
3.0/modules/auto_date/helpers/auto_date_event.php
Normal file
34
3.0/modules/auto_date/helpers/auto_date_event.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* 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
|
||||
* 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 auto_date_event_Core {
|
||||
static function admin_menu($menu, $theme) {
|
||||
$menu
|
||||
->get("settings_menu")
|
||||
->append(Menu::factory("link")
|
||||
->id("auto_date_menu")
|
||||
->label(t("Auto Date"))
|
||||
->url(url::site("admin/auto_date")));
|
||||
}
|
||||
|
||||
static function item_created($item) {
|
||||
auto_date::set_auto_date($item);
|
||||
}
|
||||
|
||||
}
|
37
3.0/modules/auto_date/helpers/auto_date_installer.php
Normal file
37
3.0/modules/auto_date/helpers/auto_date_installer.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* 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
|
||||
* 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 auto_date_installer {
|
||||
static function install() {
|
||||
module::set_version("auto_date", 1);
|
||||
if (!module::get_var("auto_date", "template")) {
|
||||
module::set_var("auto_date", "template", "%Y%m%d_%H%M%S");
|
||||
}
|
||||
}
|
||||
|
||||
static function upgrade($version) {
|
||||
}
|
||||
|
||||
static function deactivate() {
|
||||
}
|
||||
|
||||
static function can_activate() {
|
||||
}
|
||||
}
|
||||
|
90
3.0/modules/auto_date/helpers/auto_date_task.php
Normal file
90
3.0/modules/auto_date/helpers/auto_date_task.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* 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
|
||||
* 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 auto_date_task_Core {
|
||||
|
||||
static function available_tasks() {
|
||||
$tasks[] = Task_Definition::factory()
|
||||
->callback("auto_date_task::set_auto_date_all")
|
||||
->name(t("Set captured date for all unset items"))
|
||||
->description(t("Attempt to guess the captured date based on the filename (NULL capture dates only)"))
|
||||
->severity(log::SUCCESS);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Task_Model the task
|
||||
*/
|
||||
static function set_auto_date_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", "!=", "album")->and_where("captured", "is", NULL)->count_all());
|
||||
$task->set("mode", "set_auto_date_all");
|
||||
$task->set("completed", 0);
|
||||
$task->set("last_item_id", 0);
|
||||
|
||||
case "set_auto_date_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", "!=", "album")
|
||||
->and_where("captured", "is", NULL)
|
||||
->find_all(100); /* 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})");
|
||||
auto_date::set_auto_date($item);
|
||||
|
||||
$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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
7
3.0/modules/auto_date/module.info
Normal file
7
3.0/modules/auto_date/module.info
Normal file
@ -0,0 +1,7 @@
|
||||
name = "Auto Date"
|
||||
description = "Guess image / video capture date from the filename, if no EXIF information is available"
|
||||
version = 1
|
||||
author_name ="mikeage"
|
||||
author_url = "http://mikeage.net"
|
||||
info_url = "http://TODO"
|
||||
discuss_url = "http://TODO"
|
11
3.0/modules/auto_date/views/admin_auto_date.html.php
Normal file
11
3.0/modules/auto_date/views/admin_auto_date.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("Date filename format for unspecified images") ?></h2>
|
||||
|
||||
<p><?= t("Enter a template for the filename of images."); ?></p>
|
||||
|
||||
<div class="g-block-content">
|
||||
<?php echo $form; ?>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user