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