1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-02-01 02:46:26 +0000 (Wed, 01 Feb 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1020 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | if (!defined('PHPWG_ROOT_PATH')) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
33 | |
---|
34 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
35 | define('CURRENT_DATE', $dbnow); |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | // | functions | |
---|
38 | // +-----------------------------------------------------------------------+ |
---|
39 | |
---|
40 | /** |
---|
41 | * requests the given $url (a remote create_listing_file.php) and fills a |
---|
42 | * list of lines corresponding to request output |
---|
43 | * |
---|
44 | * @param string $url |
---|
45 | * @return void |
---|
46 | */ |
---|
47 | function remote_output($url) |
---|
48 | { |
---|
49 | global $template, $page, $lang; |
---|
50 | |
---|
51 | if($lines = @file($url)) |
---|
52 | { |
---|
53 | $template->assign_block_vars('remote_output', array()); |
---|
54 | // cleaning lines from HTML tags |
---|
55 | foreach ($lines as $line) |
---|
56 | { |
---|
57 | $line = trim(strip_tags($line)); |
---|
58 | if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches)) |
---|
59 | { |
---|
60 | $template->assign_block_vars( |
---|
61 | 'remote_output.remote_line', |
---|
62 | array( |
---|
63 | 'CLASS' => 'remote'.ucfirst(strtolower($matches[1])), |
---|
64 | 'CONTENT' => $line |
---|
65 | ) |
---|
66 | ); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | array_push($page['errors'], $lang['remote_site_file_not_found']); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * returns an array where are linked the sub-categories id and there |
---|
78 | * directories corresponding to the given uppercat id |
---|
79 | * |
---|
80 | * @param int site_id |
---|
81 | * @param mixed id_uppercat |
---|
82 | * @return array |
---|
83 | */ |
---|
84 | function database_subdirs($site_id, $id_uppercat) |
---|
85 | { |
---|
86 | $database_dirs = array(); |
---|
87 | |
---|
88 | $query = ' |
---|
89 | SELECT id,dir |
---|
90 | FROM '.CATEGORIES_TABLE.' |
---|
91 | WHERE site_id = '.$site_id; |
---|
92 | if (!is_numeric($id_uppercat)) |
---|
93 | { |
---|
94 | $query.= ' |
---|
95 | AND id_uppercat IS NULL'; |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | $query.= ' |
---|
100 | AND id_uppercat = '.$id_uppercat; |
---|
101 | } |
---|
102 | // virtual categories not taken |
---|
103 | $query.= ' |
---|
104 | AND dir IS NOT NULL |
---|
105 | ;'; |
---|
106 | $result = pwg_query($query); |
---|
107 | while ($row = mysql_fetch_array($result)) |
---|
108 | { |
---|
109 | $database_dirs[$row['id']] = $row['dir']; |
---|
110 | } |
---|
111 | |
---|
112 | return $database_dirs; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * read $listing_file and update a remote site according to its id |
---|
117 | * |
---|
118 | * @param string listing_file |
---|
119 | * @param int site_id |
---|
120 | * @return void |
---|
121 | */ |
---|
122 | function update_remote_site($listing_file, $site_id) |
---|
123 | { |
---|
124 | global $lang, $counts, $template, $removes, $page; |
---|
125 | |
---|
126 | if (@fopen($listing_file, 'r')) |
---|
127 | { |
---|
128 | $counts = array( |
---|
129 | 'new_elements' => 0, |
---|
130 | 'new_categories' => 0, |
---|
131 | 'del_elements' => 0, |
---|
132 | 'del_categories' => 0 |
---|
133 | ); |
---|
134 | $removes = array(); |
---|
135 | |
---|
136 | $xml_content = getXmlCode($listing_file); |
---|
137 | insert_remote_category($xml_content, $site_id, 'NULL', 0); |
---|
138 | update_category(); |
---|
139 | ordering(); |
---|
140 | update_global_rank(); |
---|
141 | |
---|
142 | $template->assign_block_vars( |
---|
143 | 'update', |
---|
144 | array( |
---|
145 | 'NB_NEW_CATEGORIES'=>$counts['new_categories'], |
---|
146 | 'NB_DEL_CATEGORIES'=>$counts['del_categories'], |
---|
147 | 'NB_NEW_ELEMENTS'=>$counts['new_elements'], |
---|
148 | 'NB_DEL_ELEMENTS'=>$counts['del_elements'] |
---|
149 | )); |
---|
150 | |
---|
151 | if (count($removes) > 0) |
---|
152 | { |
---|
153 | $template->assign_block_vars('update.removes', array()); |
---|
154 | } |
---|
155 | foreach ($removes as $remove) |
---|
156 | { |
---|
157 | $template->assign_block_vars('update.removes.remote_remove', |
---|
158 | array('NAME'=>$remove)); |
---|
159 | } |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | array_push($page['errors'], $lang['remote_site_listing_not_found']); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | * searchs the "dir" node of the xml_dir given and insert the contained |
---|
169 | * categories if the are not in the database yet. The function also deletes |
---|
170 | * the categories that are in the database and not in the xml_file. |
---|
171 | * |
---|
172 | * @param string xml_content |
---|
173 | * @param int site_id |
---|
174 | * @param mixed id_uppercat |
---|
175 | * @param int level |
---|
176 | * @return void |
---|
177 | */ |
---|
178 | function insert_remote_category($xml_content, $site_id, $id_uppercat, $level) |
---|
179 | { |
---|
180 | global $counts, $removes, $conf; |
---|
181 | |
---|
182 | $uppercats = ''; |
---|
183 | // 0. retrieving informations on the category to display |
---|
184 | |
---|
185 | if (is_numeric($id_uppercat)) |
---|
186 | { |
---|
187 | $query = ' |
---|
188 | SELECT id,name,uppercats,dir,status,visible |
---|
189 | FROM '.CATEGORIES_TABLE.' |
---|
190 | WHERE id = '.$id_uppercat.' |
---|
191 | ;'; |
---|
192 | $row = mysql_fetch_array(pwg_query($query)); |
---|
193 | $parent = array('id' => $row['id'], |
---|
194 | 'name' => $row['name'], |
---|
195 | 'dir' => $row['dir'], |
---|
196 | 'uppercats' => $row['uppercats'], |
---|
197 | 'visible' => $row['visible'], |
---|
198 | 'status' => $row['status']); |
---|
199 | |
---|
200 | insert_remote_element($xml_content, $id_uppercat); |
---|
201 | } |
---|
202 | |
---|
203 | // $xml_dirs contains dir names contained in the xml file for this |
---|
204 | // id_uppercat |
---|
205 | $xml_dirs = array(); |
---|
206 | $temp_dirs = getChildren($xml_content, 'dir'.$level); |
---|
207 | foreach ($temp_dirs as $temp_dir) |
---|
208 | { |
---|
209 | array_push($xml_dirs, getAttribute($temp_dir, 'name')); |
---|
210 | } |
---|
211 | |
---|
212 | // $database_dirs contains dir names contained in the database for this |
---|
213 | // id_uppercat and site_id |
---|
214 | $database_dirs = database_subdirs($site_id, $id_uppercat); |
---|
215 | |
---|
216 | // 3. we have to remove the categories of the database not present anymore |
---|
217 | $to_delete = array(); |
---|
218 | foreach ($database_dirs as $id => $dir) |
---|
219 | { |
---|
220 | if (!in_array($dir, $xml_dirs)) |
---|
221 | { |
---|
222 | array_push($to_delete, $id); |
---|
223 | array_push($removes, get_complete_dir($id)); |
---|
224 | } |
---|
225 | } |
---|
226 | delete_categories($to_delete); |
---|
227 | |
---|
228 | // array of new categories to insert |
---|
229 | $inserts = array(); |
---|
230 | |
---|
231 | // calculate default value at category creation |
---|
232 | $create_values = array(); |
---|
233 | if (isset($parent)) |
---|
234 | { |
---|
235 | // at creation, must a category be visible or not ? Warning : if |
---|
236 | // the parent category is invisible, the category is automatically |
---|
237 | // create invisible. (invisible = locked) |
---|
238 | if ('false' == $parent['visible']) |
---|
239 | { |
---|
240 | $create_values{'visible'} = 'false'; |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | $create_values{'visible'} = $conf['newcat_default_visible']; |
---|
245 | } |
---|
246 | // at creation, must a category be public or private ? Warning : |
---|
247 | // if the parent category is private, the category is |
---|
248 | // automatically create private. |
---|
249 | if ('private' == $parent['status']) |
---|
250 | { |
---|
251 | $create_values{'status'} = 'private'; |
---|
252 | } |
---|
253 | else |
---|
254 | { |
---|
255 | $create_values{'status'} = $conf['newcat_default_status']; |
---|
256 | } |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | $create_values{'visible'} = $conf['newcat_default_visible']; |
---|
261 | $create_values{'status'} = $conf['newcat_default_status']; |
---|
262 | } |
---|
263 | |
---|
264 | foreach ($xml_dirs as $xml_dir) |
---|
265 | { |
---|
266 | // 5. Is the category already existing ? we create a subcat if not |
---|
267 | // existing |
---|
268 | $category_id = array_search($xml_dir, $database_dirs); |
---|
269 | if (!is_numeric($category_id)) |
---|
270 | { |
---|
271 | $name = str_replace('_', ' ', $xml_dir); |
---|
272 | |
---|
273 | $insert = array(); |
---|
274 | |
---|
275 | $insert{'dir'} = $xml_dir; |
---|
276 | $insert{'name'} = $name; |
---|
277 | $insert{'site_id'} = $site_id; |
---|
278 | $insert{'uppercats'} = 'undef'; |
---|
279 | $insert{'commentable'} = $conf['newcat_default_commentable']; |
---|
280 | $insert{'uploadable'} = 'false'; |
---|
281 | $insert{'status'} = $create_values{'status'}; |
---|
282 | $insert{'visible'} = $create_values{'visible'}; |
---|
283 | if (isset($parent)) |
---|
284 | { |
---|
285 | $insert{'id_uppercat'} = $parent['id']; |
---|
286 | } |
---|
287 | array_push($inserts, $insert); |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | // we have to create the category |
---|
292 | if (count($inserts) > 0) |
---|
293 | { |
---|
294 | // inserts all found categories |
---|
295 | $dbfields = array('dir','name','site_id','uppercats','id_uppercat', |
---|
296 | 'commentable','uploadable','status','visible'); |
---|
297 | mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); |
---|
298 | $counts{'new_categories'}+= count($inserts); |
---|
299 | |
---|
300 | // updating uppercats field |
---|
301 | $query = ' |
---|
302 | UPDATE '.CATEGORIES_TABLE; |
---|
303 | if (isset($parent)) |
---|
304 | { |
---|
305 | $query.= " |
---|
306 | SET uppercats = CONCAT('".$parent['uppercats']."',',',id) |
---|
307 | WHERE id_uppercat = ".$id_uppercat; |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | $query.= ' |
---|
312 | SET uppercats = id |
---|
313 | WHERE id_uppercat IS NULL'; |
---|
314 | } |
---|
315 | $query.= ' |
---|
316 | ;'; |
---|
317 | pwg_query($query); |
---|
318 | } |
---|
319 | |
---|
320 | // Recursive call on the sub-categories (not virtual ones) |
---|
321 | $database_dirs = database_subdirs($site_id, $id_uppercat); |
---|
322 | |
---|
323 | foreach ($temp_dirs as $temp_dir) |
---|
324 | { |
---|
325 | $dir = getAttribute($temp_dir, 'name'); |
---|
326 | $id_uppercat = array_search($dir, $database_dirs); |
---|
327 | insert_remote_category($temp_dir, $site_id, $id_uppercat, $level+1); |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | /** |
---|
332 | * searchs the "root" node of $xml_dir (xml string), inserts elements in the |
---|
333 | * database if new |
---|
334 | * |
---|
335 | * @param string xml_dir |
---|
336 | * @param int category_id |
---|
337 | * @return void |
---|
338 | */ |
---|
339 | function insert_remote_element($xml_dir, $category_id) |
---|
340 | { |
---|
341 | global $counts, $lang, $removes; |
---|
342 | |
---|
343 | $output = ''; |
---|
344 | $root = getChild($xml_dir, 'root'); |
---|
345 | |
---|
346 | $xml_files = array(); |
---|
347 | $xml_elements = getChildren($root, 'element'); |
---|
348 | foreach ($xml_elements as $xml_element) |
---|
349 | { |
---|
350 | array_push($xml_files, getAttribute($xml_element,'file')); |
---|
351 | } |
---|
352 | |
---|
353 | // we have to delete all the images from the database that are not in the |
---|
354 | // directory anymore (not in the XML anymore) |
---|
355 | $query = ' |
---|
356 | SELECT id,file |
---|
357 | FROM '.IMAGES_TABLE.' |
---|
358 | WHERE storage_category_id = '.$category_id.' |
---|
359 | ;'; |
---|
360 | $result = pwg_query($query); |
---|
361 | $to_delete = array(); |
---|
362 | while ($row = mysql_fetch_array($result)) |
---|
363 | { |
---|
364 | if (!in_array($row['file'], $xml_files)) |
---|
365 | { |
---|
366 | // local_dir is cached |
---|
367 | if (!isset($local_dir)) |
---|
368 | { |
---|
369 | $local_dir = get_local_dir($category_id); |
---|
370 | } |
---|
371 | array_push($removes, $local_dir.$row['file']); |
---|
372 | array_push($to_delete, $row['id']); |
---|
373 | } |
---|
374 | } |
---|
375 | delete_elements($to_delete); |
---|
376 | |
---|
377 | $database_elements = array(); |
---|
378 | $query = ' |
---|
379 | SELECT file |
---|
380 | FROM '.IMAGES_TABLE.' |
---|
381 | WHERE storage_category_id = '.$category_id.' |
---|
382 | ;'; |
---|
383 | $result = pwg_query($query); |
---|
384 | while ($row = mysql_fetch_array($result)) |
---|
385 | { |
---|
386 | array_push($database_elements, $row['file']); |
---|
387 | } |
---|
388 | |
---|
389 | $inserts = array(); |
---|
390 | foreach ($xml_elements as $xml_element) |
---|
391 | { |
---|
392 | // minimal tag : <element file="albatros.jpg"/> |
---|
393 | $file = getAttribute($xml_element, 'file'); |
---|
394 | |
---|
395 | // is the picture already existing in the database ? |
---|
396 | if (!in_array($file, $database_elements)) |
---|
397 | { |
---|
398 | $insert = array(); |
---|
399 | $insert{'file'} = $file; |
---|
400 | $insert{'storage_category_id'} = $category_id; |
---|
401 | $insert{'date_available'} = CURRENT_DATE; |
---|
402 | $optional_atts = array('tn_ext', |
---|
403 | 'representative_ext', |
---|
404 | 'filesize', |
---|
405 | 'width', |
---|
406 | 'height', |
---|
407 | 'date_creation', |
---|
408 | 'author', |
---|
409 | 'keywords', |
---|
410 | 'name', |
---|
411 | 'comment', |
---|
412 | 'has_high', |
---|
413 | 'path'); |
---|
414 | foreach ($optional_atts as $att) |
---|
415 | { |
---|
416 | if (getAttribute($xml_element, $att) != '') |
---|
417 | { |
---|
418 | $insert{$att} = getAttribute($xml_element, $att); |
---|
419 | } |
---|
420 | } |
---|
421 | array_push($inserts, $insert); |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | if (count($inserts) > 0) |
---|
426 | { |
---|
427 | $dbfields = array('file','storage_category_id','date_available','tn_ext', |
---|
428 | 'filesize','width','height','date_creation','author', |
---|
429 | 'keywords','name','comment','has_high','path'); |
---|
430 | mass_inserts(IMAGES_TABLE, $dbfields, $inserts); |
---|
431 | $counts{'new_elements'}+= count($inserts); |
---|
432 | |
---|
433 | // what are the ids of the pictures in the $category_id ? |
---|
434 | $ids = array(); |
---|
435 | |
---|
436 | $query = ' |
---|
437 | SELECT id |
---|
438 | FROM '.IMAGES_TABLE.' |
---|
439 | WHERE storage_category_id = '.$category_id.' |
---|
440 | ;'; |
---|
441 | $result = pwg_query($query); |
---|
442 | while ($row = mysql_fetch_array($result)) |
---|
443 | { |
---|
444 | array_push($ids, $row['id']); |
---|
445 | } |
---|
446 | |
---|
447 | // recreation of the links between this storage category pictures and |
---|
448 | // its storage category |
---|
449 | $query = ' |
---|
450 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
451 | WHERE category_id = '.$category_id.' |
---|
452 | AND image_id IN ('.implode(',', $ids).') |
---|
453 | ;'; |
---|
454 | pwg_query($query); |
---|
455 | |
---|
456 | $query = ' |
---|
457 | INSERT INTO '.IMAGE_CATEGORY_TABLE.' |
---|
458 | (category_id,image_id) |
---|
459 | VALUES'; |
---|
460 | foreach ($ids as $num => $image_id) |
---|
461 | { |
---|
462 | $query.= ' |
---|
463 | '; |
---|
464 | if ($num > 0) |
---|
465 | { |
---|
466 | $query.= ','; |
---|
467 | } |
---|
468 | $query.= '('.$category_id.','.$image_id.')'; |
---|
469 | } |
---|
470 | $query.= ' |
---|
471 | ;'; |
---|
472 | pwg_query($query); |
---|
473 | // set a new representative element for this category |
---|
474 | $query = ' |
---|
475 | SELECT image_id |
---|
476 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
477 | WHERE category_id = '.$category_id.' |
---|
478 | ORDER BY RAND() |
---|
479 | LIMIT 0,1 |
---|
480 | ;'; |
---|
481 | list($representative) = mysql_fetch_array(pwg_query($query)); |
---|
482 | $query = ' |
---|
483 | UPDATE '.CATEGORIES_TABLE.' |
---|
484 | SET representative_picture_id = '.$representative.' |
---|
485 | WHERE id = '.$category_id.' |
---|
486 | ;'; |
---|
487 | pwg_query($query); |
---|
488 | } |
---|
489 | } |
---|
490 | // +-----------------------------------------------------------------------+ |
---|
491 | // | template init | |
---|
492 | // +-----------------------------------------------------------------------+ |
---|
493 | $template->set_filenames(array('remote_site'=>'admin/remote_site.tpl')); |
---|
494 | |
---|
495 | $template->assign_vars( |
---|
496 | array( |
---|
497 | 'L_SUBMIT'=>$lang['submit'], |
---|
498 | 'L_REMOTE_SITE_CREATE'=>$lang['remote_site_create'], |
---|
499 | 'L_REMOTE_SITE_GENERATE'=>$lang['remote_site_generate'], |
---|
500 | 'L_REMOTE_SITE_GENERATE_HINT'=>$lang['remote_site_generate_hint'], |
---|
501 | 'L_REMOTE_SITE_UPDATE'=>$lang['remote_site_update'], |
---|
502 | 'L_REMOTE_SITE_UPDATE_HINT'=>$lang['remote_site_update_hint'], |
---|
503 | 'L_REMOTE_SITE_CLEAN'=>$lang['remote_site_clean'], |
---|
504 | 'L_REMOTE_SITE_CLEAN_HINT'=>$lang['remote_site_clean_hint'], |
---|
505 | 'L_REMOTE_SITE_DELETE'=>$lang['remote_site_delete'], |
---|
506 | 'L_REMOTE_SITE_DELETE_HINT'=>$lang['remote_site_delete_hint'], |
---|
507 | 'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'], |
---|
508 | 'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'], |
---|
509 | 'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'], |
---|
510 | 'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'], |
---|
511 | 'L_REMOTE_SITE_REMOVED_TITLE'=>$lang['remote_site_removed_title'], |
---|
512 | 'L_REMOTE_SITE_REMOVED'=>$lang['remote_site_removed'], |
---|
513 | 'L_REMOTE_SITE_LOCAL_FOUND'=>$lang['remote_site_local_found'], |
---|
514 | 'L_REMOTE_SITE_LOCAL_NEW'=>$lang['remote_site_local_new'], |
---|
515 | 'L_REMOTE_SITE_LOCAL_UPDATE'=>$lang['remote_site_local_update'], |
---|
516 | |
---|
517 | 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=remote_site', |
---|
518 | |
---|
519 | 'F_ACTION'=>PHPWG_ROOT_PATH.'admin.php?page=remote_site' |
---|
520 | ) |
---|
521 | ); |
---|
522 | |
---|
523 | // +-----------------------------------------------------------------------+ |
---|
524 | // | new site creation form | |
---|
525 | // +-----------------------------------------------------------------------+ |
---|
526 | if (isset($_POST['submit'])) |
---|
527 | { |
---|
528 | // site must start by http:// or https:// |
---|
529 | if (!preg_match('/^https?:\/\/[~\/\.\w-]+$/', $_POST['galleries_url'])) |
---|
530 | { |
---|
531 | array_push($page['errors'], $lang['remote_site_uncorrect_url']); |
---|
532 | } |
---|
533 | else |
---|
534 | { |
---|
535 | $page['galleries_url'] = preg_replace('/[\/]*$/', |
---|
536 | '', |
---|
537 | $_POST['galleries_url']); |
---|
538 | $page['galleries_url'].= '/'; |
---|
539 | // site must not exists |
---|
540 | $query = ' |
---|
541 | SELECT COUNT(id) AS count |
---|
542 | FROM '.SITES_TABLE.' |
---|
543 | WHERE galleries_url = \''.$page['galleries_url'].'\' |
---|
544 | ;'; |
---|
545 | $row = mysql_fetch_array(pwg_query($query)); |
---|
546 | if ($row['count'] > 0) |
---|
547 | { |
---|
548 | array_push($page['errors'], $lang['remote_site_already_exists']); |
---|
549 | } |
---|
550 | } |
---|
551 | |
---|
552 | if (count($page['errors']) == 0) |
---|
553 | { |
---|
554 | $url = $page['galleries_url'].'create_listing_file.php'; |
---|
555 | $url.= '?action=test'; |
---|
556 | $url.= '&version='.PHPWG_VERSION; |
---|
557 | if ($lines = @file($url)) |
---|
558 | { |
---|
559 | $first_line = strip_tags($lines[0]); |
---|
560 | if (!preg_match('/^PWG-INFO-2:/', $first_line)) |
---|
561 | { |
---|
562 | array_push($page['errors'], |
---|
563 | $lang['remote_site_error'].' : '.$first_line); |
---|
564 | } |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | array_push($page['errors'], $lang['remote_site_file_not_found']); |
---|
569 | } |
---|
570 | } |
---|
571 | |
---|
572 | if (count($page['errors']) == 0) |
---|
573 | { |
---|
574 | $query = ' |
---|
575 | INSERT INTO '.SITES_TABLE.' |
---|
576 | (galleries_url) |
---|
577 | VALUES |
---|
578 | (\''.$page['galleries_url'].'\') |
---|
579 | ;'; |
---|
580 | pwg_query($query); |
---|
581 | |
---|
582 | array_push($page['infos'], |
---|
583 | $page['galleries_url'].' '.$lang['remote_site_created']); |
---|
584 | } |
---|
585 | } |
---|
586 | // +-----------------------------------------------------------------------+ |
---|
587 | // | actions on site | |
---|
588 | // +-----------------------------------------------------------------------+ |
---|
589 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
590 | { |
---|
591 | $page['site'] = $_GET['site']; |
---|
592 | } |
---|
593 | |
---|
594 | if (isset($_GET['action'])) |
---|
595 | { |
---|
596 | if (isset($page['site'])) |
---|
597 | { |
---|
598 | $query = ' |
---|
599 | SELECT galleries_url |
---|
600 | FROM '.SITES_TABLE.' |
---|
601 | WHERE id = '.$page['site'].' |
---|
602 | ;'; |
---|
603 | list($galleries_url) = mysql_fetch_array(pwg_query($query)); |
---|
604 | } |
---|
605 | |
---|
606 | switch($_GET['action']) |
---|
607 | { |
---|
608 | case 'delete' : |
---|
609 | { |
---|
610 | delete_site($page['site']); |
---|
611 | array_push($page['infos'], |
---|
612 | $galleries_url.' '.$lang['remote_site_deleted']); |
---|
613 | break; |
---|
614 | } |
---|
615 | case 'generate' : |
---|
616 | { |
---|
617 | $title = $galleries_url.' : '.$lang['remote_site_generate']; |
---|
618 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
619 | remote_output($galleries_url.'create_listing_file.php?action=generate'); |
---|
620 | break; |
---|
621 | } |
---|
622 | case 'update' : |
---|
623 | { |
---|
624 | $title = $galleries_url.' : '.$lang['remote_site_update']; |
---|
625 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
626 | update_remote_site($galleries_url.'listing.xml', $page['site']); |
---|
627 | break; |
---|
628 | } |
---|
629 | case 'clean' : |
---|
630 | { |
---|
631 | $title = $galleries_url.' : '.$lang['remote_site_clean']; |
---|
632 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
633 | remote_output($galleries_url.'create_listing_file.php?action=clean'); |
---|
634 | break; |
---|
635 | } |
---|
636 | case 'local_update' : |
---|
637 | { |
---|
638 | $local_listing = PHPWG_ROOT_PATH.'listing.xml'; |
---|
639 | $xml_content = getXmlCode($local_listing); |
---|
640 | $url = getAttribute(getChild($xml_content, 'informations'), 'url'); |
---|
641 | |
---|
642 | // is the site already existing ? |
---|
643 | $query = ' |
---|
644 | SELECT id |
---|
645 | FROM '.SITES_TABLE.' |
---|
646 | WHERE galleries_url = \''.addslashes($url).'\' |
---|
647 | ;'; |
---|
648 | $result = pwg_query($query); |
---|
649 | if (mysql_num_rows($result) == 0) |
---|
650 | { |
---|
651 | // we have to register this site in the database |
---|
652 | $query = ' |
---|
653 | INSERT INTO '.SITES_TABLE.' |
---|
654 | (galleries_url) |
---|
655 | VALUES |
---|
656 | (\''.$url.'\') |
---|
657 | ;'; |
---|
658 | pwg_query($query); |
---|
659 | $site_id = mysql_insert_id(); |
---|
660 | } |
---|
661 | else |
---|
662 | { |
---|
663 | // we get the already registered id |
---|
664 | $row = mysql_fetch_array($result); |
---|
665 | $site_id = $row['id']; |
---|
666 | } |
---|
667 | |
---|
668 | $title = $url.' : '.$lang['remote_site_local_update']; |
---|
669 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
670 | update_remote_site($local_listing, $site_id); |
---|
671 | break; |
---|
672 | } |
---|
673 | } |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | // we search a "local" listing.xml file |
---|
678 | $local_listing = PHPWG_ROOT_PATH.'listing.xml'; |
---|
679 | if (is_file($local_listing)) |
---|
680 | { |
---|
681 | $xml_content = getXmlCode($local_listing); |
---|
682 | $url = getAttribute(getChild($xml_content, 'informations'), 'url'); |
---|
683 | |
---|
684 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=remote_site&action='; |
---|
685 | |
---|
686 | $template->assign_block_vars( |
---|
687 | 'local', |
---|
688 | array( |
---|
689 | 'URL' => $url, |
---|
690 | 'U_UPDATE' => $base_url.'local_update' |
---|
691 | ) |
---|
692 | ); |
---|
693 | |
---|
694 | // is the site already existing ? |
---|
695 | $query = ' |
---|
696 | SELECT COUNT(*) |
---|
697 | FROM '.SITES_TABLE.' |
---|
698 | WHERE galleries_url = \''.addslashes($url).'\' |
---|
699 | ;'; |
---|
700 | list($count) = mysql_fetch_array(pwg_query($query)); |
---|
701 | if ($count == 0) |
---|
702 | { |
---|
703 | $template->assign_block_vars('local.new_site', array()); |
---|
704 | } |
---|
705 | } |
---|
706 | } |
---|
707 | // +-----------------------------------------------------------------------+ |
---|
708 | // | remote sites list | |
---|
709 | // +-----------------------------------------------------------------------+ |
---|
710 | |
---|
711 | // site 1 is the local site, should not be taken into account |
---|
712 | $query = ' |
---|
713 | SELECT id, galleries_url |
---|
714 | FROM '.SITES_TABLE.' |
---|
715 | WHERE id != 1 |
---|
716 | ;'; |
---|
717 | $result = pwg_query($query); |
---|
718 | |
---|
719 | if (mysql_num_rows($result) > 0) |
---|
720 | { |
---|
721 | $template->assign_block_vars('sites', array()); |
---|
722 | } |
---|
723 | |
---|
724 | while ($row = mysql_fetch_array($result)) |
---|
725 | { |
---|
726 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
727 | $base_url.= '?page=remote_site'; |
---|
728 | $base_url.= '&site='.$row['id']; |
---|
729 | $base_url.= '&action='; |
---|
730 | |
---|
731 | $template->assign_block_vars( |
---|
732 | 'sites.site', |
---|
733 | array( |
---|
734 | 'NAME' => $row['galleries_url'], |
---|
735 | 'U_GENERATE' => $base_url.'generate', |
---|
736 | 'U_UPDATE' => $base_url.'update', |
---|
737 | 'U_CLEAN' => $base_url.'clean', |
---|
738 | 'U_DELETE' => $base_url.'delete' |
---|
739 | ) |
---|
740 | ); |
---|
741 | } |
---|
742 | // +-----------------------------------------------------------------------+ |
---|
743 | // | sending html code | |
---|
744 | // +-----------------------------------------------------------------------+ |
---|
745 | $template->assign_var_from_handle('ADMIN_CONTENT', 'remote_site'); |
---|
746 | ?> |
---|