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