source: trunk/admin/site_manager.php @ 1775

Last change on this file since 1775 was 1775, checked in by laurent_duretz, 17 years ago

Issue 0000475 : Synchroniser plus de 7000 photos

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 KB
Line 
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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-02-01 22:35:22 +0000 (Thu, 01 Feb 2007) $
10// | last modifier : $Author: laurent_duretz $
11// | revision      : $Revision: 1775 $
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
28if (!defined('PHPWG_ROOT_PATH'))
29{
30  die ("Hacking attempt!");
31}
32
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
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 */
47function remote_output($url)
48{
49  global $template, $page;
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'], l10n('site_err_remote_file_not_found'));
73  }
74}
75
76
77// +-----------------------------------------------------------------------+
78// |                             template init                             |
79// +-----------------------------------------------------------------------+
80$template->set_filenames(array('site_manager'=>'admin/site_manager.tpl'));
81
82// +-----------------------------------------------------------------------+
83// |                        new site creation form                         |
84// +-----------------------------------------------------------------------+
85if (isset($_POST['submit']) and !empty($_POST['galleries_url'])
86    and !is_adviser() )
87{
88  $is_remote = url_is_remote( $_POST['galleries_url'] );
89  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
90  $url.= '/';
91  if (! $is_remote)
92  {
93    if ( ! (strpos($url, '.') === 0 ) )
94    {
95      $url = './' . $url;
96    }
97  }
98
99  // site must not exists
100  $query = '
101SELECT COUNT(id) AS count
102  FROM '.SITES_TABLE.'
103  WHERE galleries_url = \''.$url.'\'
104;';
105  $row = mysql_fetch_array(pwg_query($query));
106  if ($row['count'] > 0)
107  {
108    array_push($page['errors'],
109      l10n('site_already_exists').' ['.$url.']');
110  }
111  if (count($page['errors']) == 0)
112  {
113    if ($is_remote)
114    {
115      if ( ! isset($_POST['no_check']) )
116      {
117        $clf_url = $url.'create_listing_file.php';
118        $clf_url.= '?action=test';
119        $clf_url.= '&version='.PHPWG_VERSION;
120        if ($lines = @file($clf_url))
121        {
122          $first_line = strip_tags($lines[0]);
123          if (!preg_match('/^PWG-INFO-2:/', $first_line))
124          {
125            array_push($page['errors'],
126                       l10n('site_err').' : '.$first_line);
127          }
128        }
129        else
130        {
131          array_push($page['errors'], l10n('site_err_remote_file_not_found') );
132        }
133      }
134    }
135    else
136    { // local directory
137      if ( ! file_exists($url) )
138      {
139        array_push($page['errors'],
140          l10n('Directory does not exist').' ['.$url.']');
141      }
142    }
143  }
144
145  if (count($page['errors']) == 0)
146  {
147    $query = '
148INSERT INTO '.SITES_TABLE.'
149  (galleries_url)
150  VALUES
151  (\''.$url.'\')
152;';
153    pwg_query($query);
154    array_push($page['infos'],
155               $url.' '.l10n('site_created'));
156  }
157}
158
159// +-----------------------------------------------------------------------+
160// |                            actions on site                            |
161// +-----------------------------------------------------------------------+
162if (isset($_GET['site']) and is_numeric($_GET['site']))
163{
164  $page['site'] = $_GET['site'];
165}
166if (isset($_GET['action']) and isset($page['site']) and !is_adviser())
167{
168  $query = '
169SELECT galleries_url
170  FROM '.SITES_TABLE.'
171  WHERE id = '.$page['site'].'
172;';
173  list($galleries_url) = mysql_fetch_array(pwg_query($query));
174  switch($_GET['action'])
175  {
176    case 'generate' :
177    {
178      $title = $galleries_url.' : '.l10n('remote_site_generate');
179      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
180      remote_output($galleries_url.'create_listing_file.php?action=generate');
181      break;
182    }
183    case 'test' :
184    {
185      $title = $galleries_url.' : '.l10n('remote_site_test');
186      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
187      remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION);
188      break;
189    }
190    case 'clean' :
191    {
192      $title = $galleries_url.' : '.l10n('remote_site_clean');
193      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
194      remote_output($galleries_url.'create_listing_file.php?action=clean');
195      break;
196    }
197    case 'protect' :
198    {
199      $title = $galleries_url.' : '.l10n('remote_site_protect');
200      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
201      remote_output($galleries_url.'create_listing_file.php?action=protect');
202      break;
203    }
204    case 'delete' :
205    {
206      delete_site($page['site']);
207      array_push($page['infos'],
208                 $galleries_url.' '.l10n('site_deleted'));
209      break;
210    }
211  }
212}
213
214$template->assign_vars( array(
215  'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=site_manager',
216  'F_ACTION' => PHPWG_ROOT_PATH.'admin.php'
217                .get_query_string_diff( array('action','site') )
218  ) );
219
220// +-----------------------------------------------------------------------+
221// |                           remote sites list                           |
222// +-----------------------------------------------------------------------+
223
224if ( is_file(PHPWG_ROOT_PATH.'listing.xml') )
225{
226  $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml');
227  $local_listing_site_url = getAttribute(
228          getChild($xml_content, 'informations'),
229          'url'
230        );
231  if ( !url_is_remote($local_listing_site_url) )
232  {
233    $local_listing_site_url = null;
234  }
235}
236
237$query = '
238SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images
239  FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c
240  ON s.id=c.site_id
241  GROUP BY s.id'.
242';';
243$result = pwg_query($query);
244
245if (mysql_num_rows($result) > 0)
246{
247  $template->assign_block_vars('sites', array());
248}
249while ($row = mysql_fetch_array($result))
250{
251  $is_remote = url_is_remote($row['galleries_url']);
252  $base_url = PHPWG_ROOT_PATH.'admin.php';
253  $base_url.= '?page=site_manager';
254  $base_url.= '&amp;site='.$row['id'];
255  $base_url.= '&amp;action=';
256
257  $update_url = PHPWG_ROOT_PATH.'admin.php';
258  $update_url.= '?page=site_update';
259  $update_url.= '&amp;site='.$row['id'];
260  $template->assign_block_vars(
261    'sites.site',
262    array(
263      'NAME' => $row['galleries_url'],
264      'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ),
265      'CATEGORIES' => $row['nb_categories'],
266      'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0,
267      'U_SYNCHRONIZE' => $update_url
268     )
269   );
270   if ($is_remote)
271   {
272     $template->assign_block_vars('sites.site.remote',
273       array(
274         'U_TEST' => $base_url.'test',
275         'U_GENERATE' => $row['galleries_url'].'create_listing_file.php?action=generate',
276         'U_CLEAN' => $base_url.'clean',
277         'U_PROTECT' => $base_url.'protect'
278         )
279       );
280   }
281
282  if ($row['id'] != 1)
283  {
284    $template->assign_block_vars( 'sites.site.delete',
285      array('U_DELETE' => $base_url.'delete') );
286  }
287
288  if ( isset($local_listing_site_url) and
289       $row['galleries_url']==$local_listing_site_url )
290  {
291    $local_listing_site_id = $row['id'];
292    $template->assign_block_vars( 'local_listing',
293        array(
294          'URL' =>  $local_listing_site_url,
295        )
296      );
297
298    $template->assign_block_vars( 'local_listing.update',
299          array(
300            'U_SYNCHRONIZE' => $update_url.'&amp;local_listing=1'
301            )
302        );
303  }
304 
305  $plugin_links = array();
306  //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION
307  $plugin_links = 
308    trigger_event('get_admins_site_links',
309      $plugin_links, $row['id'], $is_remote);
310
311  // plugin_links
312  if (count($plugin_links) > 0)
313  {
314    foreach ($plugin_links as $plugin_link)
315    {
316      $template->assign_block_vars('sites.site.plugin_links.plugin_link', $plugin_link);
317    }
318  }
319
320}
321
322if ( isset($local_listing_site_url) and !isset($local_listing_site_id) )
323{
324  $template->assign_block_vars( 'local_listing',
325      array(
326        'URL' =>  $local_listing_site_url,
327      )
328    );
329
330  $template->assign_block_vars( 'local_listing.create',
331        array('NAME' => $local_listing_site_url)
332      );
333}
334
335
336$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
337?>
Note: See TracBrowser for help on using the repository browser.