source: trunk/admin/plugins_update.php @ 2255

Last change on this file since 2255 was 2255, checked in by rvelices, 16 years ago
  • plugins.php does only the tabsheet - nothing else
  • need to review plugins_update.php upgrade action
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: plugins_update.php 2255 2008-03-06 02:29:29Z rvelices $
7// | last update   : $Date: 2008-03-06 02:29:29 +0000 (Thu, 06 Mar 2008) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Revision: 2255 $
10// +-----------------------------------------------------------------------+
11// | This program is free software; you can redistribute it and/or modify  |
12// | it under the terms of the GNU General Public License as published by  |
13// | the Free Software Foundation                                          |
14// |                                                                       |
15// | This program is distributed in the hope that it will be useful, but   |
16// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
17// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
18// | General Public License for more details.                              |
19// |                                                                       |
20// | You should have received a copy of the GNU General Public License     |
21// | along with this program; if not, write to the Free Software           |
22// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23// | USA.                                                                  |
24// +-----------------------------------------------------------------------+
25
26if( !defined("PHPWG_ROOT_PATH") )
27{
28  die ("Hacking attempt!");
29}
30
31$fs_plugins = get_fs_plugins();
32$my_base_url= get_root_url().'admin.php'.get_query_string_diff( array('upgrade', 'plugin', 'reactivate', 'action', 'upgradestatus') );
33
34$db_plugins = get_db_plugins();
35$db_plugins_by_id = array();
36foreach ($db_plugins as $db_plugin)
37{
38  $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
39}
40
41$template->set_filenames(array('plugins' => 'admin/plugins_update.tpl'));
42
43
44//-----------------------------------------------------------automatic upgrade
45if (isset($_GET['upgrade']) and isset($_GET['plugin']) and !is_adviser())
46{
47  include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
48
49  $upgrade_status  = extract_plugin_files('upgrade',
50                      $_GET['upgrade'],
51                      $_GET['plugin']);
52
53  $my_base_url .= isset($_GET['reactivate']) ? '&action=activate' : '';
54
55  redirect($my_base_url.'&plugin='.$_GET['plugin'].'&upgradestatus='.$upgrade_status);
56}
57
58
59//--------------------------------------------------------------upgrade result
60if (isset($_GET['upgradestatus']) and isset($_GET['plugin']))
61{
62  switch ($_GET['upgradestatus'])
63  {
64  case 'ok':
65    array_push($page['infos'],
66               sprintf(l10n('plugins_upgrade_ok'),
67               $fs_plugins[$_GET['plugin']]['name']));
68    break;
69
70  case 'temp_path_error':
71    array_push($page['errors'], l10n('plugins_temp_path_error'));
72    break;
73
74  case 'dl_archive_error':
75    array_push($page['errors'], l10n('plugins_dl_archive_error'));
76    break;
77
78  case 'archive_error':
79    array_push($page['errors'], l10n('plugins_archive_error'));
80    break;
81
82  default:
83    array_push($page['errors'],
84               sprintf(l10n('plugins_extract_error'),
85               $_GET['upgradestatus']));
86  }
87}
88
89
90// +-----------------------------------------------------------------------+
91// |                     start template output                             |
92// +-----------------------------------------------------------------------+
93$plugins_infos = check_server_plugins($fs_plugins);
94
95if ($plugins_infos !== false)
96{
97  foreach($fs_plugins as $plugin_id => $fs_plugin)
98  {
99    if (isset($fs_plugin['extension'])
100      and isset($plugins_infos[$fs_plugin['extension']]))
101    {
102      $plugin_info = $plugins_infos[$fs_plugin['extension']];
103
104      $ext_desc = nl2br(htmlspecialchars(strip_tags(
105                    utf8_encode($plugin_info['ext_description']))));
106
107      $ver_desc = sprintf(l10n('plugins_description'),
108              $plugin_info['version'],
109              date('Y-m-d', $plugin_info['date']),
110              nl2br(htmlspecialchars(strip_tags(
111                utf8_encode($plugin_info['description'])))));
112
113      if ($plugin_info['version'] == $fs_plugin['version'])
114      {
115        // Plugin is up to date
116        $template->append('plugins_uptodate',
117              array('URL' => $fs_plugin['uri'],
118                'NAME' => $fs_plugin['name'],
119                'EXT_DESC' => $ext_desc,
120                'VERSION' => $fs_plugin['version'],
121                'VER_DESC' => $ver_desc));
122      }
123      else
124      {
125        // Plugin need upgrade
126        $url_auto_update = $my_base_url
127          . '&amp;plugin=' . $plugin_id
128          . (
129              (isset($db_plugins_by_id[$plugin_id])
130                and $db_plugins_by_id[$plugin_id]['state'] == 'active') ?
131                  '&amp;action=deactivate' : ''
132            )
133          . '&amp;upgrade=%2Fupload%2Fextension-' . $fs_plugin['extension']
134          . '%2Frevision-' . $plugin_info['id_revision']
135          . '%2F' . $plugin_info['url'];
136
137        $url_download = PEM_URL.'/upload/extension-'. $fs_plugin['extension']
138            . '/revision-' . $plugin_info['id_revision']
139            . '/' . $plugin_info['url'];
140
141        $template->append('plugins_not_uptodate',
142          array('EXT_NAME' => $fs_plugin['name'],
143            'EXT_URL' => $fs_plugin['uri'],
144            'EXT_DESC' => $ext_desc,
145            'VERSION' => $fs_plugin['version'],
146            'VERSION_URL' => PEM_URL.'/revision_view.php?rid='.$plugin_info['id_revision'],
147            'NEW_VERSION' => $plugin_info['version'],
148            'NEW_VER_DESC' => $ver_desc,
149            'URL_UPDATE' => $url_auto_update,
150            'URL_DOWNLOAD' => $url_download));
151      }
152    }
153    else
154    {
155      // Can't check plugin
156      $template->append('plugins_cant_check',
157          array('NAME' => $fs_plugin['name'],
158            'VERSION' => $fs_plugin['version']));
159    }
160  }
161}
162else
163{
164  array_push($page['errors'], l10n('plugins_server_error'));
165}
166
167$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
168?>
Note: See TracBrowser for help on using the repository browser.