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