source: trunk/admin/site_manager.php @ 1033

Last change on this file since 1033 was 1033, checked in by rvelices, 18 years ago

remake Remote Site/Synchro - bug on commentable + use l10n instead of get_lang

File size: 8.3 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: 2006-01-31 21:46:26 -0500 (Tue, 31 Jan 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
28if (!defined('PHPWG_ROOT_PATH'))
29{
30  die ("Hacking attempt!");
31}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33
34/**
35 * requests the given $url (a remote create_listing_file.php) and fills a
36 * list of lines corresponding to request output
37 *
38 * @param string $url
39 * @return void
40 */
41function remote_output($url)
42{
43  global $template, $page;
44
45  if($lines = @file($url))
46  {
47    $template->assign_block_vars('remote_output', array());
48    // cleaning lines from HTML tags
49    foreach ($lines as $line)
50    {
51      $line = trim(strip_tags($line));
52      if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches))
53      {
54        $template->assign_block_vars(
55          'remote_output.remote_line',
56          array(
57            'CLASS' => 'remote'.ucfirst(strtolower($matches[1])),
58            'CONTENT' => $line
59           )
60         );
61      }
62    }
63  }
64  else
65  {
66    array_push($page['errors'], l10n('remote_site_file_not_found'));
67  }
68}
69
70
71// +-----------------------------------------------------------------------+
72// |                             template init                             |
73// +-----------------------------------------------------------------------+
74$template->set_filenames(array('site_manager'=>'admin/site_manager.tpl'));
75
76// +-----------------------------------------------------------------------+
77// |                        new site creation form                         |
78// +-----------------------------------------------------------------------+
79if (isset($_POST['submit']))
80{
81  $is_remote = url_is_remote( $_POST['galleries_url'] );
82  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
83  $url.= '/';
84  if (! $is_remote)
85  {
86    if ( ! (strpos($url, '.') === 0 ) )
87    {
88      $url = './' . $url;
89    }
90  }
91
92  // site must not exists
93  $query = '
94SELECT COUNT(id) AS count
95  FROM '.SITES_TABLE.'
96  WHERE galleries_url = \''.$url.'\'
97;';
98  $row = mysql_fetch_array(pwg_query($query));
99  if ($row['count'] > 0)
100  {
101    array_push($page['errors'],
102      l10n('remote_site_already_exists').' ['.$url.']');
103  }
104  if (count($page['errors']) == 0)
105  {
106    if ($is_remote)
107    {
108      $clf_url = $url.'create_listing_file.php';
109      $clf_url.= '?action=test';
110      $clf_url.= '&version='.PHPWG_VERSION;
111      if ($lines = @file($clf_url))
112      {
113        $first_line = strip_tags($lines[0]);
114        if (!preg_match('/^PWG-INFO-2:/', $first_line))
115        {
116          array_push($page['errors'],
117                     l10n('remote_site_error').' : '.$first_line);
118        }
119      }
120      else
121      {
122        array_push($page['errors'], l10n('remote_site_file_not_found') );
123      }
124    }
125    else
126    { // local directory
127      if ( ! file_exists($url) )
128      {
129        array_push($page['errors'],
130          l10n('Directory does not exist').' ['.$url.']');
131      }
132    }
133  }
134
135  if (count($page['errors']) == 0)
136  {
137    $query = '
138INSERT INTO '.SITES_TABLE.'
139  (galleries_url)
140  VALUES
141  (\''.$url.'\')
142;';
143    pwg_query($query);
144    array_push($page['infos'],
145               $url.' '.l10n('remote_site_created'));
146  }
147}
148
149// +-----------------------------------------------------------------------+
150// |                            actions on site                            |
151// +-----------------------------------------------------------------------+
152if (isset($_GET['site']) and is_numeric($_GET['site']))
153{
154  $page['site'] = $_GET['site'];
155}
156if (isset($_GET['action']) and isset($page['site']) )
157{
158  $query = '
159SELECT galleries_url
160  FROM '.SITES_TABLE.'
161  WHERE id = '.$page['site'].'
162;';
163  list($galleries_url) = mysql_fetch_array(pwg_query($query));
164  switch($_GET['action'])
165  {
166    case 'generate' :
167    {
168      $title = $galleries_url.' : '.l10n('remote_site_generate');
169      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
170      remote_output($galleries_url.'create_listing_file.php?action=generate');
171      break;
172    }
173    case 'test' :
174    {
175      $title = $galleries_url.' : '.l10n('remote_site_test');
176      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
177      remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION);
178      break;
179    }
180    case 'clean' :
181    {
182      $title = $galleries_url.' : '.l10n('remote_site_clean');
183      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
184      remote_output($galleries_url.'create_listing_file.php?action=clean');
185      break;
186    }
187    case 'delete' :
188    {
189      delete_site($page['site']);
190      array_push($page['infos'],
191                 $galleries_url.' '.l10n('remote_site_deleted'));
192      break;
193    }
194  }
195}
196
197$template->assign_vars( array(
198  'F_ACTION' => PHPWG_ROOT_PATH.'admin.php'
199                .get_query_string_diff( array('action','site') ) 
200  ) );
201 
202// +-----------------------------------------------------------------------+
203// |                           remote sites list                           |
204// +-----------------------------------------------------------------------+
205
206$query = '
207SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images
208FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c
209ON s.id=c.site_id
210GROUP BY s.id'.
211';';
212$result = pwg_query($query);
213
214if (mysql_num_rows($result) > 0)
215{
216  $template->assign_block_vars('sites', array());
217}
218while ($row = mysql_fetch_array($result))
219{
220  $is_remote = url_is_remote($row['galleries_url']);
221  $base_url = PHPWG_ROOT_PATH.'admin.php';
222  $base_url.= '?page=site_manager';
223  $base_url.= '&amp;site='.$row['id'];
224  $base_url.= '&amp;action=';
225
226  $update_url = PHPWG_ROOT_PATH.'admin.php';
227  $update_url.= '?page=site_update';
228  $update_url.= '&amp;site='.$row['id'];
229
230  $template->assign_block_vars(
231    'sites.site',
232    array(
233      'NAME' => $row['galleries_url'],
234      'TYPE' => l10n( $is_remote ? 'Remote' : 'Local' ),
235      'CATEGORIES' => $row['nb_categories'],
236      'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0,
237      'U_UPDATE' => $update_url
238     )
239   );
240
241   if ($is_remote)
242   {
243     $template->assign_block_vars('sites.site.remote',
244       array(
245         'U_TEST' => $base_url.'test',
246         'U_GENERATE' => $base_url.'generate',
247         'U_CLEAN' => $base_url.'clean'
248         )
249       );
250   }
251
252   if ($row['id'] != 1)
253   {
254     $template->assign_block_vars( 'sites.site.delete',
255       array('U_DELETE' => $base_url.'delete') );
256   }
257}
258
259$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
260?>
Note: See TracBrowser for help on using the repository browser.