source: branches/2.2/admin/plugins_update.php @ 11371

Last change on this file since 11371 was 9493, checked in by patdenice, 13 years ago

Improve display for plugins and themes update page.

  • Property svn:eol-style set to LF
File size: 5.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
30
31$template->set_filenames(array('plugins' => 'plugins_update.tpl'));
32
33$base_url = get_root_url().'admin.php?page='.$page['page'];
34
35$plugins = new plugins();
36
37//-----------------------------------------------------------automatic upgrade
38if (isset($_GET['plugin']) and isset($_GET['revision']))
39{
40  if (!is_webmaster())
41  {
42    array_push($page['errors'], l10n('Webmaster status is required.'));
43  }
44  else
45  {
46    check_pwg_token();
47   
48    $plugin_id = $_GET['plugin'];
49    $revision = $_GET['revision'];
50
51    if (isset($plugins->db_plugins_by_id[$plugin_id])
52      and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active')
53    {
54      $plugins->perform_action('deactivate', $plugin_id);
55
56      redirect($base_url
57        . '&revision=' . $revision
58        . '&plugin=' . $plugin_id
59        . '&pwg_token='.get_pwg_token()
60        . '&reactivate=true');
61    }
62
63    $upgrade_status = $plugins->extract_plugin_files('upgrade', $revision, $plugin_id);
64
65    if (isset($_GET['reactivate']))
66    {
67      $plugins->perform_action('activate', $plugin_id);
68    }
69
70    $template->delete_compiled_templates();
71
72    redirect($base_url.'&plugin='.$plugin_id.'&upgradestatus='.$upgrade_status);
73  }
74}
75
76//--------------------------------------------------------------upgrade result
77if (isset($_GET['upgradestatus']) and isset($_GET['plugin']))
78{
79  switch ($_GET['upgradestatus'])
80  {
81    case 'ok':
82      array_push($page['infos'],
83         sprintf(
84            l10n('%s has been successfully upgraded.'),
85            $plugins->fs_plugins[$_GET['plugin']]['name']));
86      break;
87
88    case 'temp_path_error':
89      array_push($page['errors'], l10n('Can\'t create temporary file.'));
90      break;
91
92    case 'dl_archive_error':
93      array_push($page['errors'], l10n('Can\'t download archive.'));
94      break;
95
96    case 'archive_error':
97      array_push($page['errors'], l10n('Can\'t read or extract archive.'));
98      break;
99
100    default:
101      array_push($page['errors'],
102        sprintf(l10n('An error occured during extraction (%s).'), $_GET['upgradestatus']),
103        l10n('Please check "plugins" folder and sub-folders permissions (CHMOD).'));
104  } 
105}
106
107//--------------------------------------------------------------------Tabsheet
108$plugins->set_tabsheet($page['page']);
109
110// +-----------------------------------------------------------------------+
111// |                     start template output                             |
112// +-----------------------------------------------------------------------+
113if ($plugins->get_server_plugins())
114{
115  foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
116  {
117    if (isset($fs_plugin['extension'])
118      and isset($plugins->server_plugins[$fs_plugin['extension']]))
119    {
120      $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
121
122      if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name']))
123      {
124        $url_auto_update = $base_url
125          . '&amp;revision=' . $plugin_info['revision_id']
126          . '&amp;plugin=' . $plugin_id
127          . '&amp;pwg_token='.get_pwg_token()
128          ;
129
130        $template->append('plugins', array(
131          'ID' => $plugin_info['extension_id'],
132          'EXT_NAME' => $fs_plugin['name'],
133          'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$plugin_info['extension_id'],
134          'EXT_DESC' => trim($plugin_info['extension_description'], " \n\r"),
135          'REV_DESC' => trim($plugin_info['revision_description'], " \n\r"),
136          'CURRENT_VERSION' => $fs_plugin['version'],
137          'NEW_VERSION' => $plugin_info['revision_name'],
138          'AUTHOR' => $plugin_info['author_name'],
139          'DOWNLOADS' => $plugin_info['extension_nb_downloads'],
140          'URL_UPDATE' => $url_auto_update,
141          'URL_DOWNLOAD' => $plugin_info['download_url'] . '&amp;origin=piwigo_download'));
142      }
143    }
144  }
145}
146else
147{
148  $template->assign('SERVER_ERROR', true);
149  array_push($page['errors'], l10n('Can\'t connect to server.'));
150}
151
152$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
153?>
Note: See TracBrowser for help on using the repository browser.