Dotclear

source: admin/langs.php @ 1553:e42635c9dc4a

Revision 1553:e42635c9dc4a, 8.1 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Replace class="message" by class="success" where it is needed.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::checkSuper();
16
17$is_writable = is_dir(DC_L10N_ROOT) && is_writable(DC_L10N_ROOT);
18$iso_codes = l10n::getISOCodes();
19
20# Get languages list on Dotclear.net
21$dc_langs = false;
22$feed_reader = new feedReader;
23$feed_reader->setCacheDir(DC_TPL_CACHE);
24$feed_reader->setTimeout(5);
25$feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
26try {
27     $dc_langs = $feed_reader->parse(sprintf(DC_L10N_UPDATE_URL,DC_VERSION));
28     if ($dc_langs !== false) {
29          $dc_langs = $dc_langs->items;
30     }
31} catch (Exception $e) {}
32
33# Delete a language pack
34if ($is_writable && !empty($_POST['delete']) && !empty($_POST['locale_id']))
35{
36     try
37     {
38          $locale_id = $_POST['locale_id'];
39          if (!isset($iso_codes[$locale_id]) || !is_dir(DC_L10N_ROOT.'/'.$locale_id)) {
40               throw new Exception(__('No such installed language'));
41          }
42         
43          if ($locale_id == 'en') {
44               throw new Exception(__("You can't remove English language."));
45          }
46         
47          if (!files::deltree(DC_L10N_ROOT.'/'.$locale_id)) {
48               throw new Exception(__('Permissions to delete language denied.'));
49          }
50         
51          http::redirect('langs.php?removed=1');
52     }
53     catch (Exception $e)
54     {
55          $core->error->add($e->getMessage());
56     }
57}
58
59# Download a language pack
60if ($is_writable && !empty($_POST['pkg_url']))
61{
62     try
63     {
64          if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) {
65               throw new Exception(__('Password verification failed'));
66          }
67         
68          $url = html::escapeHTML($_POST['pkg_url']);
69          $dest = DC_L10N_ROOT.'/'.basename($url);
70          if (!preg_match('#^http://[^.]+\.dotclear\.(net|org)/.*\.zip$#',$url)) {
71               throw new Exception(__('Invalid language file URL.'));
72          }
73         
74          $client = netHttp::initClient($url,$path);
75          $client->setUserAgent('Dotclear - http://www.dotclear.org/');
76          $client->useGzip(false);
77          $client->setPersistReferers(false);
78          $client->setOutput($dest);
79          $client->get($path);
80         
81          try {
82               $ret_code = dc_lang_install($dest);
83          } catch (Exception $e) {
84               @unlink($dest);
85               throw $e;
86          }
87         
88          @unlink($dest);
89          http::redirect('langs.php?added='.$ret_code);
90     }
91     catch (Exception $e)
92     {
93          $core->error->add($e->getMessage());
94     }
95}
96
97# Upload a language pack
98if ($is_writable && !empty($_POST['upload_pkg']))
99{
100     try
101     {
102          if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) {
103               throw new Exception(__('Password verification failed'));
104          }
105         
106          files::uploadStatus($_FILES['pkg_file']);
107          $dest = DC_L10N_ROOT.'/'.$_FILES['pkg_file']['name'];
108          if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) {
109               throw new Exception(__('Unable to move uploaded file.'));
110          }
111         
112          try {
113               $ret_code = dc_lang_install($dest);
114          } catch (Exception $e) {
115               @unlink($dest);
116               throw $e;
117          }
118         
119          @unlink($dest);
120          http::redirect('langs.php?added='.$ret_code);
121     }
122     catch (Exception $e)
123     {
124          $core->error->add($e->getMessage());
125     }
126}
127
128/* DISPLAY Main page
129-------------------------------------------------------- */
130dcPage::open(__('Languages management'),
131     dcPage::jsLoad('js/_langs.js'),
132     dcPage::breadcrumb(
133     array(
134          __('System') => '',
135          '<span class="page-title">'.__('Languages management').'</span>' => ''
136     ))
137);
138
139if (!empty($_GET['removed'])) {
140     dcPage::success(__('Language has been successfully deleted.'));
141}
142
143if (!empty($_GET['added'])) {
144     dcPage::success(($_GET['added'] == 2 ? __('Language has been successfully upgraded') : __('Language has been successfully installed.')));
145}
146
147echo
148'<p>'.__('Here you can install, upgrade or remove languages for your Dotclear '.
149'installation.').'</p>'.
150'<p>'.sprintf(__('You can change your user language in your <a href="%1$s">preferences</a> or '.
151'change your blog\'s main language in your <a href="%2$s">blog settings</a>.'),
152'preferences.php','blog_pref.php').'</p>';
153
154echo
155'<h3>'.__('Installed languages').'</h3>';
156
157$locales_content = scandir(DC_L10N_ROOT);
158$tmp = array();
159foreach ($locales_content as $v) {
160     $c = ($v == '.' || $v == '..' || $v == 'en' || !is_dir(DC_L10N_ROOT.'/'.$v) || !isset($iso_codes[$v]));
161     
162     if (!$c) {
163          $tmp[$v] = DC_L10N_ROOT.'/'.$v;
164     }
165}
166$locales_content = $tmp;
167
168if (empty($locales_content))
169{
170     echo '<p><strong>'.__('No additional language is installed.').'</strong></p>';
171}
172else
173{
174     echo
175     '<table class="clear plugins"><tr>'.
176     '<th>'.__('Language').'</th>'.
177     '<th class="nowrap">'.__('Action').'</th>'.
178     '</tr>';
179     
180     foreach ($locales_content as $k => $v)
181     {
182          $is_deletable = $is_writable && is_writable($v);
183         
184          echo
185          '<tr class="line wide">'.
186          '<td class="maximal nowrap">('.$k.') '.
187          '<strong>'.html::escapeHTML($iso_codes[$k]).'</strong></td>'.
188          '<td class="nowrap action">';
189         
190          if ($is_deletable)
191          {
192               echo
193               '<form action="langs.php" method="post">'.
194               '<div>'.
195               $core->formNonce().
196               form::hidden(array('locale_id'),html::escapeHTML($k)).
197               '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> '.
198               '</div>'.
199               '</form>';
200          }
201         
202          echo '</td></tr>';
203     }
204     echo '</table>';
205}
206
207echo '<h3>'.__('Install or upgrade languages').'</h3>';
208
209if (!$is_writable) {
210     echo '<p>'.sprintf(__('You can install or remove a language by adding or '.
211          'removing the relevant directory in your %s folder.'),'<strong>locales</strong>').'</p>';
212}
213
214if (!empty($dc_langs) && $is_writable)
215{
216     $dc_langs_combo = array();
217     foreach ($dc_langs as $k => $v) {
218          if ($v->link && isset($iso_codes[$v->title])) {
219               $dc_langs_combo[html::escapeHTML('('.$v->title.') '.$iso_codes[$v->title])] = html::escapeHTML($v->link);
220          }
221     }
222     
223     echo
224     '<form method="post" action="langs.php" enctype="multipart/form-data" class="fieldset">'.
225     '<h4>'.__('Available languages').'</h4>'.
226     '<p>'.sprintf(__('You can download and install a additional language directly from Dotclear.net. '.
227     'Proposed languages are based on your version: %s.'),'<strong>'.DC_VERSION.'</strong>').'</p>'.
228     '<p class="field"><label for="pkg_url" class="classic">'.__('Language:').'</label> '.
229     form::combo(array('pkg_url'),$dc_langs_combo).'</p>'.
230     '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
231     form::password(array('your_pwd','your_pwd1'),20,255).'</p>'.
232     '<p><input type="submit" value="'.__('Install language').'" />'.
233     $core->formNonce().
234     '</p>'.
235     '</form>';
236}
237
238if ($is_writable)
239{
240     # 'Upload language pack' form
241     echo
242     '<form method="post" action="langs.php" enctype="multipart/form-data" class="fieldset">'.
243     '<h4>'.__('Upload a zip file').'</h4>'.
244     '<p>'.__('You can install languages by uploading zip files.').'</p>'.
245     '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Language zip file:').'</label> '.
246     '<input type="file" id="pkg_file" name="pkg_file" /></p>'.
247     '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
248     form::password(array('your_pwd','your_pwd2'),20,255).'</p>'.
249     '<p><input type="submit" name="upload_pkg" value="'.__('Upload language').'" />'.
250     $core->formNonce().
251     '</p>'.
252     '</form>';
253}
254
255dcPage::close();
256
257
258# Language installation function
259function dc_lang_install($file)
260{
261     $zip = new fileUnzip($file);
262     $zip->getList(false,'#(^|/)(__MACOSX|\.svn|\.DS_Store|\.directory|Thumbs\.db)(/|$)#');
263     
264     if (!preg_match('/^[a-z]{2,3}(-[a-z]{2})?$/',$zip->getRootDir())) {
265          throw new Exception(__('Invalid language zip file.'));
266     }
267     
268     if ($zip->isEmpty() || !$zip->hasFile($zip->getRootDir().'/main.po')) {
269          throw new Exception(__('The zip file does not appear to be a valid Dotclear language pack.'));
270     }
271     
272     
273     $target = dirname($file);
274     $destination = $target.'/'.$zip->getRootDir();
275     $res = 1;
276     
277     if (is_dir($destination)) {
278          if (!files::deltree($destination)) {
279               throw new Exception(__('An error occurred during language upgrade.'));
280          }
281          $res = 2;
282     }
283     
284     $zip->unzipAll($target);
285     return $res;
286}
287?>
Note: See TracBrowser for help on using the repository browser.

Sites map