Dotclear

source: admin/langs.php @ 1305:bcd12d4d85f6

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

Better h2 : now breadcrumb with main level set to Blog, System or Plugins

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);
133
134echo
135'<h2>'.__('System').' &rsaquo; <span class="page-title">'.__('Languages management').'</span></h2>';
136
137if (!empty($_GET['removed'])) {
138     dcPage::message(__('Language has been successfully deleted.'));
139}
140
141if (!empty($_GET['added'])) {
142     dcPage::message(($_GET['added'] == 2 ? __('Language has been successfully upgraded') : __('Language has been successfully installed.')));
143}
144
145echo
146'<p>'.__('Here you can install, upgrade or remove languages for your Dotclear '.
147'installation.').'</p>'.
148'<p>'.sprintf(__('You can change your user language in your <a href="%1$s">preferences</a> or '.
149'change your blog\'s main language in your <a href="%2$s">blog settings</a>.'),
150'preferences.php','blog_pref.php').'</p>';
151
152echo
153'<h3>'.__('Installed languages').'</h3>';
154
155$locales_content = scandir(DC_L10N_ROOT);
156$tmp = array();
157foreach ($locales_content as $v) {
158     $c = ($v == '.' || $v == '..' || $v == 'en' || !is_dir(DC_L10N_ROOT.'/'.$v) || !isset($iso_codes[$v]));
159     
160     if (!$c) {
161          $tmp[$v] = DC_L10N_ROOT.'/'.$v;
162     }
163}
164$locales_content = $tmp;
165
166if (empty($locales_content))
167{
168     echo '<p><strong>'.__('No additional language is installed.').'</strong></p>';
169}
170else
171{
172     echo
173     '<table class="clear plugins"><tr>'.
174     '<th>'.__('Language').'</th>'.
175     '<th class="nowrap">'.__('Action').'</th>'.
176     '</tr>';
177     
178     foreach ($locales_content as $k => $v)
179     {
180          $is_deletable = $is_writable && is_writable($v);
181         
182          echo
183          '<tr class="line wide">'.
184          '<td class="maximal nowrap">('.$k.') '.
185          '<strong>'.html::escapeHTML($iso_codes[$k]).'</strong></td>'.
186          '<td class="nowrap action">';
187         
188          if ($is_deletable)
189          {
190               echo
191               '<form action="langs.php" method="post">'.
192               '<div>'.
193               $core->formNonce().
194               form::hidden(array('locale_id'),html::escapeHTML($k)).
195               '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> '.
196               '</div>'.
197               '</form>';
198          }
199         
200          echo '</td></tr>';
201     }
202     echo '</table>';
203}
204
205echo '<h3>'.__('Install or upgrade languages').'</h3>';
206
207if (!$is_writable) {
208     echo '<p>'.sprintf(__('You can install or remove a language by adding or '.
209          'removing the relevant directory in your %s folder.'),'<strong>locales</strong>').'</p>';
210}
211
212if (!empty($dc_langs) && $is_writable)
213{
214     $dc_langs_combo = array();
215     foreach ($dc_langs as $k => $v) {
216          if ($v->link && isset($iso_codes[$v->title])) {
217               $dc_langs_combo[html::escapeHTML('('.$v->title.') '.$iso_codes[$v->title])] = html::escapeHTML($v->link);
218          }
219     }
220     
221     echo
222     '<form method="post" action="langs.php" enctype="multipart/form-data">'.
223     '<fieldset>'.
224     '<legend>'.__('Available languages').'</legend>'.
225     '<p>'.sprintf(__('You can download and install a additional language directly from Dotclear.net. '.
226     'Proposed languages are based on your version: %s.'),'<strong>'.DC_VERSION.'</strong>').'</p>'.
227     '<p class="field"><label for="pkg_url" class="classic">'.__('Language:').' '.
228     form::combo(array('pkg_url'),$dc_langs_combo).'</label></p>'.
229     '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '.
230     form::password(array('your_pwd','your_pwd1'),20,255).'</label></p>'.
231     '<input type="submit" value="'.__('Install language').'" />'.
232     $core->formNonce().
233     '</fieldset>'.
234     '</form>';
235}
236
237if ($is_writable)
238{
239     # 'Upload language pack' form
240     echo
241     '<form method="post" action="langs.php" enctype="multipart/form-data">'.
242     '<fieldset>'.
243     '<legend>'.__('Upload a zip file').'</legend>'.
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:').' '.
246     '<input type="file" id="pkg_file" name="pkg_file" /></label></p>'.
247     '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '.
248     form::password(array('your_pwd','your_pwd2'),20,255).'</label></p>'.
249     '<input type="submit" name="upload_pkg" value="'.__('Upload language').'" />'.
250     $core->formNonce().
251     '</fieldset>'.
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