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