[1612] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[1612] | 23 | |
---|
[25550] | 24 | /** |
---|
| 25 | * @package functions\picture |
---|
| 26 | */ |
---|
[1612] | 27 | |
---|
[25550] | 28 | |
---|
| 29 | /** |
---|
| 30 | * Returns slideshow default params. |
---|
| 31 | * - period |
---|
| 32 | * - repeat |
---|
| 33 | * - play |
---|
[2218] | 34 | * |
---|
[25550] | 35 | * @return array |
---|
[2218] | 36 | */ |
---|
| 37 | function get_default_slideshow_params() |
---|
| 38 | { |
---|
| 39 | global $conf; |
---|
| 40 | |
---|
| 41 | return array( |
---|
| 42 | 'period' => $conf['slideshow_period'], |
---|
| 43 | 'repeat' => $conf['slideshow_repeat'], |
---|
| 44 | 'play' => true, |
---|
| 45 | ); |
---|
| 46 | } |
---|
| 47 | |
---|
[25550] | 48 | /** |
---|
| 49 | * Checks and corrects slideshow params |
---|
[2218] | 50 | * |
---|
[25550] | 51 | * @param array $params |
---|
| 52 | * @return array |
---|
[2218] | 53 | */ |
---|
[25550] | 54 | function correct_slideshow_params($params=array()) |
---|
[2218] | 55 | { |
---|
| 56 | global $conf; |
---|
| 57 | |
---|
| 58 | if ($params['period'] < $conf['slideshow_period_min']) |
---|
| 59 | { |
---|
| 60 | $params['period'] = $conf['slideshow_period_min']; |
---|
| 61 | } |
---|
| 62 | else if ($params['period'] > $conf['slideshow_period_max']) |
---|
| 63 | { |
---|
| 64 | $params['period'] = $conf['slideshow_period_max']; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | return $params; |
---|
| 68 | } |
---|
| 69 | |
---|
[25550] | 70 | /** |
---|
| 71 | * Decodes slideshow string params into array |
---|
[2218] | 72 | * |
---|
[25550] | 73 | * @param string $encode_params |
---|
| 74 | * @return array |
---|
[2218] | 75 | */ |
---|
[25550] | 76 | function decode_slideshow_params($encode_params=null) |
---|
[2218] | 77 | { |
---|
| 78 | global $conf; |
---|
| 79 | |
---|
| 80 | $result = get_default_slideshow_params(); |
---|
| 81 | |
---|
| 82 | if (is_numeric($encode_params)) |
---|
| 83 | { |
---|
| 84 | $result['period'] = $encode_params; |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | $matches = array(); |
---|
| 89 | if (preg_match_all('/([a-z]+)-(\d+)/', $encode_params, $matches)) |
---|
| 90 | { |
---|
| 91 | $matchcount = count($matches[1]); |
---|
| 92 | for ($i = 0; $i < $matchcount; $i++) |
---|
| 93 | { |
---|
| 94 | $result[$matches[1][$i]] = $matches[2][$i]; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if (preg_match_all('/([a-z]+)-(true|false)/', $encode_params, $matches)) |
---|
| 99 | { |
---|
| 100 | $matchcount = count($matches[1]); |
---|
| 101 | for ($i = 0; $i < $matchcount; $i++) |
---|
| 102 | { |
---|
| 103 | $result[$matches[1][$i]] = get_boolean($matches[2][$i]); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | return correct_slideshow_params($result); |
---|
| 109 | } |
---|
| 110 | |
---|
[25550] | 111 | /** |
---|
| 112 | * Encodes slideshow array params into a string |
---|
[2218] | 113 | * |
---|
[25550] | 114 | * @param array $decode_params |
---|
| 115 | * @return string |
---|
[2218] | 116 | */ |
---|
[25550] | 117 | function encode_slideshow_params($decode_params=array()) |
---|
[2218] | 118 | { |
---|
| 119 | global $conf; |
---|
| 120 | |
---|
| 121 | $params = array_diff_assoc(correct_slideshow_params($decode_params), get_default_slideshow_params()); |
---|
| 122 | $result = ''; |
---|
| 123 | |
---|
| 124 | foreach ($params as $name => $value) |
---|
| 125 | { |
---|
| 126 | // boolean_to_string return $value, if it's not a bool |
---|
| 127 | $result .= '+'.$name.'-'.boolean_to_string($value); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | return $result; |
---|
| 131 | } |
---|
[25550] | 132 | |
---|
[12920] | 133 | ?> |
---|