1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-03-23 01:49:04 +0000 (Thu, 23 Mar 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1094 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | include_once( PHPWG_ROOT_PATH .'include/functions_user.inc.php' ); |
---|
29 | include_once( PHPWG_ROOT_PATH .'include/functions_session.inc.php' ); |
---|
30 | include_once( PHPWG_ROOT_PATH .'include/functions_category.inc.php' ); |
---|
31 | include_once( PHPWG_ROOT_PATH .'include/functions_xml.inc.php' ); |
---|
32 | include_once( PHPWG_ROOT_PATH .'include/functions_group.inc.php' ); |
---|
33 | include_once( PHPWG_ROOT_PATH .'include/functions_html.inc.php' ); |
---|
34 | |
---|
35 | //----------------------------------------------------------- generic functions |
---|
36 | |
---|
37 | /** |
---|
38 | * returns an array containing the possible values of an enum field |
---|
39 | * |
---|
40 | * @param string tablename |
---|
41 | * @param string fieldname |
---|
42 | */ |
---|
43 | function get_enums($table, $field) |
---|
44 | { |
---|
45 | // retrieving the properties of the table. Each line represents a field : |
---|
46 | // columns are 'Field', 'Type' |
---|
47 | $result = pwg_query('desc '.$table); |
---|
48 | while ($row = mysql_fetch_array($result)) |
---|
49 | { |
---|
50 | // we are only interested in the the field given in parameter for the |
---|
51 | // function |
---|
52 | if ($row['Field'] == $field) |
---|
53 | { |
---|
54 | // retrieving possible values of the enum field |
---|
55 | // enum('blue','green','black') |
---|
56 | $options = explode(',', substr($row['Type'], 5, -1)); |
---|
57 | foreach ($options as $i => $option) |
---|
58 | { |
---|
59 | $options[$i] = str_replace("'", '',$option); |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | mysql_free_result($result); |
---|
64 | return $options; |
---|
65 | } |
---|
66 | |
---|
67 | // get_boolean transforms a string to a boolean value. If the string is |
---|
68 | // "false" (case insensitive), then the boolean value false is returned. In |
---|
69 | // any other case, true is returned. |
---|
70 | function get_boolean( $string ) |
---|
71 | { |
---|
72 | $boolean = true; |
---|
73 | if ( preg_match( '/^false$/i', $string ) ) |
---|
74 | { |
---|
75 | $boolean = false; |
---|
76 | } |
---|
77 | return $boolean; |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * returns boolean string 'true' or 'false' if the given var is boolean |
---|
82 | * |
---|
83 | * @param mixed $var |
---|
84 | * @return mixed |
---|
85 | */ |
---|
86 | function boolean_to_string($var) |
---|
87 | { |
---|
88 | if (is_bool($var)) |
---|
89 | { |
---|
90 | if ($var) |
---|
91 | { |
---|
92 | return 'true'; |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | return 'false'; |
---|
97 | } |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | return $var; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | // The function get_moment returns a float value coresponding to the number |
---|
106 | // of seconds since the unix epoch (1st January 1970) and the microseconds |
---|
107 | // are precised : e.g. 1052343429.89276600 |
---|
108 | function get_moment() |
---|
109 | { |
---|
110 | $t1 = explode( ' ', microtime() ); |
---|
111 | $t2 = explode( '.', $t1[0] ); |
---|
112 | $t2 = $t1[1].'.'.$t2[1]; |
---|
113 | return $t2; |
---|
114 | } |
---|
115 | |
---|
116 | // The function get_elapsed_time returns the number of seconds (with 3 |
---|
117 | // decimals precision) between the start time and the end time given. |
---|
118 | function get_elapsed_time( $start, $end ) |
---|
119 | { |
---|
120 | return number_format( $end - $start, 3, '.', ' ').' s'; |
---|
121 | } |
---|
122 | |
---|
123 | // - The replace_space function replaces space and '-' characters |
---|
124 | // by their HTML equivalent &nbsb; and − |
---|
125 | // - The function does not replace characters in HTML tags |
---|
126 | // - This function was created because IE5 does not respect the |
---|
127 | // CSS "white-space: nowrap;" property unless space and minus |
---|
128 | // characters are replaced like this function does. |
---|
129 | // - Example : |
---|
130 | // <div class="foo">My friend</div> |
---|
131 | // ( 01234567891111111111222222222233 ) |
---|
132 | // ( 0123456789012345678901 ) |
---|
133 | // becomes : |
---|
134 | // <div class="foo">My friend</div> |
---|
135 | function replace_space( $string ) |
---|
136 | { |
---|
137 | //return $string; |
---|
138 | $return_string = ''; |
---|
139 | // $remaining is the rest of the string where to replace spaces characters |
---|
140 | $remaining = $string; |
---|
141 | // $start represents the position of the next '<' character |
---|
142 | // $end represents the position of the next '>' character |
---|
143 | $start = 0; |
---|
144 | $end = 0; |
---|
145 | $start = strpos ( $remaining, '<' ); // -> 0 |
---|
146 | $end = strpos ( $remaining, '>' ); // -> 16 |
---|
147 | // as long as a '<' and his friend '>' are found, we loop |
---|
148 | while ( is_numeric( $start ) and is_numeric( $end ) ) |
---|
149 | { |
---|
150 | // $treatment is the part of the string to treat |
---|
151 | // In the first loop of our example, this variable is empty, but in the |
---|
152 | // second loop, it equals 'My friend' |
---|
153 | $treatment = substr ( $remaining, 0, $start ); |
---|
154 | // Replacement of ' ' by his equivalent ' ' |
---|
155 | $treatment = str_replace( ' ', ' ', $treatment ); |
---|
156 | $treatment = str_replace( '-', '−', $treatment ); |
---|
157 | // composing the string to return by adding the treated string and the |
---|
158 | // following HTML tag -> 'My friend</div>' |
---|
159 | $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 ); |
---|
160 | // the remaining string is deplaced to the part after the '>' of this |
---|
161 | // loop |
---|
162 | $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) ); |
---|
163 | $start = strpos ( $remaining, '<' ); |
---|
164 | $end = strpos ( $remaining, '>' ); |
---|
165 | } |
---|
166 | $treatment = str_replace( ' ', ' ', $remaining ); |
---|
167 | $treatment = str_replace( '-', '−', $treatment ); |
---|
168 | $return_string.= $treatment; |
---|
169 | |
---|
170 | return $return_string; |
---|
171 | } |
---|
172 | |
---|
173 | // get_extension returns the part of the string after the last "." |
---|
174 | function get_extension( $filename ) |
---|
175 | { |
---|
176 | return substr( strrchr( $filename, '.' ), 1, strlen ( $filename ) ); |
---|
177 | } |
---|
178 | |
---|
179 | // get_filename_wo_extension returns the part of the string before the last |
---|
180 | // ".". |
---|
181 | // get_filename_wo_extension( 'test.tar.gz' ) -> 'test.tar' |
---|
182 | function get_filename_wo_extension( $filename ) |
---|
183 | { |
---|
184 | return substr( $filename, 0, strrpos( $filename, '.' ) ); |
---|
185 | } |
---|
186 | |
---|
187 | /** |
---|
188 | * returns an array contening sub-directories, excluding "CVS" |
---|
189 | * |
---|
190 | * @param string $dir |
---|
191 | * @return array |
---|
192 | */ |
---|
193 | function get_dirs($directory) |
---|
194 | { |
---|
195 | $sub_dirs = array(); |
---|
196 | |
---|
197 | if ($opendir = opendir($directory)) |
---|
198 | { |
---|
199 | while ($file = readdir($opendir)) |
---|
200 | { |
---|
201 | if ($file != '.' |
---|
202 | and $file != '..' |
---|
203 | and is_dir($directory.'/'.$file) |
---|
204 | and $file != 'CVS' |
---|
205 | and $file != '.svn') |
---|
206 | { |
---|
207 | array_push($sub_dirs, $file); |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | return $sub_dirs; |
---|
212 | } |
---|
213 | |
---|
214 | // The get_picture_size function return an array containing : |
---|
215 | // - $picture_size[0] : final width |
---|
216 | // - $picture_size[1] : final height |
---|
217 | // The final dimensions are calculated thanks to the original dimensions and |
---|
218 | // the maximum dimensions given in parameters. get_picture_size respects |
---|
219 | // the width/height ratio |
---|
220 | function get_picture_size( $original_width, $original_height, |
---|
221 | $max_width, $max_height ) |
---|
222 | { |
---|
223 | $width = $original_width; |
---|
224 | $height = $original_height; |
---|
225 | $is_original_size = true; |
---|
226 | |
---|
227 | if ( $max_width != "" ) |
---|
228 | { |
---|
229 | if ( $original_width > $max_width ) |
---|
230 | { |
---|
231 | $width = $max_width; |
---|
232 | $height = floor( ( $width * $original_height ) / $original_width ); |
---|
233 | } |
---|
234 | } |
---|
235 | if ( $max_height != "" ) |
---|
236 | { |
---|
237 | if ( $original_height > $max_height ) |
---|
238 | { |
---|
239 | $height = $max_height; |
---|
240 | $width = floor( ( $height * $original_width ) / $original_height ); |
---|
241 | $is_original_size = false; |
---|
242 | } |
---|
243 | } |
---|
244 | if ( is_numeric( $max_width ) and is_numeric( $max_height ) |
---|
245 | and $max_width != 0 and $max_height != 0 ) |
---|
246 | { |
---|
247 | $ratioWidth = $original_width / $max_width; |
---|
248 | $ratioHeight = $original_height / $max_height; |
---|
249 | if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) ) |
---|
250 | { |
---|
251 | if ( $ratioWidth < $ratioHeight ) |
---|
252 | { |
---|
253 | $width = floor( $original_width / $ratioHeight ); |
---|
254 | $height = $max_height; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | $width = $max_width; |
---|
259 | $height = floor( $original_height / $ratioWidth ); |
---|
260 | } |
---|
261 | $is_original_size = false; |
---|
262 | } |
---|
263 | } |
---|
264 | $picture_size = array(); |
---|
265 | $picture_size[0] = $width; |
---|
266 | $picture_size[1] = $height; |
---|
267 | return $picture_size; |
---|
268 | } |
---|
269 | //-------------------------------------------- PhpWebGallery specific functions |
---|
270 | |
---|
271 | /** |
---|
272 | * returns an array with a list of {language_code => language_name} |
---|
273 | * |
---|
274 | * @returns array |
---|
275 | */ |
---|
276 | function get_languages() |
---|
277 | { |
---|
278 | $dir = opendir(PHPWG_ROOT_PATH.'language'); |
---|
279 | $languages = array(); |
---|
280 | |
---|
281 | while ($file = readdir($dir)) |
---|
282 | { |
---|
283 | $path = PHPWG_ROOT_PATH.'language/'.$file; |
---|
284 | if (is_dir($path) and !is_link($path) and file_exists($path.'/iso.txt')) |
---|
285 | { |
---|
286 | list($language_name) = @file($path.'/iso.txt'); |
---|
287 | $languages[$file] = $language_name; |
---|
288 | } |
---|
289 | } |
---|
290 | closedir($dir); |
---|
291 | @asort($languages); |
---|
292 | @reset($languages); |
---|
293 | |
---|
294 | return $languages; |
---|
295 | } |
---|
296 | |
---|
297 | /** |
---|
298 | * replaces the $search into <span style="$style">$search</span> in the |
---|
299 | * given $string. |
---|
300 | * |
---|
301 | * case insensitive replacements, does not replace characters in HTML tags |
---|
302 | * |
---|
303 | * @param string $string |
---|
304 | * @param string $search |
---|
305 | * @param string $style |
---|
306 | * @return string |
---|
307 | */ |
---|
308 | function add_style( $string, $search, $style ) |
---|
309 | { |
---|
310 | //return $string; |
---|
311 | $return_string = ''; |
---|
312 | $remaining = $string; |
---|
313 | |
---|
314 | $start = 0; |
---|
315 | $end = 0; |
---|
316 | $start = strpos ( $remaining, '<' ); |
---|
317 | $end = strpos ( $remaining, '>' ); |
---|
318 | while ( is_numeric( $start ) and is_numeric( $end ) ) |
---|
319 | { |
---|
320 | $treatment = substr ( $remaining, 0, $start ); |
---|
321 | $treatment = preg_replace( '/('.$search.')/i', |
---|
322 | '<span style="'.$style.'">\\0</span>', |
---|
323 | $treatment ); |
---|
324 | $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 ); |
---|
325 | $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) ); |
---|
326 | $start = strpos ( $remaining, '<' ); |
---|
327 | $end = strpos ( $remaining, '>' ); |
---|
328 | } |
---|
329 | $treatment = preg_replace( '/('.$search.')/i', |
---|
330 | '<span style="'.$style.'">\\0</span>', |
---|
331 | $remaining ); |
---|
332 | $return_string.= $treatment; |
---|
333 | |
---|
334 | return $return_string; |
---|
335 | } |
---|
336 | |
---|
337 | // replace_search replaces a searched words array string by the search in |
---|
338 | // another style for the given $string. |
---|
339 | function replace_search( $string, $search ) |
---|
340 | { |
---|
341 | // FIXME : with new advanced search, this function needs a rewrite |
---|
342 | return $string; |
---|
343 | |
---|
344 | $words = explode( ',', $search ); |
---|
345 | $style = 'background-color:white;color:red;'; |
---|
346 | foreach ( $words as $word ) { |
---|
347 | $string = add_style( $string, $word, $style ); |
---|
348 | } |
---|
349 | return $string; |
---|
350 | } |
---|
351 | |
---|
352 | function pwg_log( $file, $category, $picture = '' ) |
---|
353 | { |
---|
354 | global $conf, $user; |
---|
355 | |
---|
356 | if ($conf['log']) |
---|
357 | { |
---|
358 | if ( ($conf['history_admin'] ) or ( (! $conf['history_admin']) and (!is_admin()) ) ) |
---|
359 | { |
---|
360 | $login = ($user['id'] == $conf['guest_id']) |
---|
361 | ? 'guest' : addslashes($user['username']); |
---|
362 | |
---|
363 | $query = ' |
---|
364 | INSERT INTO '.HISTORY_TABLE.' |
---|
365 | (date,login,IP,file,category,picture) |
---|
366 | VALUES |
---|
367 | (NOW(), |
---|
368 | \''.$login.'\', |
---|
369 | \''.$_SERVER['REMOTE_ADDR'].'\', |
---|
370 | \''.addslashes($file).'\', |
---|
371 | \''.addslashes(strip_tags($category)).'\', |
---|
372 | \''.addslashes($picture).'\') |
---|
373 | ;'; |
---|
374 | pwg_query($query); |
---|
375 | } |
---|
376 | } |
---|
377 | } |
---|
378 | |
---|
379 | // format_date returns a formatted date for display. The date given in |
---|
380 | // argument can be a unixdate (number of seconds since the 01.01.1970) or an |
---|
381 | // american format (2003-09-15). By option, you can show the time. The |
---|
382 | // output is internationalized. |
---|
383 | // |
---|
384 | // format_date( "2003-09-15", 'us', true ) -> "Monday 15 September 2003 21:52" |
---|
385 | function format_date($date, $type = 'us', $show_time = false) |
---|
386 | { |
---|
387 | global $lang; |
---|
388 | |
---|
389 | list($year,$month,$day,$hour,$minute,$second) = array(0,0,0,0,0,0); |
---|
390 | |
---|
391 | switch ( $type ) |
---|
392 | { |
---|
393 | case 'us' : |
---|
394 | { |
---|
395 | list($year,$month,$day) = explode('-', $date); |
---|
396 | break; |
---|
397 | } |
---|
398 | case 'unix' : |
---|
399 | { |
---|
400 | list($year,$month,$day,$hour,$minute) = |
---|
401 | explode('.', date('Y.n.j.G.i', $date)); |
---|
402 | break; |
---|
403 | } |
---|
404 | case 'mysql_datetime' : |
---|
405 | { |
---|
406 | preg_match('/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/', |
---|
407 | $date, $out); |
---|
408 | list($year,$month,$day,$hour,$minute,$second) = |
---|
409 | array($out[1],$out[2],$out[3],$out[4],$out[5],$out[6]); |
---|
410 | break; |
---|
411 | } |
---|
412 | } |
---|
413 | $formated_date = ''; |
---|
414 | // before 1970, Microsoft Windows can't mktime |
---|
415 | if ($year >= 1970) |
---|
416 | { |
---|
417 | // we ask midday because Windows think it's prior to midnight with a |
---|
418 | // zero and refuse to work |
---|
419 | $formated_date.= $lang['day'][date('w', mktime(12,0,0,$month,$day,$year))]; |
---|
420 | } |
---|
421 | $formated_date.= ' '.$day; |
---|
422 | $formated_date.= ' '.$lang['month'][(int)$month]; |
---|
423 | $formated_date.= ' '.$year; |
---|
424 | if ($show_time) |
---|
425 | { |
---|
426 | $formated_date.= ' '.$hour.':'.$minute; |
---|
427 | } |
---|
428 | |
---|
429 | return $formated_date; |
---|
430 | } |
---|
431 | |
---|
432 | function pwg_query($query) |
---|
433 | { |
---|
434 | global $conf,$page,$debug,$t2; |
---|
435 | |
---|
436 | $start = get_moment(); |
---|
437 | $result = mysql_query($query) or my_error($query."\n"); |
---|
438 | |
---|
439 | $time = get_moment() - $start; |
---|
440 | |
---|
441 | if (!isset($page['count_queries'])) |
---|
442 | { |
---|
443 | $page['count_queries'] = 0; |
---|
444 | $page['queries_time'] = 0; |
---|
445 | } |
---|
446 | |
---|
447 | $page['count_queries']++; |
---|
448 | $page['queries_time']+= $time; |
---|
449 | |
---|
450 | if ($conf['show_queries']) |
---|
451 | { |
---|
452 | $output = ''; |
---|
453 | $output.= '<pre>['.$page['count_queries'].'] '; |
---|
454 | $output.= "\n".$query; |
---|
455 | $output.= "\n".'(this query time : '; |
---|
456 | $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>'; |
---|
457 | $output.= "\n".'(total SQL time : '; |
---|
458 | $output.= number_format($page['queries_time'], 3, '.', ' ').' s)'; |
---|
459 | $output.= "\n".'(total time : '; |
---|
460 | $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)'; |
---|
461 | $output.= "</pre>\n"; |
---|
462 | |
---|
463 | $debug .= $output; |
---|
464 | } |
---|
465 | |
---|
466 | return $result; |
---|
467 | } |
---|
468 | |
---|
469 | function pwg_debug( $string ) |
---|
470 | { |
---|
471 | global $debug,$t2,$page; |
---|
472 | |
---|
473 | $now = explode( ' ', microtime() ); |
---|
474 | $now2 = explode( '.', $now[0] ); |
---|
475 | $now2 = $now[1].'.'.$now2[1]; |
---|
476 | $time = number_format( $now2 - $t2, 3, '.', ' ').' s'; |
---|
477 | $debug .= '<p>'; |
---|
478 | $debug.= '['.$time.', '; |
---|
479 | $debug.= $page['count_queries'].' queries] : '.$string; |
---|
480 | $debug.= "</p>\n"; |
---|
481 | } |
---|
482 | |
---|
483 | /** |
---|
484 | * Redirects to the given URL |
---|
485 | * |
---|
486 | * Note : once this function called, the execution doesn't go further |
---|
487 | * (presence of an exit() instruction. |
---|
488 | * |
---|
489 | * @param string $url |
---|
490 | * @return void |
---|
491 | */ |
---|
492 | function redirect( $url ) |
---|
493 | { |
---|
494 | global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug; |
---|
495 | |
---|
496 | // $refresh, $url_link and $title are required for creating an automated |
---|
497 | // refresh page in header.tpl |
---|
498 | $refresh = 0; |
---|
499 | $url_link = $url; |
---|
500 | $title = 'redirection'; |
---|
501 | |
---|
502 | include( PHPWG_ROOT_PATH.'include/page_header.php' ); |
---|
503 | |
---|
504 | $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) ); |
---|
505 | $template->parse('redirect'); |
---|
506 | |
---|
507 | include( PHPWG_ROOT_PATH.'include/page_tail.php' ); |
---|
508 | |
---|
509 | exit(); |
---|
510 | } |
---|
511 | |
---|
512 | /** |
---|
513 | * returns $_SERVER['QUERY_STRING'] whitout keys given in parameters |
---|
514 | * |
---|
515 | * @param array $rejects |
---|
516 | * @returns string |
---|
517 | */ |
---|
518 | function get_query_string_diff($rejects = array()) |
---|
519 | { |
---|
520 | $query_string = ''; |
---|
521 | |
---|
522 | $str = $_SERVER['QUERY_STRING']; |
---|
523 | parse_str($str, $vars); |
---|
524 | |
---|
525 | $is_first = true; |
---|
526 | foreach ($vars as $key => $value) |
---|
527 | { |
---|
528 | if (!in_array($key, $rejects)) |
---|
529 | { |
---|
530 | $query_string.= $is_first ? '?' : '&'; |
---|
531 | $is_first = false; |
---|
532 | $query_string.= $key.'='.$value; |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | return $query_string; |
---|
537 | } |
---|
538 | |
---|
539 | function url_is_remote($url) |
---|
540 | { |
---|
541 | if (preg_match('/^https?:\/\/[~\/\.\w-]+$/', $url)) |
---|
542 | { |
---|
543 | return true; |
---|
544 | } |
---|
545 | return false; |
---|
546 | } |
---|
547 | |
---|
548 | /** |
---|
549 | * returns available template/theme |
---|
550 | */ |
---|
551 | function get_pwg_themes() |
---|
552 | { |
---|
553 | $themes = array(); |
---|
554 | |
---|
555 | $template_dir = PHPWG_ROOT_PATH.'template'; |
---|
556 | |
---|
557 | foreach (get_dirs($template_dir) as $template) |
---|
558 | { |
---|
559 | foreach (get_dirs($template_dir.'/'.$template.'/theme') as $theme) |
---|
560 | { |
---|
561 | array_push($themes, $template.'/'.$theme); |
---|
562 | } |
---|
563 | } |
---|
564 | |
---|
565 | return $themes; |
---|
566 | } |
---|
567 | |
---|
568 | /** |
---|
569 | * returns thumbnail filepath (or distant URL if thumbnail is remote) for a |
---|
570 | * given element |
---|
571 | * |
---|
572 | * the returned string can represente the filepath of the thumbnail or the |
---|
573 | * filepath to the corresponding icon for non picture elements |
---|
574 | * |
---|
575 | * @param string path |
---|
576 | * @param string tn_ext |
---|
577 | * @param bool with_rewrite if true returned path can't be used from the script |
---|
578 | * @return string |
---|
579 | */ |
---|
580 | function get_thumbnail_src($path, $tn_ext = '', $with_rewrite = true) |
---|
581 | { |
---|
582 | global $conf, $user; |
---|
583 | |
---|
584 | if ($tn_ext != '') |
---|
585 | { |
---|
586 | $src = substr_replace( |
---|
587 | get_filename_wo_extension($path), |
---|
588 | '/thumbnail/'.$conf['prefix_thumbnail'], |
---|
589 | strrpos($path,'/'), |
---|
590 | 1 |
---|
591 | ); |
---|
592 | $src.= '.'.$tn_ext; |
---|
593 | if ($with_rewrite==true and !url_is_remote($src) ) |
---|
594 | { |
---|
595 | $src = get_root_url().$src; |
---|
596 | } |
---|
597 | } |
---|
598 | else |
---|
599 | { |
---|
600 | $src = ($with_rewrite==true) ? get_root_url() : ''; |
---|
601 | $src .= get_themeconf('mime_icon_dir'); |
---|
602 | $src.= strtolower(get_extension($path)).'.png'; |
---|
603 | } |
---|
604 | |
---|
605 | return $src; |
---|
606 | } |
---|
607 | |
---|
608 | // my_error returns (or send to standard output) the message concerning the |
---|
609 | // error occured for the last mysql query. |
---|
610 | function my_error($header) |
---|
611 | { |
---|
612 | $error = '<pre>'; |
---|
613 | $error.= $header; |
---|
614 | $error.= '[mysql error '.mysql_errno().'] '; |
---|
615 | $error.= mysql_error(); |
---|
616 | $error.= '</pre>'; |
---|
617 | die ($error); |
---|
618 | } |
---|
619 | |
---|
620 | /** |
---|
621 | * creates an array based on a query, this function is a very common pattern |
---|
622 | * used here |
---|
623 | * |
---|
624 | * @param string $query |
---|
625 | * @param string $fieldname |
---|
626 | * @return array |
---|
627 | */ |
---|
628 | function array_from_query($query, $fieldname) |
---|
629 | { |
---|
630 | $array = array(); |
---|
631 | |
---|
632 | $result = pwg_query($query); |
---|
633 | while ($row = mysql_fetch_array($result)) |
---|
634 | { |
---|
635 | array_push($array, $row[$fieldname]); |
---|
636 | } |
---|
637 | |
---|
638 | return $array; |
---|
639 | } |
---|
640 | |
---|
641 | /** |
---|
642 | * instantiate number list for days in a template block |
---|
643 | * |
---|
644 | * @param string blockname |
---|
645 | * @param string selection |
---|
646 | */ |
---|
647 | function get_day_list($blockname, $selection) |
---|
648 | { |
---|
649 | global $template; |
---|
650 | |
---|
651 | $template->assign_block_vars( |
---|
652 | $blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--')); |
---|
653 | |
---|
654 | for ($i = 1; $i <= 31; $i++) |
---|
655 | { |
---|
656 | $selected = ''; |
---|
657 | if ($i == (int)$selection) |
---|
658 | { |
---|
659 | $selected = 'selected="selected"'; |
---|
660 | } |
---|
661 | $template->assign_block_vars( |
---|
662 | $blockname, array('SELECTED' => $selected, |
---|
663 | 'VALUE' => $i, |
---|
664 | 'OPTION' => str_pad($i, 2, '0', STR_PAD_LEFT))); |
---|
665 | } |
---|
666 | } |
---|
667 | |
---|
668 | /** |
---|
669 | * instantiate month list in a template block |
---|
670 | * |
---|
671 | * @param string blockname |
---|
672 | * @param string selection |
---|
673 | */ |
---|
674 | function get_month_list($blockname, $selection) |
---|
675 | { |
---|
676 | global $template, $lang; |
---|
677 | |
---|
678 | $template->assign_block_vars( |
---|
679 | $blockname, array('SELECTED' => '', |
---|
680 | 'VALUE' => 0, |
---|
681 | 'OPTION' => '------------')); |
---|
682 | |
---|
683 | for ($i = 1; $i <= 12; $i++) |
---|
684 | { |
---|
685 | $selected = ''; |
---|
686 | if ($i == (int)$selection) |
---|
687 | { |
---|
688 | $selected = 'selected="selected"'; |
---|
689 | } |
---|
690 | $template->assign_block_vars( |
---|
691 | $blockname, array('SELECTED' => $selected, |
---|
692 | 'VALUE' => $i, |
---|
693 | 'OPTION' => $lang['month'][$i])); |
---|
694 | } |
---|
695 | } |
---|
696 | |
---|
697 | /** |
---|
698 | * fill the current user caddie with given elements, if not already in |
---|
699 | * caddie |
---|
700 | * |
---|
701 | * @param array elements_id |
---|
702 | */ |
---|
703 | function fill_caddie($elements_id) |
---|
704 | { |
---|
705 | global $user; |
---|
706 | |
---|
707 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
708 | |
---|
709 | $query = ' |
---|
710 | SELECT element_id |
---|
711 | FROM '.CADDIE_TABLE.' |
---|
712 | WHERE user_id = '.$user['id'].' |
---|
713 | ;'; |
---|
714 | $in_caddie = array_from_query($query, 'element_id'); |
---|
715 | |
---|
716 | $caddiables = array_diff($elements_id, $in_caddie); |
---|
717 | |
---|
718 | $datas = array(); |
---|
719 | |
---|
720 | foreach ($caddiables as $caddiable) |
---|
721 | { |
---|
722 | array_push($datas, array('element_id' => $caddiable, |
---|
723 | 'user_id' => $user['id'])); |
---|
724 | } |
---|
725 | |
---|
726 | if (count($caddiables) > 0) |
---|
727 | { |
---|
728 | mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas); |
---|
729 | } |
---|
730 | } |
---|
731 | |
---|
732 | /** |
---|
733 | * returns the element name from its filename |
---|
734 | * |
---|
735 | * @param string filename |
---|
736 | * @return string name |
---|
737 | */ |
---|
738 | function get_name_from_file($filename) |
---|
739 | { |
---|
740 | return str_replace('_',' ',get_filename_wo_extension($filename)); |
---|
741 | } |
---|
742 | |
---|
743 | /** |
---|
744 | * returns the corresponding value from $lang if existing. Else, the key is |
---|
745 | * returned |
---|
746 | * |
---|
747 | * @param string key |
---|
748 | * @return string |
---|
749 | */ |
---|
750 | function l10n($key) |
---|
751 | { |
---|
752 | global $lang, $conf; |
---|
753 | |
---|
754 | if ($conf['debug_l10n'] and !isset($lang[$key])) |
---|
755 | { |
---|
756 | echo '[l10n] language key "'.$key.'" is not defined<br />'; |
---|
757 | } |
---|
758 | |
---|
759 | return isset($lang[$key]) ? $lang[$key] : $key; |
---|
760 | } |
---|
761 | |
---|
762 | /** |
---|
763 | * returns the corresponding value from $themeconf if existing. Else, the |
---|
764 | * key is returned |
---|
765 | * |
---|
766 | * @param string key |
---|
767 | * @return string |
---|
768 | */ |
---|
769 | function get_themeconf($key) |
---|
770 | { |
---|
771 | global $themeconf; |
---|
772 | |
---|
773 | return $themeconf[$key]; |
---|
774 | } |
---|
775 | |
---|
776 | /** |
---|
777 | * Prepends and appends a string at each value of the given array. |
---|
778 | * |
---|
779 | * @param array |
---|
780 | * @param string prefix to each array values |
---|
781 | * @param string suffix to each array values |
---|
782 | */ |
---|
783 | function prepend_append_array_items($array, $prepend_str, $append_str) |
---|
784 | { |
---|
785 | array_walk( |
---|
786 | $array, |
---|
787 | create_function('&$s', '$s = "'.$prepend_str.'".$s."'.$append_str.'";') |
---|
788 | ); |
---|
789 | |
---|
790 | return $array; |
---|
791 | } |
---|
792 | |
---|
793 | /** |
---|
794 | * returns search rules stored into a serialized array in "search" |
---|
795 | * table. Each search rules set is numericaly identified. |
---|
796 | * |
---|
797 | * @param int search_id |
---|
798 | * @return array |
---|
799 | */ |
---|
800 | function get_search_array($search_id) |
---|
801 | { |
---|
802 | if (!is_numeric($search_id)) |
---|
803 | { |
---|
804 | die('Search id must be an integer'); |
---|
805 | } |
---|
806 | |
---|
807 | $query = ' |
---|
808 | SELECT rules |
---|
809 | FROM '.SEARCH_TABLE.' |
---|
810 | WHERE id = '.$search_id.' |
---|
811 | ;'; |
---|
812 | list($serialized_rules) = mysql_fetch_row(pwg_query($query)); |
---|
813 | |
---|
814 | return unserialize($serialized_rules); |
---|
815 | } |
---|
816 | |
---|
817 | /** |
---|
818 | * returns the SQL clause from a search identifier |
---|
819 | * |
---|
820 | * Search rules are stored in search table as a serialized array. This array |
---|
821 | * need to be transformed into an SQL clause to be used in queries. |
---|
822 | * |
---|
823 | * @param int search_id |
---|
824 | * @return string |
---|
825 | */ |
---|
826 | function get_sql_search_clause($search_id) |
---|
827 | { |
---|
828 | $search = get_search_array($search_id); |
---|
829 | |
---|
830 | // SQL where clauses are stored in $clauses array during query |
---|
831 | // construction |
---|
832 | $clauses = array(); |
---|
833 | |
---|
834 | foreach (array('file','name','comment','keywords','author') as $textfield) |
---|
835 | { |
---|
836 | if (isset($search['fields'][$textfield])) |
---|
837 | { |
---|
838 | $local_clauses = array(); |
---|
839 | foreach ($search['fields'][$textfield]['words'] as $word) |
---|
840 | { |
---|
841 | array_push($local_clauses, $textfield." LIKE '%".$word."%'"); |
---|
842 | } |
---|
843 | |
---|
844 | // adds brackets around where clauses |
---|
845 | $local_clauses = prepend_append_array_items($local_clauses, '(', ')'); |
---|
846 | |
---|
847 | array_push( |
---|
848 | $clauses, |
---|
849 | implode( |
---|
850 | ' '.$search['fields'][$textfield]['mode'].' ', |
---|
851 | $local_clauses |
---|
852 | ) |
---|
853 | ); |
---|
854 | } |
---|
855 | } |
---|
856 | |
---|
857 | if (isset($search['fields']['allwords'])) |
---|
858 | { |
---|
859 | $fields = array('file', 'name', 'comment', 'keywords', 'author'); |
---|
860 | // in the OR mode, request bust be : |
---|
861 | // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%') |
---|
862 | // OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%')) |
---|
863 | // |
---|
864 | // in the AND mode : |
---|
865 | // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%') |
---|
866 | // AND (field1 LIKE '%word2%' OR field2 LIKE '%word2%')) |
---|
867 | $word_clauses = array(); |
---|
868 | foreach ($search['fields']['allwords']['words'] as $word) |
---|
869 | { |
---|
870 | $field_clauses = array(); |
---|
871 | foreach ($fields as $field) |
---|
872 | { |
---|
873 | array_push($field_clauses, $field." LIKE '%".$word."%'"); |
---|
874 | } |
---|
875 | // adds brackets around where clauses |
---|
876 | array_push( |
---|
877 | $word_clauses, |
---|
878 | implode( |
---|
879 | "\n OR ", |
---|
880 | $field_clauses |
---|
881 | ) |
---|
882 | ); |
---|
883 | } |
---|
884 | |
---|
885 | array_walk( |
---|
886 | $word_clauses, |
---|
887 | create_function('&$s','$s="(".$s.")";') |
---|
888 | ); |
---|
889 | |
---|
890 | array_push( |
---|
891 | $clauses, |
---|
892 | "\n ". |
---|
893 | implode( |
---|
894 | "\n ". |
---|
895 | $search['fields']['allwords']['mode']. |
---|
896 | "\n ", |
---|
897 | $word_clauses |
---|
898 | ) |
---|
899 | ); |
---|
900 | } |
---|
901 | |
---|
902 | foreach (array('date_available', 'date_creation') as $datefield) |
---|
903 | { |
---|
904 | if (isset($search['fields'][$datefield])) |
---|
905 | { |
---|
906 | array_push( |
---|
907 | $clauses, |
---|
908 | $datefield." = '".$search['fields'][$datefield]['date']."'" |
---|
909 | ); |
---|
910 | } |
---|
911 | |
---|
912 | foreach (array('after','before') as $suffix) |
---|
913 | { |
---|
914 | $key = $datefield.'-'.$suffix; |
---|
915 | |
---|
916 | if (isset($search['fields'][$key])) |
---|
917 | { |
---|
918 | array_push( |
---|
919 | $clauses, |
---|
920 | |
---|
921 | $datefield. |
---|
922 | ($suffix == 'after' ? ' >' : ' <'). |
---|
923 | ($search['fields'][$key]['inc'] ? '=' : ''). |
---|
924 | " '".$search['fields'][$key]['date']."'" |
---|
925 | |
---|
926 | ); |
---|
927 | } |
---|
928 | } |
---|
929 | } |
---|
930 | |
---|
931 | if (isset($search['fields']['cat'])) |
---|
932 | { |
---|
933 | if ($search['fields']['cat']['sub_inc']) |
---|
934 | { |
---|
935 | // searching all the categories id of sub-categories |
---|
936 | $cat_ids = get_subcat_ids($search['fields']['cat']['words']); |
---|
937 | } |
---|
938 | else |
---|
939 | { |
---|
940 | $cat_ids = $search['fields']['cat']['words']; |
---|
941 | } |
---|
942 | |
---|
943 | $local_clause = 'category_id IN ('.implode(',', $cat_ids).')'; |
---|
944 | array_push($clauses, $local_clause); |
---|
945 | } |
---|
946 | |
---|
947 | // adds brackets around where clauses |
---|
948 | $clauses = prepend_append_array_items($clauses, '(', ')'); |
---|
949 | |
---|
950 | $where_separator = |
---|
951 | implode( |
---|
952 | "\n ".$search['mode'].' ', |
---|
953 | $clauses |
---|
954 | ); |
---|
955 | |
---|
956 | $search_clause = $where_separator; |
---|
957 | |
---|
958 | if (isset($forbidden)) |
---|
959 | { |
---|
960 | $search_clause.= "\n AND ".$forbidden; |
---|
961 | } |
---|
962 | |
---|
963 | return $search_clause; |
---|
964 | } |
---|
965 | |
---|
966 | /** |
---|
967 | * Returns webmaster mail address depending on $conf['webmaster_id'] |
---|
968 | * |
---|
969 | * @return string |
---|
970 | */ |
---|
971 | function get_webmaster_mail_address() |
---|
972 | { |
---|
973 | global $conf; |
---|
974 | |
---|
975 | $query = ' |
---|
976 | SELECT '.$conf['user_fields']['email'].' |
---|
977 | FROM '.USERS_TABLE.' |
---|
978 | WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].' |
---|
979 | ;'; |
---|
980 | list($email) = mysql_fetch_array(pwg_query($query)); |
---|
981 | |
---|
982 | return $email; |
---|
983 | } |
---|
984 | |
---|
985 | /** |
---|
986 | * which upgrades are available ? |
---|
987 | * |
---|
988 | * @return array |
---|
989 | */ |
---|
990 | function get_available_upgrade_ids() |
---|
991 | { |
---|
992 | $upgrades_path = PHPWG_ROOT_PATH.'install/db'; |
---|
993 | |
---|
994 | $available_upgrade_ids = array(); |
---|
995 | |
---|
996 | if ($contents = opendir($upgrades_path)) |
---|
997 | { |
---|
998 | while (($node = readdir($contents)) !== false) |
---|
999 | { |
---|
1000 | if (is_file($upgrades_path.'/'.$node) |
---|
1001 | and preg_match('/^(.*?)-database\.php$/', $node, $match)) |
---|
1002 | { |
---|
1003 | array_push($available_upgrade_ids, $match[1]); |
---|
1004 | } |
---|
1005 | } |
---|
1006 | } |
---|
1007 | natcasesort($available_upgrade_ids); |
---|
1008 | |
---|
1009 | return $available_upgrade_ids; |
---|
1010 | } |
---|
1011 | |
---|
1012 | /** |
---|
1013 | * returns a prefix for each url link on displayed page |
---|
1014 | * @return string |
---|
1015 | */ |
---|
1016 | function get_root_url() |
---|
1017 | { |
---|
1018 | global $page; |
---|
1019 | if ( isset($page['root_path']) ) |
---|
1020 | { |
---|
1021 | return $page['root_path']; |
---|
1022 | } |
---|
1023 | return PHPWG_ROOT_PATH; |
---|
1024 | } |
---|
1025 | |
---|
1026 | /** |
---|
1027 | * adds one or more _GET style parameters to an url |
---|
1028 | * example: add_url_params('/x', array('a'=>'b')) returns /x?a=b |
---|
1029 | * add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&a=b |
---|
1030 | * @param string url |
---|
1031 | * @param array params |
---|
1032 | * @return string |
---|
1033 | */ |
---|
1034 | function add_url_params($url, $params) |
---|
1035 | { |
---|
1036 | if ( !empty($params) ) |
---|
1037 | { |
---|
1038 | assert( is_array($params) ); |
---|
1039 | $is_first = true; |
---|
1040 | foreach($params as $param=>$val) |
---|
1041 | { |
---|
1042 | if ($is_first) |
---|
1043 | { |
---|
1044 | $is_first = false; |
---|
1045 | $url .= ( strstr($url, '?')===false ) ? '?' :'&'; |
---|
1046 | } |
---|
1047 | else |
---|
1048 | { |
---|
1049 | $url .= '&'; |
---|
1050 | } |
---|
1051 | $url .= $param; |
---|
1052 | if (isset($val)) |
---|
1053 | { |
---|
1054 | $url .= '='.$val; |
---|
1055 | } |
---|
1056 | } |
---|
1057 | } |
---|
1058 | return $url; |
---|
1059 | } |
---|
1060 | |
---|
1061 | /** |
---|
1062 | * build an index URL for a specific section |
---|
1063 | * |
---|
1064 | * @param array |
---|
1065 | * @return string |
---|
1066 | */ |
---|
1067 | function make_index_URL($params = array()) |
---|
1068 | { |
---|
1069 | global $conf; |
---|
1070 | $url = get_root_url().'category'; |
---|
1071 | if ($conf['question_mark_in_urls']) |
---|
1072 | { |
---|
1073 | } |
---|
1074 | if ($conf['php_extension_in_urls']) |
---|
1075 | { |
---|
1076 | $url .= '.php'; |
---|
1077 | } |
---|
1078 | $url.= make_section_in_URL($params); |
---|
1079 | $url = add_well_known_params_in_url($url, $params); |
---|
1080 | return $url; |
---|
1081 | } |
---|
1082 | |
---|
1083 | /** |
---|
1084 | * build an index URL with current page parameters, but with redefinitions |
---|
1085 | * and removes. |
---|
1086 | * |
---|
1087 | * duplicate_index_URL(array('category' => 12), array('start')) will create |
---|
1088 | * an index URL on the current section (categories), but on a redefined |
---|
1089 | * category and without the start URL parameter. |
---|
1090 | * |
---|
1091 | * @param array redefined keys |
---|
1092 | * @param array removed keys |
---|
1093 | * @return string |
---|
1094 | */ |
---|
1095 | function duplicate_index_URL($redefined = array(), $removed = array()) |
---|
1096 | { |
---|
1097 | return make_index_URL( |
---|
1098 | params_for_duplication($redefined, $removed) |
---|
1099 | ); |
---|
1100 | } |
---|
1101 | |
---|
1102 | /** |
---|
1103 | * returns $page global array with key redefined and key removed |
---|
1104 | * |
---|
1105 | * @param array redefined keys |
---|
1106 | * @param array removed keys |
---|
1107 | * @return array |
---|
1108 | */ |
---|
1109 | function params_for_duplication($redefined, $removed) |
---|
1110 | { |
---|
1111 | global $page; |
---|
1112 | |
---|
1113 | if (count($removed) > 0) |
---|
1114 | { |
---|
1115 | $params = array(); |
---|
1116 | |
---|
1117 | foreach ($page as $page_item_key => $page_item_value) |
---|
1118 | { |
---|
1119 | if (!in_array($page_item_key, $removed)) |
---|
1120 | { |
---|
1121 | $params[$page_item_key] = $page_item_value; |
---|
1122 | } |
---|
1123 | } |
---|
1124 | } |
---|
1125 | else |
---|
1126 | { |
---|
1127 | $params = $page; |
---|
1128 | } |
---|
1129 | |
---|
1130 | foreach ($redefined as $redefined_param => $redefined_value) |
---|
1131 | { |
---|
1132 | $params[$redefined_param] = $redefined_value; |
---|
1133 | } |
---|
1134 | |
---|
1135 | return $params; |
---|
1136 | } |
---|
1137 | |
---|
1138 | /** |
---|
1139 | * create a picture URL with current page parameters, but with redefinitions |
---|
1140 | * and removes. See duplicate_index_URL. |
---|
1141 | * |
---|
1142 | * @param array redefined keys |
---|
1143 | * @param array removed keys |
---|
1144 | * @return string |
---|
1145 | */ |
---|
1146 | function duplicate_picture_URL($redefined = array(), $removed = array()) |
---|
1147 | { |
---|
1148 | return make_picture_URL( |
---|
1149 | params_for_duplication($redefined, $removed) |
---|
1150 | ); |
---|
1151 | } |
---|
1152 | |
---|
1153 | /** |
---|
1154 | * create a picture URL on a specific section for a specific picture |
---|
1155 | * |
---|
1156 | * @param array |
---|
1157 | * @return string |
---|
1158 | */ |
---|
1159 | function make_picture_URL($params) |
---|
1160 | { |
---|
1161 | global $conf; |
---|
1162 | if (!isset($params['image_id'])) |
---|
1163 | { |
---|
1164 | die('make_picture_URL: image_id is a required parameter'); |
---|
1165 | } |
---|
1166 | |
---|
1167 | $url = get_root_url().'picture'; |
---|
1168 | if ($conf['php_extension_in_urls']) |
---|
1169 | { |
---|
1170 | $url .= '.php'; |
---|
1171 | } |
---|
1172 | if ($conf['question_mark_in_urls']) |
---|
1173 | { |
---|
1174 | $url .= '?'; |
---|
1175 | } |
---|
1176 | $url .= make_section_in_URL($params); |
---|
1177 | $url = add_well_known_params_in_url($url, $params); |
---|
1178 | $url.= '/'; |
---|
1179 | switch ( $conf['picture_url_style'] ) |
---|
1180 | { |
---|
1181 | case 'id-file': |
---|
1182 | $url .= $params['image_id'].'-'; |
---|
1183 | case 'file': |
---|
1184 | $url .= get_filename_wo_extension($params['image_file']).'.htm'; |
---|
1185 | break; |
---|
1186 | default: |
---|
1187 | $url .= $params['image_id']; |
---|
1188 | } |
---|
1189 | return $url; |
---|
1190 | } |
---|
1191 | |
---|
1192 | /** |
---|
1193 | *adds to the url the chronology and start parameters |
---|
1194 | */ |
---|
1195 | function add_well_known_params_in_url($url, $params) |
---|
1196 | { |
---|
1197 | if ( isset($params['chronology_field']) ) |
---|
1198 | { |
---|
1199 | $url .= '/'. $params['chronology_field']; |
---|
1200 | $url .= '-'. $params['chronology_style']; |
---|
1201 | if ( isset($params['chronology_view']) ) |
---|
1202 | { |
---|
1203 | $url .= '-'. $params['chronology_view']; |
---|
1204 | } |
---|
1205 | if ( !empty($params['chronology_date']) ) |
---|
1206 | { |
---|
1207 | $url .= '-'. implode('-', $params['chronology_date'] ); |
---|
1208 | } |
---|
1209 | } |
---|
1210 | |
---|
1211 | if (isset($params['start']) and $params['start'] > 0) |
---|
1212 | { |
---|
1213 | $url.= '/start-'.$params['start']; |
---|
1214 | } |
---|
1215 | return $url; |
---|
1216 | } |
---|
1217 | |
---|
1218 | /** |
---|
1219 | * return the section token of an index or picture URL. |
---|
1220 | * |
---|
1221 | * Depending on section, other parameters are required (see function code |
---|
1222 | * for details) |
---|
1223 | * |
---|
1224 | * @param array |
---|
1225 | * @return string |
---|
1226 | */ |
---|
1227 | function make_section_in_URL($params) |
---|
1228 | { |
---|
1229 | $section_string = ''; |
---|
1230 | |
---|
1231 | if (!isset($params['section'])) |
---|
1232 | { |
---|
1233 | if (isset($params['category'])) |
---|
1234 | { |
---|
1235 | $params['section'] = 'categories'; |
---|
1236 | } |
---|
1237 | else if (isset($params['tags'])) |
---|
1238 | { |
---|
1239 | $params['section'] = 'tags'; |
---|
1240 | } |
---|
1241 | else if (isset($params['list'])) |
---|
1242 | { |
---|
1243 | $params['section'] = 'list'; |
---|
1244 | } |
---|
1245 | else if (isset($params['search'])) |
---|
1246 | { |
---|
1247 | $params['section'] = 'search'; |
---|
1248 | } |
---|
1249 | } |
---|
1250 | |
---|
1251 | if (!isset($params['section'])) |
---|
1252 | { |
---|
1253 | $params['section'] = 'categories'; |
---|
1254 | } |
---|
1255 | |
---|
1256 | switch($params['section']) |
---|
1257 | { |
---|
1258 | case 'categories' : |
---|
1259 | { |
---|
1260 | if (!isset($params['category'])) |
---|
1261 | { |
---|
1262 | //$section_string.= '/categories'; |
---|
1263 | } |
---|
1264 | else |
---|
1265 | { |
---|
1266 | $section_string.= '/category/'.$params['category']; |
---|
1267 | } |
---|
1268 | |
---|
1269 | break; |
---|
1270 | } |
---|
1271 | case 'tags' : |
---|
1272 | { |
---|
1273 | if (!isset($params['tags']) or count($params['tags']) == 0) |
---|
1274 | { |
---|
1275 | die('make_section_in_URL: require at least one tag'); |
---|
1276 | } |
---|
1277 | |
---|
1278 | $section_string.= '/tags'; |
---|
1279 | |
---|
1280 | foreach ($params['tags'] as $tag) |
---|
1281 | { |
---|
1282 | $section_string.= '/'.$tag; |
---|
1283 | } |
---|
1284 | |
---|
1285 | break; |
---|
1286 | } |
---|
1287 | case 'search' : |
---|
1288 | { |
---|
1289 | if (!isset($params['search'])) |
---|
1290 | { |
---|
1291 | die('make_section_in_URL: require a search identifier'); |
---|
1292 | } |
---|
1293 | |
---|
1294 | $section_string.= '/search/'.$params['search']; |
---|
1295 | |
---|
1296 | break; |
---|
1297 | } |
---|
1298 | case 'list' : |
---|
1299 | { |
---|
1300 | if (!isset($params['list'])) |
---|
1301 | { |
---|
1302 | die('make_section_in_URL: require a list of items'); |
---|
1303 | } |
---|
1304 | |
---|
1305 | $section_string.= '/list/'.implode(',', $params['list']); |
---|
1306 | |
---|
1307 | break; |
---|
1308 | } |
---|
1309 | default : |
---|
1310 | { |
---|
1311 | $section_string.= '/'.$params['section']; |
---|
1312 | } |
---|
1313 | } |
---|
1314 | |
---|
1315 | return $section_string; |
---|
1316 | } |
---|
1317 | ?> |
---|