1
0

Initial commit

This commit is contained in:
Kriss Andsten 2010-11-26 22:12:56 +01:00 committed by Bharat Mediratta
parent b7444e5cfc
commit f25f70ef77
7 changed files with 268 additions and 0 deletions

View File

@ -0,0 +1,98 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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.
*/
/**
* This is the API for handling exif data.
*/
class author_Core {
static function fix($item) {
if ($item->is_album()) { return false; }
$mime = $item->mime_type;
if ($mime == 'image/jpeg' || $mime == 'image/png' || $mime == 'image/gif') {}
else { return false; }
$owner = ORM::factory("user")->where("id", "=", $item->owner_id)->find();
$user_name = $owner->full_name;
$exiv = module::get_var('author', 'exiv_path');
$exivData = array();
exec("$exiv -p a " . escapeshellarg($item->file_path()), $exivData);
$has = array();
$mod = array();
foreach ($exivData as $line)
{
$tokens = preg_split('/\s+/', $line, 4);
$has[ $tokens[0] ] = $tokens[3];
}
$candidates = array(
$has['Xmp.dc.creator'],
$has['Iptc.Application2.Byline'],
$has['Exif.Image.Artist'],
$user_name,
'Unknown');
foreach ($candidates as $cand) {
if ($cand != '') { $byline = $cand; break; }
}
if (!array_key_exists('Exif.Image.Artist', $has)) { $mod['Exif.Image.Artist'] = $byline; }
if (!array_key_exists('Xmp.dc.creator', $has)) { $mod['Xmp.dc.creator'] = $byline; }
if (!array_key_exists('Iptc.Application2.Byline', $has)) { $mod['Iptc.Application2.Byline'] = $byline; }
# Apply our own image terms URL.
$terms = module::get_var("author", "usage_terms")
if ($terms != '') {
$mod['Xmp.xmpRights.UsageTerms'] = 'http://wiki.sverok.se/wiki/Bildbank-Bilder';
}
# ..and credit.
$credit = module::get_var("author", "credit")
if ($credit != '') {
$mod['Iptc.Application2.Credit'] = $credit;
}
$line = $exiv . ' ';
foreach ($mod as $key => $value) {
$line .= "-M \"set $key " . escapeshellarg($value) . "\" ";
}
$files = array(
$item->file_path(),
$item->thumb_path(),
$item->resize_path()
);
foreach ($files as $file) {
system("$line " . escapeshellarg($file));
}
$record = ORM::factory("author_record")->where("item_id", "=", $item->id)->find();
if (!$record->loaded()) {
$record->item_id = $item->id;
}
$record->author = $byline;
$record->dirty = 0;
$record->save();
return $byline;
}
}

View File

@ -0,0 +1,48 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 author_block_Core {
static function get_site_list() {
return array("author" => t("Author"));
}
static function get($block_id, $theme) {
$item = $theme->item;
if ($block_id != 'author' || $item->is_album() ) {
return '';
}
$record = db::build()
->select("author")
->from("author_records")
->where("item_id", "=", $item->id)
->execute()
->current();
$byline = $record->author;
if ($byline == '') {
$byline = author::fix($item);
}
$block = new Block();
$block->content = new View("author_block.html");
$block->content->author = $byline;
return $block;
}
}

View File

@ -0,0 +1,32 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 author_event_Core
{
static function item_created($item) {
$byline = author::fix($item);
}
static function item_deleted($item) {
db::build()
->delete("author_records")
->where("item_id", "=", $item->id)
->execute();
}
}

View File

@ -0,0 +1,60 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 author_installer {
static function install() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {author_records} (
`id` int(9) NOT NULL auto_increment,
`item_id` INTEGER(9) NOT NULL,
`author` TEXT,
`dirty` BOOLEAN default 1,
PRIMARY KEY (`id`),
KEY(`item_id`))
DEFAULT CHARSET=utf8;");
module::set_version("author", 1);
module::set_var("author", "usage_terms", '');
module::set_var("author", "credit", '');
return true;
}
static function activate() {
gallery::set_path_env(
array(
getenv("PATH"),
module::get_var("gallery", "extra_binary_paths")
));
$exiv = exec('which exiv2');
if ($exiv == '') {
# Proper warning
}
else {
module::set_var("author", "exiv_path", $exiv);
}
}
static function deactivate() {
}
static function uninstall() {
Database::instance()->query("DROP TABLE IF EXISTS {author_records};");
}
}

View File

@ -0,0 +1,21 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 Author_Record_Model extends ORM {
}

View File

@ -0,0 +1,3 @@
name = "Author"
description = "Allows for the display and modification of the Author/Photographer/Byline data in photos."
version = 1

View File

@ -0,0 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-author-block">
<?= t('Credit') ?>: <?= html::clean($author) ?>
</div>