[7015] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Extended Description |
---|
| 4 | Version: 2.0.g |
---|
| 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 | history |
---|
| 11 | |
---|
| 12 | | date | release | |
---|
| 13 | | | 2.0.c | P@t |
---|
| 14 | | 2009-04-01 | 2.0.d | Grum |
---|
| 15 | | | | * bug corrected, markup <!--hidden--> now works again |
---|
| 16 | | | | on categories name |
---|
| 17 | | | | * new functionality, can use a markup <!--hidden--> |
---|
| 18 | | | | on image's name |
---|
| 19 | | | | * new functionality, add a new parameter for the image |
---|
| 20 | | | | markup [img=] ; possibility to show the image name |
---|
| 21 | | | | with the "name" parameter |
---|
| 22 | | | | * new functionality, the image markup [img=] allows now |
---|
| 23 | | | | to display more than one image |
---|
| 24 | | 2009-04-30 | 2.0.e | P@t |
---|
| 25 | | | | * bug corrected, avoid errors on categories pages when |
---|
| 26 | | | | $conf['show_thumbnail_caption'] = false |
---|
| 27 | | 2009-05-10 | 2.0.f | P@t |
---|
| 28 | | | | * add possibility to remove a category from menubar |
---|
| 29 | | | | with markup <!--mb-hidden--> |
---|
| 30 | | 2010-25-09 | 2.0.g | Grum |
---|
| 31 | | | | * possibility to display the picture's name into the |
---|
| 32 | | | | image title ('titleName' parameter) rather than under |
---|
| 33 | | | | the picture ('name' parameter) |
---|
| 34 | | | | * add Id for image & anchor for [img=...] markup |
---|
| 35 | | | | |
---|
| 36 | | | | |
---|
| 37 | | | | |
---|
| 38 | |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 42 | define('EXTENDED_DESC_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
| 43 | load_language('plugin.lang', EXTENDED_DESC_PATH); |
---|
| 44 | |
---|
| 45 | global $conf; |
---|
| 46 | |
---|
| 47 | $extdesc_conf = array( |
---|
| 48 | 'more' => '<!--more-->', |
---|
| 49 | 'complete' => '<!--complete-->', |
---|
| 50 | 'up-down' => '<!--up-down-->', |
---|
| 51 | 'not_visible' => '<!--hidden-->', |
---|
| 52 | 'mb_not_visible' => '<!--mb-hidden-->' |
---|
| 53 | ); |
---|
| 54 | |
---|
| 55 | $conf['ExtendedDescription'] = isset($conf['ExtendedDescription']) ? |
---|
| 56 | array_merge($extdesc_conf, $conf['ExtendedDescription']) : |
---|
| 57 | $extdesc_conf; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | // Traite les balises [lang=xx] |
---|
| 61 | function get_user_language_desc($desc) |
---|
| 62 | { |
---|
| 63 | global $user; |
---|
| 64 | |
---|
| 65 | $user_lang = substr($user['language'], 0, 2); |
---|
| 66 | |
---|
| 67 | if (!substr_count(strtolower($desc), '[lang=' . $user_lang . ']')) |
---|
| 68 | { |
---|
| 69 | $user_lang = 'default'; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if (substr_count(strtolower($desc), '[lang=' . $user_lang . ']')) |
---|
| 73 | { |
---|
| 74 | // la balise avec la langue de l'utilisateur a été trouvée |
---|
| 75 | $patterns[] = '#(^|\[/lang\])(.*?)(\[lang=(' . $user_lang . '|all)\]|$)#is'; |
---|
| 76 | $replacements[] = ''; |
---|
| 77 | $patterns[] = '#\[lang=(' . $user_lang . '|all)\](.*?)\[/lang\]#is'; |
---|
| 78 | $replacements[] = '\\1'; |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | { |
---|
| 82 | // la balise avec la langue de l'utilisateur n'a pas été trouvée |
---|
| 83 | // On prend tout ce qui est hors balise |
---|
| 84 | $patterns[] = '#\[lang=all\](.*?)\[/lang\]#is'; |
---|
| 85 | $replacements[] = '\\1'; |
---|
| 86 | $patterns[] = '#\[lang=.*\].*\[/lang\]#is'; |
---|
| 87 | $replacements[] = ''; |
---|
| 88 | } |
---|
| 89 | return preg_replace($patterns, $replacements, $desc); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // Traite les autres balises |
---|
| 93 | function get_extended_desc($desc, $param='') |
---|
| 94 | { |
---|
| 95 | global $conf; |
---|
| 96 | |
---|
| 97 | $desc = get_user_language_desc($desc); |
---|
| 98 | |
---|
| 99 | // Balises [cat=xx] |
---|
| 100 | $patterns[] = '#\[cat=(\d*)\]#ie'; |
---|
| 101 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_cat_thumb("$1")'; |
---|
| 102 | |
---|
| 103 | // Balises [img=xx.yy,xx.yy,xx.yy;left|rigtht|;name|titleName|] |
---|
| 104 | //$patterns[] = '#\[img=(\d*)\.?(\d*|);?(left|right|);?(name|titleName|)\]#ie'; |
---|
| 105 | $patterns[] = '#\[img=([\d\s\.]*);?(left|right|);?(name|titleName|)\]#ie'; |
---|
| 106 | $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_img_thumb("$1", "$2", "$3")'; |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | // Balises <!--complete-->, <!--more--> et <!--up-down--> |
---|
| 110 | switch ($param) |
---|
| 111 | { |
---|
| 112 | case 'subcatify_category_description' : |
---|
| 113 | $patterns[] = '#^(.*?)('. preg_quote($conf['ExtendedDescription']['complete']) . '|' . preg_quote($conf['ExtendedDescription']['more']) . '|' . preg_quote($conf['ExtendedDescription']['up-down']) . ').*$#is'; |
---|
| 114 | $replacements[] = '$1'; |
---|
| 115 | $desc = preg_replace($patterns, $replacements, $desc); |
---|
| 116 | break; |
---|
| 117 | |
---|
| 118 | case 'main_page_category_description' : |
---|
| 119 | $patterns[] = '#^.*' . preg_quote($conf['ExtendedDescription']['complete']) . '|' . preg_quote($conf['ExtendedDescription']['more']) . '#is'; |
---|
| 120 | $replacements[] = ''; |
---|
| 121 | $desc = preg_replace($patterns, $replacements, $desc); |
---|
| 122 | if (substr_count($desc, $conf['ExtendedDescription']['up-down'])) |
---|
| 123 | { |
---|
| 124 | list($conf['ExtendedDescription']['top_comment'], $desc) = explode($conf['ExtendedDescription']['up-down'], $desc); |
---|
| 125 | add_event_handler('loc_end_index', 'add_top_description'); |
---|
| 126 | } |
---|
| 127 | break; |
---|
| 128 | |
---|
| 129 | default: |
---|
| 130 | $desc = preg_replace($patterns, $replacements, $desc); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | return $desc; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | function extended_desc_mail_group_assign_vars($assign_vars) |
---|
| 137 | { |
---|
| 138 | if (isset($assign_vars['CPL_CONTENT'])) |
---|
| 139 | { |
---|
| 140 | $assign_vars['CPL_CONTENT'] = get_extended_desc($assign_vars['CPL_CONTENT']); |
---|
| 141 | } |
---|
| 142 | return $assign_vars; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | // Add top description |
---|
| 146 | function add_top_description() |
---|
| 147 | { |
---|
| 148 | global $template, $conf; |
---|
| 149 | $template->concat('PLUGIN_INDEX_CONTENT_BEGIN', ' |
---|
| 150 | <div class="additional_info"> |
---|
| 151 | ' . $conf['ExtendedDescription']['top_comment'] . ' |
---|
| 152 | </div>'); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | // Remove a category |
---|
| 156 | function ext_remove_cat($tpl_var, $categories) |
---|
| 157 | { |
---|
| 158 | global $conf; |
---|
| 159 | |
---|
| 160 | $i=0; |
---|
| 161 | while($i<count($tpl_var)) |
---|
| 162 | { |
---|
| 163 | if (substr_count($tpl_var[$i]['NAME'], $conf['ExtendedDescription']['not_visible'])) |
---|
| 164 | { |
---|
| 165 | array_splice($tpl_var, $i, 1); |
---|
| 166 | } |
---|
| 167 | else |
---|
| 168 | { |
---|
| 169 | $i++; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | return $tpl_var; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | // Remove a category from menubar |
---|
| 177 | function ext_remove_menubar_cats($where) |
---|
| 178 | { |
---|
| 179 | global $conf; |
---|
| 180 | |
---|
| 181 | $query = 'SELECT id, uppercats |
---|
| 182 | FROM '.CATEGORIES_TABLE.' |
---|
| 183 | WHERE name LIKE "%'.$conf['ExtendedDescription']['mb_not_visible'].'%"'; |
---|
| 184 | |
---|
| 185 | $result = pwg_query($query); |
---|
| 186 | while ($row = mysql_fetch_assoc($result)) |
---|
| 187 | { |
---|
| 188 | $ids[] = $row['id']; |
---|
| 189 | $where .= ' |
---|
| 190 | AND uppercats NOT LIKE "'.$row['uppercats'].',%"'; |
---|
| 191 | } |
---|
| 192 | if (!empty($ids)) |
---|
| 193 | { |
---|
| 194 | $where .= ' |
---|
| 195 | AND id NOT IN ('.implode(',', $ids).')'; |
---|
| 196 | } |
---|
| 197 | return $where; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | // Remove an image |
---|
| 201 | function ext_remove_image($tpl_var, $pictures) |
---|
| 202 | { |
---|
| 203 | global $conf; |
---|
| 204 | |
---|
| 205 | $i=0; |
---|
| 206 | while($i<count($tpl_var)) |
---|
| 207 | { |
---|
| 208 | if (substr_count($pictures[$i]['name'], $conf['ExtendedDescription']['not_visible'])) |
---|
| 209 | { |
---|
| 210 | array_splice($tpl_var, $i, 1); |
---|
| 211 | array_splice($pictures, $i, 1); |
---|
| 212 | } |
---|
| 213 | else |
---|
| 214 | { |
---|
| 215 | $i++; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | return $tpl_var; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | // Return html code for caterogy thumb |
---|
| 223 | function get_cat_thumb($elem_id) |
---|
| 224 | { |
---|
| 225 | global $template; |
---|
| 226 | |
---|
| 227 | $query = 'SELECT cat.id, cat.name, cat.comment, cat.representative_picture_id, cat.permalink, |
---|
| 228 | uc.nb_images, uc.count_images, uc.count_categories, |
---|
| 229 | img.path, img.tn_ext |
---|
| 230 | FROM ' . CATEGORIES_TABLE . ' AS cat |
---|
| 231 | INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' as uc |
---|
| 232 | INNER JOIN ' . IMAGES_TABLE . ' AS img |
---|
| 233 | ON cat.id = uc.cat_id |
---|
| 234 | AND img.id = cat.representative_picture_id |
---|
| 235 | WHERE cat.id = ' . $elem_id . ';'; |
---|
| 236 | $result = pwg_query($query); |
---|
| 237 | |
---|
| 238 | if($result) |
---|
| 239 | { |
---|
| 240 | $template->set_filename('extended_description_content', dirname(__FILE__) . '/template/cat.tpl'); |
---|
| 241 | while($category=mysql_fetch_array($result)) |
---|
| 242 | { |
---|
| 243 | $template->assign(array( |
---|
| 244 | 'ID' => $category['id'], |
---|
| 245 | 'TN_SRC' => get_thumbnail_url($category), |
---|
| 246 | 'TN_ALT' => strip_tags($category['name']), |
---|
| 247 | 'URL' => make_index_url(array('category' => $category)), |
---|
| 248 | 'CAPTION_NB_IMAGES' => get_display_images_count |
---|
| 249 | ( |
---|
| 250 | $category['nb_images'], |
---|
| 251 | $category['count_images'], |
---|
| 252 | $category['count_categories'], |
---|
| 253 | true, |
---|
| 254 | '<br />' |
---|
| 255 | ), |
---|
| 256 | 'DESCRIPTION' => |
---|
| 257 | trigger_event('render_category_literal_description', |
---|
| 258 | trigger_event('render_category_description', |
---|
| 259 | @$category['comment'], |
---|
| 260 | 'subcatify_category_description')), |
---|
| 261 | 'NAME' => trigger_event( |
---|
| 262 | 'render_category_name', |
---|
| 263 | $category['name'], |
---|
| 264 | 'subcatify_category_name' |
---|
| 265 | ), |
---|
| 266 | )); |
---|
| 267 | } |
---|
| 268 | return $template->parse('extended_description_content', true); |
---|
| 269 | } |
---|
| 270 | return ''; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | // Return html code for img thumb |
---|
| 274 | //function get_img_thumb($elem_id, $cat_id='', $align='', $name='') |
---|
| 275 | function get_img_thumb($elem_ids, $align='', $name='') |
---|
| 276 | { |
---|
| 277 | global $template; |
---|
| 278 | |
---|
| 279 | $ids=explode(" ",$elem_ids); |
---|
| 280 | $assoc = array(); |
---|
| 281 | foreach($ids as $key=>$val) |
---|
| 282 | { |
---|
| 283 | list($a,$b)=array_pad(explode(".",$val),2,""); |
---|
| 284 | $assoc[0][]=$a; |
---|
| 285 | $assoc[1][]=$b; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id in (' . implode(",",$assoc[0]). ');'; |
---|
| 289 | $result = pwg_query($query); |
---|
| 290 | |
---|
| 291 | if($result) |
---|
| 292 | { |
---|
| 293 | $template->set_filename('extended_description_content', dirname(__FILE__) . '/template/img.tpl'); |
---|
| 294 | |
---|
| 295 | $imglist=array(); |
---|
| 296 | while ($picture = mysql_fetch_array($result)) |
---|
| 297 | { |
---|
| 298 | $imglist[$picture["id"]]=$picture; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | $img=array(); |
---|
| 302 | for($i=0;$i<count($assoc[0]);$i++) |
---|
| 303 | { |
---|
| 304 | if (!empty($assoc[1][$i])) |
---|
| 305 | { |
---|
| 306 | $url = make_picture_url(array( |
---|
| 307 | 'image_id' => $imglist[$assoc[0][$i]]['id'], |
---|
| 308 | 'category' => array( |
---|
| 309 | 'id' => $assoc[1][$i], |
---|
| 310 | 'name' => '', |
---|
| 311 | 'permalink' => ''))); |
---|
| 312 | } |
---|
| 313 | else |
---|
| 314 | { |
---|
| 315 | $url = make_picture_url(array('image_id' => $imglist[$assoc[0][$i]]['id'])); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | $img[]=array( |
---|
| 319 | 'ID' => $imglist[$assoc[0][$i]]['id'], |
---|
| 320 | 'IMAGE' => get_thumbnail_url($imglist[$assoc[0][$i]]), |
---|
| 321 | 'IMAGE_ALT' => $imglist[$assoc[0][$i]]['file'], |
---|
| 322 | 'IMG_TITLE' => ($name=="titleName")?htmlspecialchars($imglist[$assoc[0][$i]]['name'], ENT_QUOTES):get_thumbnail_title($imglist[$assoc[0][$i]]), |
---|
| 323 | 'U_IMG_LINK' => $url, |
---|
| 324 | 'LEGEND' => ($name=="name")?$imglist[$assoc[0][$i]]['name']:"", |
---|
| 325 | 'FLOAT' => !empty($align) ? 'float: ' . $align . ';' : '', |
---|
| 326 | 'COMMENT' => $imglist[$assoc[0][$i]]['file']); |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | } |
---|
| 330 | $template->assign('img', $img); |
---|
| 331 | return $template->parse('extended_description_content', true); |
---|
| 332 | } |
---|
| 333 | return ''; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | if (script_basename() == 'admin' or script_basename() == 'popuphelp') |
---|
| 338 | { |
---|
| 339 | include(EXTENDED_DESC_PATH . 'admin.inc.php'); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | add_event_handler ('render_page_banner', 'get_user_language_desc'); |
---|
| 343 | add_event_handler ('render_category_name', 'get_user_language_desc'); |
---|
| 344 | add_event_handler ('render_category_description', 'get_extended_desc', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 345 | add_event_handler ('render_element_description', 'get_extended_desc'); |
---|
| 346 | add_event_handler ('nbm_render_user_customize_mail_content', 'get_extended_desc'); |
---|
| 347 | add_event_handler ('mail_group_assign_vars', 'extended_desc_mail_group_assign_vars'); |
---|
| 348 | add_event_handler ('loc_end_index_category_thumbnails', 'ext_remove_cat', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 349 | add_event_handler ('loc_end_index_thumbnails', 'ext_remove_image', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 350 | add_event_handler ('get_categories_menu_sql_where', 'ext_remove_menubar_cats'); |
---|
| 351 | ?> |
---|