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