From 8e098d502a8f0e413b9c085db27d6a62a6c0909f Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 3 Dec 2015 16:04:02 +0100 Subject: feature #379 multiple format, step 1: add formats * new table piwigo_image_format (each photo can have 0 to many formats) * only compatible with synchronization for now. Formats must be in sub-directory pwg_format * formats are visible on edition page only for now --- admin/include/functions.php | 35 +++++++++++++++++++ admin/picture_modify.php | 19 ++++++++++ admin/site_reader_local.php | 31 +++++++++++++++++ admin/site_update.php | 28 +++++++++++++++ admin/themes/default/template/picture_modify.tpl | 1 + include/config_default.inc.php | 4 +++ include/constants.php | 2 ++ include/functions.inc.php | 15 ++++++++ install/db/145-database.php | 44 ++++++++++++++++++++++++ install/piwigo_structure-mysql.sql | 12 +++++++ 10 files changed, 191 insertions(+) create mode 100644 install/db/145-database.php diff --git a/admin/include/functions.php b/admin/include/functions.php index 5cd44b31d..903267153 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -180,6 +180,25 @@ function delete_element_files($ids) } $new_ids = array(); + $formats_of = array(); + + $query = ' +SELECT + image_id, + ext + FROM '.IMAGE_FORMAT_TABLE.' + WHERE image_id IN ('.implode(',', $ids).') +;'; + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) + { + if (!isset($formats_of[ $row['image_id'] ])) + { + $formats_of[ $row['image_id'] ] = array(); + } + + $formats_of[ $row['image_id'] ][] = $row['ext']; + } $query = ' SELECT @@ -205,6 +224,14 @@ SELECT $files[] = original_to_representative( $files[0], $row['representative_ext']); } + if (isset($formats_of[ $row['id'] ])) + { + foreach ($formats_of[ $row['id'] ] as $format_ext) + { + $files[] = original_to_format($files[0], $format_ext); + } + } + $ok = true; if (!isset($conf['never_delete_originals'])) { @@ -277,6 +304,13 @@ DELETE FROM '.IMAGE_CATEGORY_TABLE.' ;'; pwg_query($query); + // destruction of the formats + $query = ' +DELETE FROM '.IMAGE_FORMAT_TABLE.' + WHERE image_id IN ('. $ids_str .') +;'; + pwg_query($query); + // destruction of the links between images and tags $query = ' DELETE FROM '.IMAGE_TAG_TABLE.' @@ -540,6 +574,7 @@ function get_fs_directories($path, $recursive = true) '.', '..', '.svn', 'thumbnail', 'pwg_high', 'pwg_representative', + 'pwg_format', ) ); $exclude_folders = array_flip($exclude_folders); diff --git a/admin/picture_modify.php b/admin/picture_modify.php index bf0e458e6..cdb7ccbbe 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -306,6 +306,25 @@ SELECT $intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']); } +$query = ' +SELECT * + FROM '.IMAGE_FORMAT_TABLE.' + WHERE image_id = '.$row['id'].' +;'; +$formats = query2array($query); + +if (!empty($formats)) +{ + $format_strings = array(); + + foreach ($formats as $format) + { + $format_strings[] = sprintf('%s (%.2fMB)', $format['ext'], $format['filesize']/1024); + } + + $intro_vars['formats'] = l10n('Formats: %s', implode(', ', $format_strings)); +} + $template->assign('INTRO', $intro_vars); diff --git a/admin/site_reader_local.php b/admin/site_reader_local.php index 7e618ca17..051e574a6 100644 --- a/admin/site_reader_local.php +++ b/admin/site_reader_local.php @@ -100,14 +100,19 @@ function get_elements($path) { $representative_ext = $this->get_representative_ext($path, $filename_wo_ext); } + + $formats = $this->get_formats($path, $filename_wo_ext); + $fs[ $path.'/'.$node ] = array( 'representative_ext' => $representative_ext, + 'formats' => $formats, ); } } else if (is_dir($path.'/'.$node) and $node != 'pwg_high' and $node != 'pwg_representative' + and $node != 'pwg_format' and $node != 'thumbnail' ) { $subdirs[] = $node; @@ -182,6 +187,32 @@ function get_representative_ext($path, $filename_wo_ext) return null; } +function get_formats($path, $filename_wo_ext) +{ + global $conf; + + $formats = array(); + + $base_test = $path.'/pwg_format/'.$filename_wo_ext.'.'; + + foreach ($conf['format_ext'] as $ext) + { + $test = $base_test.$ext; + + if (is_file($test)) + { + // $formats[] = array( + // 'ext' => $ext, + // 'filesize' => floor(filesize($file) / 1024), + // ); + + // we return a "/" splitted string instead of an array with 2 keys, to reduce memory usage + $formats[] = $ext.'/'.floor(filesize($test) / 1024); + } + } + + return $formats; +} } ?> \ No newline at end of file diff --git a/admin/site_update.php b/admin/site_update.php index 5bcaea12a..3a12965af 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -457,6 +457,7 @@ if (isset($_POST['submit']) and $_POST['sync'] == 'files' $start= $start_files; $fs = $site_reader->get_elements($basedir); + $template->append('footer_elements', '' ); @@ -486,6 +487,7 @@ SELECT id, path $inserts = array(); $insert_links = array(); + $insert_formats = array(); foreach (array_diff(array_keys($fs), $db_elements) as $path) { @@ -535,6 +537,22 @@ SELECT id, path 'info' => l10n('added') ); + foreach ($fs[$path]['formats'] as $format) + { + list($ext, $filesize) = explode('/', $format); + + $insert_formats[] = array( + 'image_id' => $insert['id'], + 'ext' => $ext, + 'filesize' => $filesize, + ); + + $infos[] = array( + 'path' => $insert['path'], + 'info' => l10n('format %s added', $ext) + ); + } + $caddiables[] = $insert['id']; } @@ -555,6 +573,16 @@ SELECT id, path array_keys($insert_links[0]), $insert_links ); + + // inserts all formats + if (count($insert_formats) > 0) + { + mass_inserts( + IMAGE_FORMAT_TABLE, + array_keys($insert_formats[0]), + $insert_formats + ); + } // add new photos to caddie if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) diff --git a/admin/themes/default/template/picture_modify.tpl b/admin/themes/default/template/picture_modify.tpl index aeba2dd6f..71b3d2ba4 100644 --- a/admin/themes/default/template/picture_modify.tpl +++ b/admin/themes/default/template/picture_modify.tpl @@ -63,6 +63,7 @@ jQuery("a.preview-box").colorbox({
  • {$INTRO.add_date}
  • {$INTRO.added_by}
  • {$INTRO.size}
  • +
  • {$INTRO.formats}
  • {$INTRO.stats}
  • {$INTRO.id}
  • diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 60a3da323..ec0b58522 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -63,6 +63,10 @@ $conf['file_ext'] = array_merge( array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf') ); +// format_ext : file extensions for formats, ie additional versions of a +// photo (or nay other file). Formats are in sub-directory pwg_format. +$conf['format_ext'] = array('cr2', 'tif', 'tiff', 'nef', 'dng', 'ai'); + // top_number : number of element to display for "best rated" and "most // visited" categories $conf['top_number'] = 15; diff --git a/include/constants.php b/include/constants.php index 83d8747bc..ef321a4bc 100644 --- a/include/constants.php +++ b/include/constants.php @@ -105,5 +105,7 @@ if (!defined('THEMES_TABLE')) define('THEMES_TABLE', $prefixeTable.'themes'); if (!defined('LANGUAGES_TABLE')) define('LANGUAGES_TABLE', $prefixeTable.'languages'); +if (!defined('IMAGE_FORMAT_TABLE')) + define('IMAGE_FORMAT_TABLE', $prefixeTable.'image_format'); ?> diff --git a/include/functions.inc.php b/include/functions.inc.php index 60a1885e5..e1658c31f 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -952,6 +952,21 @@ function original_to_representative($path, $representative_ext) return substr_replace($path, $representative_ext, $pos+1); } +/** + * Transforms an original path to its format + * + * @param string $path + * @param string $format_ext + * @return string + */ +function original_to_format($path, $format_ext) +{ + $pos = strrpos($path, '/'); + $path = substr_replace($path, 'pwg_format/', $pos+1, 0); + $pos = strrpos($path, '.'); + return substr_replace($path, $format_ext, $pos+1); +} + /** * get the full path of an image * diff --git a/install/db/145-database.php b/install/db/145-database.php new file mode 100644 index 000000000..3f43761bf --- /dev/null +++ b/install/db/145-database.php @@ -0,0 +1,44 @@ + diff --git a/install/piwigo_structure-mysql.sql b/install/piwigo_structure-mysql.sql index b36844a8f..a452068a0 100644 --- a/install/piwigo_structure-mysql.sql +++ b/install/piwigo_structure-mysql.sql @@ -162,6 +162,18 @@ CREATE TABLE `piwigo_image_category` ( KEY `image_category_i1` (`category_id`) ) ENGINE=MyISAM; +-- +-- Table structure for table `piwigo_image_format` +-- + +CREATE TABLE `piwigo_image_format` ( + `format_id` int(11) unsigned NOT NULL auto_increment, + `image_id` mediumint(8) unsigned NOT NULL DEFAULT '0', + `ext` varchar(255) NOT NULL, + `filesize` mediumint(9) unsigned DEFAULT NULL, + PRIMARY KEY (`format_id`) +) ENGINE=MyISAM; + -- -- Table structure for table `piwigo_image_tag` -- -- cgit v1.2.3 From c3b748ecbfd1a359f6e95e7fd691ac5c11c3c4de Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 7 Dec 2015 10:54:18 +0100 Subject: feature #379 multiple format, step 2: download formats * if formats are available, replace the download link on picture.php by a switchBox with all formats * register format in the history table for future statistics --- action.php | 33 ++++++++++++++++++++++++++++++- include/functions.inc.php | 4 +++- install/db/146-database.php | 39 +++++++++++++++++++++++++++++++++++++ install/piwigo_structure-mysql.sql | 1 + picture.php | 20 +++++++++++++++++++ themes/default/template/picture.tpl | 32 +++++++++++++++++++++++++++++- themes/default/theme.css | 6 ++++++ 7 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 install/db/146-database.php diff --git a/action.php b/action.php index 4b92e056c..de326e8b6 100644 --- a/action.php +++ b/action.php @@ -57,11 +57,34 @@ function do_error( $code, $str ) exit(); } +if (isset($_GET['format'])) +{ + check_input_parameter('format', $_GET, false, PATTERN_ID); + + $query = ' +SELECT + * + FROM '.IMAGE_FORMAT_TABLE.' + WHERE format_id = '.$_GET['format'].' +;'; + $formats = query2array($query); + + if (count($formats) == 0) + { + do_error(400, 'Invalid request - format'); + } + + $format = $formats[0]; + + $_GET['id'] = $format['image_id']; + $_GET['part'] = 'f'; // "f" for "format" +} + if (!isset($_GET['id']) or !is_numeric($_GET['id']) or !isset($_GET['part']) - or !in_array($_GET['part'], array('e','r') ) ) + or !in_array($_GET['part'], array('e','r','f') ) ) { do_error(400, 'Invalid request - id/part'); } @@ -116,6 +139,10 @@ switch ($_GET['part']) case 'r': $file = original_to_representative( get_element_path($element_info), $element_info['representative_ext'] ); break; + case 'f' : + $file = original_to_format(get_element_path($element_info), $format['ext']); + $element_info['file'] = get_filename_wo_extension($element_info['file']).'.'.$format['ext']; + break; } if ( empty($file) ) @@ -130,6 +157,10 @@ else if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'other'); } +else if ($_GET['part'] == 'f') +{ + pwg_log($_GET['id'], 'high', $format['format_id']); +} $http_headers = array(); diff --git a/include/functions.inc.php b/include/functions.inc.php index e1658c31f..2119abe8f 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -407,7 +407,7 @@ SELECT id, name * @param string $image_type * @return bool */ -function pwg_log($image_id = null, $image_type = null) +function pwg_log($image_id = null, $image_type = null, $format_id = null) { global $conf, $user, $page; @@ -445,6 +445,7 @@ INSERT INTO '.HISTORY_TABLE.' category_id, image_id, image_type, + format_id, tag_ids ) VALUES @@ -457,6 +458,7 @@ INSERT INTO '.HISTORY_TABLE.' '.(isset($page['category']['id']) ? $page['category']['id'] : 'NULL').', '.(isset($image_id) ? $image_id : 'NULL').', '.(isset($image_type) ? "'".$image_type."'" : 'NULL').', + '.(isset($format_id) ? $format_id : 'NULL').', '.(isset($tags_string) ? "'".$tags_string."'" : 'NULL').' ) ;'; diff --git a/install/db/146-database.php b/install/db/146-database.php new file mode 100644 index 000000000..2d168eb52 --- /dev/null +++ b/install/db/146-database.php @@ -0,0 +1,39 @@ + diff --git a/install/piwigo_structure-mysql.sql b/install/piwigo_structure-mysql.sql index a452068a0..24c386abf 100644 --- a/install/piwigo_structure-mysql.sql +++ b/install/piwigo_structure-mysql.sql @@ -131,6 +131,7 @@ CREATE TABLE `piwigo_history` ( `image_id` mediumint(8) default NULL, `summarized` enum('true','false') default 'false', `image_type` enum('picture','high','other') default NULL, + `format_id` int(11) unsigned default NULL, PRIMARY KEY (`id`), KEY `history_i1` (`summarized`) ) ENGINE=MyISAM; diff --git a/picture.php b/picture.php index 94c2b3ea3..a6c6defb7 100644 --- a/picture.php +++ b/picture.php @@ -662,6 +662,26 @@ foreach (array('first','previous','next','last', 'current') as $which_image) if ($conf['picture_download_icon'] and !empty($picture['current']['download_url'])) { $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true); + + $query = ' +SELECT * + FROM '.IMAGE_FORMAT_TABLE.' + WHERE image_id = '.$picture['current']['id'].' +;'; + $formats = query2array($query); + + if (!empty($formats)) + { + foreach ($formats as &$format) + { + $format['download_url'] = 'action.php?format='.$format['format_id']; + $format['download_url'].= '&download='.substr(md5(time()), 0, 6); // a random string to avoid browser cache + + $format['filesize'] = sprintf('%.1fMB', $format['filesize']/1024); + } + } + + $template->append('current', array('formats' => $formats), true); } diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 733cefcf8..331de8384 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -65,9 +65,39 @@ function changeImgSrc(url,typeSave,typeMap) {/if}{/strip} {strip}{if isset($current.U_DOWNLOAD)} - + {'Download'|@translate} + +{if !empty($current.formats)} +{footer_script require='jquery'}{literal} +jQuery().ready(function() { + jQuery("#downloadSwitchLink").click(function() { + var elt = jQuery("#downloadSwitchBox"); + + elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) + .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true)) + .toggle(); + + return false; + }); + + jQuery("#downloadSwitchBox").on("mouseleave click", function() { + jQuery(this).hide(); + }); +}); +{/literal}{/footer_script} + +
    +
    {'Download'|translate} - {'Formats'|translate}
    + +
    +{/if} {* has formats *} {/if}{/strip} {if isset($PLUGIN_PICTURE_BUTTONS)}{foreach from=$PLUGIN_PICTURE_BUTTONS item=button}{$button}{/foreach}{/if} {if isset($PLUGIN_PICTURE_ACTIONS)}{$PLUGIN_PICTURE_ACTIONS}{/if} diff --git a/themes/default/theme.css b/themes/default/theme.css index 3a68f1577..5a438be9c 100644 --- a/themes/default/theme.css +++ b/themes/default/theme.css @@ -363,6 +363,12 @@ TD.calDayCellFull, TD.calDayCellEmpty { margin-bottom:5px; } +#downloadSwitchBox ul { + margin:0; + padding:0; + list-style-type:none; +} + #theImage { text-align: center; } -- cgit v1.2.3 From ca238de66d4b6801c4cd817c27effcf18a211da2 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 16 Dec 2015 18:16:16 +0100 Subject: feature #379 multiple format, step 3: add/remove * during sync, Piwigo will detect new/removed formats for an existing photo * multiple formats features is disabled by default --- admin/site_reader_local.php | 20 ++---- admin/site_update.php | 145 ++++++++++++++++++++++++++++++++--------- include/config_default.inc.php | 3 + 3 files changed, 124 insertions(+), 44 deletions(-) diff --git a/admin/site_reader_local.php b/admin/site_reader_local.php index 051e574a6..69f644467 100644 --- a/admin/site_reader_local.php +++ b/admin/site_reader_local.php @@ -101,12 +101,12 @@ function get_elements($path) $representative_ext = $this->get_representative_ext($path, $filename_wo_ext); } - $formats = $this->get_formats($path, $filename_wo_ext); - - $fs[ $path.'/'.$node ] = array( - 'representative_ext' => $representative_ext, - 'formats' => $formats, - ); + $fs[ $path.'/'.$node ] = array('representative_ext' => $representative_ext); + + if ($conf['enable_formats']) + { + $fs[ $path.'/'.$node ]['formats'] = $this->get_formats($path, $filename_wo_ext); + } } } else if (is_dir($path.'/'.$node) @@ -201,13 +201,7 @@ function get_formats($path, $filename_wo_ext) if (is_file($test)) { - // $formats[] = array( - // 'ext' => $ext, - // 'filesize' => floor(filesize($file) / 1024), - // ); - - // we return a "/" splitted string instead of an array with 2 keys, to reduce memory usage - $formats[] = $ext.'/'.floor(filesize($test) / 1024); + $formats[$ext] = floor(filesize($test) / 1024); } } diff --git a/admin/site_update.php b/admin/site_update.php index 3a12965af..ae77960ae 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -537,62 +537,145 @@ SELECT id, path 'info' => l10n('added') ); - foreach ($fs[$path]['formats'] as $format) + if ($conf['enable_formats']) { - list($ext, $filesize) = explode('/', $format); - - $insert_formats[] = array( - 'image_id' => $insert['id'], - 'ext' => $ext, - 'filesize' => $filesize, - ); + foreach ($fs[$path]['formats'] as $ext => $filesize) + { + $insert_formats[] = array( + 'image_id' => $insert['id'], + 'ext' => $ext, + 'filesize' => $filesize, + ); - $infos[] = array( - 'path' => $insert['path'], - 'info' => l10n('format %s added', $ext) - ); + $infos[] = array( + 'path' => $insert['path'], + 'info' => l10n('format %s added', $ext) + ); + } } $caddiables[] = $insert['id']; } - if (count($inserts) > 0) + // search new/removed formats on photos already registered in database + if ($conf['enable_formats']) { - if (!$simulate) + $db_elements_flip = array_flip($db_elements); + + $existing_ids = array(); + + foreach (array_intersect_key($fs, $db_elements_flip) as $path => $existing) + { + $existing_ids[] = $db_elements_flip[$path]; + } + + $logger->debug('existing_ids', 'sync', $existing_ids); + + if (count($existing_ids) > 0) + { + $db_formats = array(); + + // find formats for existing photos + $query = ' +SELECT * + FROM '.IMAGE_FORMAT_TABLE.' + WHERE image_id IN ('.implode(',', $existing_ids).') +;'; + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) + { + if (!isset($db_formats[$row['image_id']])) + { + $db_formats[$row['image_id']] = array(); + } + + $db_formats[$row['image_id']][$row['ext']] = $row['format_id']; + } + + $formats_to_delete = array(); + + foreach ($db_formats as $image_id => $formats) + { + $image_formats_to_delete = array_diff_key($formats, $fs[ $db_elements[$image_id] ]['formats']); + $logger->debug('image_formats_to_delete', 'sync', $image_formats_to_delete); + foreach ($image_formats_to_delete as $ext => $format_id) + { + $formats_to_delete[] = $format_id; + + $infos[] = array( + 'path' => $db_elements[$image_id], + 'info' => l10n('format %s removed', $ext) + ); + } + + $image_formats_to_insert = array_diff_key($fs[ $db_elements[$image_id] ]['formats'], $formats); + $logger->debug('image_formats_to_insert', 'sync', $image_formats_to_insert); + foreach ($image_formats_to_insert as $ext => $filesize) + { + $insert_formats[] = array( + 'image_id' => $image_id, + 'ext' => $ext, + 'filesize' => $filesize, + ); + + $infos[] = array( + 'path' => $db_elements[$image_id], + 'info' => l10n('format %s added', $ext) + ); + } + } + } + } + + + if (!$simulate) + { + // inserts all new elements + if (count($inserts) > 0) { - // inserts all new elements mass_inserts( IMAGES_TABLE, array_keys($inserts[0]), $inserts ); - + // inserts all links between new elements and their storage category mass_inserts( IMAGE_CATEGORY_TABLE, array_keys($insert_links[0]), $insert_links ); + } - // inserts all formats - if (count($insert_formats) > 0) - { - mass_inserts( - IMAGE_FORMAT_TABLE, - array_keys($insert_formats[0]), - $insert_formats - ); - } + // inserts all formats + if (count($insert_formats) > 0) + { + mass_inserts( + IMAGE_FORMAT_TABLE, + array_keys($insert_formats[0]), + $insert_formats + ); + } - // add new photos to caddie - if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) - { - fill_caddie($caddiables); - } + if (count($formats_to_delete) > 0) + { + $query = ' +DELETE + FROM '.IMAGE_FORMAT_TABLE.' + WHERE format_id IN ('.implode(',', $formats_to_delete).') +;'; + pwg_query($query); + } + + // add new photos to caddie + if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) + { + fill_caddie($caddiables); } - $counts['new_elements'] = count($inserts); } + $counts['new_elements'] = count($inserts); + // delete elements that are in database but not in the filesystem $to_delete_elements = array(); foreach (array_diff($db_elements, array_keys($fs)) as $path) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index ec0b58522..dc8a47183 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -63,6 +63,9 @@ $conf['file_ext'] = array_merge( array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf') ); +// enable_formats: should Piwigo search for multiple formats? +$conf['enable_formats'] = false; + // format_ext : file extensions for formats, ie additional versions of a // photo (or nay other file). Formats are in sub-directory pwg_format. $conf['format_ext'] = array('cr2', 'tif', 'tiff', 'nef', 'dng', 'ai'); -- cgit v1.2.3 From f66c27b731e5b6ed4d8c58fd89cf2156ebeef75a Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 17 Dec 2015 14:00:17 +0100 Subject: indentation --- admin/site_update.php | 80 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/admin/site_update.php b/admin/site_update.php index ae77960ae..411a527c9 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -571,61 +571,61 @@ SELECT id, path $logger->debug('existing_ids', 'sync', $existing_ids); - if (count($existing_ids) > 0) - { - $db_formats = array(); + if (count($existing_ids) > 0) + { + $db_formats = array(); - // find formats for existing photos - $query = ' + // find formats for existing photos (already in database) + $query = ' SELECT * FROM '.IMAGE_FORMAT_TABLE.' WHERE image_id IN ('.implode(',', $existing_ids).') ;'; - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - if (!isset($db_formats[$row['image_id']])) + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) { - $db_formats[$row['image_id']] = array(); + if (!isset($db_formats[$row['image_id']])) + { + $db_formats[$row['image_id']] = array(); + } + + $db_formats[$row['image_id']][$row['ext']] = $row['format_id']; } - $db_formats[$row['image_id']][$row['ext']] = $row['format_id']; - } - - $formats_to_delete = array(); + $formats_to_delete = array(); - foreach ($db_formats as $image_id => $formats) - { - $image_formats_to_delete = array_diff_key($formats, $fs[ $db_elements[$image_id] ]['formats']); - $logger->debug('image_formats_to_delete', 'sync', $image_formats_to_delete); - foreach ($image_formats_to_delete as $ext => $format_id) + foreach ($db_formats as $image_id => $formats) { - $formats_to_delete[] = $format_id; - - $infos[] = array( - 'path' => $db_elements[$image_id], - 'info' => l10n('format %s removed', $ext) - ); - } + $image_formats_to_delete = array_diff_key($formats, $fs[ $db_elements[$image_id] ]['formats']); + $logger->debug('image_formats_to_delete', 'sync', $image_formats_to_delete); + foreach ($image_formats_to_delete as $ext => $format_id) + { + $formats_to_delete[] = $format_id; + + $infos[] = array( + 'path' => $db_elements[$image_id], + 'info' => l10n('format %s removed', $ext) + ); + } - $image_formats_to_insert = array_diff_key($fs[ $db_elements[$image_id] ]['formats'], $formats); - $logger->debug('image_formats_to_insert', 'sync', $image_formats_to_insert); - foreach ($image_formats_to_insert as $ext => $filesize) - { - $insert_formats[] = array( - 'image_id' => $image_id, - 'ext' => $ext, - 'filesize' => $filesize, - ); + $image_formats_to_insert = array_diff_key($fs[ $db_elements[$image_id] ]['formats'], $formats); + $logger->debug('image_formats_to_insert', 'sync', $image_formats_to_insert); + foreach ($image_formats_to_insert as $ext => $filesize) + { + $insert_formats[] = array( + 'image_id' => $image_id, + 'ext' => $ext, + 'filesize' => $filesize, + ); - $infos[] = array( - 'path' => $db_elements[$image_id], - 'info' => l10n('format %s added', $ext) - ); + $infos[] = array( + 'path' => $db_elements[$image_id], + 'info' => l10n('format %s added', $ext) + ); + } } } } - } if (!$simulate) -- cgit v1.2.3 From b1b91992581b769fba5dae51aa5fb17b155516ba Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 17 Dec 2015 14:06:04 +0100 Subject: feature #379, multiple format, hide url on download link --- themes/default/template/picture.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 331de8384..c576748fb 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -72,6 +72,8 @@ function changeImgSrc(url,typeSave,typeMap) {if !empty($current.formats)} {footer_script require='jquery'}{literal} jQuery().ready(function() { + jQuery("#downloadSwitchLink").removeAttr("href"); + jQuery("#downloadSwitchLink").click(function() { var elt = jQuery("#downloadSwitchBox"); -- cgit v1.2.3 From 0f8d85491f656440e7cc66ecca70f7af8dff0022 Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 17 Dec 2015 14:08:53 +0100 Subject: feature #379, multiple format, hide formats when disabled --- action.php | 2 +- picture.php | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/action.php b/action.php index de326e8b6..6bdb3bf11 100644 --- a/action.php +++ b/action.php @@ -57,7 +57,7 @@ function do_error( $code, $str ) exit(); } -if (isset($_GET['format'])) +if ($conf['enable_formats'] and isset($_GET['format'])) { check_input_parameter('format', $_GET, false, PATTERN_ID); diff --git a/picture.php b/picture.php index a6c6defb7..f2dfecf0e 100644 --- a/picture.php +++ b/picture.php @@ -663,25 +663,28 @@ if ($conf['picture_download_icon'] and !empty($picture['current']['download_url' { $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true); - $query = ' + if ($conf['enable_formats']) + { + $query = ' SELECT * FROM '.IMAGE_FORMAT_TABLE.' WHERE image_id = '.$picture['current']['id'].' ;'; - $formats = query2array($query); + $formats = query2array($query); - if (!empty($formats)) - { - foreach ($formats as &$format) + if (!empty($formats)) { - $format['download_url'] = 'action.php?format='.$format['format_id']; - $format['download_url'].= '&download='.substr(md5(time()), 0, 6); // a random string to avoid browser cache - - $format['filesize'] = sprintf('%.1fMB', $format['filesize']/1024); + foreach ($formats as &$format) + { + $format['download_url'] = 'action.php?format='.$format['format_id']; + $format['download_url'].= '&download='.substr(md5(time()), 0, 6); // a random string to avoid browser cache + + $format['filesize'] = sprintf('%.1fMB', $format['filesize']/1024); + } } - } - $template->append('current', array('formats' => $formats), true); + $template->append('current', array('formats' => $formats), true); + } } -- cgit v1.2.3 From 89bc74b3f30e169ab51e5b2728767f02a94a991c Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 20 Dec 2015 15:44:01 +0100 Subject: feature #379, multiple format, labels Ability to customize, with $lang['format CR2'] = 'RAW Canon' (in LocalFiles Editor) for example --- picture.php | 7 +++++++ themes/default/template/picture.tpl | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/picture.php b/picture.php index f2dfecf0e..093e4b271 100644 --- a/picture.php +++ b/picture.php @@ -679,6 +679,13 @@ SELECT * $format['download_url'] = 'action.php?format='.$format['format_id']; $format['download_url'].= '&download='.substr(md5(time()), 0, 6); // a random string to avoid browser cache + $format['label'] = strtoupper($format['ext']); + $lang_key = 'format '.strtoupper($format['ext']); + if (isset($lang[$lang_key])) + { + $format['label'] = $lang[$lang_key]; + } + $format['filesize'] = sprintf('%.1fMB', $format['filesize']/1024); } } diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index c576748fb..f18fdd615 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -95,7 +95,7 @@ jQuery().ready(function() { -- cgit v1.2.3 From 11f37b24b48ed9307ecdb2ac19f5809876d9227a Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 20 Dec 2015 17:49:12 +0100 Subject: feature #379, multiple format, no browser cache No need random string in URL to avoid browser cache, coding tip by @modus75 --- action.php | 2 +- picture.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.php b/action.php index 6bdb3bf11..c26df65e5 100644 --- a/action.php +++ b/action.php @@ -186,7 +186,7 @@ if (!url_is_remote($file)) // HTTP/1.1 only $http_headers[] = 'Cache-Control: private, must-revalidate, max-age='.$max_age;*/ - if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) + if ('f' != $_GET['part'] and isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { set_status_header(304); foreach ($http_headers as $header) diff --git a/picture.php b/picture.php index 093e4b271..75b7cdaf2 100644 --- a/picture.php +++ b/picture.php @@ -677,7 +677,7 @@ SELECT * foreach ($formats as &$format) { $format['download_url'] = 'action.php?format='.$format['format_id']; - $format['download_url'].= '&download='.substr(md5(time()), 0, 6); // a random string to avoid browser cache + $format['download_url'].= '&download'; $format['label'] = strtoupper($format['ext']); $lang_key = 'format '.strtoupper($format['ext']); -- cgit v1.2.3 From e7183e91d9c7fd84ae21a7f59926824ec6c78d9e Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 20 Dec 2015 20:38:30 +0100 Subject: use window.SwitchBox instead of duplicating code --- themes/default/template/picture.tpl | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index f18fdd615..3cccf6b29 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -74,19 +74,7 @@ function changeImgSrc(url,typeSave,typeMap) jQuery().ready(function() { jQuery("#downloadSwitchLink").removeAttr("href"); - jQuery("#downloadSwitchLink").click(function() { - var elt = jQuery("#downloadSwitchBox"); - - elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) - .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true)) - .toggle(); - - return false; - }); - - jQuery("#downloadSwitchBox").on("mouseleave click", function() { - jQuery(this).hide(); - }); + (window.SwitchBox=window.SwitchBox||[]).push("#downloadSwitchLink", "#downloadSwitchBox"); }); {/literal}{/footer_script} -- cgit v1.2.3 From 6e2a4495bfa576fc1c08ed1ec586d6eb4a4ad5d8 Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 20 Dec 2015 21:00:28 +0100 Subject: feature #379, multiple format, add psd file extension by default --- include/config_default.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index dc8a47183..eafb9d5a9 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -68,7 +68,7 @@ $conf['enable_formats'] = false; // format_ext : file extensions for formats, ie additional versions of a // photo (or nay other file). Formats are in sub-directory pwg_format. -$conf['format_ext'] = array('cr2', 'tif', 'tiff', 'nef', 'dng', 'ai'); +$conf['format_ext'] = array('cr2', 'tif', 'tiff', 'nef', 'dng', 'ai', 'psd'); // top_number : number of element to display for "best rated" and "most // visited" categories -- cgit v1.2.3 From e439de1612eb471571c5a1503fba7f6531a90c08 Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 22 Dec 2015 19:04:00 +0100 Subject: feature #379, multiple format, consider the original as a format --- picture.php | 17 +++++++++++++++-- themes/default/template/picture.tpl | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/picture.php b/picture.php index 75b7cdaf2..d88e6e262 100644 --- a/picture.php +++ b/picture.php @@ -674,10 +674,23 @@ SELECT * if (!empty($formats)) { + // let's add the original as a format among others. It will just have + // a specific download URL + array_unshift( + $formats, + array( + 'download_url' => $picture['current']['download_url'], + 'ext' => get_extension($picture['current']['file']), + 'filesize' => $picture['current']['filesize'], + ) + ); + foreach ($formats as &$format) { - $format['download_url'] = 'action.php?format='.$format['format_id']; - $format['download_url'].= '&download'; + if (!isset($format['download_url'])) + { + $format['download_url'] = 'action.php?format='.$format['format_id'].'&download'; + } $format['label'] = strtoupper($format['ext']); $lang_key = 'format '.strtoupper($format['ext']); diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 3cccf6b29..bfc0c2498 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -81,7 +81,6 @@ jQuery().ready(function() {
    {'Download'|translate} - {'Formats'|translate}
      -
    • {'Original'|@translate}
    • {foreach from=$current.formats item=format}
    • {$format.label} ({$format.filesize})
    • {/foreach} -- cgit v1.2.3 From 99b1fd270445c719d85aacc9e3a8e7add1cd5106 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 23 Dec 2015 10:10:34 +0100 Subject: feature #379, multiple format, bug fixed on sync New formats were not detected if the photo had not already at least one format. --- admin/site_update.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/admin/site_update.php b/admin/site_update.php index 411a527c9..2a70ae5d9 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -592,6 +592,7 @@ SELECT * $db_formats[$row['image_id']][$row['ext']] = $row['format_id']; } + // first we search the formats that were removed $formats_to_delete = array(); foreach ($db_formats as $image_id => $formats) @@ -607,8 +608,20 @@ SELECT * 'info' => l10n('format %s removed', $ext) ); } + } - $image_formats_to_insert = array_diff_key($fs[ $db_elements[$image_id] ]['formats'], $formats); + // then we search for new formats on existing photos + foreach ($existing_ids as $image_id) + { + $path = $db_elements[$image_id]; + + $formats = array(); + if (isset($db_formats[$image_id])) + { + $formats = $db_formats[$image_id]; + } + + $image_formats_to_insert = array_diff_key($fs[$path]['formats'], $formats); $logger->debug('image_formats_to_insert', 'sync', $image_formats_to_insert); foreach ($image_formats_to_insert as $ext => $filesize) { -- cgit v1.2.3 From 7b653c04d6cfb20366c3bb0e183a521b3c9d22d2 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 30 Dec 2015 16:04:32 +0100 Subject: feature #379, multiple format, download original as format If multiple format feature is enabled, always put the original file in the formats list. --- picture.php | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/picture.php b/picture.php index d88e6e262..d993fe3f2 100644 --- a/picture.php +++ b/picture.php @@ -671,36 +671,33 @@ SELECT * WHERE image_id = '.$picture['current']['id'].' ;'; $formats = query2array($query); + + // let's add the original as a format among others. It will just have a + // specific download URL + array_unshift( + $formats, + array( + 'download_url' => $picture['current']['download_url'], + 'ext' => get_extension($picture['current']['file']), + 'filesize' => $picture['current']['filesize'], + ) + ); - if (!empty($formats)) + foreach ($formats as &$format) { - // let's add the original as a format among others. It will just have - // a specific download URL - array_unshift( - $formats, - array( - 'download_url' => $picture['current']['download_url'], - 'ext' => get_extension($picture['current']['file']), - 'filesize' => $picture['current']['filesize'], - ) - ); + if (!isset($format['download_url'])) + { + $format['download_url'] = 'action.php?format='.$format['format_id'].'&download'; + } - foreach ($formats as &$format) + $format['label'] = strtoupper($format['ext']); + $lang_key = 'format '.strtoupper($format['ext']); + if (isset($lang[$lang_key])) { - if (!isset($format['download_url'])) - { - $format['download_url'] = 'action.php?format='.$format['format_id'].'&download'; - } - - $format['label'] = strtoupper($format['ext']); - $lang_key = 'format '.strtoupper($format['ext']); - if (isset($lang[$lang_key])) - { - $format['label'] = $lang[$lang_key]; - } - - $format['filesize'] = sprintf('%.1fMB', $format['filesize']/1024); + $format['label'] = $lang[$lang_key]; } + + $format['filesize'] = sprintf('%.1fMB', $format['filesize']/1024); } $template->append('current', array('formats' => $formats), true); -- cgit v1.2.3