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