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 ($param == 'main_page_category_description' and isset($page['category']) and !isset($page['image_id']) and preg_match('#\[redirect (.*?)\]#i', $desc, $m1)) |
---|
86 | { |
---|
87 | if (preg_match('#^(img|cat|search)=(\d*)\.?(\d*|)$#i', $m1[1], $m2)) |
---|
88 | { |
---|
89 | switch ($m2[1]) |
---|
90 | { |
---|
91 | case 'img': |
---|
92 | $url_params = array('image_id' => $m2[2]); |
---|
93 | if (!empty($m2[3])) |
---|
94 | { |
---|
95 | $url_params['category'] = array('id' => $m2[3], 'name' => '', 'permalink' => ''); |
---|
96 | } |
---|
97 | $url = rtrim(make_picture_url($url_params), '-'); |
---|
98 | break; |
---|
99 | |
---|
100 | case 'cat': |
---|
101 | $url_params = array('category' => array('id' => $m2[2], 'name' => '', 'permalink' => '')); |
---|
102 | $url = rtrim(make_index_url($url_params), '-'); |
---|
103 | break; |
---|
104 | |
---|
105 | case 'search': |
---|
106 | $url = make_index_url(array('section' => 'search', 'search' => $m2[2])); |
---|
107 | } |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | $url = $m1[1]; |
---|
112 | } |
---|
113 | if (is_admin()) |
---|
114 | { |
---|
115 | global $header_notes; |
---|
116 | $header_notes[] = sprintf(l10n('This category is redirected to %s'), '<a href="'.$url.'">'.$url.'</a>'); |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | redirect($url); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | $desc = get_user_language_desc($desc); |
---|
125 | |
---|
126 | // Remove redirect tags for subcatify_category_description |
---|
127 | $patterns[] = '#\[redirect .*?\]#i'; |
---|
128 | $replacements[] = ''; |
---|
129 | |
---|
130 | // Balises [cat=xx] |
---|
131 | $patterns[] = '#\[cat=(\d*)\]#ie'; |
---|
132 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_cat_thumb("$1")'; |
---|
133 | |
---|
134 | // Balises [img=xx.yy,xx.yy,xx.yy;left|right|;name|titleName|] |
---|
135 | //$patterns[] = '#\[img=(\d*)\.?(\d*|);?(left|right|);?(name|titleName|)\]#ie'; |
---|
136 | $patterns[] = '#\[img=([\d\s\.,]*);?(left|right|);?(name|titleName|)\]#ie'; |
---|
137 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_img_thumb("$1", "$2", "$3")'; |
---|
138 | |
---|
139 | // Balises [photo id=xx album=yy size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] |
---|
140 | // $patterns[] = '#\[photo(?:(?:\s+(id)=(\d+))|(?:\s+(album)=(\d+))|(?:\s+(size)=(SQ|TH|XXS|XS|S|M|L|XL|XXL))|(?:\s+(html)=(yes|no))|(?:\s+(link)=(yes|no))){1,5}\s*\]#ie'; //10 |
---|
141 | $patterns[] = '#\[photo ([^\]]+)\]#ie'; |
---|
142 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1")'; |
---|
143 | |
---|
144 | // Balises [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] |
---|
145 | // $patterns[] = '#\[random(?:(?:\s+(album|cat)=(\d+))|(?:\s+(size)=(SQ|TH|XXS|XS|S|M|L|XL|XXL))|(?:\s+(html)=(yes|no))|(?:\s+(link)=(yes|no))){1,4}\s*\]#ie'; //8 |
---|
146 | $patterns[] = '#\[random ([^\]]+)\]#ie'; |
---|
147 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'extdesc_get_random_photo("$1")'; |
---|
148 | |
---|
149 | // 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] |
---|
150 | // $patterns[] = '#\[slider(?:(?:\s+(album)=(\d+))|(?:\s+(nb_images)=(\d+))|(?:\s+(random)=(yes|no))|(?:\s+(list)=([\d,]+))|(?:\s+(size)=(SQ|TH|XXS|XS|S|M|L|XL|XXL))|(?:\s+(speed)=(\d+))|(?:\s+(title)=(yes|no))|(?:\s+(effect)=([a-zA-Z]+))|(?:\s+(arrows)=(yes|no))|(?:\s+(control)=(yes|no))|(?:\s+(elastic)=(yes|no))){1,11}\s*\]#ie'; //22 |
---|
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, $categories) |
---|
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 |
---|
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'])) |
---|
507 | { |
---|
508 | if (empty($params['cat'])) return 'missing album id'; |
---|
509 | $params['album'] = $params['cat']; |
---|
510 | } |
---|
511 | |
---|
512 | // get picture id |
---|
513 | $query = ' |
---|
514 | SELECT id |
---|
515 | FROM '.IMAGES_TABLE.' |
---|
516 | JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id |
---|
517 | WHERE category_id = '.$params['album'].' |
---|
518 | ORDER BY '.DB_RANDOM_FUNCTION.'() |
---|
519 | LIMIT 1 |
---|
520 | ;'; |
---|
521 | $result = pwg_query($query); |
---|
522 | |
---|
523 | if (pwg_db_num_rows($result)) |
---|
524 | { |
---|
525 | list($img_id) = pwg_db_fetch_row($result); |
---|
526 | return get_photo_sized('id='.$img_id.' album='.$params['album'].' size='.$params['size'].' html='.$params['html'].' link='.$params['link']); |
---|
527 | } |
---|
528 | |
---|
529 | return ''; |
---|
530 | } |
---|
531 | |
---|
532 | /** |
---|
533 | * Return html code for a nivo slider (album or list is mandatory) |
---|
534 | * |
---|
535 | * @int album: select pictures from this album |
---|
536 | * @int nb_images: display only x pictures (default: 10) |
---|
537 | * @string random: random sort order (default: no) |
---|
538 | * |
---|
539 | * @string list: pictures id separated by a comma |
---|
540 | * |
---|
541 | * @string size: picture size (default: M) |
---|
542 | * @int speed: slideshow duration (default: 3) |
---|
543 | * @string title: display picture name (default: no) |
---|
544 | * @string effect: transition effect (default: fade) |
---|
545 | * @string arrows: display navigation arrows (default: yes) |
---|
546 | * @string control: display navigation bar (default: yes) |
---|
547 | * @string elastic: adapt slider size to each picture (default: no) |
---|
548 | */ |
---|
549 | function get_slider($param) |
---|
550 | { |
---|
551 | global $template, $conf, $ids; // global $ids for the callback |
---|
552 | |
---|
553 | $default_params = array( |
---|
554 | 'album' => array('\d+', null), |
---|
555 | 'nb_images' => array('\d+', 10), |
---|
556 | 'random' => array('yes|no', 'no'), |
---|
557 | 'list' => array('[\d,]+', null), |
---|
558 | 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), |
---|
559 | 'speed' => array('\d+', 3), |
---|
560 | 'title' => array('yes|no', 'no'), |
---|
561 | 'effect' => array('[a-zA-Z]+', 'fade'), |
---|
562 | 'arrows' => array('yes|no', 'yes'), |
---|
563 | 'control' => array('yes|no', 'yes'), |
---|
564 | 'elastic' => array('yes|no', 'no'), |
---|
565 | ); |
---|
566 | |
---|
567 | $params = parse_parameters($param, $default_params); |
---|
568 | |
---|
569 | // check size |
---|
570 | $deriv_type = get_deriv_type($params['size']); |
---|
571 | $enabled = ImageStdParams::get_defined_type_map(); |
---|
572 | if (empty($enabled[ $deriv_type ])) return 'size disabled'; |
---|
573 | |
---|
574 | // parameters |
---|
575 | $params['arrows'] = $params['arrows']==='no' ? 'false' : 'true'; |
---|
576 | $params['control'] = $params['control']==='no' ? 'false' : 'true'; |
---|
577 | $params['elastic'] = $params['elastic']==='yes' ? true : false; |
---|
578 | $params['title'] = $params['title']==='yes' ? true : false; |
---|
579 | |
---|
580 | // pictures from album... |
---|
581 | if (!empty($params['album'])) |
---|
582 | { |
---|
583 | // parameters |
---|
584 | $params['random'] = $params['random']==='yes' ? true : false; |
---|
585 | |
---|
586 | // get image order inside category |
---|
587 | if ($params['random']) |
---|
588 | { |
---|
589 | $order_by = DB_RANDOM_FUNCTION.'()'; |
---|
590 | } |
---|
591 | else |
---|
592 | { |
---|
593 | $query = ' |
---|
594 | SELECT image_order |
---|
595 | FROM '.CATEGORIES_TABLE.' |
---|
596 | WHERE id = '.$params['album'].' |
---|
597 | ;'; |
---|
598 | list($order_by) = pwg_db_fetch_row(pwg_query($query)); |
---|
599 | if (empty($order_by)) |
---|
600 | { |
---|
601 | $order_by = str_replace('ORDER BY ', null, $conf['order_by_inside_category']); |
---|
602 | } |
---|
603 | } |
---|
604 | |
---|
605 | // get pictures ids |
---|
606 | $query = ' |
---|
607 | SELECT image_id |
---|
608 | FROM '.IMAGE_CATEGORY_TABLE.' as ic |
---|
609 | INNER JOIN '.IMAGES_TABLE.' as i |
---|
610 | ON i.id = ic.image_id |
---|
611 | WHERE category_id = '.$params['album'].' |
---|
612 | ORDER BY '.$order_by.' |
---|
613 | LIMIT '.$params['nb_images'].' |
---|
614 | ;'; |
---|
615 | $ids = array_from_query($query, 'image_id'); |
---|
616 | } |
---|
617 | // ...or pictures list |
---|
618 | else if (empty($params['list'])) |
---|
619 | { |
---|
620 | return 'missing album id or empty picture list'; |
---|
621 | } |
---|
622 | else |
---|
623 | { |
---|
624 | $ids = explode(',', $params['list']); |
---|
625 | } |
---|
626 | |
---|
627 | |
---|
628 | // get pictures |
---|
629 | $query = ' |
---|
630 | SELECT * |
---|
631 | FROM '.IMAGES_TABLE.' |
---|
632 | WHERE id IN ('.implode(',', $ids).') |
---|
633 | ;'; |
---|
634 | $pictures = hash_from_query($query, 'id'); |
---|
635 | |
---|
636 | // sort pictures |
---|
637 | if (!function_exists('ed_rank_sort')) |
---|
638 | { |
---|
639 | function ed_rank_sort($a, $b) |
---|
640 | { |
---|
641 | global $ids; |
---|
642 | return array_search($a, $ids) > array_search($b, $ids); |
---|
643 | } |
---|
644 | } |
---|
645 | uksort($pictures, 'ed_rank_sort'); |
---|
646 | |
---|
647 | foreach ($pictures as $row) |
---|
648 | { |
---|
649 | // url |
---|
650 | if (!empty($params['album'])) |
---|
651 | { |
---|
652 | $url = make_picture_url(array( |
---|
653 | 'image_id' => $row['id'], |
---|
654 | 'category' => array( |
---|
655 | 'id' => $params['album'], |
---|
656 | 'name' => '', |
---|
657 | 'permalink' => '', |
---|
658 | ))); |
---|
659 | } |
---|
660 | else |
---|
661 | { |
---|
662 | $url = make_picture_url(array('image_id' => $row['id'])); |
---|
663 | } |
---|
664 | |
---|
665 | $name = render_element_name($row); |
---|
666 | |
---|
667 | $tpl_vars[] = array_merge($row, array( |
---|
668 | 'TN_ALT' => htmlspecialchars(strip_tags($name)), |
---|
669 | 'NAME' => $name, |
---|
670 | 'URL' => $url, |
---|
671 | 'src_image' => new SrcImage($row), |
---|
672 | )); |
---|
673 | } |
---|
674 | |
---|
675 | list($img_size['w'], $img_size['h']) = $enabled[ $deriv_type ]->sizing->ideal_size; |
---|
676 | |
---|
677 | $template->assign(array( |
---|
678 | 'EXTENDED_DESC_PATH' => EXTENDED_DESC_PATH, |
---|
679 | 'slider_id' => crc32(uniqid($params['list'])), // need a unique id if we have multiple sliders |
---|
680 | 'slider_content' => $tpl_vars, |
---|
681 | 'derivative_params' => ImageStdParams::get_by_type( $deriv_type ), |
---|
682 | 'img_size' => $img_size, |
---|
683 | 'pauseTime' => $params['speed']*1000, |
---|
684 | 'controlNav' => $params['control'], |
---|
685 | 'effect' => $params['effect'], |
---|
686 | 'directionNav' => $params['arrows'], |
---|
687 | 'elastic_size' => $params['elastic'], |
---|
688 | 'show_title' => $params['title'], |
---|
689 | )); |
---|
690 | |
---|
691 | $template->set_filename('extended_description_content', dirname(__FILE__).'/template/slider.tpl'); |
---|
692 | return $template->parse('extended_description_content', true); |
---|
693 | } |
---|
694 | |
---|
695 | |
---|
696 | function parse_parameters($param, $default_params) |
---|
697 | { |
---|
698 | $params = array(); |
---|
699 | |
---|
700 | foreach ($default_params as $name => $value) |
---|
701 | { |
---|
702 | if (preg_match('#'.$name.'=('.$value[0].')#', $param, $matches)) |
---|
703 | { |
---|
704 | $params[$name] = $matches[1]; |
---|
705 | } |
---|
706 | else |
---|
707 | { |
---|
708 | $params[$name] = $value[1]; |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | return $params; |
---|
713 | } |
---|
714 | |
---|
715 | function get_deriv_type($size) |
---|
716 | { |
---|
717 | $size_map = array( |
---|
718 | 'SQ' => IMG_SQUARE, |
---|
719 | 'TH' => IMG_THUMB, |
---|
720 | 'XXS' => IMG_XXSMALL, |
---|
721 | 'XS' => IMG_XSMALL, |
---|
722 | 'S' => IMG_SMALL, |
---|
723 | 'M' => IMG_MEDIUM, |
---|
724 | 'L' => IMG_LARGE, |
---|
725 | 'XL' => IMG_XLARGE, |
---|
726 | 'XXL' => IMG_XXLARGE, |
---|
727 | ); |
---|
728 | |
---|
729 | if (!array_key_exists($size, $size_map)) $size = 'M'; |
---|
730 | |
---|
731 | return $size_map[ strtoupper($size) ]; |
---|
732 | } |
---|
733 | |
---|
734 | |
---|
735 | if (script_basename() == 'admin' or script_basename() == 'popuphelp') |
---|
736 | { |
---|
737 | include(EXTENDED_DESC_PATH . 'admin.inc.php'); |
---|
738 | } |
---|
739 | |
---|
740 | add_event_handler ('render_page_banner', 'get_extended_desc'); |
---|
741 | add_event_handler ('render_category_name', 'get_user_language_desc'); |
---|
742 | add_event_handler ('render_category_description', 'get_extended_desc', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
743 | add_event_handler ('render_tag_name', 'get_user_language_desc'); |
---|
744 | add_event_handler ('render_tag_url', 'get_user_language_tag_url', 40); |
---|
745 | add_event_handler ('get_tag_alt_names', 'ed_get_all_alt_names', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
746 | add_event_handler ('render_element_description', 'get_extended_desc'); |
---|
747 | add_event_handler ('nbm_render_user_customize_mail_content', 'get_extended_desc'); |
---|
748 | add_event_handler ('mail_group_assign_vars', 'extended_desc_mail_group_assign_vars'); |
---|
749 | add_event_handler ('loc_end_index_category_thumbnails', 'ext_remove_cat', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
750 | add_event_handler ('loc_end_index_thumbnails', 'ext_remove_image', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
751 | add_event_handler ('get_categories_menu_sql_where', 'ext_remove_menubar_cats'); |
---|
752 | ?> |
---|