1 | <?php |
---|
2 | /* |
---|
3 | * Plugin Name: CoolIris-Piclens |
---|
4 | * Version: 0.3.4 |
---|
5 | * Description: Cooliris/Piclens activation |
---|
6 | * Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=234 |
---|
7 | * Author: Tiico |
---|
8 | * Author URI: |
---|
9 | * */ |
---|
10 | /********* Fichier generate_rss.php *********/ |
---|
11 | |
---|
12 | $debug = false; |
---|
13 | |
---|
14 | define('PHPWG_ROOT_PATH','../../'); |
---|
15 | |
---|
16 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
17 | include_once FLASHGAL_PATH.'include/class.inc.php'; |
---|
18 | |
---|
19 | $home = null; |
---|
20 | $catid = null ; |
---|
21 | $permalinkcat = null; |
---|
22 | |
---|
23 | // utilisation en mode parametres (home, catid=XX et permalink=XX) ou pas |
---|
24 | // Necessaire pour certains modules |
---|
25 | if (isset($_GET['home'])) |
---|
26 | { |
---|
27 | $home = true; |
---|
28 | $page['section'] = 'categories'; |
---|
29 | } |
---|
30 | elseif (isset($_GET['catid'])) |
---|
31 | { |
---|
32 | $catid = $_GET['catid']; |
---|
33 | $page['section'] = 'categories'; |
---|
34 | $page['category']['id'] = $catid; |
---|
35 | } |
---|
36 | elseif (isset($_GET['permalink'])) |
---|
37 | { |
---|
38 | $permalink = $_GET['permalink']; |
---|
39 | $page['section'] = 'categories'; |
---|
40 | $page['category']['id'] = $permalink; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); |
---|
45 | |
---|
46 | $home = (($page['section'] == 'categories') and empty($page['category'])) ? true : null ; |
---|
47 | $catid = ($page['section'] == 'categories' and |
---|
48 | isset($page['category'])) ? $page['category']['id'] : null ; |
---|
49 | $permalinkcat = empty($page['category']['permalink']) ? null : $page['category']['permalink']; |
---|
50 | } |
---|
51 | |
---|
52 | $flashgal = new flashgal($catid, $home, $permalinkcat); |
---|
53 | |
---|
54 | set_make_full_url(); |
---|
55 | |
---|
56 | |
---|
57 | $module = $flashgal->module; |
---|
58 | |
---|
59 | // Parameters for module |
---|
60 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/module.inc.php'); |
---|
61 | |
---|
62 | |
---|
63 | // Vérification d'activation du plugin (page administration) OU activation de piclensWall |
---|
64 | if (isset($page['section'])) |
---|
65 | { |
---|
66 | $cat = array(); |
---|
67 | $pictures = array(); |
---|
68 | |
---|
69 | $forbidden = get_sql_condition_FandF( |
---|
70 | array |
---|
71 | ( |
---|
72 | 'forbidden_categories' => 'category_id', |
---|
73 | 'visible_categories' => 'category_id', |
---|
74 | 'visible_images' => 'id' |
---|
75 | ), |
---|
76 | 'AND' |
---|
77 | ); |
---|
78 | |
---|
79 | if (($page['section']) == 'categories') |
---|
80 | { |
---|
81 | // Accueil |
---|
82 | if(empty($page['category']) and $module['on_home']) |
---|
83 | { |
---|
84 | // Page accueil |
---|
85 | // actif sur page accueil |
---|
86 | |
---|
87 | // Categories de premier niveau |
---|
88 | $query = 'SELECT id,name,permalink FROM ' . CATEGORIES_TABLE |
---|
89 | .' WHERE id_uppercat is NULL'; |
---|
90 | |
---|
91 | $result = pwg_query($query); |
---|
92 | |
---|
93 | while ($row = mysql_fetch_assoc($result)) |
---|
94 | { |
---|
95 | if (!(in_array($row['id'], explode(',', $user['forbidden_categories'])))) |
---|
96 | { |
---|
97 | array_push($cat, $row['id']); |
---|
98 | |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | // Affichage sur l'accueil uniquement des categories selectionnees |
---|
103 | if ($module['on_home_global'] == 'selective') |
---|
104 | { |
---|
105 | $cats_selected = $module['cats'];//(!empty($module['cats']) ? unserialize($module['cats']) : array()); |
---|
106 | |
---|
107 | foreach($cat as $i => $wcat) |
---|
108 | { |
---|
109 | if (!in_array($wcat, $cats_selected)) |
---|
110 | unset($cat[$i]); |
---|
111 | } |
---|
112 | } |
---|
113 | // avec recursiite |
---|
114 | elseif ($module['recurs_cats'] == 'true') |
---|
115 | { |
---|
116 | // recuperation des sous-categories (tous niveaux) de la categorie en cours. |
---|
117 | $subcat= get_subcat_ids($cat); |
---|
118 | |
---|
119 | // Verification droits des sous-categories |
---|
120 | foreach($subcat as $sscat) |
---|
121 | { |
---|
122 | if (!(in_array($sscat, explode(',', $user['forbidden_categories'])))) |
---|
123 | array_push($cat, $sscat); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | $query = 'SELECT DISTINCT(img.id) AS IMGID, img.file AS IMGFILE, |
---|
128 | img.tn_ext, img.path, img.has_high, |
---|
129 | img.width AS IMGWIDTH, img.height AS IMGHEIGHT, |
---|
130 | img.name AS IMGNAME, img.comment AS IMGDESC, |
---|
131 | img.author AS IMGAUTHOR, img.path AS IMGPATH, |
---|
132 | cat.id AS CATID, cat.name AS CATNAME, |
---|
133 | cat.comment AS CATDESC, cat.dir AS CATDIR' |
---|
134 | .' FROM ' . IMAGES_TABLE.' AS img' |
---|
135 | .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id' |
---|
136 | .' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id' |
---|
137 | .' WHERE ic.category_id IN ('.implode(',', $cat).')' |
---|
138 | // Verif droits (niveaux) de l'utilisateur sur les images |
---|
139 | .' AND img.level <='.$user['level'].' ' |
---|
140 | // Choix du critere de tri d'affichage |
---|
141 | .(isset($module_data['Order']) ? $module_data['Order'] : |
---|
142 | str_replace(' id', ' IMGID', $conf['order_by_inside_category'])) |
---|
143 | .''; |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | // Page category et actif sur categories |
---|
148 | elseif (isset($page['category']) and $module['on_cats']) |
---|
149 | { |
---|
150 | check_restrictions($page['category']['id']); |
---|
151 | |
---|
152 | // recherche de toutes les photos de la categorie (incluant les photos des sous-categories si necessaire) |
---|
153 | $selectionID = $page['category']['id']; |
---|
154 | |
---|
155 | array_push($cat, $selectionID); |
---|
156 | |
---|
157 | |
---|
158 | // Si recursivite activee |
---|
159 | if ($module['recurs_cats'] == 'true') |
---|
160 | { |
---|
161 | // recuperation des sous-categories (tous niveaux) de la categorie en cours. |
---|
162 | $subcat= get_subcat_ids(array($selectionID)); |
---|
163 | |
---|
164 | // Verification droits des sous-categories |
---|
165 | foreach($subcat as $sscat) |
---|
166 | { |
---|
167 | if (!(in_array($sscat, explode(',', $user['forbidden_categories'])))) |
---|
168 | array_push($cat, $sscat); |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | $query = 'SELECT DISTINCT(img.id) AS IMGID, img.file AS IMGFILE, |
---|
174 | img.tn_ext, img.path, img.has_high, |
---|
175 | img.width AS IMGWIDTH, img.height AS IMGHEIGHT, |
---|
176 | img.name AS IMGNAME, img.comment AS IMGDESC, |
---|
177 | img.author AS IMGAUTHOR, img.path AS IMGPATH, |
---|
178 | cat.id AS CATID, cat.name AS CATNAME, |
---|
179 | cat.comment AS CATDESC, cat.dir AS CATDIR' |
---|
180 | .' FROM ' . IMAGES_TABLE.' AS img' |
---|
181 | .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id' |
---|
182 | .' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id' |
---|
183 | .' WHERE ic.category_id IN ('.implode(',', $cat).')' |
---|
184 | // Verif droits (niveaux) de l'utilisateur sur les images |
---|
185 | .' AND img.level <='.$user['level'].' ' |
---|
186 | // Choix du critere de tri d'affichage |
---|
187 | .(isset($module_data['Order']) ? $module_data['Order'] : |
---|
188 | str_replace(' id', ' IMGID', $conf['order_by_inside_category'])) |
---|
189 | .''; |
---|
190 | |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | if ($debug) echo $query; |
---|
195 | |
---|
196 | $flashgal_extdesc_hidden = '<!--hidden-->'; |
---|
197 | // Si au moins une image récupérée (une catégorie ou une image présente) |
---|
198 | if (count($cat)!=0) |
---|
199 | { |
---|
200 | $result = pwg_query($query); |
---|
201 | while ($row = mysql_fetch_assoc($result)) |
---|
202 | { |
---|
203 | // Prise en compte images et galeries en hidden |
---|
204 | if ( !(substr_count($row['IMGNAME'], $flashgal_extdesc_hidden)) |
---|
205 | && ((isset($row['CATNAME']) ? !(substr_count($row['CATNAME'], $flashgal_extdesc_hidden)) : true)) |
---|
206 | ) |
---|
207 | |
---|
208 | array_push($pictures, $row); |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | // Fin requetes recherches photos |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | $module['datas'] = (!empty($module['datas']) ? unserialize($module['datas']) : array('')); |
---|
217 | $module['ext_datas'] = (!empty($module['ext_datas']) ? unserialize($module['ext_datas']) : array('')); |
---|
218 | |
---|
219 | |
---|
220 | // Creation du fichier xml (flux rss) |
---|
221 | // Possibilite de ne pas ajouter l'entete xml (certains modules) |
---|
222 | if (!isset($module_data['no_xml_header']) or $module_data['no_xml_header'] == false ) |
---|
223 | { |
---|
224 | header("Content-Type: application/xml; charset=UTF-8"); |
---|
225 | } |
---|
226 | |
---|
227 | include_once(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/before_header.inc.php'); |
---|
228 | include_once(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/header.xml.php'); |
---|
229 | |
---|
230 | |
---|
231 | $prev_catid = ""; // Variable pour categorie precedente |
---|
232 | // Pour chacune des images, preparation du flux xml |
---|
233 | foreach ($pictures as $row) |
---|
234 | { |
---|
235 | // Alimentation des variables pour la constitution du flux xml |
---|
236 | foreach ($module_data['datas'] as $keydata => $valuedata) |
---|
237 | { |
---|
238 | if ($valuedata) // == true |
---|
239 | $picture[$keydata] = parse($module['datas'][$keydata], $row, $module['maxcomment']); |
---|
240 | else |
---|
241 | $picture[$keydata] = ''; |
---|
242 | } |
---|
243 | // Si module avec regroupement par categorie et categorie precedente != categorie actuelle (ATTENTION, le tri a du être trié par categories) |
---|
244 | if (isset($module_data['Cat_Regroup']) and $module_data['Cat_Regroup'] and $prev_catid != $row['CATID'] and $prev_catid !="") |
---|
245 | { |
---|
246 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/after_imageNode.xml.php'); |
---|
247 | } |
---|
248 | |
---|
249 | // Si module avec regroupement par categorie et categorie precedente != categorie actuelle (ATTENTION, le tri a du être trié par categories) |
---|
250 | if (isset($module_data['Cat_Regroup']) and $module_data['Cat_Regroup'] and $prev_catid != $row['CATID']) |
---|
251 | { |
---|
252 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/before_imageNode.xml.php'); |
---|
253 | } |
---|
254 | |
---|
255 | // Constitution du flux xml avec l'image en cours |
---|
256 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/imageNode.xml.php'); |
---|
257 | |
---|
258 | |
---|
259 | // categorie precedente sauvegardee |
---|
260 | $prev_catid = $row['CATID']; |
---|
261 | } |
---|
262 | if (isset($module_data['Cat_Regroup']) and $module_data['Cat_Regroup'] and $prev_catid !="") |
---|
263 | { |
---|
264 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/after_imageNode.xml.php'); |
---|
265 | } |
---|
266 | |
---|
267 | include_once(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/before_footer.inc.php'); |
---|
268 | include_once(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/footer.xml.php'); |
---|
269 | |
---|
270 | |
---|
271 | } |
---|
272 | unset_make_full_url(); |
---|
273 | |
---|
274 | function parse($data, $row, $nb_comment = 0) |
---|
275 | { |
---|
276 | // Eviter de charger les commentaires (appels base) si ils ne sont pas affichés |
---|
277 | if (strpos($data, '%ID') === false) |
---|
278 | $nb_comment = 0; |
---|
279 | |
---|
280 | include (FLASHGAL_PATH.'include/config_param.inc.php'); |
---|
281 | |
---|
282 | $patterns = array(); |
---|
283 | $replacements = array(); |
---|
284 | foreach ($flashgal_parse as $key => $value) |
---|
285 | { |
---|
286 | array_push($patterns, $key); |
---|
287 | array_push($replacements, $value); |
---|
288 | } |
---|
289 | |
---|
290 | return str_replace($patterns, $replacements, $data); |
---|
291 | } |
---|
292 | |
---|
293 | // Return the last comments of an image id |
---|
294 | function get_comment($img_id, $nb_comment = 0) |
---|
295 | { |
---|
296 | $commentstring = ''; |
---|
297 | |
---|
298 | if ($nb_comment != 0) |
---|
299 | { |
---|
300 | $query = ' |
---|
301 | SELECT id,author,date,image_id,content |
---|
302 | FROM '.COMMENTS_TABLE.' |
---|
303 | WHERE image_id = '.$img_id.' |
---|
304 | AND validated = \'true\' |
---|
305 | ORDER BY date ASC |
---|
306 | LIMIT 0,'.$nb_comment.' |
---|
307 | ;'; |
---|
308 | $result = pwg_query( $query ); |
---|
309 | $first = true; |
---|
310 | |
---|
311 | while ($row = mysql_fetch_array($result)) |
---|
312 | { |
---|
313 | |
---|
314 | // Format : "Commentaire (Utilisateur - Date)" |
---|
315 | $commentstring .= ($first ? '' : " / \n") |
---|
316 | .trigger_event('render_comment_content',$row['content']) |
---|
317 | .' ('. trigger_event('render_comment_author', |
---|
318 | empty($row['author']) |
---|
319 | ? l10n('guest') |
---|
320 | : $row['author']) |
---|
321 | .' - ' |
---|
322 | .format_date( $row['date'], false) |
---|
323 | .")"; |
---|
324 | |
---|
325 | $first = false; |
---|
326 | |
---|
327 | } |
---|
328 | } |
---|
329 | return $commentstring; |
---|
330 | } |
---|
331 | |
---|
332 | ?> |
---|