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