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