source: branches/gettext/admin/themes_new.php @ 5283

Last change on this file since 5283 was 5143, checked in by plg, 15 years ago

feature 1507: ability to install themes directly from piwigo.org/ext.

The theme manager backend for installation is the plugin manager backend,
because they are very close.

thanks to feature:1502, installing a theme and installing a plugin are very
similare operations. The only differences are the installation directory and
the main file to find in the archive.

This is only the very first step, the "add new theme" screen needs many
improvements, to begin with display style.

File size: 4.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 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$base_url = get_root_url().'admin.php?page='.$page['page'];
32
33$themes = new plugins();
34
35// +-----------------------------------------------------------------------+
36// |                           setup check                                 |
37// +-----------------------------------------------------------------------+
38
39$themes_dir = PHPWG_ROOT_PATH.'themes';
40if (!is_writable($themes_dir))
41{
42  array_push(
43    $page['errors'],
44    sprintf(
45      l10n('Add write access to the "%s" directory'),
46      'themes'
47      )
48    );
49}
50
51// +-----------------------------------------------------------------------+
52// |                       perform installation                            |
53// +-----------------------------------------------------------------------+
54
55if (isset($_GET['revision']) and isset($_GET['extension']) and !is_adviser())
56{
57  $install_status = $themes->extract_plugin_files(
58    'install',
59    $_GET['revision'],
60    $_GET['extension'],
61    'theme'
62    );
63 
64  redirect($base_url.'&installstatus='.$install_status);
65}
66
67// +-----------------------------------------------------------------------+
68// |                        installation result                            |
69// +-----------------------------------------------------------------------+
70
71if (isset($_GET['installstatus']))
72{
73  switch ($_GET['installstatus'])
74  {
75    case 'ok':
76      array_push(
77        $page['infos'],
78        l10n('Theme has been successfully installed')
79        );
80      break;
81
82    case 'temp_path_error':
83      array_push($page['errors'], l10n('Can\'t create temporary file.'));
84      break;
85
86    case 'dl_archive_error':
87      array_push($page['errors'], l10n('Can\'t download archive.'));
88      break;
89
90    case 'archive_error':
91      array_push($page['errors'], l10n('Can\'t read or extract archive.'));
92      break;
93
94    default:
95      array_push(
96        $page['errors'],
97        sprintf(l10n('An error occured during extraction (%s).'), $_GET['installstatus'])
98        );
99  } 
100}
101
102// +-----------------------------------------------------------------------+
103// |                          template output                              |
104// +-----------------------------------------------------------------------+
105
106$template->set_filenames(array('themes' => 'themes_new.tpl'));
107
108if ($themes->get_server_plugins(true, 'theme'))
109{
110  foreach($themes->server_plugins as $theme)
111  {
112    $url_auto_install = htmlentities($base_url)
113      . '&amp;revision=' . $theme['revision_id']
114      . '&amp;extension=' . $theme['extension_id']
115      ;
116
117    $template->append(
118      'new_themes',
119      array(
120        'name' => $theme['extension_name'],
121        'src' => PEM_URL.'/upload/extension-'.$theme['extension_id'].'/thumbnail.jpg',
122        'install_url' => $url_auto_install,
123        )
124      );
125  }
126}
127else
128{
129  array_push($page['errors'], l10n('Can\'t connect to server.'));
130}
131
132$template->assign_var_from_handle('ADMIN_CONTENT', 'themes');
133?>
Note: See TracBrowser for help on using the repository browser.