[1612] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12920] | 5 | // | Copyright(C) 2008-2012 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 | |
---|
| 24 | |
---|
[9366] | 25 | /* |
---|
[2218] | 26 | * get slideshow default params into array |
---|
| 27 | * |
---|
| 28 | * @param void |
---|
| 29 | * |
---|
| 30 | * @return slideshow default values into array |
---|
| 31 | */ |
---|
| 32 | function get_default_slideshow_params() |
---|
| 33 | { |
---|
| 34 | global $conf; |
---|
| 35 | |
---|
| 36 | return array( |
---|
| 37 | 'period' => $conf['slideshow_period'], |
---|
| 38 | 'repeat' => $conf['slideshow_repeat'], |
---|
| 39 | 'play' => true, |
---|
| 40 | ); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * check and correct slideshow params from array |
---|
| 45 | * |
---|
| 46 | * @param array of params |
---|
| 47 | * |
---|
| 48 | * @return slideshow corrected values into array |
---|
| 49 | */ |
---|
| 50 | function correct_slideshow_params($params = array()) |
---|
| 51 | { |
---|
| 52 | global $conf; |
---|
| 53 | |
---|
| 54 | if ($params['period'] < $conf['slideshow_period_min']) |
---|
| 55 | { |
---|
| 56 | $params['period'] = $conf['slideshow_period_min']; |
---|
| 57 | } |
---|
| 58 | else if ($params['period'] > $conf['slideshow_period_max']) |
---|
| 59 | { |
---|
| 60 | $params['period'] = $conf['slideshow_period_max']; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | return $params; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /* |
---|
| 67 | * Decode slideshow string params into array |
---|
| 68 | * |
---|
| 69 | * @param string params like "" |
---|
| 70 | * |
---|
| 71 | * @return slideshow values into array |
---|
| 72 | */ |
---|
| 73 | function decode_slideshow_params($encode_params = null) |
---|
| 74 | { |
---|
| 75 | global $conf; |
---|
| 76 | |
---|
| 77 | $result = get_default_slideshow_params(); |
---|
| 78 | |
---|
| 79 | if (is_numeric($encode_params)) |
---|
| 80 | { |
---|
| 81 | $result['period'] = $encode_params; |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | $matches = array(); |
---|
| 86 | if (preg_match_all('/([a-z]+)-(\d+)/', $encode_params, $matches)) |
---|
| 87 | { |
---|
| 88 | $matchcount = count($matches[1]); |
---|
| 89 | for ($i = 0; $i < $matchcount; $i++) |
---|
| 90 | { |
---|
| 91 | $result[$matches[1][$i]] = $matches[2][$i]; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | if (preg_match_all('/([a-z]+)-(true|false)/', $encode_params, $matches)) |
---|
| 96 | { |
---|
| 97 | $matchcount = count($matches[1]); |
---|
| 98 | for ($i = 0; $i < $matchcount; $i++) |
---|
| 99 | { |
---|
| 100 | $result[$matches[1][$i]] = get_boolean($matches[2][$i]); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | return correct_slideshow_params($result); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | /* |
---|
| 109 | * Encode slideshow array params into array |
---|
| 110 | * |
---|
| 111 | * @param array params |
---|
| 112 | * |
---|
| 113 | * @return slideshow values into string |
---|
| 114 | */ |
---|
| 115 | function encode_slideshow_params($decode_params = array()) |
---|
| 116 | { |
---|
| 117 | global $conf; |
---|
| 118 | |
---|
| 119 | $params = array_diff_assoc(correct_slideshow_params($decode_params), get_default_slideshow_params()); |
---|
| 120 | $result = ''; |
---|
| 121 | |
---|
| 122 | foreach ($params as $name => $value) |
---|
| 123 | { |
---|
| 124 | // boolean_to_string return $value, if it's not a bool |
---|
| 125 | $result .= '+'.$name.'-'.boolean_to_string($value); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | return $result; |
---|
| 129 | } |
---|
[12920] | 130 | ?> |
---|