aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-01-03 20:21:13 +0000
committerrvelices <rv-github@modusoptimus.com>2012-01-03 20:21:13 +0000
commitd0b5df605c98e4c6985d825ab7110d2e3e9cb072 (patch)
treec2679a774a87e8daa6cb36bcd927eb0e8269e5f3
parent6c3ff240cba49ff9a8868b13d93b8c8110204217 (diff)
feature 2548 multisize
- rewrote local site sync + metadata sync git-svn-id: http://piwigo.org/svn/trunk@12831 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/batch_manager_global.php14
-rw-r--r--admin/include/functions_metadata.php202
-rw-r--r--admin/include/functions_upload.inc.php2
-rw-r--r--admin/picture_modify.php9
-rw-r--r--admin/site_reader_local.php145
-rw-r--r--admin/site_update.php139
-rw-r--r--include/derivative.inc.php5
-rw-r--r--include/functions.inc.php10
-rw-r--r--include/ws_functions.inc.php13
9 files changed, 184 insertions, 355 deletions
diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php
index 74e1a6a21..73e3586b5 100644
--- a/admin/batch_manager_global.php
+++ b/admin/batch_manager_global.php
@@ -382,19 +382,7 @@ DELETE
// 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'],
diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php
index 7f9b516b0..293c80b4b 100644
--- a/admin/include/functions_metadata.php
+++ b/admin/include/functions_metadata.php
@@ -48,7 +48,7 @@ function get_sync_iptc_data($file)
$month = 1;
$day = 1;
}
-
+
$iptc[$pwg_key] = $year.'-'.$month.'-'.$day;
}
}
@@ -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;
@@ -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)
+ );
}
}
}
@@ -207,41 +233,19 @@ SELECT id
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
@@ -300,10 +304,8 @@ SELECT id
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)
@@ -314,12 +316,6 @@ SELECT id, path
}
$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');
}
?> \ No newline at end of file
diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php
index 67bd8dd30..9181e3dc6 100644
--- a/admin/include/functions_upload.inc.php
+++ b/admin/include/functions_upload.inc.php
@@ -480,7 +480,7 @@ SELECT
{
$conf['use_exif'] = false;
}
- update_metadata(array($image_id=>$file_path));
+ sync_metadata(array($image_id));
invalidate_user_cache();
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index 57a78aaf2..a4bde5179 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -94,14 +94,7 @@ SELECT category_id
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'));
}
diff --git a/admin/site_reader_local.php b/admin/site_reader_local.php
index 5a48fe30a..5b1d62e64 100644
--- a/admin/site_reader_local.php
+++ b/admin/site_reader_local.php
@@ -30,6 +30,15 @@ var $site_url;
function LocalSiteReader($url)
{
$this->site_url = $url;
+ global $conf;
+ if (!isset($conf['flip_file_ext']))
+ {
+ $conf['flip_file_ext'] = array_flip($conf['file_ext']);
+ }
+ if (!isset($conf['flip_picture_ext']))
+ {
+ $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
+ }
}
/**
@@ -68,15 +77,11 @@ function get_full_directories($basedir)
* Returns an array with all file system files according to $conf['file_ext']
* and $conf['picture_ext']
* @param string $path recurse in this directory
- * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... )
+ * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... )
*/
function get_elements($path)
{
global $conf;
- if (!isset($conf['flip_file_ext']))
- {
- $conf['flip_file_ext'] = array_flip($conf['file_ext']);
- }
$subdirs = array();
$fs = array();
@@ -93,9 +98,13 @@ function get_elements($path)
if ( isset($conf['flip_file_ext'][$extension]) )
{
- $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
+ $representative_ext = null;
+ if (! isset($conf['flip_picture_ext'][$extension]) )
+ {
+ $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
+ }
$fs[ $path.'/'.$node ] = array(
- 'tn_ext' => $tn_ext,
+ 'representative_ext' => $representative_ext,
);
}
}
@@ -123,7 +132,7 @@ function get_elements($path)
// files update/synchronization
function get_update_attributes()
{
- return array('tn_ext', 'has_high', 'representative_ext');
+ return array('representative_ext');
}
function get_element_update_attributes($file)
@@ -132,19 +141,17 @@ function get_element_update_attributes($file)
$data = array();
$filename = basename($file);
- $dirname = dirname($file);
- $filename_wo_ext = get_filename_wo_extension($filename);
$extension = get_extension($filename);
- $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext);
- $data['has_high'] = $this->get_has_high($dirname, $filename);
-
- if ( !isset($conf['flip_picture_ext'][$extension]) )
+ $representative_ext = null;
+ if (! isset($conf['flip_picture_ext'][$extension]) )
{
- $data['representative_ext'] = $this->get_representative_ext(
- $dirname, $filename_wo_ext
- );
+ $dirname = dirname($file);
+ $filename_wo_ext = get_filename_wo_extension($filename);
+ $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext);
}
+
+ $data['representative_ext'] = $representative_ext;
return $data;
}
@@ -152,83 +159,13 @@ function get_element_update_attributes($file)
// metadata update/synchronization according to configuration
function get_metadata_attributes()
{
- global $conf;
-
- $update_fields = array('filesize', 'width', 'height', 'high_filesize', 'high_width', 'high_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 $update_fields;
+ return get_sync_metadata_attributes();
}
// returns a hash of attributes (metadata+filesize+width,...) for file
-function get_element_metadata($file, $has_high = false)
+function get_element_metadata($infos)
{
- global $conf;
- if (!is_file($file))
- {
- return null;
- }
-
- $data = array();
-
- $data['filesize'] = floor(filesize($file)/1024);
-
- if ($image_size = @getimagesize($file))
- {
- $data['width'] = $image_size[0];
- $data['height'] = $image_size[1];
- }
-
- if ($has_high)
- {
- $high_file = dirname($file).'/pwg_high/'.basename($file);
- $data['high_filesize'] = floor(filesize($high_file)/1024);
-
- if ($high_size = @getimagesize($high_file))
- {
- $data['high_width'] = $high_size[0];
- $data['high_height'] = $high_size[1];
- }
- }
-
- if ($conf['use_exif'])
- {
- $exif = get_sync_exif_data($file);
- if (count($exif) == 0 and isset($data['high_filesize']))
- {
- $exif = get_sync_exif_data($high_file);
- }
- $data = array_merge($data, $exif);
- }
-
- 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);
- }
-
- return $data;
+ return get_sync_metadata($infos);
}
@@ -248,34 +185,6 @@ function get_representative_ext($path, $filename_wo_ext)
return null;
}
-function get_tn_ext($path, $filename_wo_ext)
-{
- global $conf;
-
- $base_test =
- $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.';
-
- foreach ($conf['picture_ext'] as $ext)
- {
- $test = $base_test.$ext;
- if (is_file($test))
- {
- return $ext;
- }
- }
-
- return null;
-}
-
-function get_has_high($path, $filename)
-{
- if (is_file($path.'/pwg_high/'.$filename))
- {
- return 'true';
- }
-
- return null;
-}
}
?> \ No newline at end of file
diff --git a/admin/site_update.php b/admin/site_update.php
index 71bc4c7fc..55238cb80 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -80,6 +80,7 @@ $infos = array();
if ($site_is_remote)
{
+ fatal_error('remote sites not supported');
include_once(PHPWG_ROOT_PATH.'admin/site_reader_remote.php');
$local_listing = null;
if ( isset($_GET['local_listing'])
@@ -98,10 +99,6 @@ else
$general_failure = true;
if (isset($_POST['submit']))
{
- if (!isset($conf['flip_picture_ext']))
- {
- $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
- }
if ($site_reader->open())
{
$general_failure = false;
@@ -312,7 +309,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
'visible','status','rank','global_rank'
);
mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
-
+
// add default permissions to categories
$category_ids = array();
foreach ($inserts as $category)
@@ -321,7 +318,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
}
add_permission_on_category($category_ids, get_admins());
}
-
+
$counts['new_categories'] = count($inserts);
}
@@ -373,7 +370,7 @@ SELECT id, path
WHERE storage_category_id IN ('
.wordwrap(
implode(', ', $cat_ids),
- 80,
+ 160,
"\n"
).')';
$db_elements = simple_hash_from_query($query, 'id', 'path');
@@ -410,60 +407,43 @@ SELECT id, path
continue;
}
- if ( isset( $conf['flip_picture_ext'][get_extension($filename)] )
- and !isset($fs[$path]['tn_ext']) )
- { // For a picture thumbnail is mandatory and for non picture element,
- // thumbnail and representative are optionnal
- array_push(
- $errors,
- array(
- 'path' => $path,
- 'type' => 'PWG-UPDATE-2'
- )
- );
- }
- else
- {
- $insert = array(
- 'id' => $next_element_id++,
- 'file' => $filename,
- 'date_available' => CURRENT_DATE,
- 'path' => $path,
- 'tn_ext' => isset($fs[$path]['tn_ext'])
- ? $fs[$path]['tn_ext']
- : null,
- 'storage_category_id' => $db_fulldirs[$dirname],
- 'added_by' => $user['id'],
- );
+ $insert = array(
+ 'id' => $next_element_id++,
+ 'file' => $filename,
+ 'date_available' => CURRENT_DATE,
+ 'path' => $path,
+ 'representative_ext' => $fs[$path]['representative_ext'],
+ 'storage_category_id' => $db_fulldirs[$dirname],
+ 'added_by' => $user['id'],
+ );
- if ( $_POST['privacy_level']!=0 )
- {
- $insert['level'] = $_POST['privacy_level'];
- }
+ if ( $_POST['privacy_level']!=0 )
+ {
+ $insert['level'] = $_POST['privacy_level'];
+ }
- array_push(
- $inserts,
- $insert
- );
+ array_push(
+ $inserts,
+ $insert
+ );
- array_push(
- $insert_links,
- array(
- 'image_id' => $insert['id'],
- 'category_id' => $insert['storage_category_id'],
- )
- );
+ array_push(
+ $insert_links,
+ array(
+ 'image_id' => $insert['id'],
+ 'category_id' => $insert['storage_category_id'],
+ )
+ );
- array_push(
- $infos,
- array(
- 'path' => $insert['path'],
- 'info' => l10n('added')
- )
- );
+ array_push(
+ $infos,
+ array(
+ 'path' => $insert['path'],
+ 'info' => l10n('added')
+ )
+ );
- $caddiables[] = $insert['id'];
- }
+ $caddiables[] = $insert['id'];
}
if (count($inserts) > 0)
@@ -560,26 +540,12 @@ if (isset($_POST['submit'])
$datas = array();
foreach ( $files as $id=>$file )
{
+ $file = $file['path'];
$data = $site_reader->get_element_update_attributes($file);
if ( !is_array($data) )
{
continue;
}
- $extension = get_extension($file);
- if ( isset($conf['flip_picture_ext'][$extension]) )
- {
- if ( !isset($data['tn_ext']) )
- {
- array_push(
- $errors,
- array(
- 'path' => $file,
- 'type' => 'PWG-UPDATE-2'
- )
- );
- continue;
- }
- }
$data['id']=$id;
array_push($datas, $data);
@@ -655,32 +621,9 @@ if (isset($_POST['submit']) and isset($_POST['sync_meta'])
$datas = array();
$tags_of = array();
- $has_high_images = array();
-
- $image_ids = array();
- foreach ($files as $id => $file)
+ foreach ( $files as $id => $element_infos )
{
- array_push($image_ids, $id);
- }
-
- if (count($image_ids) > 0)
- {
- $query = '
-SELECT id
- FROM '.IMAGES_TABLE.'
- WHERE has_high = \'true\'
- AND id IN (
-'.wordwrap(implode(', ', $image_ids), 80, "\n").'
-)';
- $has_high_images = array_from_query($query, 'id' );
- }
-
- foreach ( $files as $id=>$file )
- {
- $data = $site_reader->get_element_metadata(
- $file,
- in_array($id, $has_high_images)
- );
+ $data = $site_reader->get_element_metadata($element_infos);
if ( is_array($data) )
{
@@ -709,7 +652,7 @@ SELECT id
}
else
{
- array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS'));
+ array_push($errors, array('path' => $element_infos['path'], 'type' => 'PWG-ERROR-NO-FS'));
}
}
@@ -817,7 +760,7 @@ else
'meta_all' => false,
'meta_empty_overrides' => false,
);
-
+
$cat_selected = array();
if (isset($_GET['cat_id']))
diff --git a/include/derivative.inc.php b/include/derivative.inc.php
index c22e27573..282b500ec 100644
--- a/include/derivative.inc.php
+++ b/include/derivative.inc.php
@@ -42,10 +42,7 @@ final class SrcImage
}
elseif (!empty($infos['representative_ext']))
{
- $pi = pathinfo($infos['path']);
- $file_wo_ext = get_filename_wo_extension($pi['basename']);
- $this->rel_path = $pi['dirname'].'/pwg_representative/'
- .$file_wo_ext.'.'.$infos['representative_ext'];
+ $this->rel_path = original_to_representative($infos['path'], $infos['representative_ext']);
}
else
{
diff --git a/include/functions.inc.php b/include/functions.inc.php
index afd3ea702..80b25281b 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -731,6 +731,16 @@ function check_theme_installed($theme_id)
return file_exists($conf['themes_dir'].'/'.$theme_id.'/'.'themeconf.inc.php');
}
+/** Transforms an original path to its pwg representative */
+function original_to_representative($path, $representative_ext)
+{
+ $pos = strrpos($path, '/');
+ $path = substr_replace($path, 'pwg_representative/', $pos+1, 0);
+ $pos = strrpos($path, '.');
+ return substr_replace($path, $representative_ext, $pos+1);
+}
+
+
/* Returns the PATH to the thumbnail to be displayed. If the element does not
* have a thumbnail, the default mime image path is returned. The PATH can be
* used in the php script, but not sent to the browser.
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 5839ce9e9..2c14feac4 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -1741,7 +1741,7 @@ SELECT
// update metadata from the uploaded file (exif/iptc)
require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
- update_metadata(array($image_id=>$file_path));
+ sync_metadata(array($image_id));
}
$info_columns = array(
@@ -1925,16 +1925,9 @@ SELECT id, name, permalink
// update metadata from the uploaded file (exif/iptc), even if the sync
// was already performed by add_uploaded_file().
- $query = '
-SELECT
- path
- FROM '.IMAGES_TABLE.'
- WHERE id = '.$image_id.'
-;';
- list($file_path) = pwg_db_fetch_row(pwg_query($query));
require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
- update_metadata(array($image_id=>$file_path));
+ sync_metadata(array($image_id));
return array(
'image_id' => $image_id,
@@ -3328,7 +3321,7 @@ SELECT id, path, tn_ext, has_high, width, height
global $conf;
$conf['use_exif'] = false;
$conf['use_iptc'] = false;
- update_metadata(array($image['id'] => $image['path']));
+ sync_metadata(array($image['id']));
return $result;
}