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