source: trunk/include/functions_picture.inc.php @ 31056

Last change on this file since 31056 was 26461, checked in by mistic100, 11 years ago

Update headers to 2014. Happy new year!!

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24/**
25 * @package functions\picture
26 */
27
28
29/**
30 * Returns slideshow default params.
31 * - period
32 * - repeat
33 * - play
34 *
35 * @return array
36 */
37function 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
48/**
49 * Checks and corrects slideshow params
50 *
51 * @param array $params
52 * @return array
53 */
54function correct_slideshow_params($params=array())
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
70/**
71 * Decodes slideshow string params into array
72 *
73 * @param string $encode_params
74 * @return array
75 */
76function decode_slideshow_params($encode_params=null)
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
111/**
112 * Encodes slideshow array params into a string
113 *
114 * @param array $decode_params
115 * @return string
116 */
117function encode_slideshow_params($decode_params=array())
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}
132
133?>
Note: See TracBrowser for help on using the repository browser.