Navigation Menu

Skip to content

Commit

Permalink
feature 2548 multisize
Browse files Browse the repository at this point in the history
- rewrote local site sync + metadata sync

git-svn-id: http://piwigo.org/svn/trunk@12831 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Jan 3, 2012
1 parent 6c3ff24 commit d0b5df6
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 355 deletions.
14 changes: 1 addition & 13 deletions admin/batch_manager_global.php
Expand Up @@ -382,19 +382,7 @@
// synchronize metadata
if ('metadata' == $action)
{
$query = '
SELECT id, path
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $collection).')
;';
$id_to_path = array();
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
$id_to_path[$row['id']] = $row['path'];
}

update_metadata($id_to_path);
sync_metadata($collection);

array_push(
$page['infos'],
Expand Down
202 changes: 99 additions & 103 deletions admin/include/functions_metadata.php
Expand Up @@ -48,7 +48,7 @@ function get_sync_iptc_data($file)
$month = 1;
$day = 1;
}

$iptc[$pwg_key] = $year.'-'.$month.'-'.$day;
}
}
Expand Down Expand Up @@ -109,7 +109,75 @@ function get_sync_exif_data($file)
return $exif;
}

function update_metadata($files)

function get_sync_metadata_attributes()
{
global $conf;

$update_fields = array('filesize', 'width', 'height');

if ($conf['use_exif'])
{
$update_fields =
array_merge(
$update_fields,
array_keys($conf['use_exif_mapping'])
);
}

if ($conf['use_iptc'])
{
$update_fields =
array_merge(
$update_fields,
array_keys($conf['use_iptc_mapping'])
);
}

return array_unique($update_fields);
}

function get_sync_metadata($infos)
{
global $conf;
$file = PHPWG_ROOT_PATH.$infos['path'];
$fs = @filesize($file);

if ($fs===false)
{
return false;
}

$infos['filesize'] = floor($fs/1024);

if (isset($infos['representative_ext']))
{
$file = original_to_representative($file, $infos['representative_ext']);
}

if ($image_size = @getimagesize($file))
{
$infos['width'] = $image_size[0];
$infos['height'] = $image_size[1];
}

if ($conf['use_exif'])
{
$exif = get_sync_exif_data($file);
$infos = array_merge($infos, $exif);
}

if ($conf['use_iptc'])
{
$iptc = get_sync_iptc_data($file);
$infos = array_merge($infos, $iptc);
}

return $infos;
}


function sync_metadata($ids)
{
global $conf;

Expand All @@ -120,82 +188,40 @@ function update_metadata($files)

$datas = array();
$tags_of = array();
$has_high_images = array();

$image_ids = array();
foreach ($files as $id => $file)
{
array_push($image_ids, $id);
}

$query = '
SELECT id
SELECT id, path, representative_ext
FROM '.IMAGES_TABLE.'
WHERE has_high = \'true\'
AND id IN (
'.wordwrap(implode(', ', $image_ids), 80, "\n").'
WHERE id IN (
'.wordwrap(implode(', ', $ids), 160, "\n").'
)
;';

$has_high_images = array_from_query($query, 'id');

foreach ($files as $id => $file)
$result = pwg_query($query);
while ($data = pwg_db_fetch_assoc($result))
{
$data = array();
$data['id'] = $id;
$data['filesize'] = floor(filesize($file)/1024);

if ($image_size = @getimagesize($file))
$data = get_sync_metadata($data);
if ($data === false)
{
$data['width'] = $image_size[0];
$data['height'] = $image_size[1];
}

if (in_array($id, $has_high_images))
{
$high_file = dirname($file).'/pwg_high/'.basename($file);

$data['high_filesize'] = floor(filesize($high_file)/1024);
continue;
}

if ($conf['use_exif'])
$id = $data['id'];
foreach (array('keywords', 'tags') as $key)
{
$exif = get_sync_exif_data($file);
if (count($exif) == 0 and isset($data['high_filesize']))
if (isset($data[$key]))
{
$exif = get_sync_exif_data($high_file);
}
$data = array_merge($data, $exif);
}
if (!isset($tags_of[$id]))
{
$tags_of[$id] = array();
}

if ($conf['use_iptc'])
{
$iptc = get_sync_iptc_data($file);
if (count($iptc) == 0 and isset($data['high_filesize']))
{
$iptc = get_sync_iptc_data($high_file);
}
$data = array_merge($data, $iptc);

if (count($iptc) > 0)
{
foreach (array_keys($iptc) as $key)
foreach (explode(',', $data[$key]) as $tag_name)
{
if ($key == 'keywords' or $key == 'tags')
{
if (!isset($tags_of[$id]))
{
$tags_of[$id] = array();
}

foreach (explode(',', $iptc[$key]) as $tag_name)
{
array_push(
$tags_of[$id],
tag_id_from_tag_name($tag_name)
);
}
}
array_push(
$tags_of[$id],
tag_id_from_tag_name($tag_name)
);
}
}
}
Expand All @@ -207,41 +233,19 @@ function update_metadata($files)

if (count($datas) > 0)
{
$update_fields =
array(
'filesize',
'width',
'height',
'high_filesize',
'date_metadata_update'
);

if ($conf['use_exif'])
{
$update_fields =
array_merge(
$update_fields,
array_keys($conf['use_exif_mapping'])
);
}
$update_fields = get_sync_metadata_attributes();
array_push($update_fields, 'date_metadata_update');

if ($conf['use_iptc'])
{
$update_fields =
array_merge(
$update_fields,
array_diff(
array_keys($conf['use_iptc_mapping']),
array('tags', 'keywords')
)
);
}
$update_fields = array_diff(
$update_fields,
array('tags', 'keywords')
);

mass_updates(
IMAGES_TABLE,
array(
'primary' => array('id'),
'update' => array_unique($update_fields)
'update' => $update_fields
),
$datas,
MASS_UPDATES_SKIP_EMPTY
Expand Down Expand Up @@ -300,10 +304,8 @@ function get_filelist($category_id = '', $site_id=1, $recursive = false,
return array();
}

$files = array();

$query = '
SELECT id, path
SELECT id, path, representative_ext
FROM '.IMAGES_TABLE.'
WHERE storage_category_id IN ('.implode(',', $cat_ids).')';
if ($only_new)
Expand All @@ -314,12 +316,6 @@ function get_filelist($category_id = '', $site_id=1, $recursive = false,
}
$query.= '
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
$files[$row['id']] = $row['path'];
}

return $files;
return hash_from_query($query, 'id');
}
?>
2 changes: 1 addition & 1 deletion admin/include/functions_upload.inc.php
Expand Up @@ -480,7 +480,7 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
{
$conf['use_exif'] = false;
}
update_metadata(array($image_id=>$file_path));
sync_metadata(array($image_id));

invalidate_user_cache();

Expand Down
9 changes: 1 addition & 8 deletions admin/picture_modify.php
Expand Up @@ -94,14 +94,7 @@

if (isset($_GET['sync_metadata']))
{
$query = '
SELECT path
FROM '.IMAGES_TABLE.'
WHERE id = '.$_GET['image_id'].'
;';
list($path) = pwg_db_fetch_row(pwg_query($query));
update_metadata(array($_GET['image_id'] => $path));

sync_metadata(array( intval($_GET['image_id'])));
array_push($page['infos'], l10n('Metadata synchronized from file'));
}

Expand Down

0 comments on commit d0b5df6

Please sign in to comment.