source: trunk/admin/themes_update.php @ 9472

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

Add themes autmatic update functionality.

File size: 5.6 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
24
25if( !defined("PHPWG_ROOT_PATH") )
26{
27  die ("Hacking attempt!");
28}
29
30include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
31
32$base_url = get_root_url().'admin.php?page='.$page['page'];
33
34$themes = new themes();
35
36$themes->set_tabsheet($page['page']);
37
38//-----------------------------------------------------------automatic upgrade
39if (isset($_GET['theme']) and isset($_GET['revision']))
40{
41  if (!is_webmaster())
42  {
43    array_push($page['errors'], l10n('Webmaster status is required.'));
44  }
45  else
46  {
47    check_pwg_token();
48   
49    $theme_id = $_GET['theme'];
50    $revision = $_GET['revision'];
51
52    $upgrade_status = $themes->extract_theme_files('upgrade', $revision, $theme_id);
53
54    switch ($upgrade_status)
55    {
56      case 'ok':
57        array_push($page['infos'],
58           sprintf(
59              l10n('%s has been successfully upgraded.'),
60              $themes->fs_themes[$_GET['theme']]['name']));
61        break;
62
63      case 'temp_path_error':
64        array_push($page['errors'], l10n('Can\'t create temporary file.'));
65        break;
66
67      case 'dl_archive_error':
68        array_push($page['errors'], l10n('Can\'t download archive.'));
69        break;
70
71      case 'archive_error':
72        array_push($page['errors'], l10n('Can\'t read or extract archive.'));
73        break;
74
75      default:
76        array_push($page['errors'],
77          sprintf(l10n('An error occured during extraction (%s).'), $_GET['upgradestatus'])
78        );
79    }
80
81    $themes->themes();
82    $template->delete_compiled_templates();
83  }
84}
85
86// +-----------------------------------------------------------------------+
87// |                     start template output                             |
88// +-----------------------------------------------------------------------+
89$template->set_filenames(array('themes' => 'themes_update.tpl'));
90
91if ($themes->get_server_themes())
92{
93  foreach($themes->fs_themes as $theme_id => $fs_theme)
94  {
95    if (isset($fs_theme['extension'])
96      and isset($themes->server_themes[$fs_theme['extension']]))
97    {
98      $theme_info = $themes->server_themes[$fs_theme['extension']];
99
100      list($date, ) = explode(' ', $theme_info['revision_date']);
101
102      $ext_desc = '<i>'.l10n('Downloads').':</i> '.$theme_info['extension_nb_downloads']."\r\n"
103        ."\r\n"
104        .$theme_info['extension_description'];
105
106      $rev_desc = '<i>'.l10n('Version').':</i> '.$theme_info['revision_name']."\r\n"
107        .'<i>'.l10n('Released on').':</i> '.$date."\r\n"
108        .'<i>'.l10n('Downloads').':</i> '.$theme_info['revision_nb_downloads']."\r\n"
109        ."\r\n"
110        .$theme_info['revision_description'];
111
112      if ($themes->theme_version_compare($fs_theme['version'], $theme_info['revision_name']))
113      {
114        // Plugin is up to date
115        $template->append('themes_uptodate', array(
116          'URL' => PEM_URL.'/extension_view.php?eid='.$theme_info['extension_id'],
117          'NAME' => $fs_theme['name'],
118          'EXT_DESC' => $ext_desc,
119          'VERSION' => $fs_theme['version'],
120          'VER_DESC' => $rev_desc));
121      }
122      else
123      {
124        // Plugin need upgrade
125        $url_auto_update = $base_url
126          . '&amp;revision=' . $theme_info['revision_id']
127          . '&amp;theme=' . $theme_id
128          . '&amp;pwg_token='.get_pwg_token()
129          ;
130
131        $template->append('themes_not_uptodate', array(
132          'EXT_NAME' => $fs_theme['name'],
133          'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$theme_info['extension_id'],
134          'EXT_DESC' => $ext_desc,
135          'VERSION' => $fs_theme['version'],
136          'NEW_VERSION' => $theme_info['revision_name'],
137          'NEW_VER_DESC' => $rev_desc,
138          'URL_UPDATE' => $url_auto_update,
139          'URL_DOWNLOAD' => $theme_info['download_url'] . '&amp;origin=piwigo_download'));
140      }
141    }
142    else
143    {
144      // Can't check theme
145      $template->append('themes_cant_check', array(
146        'NAME' => $fs_theme['name'],
147        'VERSION' => $fs_theme['version']));
148    }
149  }
150}
151else
152{
153  array_push($page['errors'], l10n('Can\'t connect to server.'));
154}
155
156$template->assign_var_from_handle('ADMIN_CONTENT', 'themes');
157?>
Note: See TracBrowser for help on using the repository browser.