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