source: trunk/admin/site_manager.php @ 2273

Last change on this file since 2273 was 2273, checked in by rvelices, 16 years ago

group_list, group_perm and site_manager go smarty

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