[7015] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Extended Description |
---|
[12554] | 4 | Version: auto |
---|
[7015] | 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] |
---|
[12554] | 30 | function get_user_language_desc($desc, $user_lang=null) |
---|
[7015] | 31 | { |
---|
[12554] | 32 | if (is_null($user_lang)) |
---|
| 33 | { |
---|
| 34 | global $user; |
---|
| 35 | $user_lang = substr($user['language'], 0, 2); |
---|
| 36 | } |
---|
[7015] | 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 | |
---|
[12554] | 63 | function get_user_language_tag_url($tag) |
---|
| 64 | { |
---|
| 65 | return get_user_language_desc($tag, get_default_language()); |
---|
| 66 | } |
---|
| 67 | |
---|
[17767] | 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 | |
---|
[7015] | 80 | // Traite les autres balises |
---|
| 81 | function get_extended_desc($desc, $param='') |
---|
| 82 | { |
---|
[8314] | 83 | global $conf, $page; |
---|
[19159] | 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 | ) |
---|
[8314] | 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 | } |
---|
[9437] | 101 | $url = rtrim(make_picture_url($url_params), '-'); |
---|
[8314] | 102 | break; |
---|
| 103 | |
---|
| 104 | case 'cat': |
---|
| 105 | $url_params = array('category' => array('id' => $m2[2], 'name' => '', 'permalink' => '')); |
---|
[9437] | 106 | $url = rtrim(make_index_url($url_params), '-'); |
---|
[8314] | 107 | break; |
---|
| 108 | |
---|
| 109 | case 'search': |
---|
[9437] | 110 | $url = make_index_url(array('section' => 'search', 'search' => $m2[2])); |
---|
[8314] | 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 | |
---|
[7015] | 128 | $desc = get_user_language_desc($desc); |
---|
| 129 | |
---|
[8314] | 130 | // Remove redirect tags for subcatify_category_description |
---|
| 131 | $patterns[] = '#\[redirect .*?\]#i'; |
---|
| 132 | $replacements[] = ''; |
---|
| 133 | |
---|
[7015] | 134 | // Balises [cat=xx] |
---|
| 135 | $patterns[] = '#\[cat=(\d*)\]#ie'; |
---|
| 136 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_cat_thumb("$1")'; |
---|
| 137 | |
---|
[16120] | 138 | // Balises [img=xx.yy,xx.yy,xx.yy;left|right|;name|titleName|] |
---|
[17010] | 139 | $patterns[] = '#\[img=([\d\s\.,]*);?(left|right|);?(name|titleName|)\]#ie'; |
---|
[7015] | 140 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_img_thumb("$1", "$2", "$3")'; |
---|
[16120] | 141 | |
---|
[16125] | 142 | // Balises [photo id=xx album=yy size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] |
---|
[17010] | 143 | $patterns[] = '#\[photo ([^\]]+)\]#ie'; |
---|
| 144 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1")'; |
---|
[7015] | 145 | |
---|
[16125] | 146 | // Balises [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] |
---|
[19282] | 147 | $patterns[] = '#\[random([^\]]*)\]#ie'; |
---|
[17010] | 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")'; |
---|
[7015] | 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 | { |
---|
[10754] | 169 | list($desc, $conf['ExtendedDescription']['bottom_comment']) = explode($conf['ExtendedDescription']['up-down'], $desc); |
---|
| 170 | add_event_handler('loc_end_index', 'add_bottom_description'); |
---|
[7015] | 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 | |
---|
[10754] | 190 | // Add bottom description |
---|
| 191 | function add_bottom_description() |
---|
[7015] | 192 | { |
---|
| 193 | global $template, $conf; |
---|
[10754] | 194 | $template->concat('PLUGIN_INDEX_CONTENT_END', ' |
---|
[7015] | 195 | <div class="additional_info"> |
---|
[10754] | 196 | ' . $conf['ExtendedDescription']['bottom_comment'] . ' |
---|
[7015] | 197 | </div>'); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | // Remove a category |
---|
[19159] | 201 | function ext_remove_cat($tpl_var) |
---|
[7015] | 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); |
---|
[19840] | 231 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[7015] | 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 | { |
---|
[12400] | 270 | global $template, $user; |
---|
[7015] | 271 | |
---|
[16119] | 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 |
---|
[12400] | 283 | FROM ' . CATEGORIES_TABLE . ' AS cat |
---|
[16119] | 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 |
---|
[12400] | 288 | WHERE cat.id = ' . $elem_id . ';'; |
---|
[7015] | 289 | $result = pwg_query($query); |
---|
| 290 | |
---|
[19840] | 291 | if($result and $category = pwg_db_fetch_array($result)) |
---|
[7015] | 292 | { |
---|
| 293 | $template->set_filename('extended_description_content', dirname(__FILE__) . '/template/cat.tpl'); |
---|
[12400] | 294 | |
---|
| 295 | $template->assign( |
---|
| 296 | array( |
---|
| 297 | 'ID' => $category['id'], |
---|
[16119] | 298 | 'TN_SRC' => DerivativeImage::thumb_url(array( |
---|
| 299 | 'id' => $category['representative_picture_id'], |
---|
| 300 | 'path' => $category['path'], |
---|
| 301 | )), |
---|
[12400] | 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 | |
---|
[7015] | 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,""); |
---|
[16119] | 341 | $assoc[$a] = $b; |
---|
[7015] | 342 | } |
---|
| 343 | |
---|
[16119] | 344 | $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id in (' . implode(',', array_keys($assoc)) . ');'; |
---|
[7015] | 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(); |
---|
[19840] | 352 | while ($picture = pwg_db_fetch_array($result)) |
---|
[7015] | 353 | { |
---|
| 354 | $imglist[$picture["id"]]=$picture; |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | $img=array(); |
---|
[16119] | 358 | foreach ($imglist as $id => $picture) |
---|
[7015] | 359 | { |
---|
[16119] | 360 | if (!empty($assoc[$id])) |
---|
[7015] | 361 | { |
---|
| 362 | $url = make_picture_url(array( |
---|
[16119] | 363 | 'image_id' => $picture['id'], |
---|
[7015] | 364 | 'category' => array( |
---|
[16119] | 365 | 'id' => $assoc[$id], |
---|
[7015] | 366 | 'name' => '', |
---|
| 367 | 'permalink' => ''))); |
---|
| 368 | } |
---|
| 369 | else |
---|
| 370 | { |
---|
[16119] | 371 | $url = make_picture_url(array('image_id' => $picture['id'])); |
---|
[7015] | 372 | } |
---|
[16119] | 373 | |
---|
[7015] | 374 | $img[]=array( |
---|
[16119] | 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), |
---|
[7015] | 379 | 'U_IMG_LINK' => $url, |
---|
[16119] | 380 | 'LEGEND' => ($name=="name")?$picture['name']:"", |
---|
| 381 | 'COMMENT' => $picture['file'], |
---|
| 382 | ); |
---|
[7015] | 383 | } |
---|
[16119] | 384 | |
---|
| 385 | $template->assign('img', $img); |
---|
| 386 | $template->assign('FLOAT', !empty($align) ? 'float: ' . $align . ';' : ''); |
---|
[7015] | 387 | return $template->parse('extended_description_content', true); |
---|
| 388 | } |
---|
| 389 | return ''; |
---|
| 390 | } |
---|
| 391 | |
---|
[17010] | 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) |
---|
[16120] | 402 | { |
---|
| 403 | global $template; |
---|
[16121] | 404 | |
---|
[17010] | 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'), |
---|
[16120] | 411 | ); |
---|
| 412 | |
---|
[17010] | 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']); |
---|
[16120] | 422 | |
---|
[17010] | 423 | // get picture |
---|
| 424 | $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = '.$params['id'].';'; |
---|
[16120] | 425 | $result = pwg_query($query); |
---|
| 426 | |
---|
[16123] | 427 | if (pwg_db_num_rows($result)) |
---|
[16120] | 428 | { |
---|
[16123] | 429 | $picture = pwg_db_fetch_assoc($result); |
---|
[16120] | 430 | |
---|
| 431 | // url |
---|
[17010] | 432 | if ($params['link']) |
---|
[16120] | 433 | { |
---|
[17010] | 434 | if (!empty($params['album'])) |
---|
| 435 | { |
---|
[17433] | 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 | |
---|
[17010] | 443 | $url = make_picture_url(array( |
---|
| 444 | 'image_id' => $picture['id'], |
---|
| 445 | 'category' => array( |
---|
[17433] | 446 | 'id' => $category['id'], |
---|
| 447 | 'name' => $category['name'], |
---|
| 448 | 'permalink' => $category['permalink'], |
---|
[17010] | 449 | ))); |
---|
| 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
| 453 | $url = make_picture_url(array('image_id' => $picture['id'])); |
---|
| 454 | } |
---|
[16120] | 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( |
---|
[17180] | 463 | 'ed_image' => array( |
---|
[16120] | 464 | 'selected_derivative' => $selected_derivative, |
---|
[17180] | 465 | 'ALT_IMG' => $picture['file'], |
---|
| 466 | ))); |
---|
[16120] | 467 | |
---|
[17010] | 468 | // output |
---|
| 469 | if ($params['html']) |
---|
[16121] | 470 | { |
---|
[17010] | 471 | $template->set_filename('extended_description_content', dirname(__FILE__).'/template/picture_content.tpl'); |
---|
[16125] | 472 | $content = $template->parse('extended_description_content', true); |
---|
[17010] | 473 | if ($params['link']) return '<a href="'.$url.'">'.$content.'</a>'; |
---|
| 474 | else return $content; |
---|
[16121] | 475 | } |
---|
| 476 | else |
---|
| 477 | { |
---|
[16125] | 478 | return $selected_derivative->get_url(); |
---|
[16121] | 479 | } |
---|
[16120] | 480 | } |
---|
| 481 | |
---|
[17010] | 482 | return 'invalid picture id'; |
---|
[16120] | 483 | } |
---|
| 484 | |
---|
[17010] | 485 | /** |
---|
| 486 | * Return html code for a random photo |
---|
| 487 | * |
---|
[19282] | 488 | * @int album: select picture from this album (default: all) |
---|
[17010] | 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) |
---|
[12400] | 494 | { |
---|
[17010] | 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 |
---|
[19282] | 506 | if ( empty($params['album']) and !empty($params['cat']) ) |
---|
[16969] | 507 | { |
---|
[17010] | 508 | $params['album'] = $params['cat']; |
---|
[16969] | 509 | } |
---|
[12400] | 510 | |
---|
[17010] | 511 | // get picture id |
---|
[12400] | 512 | $query = ' |
---|
[19282] | 513 | SELECT id, category_id |
---|
[12400] | 514 | FROM '.IMAGES_TABLE.' |
---|
| 515 | JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id |
---|
[19282] | 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.= ' |
---|
[12400] | 528 | ORDER BY '.DB_RANDOM_FUNCTION.'() |
---|
| 529 | LIMIT 1 |
---|
| 530 | ;'; |
---|
| 531 | $result = pwg_query($query); |
---|
[16123] | 532 | |
---|
| 533 | if (pwg_db_num_rows($result)) |
---|
[12400] | 534 | { |
---|
[19282] | 535 | list($params['id'], $params['album']) = pwg_db_fetch_row($result); |
---|
| 536 | return get_photo_sized($params); |
---|
[12400] | 537 | } |
---|
| 538 | |
---|
| 539 | return ''; |
---|
| 540 | } |
---|
| 541 | |
---|
[17010] | 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) |
---|
[19282] | 557 | * @string elastic: adapt slider size to each picture (default: yes) |
---|
[17010] | 558 | */ |
---|
| 559 | function get_slider($param) |
---|
| 560 | { |
---|
[19283] | 561 | global $template, $conf; |
---|
[17010] | 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'), |
---|
[19282] | 574 | 'elastic' => array('yes|no', 'yes'), |
---|
[17010] | 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 |
---|
[19282] | 585 | $params['arrows'] = $params['arrows']==='yes' ? 'true' : 'false'; |
---|
| 586 | $params['control'] = $params['control']==='yes' ? 'true' : 'false'; |
---|
[17010] | 587 | $params['elastic'] = $params['elastic']==='yes' ? true : false; |
---|
| 588 | $params['title'] = $params['title']==='yes' ? true : false; |
---|
[19282] | 589 | $params['random'] = $params['random']==='yes' ? true : false; |
---|
[17010] | 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 | ;'; |
---|
[17181] | 623 | $ids = array_from_query($query, 'image_id'); |
---|
[19840] | 624 | $ids = implode(',', $ids); |
---|
[17010] | 625 | } |
---|
| 626 | // ...or pictures list |
---|
[17181] | 627 | else if (empty($params['list'])) |
---|
[17010] | 628 | { |
---|
| 629 | return 'missing album id or empty picture list'; |
---|
| 630 | } |
---|
[17181] | 631 | else |
---|
| 632 | { |
---|
[19840] | 633 | $ids = $params['list']; |
---|
[17181] | 634 | } |
---|
[17010] | 635 | |
---|
| 636 | // get pictures |
---|
| 637 | $query = ' |
---|
| 638 | SELECT * |
---|
| 639 | FROM '.IMAGES_TABLE.' |
---|
[19840] | 640 | WHERE id IN ('.$ids.') |
---|
| 641 | ORDER BY FIND_IN_SET(id, "'.$ids.'") |
---|
[17010] | 642 | ;'; |
---|
| 643 | $pictures = hash_from_query($query, 'id'); |
---|
[17181] | 644 | |
---|
[17010] | 645 | foreach ($pictures as $row) |
---|
| 646 | { |
---|
| 647 | // url |
---|
| 648 | if (!empty($params['album'])) |
---|
| 649 | { |
---|
| 650 | $url = make_picture_url(array( |
---|
| 651 | 'image_id' => $row['id'], |
---|
| 652 | 'category' => array( |
---|
| 653 | 'id' => $params['album'], |
---|
| 654 | 'name' => '', |
---|
| 655 | 'permalink' => '', |
---|
| 656 | ))); |
---|
| 657 | } |
---|
| 658 | else |
---|
| 659 | { |
---|
| 660 | $url = make_picture_url(array('image_id' => $row['id'])); |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | $name = render_element_name($row); |
---|
| 664 | |
---|
| 665 | $tpl_vars[] = array_merge($row, array( |
---|
| 666 | 'TN_ALT' => htmlspecialchars(strip_tags($name)), |
---|
| 667 | 'NAME' => $name, |
---|
| 668 | 'URL' => $url, |
---|
| 669 | 'src_image' => new SrcImage($row), |
---|
| 670 | )); |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | list($img_size['w'], $img_size['h']) = $enabled[ $deriv_type ]->sizing->ideal_size; |
---|
| 674 | |
---|
| 675 | $template->assign(array( |
---|
| 676 | 'EXTENDED_DESC_PATH' => EXTENDED_DESC_PATH, |
---|
| 677 | 'slider_id' => crc32(uniqid($params['list'])), // need a unique id if we have multiple sliders |
---|
| 678 | 'slider_content' => $tpl_vars, |
---|
| 679 | 'derivative_params' => ImageStdParams::get_by_type( $deriv_type ), |
---|
| 680 | 'img_size' => $img_size, |
---|
| 681 | 'pauseTime' => $params['speed']*1000, |
---|
| 682 | 'controlNav' => $params['control'], |
---|
| 683 | 'effect' => $params['effect'], |
---|
| 684 | 'directionNav' => $params['arrows'], |
---|
| 685 | 'elastic_size' => $params['elastic'], |
---|
| 686 | 'show_title' => $params['title'], |
---|
| 687 | )); |
---|
| 688 | |
---|
| 689 | $template->set_filename('extended_description_content', dirname(__FILE__).'/template/slider.tpl'); |
---|
| 690 | return $template->parse('extended_description_content', true); |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | |
---|
| 694 | function parse_parameters($param, $default_params) |
---|
| 695 | { |
---|
[19282] | 696 | if (is_array($param)) |
---|
| 697 | { |
---|
| 698 | return $param; |
---|
| 699 | } |
---|
| 700 | |
---|
[17010] | 701 | $params = array(); |
---|
| 702 | |
---|
| 703 | foreach ($default_params as $name => $value) |
---|
| 704 | { |
---|
| 705 | if (preg_match('#'.$name.'=('.$value[0].')#', $param, $matches)) |
---|
| 706 | { |
---|
| 707 | $params[$name] = $matches[1]; |
---|
| 708 | } |
---|
| 709 | else |
---|
| 710 | { |
---|
| 711 | $params[$name] = $value[1]; |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | return $params; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | function get_deriv_type($size) |
---|
| 719 | { |
---|
[19840] | 720 | $size = strtoupper($size); |
---|
| 721 | |
---|
[17010] | 722 | $size_map = array( |
---|
| 723 | 'SQ' => IMG_SQUARE, |
---|
| 724 | 'TH' => IMG_THUMB, |
---|
| 725 | 'XXS' => IMG_XXSMALL, |
---|
| 726 | 'XS' => IMG_XSMALL, |
---|
| 727 | 'S' => IMG_SMALL, |
---|
| 728 | 'M' => IMG_MEDIUM, |
---|
| 729 | 'L' => IMG_LARGE, |
---|
| 730 | 'XL' => IMG_XLARGE, |
---|
| 731 | 'XXL' => IMG_XXLARGE, |
---|
| 732 | ); |
---|
| 733 | |
---|
| 734 | if (!array_key_exists($size, $size_map)) $size = 'M'; |
---|
| 735 | |
---|
[19840] | 736 | return $size_map[$size]; |
---|
[17010] | 737 | } |
---|
| 738 | |
---|
| 739 | |
---|
[7015] | 740 | if (script_basename() == 'admin' or script_basename() == 'popuphelp') |
---|
| 741 | { |
---|
| 742 | include(EXTENDED_DESC_PATH . 'admin.inc.php'); |
---|
| 743 | } |
---|
| 744 | |
---|
[18971] | 745 | // main |
---|
| 746 | add_event_handler ('get_extended_desc', 'get_extended_desc'); |
---|
[17010] | 747 | add_event_handler ('render_page_banner', 'get_extended_desc'); |
---|
[18971] | 748 | // categories |
---|
| 749 | add_event_handler ('render_category_name', 'get_user_language_desc'); |
---|
[7015] | 750 | add_event_handler ('render_category_description', 'get_extended_desc', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[18971] | 751 | // tags |
---|
| 752 | add_event_handler ('render_tag_name', 'get_user_language_desc'); |
---|
| 753 | add_event_handler ('render_tag_url', 'get_user_language_tag_url', 40); |
---|
[17767] | 754 | add_event_handler ('get_tag_alt_names', 'ed_get_all_alt_names', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[18971] | 755 | // element |
---|
| 756 | add_event_handler ('render_element_name', 'get_user_language_desc'); |
---|
[7015] | 757 | add_event_handler ('render_element_description', 'get_extended_desc'); |
---|
[18971] | 758 | // mail/nbm |
---|
[7015] | 759 | add_event_handler ('nbm_render_user_customize_mail_content', 'get_extended_desc'); |
---|
[18971] | 760 | add_event_handler ('mail_group_assign_vars', 'extended_desc_mail_group_assign_vars'); |
---|
| 761 | // removals |
---|
[7015] | 762 | add_event_handler ('loc_end_index_category_thumbnails', 'ext_remove_cat', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[18971] | 763 | add_event_handler ('loc_end_index_thumbnails', 'ext_remove_image', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 764 | add_event_handler ('get_categories_menu_sql_where', 'ext_remove_menubar_cats'); |
---|
| 765 | |
---|
[7015] | 766 | ?> |
---|