source: branches/1.7/include/functions_picture.inc.php @ 4636

Last change on this file since 4636 was 2207, checked in by rvelices, 16 years ago

merge revisions 2205 and 2206 from trunk to branch-1_7
feature 803: Implement keyboard navigation (left/right arrows) on the picture page
fix: non-image elements without representative and without mime type icon default to thumbnail if possible

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $RCSfile$
8// | last update   : $Date: 2008-02-13 01:25:07 +0000 (Wed, 13 Feb 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2207 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27/**
28 * @param element_info array containing element information from db;
29 * at least 'id', 'path' should be present
30 */
31function get_element_path($element_info)
32{
33  $path = get_element_location($element_info);
34  if ( !url_is_remote($path) )
35  {
36    $path = PHPWG_ROOT_PATH.$path;
37  }
38  return $path;
39}
40
41/*
42 * @param element_info array containing element information from db;
43 * at least 'id', 'path' should be present
44 */
45function get_element_url($element_info)
46{
47  $url = get_element_location($element_info);
48  if ( !url_is_remote($url) )
49  {
50    $url = get_root_url().$url;
51  }
52  // plugins want another url ?
53  return trigger_event('get_element_url', $url, $element_info);
54}
55
56/**
57 * Returns the relative path of the element with regards to to the root
58 * of PWG (not the current page). This function is not intended to be
59 * called directly from code.
60 * @param element_info array containing element information from db;
61 * at least 'id', 'path' should be present
62 */
63function get_element_location($element_info)
64{
65  // maybe a cached watermark ?
66  return trigger_event('get_element_location',
67    $element_info['path'], $element_info);
68}
69
70
71/**
72 * Returns the PATH to the image to be displayed in the picture page. If the
73 * element is not a picture, then the representative image or the default
74 * mime image. The path can be used in the php script, but not sent to the
75 * browser.
76 * @param element_info array containing element information from db;
77 * at least 'id', 'path', 'representative_ext' should be present
78 */
79function get_image_path($element_info)
80{
81  global $conf;
82  $ext = get_extension($element_info['path']);
83  if (in_array($ext, $conf['picture_ext']))
84  {
85    if (isset($element_info['element_path']) )
86    {
87      return $element_info['element_path'];
88    }
89    return get_element_path($element_info);
90  }
91
92  $path = get_image_location($element_info);
93  if ( !url_is_remote($path) )
94  {
95    $path = PHPWG_ROOT_PATH.$path;
96  }
97  return $path;
98}
99
100/**
101 * Returns the URL of the image to be displayed in the picture page. If the
102 * element is not a picture, then the representative image or the default
103 * mime image. The URL can't be used in the php script, but can be sent to the
104 * browser.
105 * @param element_info array containing element information from db;
106 * at least 'id', 'path', 'representative_ext' should be present
107 */
108function get_image_url($element_info)
109{
110  global $conf;
111  $ext = get_extension($element_info['path']);
112  if (in_array($ext, $conf['picture_ext']))
113  {
114    if (isset($element_info['element_url']) )
115    {
116      return $element_info['element_url'];
117    }
118    return get_element_url($element_info);
119  }
120
121  $url = get_image_location($element_info);
122  if ( !url_is_remote($url) )
123  {
124    $url = get_root_url().$url;
125  }
126  return $url;
127}
128
129/**
130 * Returns the relative path of the image (element/representative/mimetype)
131 * with regards to the root of PWG (not the current page). This function
132 * is not intended to be called directly from code.
133 * @param element_info array containing element information from db;
134 * at least 'id', 'path', 'representative_ext' should be present
135 */
136function get_image_location($element_info)
137{
138    if (isset($element_info['representative_ext'])
139          and $element_info['representative_ext'] != '')
140    {
141      $pi = pathinfo($element_info['path']);
142      $file_wo_ext = get_filename_wo_extension($pi['basename']);
143      $path =
144        $pi['dirname'].'/pwg_representative/'
145        .$file_wo_ext.'.'.$element_info['representative_ext'];
146    }
147    else
148    {
149      $ext = get_extension($element_info['path']);
150      $path = get_themeconf('mime_icon_dir');
151      $path.= strtolower($ext).'.png';
152      if ( !file_exists(PHPWG_ROOT_PATH.$path)
153          and !empty($element_info['tn_ext']) )
154      {
155        $path = get_thumbnail_location($element_info);
156      }
157    }
158
159  // plugins want another location ?
160  return trigger_event( 'get_image_location', $path, $element_info);
161}
162
163
164/*
165 * @param element_info array containing element information from db;
166 * at least 'id', 'path', 'has_high' should be present
167 */
168function get_high_path($element_info)
169{
170  $path = get_high_location($element_info);
171  if (!empty($path) and !url_is_remote($path) )
172  {
173    $path = PHPWG_ROOT_PATH.$path;
174  }
175  return $path;
176}
177
178/**
179 * @param element_info array containing element information from db;
180 * at least 'id', 'path', 'has_high' should be present
181 */
182function get_high_url($element_info)
183{
184  $url = get_high_location($element_info);
185  if (!empty($url) and !url_is_remote($url) )
186  {
187    $url = get_root_url().$url;
188  }
189  // plugins want another url ?
190  return trigger_event('get_high_url', $url, $element_info);
191}
192
193/**
194 * @param element_info array containing element information from db;
195 * at least 'id', 'path', 'has_high' should be present
196 */
197function get_high_location($element_info)
198{
199  $location = '';
200  if ($element_info['has_high'] == 'true')
201  {
202    $pi = pathinfo($element_info['path']);
203    $location=$pi['dirname'].'/pwg_high/'.$pi['basename'];
204  }
205  return trigger_event( 'get_high_location', $location, $element_info);
206}
207
208
209/**
210 * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image),
211 *   'h' (high resolution image)
212 * @param element_info array containing element information from db;
213 * at least 'id', 'path' should be present
214 */
215function get_download_url($what_part, $element_info)
216{
217  $url = get_root_url().'action.php';
218  $url = add_url_params($url,
219      array(
220        'id' => $element_info['id'],
221        'part' => $what_part,
222      )
223    );
224  return trigger_event( 'get_download_url', $url, $element_info);
225}
226
227?>
Note: See TracBrowser for help on using the repository browser.