PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/fsn-site-central/mediatheque/include/functions_picture.inc.php

https://gitlab.com/team_fsn/fsn-php
PHP | 133 lines | 65 code | 17 blank | 51 comment | 8 complexity | ce7a0e28c8150772e4f217a300fd24d5 MD5 | raw file
  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Piwigo - a PHP based photo gallery |
  4. // +-----------------------------------------------------------------------+
  5. // | Copyright(C) 2008-2016 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. * @package functions\picture
  25. */
  26. /**
  27. * Returns slideshow default params.
  28. * - period
  29. * - repeat
  30. * - play
  31. *
  32. * @return array
  33. */
  34. function get_default_slideshow_params()
  35. {
  36. global $conf;
  37. return array(
  38. 'period' => $conf['slideshow_period'],
  39. 'repeat' => $conf['slideshow_repeat'],
  40. 'play' => true,
  41. );
  42. }
  43. /**
  44. * Checks and corrects slideshow params
  45. *
  46. * @param array $params
  47. * @return array
  48. */
  49. function correct_slideshow_params($params=array())
  50. {
  51. global $conf;
  52. if ($params['period'] < $conf['slideshow_period_min'])
  53. {
  54. $params['period'] = $conf['slideshow_period_min'];
  55. }
  56. else if ($params['period'] > $conf['slideshow_period_max'])
  57. {
  58. $params['period'] = $conf['slideshow_period_max'];
  59. }
  60. return $params;
  61. }
  62. /**
  63. * Decodes slideshow string params into array
  64. *
  65. * @param string $encode_params
  66. * @return array
  67. */
  68. function decode_slideshow_params($encode_params=null)
  69. {
  70. global $conf;
  71. $result = get_default_slideshow_params();
  72. if (is_numeric($encode_params))
  73. {
  74. $result['period'] = $encode_params;
  75. }
  76. else
  77. {
  78. $matches = array();
  79. if (preg_match_all('/([a-z]+)-(\d+)/', $encode_params, $matches))
  80. {
  81. $matchcount = count($matches[1]);
  82. for ($i = 0; $i < $matchcount; $i++)
  83. {
  84. $result[$matches[1][$i]] = $matches[2][$i];
  85. }
  86. }
  87. if (preg_match_all('/([a-z]+)-(true|false)/', $encode_params, $matches))
  88. {
  89. $matchcount = count($matches[1]);
  90. for ($i = 0; $i < $matchcount; $i++)
  91. {
  92. $result[$matches[1][$i]] = get_boolean($matches[2][$i]);
  93. }
  94. }
  95. }
  96. return correct_slideshow_params($result);
  97. }
  98. /**
  99. * Encodes slideshow array params into a string
  100. *
  101. * @param array $decode_params
  102. * @return string
  103. */
  104. function encode_slideshow_params($decode_params=array())
  105. {
  106. global $conf;
  107. $params = array_diff_assoc(correct_slideshow_params($decode_params), get_default_slideshow_params());
  108. $result = '';
  109. foreach ($params as $name => $value)
  110. {
  111. // boolean_to_string return $value, if it's not a bool
  112. $result .= '+'.$name.'-'.boolean_to_string($value);
  113. }
  114. return $result;
  115. }
  116. ?>