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 | // echo "prev=".$prev_catid; |
---|
236 | // echo "catid=".$row['CATID']; |
---|
237 | // Alimentation des variables pour la constitution du flux xml |
---|
238 | foreach ($module_data['datas'] as $keydata => $valuedata) |
---|
239 | { |
---|
240 | if ($valuedata) // == true |
---|
241 | $picture[$keydata] = parse($module['datas'][$keydata], $row); |
---|
242 | else |
---|
243 | $picture[$keydata] = ''; |
---|
244 | } |
---|
245 | // Si module avec regroupement par categorie et categorie precedente != categorie actuelle (ATTENTION, le tri a du être trié par categories) |
---|
246 | if (isset($module_data['Cat_Regroup']) and $module_data['Cat_Regroup'] and $prev_catid != $row['CATID'] and $prev_catid !="") |
---|
247 | { |
---|
248 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/after_imageNode.xml.php'); |
---|
249 | } |
---|
250 | |
---|
251 | // Si module avec regroupement par categorie et categorie precedente != categorie actuelle (ATTENTION, le tri a du être trié par categories) |
---|
252 | if (isset($module_data['Cat_Regroup']) and $module_data['Cat_Regroup'] and $prev_catid != $row['CATID']) |
---|
253 | { |
---|
254 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/before_imageNode.xml.php'); |
---|
255 | } |
---|
256 | |
---|
257 | // Constitution du flux xml avec l'image en cours |
---|
258 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/imageNode.xml.php'); |
---|
259 | |
---|
260 | |
---|
261 | // categorie precedente sauvegardee |
---|
262 | $prev_catid = $row['CATID']; |
---|
263 | } |
---|
264 | if (isset($module_data['Cat_Regroup']) and $module_data['Cat_Regroup'] and $prev_catid !="") |
---|
265 | { |
---|
266 | include(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/after_imageNode.xml.php'); |
---|
267 | } |
---|
268 | |
---|
269 | include_once(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/before_footer.inc.php'); |
---|
270 | include_once(FLASHGAL_PATH . 'modules/' . $module['type']. '/xml/footer.xml.php'); |
---|
271 | |
---|
272 | |
---|
273 | } |
---|
274 | unset_make_full_url(); |
---|
275 | |
---|
276 | function parse($data, $row) |
---|
277 | { |
---|
278 | include (FLASHGAL_PATH.'include/config_param.inc.php'); |
---|
279 | |
---|
280 | $patterns = array(); |
---|
281 | $replacements = array(); |
---|
282 | foreach ($flashgal_parse as $key => $value) |
---|
283 | { |
---|
284 | // echo "key=".$key." value=".$value."\n"; |
---|
285 | array_push($patterns, $key); |
---|
286 | array_push($replacements, $value); |
---|
287 | } |
---|
288 | |
---|
289 | return str_replace($patterns, $replacements, $data); |
---|
290 | // echo "output=".$output; |
---|
291 | // return $output; |
---|
292 | } |
---|
293 | |
---|
294 | ?> |
---|