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