1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | branch : BSF (Best So Far) |
---|
7 | // | file : $RCSfile$ |
---|
8 | // | last update : $Date: 2006-11-17 04:26:10 +0000 (Fri, 17 Nov 2006) $ |
---|
9 | // | last modifier : $Author: rvelices $ |
---|
10 | // | revision : $Revision: 1612 $ |
---|
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 | */ |
---|
31 | function 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 | */ |
---|
45 | function 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 | */ |
---|
63 | function 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 | */ |
---|
79 | function 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 | */ |
---|
108 | function 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 | */ |
---|
136 | function 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 | } |
---|
153 | |
---|
154 | // plugins want another location ? |
---|
155 | return trigger_event( 'get_image_location', $path, $element_info); |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | /* |
---|
160 | * @param element_info array containing element information from db; |
---|
161 | * at least 'id', 'path', 'has_high' should be present |
---|
162 | */ |
---|
163 | function get_high_path($element_info) |
---|
164 | { |
---|
165 | $path = get_high_location($element_info); |
---|
166 | if (!empty($path) and !url_is_remote($path) ) |
---|
167 | { |
---|
168 | $path = PHPWG_ROOT_PATH.$path; |
---|
169 | } |
---|
170 | return $path; |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * @param element_info array containing element information from db; |
---|
175 | * at least 'id', 'path', 'has_high' should be present |
---|
176 | */ |
---|
177 | function get_high_url($element_info) |
---|
178 | { |
---|
179 | $url = get_high_location($element_info); |
---|
180 | if (!empty($url) and !url_is_remote($url) ) |
---|
181 | { |
---|
182 | $url = get_root_url().$url; |
---|
183 | } |
---|
184 | // plugins want another url ? |
---|
185 | return trigger_event('get_high_url', $url, $element_info); |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | * @param element_info array containing element information from db; |
---|
190 | * at least 'id', 'path', 'has_high' should be present |
---|
191 | */ |
---|
192 | function get_high_location($element_info) |
---|
193 | { |
---|
194 | $location = ''; |
---|
195 | if ($element_info['has_high'] == 'true') |
---|
196 | { |
---|
197 | $pi = pathinfo($element_info['path']); |
---|
198 | $location=$pi['dirname'].'/pwg_high/'.$pi['basename']; |
---|
199 | } |
---|
200 | return trigger_event( 'get_high_location', $location, $element_info); |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | /** |
---|
205 | * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image), |
---|
206 | * 'h' (high resolution image) |
---|
207 | * @param element_info array containing element information from db; |
---|
208 | * at least 'id', 'path' should be present |
---|
209 | */ |
---|
210 | function get_download_url($what_part, $element_info) |
---|
211 | { |
---|
212 | $url = get_root_url().'action.php'; |
---|
213 | $url = add_url_params($url, |
---|
214 | array( |
---|
215 | 'id' => $element_info['id'], |
---|
216 | 'part' => $what_part, |
---|
217 | ) |
---|
218 | ); |
---|
219 | return trigger_event( 'get_download_url', $url, $element_info); |
---|
220 | } |
---|
221 | |
---|
222 | ?> |
---|