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

Last change on this file since 2252 was 2218, checked in by rub, 16 years ago

Resolved issue 0000807: New slideshow features

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: functions_picture.inc.php 2218 2008-02-27 20:25:18Z rub $
7// | last update   : $Date: 2008-02-27 20:25:18 +0000 (Wed, 27 Feb 2008) $
8// | last modifier : $Author: rub $
9// | revision      : $Revision: 2218 $
10// +-----------------------------------------------------------------------+
11// | This program is free software; you can redistribute it and/or modify  |
12// | it under the terms of the GNU General Public License as published by  |
13// | the Free Software Foundation                                          |
14// |                                                                       |
15// | This program is distributed in the hope that it will be useful, but   |
16// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
17// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
18// | General Public License for more details.                              |
19// |                                                                       |
20// | You should have received a copy of the GNU General Public License     |
21// | along with this program; if not, write to the Free Software           |
22// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23// | USA.                                                                  |
24// +-----------------------------------------------------------------------+
25
26/**
27 * @param element_info array containing element information from db;
28 * at least 'id', 'path' should be present
29 */
30function get_element_path($element_info)
31{
32  $path = get_element_location($element_info);
33  if ( !url_is_remote($path) )
34  {
35    $path = PHPWG_ROOT_PATH.$path;
36  }
37  return $path;
38}
39
40/*
41 * @param element_info array containing element information from db;
42 * at least 'id', 'path' should be present
43 */
44function get_element_url($element_info)
45{
46  $url = get_element_location($element_info);
47  if ( !url_is_remote($url) )
48  {
49    $url = embellish_url(get_root_url().$url);
50  }
51  // plugins want another url ?
52  return trigger_event('get_element_url', $url, $element_info);
53}
54
55/**
56 * Returns the relative path of the element with regards to to the root
57 * of PWG (not the current page). This function is not intended to be
58 * called directly from code.
59 * @param element_info array containing element information from db;
60 * at least 'id', 'path' should be present
61 */
62function get_element_location($element_info)
63{
64  // maybe a cached watermark ?
65  return trigger_event('get_element_location',
66    $element_info['path'], $element_info);
67}
68
69
70/**
71 * Returns the PATH to the image to be displayed in the picture page. If the
72 * element is not a picture, then the representative image or the default
73 * mime image. The path can be used in the php script, but not sent to the
74 * browser.
75 * @param element_info array containing element information from db;
76 * at least 'id', 'path', 'representative_ext' should be present
77 */
78function get_image_path($element_info)
79{
80  global $conf;
81  $ext = get_extension($element_info['path']);
82  if (in_array($ext, $conf['picture_ext']))
83  {
84    if (isset($element_info['element_path']) )
85    {
86      return $element_info['element_path'];
87    }
88    return get_element_path($element_info);
89  }
90
91  $path = get_image_location($element_info);
92  if ( !url_is_remote($path) )
93  {
94    $path = PHPWG_ROOT_PATH.$path;
95  }
96  return $path;
97}
98
99/**
100 * Returns the URL of the image to be displayed in the picture page. If the
101 * element is not a picture, then the representative image or the default
102 * mime image. The URL can't be used in the php script, but can be sent to the
103 * browser.
104 * @param element_info array containing element information from db;
105 * at least 'id', 'path', 'representative_ext' should be present
106 */
107function get_image_url($element_info)
108{
109  global $conf;
110  $ext = get_extension($element_info['path']);
111  if (in_array($ext, $conf['picture_ext']))
112  {
113    if (isset($element_info['element_url']) )
114    {
115      return $element_info['element_url'];
116    }
117    return get_element_url($element_info);
118  }
119
120  $url = get_image_location($element_info);
121  if ( !url_is_remote($url) )
122  {
123    $url = embellish_url(get_root_url().$url);
124  }
125  return $url;
126}
127
128/**
129 * Returns the relative path of the image (element/representative/mimetype)
130 * with regards to the root of PWG (not the current page). This function
131 * is not intended to be called directly from code.
132 * @param element_info array containing element information from db;
133 * at least 'id', 'path', 'representative_ext' should be present
134 */
135function get_image_location($element_info)
136{
137    if (isset($element_info['representative_ext'])
138          and $element_info['representative_ext'] != '')
139    {
140      $pi = pathinfo($element_info['path']);
141      $file_wo_ext = get_filename_wo_extension($pi['basename']);
142      $path =
143        $pi['dirname'].'/pwg_representative/'
144        .$file_wo_ext.'.'.$element_info['representative_ext'];
145    }
146    else
147    {
148      $ext = get_extension($element_info['path']);
149      $path = get_themeconf('mime_icon_dir');
150      $path.= strtolower($ext).'.png';
151      if ( !file_exists(PHPWG_ROOT_PATH.$path)
152          and !empty($element_info['tn_ext']) )
153      {
154        $path = get_thumbnail_location($element_info);
155      }
156    }
157
158  // plugins want another location ?
159  return trigger_event( 'get_image_location', $path, $element_info);
160}
161
162
163/*
164 * @param element_info array containing element information from db;
165 * at least 'id', 'path', 'has_high' should be present
166 */
167function get_high_path($element_info)
168{
169  $path = get_high_location($element_info);
170  if (!empty($path) and !url_is_remote($path) )
171  {
172    $path = PHPWG_ROOT_PATH.$path;
173  }
174  return $path;
175}
176
177/**
178 * @param element_info array containing element information from db;
179 * at least 'id', 'path', 'has_high' should be present
180 */
181function get_high_url($element_info)
182{
183  $url = get_high_location($element_info);
184  if (!empty($url) and !url_is_remote($url) )
185  {
186    $url = embellish_url(get_root_url().$url);
187  }
188  // plugins want another url ?
189  return trigger_event('get_high_url', $url, $element_info);
190}
191
192/**
193 * @param element_info array containing element information from db;
194 * at least 'id', 'path', 'has_high' should be present
195 */
196function get_high_location($element_info)
197{
198  $location = '';
199  if ($element_info['has_high'] == 'true')
200  {
201    $pi = pathinfo($element_info['path']);
202    $location=$pi['dirname'].'/pwg_high/'.$pi['basename'];
203  }
204  return trigger_event( 'get_high_location', $location, $element_info);
205}
206
207
208/**
209 * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image),
210 *   'h' (high resolution image)
211 * @param element_info array containing element information from db;
212 * at least 'id', 'path' should be present
213 */
214function get_download_url($what_part, $element_info)
215{
216  $url = get_root_url().'action.php';
217  $url = add_url_params($url,
218      array(
219        'id' => $element_info['id'],
220        'part' => $what_part,
221      )
222    );
223  return trigger_event( 'get_download_url', $url, $element_info);
224}
225
226/*
227 * get slideshow default params into array
228 *
229 * @param void
230 *
231 * @return slideshow default values into array
232 */
233function get_default_slideshow_params()
234{
235  global $conf;
236
237  return array(
238    'period' => $conf['slideshow_period'],
239    'repeat' => $conf['slideshow_repeat'],
240    'play' => true,
241    );
242}
243
244/*
245 * check and correct slideshow params from array
246 *
247 * @param array of params
248 *
249 * @return slideshow corrected values into array
250 */
251function correct_slideshow_params($params = array())
252{
253  global $conf;
254
255  if ($params['period'] < $conf['slideshow_period_min'])
256  {
257    $params['period'] = $conf['slideshow_period_min'];
258  }
259  else if ($params['period'] > $conf['slideshow_period_max'])
260  {
261    $params['period'] = $conf['slideshow_period_max'];
262  }
263
264  return $params;
265}
266
267/*
268 * Decode slideshow string params into array
269 *
270 * @param string params like ""
271 *
272 * @return slideshow values into array
273 */
274function decode_slideshow_params($encode_params = null)
275{
276  global $conf;
277
278  $result = get_default_slideshow_params();
279
280  if (is_numeric($encode_params))
281  {
282    $result['period'] = $encode_params;
283  }
284  else
285  {
286    $matches = array();
287    if (preg_match_all('/([a-z]+)-(\d+)/', $encode_params, $matches))
288    {
289      $matchcount = count($matches[1]);
290      for ($i = 0; $i < $matchcount; $i++)
291      {
292        $result[$matches[1][$i]] = $matches[2][$i];
293      }
294    }
295
296    if (preg_match_all('/([a-z]+)-(true|false)/', $encode_params, $matches))
297    {
298      $matchcount = count($matches[1]);
299      for ($i = 0; $i < $matchcount; $i++)
300      {
301        $result[$matches[1][$i]] = get_boolean($matches[2][$i]);
302      }
303    }
304  }
305
306  return correct_slideshow_params($result);
307}
308
309/*
310 * Encode slideshow array params into array
311 *
312 * @param array params
313 *
314 * @return slideshow values into string
315 */
316function encode_slideshow_params($decode_params = array())
317{
318  global $conf;
319
320  $params = array_diff_assoc(correct_slideshow_params($decode_params), get_default_slideshow_params());
321  $result = '';
322
323  foreach ($params as $name => $value)
324  {
325    // boolean_to_string return $value, if it's not a bool
326    $result .= '+'.$name.'-'.boolean_to_string($value);
327  }
328
329  return $result;
330}
331
332?>
Note: See TracBrowser for help on using the repository browser.