From bf4012291a878c3f22fa318595e2ca7881c2978a Mon Sep 17 00:00:00 2001 From: rub Date: Wed, 27 Feb 2008 20:25:18 +0000 Subject: Resolved issue 0000807: New slideshow features git-svn-id: http://piwigo.org/svn/trunk@2218 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_picture.inc.php | 108 +++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) (limited to 'include/functions_picture.inc.php') diff --git a/include/functions_picture.inc.php b/include/functions_picture.inc.php index d11574b57..13a09834d 100644 --- a/include/functions_picture.inc.php +++ b/include/functions_picture.inc.php @@ -1,7 +1,7 @@ $conf['slideshow_period'], + 'repeat' => $conf['slideshow_repeat'], + 'play' => true, + ); +} + +/* + * check and correct slideshow params from array + * + * @param array of params + * + * @return slideshow corrected values into array + */ +function correct_slideshow_params($params = array()) +{ + 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; +} + +/* + * Decode slideshow string params into array + * + * @param string params like "" + * + * @return slideshow values into array + */ +function decode_slideshow_params($encode_params = null) +{ + 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); +} + +/* + * Encode slideshow array params into array + * + * @param array params + * + * @return slideshow values into string + */ +function encode_slideshow_params($decode_params = array()) +{ + 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; +} + ?> -- cgit v1.2.3