source: branches/2.0/admin/site_manager.php @ 2904

Last change on this file since 2904 was 2903, checked in by patdenice, 16 years ago

merge -c2902 from trunk to branch 2.0.

  • Add home and identification buttons after installation.
  • Use fetchRemote function for remote site actions.
  • Corrections in fetchRemote fnction.
  • Move PLUGIN_PICTURE_BEFORE in picture.tpl.
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
RevLine 
[1058]1<?php
2// +-----------------------------------------------------------------------+
[2297]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// +-----------------------------------------------------------------------+
[1058]23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die ("Hacking attempt!");
27}
28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
[1058]36/**
37 * requests the given $url (a remote create_listing_file.php) and fills a
38 * list of lines corresponding to request output
39 *
40 * @param string $url
41 * @return void
42 */
43function remote_output($url)
44{
45  global $template, $page;
46
[2903]47  if (fetchRemote($url, $result))
[1058]48  {
[2903]49    $lines = explode("\r\n", $result);
[1058]50    // cleaning lines from HTML tags
51    foreach ($lines as $line)
52    {
53      $line = trim(strip_tags($line));
54      if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches))
55      {
[2273]56        $template->append(
57          'remote_output',
[1058]58          array(
59            'CLASS' => 'remote'.ucfirst(strtolower($matches[1])),
60            'CONTENT' => $line
61           )
62         );
63      }
64    }
65  }
66  else
67  {
68    array_push($page['errors'], l10n('site_err_remote_file_not_found'));
69  }
70}
71
72
73// +-----------------------------------------------------------------------+
74// |                             template init                             |
75// +-----------------------------------------------------------------------+
[2530]76$template->set_filenames(array('site_manager'=>'site_manager.tpl'));
[1058]77
78// +-----------------------------------------------------------------------+
79// |                        new site creation form                         |
80// +-----------------------------------------------------------------------+
[1654]81if (isset($_POST['submit']) and !empty($_POST['galleries_url'])
82    and !is_adviser() )
[1058]83{
84  $is_remote = url_is_remote( $_POST['galleries_url'] );
85  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
86  $url.= '/';
87  if (! $is_remote)
88  {
89    if ( ! (strpos($url, '.') === 0 ) )
90    {
91      $url = './' . $url;
92    }
93  }
94
95  // site must not exists
96  $query = '
97SELECT COUNT(id) AS count
98  FROM '.SITES_TABLE.'
99  WHERE galleries_url = \''.$url.'\'
100;';
101  $row = mysql_fetch_array(pwg_query($query));
102  if ($row['count'] > 0)
103  {
104    array_push($page['errors'],
105      l10n('site_already_exists').' ['.$url.']');
106  }
107  if (count($page['errors']) == 0)
108  {
109    if ($is_remote)
110    {
[1107]111      if ( ! isset($_POST['no_check']) )
[1058]112      {
[1107]113        $clf_url = $url.'create_listing_file.php';
114        $clf_url.= '?action=test';
115        $clf_url.= '&version='.PHPWG_VERSION;
[2903]116        if (fetchRemote($clf_url, $result))
[1058]117        {
[2903]118          $lines = explode("\r\n", $result);
[1107]119          $first_line = strip_tags($lines[0]);
120          if (!preg_match('/^PWG-INFO-2:/', $first_line))
121          {
122            array_push($page['errors'],
123                       l10n('site_err').' : '.$first_line);
124          }
[1058]125        }
[1107]126        else
127        {
128          array_push($page['errors'], l10n('site_err_remote_file_not_found') );
129        }
[1058]130      }
131    }
132    else
133    { // local directory
134      if ( ! file_exists($url) )
135      {
136        array_push($page['errors'],
137          l10n('Directory does not exist').' ['.$url.']');
138      }
139    }
140  }
141
142  if (count($page['errors']) == 0)
143  {
144    $query = '
145INSERT INTO '.SITES_TABLE.'
146  (galleries_url)
147  VALUES
148  (\''.$url.'\')
149;';
150    pwg_query($query);
151    array_push($page['infos'],
152               $url.' '.l10n('site_created'));
153  }
154}
155
156// +-----------------------------------------------------------------------+
157// |                            actions on site                            |
158// +-----------------------------------------------------------------------+
159if (isset($_GET['site']) and is_numeric($_GET['site']))
160{
161  $page['site'] = $_GET['site'];
162}
[1458]163if (isset($_GET['action']) and isset($page['site']) and !is_adviser())
[1058]164{
165  $query = '
166SELECT galleries_url
167  FROM '.SITES_TABLE.'
168  WHERE id = '.$page['site'].'
169;';
170  list($galleries_url) = mysql_fetch_array(pwg_query($query));
171  switch($_GET['action'])
172  {
173    case 'generate' :
174    {
175      $title = $galleries_url.' : '.l10n('remote_site_generate');
176      remote_output($galleries_url.'create_listing_file.php?action=generate');
177      break;
178    }
179    case 'test' :
180    {
181      $title = $galleries_url.' : '.l10n('remote_site_test');
182      remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION);
183      break;
184    }
185    case 'clean' :
186    {
187      $title = $galleries_url.' : '.l10n('remote_site_clean');
188      remote_output($galleries_url.'create_listing_file.php?action=clean');
189      break;
190    }
191    case 'delete' :
192    {
193      delete_site($page['site']);
194      array_push($page['infos'],
195                 $galleries_url.' '.l10n('site_deleted'));
196      break;
197    }
198  }
199}
200
[2273]201$template->assign( array(
202  'U_HELP'    => get_root_url().'popuphelp.php?page=site_manager',
203  'F_ACTION'  => get_root_url().'admin.php'
[1058]204                .get_query_string_diff( array('action','site') )
205  ) );
206
207// +-----------------------------------------------------------------------+
208// |                           remote sites list                           |
209// +-----------------------------------------------------------------------+
210
[1107]211if ( is_file(PHPWG_ROOT_PATH.'listing.xml') )
212{
213  $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml');
214  $local_listing_site_url = getAttribute(
215          getChild($xml_content, 'informations'),
216          'url'
217        );
218  if ( !url_is_remote($local_listing_site_url) )
219  {
220    $local_listing_site_url = null;
221  }
222}
223
[1058]224$query = '
[2324]225SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images
226  FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i
227  ON c.id=i.storage_category_id
228  WHERE c.site_id IS NOT NULL
229  GROUP BY c.site_id
230;';
231$sites_detail = hash_from_query($query, 'site_id'); 
232
233$query = '
234SELECT *
235  FROM '.SITES_TABLE.'
236;';
[1058]237$result = pwg_query($query);
238
239while ($row = mysql_fetch_array($result))
240{
241  $is_remote = url_is_remote($row['galleries_url']);
242  $base_url = PHPWG_ROOT_PATH.'admin.php';
243  $base_url.= '?page=site_manager';
244  $base_url.= '&amp;site='.$row['id'];
245  $base_url.= '&amp;action=';
246
247  $update_url = PHPWG_ROOT_PATH.'admin.php';
248  $update_url.= '?page=site_update';
249  $update_url.= '&amp;site='.$row['id'];
[2273]250 
251  $tpl_var =
[1058]252    array(
253      'NAME' => $row['galleries_url'],
254      'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ),
[2324]255      'CATEGORIES' => (int)@$sites_detail[$row['id']]['nb_categories'],
256      'IMAGES' => (int)@$sites_detail[$row['id']]['nb_images'],
[1058]257      'U_SYNCHRONIZE' => $update_url
[2273]258     );
259     
[1058]260   if ($is_remote)
261   {
[2273]262     $tpl_var['remote'] =
[1058]263       array(
264         'U_TEST' => $base_url.'test',
[1775]265         'U_GENERATE' => $row['galleries_url'].'create_listing_file.php?action=generate',
266         'U_CLEAN' => $base_url.'clean',
[2273]267         );
[1058]268   }
269
[1107]270  if ($row['id'] != 1)
271  {
[2273]272    $tpl_var['U_DELETE'] = $base_url.'delete';
[1107]273  }
274
[2273]275  $plugin_links = array();
276  //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION
277  $plugin_links =
278    trigger_event('get_admins_site_links',
279      $plugin_links, $row['id'], $is_remote);
280  $tpl_var['plugin_links'] = $plugin_links;
281
282  $template->append('sites', $tpl_var);
283
[1107]284  if ( isset($local_listing_site_url) and
285       $row['galleries_url']==$local_listing_site_url )
286  {
287    $local_listing_site_id = $row['id'];
[2273]288    $template->assign( 'local_listing',
[1107]289        array(
290          'URL' =>  $local_listing_site_url,
[2273]291          'U_SYNCHRONIZE' => $update_url.'&amp;local_listing=1'
[1107]292        )
293      );
294  }
[1058]295}
296
[1107]297if ( isset($local_listing_site_url) and !isset($local_listing_site_id) )
298{
[2273]299  $template->assign( 'local_listing',
[1107]300      array(
301        'URL' =>  $local_listing_site_url,
[2273]302        'CREATE' => true
[1107]303      )
304    );
305}
306
307
[1058]308$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
[1775]309?>
Note: See TracBrowser for help on using the repository browser.