2006-11-17 04:26:10 +00:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2019-06-04 17:13:51 +02:00
|
|
|
// | This file is part of Piwigo. |
|
2008-04-04 22:57:23 +00:00
|
|
|
// | |
|
2019-06-04 17:13:51 +02:00
|
|
|
// | For copyright and license information, please view the COPYING.txt |
|
|
|
|
// | file that was distributed with this source code. |
|
2006-11-17 04:26:10 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
2013-11-18 17:36:35 +00:00
|
|
|
/**
|
|
|
|
* @package functions\picture
|
|
|
|
*/
|
2006-11-17 04:26:10 +00:00
|
|
|
|
2013-11-18 17:36:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns slideshow default params.
|
|
|
|
* - period
|
|
|
|
* - repeat
|
|
|
|
* - play
|
2008-02-27 20:25:18 +00:00
|
|
|
*
|
2013-11-18 17:36:35 +00:00
|
|
|
* @return array
|
2008-02-27 20:25:18 +00:00
|
|
|
*/
|
|
|
|
function get_default_slideshow_params()
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'period' => $conf['slideshow_period'],
|
|
|
|
'repeat' => $conf['slideshow_repeat'],
|
|
|
|
'play' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:36:35 +00:00
|
|
|
/**
|
|
|
|
* Checks and corrects slideshow params
|
2008-02-27 20:25:18 +00:00
|
|
|
*
|
2013-11-18 17:36:35 +00:00
|
|
|
* @param array $params
|
|
|
|
* @return array
|
2008-02-27 20:25:18 +00:00
|
|
|
*/
|
2013-11-18 17:36:35 +00:00
|
|
|
function correct_slideshow_params($params=array())
|
2008-02-27 20:25:18 +00:00
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
if ($params['period'] < $conf['slideshow_period_min'])
|
|
|
|
{
|
|
|
|
$params['period'] = $conf['slideshow_period_min'];
|
|
|
|
}
|
|
|
|
else if ($params['period'] > $conf['slideshow_period_max'])
|
|
|
|
{
|
|
|
|
$params['period'] = $conf['slideshow_period_max'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:36:35 +00:00
|
|
|
/**
|
|
|
|
* Decodes slideshow string params into array
|
2008-02-27 20:25:18 +00:00
|
|
|
*
|
2013-11-18 17:36:35 +00:00
|
|
|
* @param string $encode_params
|
|
|
|
* @return array
|
2008-02-27 20:25:18 +00:00
|
|
|
*/
|
2013-11-18 17:36:35 +00:00
|
|
|
function decode_slideshow_params($encode_params=null)
|
2008-02-27 20:25:18 +00:00
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$result = get_default_slideshow_params();
|
|
|
|
|
|
|
|
if (is_numeric($encode_params))
|
|
|
|
{
|
|
|
|
$result['period'] = $encode_params;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$matches = array();
|
|
|
|
if (preg_match_all('/([a-z]+)-(\d+)/', $encode_params, $matches))
|
|
|
|
{
|
|
|
|
$matchcount = count($matches[1]);
|
|
|
|
for ($i = 0; $i < $matchcount; $i++)
|
|
|
|
{
|
|
|
|
$result[$matches[1][$i]] = $matches[2][$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match_all('/([a-z]+)-(true|false)/', $encode_params, $matches))
|
|
|
|
{
|
|
|
|
$matchcount = count($matches[1]);
|
|
|
|
for ($i = 0; $i < $matchcount; $i++)
|
|
|
|
{
|
|
|
|
$result[$matches[1][$i]] = get_boolean($matches[2][$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return correct_slideshow_params($result);
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:36:35 +00:00
|
|
|
/**
|
|
|
|
* Encodes slideshow array params into a string
|
2008-02-27 20:25:18 +00:00
|
|
|
*
|
2013-11-18 17:36:35 +00:00
|
|
|
* @param array $decode_params
|
|
|
|
* @return string
|
2008-02-27 20:25:18 +00:00
|
|
|
*/
|
2013-11-18 17:36:35 +00:00
|
|
|
function encode_slideshow_params($decode_params=array())
|
2008-02-27 20:25:18 +00:00
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$params = array_diff_assoc(correct_slideshow_params($decode_params), get_default_slideshow_params());
|
|
|
|
$result = '';
|
|
|
|
|
|
|
|
foreach ($params as $name => $value)
|
|
|
|
{
|
|
|
|
// boolean_to_string return $value, if it's not a bool
|
|
|
|
$result .= '+'.$name.'-'.boolean_to_string($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2013-11-18 17:36:35 +00:00
|
|
|
|
2023-07-10 14:49:36 +02:00
|
|
|
/**
|
|
|
|
* Increase the number of visits for a given photo.
|
|
|
|
*
|
|
|
|
* Code moved from picture.php to be used by both the API and picture.php
|
|
|
|
*
|
|
|
|
* @since 14
|
|
|
|
* @param int $image_id
|
|
|
|
*/
|
|
|
|
function increase_image_visit_counter($image_id)
|
|
|
|
{
|
|
|
|
// avoiding auto update of "lastmodified" field
|
|
|
|
$query = '
|
|
|
|
UPDATE
|
|
|
|
'.IMAGES_TABLE.'
|
|
|
|
SET hit = hit+1, lastmodified = lastmodified
|
|
|
|
WHERE id = '.$image_id.'
|
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
}
|
|
|
|
|
2024-06-20 11:51:55 +02:00
|
|
|
/**
|
|
|
|
* Returns the number of pages of a PDF file
|
|
|
|
*
|
|
|
|
* @param string $pdfPath
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function count_pdf_pages($pdfPath)
|
|
|
|
{
|
|
|
|
$pdftext = file_get_contents($pdfPath);
|
|
|
|
$num = preg_match_all("/\/Page\W/", $pdftext, $dummy);
|
|
|
|
|
|
|
|
return $num;
|
|
|
|
}
|
|
|
|
|
2012-01-17 21:58:18 +00:00
|
|
|
?>
|