2004-08-21 12:52:43 +00:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 21:12:59 +00:00
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
|
|
|
// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net |
|
2004-08-21 12:52:43 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 21:12:59 +00:00
|
|
|
// | branch : BSF (Best So Far)
|
2004-08-21 12:52:43 +00:00
|
|
|
// | file : $RCSfile$
|
|
|
|
// | last update : $Date$
|
|
|
|
// | last modifier : $Author$
|
|
|
|
// | revision : $Revision$
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | 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 |
|
|
|
|
// | |
|
|
|
|
// | 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
2004-08-25 21:09:09 +00:00
|
|
|
include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
|
|
|
|
|
|
|
|
function get_sync_iptc_data($file)
|
2004-08-21 12:52:43 +00:00
|
|
|
{
|
2004-11-10 22:31:51 +00:00
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$map = $conf['use_iptc_mapping'];
|
2004-08-21 12:52:43 +00:00
|
|
|
$datefields = array('date_creation', 'date_available');
|
|
|
|
|
2004-08-25 21:09:09 +00:00
|
|
|
$iptc = get_iptc_data($file, $map);
|
|
|
|
|
|
|
|
foreach ($iptc as $pwg_key => $value)
|
2004-08-21 12:52:43 +00:00
|
|
|
{
|
2004-08-25 21:09:09 +00:00
|
|
|
if (in_array($pwg_key, $datefields))
|
2004-08-21 12:52:43 +00:00
|
|
|
{
|
2004-11-23 22:31:24 +00:00
|
|
|
if (preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches))
|
2004-08-21 12:52:43 +00:00
|
|
|
{
|
2004-08-25 21:09:09 +00:00
|
|
|
$iptc[$pwg_key] = $matches[1].'-'.$matches[2].'-'.$matches[3];
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-25 21:09:09 +00:00
|
|
|
|
2004-10-09 10:04:23 +00:00
|
|
|
if (isset($iptc['keywords']))
|
|
|
|
{
|
|
|
|
// keywords separator is the comma, nothing else. Allowed characters in
|
|
|
|
// keywords : [A-Za-z0-9], "-" and "_". All other characters will be
|
|
|
|
// considered as separators
|
|
|
|
$iptc['keywords'] = preg_replace('/[^\w-]+/', ',', $iptc['keywords']);
|
|
|
|
$iptc['keywords'] = preg_replace('/^,+|,+$/', '', $iptc['keywords']);
|
|
|
|
}
|
|
|
|
|
2004-08-25 21:09:09 +00:00
|
|
|
return $iptc;
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_metadata($files)
|
|
|
|
{
|
|
|
|
global $conf;
|
2004-10-24 18:57:19 +00:00
|
|
|
|
|
|
|
if (!defined('CURRENT_DATE'))
|
|
|
|
{
|
2004-11-30 19:53:33 +00:00
|
|
|
define('CURRENT_DATE', date('Y-m-d'));
|
2004-10-24 18:57:19 +00:00
|
|
|
}
|
|
|
|
|
2004-11-30 20:26:44 +00:00
|
|
|
$datas = array();
|
2004-08-21 12:52:43 +00:00
|
|
|
|
|
|
|
foreach ($files as $id => $file)
|
|
|
|
{
|
2004-11-30 20:26:44 +00:00
|
|
|
$data = array();
|
|
|
|
$data['id'] = $id;
|
|
|
|
$data['filesize'] = floor(filesize($file)/1024);
|
2004-08-21 12:52:43 +00:00
|
|
|
|
|
|
|
if ($image_size = @getimagesize($file))
|
|
|
|
{
|
2004-11-30 20:26:44 +00:00
|
|
|
$data['width'] = $image_size[0];
|
|
|
|
$data['height'] = $image_size[1];
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($conf['use_exif'])
|
|
|
|
{
|
|
|
|
if ($exif = @read_exif_data($file))
|
|
|
|
{
|
|
|
|
if (isset($exif['DateTime']))
|
|
|
|
{
|
2004-11-30 20:26:44 +00:00
|
|
|
preg_match('/^(\d{4}).(\d{2}).(\d{2})/',$exif['DateTime'],$matches);
|
|
|
|
$data['date_creation'] = $matches[1].'-'.$matches[2].'-'.$matches[3];
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($conf['use_iptc'])
|
|
|
|
{
|
2004-08-25 21:09:09 +00:00
|
|
|
$iptc = get_sync_iptc_data($file);
|
|
|
|
if (count($iptc) > 0)
|
2004-08-21 12:52:43 +00:00
|
|
|
{
|
2004-08-25 21:09:09 +00:00
|
|
|
foreach (array_keys($iptc) as $key)
|
|
|
|
{
|
2004-11-30 20:26:44 +00:00
|
|
|
$data[$key] = "'".addslashes($iptc[$key])."'";
|
2004-08-25 21:09:09 +00:00
|
|
|
}
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-30 20:26:44 +00:00
|
|
|
$data['date_metadata_update'] = CURRENT_DATE;
|
2004-08-21 12:52:43 +00:00
|
|
|
|
2004-11-30 20:26:44 +00:00
|
|
|
array_push($datas, $data);
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
|
2004-11-30 20:26:44 +00:00
|
|
|
if (count($datas) > 0)
|
2004-08-21 12:52:43 +00:00
|
|
|
{
|
2004-11-30 20:26:44 +00:00
|
|
|
$fields = array('primary' => array('id'),
|
|
|
|
'update' => array('filesize','width','height','name',
|
|
|
|
'author','comment','date_creation',
|
|
|
|
'keywords','date_metadata_update'));
|
|
|
|
mass_updates(IMAGES_TABLE, $fields, $datas);
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns an array associating element id (images.id) with its complete
|
|
|
|
* path in the filesystem
|
|
|
|
*
|
|
|
|
* @param int id_uppercat
|
|
|
|
* @param boolean recursive ?
|
|
|
|
* @param boolean only newly added files ?
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function get_filelist($category_id = '', $recursive = false, $only_new = false)
|
|
|
|
{
|
2004-12-25 19:33:36 +00:00
|
|
|
// filling $cat_ids : all categories required
|
|
|
|
$cat_ids = array();
|
2004-08-21 12:52:43 +00:00
|
|
|
|
|
|
|
$query = '
|
2004-12-25 19:33:36 +00:00
|
|
|
SELECT id
|
2004-10-24 18:57:19 +00:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE site_id = 1
|
|
|
|
AND dir IS NOT NULL';
|
2004-08-21 12:52:43 +00:00
|
|
|
if (is_numeric($category_id))
|
|
|
|
{
|
|
|
|
if ($recursive)
|
|
|
|
{
|
|
|
|
$query.= '
|
2004-10-24 18:57:19 +00:00
|
|
|
AND uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\'
|
2004-08-21 12:52:43 +00:00
|
|
|
';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query.= '
|
2004-10-24 18:57:19 +00:00
|
|
|
AND id = '.$category_id.'
|
2004-08-21 12:52:43 +00:00
|
|
|
';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query.= '
|
|
|
|
;';
|
2004-10-30 15:42:29 +00:00
|
|
|
$result = pwg_query($query);
|
2004-08-21 12:52:43 +00:00
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
2004-12-25 19:33:36 +00:00
|
|
|
array_push($cat_ids, $row['id']);
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
2004-11-02 23:25:27 +00:00
|
|
|
|
2004-12-25 19:33:36 +00:00
|
|
|
if (count($cat_ids) == 0)
|
2004-11-02 23:25:27 +00:00
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
2004-08-21 12:52:43 +00:00
|
|
|
|
2004-12-25 19:33:36 +00:00
|
|
|
$files = array();
|
2004-08-21 12:52:43 +00:00
|
|
|
|
|
|
|
$query = '
|
2004-12-25 19:33:36 +00:00
|
|
|
SELECT id, path
|
2004-08-21 12:52:43 +00:00
|
|
|
FROM '.IMAGES_TABLE.'
|
2004-12-25 19:33:36 +00:00
|
|
|
WHERE storage_category_id IN ('.implode(',', $cat_ids).')';
|
2004-08-21 12:52:43 +00:00
|
|
|
if ($only_new)
|
|
|
|
{
|
|
|
|
$query.= '
|
|
|
|
AND date_metadata_update IS NULL
|
|
|
|
';
|
|
|
|
}
|
|
|
|
$query.= '
|
|
|
|
;';
|
2004-10-30 15:42:29 +00:00
|
|
|
$result = pwg_query($query);
|
2004-08-21 12:52:43 +00:00
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
2004-12-25 19:33:36 +00:00
|
|
|
$files[$row['id']] = $row['path'];
|
2004-08-21 12:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
?>
|