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