[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2010 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 | |
---|
| 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 | } |
---|
| 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 |
---|
| 60 | if ($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 |
---|
| 98 | if ($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 | -------------------------------------------------------- */ |
---|
| 130 | dcPage::open(__('Languages management'), |
---|
| 131 | dcPage::jsLoad('js/_langs.js') |
---|
| 132 | ); |
---|
| 133 | |
---|
| 134 | echo |
---|
| 135 | '<h2>'.__('Languages management').'</h2>'; |
---|
| 136 | |
---|
| 137 | if (!empty($_GET['removed'])) { |
---|
| 138 | echo '<p class="message">'.__('Language has been successfully deleted.').'</p>'; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if (!empty($_GET['added'])) { |
---|
| 142 | echo '<p class="message">'. |
---|
| 143 | ($_GET['added'] == 2 ? __('Language has been successfully upgraded') : __('Language has been successfully installed.')). |
---|
| 144 | '</p>'; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | echo |
---|
| 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 | |
---|
| 154 | echo |
---|
| 155 | '<h3>'.__('Installed languages').'</h3>'; |
---|
| 156 | |
---|
| 157 | $locales_content = scandir(DC_L10N_ROOT); |
---|
| 158 | $tmp = array(); |
---|
| 159 | foreach ($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 | |
---|
| 168 | if (empty($locales_content)) |
---|
| 169 | { |
---|
| 170 | echo '<p><strong>'.__('No additional language is installed.').'</strong></p>'; |
---|
| 171 | } |
---|
| 172 | else |
---|
| 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 | |
---|
| 207 | echo '<h3>'.__('Install or upgrade languages').'</h3>'; |
---|
| 208 | |
---|
| 209 | if (!$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 | |
---|
| 214 | if (!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">'. |
---|
| 225 | '<fieldset>'. |
---|
| 226 | '<legend>'.__('Available languages').'</legend>'. |
---|
| 227 | '<p>'.sprintf(__('You can download and install a additional language directly from Dotclear.net. '. |
---|
| 228 | 'Proposed languages are based on your version: %s.'),'<strong>'.DC_VERSION.'</strong>').'</p>'. |
---|
| 229 | '<p class="field"><label class="classic">'.__('Language:').' '. |
---|
| 230 | form::combo(array('pkg_url'),$dc_langs_combo).'</label></p>'. |
---|
| 231 | '<p class="field"><label class="classic required" title="'.__('Required field').'">'.__('Your password:').' '. |
---|
| 232 | form::password(array('your_pwd'),20,255).'</label></p>'. |
---|
| 233 | '<input type="submit" value="'.__('Install language').'" />'. |
---|
| 234 | $core->formNonce(). |
---|
| 235 | '</fieldset>'. |
---|
| 236 | '</form>'; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | if ($is_writable) |
---|
| 240 | { |
---|
| 241 | # 'Upload language pack' form |
---|
| 242 | echo |
---|
| 243 | '<form method="post" action="langs.php" enctype="multipart/form-data">'. |
---|
| 244 | '<fieldset>'. |
---|
| 245 | '<legend>'.__('Upload a zip file').'</legend>'. |
---|
| 246 | '<p>'.__('You can install languages by uploading zip files.').'</p>'. |
---|
| 247 | '<p class="field"><label class="classic required" title="'.__('Required field').'">'.__('Language zip file:').' '. |
---|
| 248 | '<input type="file" name="pkg_file" /></label></p>'. |
---|
| 249 | '<p class="field"><label class="classic required" title="'.__('Required field').'">'.__('Your password:').' '. |
---|
| 250 | form::password(array('your_pwd'),20,255).'</label></p>'. |
---|
| 251 | '<input type="submit" name="upload_pkg" value="'.__('Upload language').'" />'. |
---|
| 252 | $core->formNonce(). |
---|
| 253 | '</fieldset>'. |
---|
| 254 | '</form>'; |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | dcPage::close(); |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | # Language installation function |
---|
| 261 | function dc_lang_install($file) |
---|
| 262 | { |
---|
| 263 | $zip = new fileUnzip($file); |
---|
| 264 | $zip->getList(false,'#(^|/)(__MACOSX|\.svn|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); |
---|
| 265 | |
---|
| 266 | if (!preg_match('/^[a-z]{2,3}(-[a-z]{2})?$/',$zip->getRootDir())) { |
---|
| 267 | throw new Exception(__('Invalid language zip file.')); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | if ($zip->isEmpty() || !$zip->hasFile($zip->getRootDir().'/main.po')) { |
---|
| 271 | throw new Exception(__('The zip file does not appear to be a valid Dotclear language pack.')); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | |
---|
| 275 | $target = dirname($file); |
---|
| 276 | $destination = $target.'/'.$zip->getRootDir(); |
---|
| 277 | $res = 1; |
---|
| 278 | |
---|
| 279 | if (is_dir($destination)) { |
---|
| 280 | if (!files::deltree($destination)) { |
---|
| 281 | throw new Exception(__('An error occurred during language upgrade.')); |
---|
| 282 | } |
---|
| 283 | $res = 2; |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | $zip->unzipAll($target); |
---|
| 287 | return $res; |
---|
| 288 | } |
---|
| 289 | ?> |
---|