source: trunk/admin/site_manager.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: site_manager.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48if (!defined('PHPWG_ROOT_PATH'))
49{
50  die ("Hacking attempt!");
51}
52
53include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
54
55// +-----------------------------------------------------------------------+
56// | Check Access and exit when user status is not ok                      |
57// +-----------------------------------------------------------------------+
58check_status(ACCESS_ADMINISTRATOR);
59
60/**
61 * requests the given $url (a remote create_listing_file.php) and fills a
62 * list of lines corresponding to request output
63 *
64 * @param string $url
65 * @return void
66 */
67function remote_output($url)
68{
69  global $template, $page;
70
71  if($lines = @file($url))
72  {
73    // cleaning lines from HTML tags
74    foreach ($lines as $line)
75    {
76      $line = trim(strip_tags($line));
77      if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches))
78      {
79        $template->append(
80          'remote_output',
81          array(
82            'CLASS' => 'remote'.ucfirst(strtolower($matches[1])),
83            'CONTENT' => $line
84           )
85         );
86      }
87    }
88  }
89  else
90  {
91    array_push($page['errors'], l10n('site_err_remote_file_not_found'));
92  }
93}
94
95
96// +-----------------------------------------------------------------------+
97// |                             template init                             |
98// +-----------------------------------------------------------------------+
99$template->set_filenames(array('site_manager'=>'admin/site_manager.tpl'));
100
101// +-----------------------------------------------------------------------+
102// |                        new site creation form                         |
103// +-----------------------------------------------------------------------+
104if (isset($_POST['submit']) and !empty($_POST['galleries_url'])
105    and !is_adviser() )
106{
107  $is_remote = url_is_remote( $_POST['galleries_url'] );
108  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
109  $url.= '/';
110  if (! $is_remote)
111  {
112    if ( ! (strpos($url, '.') === 0 ) )
113    {
114      $url = './' . $url;
115    }
116  }
117
118  // site must not exists
119  $query = '
120SELECT COUNT(id) AS count
121  FROM '.SITES_TABLE.'
122  WHERE galleries_url = \''.$url.'\'
123;';
124  $row = mysql_fetch_array(pwg_query($query));
125  if ($row['count'] > 0)
126  {
127    array_push($page['errors'],
128      l10n('site_already_exists').' ['.$url.']');
129  }
130  if (count($page['errors']) == 0)
131  {
132    if ($is_remote)
133    {
134      if ( ! isset($_POST['no_check']) )
135      {
136        $clf_url = $url.'create_listing_file.php';
137        $clf_url.= '?action=test';
138        $clf_url.= '&version='.PHPWG_VERSION;
139        if ( ($lines = @file($clf_url)) !== false)
140        {
141          $first_line = strip_tags($lines[0]);
142          if (!preg_match('/^PWG-INFO-2:/', $first_line))
143          {
144            array_push($page['errors'],
145                       l10n('site_err').' : '.$first_line);
146          }
147        }
148        else
149        {
150          array_push($page['errors'], l10n('site_err_remote_file_not_found') );
151        }
152      }
153    }
154    else
155    { // local directory
156      if ( ! file_exists($url) )
157      {
158        array_push($page['errors'],
159          l10n('Directory does not exist').' ['.$url.']');
160      }
161    }
162  }
163
164  if (count($page['errors']) == 0)
165  {
166    $query = '
167INSERT INTO '.SITES_TABLE.'
168  (galleries_url)
169  VALUES
170  (\''.$url.'\')
171;';
172    pwg_query($query);
173    array_push($page['infos'],
174               $url.' '.l10n('site_created'));
175  }
176}
177
178// +-----------------------------------------------------------------------+
179// |                            actions on site                            |
180// +-----------------------------------------------------------------------+
181if (isset($_GET['site']) and is_numeric($_GET['site']))
182{
183  $page['site'] = $_GET['site'];
184}
185if (isset($_GET['action']) and isset($page['site']) and !is_adviser())
186{
187  $query = '
188SELECT galleries_url
189  FROM '.SITES_TABLE.'
190  WHERE id = '.$page['site'].'
191;';
192  list($galleries_url) = mysql_fetch_array(pwg_query($query));
193  switch($_GET['action'])
194  {
195    case 'generate' :
196    {
197      $title = $galleries_url.' : '.l10n('remote_site_generate');
198      remote_output($galleries_url.'create_listing_file.php?action=generate');
199      break;
200    }
201    case 'test' :
202    {
203      $title = $galleries_url.' : '.l10n('remote_site_test');
204      remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION);
205      break;
206    }
207    case 'clean' :
208    {
209      $title = $galleries_url.' : '.l10n('remote_site_clean');
210      remote_output($galleries_url.'create_listing_file.php?action=clean');
211      break;
212    }
213    case 'delete' :
214    {
215      delete_site($page['site']);
216      array_push($page['infos'],
217                 $galleries_url.' '.l10n('site_deleted'));
218      break;
219    }
220  }
221}
222
223$template->assign( array(
224  'U_HELP'    => get_root_url().'popuphelp.php?page=site_manager',
225  'F_ACTION'  => get_root_url().'admin.php'
226                .get_query_string_diff( array('action','site') )
227  ) );
228
229// +-----------------------------------------------------------------------+
230// |                           remote sites list                           |
231// +-----------------------------------------------------------------------+
232
233if ( is_file(PHPWG_ROOT_PATH.'listing.xml') )
234{
235  $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml');
236  $local_listing_site_url = getAttribute(
237          getChild($xml_content, 'informations'),
238          'url'
239        );
240  if ( !url_is_remote($local_listing_site_url) )
241  {
242    $local_listing_site_url = null;
243  }
244}
245
246$query = '
247SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images
248  FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c
249  ON s.id=c.site_id
250  GROUP BY s.id'.
251';';
252$result = pwg_query($query);
253
254while ($row = mysql_fetch_array($result))
255{
256  $is_remote = url_is_remote($row['galleries_url']);
257  $base_url = PHPWG_ROOT_PATH.'admin.php';
258  $base_url.= '?page=site_manager';
259  $base_url.= '&amp;site='.$row['id'];
260  $base_url.= '&amp;action=';
261
262  $update_url = PHPWG_ROOT_PATH.'admin.php';
263  $update_url.= '?page=site_update';
264  $update_url.= '&amp;site='.$row['id'];
265 
266  $tpl_var =
267    array(
268      'NAME' => $row['galleries_url'],
269      'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ),
270      'CATEGORIES' => $row['nb_categories'],
271      'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0,
272      'U_SYNCHRONIZE' => $update_url
273     );
274     
275   if ($is_remote)
276   {
277     $tpl_var['remote'] =
278       array(
279         'U_TEST' => $base_url.'test',
280         'U_GENERATE' => $row['galleries_url'].'create_listing_file.php?action=generate',
281         'U_CLEAN' => $base_url.'clean',
282         );
283   }
284
285  if ($row['id'] != 1)
286  {
287    $tpl_var['U_DELETE'] = $base_url.'delete';
288  }
289
290  $plugin_links = array();
291  //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION
292  $plugin_links =
293    trigger_event('get_admins_site_links',
294      $plugin_links, $row['id'], $is_remote);
295  $tpl_var['plugin_links'] = $plugin_links;
296
297  $template->append('sites', $tpl_var);
298
299  if ( isset($local_listing_site_url) and
300       $row['galleries_url']==$local_listing_site_url )
301  {
302    $local_listing_site_id = $row['id'];
303    $template->assign( 'local_listing',
304        array(
305          'URL' =>  $local_listing_site_url,
306          'U_SYNCHRONIZE' => $update_url.'&amp;local_listing=1'
307        )
308      );
309  }
310}
311
312if ( isset($local_listing_site_url) and !isset($local_listing_site_id) )
313{
314  $template->assign( 'local_listing',
315      array(
316        'URL' =>  $local_listing_site_url,
317        'CREATE' => true
318      )
319    );
320}
321
322
323$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
324?>
Note: See TracBrowser for help on using the repository browser.