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

Last change on this file since 2138 was 2026, checked in by rub, 18 years ago

Improvement of picture url built

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: functions_picture.inc.php 2026 2007-05-25 22:02:47Z rub $
7// | last update   : $Date: 2007-05-25 22:02:47 +0000 (Fri, 25 May 2007) $
8// | last modifier : $Author: rub $
9// | revision      : $Revision: 2026 $
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    }
152
153  // plugins want another location ?
154  return trigger_event( 'get_image_location', $path, $element_info);
155}
156
157
158/*
159 * @param element_info array containing element information from db;
160 * at least 'id', 'path', 'has_high' should be present
161 */
162function get_high_path($element_info)
163{
164  $path = get_high_location($element_info);
165  if (!empty($path) and !url_is_remote($path) )
166  {
167    $path = PHPWG_ROOT_PATH.$path;
168  }
169  return $path;
170}
171
172/**
173 * @param element_info array containing element information from db;
174 * at least 'id', 'path', 'has_high' should be present
175 */
176function get_high_url($element_info)
177{
178  $url = get_high_location($element_info);
179  if (!empty($url) and !url_is_remote($url) )
180  {
181    $url = embellish_url(get_root_url().$url);
182  }
183  // plugins want another url ?
184  return trigger_event('get_high_url', $url, $element_info);
185}
186
187/**
188 * @param element_info array containing element information from db;
189 * at least 'id', 'path', 'has_high' should be present
190 */
191function get_high_location($element_info)
192{
193  $location = '';
194  if ($element_info['has_high'] == 'true')
195  {
196    $pi = pathinfo($element_info['path']);
197    $location=$pi['dirname'].'/pwg_high/'.$pi['basename'];
198  }
199  return trigger_event( 'get_high_location', $location, $element_info);
200}
201
202
203/**
204 * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image),
205 *   'h' (high resolution image)
206 * @param element_info array containing element information from db;
207 * at least 'id', 'path' should be present
208 */
209function get_download_url($what_part, $element_info)
210{
211  $url = get_root_url().'action.php';
212  $url = add_url_params($url,
213      array(
214        'id' => $element_info['id'],
215        'part' => $what_part,
216      )
217    );
218  return trigger_event( 'get_download_url', $url, $element_info);
219}
220
221?>
Note: See TracBrowser for help on using the repository browser.