aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--action.php33
-rw-r--r--include/functions.inc.php4
-rw-r--r--install/db/146-database.php39
-rw-r--r--install/piwigo_structure-mysql.sql1
-rw-r--r--picture.php20
-rw-r--r--themes/default/template/picture.tpl32
-rw-r--r--themes/default/theme.css6
7 files changed, 132 insertions, 3 deletions
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 @@
+<?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 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'].= '&amp;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)
</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").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}
+
+<div id="downloadSwitchBox" class="switchBox">
+ <div class="switchBoxTitle">{'Download'|translate} - {'Formats'|translate}</div>
+ <ul>
+ <li><a href="{$current.U_DOWNLOAD}" rel="nofollow">{'Original'|@translate}</a></li>
+ {foreach from=$current.formats item=format}
+ <li><a href="{$format.download_url}" rel="nofollow">{$format.ext|upper}<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;
}