source: branches/2.2/admin/languages_new.php @ 9998

Last change on this file since 9998 was 9518, checked in by patdenice, 14 years ago

feature:2210
Improve language management.

File size: 5.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo 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/languages.class.php');
30
31$template->set_filenames(array('languages' => 'languages_new.tpl'));
32
33$base_url = get_root_url().'admin.php?page='.$page['page'];
34
35$languages = new languages();
36$languages->get_db_languages();
37$languages->set_tabsheet($page['page']);
38
39// +-----------------------------------------------------------------------+
40// |                           setup check                                 |
41// +-----------------------------------------------------------------------+
42
43$languages_dir = PHPWG_ROOT_PATH.'language';
44if (!is_writable($languages_dir))
45{
46  array_push(
47    $page['errors'],
48    sprintf(
49      l10n('Add write access to the "%s" directory'),
50      'language'
51      )
52    );
53}
54
55// +-----------------------------------------------------------------------+
56// |                       perform installation                            |
57// +-----------------------------------------------------------------------+
58
59if (isset($_GET['revision']))
60{
61  if (!is_webmaster())
62  {
63    array_push($page['errors'], l10n('Webmaster status is required.'));
64  }
65  else
66  {
67    check_pwg_token();
68
69    $install_status = $languages->extract_language_files('install', $_GET['revision']);
70
71    redirect($base_url.'&installstatus='.$install_status);
72  }
73}
74
75// +-----------------------------------------------------------------------+
76// |                        installation result                            |
77// +-----------------------------------------------------------------------+
78if (isset($_GET['installstatus']))
79{
80  switch ($_GET['installstatus'])
81  {
82    case 'ok':
83      array_push($page['infos'],
84        l10n('Language has been successfully installed')
85      );
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['installstatus'])
103      );
104  } 
105}
106
107// +-----------------------------------------------------------------------+
108// |                     start template output                             |
109// +-----------------------------------------------------------------------+
110if ($languages->get_server_languages(true))
111{
112  foreach($languages->server_languages as $language)
113  {
114    list($date, ) = explode(' ', $language['revision_date']);
115
116    $url_auto_install = htmlentities($base_url)
117      . '&amp;revision=' . $language['revision_id']
118      . '&amp;pwg_token='.get_pwg_token()
119    ;
120
121    $template->append('languages', array(
122      'EXT_NAME' => $language['extension_name'],
123      'EXT_DESC' => $language['extension_description'],
124      'EXT_URL' => PEM_URL.'/extension_view.php?eid='.$language['extension_id'],
125      'VERSION' => $language['revision_name'],
126      'VER_DESC' => $language['revision_description'],
127      'DATE' => $date,
128      'AUTHOR' => $language['author_name'],
129      'URL_INSTALL' => $url_auto_install,
130      'URL_DOWNLOAD' => $language['download_url'] . '&amp;origin=piwigo_download'));
131  }
132}
133else
134{
135  array_push($page['errors'], l10n('Can\'t connect to server.'));
136}
137
138$template->assign_var_from_handle('ADMIN_CONTENT', 'languages');
139?>
Note: See TracBrowser for help on using the repository browser.