diff options
-rw-r--r-- | action.php | 35 | ||||
-rw-r--r-- | admin/include/functions.php | 35 | ||||
-rw-r--r-- | admin/picture_modify.php | 19 | ||||
-rw-r--r-- | admin/site_reader_local.php | 31 | ||||
-rw-r--r-- | admin/site_update.php | 144 | ||||
-rw-r--r-- | admin/themes/default/template/picture_modify.tpl | 1 | ||||
-rw-r--r-- | include/config_default.inc.php | 7 | ||||
-rw-r--r-- | include/constants.php | 2 | ||||
-rw-r--r-- | include/functions.inc.php | 19 | ||||
-rw-r--r-- | install/db/145-database.php | 44 | ||||
-rw-r--r-- | install/db/146-database.php | 39 | ||||
-rw-r--r-- | install/piwigo_structure-mysql.sql | 13 | ||||
-rw-r--r-- | picture.php | 40 | ||||
-rw-r--r-- | themes/default/template/picture.tpl | 21 | ||||
-rw-r--r-- | themes/default/theme.css | 6 |
15 files changed, 439 insertions, 17 deletions
diff --git a/action.php b/action.php index 4b92e056c..c26df65e5 100644 --- a/action.php +++ b/action.php @@ -57,11 +57,34 @@ function do_error( $code, $str ) exit(); } +if ($conf['enable_formats'] and 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(); @@ -155,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/admin/include/functions.php b/admin/include/functions.php index fbbcd8c55..5ad436b71 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..69f644467 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); } - $fs[ $path.'/'.$node ] = array( - 'representative_ext' => $representative_ext, - ); + + $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) and $node != 'pwg_high' and $node != 'pwg_representative' + and $node != 'pwg_format' and $node != 'thumbnail' ) { $subdirs[] = $node; @@ -182,6 +187,26 @@ 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[$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..2a70ae5d9 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', '<!-- get_elements: ' . get_elapsed_time($start, get_moment()) . ' -->' ); @@ -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,36 +537,158 @@ SELECT id, path 'info' => l10n('added') ); + if ($conf['enable_formats']) + { + 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) + ); + } + } + $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 (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']])) + { + $db_formats[$row['image_id']] = array(); + } + + $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) + { + $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) + ); + } + } + + // 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) + { + $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 + ); + } - // 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/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({ <li>{$INTRO.add_date}</li> <li>{$INTRO.added_by}</li> <li>{$INTRO.size}</li> + <li>{$INTRO.formats}</li> <li>{$INTRO.stats}</li> <li>{$INTRO.id}</li> </ul> diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 60a3da323..eafb9d5a9 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -63,6 +63,13 @@ $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', 'psd'); + // 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..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').' ) ;'; @@ -953,6 +955,21 @@ function original_to_representative($path, $representative_ext) } /** + * 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 * * @param array $element_info element information from db (at least 'path') 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 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2015 Piwigo Team http://piwigo.org | +// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | +// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | +// +-----------------------------------------------------------------------+ +// | 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. | +// +-----------------------------------------------------------------------+ + +if (!defined('PHPWG_ROOT_PATH')) +{ + die('Hacking attempt!'); +} + +$upgrade_description = 'add image formats table'; + +// we use PREFIX_TABLE, in case Piwigo uses an external user table +pwg_query(' +CREATE TABLE `'.PREFIX_TABLE.'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 DEFAULT CHARSET=utf8 +;'); + +echo "\n".$upgrade_description."\n"; + +?> 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 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2015 Piwigo Team http://piwigo.org | +// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | +// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | +// +-----------------------------------------------------------------------+ +// | 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. | +// +-----------------------------------------------------------------------+ + +if (!defined('PHPWG_ROOT_PATH')) +{ + die('Hacking attempt!'); +} + +$upgrade_description = 'add format_id in history table'; + +// we use PREFIX_TABLE, in case Piwigo uses an external user table +pwg_query(' +ALTER TABLE `'.PREFIX_TABLE.'history` + ADD COLUMN `format_id` int(11) unsigned DEFAULT NULL +;'); + +echo "\n".$upgrade_description."\n"; + +?> diff --git a/install/piwigo_structure-mysql.sql b/install/piwigo_structure-mysql.sql index b36844a8f..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; @@ -163,6 +164,18 @@ CREATE TABLE `piwigo_image_category` ( ) 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` -- diff --git a/picture.php b/picture.php index 94c2b3ea3..d993fe3f2 100644 --- a/picture.php +++ b/picture.php @@ -662,6 +662,46 @@ 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); + + if ($conf['enable_formats']) + { + $query = ' +SELECT * + FROM '.IMAGE_FORMAT_TABLE.' + 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'], + ) + ); + + foreach ($formats as &$format) + { + 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); + } + + $template->append('current', array('formats' => $formats), true); + } } diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 733cefcf8..bfc0c2498 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -65,9 +65,28 @@ function changeImgSrc(url,typeSave,typeMap) </a> {/if}{/strip} {strip}{if isset($current.U_DOWNLOAD)} - <a href="{$current.U_DOWNLOAD}" title="{'Download this file'|@translate}" class="pwg-state-default pwg-button" rel="nofollow"> + <a id="downloadSwitchLink" href="{$current.U_DOWNLOAD}" title="{'Download this file'|@translate}" class="pwg-state-default pwg-button" rel="nofollow"> <span class="pwg-icon pwg-icon-save"></span><span class="pwg-button-text">{'Download'|@translate}</span> </a> + +{if !empty($current.formats)} +{footer_script require='jquery'}{literal} +jQuery().ready(function() { + jQuery("#downloadSwitchLink").removeAttr("href"); + + (window.SwitchBox=window.SwitchBox||[]).push("#downloadSwitchLink", "#downloadSwitchBox"); +}); +{/literal}{/footer_script} + +<div id="downloadSwitchBox" class="switchBox"> + <div class="switchBoxTitle">{'Download'|translate} - {'Formats'|translate}</div> + <ul> + {foreach from=$current.formats item=format} + <li><a href="{$format.download_url}" rel="nofollow">{$format.label}<span class="downloadformatDetails"> ({$format.filesize})</span></a></li> + {/foreach} + </ul> +</div> +{/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; } |