1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Extended Description |
---|
4 | Version: auto |
---|
5 | Description: Add multilinguale descriptions, banner, NMB, category name, etc... |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=175 |
---|
7 | Author: P@t & Grum |
---|
8 | */ |
---|
9 | |
---|
10 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
11 | define('EXTENDED_DESC_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
12 | load_language('plugin.lang', EXTENDED_DESC_PATH); |
---|
13 | |
---|
14 | global $conf; |
---|
15 | |
---|
16 | $extdesc_conf = array( |
---|
17 | 'more' => '<!--more-->', |
---|
18 | 'complete' => '<!--complete-->', |
---|
19 | 'up-down' => '<!--up-down-->', |
---|
20 | 'not_visible' => '<!--hidden-->', |
---|
21 | 'mb_not_visible' => '<!--mb-hidden-->' |
---|
22 | ); |
---|
23 | |
---|
24 | $conf['ExtendedDescription'] = isset($conf['ExtendedDescription']) ? |
---|
25 | array_merge($extdesc_conf, $conf['ExtendedDescription']) : |
---|
26 | $extdesc_conf; |
---|
27 | |
---|
28 | |
---|
29 | // Traite les balises [lang=xx] |
---|
30 | function get_user_language_desc($desc, $user_lang=null) |
---|
31 | { |
---|
32 | global $user; |
---|
33 | |
---|
34 | if (is_null($user_lang)) |
---|
35 | { |
---|
36 | $user_lang = $user['language']; |
---|
37 | } |
---|
38 | |
---|
39 | $small_user_lang = substr($user['language'], 0, 2); |
---|
40 | |
---|
41 | if (!preg_match('#\[lang=('.$user_lang.'|'.$small_user_lang.')\]#i', $desc)) |
---|
42 | { |
---|
43 | $user_lang = 'default'; |
---|
44 | $small_user_lang = 'default'; |
---|
45 | } |
---|
46 | |
---|
47 | if (preg_match('#\[lang=('.$user_lang.'|'.$small_user_lang.')\]#i', $desc)) |
---|
48 | { |
---|
49 | // la balise avec la langue de l'utilisateur a été trouvée |
---|
50 | $patterns[] = '#(^|\[/lang\])(.*?)(\[lang=(' . $user_lang . '|' . $small_user_lang . '|all)\]|$)#is'; |
---|
51 | $replacements[] = ''; |
---|
52 | $patterns[] = '#\[lang=(' . $user_lang . '|' . $small_user_lang . '|all)\](.*?)\[/lang\]#is'; |
---|
53 | $replacements[] = '\\1'; |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | // la balise avec la langue de l'utilisateur n'a pas été trouvée |
---|
58 | // On prend tout ce qui est hors balise |
---|
59 | $patterns[] = '#\[lang=all\](.*?)\[/lang\]#is'; |
---|
60 | $replacements[] = '\\1'; |
---|
61 | $patterns[] = '#\[lang=.*\].*\[/lang\]#is'; |
---|
62 | $replacements[] = ''; |
---|
63 | } |
---|
64 | return preg_replace($patterns, $replacements, $desc); |
---|
65 | } |
---|
66 | |
---|
67 | function get_user_language_tag_url($tag) |
---|
68 | { |
---|
69 | return get_user_language_desc($tag, get_default_language()); |
---|
70 | } |
---|
71 | |
---|
72 | function ed_get_all_alt_names($arr, $name) |
---|
73 | { |
---|
74 | if (preg_match_all('#\[lang=(.*?)\](.*?)\[/lang\]#is', $name, $matches)) |
---|
75 | { |
---|
76 | foreach ($matches[2] as $alt) |
---|
77 | { |
---|
78 | $arr[] = $alt; |
---|
79 | } |
---|
80 | } |
---|
81 | return $arr; |
---|
82 | } |
---|
83 | |
---|
84 | // Traite les autres balises |
---|
85 | function get_extended_desc($desc, $param='') |
---|
86 | { |
---|
87 | global $conf, $page; |
---|
88 | |
---|
89 | if ( |
---|
90 | $param != 'subcatify_category_description' |
---|
91 | and ( script_basename() != 'picture' or $param != 'main_page_category_description' ) |
---|
92 | and preg_match('#\[redirect (.*?)\]#i', $desc, $m1) |
---|
93 | ) |
---|
94 | { |
---|
95 | if (preg_match('#^(img|cat|search)=(\d*)\.?(\d*|)$#i', $m1[1], $m2)) |
---|
96 | { |
---|
97 | switch ($m2[1]) |
---|
98 | { |
---|
99 | case 'img': |
---|
100 | $url_params = array('image_id' => $m2[2]); |
---|
101 | if (!empty($m2[3])) |
---|
102 | { |
---|
103 | $url_params['category'] = array('id' => $m2[3], 'name' => '', 'permalink' => ''); |
---|
104 | } |
---|
105 | $url = rtrim(make_picture_url($url_params), '-'); |
---|
106 | break; |
---|
107 | |
---|
108 | case 'cat': |
---|
109 | $url_params = array('category' => array('id' => $m2[2], 'name' => '', 'permalink' => '')); |
---|
110 | $url = rtrim(make_index_url($url_params), '-'); |
---|
111 | break; |
---|
112 | |
---|
113 | case 'search': |
---|
114 | $url = make_index_url(array('section' => 'search', 'search' => $m2[2])); |
---|
115 | } |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | $url = $m1[1]; |
---|
120 | } |
---|
121 | if (is_admin()) |
---|
122 | { |
---|
123 | global $header_notes; |
---|
124 | $header_notes[] = sprintf(l10n('This category is redirected to %s'), '<a href="'.$url.'">'.$url.'</a>'); |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | redirect($url); |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | $desc = get_user_language_desc($desc); |
---|
133 | |
---|
134 | // Remove redirect tags for subcatify_category_description |
---|
135 | $patterns[] = '#\[redirect .*?\]#i'; |
---|
136 | $replacements[] = ''; |
---|
137 | |
---|
138 | // Balises [cat=xx] |
---|
139 | $patterns[] = '#\[cat=(\d*)\]#ie'; |
---|
140 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_cat_thumb("$1")'; |
---|
141 | |
---|
142 | // Balises [img=xx.yy,xx.yy,xx.yy;left|right|;name|titleName|] |
---|
143 | $patterns[] = '#\[img=([\d\s\.,]*);?(left|right|);?(name|titleName|)\]#ie'; |
---|
144 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_img_thumb("$1", "$2", "$3")'; |
---|
145 | |
---|
146 | // Balises [photo id=xx album=yy size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] |
---|
147 | $patterns[] = '#\[photo ([^\]]+)\]#ie'; |
---|
148 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1")'; |
---|
149 | |
---|
150 | // Balises [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] |
---|
151 | $patterns[] = '#\[random([^\]]*)\]#ie'; |
---|
152 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'extdesc_get_random_photo("$1")'; |
---|
153 | |
---|
154 | // Balises [slider album=xx nb_images=yy random=yes|no list=aa,bb,cc size=SQ|TH|XXS|XS|S|M|L|XL|XXL speed=z title=yes|no effect=... arrows=yes|no control=yes|no elastic=yes|no] |
---|
155 | $patterns[] = '#\[slider ([^\]]+)\]#ie'; |
---|
156 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_slider("$1")'; |
---|
157 | |
---|
158 | // Balises <!--complete-->, <!--more--> et <!--up-down--> |
---|
159 | switch ($param) |
---|
160 | { |
---|
161 | case 'subcatify_category_description' : |
---|
162 | $patterns[] = '#^(.*?)('. preg_quote($conf['ExtendedDescription']['complete']) . '|' . preg_quote($conf['ExtendedDescription']['more']) . '|' . preg_quote($conf['ExtendedDescription']['up-down']) . ').*$#is'; |
---|
163 | $replacements[] = '$1'; |
---|
164 | $desc = preg_replace($patterns, $replacements, $desc); |
---|
165 | break; |
---|
166 | |
---|
167 | case 'main_page_category_description' : |
---|
168 | $patterns[] = '#^.*' . preg_quote($conf['ExtendedDescription']['complete']) . '|' . preg_quote($conf['ExtendedDescription']['more']) . '#is'; |
---|
169 | $replacements[] = ''; |
---|
170 | $desc = preg_replace($patterns, $replacements, $desc); |
---|
171 | if (substr_count($desc, $conf['ExtendedDescription']['up-down'])) |
---|
172 | { |
---|
173 | list($desc, $conf['ExtendedDescription']['bottom_comment']) = explode($conf['ExtendedDescription']['up-down'], $desc); |
---|
174 | add_event_handler('loc_end_index', 'add_bottom_description'); |
---|
175 | } |
---|
176 | break; |
---|
177 | |
---|
178 | default: |
---|
179 | $desc = preg_replace($patterns, $replacements, $desc); |
---|
180 | } |
---|
181 | |
---|
182 | return $desc; |
---|
183 | } |
---|
184 | |
---|
185 | function extended_desc_mail_group_assign_vars($assign_vars) |
---|
186 | { |
---|
187 | if (isset($assign_vars['CPL_CONTENT'])) |
---|
188 | { |
---|
189 | $assign_vars['CPL_CONTENT'] = get_extended_desc($assign_vars['CPL_CONTENT']); |
---|
190 | } |
---|
191 | return $assign_vars; |
---|
192 | } |
---|
193 | |
---|
194 | // Add bottom description |
---|
195 | function add_bottom_description() |
---|
196 | { |
---|
197 | global $template, $conf; |
---|
198 | $template->concat('PLUGIN_INDEX_CONTENT_END', ' |
---|
199 | <div class="additional_info"> |
---|
200 | ' . $conf['ExtendedDescription']['bottom_comment'] . ' |
---|
201 | </div>'); |
---|
202 | } |
---|
203 | |
---|
204 | // Remove a category |
---|
205 | function ext_remove_cat($tpl_var) |
---|
206 | { |
---|
207 | global $conf; |
---|
208 | |
---|
209 | $i=0; |
---|
210 | while($i<count($tpl_var)) |
---|
211 | { |
---|
212 | if (substr_count($tpl_var[$i]['NAME'], $conf['ExtendedDescription']['not_visible'])) |
---|
213 | { |
---|
214 | array_splice($tpl_var, $i, 1); |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | $i++; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | return $tpl_var; |
---|
223 | } |
---|
224 | |
---|
225 | // Remove a category from menubar |
---|
226 | function ext_remove_menubar_cats($where) |
---|
227 | { |
---|
228 | global $conf; |
---|
229 | |
---|
230 | $query = 'SELECT id, uppercats |
---|
231 | FROM '.CATEGORIES_TABLE.' |
---|
232 | WHERE name LIKE "%'.$conf['ExtendedDescription']['mb_not_visible'].'%"'; |
---|
233 | |
---|
234 | $result = pwg_query($query); |
---|
235 | while ($row = pwg_db_fetch_assoc($result)) |
---|
236 | { |
---|
237 | $ids[] = $row['id']; |
---|
238 | $where .= ' |
---|
239 | AND uppercats NOT LIKE "'.$row['uppercats'].',%"'; |
---|
240 | } |
---|
241 | if (!empty($ids)) |
---|
242 | { |
---|
243 | $where .= ' |
---|
244 | AND id NOT IN ('.implode(',', $ids).')'; |
---|
245 | } |
---|
246 | return $where; |
---|
247 | } |
---|
248 | |
---|
249 | // Remove an image |
---|
250 | function ext_remove_image($tpl_var, $pictures) |
---|
251 | { |
---|
252 | global $conf; |
---|
253 | |
---|
254 | $i=0; |
---|
255 | while($i<count($tpl_var)) |
---|
256 | { |
---|
257 | if (substr_count($pictures[$i]['name'], $conf['ExtendedDescription']['not_visible'])) |
---|
258 | { |
---|
259 | array_splice($tpl_var, $i, 1); |
---|
260 | array_splice($pictures, $i, 1); |
---|
261 | } |
---|
262 | else |
---|
263 | { |
---|
264 | $i++; |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | return $tpl_var; |
---|
269 | } |
---|
270 | |
---|
271 | // Return html code for caterogy thumb |
---|
272 | function get_cat_thumb($elem_id) |
---|
273 | { |
---|
274 | global $template, $user; |
---|
275 | |
---|
276 | $query = ' |
---|
277 | SELECT |
---|
278 | cat.id, |
---|
279 | cat.name, |
---|
280 | cat.comment, |
---|
281 | cat.representative_picture_id, |
---|
282 | cat.permalink, |
---|
283 | uc.nb_images, |
---|
284 | uc.count_images, |
---|
285 | uc.count_categories, |
---|
286 | img.path |
---|
287 | FROM ' . CATEGORIES_TABLE . ' AS cat |
---|
288 | INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' as uc |
---|
289 | ON cat.id = uc.cat_id AND uc.user_id = '.$user['id'].' |
---|
290 | INNER JOIN ' . IMAGES_TABLE . ' AS img |
---|
291 | ON img.id = uc.user_representative_picture_id |
---|
292 | WHERE cat.id = ' . $elem_id . ';'; |
---|
293 | $result = pwg_query($query); |
---|
294 | |
---|
295 | if($result and $category = pwg_db_fetch_array($result)) |
---|
296 | { |
---|
297 | $template->set_filename('extended_description_content', dirname(__FILE__) . '/template/cat.tpl'); |
---|
298 | |
---|
299 | $template->assign( |
---|
300 | array( |
---|
301 | 'ID' => $category['id'], |
---|
302 | 'TN_SRC' => DerivativeImage::thumb_url(array( |
---|
303 | 'id' => $category['representative_picture_id'], |
---|
304 | 'path' => $category['path'], |
---|
305 | )), |
---|
306 | 'TN_ALT' => strip_tags($category['name']), |
---|
307 | 'URL' => make_index_url(array('category' => $category)), |
---|
308 | 'CAPTION_NB_IMAGES' => get_display_images_count |
---|
309 | ( |
---|
310 | $category['nb_images'], |
---|
311 | $category['count_images'], |
---|
312 | $category['count_categories'], |
---|
313 | true, |
---|
314 | '<br />' |
---|
315 | ), |
---|
316 | 'DESCRIPTION' => |
---|
317 | trigger_event('render_category_literal_description', |
---|
318 | trigger_event('render_category_description', |
---|
319 | @$category['comment'], |
---|
320 | 'subcatify_category_description')), |
---|
321 | 'NAME' => trigger_event( |
---|
322 | 'render_category_name', |
---|
323 | $category['name'], |
---|
324 | 'subcatify_category_name' |
---|
325 | ), |
---|
326 | ) |
---|
327 | ); |
---|
328 | |
---|
329 | return $template->parse('extended_description_content', true); |
---|
330 | } |
---|
331 | return ''; |
---|
332 | } |
---|
333 | |
---|
334 | // Return html code for img thumb |
---|
335 | //function get_img_thumb($elem_id, $cat_id='', $align='', $name='') |
---|
336 | function get_img_thumb($elem_ids, $align='', $name='') |
---|
337 | { |
---|
338 | global $template; |
---|
339 | |
---|
340 | $ids=explode(" ",$elem_ids); |
---|
341 | $assoc = array(); |
---|
342 | foreach($ids as $key=>$val) |
---|
343 | { |
---|
344 | list($a,$b)=array_pad(explode(".",$val),2,""); |
---|
345 | $assoc[$a] = $b; |
---|
346 | } |
---|
347 | |
---|
348 | $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id in (' . implode(',', array_keys($assoc)) . ');'; |
---|
349 | $result = pwg_query($query); |
---|
350 | |
---|
351 | if($result) |
---|
352 | { |
---|
353 | $template->set_filename('extended_description_content', dirname(__FILE__) . '/template/img.tpl'); |
---|
354 | |
---|
355 | $imglist=array(); |
---|
356 | while ($picture = pwg_db_fetch_array($result)) |
---|
357 | { |
---|
358 | $imglist[$picture["id"]]=$picture; |
---|
359 | } |
---|
360 | |
---|
361 | $img=array(); |
---|
362 | foreach ($imglist as $id => $picture) |
---|
363 | { |
---|
364 | if (!empty($assoc[$id])) |
---|
365 | { |
---|
366 | $url = make_picture_url(array( |
---|
367 | 'image_id' => $picture['id'], |
---|
368 | 'category' => array( |
---|
369 | 'id' => $assoc[$id], |
---|
370 | 'name' => '', |
---|
371 | 'permalink' => ''))); |
---|
372 | } |
---|
373 | else |
---|
374 | { |
---|
375 | $url = make_picture_url(array('image_id' => $picture['id'])); |
---|
376 | } |
---|
377 | |
---|
378 | $img[]=array( |
---|
379 | 'ID' => $picture['id'], |
---|
380 | 'IMAGE' => DerivativeImage::thumb_url($picture), |
---|
381 | 'IMAGE_ALT' => $picture['file'], |
---|
382 | 'IMG_TITLE' => ($name=="titleName")?htmlspecialchars($picture['name'], ENT_QUOTES):get_thumbnail_title($picture, $picture['name'], null), |
---|
383 | 'U_IMG_LINK' => $url, |
---|
384 | 'LEGEND' => ($name=="name")?$picture['name']:"", |
---|
385 | 'COMMENT' => $picture['file'], |
---|
386 | ); |
---|
387 | } |
---|
388 | |
---|
389 | $template->assign('img', $img); |
---|
390 | $template->assign('FLOAT', !empty($align) ? 'float: ' . $align . ';' : ''); |
---|
391 | return $template->parse('extended_description_content', true); |
---|
392 | } |
---|
393 | return ''; |
---|
394 | } |
---|
395 | |
---|
396 | /** |
---|
397 | * Return html code for a photo |
---|
398 | * |
---|
399 | * @int id: picture id |
---|
400 | * @int album: album to display picture in (default: null) |
---|
401 | * @string size: picture size (default: M) |
---|
402 | * @string html: return complete html structure (default: yes) |
---|
403 | * @string link: add a link to the picture (default: yes) |
---|
404 | */ |
---|
405 | function get_photo_sized($param) |
---|
406 | { |
---|
407 | global $template; |
---|
408 | |
---|
409 | $default_params = array( |
---|
410 | 'id' => array('\d+', null), |
---|
411 | 'album' => array('\d+', null), |
---|
412 | 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), |
---|
413 | 'html' => array('yes|no', 'yes'), |
---|
414 | 'link' => array('yes|no', 'yes'), |
---|
415 | ); |
---|
416 | |
---|
417 | $params = parse_parameters($param, $default_params); |
---|
418 | |
---|
419 | // check picture id |
---|
420 | if (empty($params['id'])) return 'missing picture id'; |
---|
421 | |
---|
422 | // parameters |
---|
423 | $params['link'] = $params['link']=='no' ? false : true; |
---|
424 | $params['html'] = $params['html']=='no' ? false : true; |
---|
425 | $deriv_type = get_deriv_type($params['size']); |
---|
426 | |
---|
427 | // get picture |
---|
428 | $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = '.$params['id'].';'; |
---|
429 | $result = pwg_query($query); |
---|
430 | |
---|
431 | if (pwg_db_num_rows($result)) |
---|
432 | { |
---|
433 | $picture = pwg_db_fetch_assoc($result); |
---|
434 | |
---|
435 | // url |
---|
436 | if ($params['link']) |
---|
437 | { |
---|
438 | if (!empty($params['album'])) |
---|
439 | { |
---|
440 | $query = ' |
---|
441 | SELECT id, name, permalink |
---|
442 | FROM '.CATEGORIES_TABLE.' |
---|
443 | WHERE id = '.$params['album'].' |
---|
444 | ;'; |
---|
445 | $category = pwg_db_fetch_assoc(pwg_query($query)); |
---|
446 | |
---|
447 | $url = make_picture_url(array( |
---|
448 | 'image_id' => $picture['id'], |
---|
449 | 'category' => array( |
---|
450 | 'id' => $category['id'], |
---|
451 | 'name' => $category['name'], |
---|
452 | 'permalink' => $category['permalink'], |
---|
453 | ))); |
---|
454 | } |
---|
455 | else |
---|
456 | { |
---|
457 | $url = make_picture_url(array('image_id' => $picture['id'])); |
---|
458 | } |
---|
459 | } |
---|
460 | |
---|
461 | // image |
---|
462 | $src_image = new SrcImage($picture); |
---|
463 | $derivatives = DerivativeImage::get_all($src_image); |
---|
464 | $selected_derivative = $derivatives[$deriv_type]; |
---|
465 | |
---|
466 | $template->assign(array( |
---|
467 | 'ed_image' => array( |
---|
468 | 'selected_derivative' => $selected_derivative, |
---|
469 | 'ALT_IMG' => $picture['file'], |
---|
470 | ))); |
---|
471 | |
---|
472 | // output |
---|
473 | if ($params['html']) |
---|
474 | { |
---|
475 | $template->set_filename('extended_description_content', dirname(__FILE__).'/template/picture_content.tpl'); |
---|
476 | $content = $template->parse('extended_description_content', true); |
---|
477 | if ($params['link']) return '<a href="'.$url.'">'.$content.'</a>'; |
---|
478 | else return $content; |
---|
479 | } |
---|
480 | else |
---|
481 | { |
---|
482 | return $selected_derivative->get_url(); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | return 'invalid picture id'; |
---|
487 | } |
---|
488 | |
---|
489 | /** |
---|
490 | * Return html code for a random photo |
---|
491 | * |
---|
492 | * @int album: select picture from this album (default: all) |
---|
493 | * @string size: picture size (default: M) |
---|
494 | * @string html: return complete html structure (default: yes) |
---|
495 | * @string link: add a link to the picture (default: no) |
---|
496 | */ |
---|
497 | function extdesc_get_random_photo($param) |
---|
498 | { |
---|
499 | $default_params = array( |
---|
500 | 'album' => array('\d+', null), |
---|
501 | 'cat' => array('\d+', null), // historical |
---|
502 | 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), |
---|
503 | 'html' => array('yes|no', 'yes'), |
---|
504 | 'link' => array('yes|no', 'no'), |
---|
505 | ); |
---|
506 | |
---|
507 | $params = parse_parameters($param, $default_params); |
---|
508 | |
---|
509 | // check album id |
---|
510 | if ( empty($params['album']) and !empty($params['cat']) ) |
---|
511 | { |
---|
512 | $params['album'] = $params['cat']; |
---|
513 | } |
---|
514 | |
---|
515 | // get picture id |
---|
516 | $query = ' |
---|
517 | SELECT id, category_id |
---|
518 | FROM '.IMAGES_TABLE.' |
---|
519 | JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id'; |
---|
520 | if (empty($params['album'])) |
---|
521 | { |
---|
522 | $query = ' |
---|
523 | WHERE 1=1 ' |
---|
524 | .get_sql_condition_FandF(array( |
---|
525 | 'forbidden_categories' => 'category_id', |
---|
526 | 'visible_categories' => 'category_id', |
---|
527 | 'visible_images' => 'id' |
---|
528 | ), |
---|
529 | 'AND' |
---|
530 | ); |
---|
531 | } |
---|
532 | else |
---|
533 | { |
---|
534 | $query.= ' |
---|
535 | WHERE category_id = '.$params['album']; |
---|
536 | } |
---|
537 | |
---|
538 | $query.= ' |
---|
539 | ORDER BY '.DB_RANDOM_FUNCTION.'() |
---|
540 | LIMIT 1 |
---|
541 | ;'; |
---|
542 | $result = pwg_query($query); |
---|
543 | |
---|
544 | if (pwg_db_num_rows($result)) |
---|
545 | { |
---|
546 | list($params['id'], $params['album']) = pwg_db_fetch_row($result); |
---|
547 | return get_photo_sized($params); |
---|
548 | } |
---|
549 | |
---|
550 | return ''; |
---|
551 | } |
---|
552 | |
---|
553 | /** |
---|
554 | * Return html code for a nivo slider (album or list is mandatory) |
---|
555 | * |
---|
556 | * @int album: select pictures from this album |
---|
557 | * @int nb_images: display only x pictures (default: 10) |
---|
558 | * @string random: random sort order (default: no) |
---|
559 | * |
---|
560 | * @string list: pictures id separated by a comma |
---|
561 | * |
---|
562 | * @string size: picture size (default: M) |
---|
563 | * @int speed: slideshow duration (default: 3) |
---|
564 | * @string title: display picture name (default: no) |
---|
565 | * @string effect: transition effect (default: fade) |
---|
566 | * @string arrows: display navigation arrows (default: yes) |
---|
567 | * @string control: display navigation bar (default: yes) |
---|
568 | * @string elastic: adapt slider size to each picture (default: yes) |
---|
569 | */ |
---|
570 | function get_slider($param) |
---|
571 | { |
---|
572 | global $template, $conf; |
---|
573 | |
---|
574 | $default_params = array( |
---|
575 | 'album' => array('\d+', null), |
---|
576 | 'nb_images' => array('\d+', 10), |
---|
577 | 'random' => array('yes|no', 'no'), |
---|
578 | 'list' => array('[\d,]+', null), |
---|
579 | 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), |
---|
580 | 'speed' => array('\d+', 3), |
---|
581 | 'title' => array('yes|no', 'no'), |
---|
582 | 'effect' => array('[a-zA-Z]+', 'fade'), |
---|
583 | 'arrows' => array('yes|no', 'yes'), |
---|
584 | 'control' => array('yes|no', 'yes'), |
---|
585 | 'elastic' => array('yes|no', 'yes'), |
---|
586 | ); |
---|
587 | |
---|
588 | $params = parse_parameters($param, $default_params); |
---|
589 | |
---|
590 | // check size |
---|
591 | $deriv_type = get_deriv_type($params['size']); |
---|
592 | $enabled = ImageStdParams::get_defined_type_map(); |
---|
593 | if (empty($enabled[ $deriv_type ])) return 'size disabled'; |
---|
594 | |
---|
595 | // parameters |
---|
596 | $params['arrows'] = $params['arrows']==='yes' ? 'true' : 'false'; |
---|
597 | $params['control'] = $params['control']==='yes' ? 'true' : 'false'; |
---|
598 | $params['elastic'] = $params['elastic']==='yes' ? true : false; |
---|
599 | $params['title'] = $params['title']==='yes' ? true : false; |
---|
600 | $params['random'] = $params['random']==='yes' ? true : false; |
---|
601 | |
---|
602 | // pictures from album... |
---|
603 | if (!empty($params['album'])) |
---|
604 | { |
---|
605 | // get image order inside category |
---|
606 | if ($params['random']) |
---|
607 | { |
---|
608 | $order_by = DB_RANDOM_FUNCTION.'()'; |
---|
609 | } |
---|
610 | else |
---|
611 | { |
---|
612 | $query = ' |
---|
613 | SELECT image_order |
---|
614 | FROM '.CATEGORIES_TABLE.' |
---|
615 | WHERE id = '.$params['album'].' |
---|
616 | ;'; |
---|
617 | list($order_by) = pwg_db_fetch_row(pwg_query($query)); |
---|
618 | if (empty($order_by)) |
---|
619 | { |
---|
620 | $order_by = str_replace('ORDER BY ', null, $conf['order_by_inside_category']); |
---|
621 | } |
---|
622 | } |
---|
623 | |
---|
624 | // get pictures ids |
---|
625 | $query = ' |
---|
626 | SELECT image_id |
---|
627 | FROM '.IMAGE_CATEGORY_TABLE.' as ic |
---|
628 | INNER JOIN '.IMAGES_TABLE.' as i |
---|
629 | ON i.id = ic.image_id |
---|
630 | WHERE category_id = '.$params['album'].' |
---|
631 | ORDER BY '.$order_by.' |
---|
632 | LIMIT '.$params['nb_images'].' |
---|
633 | ;'; |
---|
634 | $ids = array_from_query($query, 'image_id'); |
---|
635 | $ids = implode(',', $ids); |
---|
636 | } |
---|
637 | // ...or pictures list |
---|
638 | else if (empty($params['list'])) |
---|
639 | { |
---|
640 | return 'missing album id or empty picture list'; |
---|
641 | } |
---|
642 | else |
---|
643 | { |
---|
644 | $ids = $params['list']; |
---|
645 | } |
---|
646 | |
---|
647 | // get pictures |
---|
648 | $query = ' |
---|
649 | SELECT * |
---|
650 | FROM '.IMAGES_TABLE.' |
---|
651 | WHERE id IN ('.$ids.') |
---|
652 | ORDER BY FIND_IN_SET(id, "'.$ids.'") |
---|
653 | ;'; |
---|
654 | $pictures = hash_from_query($query, 'id'); |
---|
655 | |
---|
656 | foreach ($pictures as $row) |
---|
657 | { |
---|
658 | // url |
---|
659 | if (!empty($params['album'])) |
---|
660 | { |
---|
661 | $url = make_picture_url(array( |
---|
662 | 'image_id' => $row['id'], |
---|
663 | 'category' => array( |
---|
664 | 'id' => $params['album'], |
---|
665 | 'name' => '', |
---|
666 | 'permalink' => '', |
---|
667 | ))); |
---|
668 | } |
---|
669 | else |
---|
670 | { |
---|
671 | $url = make_picture_url(array('image_id' => $row['id'])); |
---|
672 | } |
---|
673 | |
---|
674 | $name = render_element_name($row); |
---|
675 | |
---|
676 | $tpl_vars[] = array_merge($row, array( |
---|
677 | 'TN_ALT' => htmlspecialchars(strip_tags($name)), |
---|
678 | 'NAME' => $name, |
---|
679 | 'URL' => $url, |
---|
680 | 'src_image' => new SrcImage($row), |
---|
681 | )); |
---|
682 | } |
---|
683 | |
---|
684 | list($img_size['w'], $img_size['h']) = $enabled[ $deriv_type ]->sizing->ideal_size; |
---|
685 | |
---|
686 | $template->assign(array( |
---|
687 | 'EXTENDED_DESC_PATH' => EXTENDED_DESC_PATH, |
---|
688 | 'slider_id' => crc32(uniqid($params['list'])), // need a unique id if we have multiple sliders |
---|
689 | 'slider_content' => $tpl_vars, |
---|
690 | 'derivative_params' => ImageStdParams::get_by_type( $deriv_type ), |
---|
691 | 'img_size' => $img_size, |
---|
692 | 'pauseTime' => $params['speed']*1000, |
---|
693 | 'controlNav' => $params['control'], |
---|
694 | 'effect' => $params['effect'], |
---|
695 | 'directionNav' => $params['arrows'], |
---|
696 | 'elastic_size' => $params['elastic'], |
---|
697 | 'show_title' => $params['title'], |
---|
698 | )); |
---|
699 | |
---|
700 | $template->set_filename('extended_description_content', dirname(__FILE__).'/template/slider.tpl'); |
---|
701 | return $template->parse('extended_description_content', true); |
---|
702 | } |
---|
703 | |
---|
704 | |
---|
705 | function parse_parameters($param, $default_params) |
---|
706 | { |
---|
707 | if (is_array($param)) |
---|
708 | { |
---|
709 | return $param; |
---|
710 | } |
---|
711 | |
---|
712 | $params = array(); |
---|
713 | |
---|
714 | foreach ($default_params as $name => $value) |
---|
715 | { |
---|
716 | if (preg_match('#'.$name.'=('.$value[0].')#', $param, $matches)) |
---|
717 | { |
---|
718 | $params[$name] = $matches[1]; |
---|
719 | } |
---|
720 | else |
---|
721 | { |
---|
722 | $params[$name] = $value[1]; |
---|
723 | } |
---|
724 | } |
---|
725 | |
---|
726 | return $params; |
---|
727 | } |
---|
728 | |
---|
729 | function get_deriv_type($size) |
---|
730 | { |
---|
731 | $size = strtoupper($size); |
---|
732 | |
---|
733 | $size_map = array( |
---|
734 | 'SQ' => IMG_SQUARE, |
---|
735 | 'TH' => IMG_THUMB, |
---|
736 | 'XXS' => IMG_XXSMALL, |
---|
737 | 'XS' => IMG_XSMALL, |
---|
738 | 'S' => IMG_SMALL, |
---|
739 | 'M' => IMG_MEDIUM, |
---|
740 | 'L' => IMG_LARGE, |
---|
741 | 'XL' => IMG_XLARGE, |
---|
742 | 'XXL' => IMG_XXLARGE, |
---|
743 | ); |
---|
744 | |
---|
745 | if (!array_key_exists($size, $size_map)) $size = 'M'; |
---|
746 | |
---|
747 | return $size_map[$size]; |
---|
748 | } |
---|
749 | |
---|
750 | |
---|
751 | if (script_basename() == 'admin' or script_basename() == 'popuphelp') |
---|
752 | { |
---|
753 | include(EXTENDED_DESC_PATH . 'admin.inc.php'); |
---|
754 | } |
---|
755 | |
---|
756 | // main |
---|
757 | add_event_handler ('get_extended_desc', 'get_extended_desc'); |
---|
758 | add_event_handler ('render_page_banner', 'get_extended_desc'); |
---|
759 | // categories |
---|
760 | add_event_handler ('render_category_name', 'get_user_language_desc'); |
---|
761 | add_event_handler ('render_category_description', 'get_extended_desc', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
762 | // tags |
---|
763 | add_event_handler ('render_tag_name', 'get_user_language_desc'); |
---|
764 | add_event_handler ('render_tag_url', 'get_user_language_tag_url', 40); |
---|
765 | add_event_handler ('get_tag_alt_names', 'ed_get_all_alt_names', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
766 | // element |
---|
767 | add_event_handler ('render_element_name', 'get_user_language_desc'); |
---|
768 | add_event_handler ('render_element_description', 'get_extended_desc'); |
---|
769 | // mail/nbm |
---|
770 | add_event_handler ('nbm_render_user_customize_mail_content', 'get_extended_desc'); |
---|
771 | add_event_handler ('mail_group_assign_vars', 'extended_desc_mail_group_assign_vars'); |
---|
772 | // removals |
---|
773 | add_event_handler ('loc_end_index_category_thumbnails', 'ext_remove_cat', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
774 | add_event_handler ('loc_end_index_thumbnails', 'ext_remove_image', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
775 | add_event_handler ('get_categories_menu_sql_where', 'ext_remove_menubar_cats'); |
---|
776 | |
---|
777 | ?> |
---|