Changes in [1105:ce855d61f9ce:1106:a4487f3ca4b4]
- Files:
-
- 366 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/auth.php
r794 r1089 14 14 15 15 # If we have a session cookie, go to index.php 16 if (isset($_SESSION['sess_user_id'])) 17 { 16 if (isset($_SESSION['sess_user_id'])) { 18 17 http::redirect('index.php'); 19 18 } … … 23 22 $dlang = http::getAcceptLanguage(); 24 23 $dlang = ($dlang == '' ? 'en' : $dlang); 25 if ($dlang != 'en' && preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$dlang)) 26 { 24 if ($dlang != 'en' && preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$dlang)) { 27 25 l10n::set(dirname(__FILE__).'/../locales/'.$dlang.'/main'); 28 26 } 29 30 $page_url = http::getHost().$_SERVER['REQUEST_URI'];31 32 $change_pwd = $core->auth->allowPassChange() && isset($_POST['new_pwd']) && isset($_POST['new_pwd_c']) && isset($_POST['login_data']);33 $login_data = !empty($_POST['login_data']) ? html::escapeHTML($_POST['login_data']) : null;34 $recover = $core->auth->allowPassChange() && !empty($_REQUEST['recover']);35 $safe_mode = !empty($_REQUEST['safe_mode']);36 $akey = $core->auth->allowPassChange() && !empty($_GET['akey']) ? $_GET['akey'] : null;37 $user_id = $user_pwd = $user_key = $user_email = null;38 $err = $msg = null;39 27 40 28 # Auto upgrade … … 43 31 try { 44 32 if (($changes = dotclearUpgrade($core)) !== false) { 45 $msg = __('Dotclear has been upgraded.').'<!-- '.$changes.' -->'; 46 } 47 } catch (Exception $e) { 48 $err = $e->getMessage(); 49 } 50 } 51 52 # If we have POST login informations, go throug auth process 53 if (!empty($_POST['user_id']) && !empty($_POST['user_pwd'])) 33 $_ctx->setAlert(__('Dotclear has been upgraded.').'<!-- '.$changes.' -->'); 34 } 35 } 36 catch (Exception $e) { 37 $_ctx->addError($e->getMessage()); 38 } 39 } 40 41 /** 42 Actions for authentication on admin pages 43 */ 44 class adminPageAuth 54 45 { 55 $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; 56 $user_pwd = !empty($_POST['user_pwd']) ? $_POST['user_pwd'] : null; 57 } 58 # If we have COOKIE login informations, go throug auth process 59 elseif (isset($_COOKIE['dc_admin']) && strlen($_COOKIE['dc_admin']) == 104) 60 { 46 # Send new password from recover email 47 public static function send($akey) 48 { 49 global $core, $_ctx; 50 51 $_ctx->akey = true; 52 53 try { 54 $recover_res = $core->auth->recoverUserPassword($akey); 55 56 $subject = mb_encode_mimeheader('DotClear '.__('Your new password'),'UTF-8','B'); 57 $message = 58 __('Username:').' '.$recover_res['user_id']."\n". 59 __('Password:').' '.$recover_res['new_pass']."\n\n". 60 preg_replace('/\?(.*)$/','',http::getHost().$_SERVER['REQUEST_URI']); 61 62 $headers[] = 'From: dotclear@'.$_SERVER['HTTP_HOST']; 63 $headers[] = 'Content-Type: text/plain; charset=UTF-8;'; 64 65 mail::sendMail($recover_res['user_email'],$subject,$message,$headers); 66 $_ctx->setAlert(__('Your new password is in your mailbox.')); 67 } 68 catch (Exception $e) { 69 $_ctx->addError($e->getMessage()); 70 } 71 } 72 73 # Authentication process 74 public static function process($form,$user_id,$user_pwd,$user_key=null) 75 { 76 global $core, $_ctx; 77 78 # We check the user 79 $check_user = $core->auth->checkUser($user_id,$user_pwd,$user_key) === true; 80 81 $cookie_admin = http::browserUID(DC_MASTER_KEY.$user_id. 82 crypt::hmac(DC_MASTER_KEY,$user_pwd)).bin2hex(pack('a32',$user_id)); 83 84 if ($check_user && $core->auth->mustChangePassword()) 85 { 86 $form->login_data = join('/',array( 87 base64_encode($user_id), 88 $cookie_admin, 89 $form->user_remember == '' ? '0' : '1' 90 )); 91 92 if (!$core->auth->allowPassChange()) { 93 $_ctx->addError(__('You have to change your password before you can login.')); 94 } else { 95 $_ctx->addError(__('In order to login, you have to change your password now.')); 96 $_ctx->change_pwd = true; 97 } 98 } 99 elseif ($check_user && $form->safe_mode != '' && !$core->auth->isSuperAdmin()) 100 { 101 $_ctx->addError(__('Safe Mode can only be used for super administrators.')); 102 } 103 elseif ($check_user) 104 { 105 $core->session->start(); 106 $_SESSION['sess_user_id'] = $user_id; 107 $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 108 109 if ($form->blog != '') { 110 $_SESSION['sess_blog_id'] = $form->blog; 111 } 112 113 if ($form->safe_mode != '' && $core->auth->isSuperAdmin()) { 114 $_SESSION['sess_safe_mode'] = true; 115 } 116 117 if ($form->user_remember != '') { 118 setcookie('dc_admin',$cookie_admin,strtotime('+15 days'),'','',DC_ADMIN_SSL); 119 } 120 121 http::redirect('index.php'); 122 } 123 else 124 { 125 if (isset($_COOKIE['dc_admin'])) { 126 unset($_COOKIE['dc_admin']); 127 setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL); 128 } 129 $_ctx->addError(__('Wrong username or password')); 130 } 131 } 132 133 # Login form action 134 public static function login($form) 135 { 136 global $_ctx; 137 138 if ($form->user_id != '' && $form->user_pwd != '') { 139 self::process($form,$form->user_id,$form->user_pwd); 140 } 141 142 # Send post values to form 143 $form->user_id = $form->user_id; 144 } 145 146 # Recover password form action 147 public static function recover($form) 148 { 149 global $core, $_ctx; 150 151 if ($form->user_id == '' || $form->user_email == '') { 152 return; 153 } 154 155 $user_id = $form->user_id; 156 $user_email = $form->user_email; 157 $page_url = http::getHost().$_SERVER['REQUEST_URI']; 158 159 try { 160 $recover_key = $core->auth->setRecoverKey($user_id,$user_email); 161 162 $subject = mail::B64Header('DotClear '.__('Password reset')); 163 $message = 164 __('Someone has requested to reset the password for the following site and username.')."\n\n". 165 $page_url."\n".__('Username:').' '.$user_id."\n\n". 166 __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.')."\n". 167 $page_url.'?akey='.$recover_key; 168 169 $headers[] = 'From: '.(defined('DC_ADMIN_MAILFROM') && DC_ADMIN_MAILFROM ? DC_ADMIN_MAILFROM : 'dotclear@local'); 170 $headers[] = 'Content-Type: text/plain; charset=UTF-8;'; 171 172 mail::sendMail($user_email,$subject,$message,$headers); 173 $_ctx->setAlert(sprintf(__('The e-mail was sent successfully to %s.'),$user_email)); 174 } 175 catch (Exception $e) { 176 $_ctx->addError($e->getMessage()); 177 } 178 179 # Send post values to form 180 $form->user_id = $form->user_id; 181 $form->user_email = $form->user_email; 182 } 183 184 # Change password form action 185 public static function change($form) 186 { 187 global $core, $_ctx; 188 189 if ($form->login_data) { 190 return; 191 } 192 $_ctx->change_pwd = true; 193 194 $new_pwd = (string) $form->new_pwd; 195 $new_pwd_c = (string) $form->new_pwd_c; 196 197 try { 198 $tmp_data = explode('/',$form->login_data); 199 if (count($tmp_data) != 3) { 200 throw new Exception(); 201 } 202 $data = array( 203 'user_id'=>base64_decode($tmp_data[0]), 204 'cookie_admin'=>$tmp_data[1], 205 'user_remember'=>$tmp_data[2]=='1' 206 ); 207 if ($data['user_id'] === false) { 208 throw new Exception(); 209 } 210 211 # Check login informations 212 $check_user = false; 213 if (isset($data['cookie_admin']) && strlen($data['cookie_admin']) == 104) 214 { 215 $user_id = substr($data['cookie_admin'],40); 216 $user_id = @unpack('a32',@pack('H*',$user_id)); 217 if (is_array($user_id)) 218 { 219 $user_id = $user_id[1]; 220 $user_key = substr($data['cookie_admin'],0,40); 221 $check_user = $core->auth->checkUser($user_id,null,$user_key) === true; 222 } 223 } 224 225 if (!$core->auth->allowPassChange() || !$check_user) { 226 $_ctx->change_pwd = false; 227 throw new Exception(); 228 } 229 230 if ($new_pwd != $new_pwd_c) { 231 throw new Exception(__("Passwords don't match")); 232 } 233 234 if ($core->auth->checkUser($user_id,$new_pwd) === true) { 235 throw new Exception(__("You didn't change your password.")); 236 } 237 238 $cur = $core->con->openCursor($core->prefix.'user'); 239 $cur->user_change_pwd = 0; 240 $cur->user_pwd = $new_pwd; 241 $core->updUser($core->auth->userID(),$cur); 242 243 $core->session->start(); 244 $_SESSION['sess_user_id'] = $user_id; 245 $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 246 247 if ($data['user_remember']) { 248 setcookie('dc_admin',$data['cookie_admin'],strtotime('+15 days'),'','',DC_ADMIN_SSL); 249 } 250 251 http::redirect('index.php'); 252 } 253 catch (Exception $e) { 254 $_ctx->addError($e->getMessage()); 255 } 256 257 # Send post values to form 258 $form->login_data = $form->login_data; 259 } 260 } 261 262 # Form fields 263 $form = new dcForm($core,'auth','auth.php'); 264 $form 265 ->addField( 266 new dcFieldText('user_id','',array( 267 "label" => __('Username:')))) 268 ->addField( 269 new dcFieldPassword('user_pwd','',array( 270 "label" => __('Password:')))) 271 ->addField( 272 new dcFieldText('user_email','',array( 273 "label" => __('Email:')))) 274 ->addField( 275 new dcFieldPassword('new_pwd','',array( 276 "label" => __('New password:')))) 277 ->addField( 278 new dcFieldPassword('new_pwd_c','',array( 279 "label" => __('Confirm password:')))) 280 ->addField( 281 new dcFieldCheckbox ('user_remenber',1,array( 282 "label" => __('Remember my ID on this computer')))) 283 ->addField( 284 new dcFieldSubmit('auth_login',__('log in'),array( 285 'action' => array('adminPageAuth','login')))) 286 ->addField( 287 new dcFieldSubmit('auth_recover',__('recover'),array( 288 'action' => array('adminPageAuth','recover')))) 289 ->addField( 290 new dcFieldSubmit('auth_change',__('change'),array( 291 'action' => array('adminPageAuth','change')))) 292 ->addField( 293 new dcFieldHidden ('safe_mode','0')) 294 ->addField( 295 new dcFieldHidden ('recover','0')) 296 ->addField( 297 new dcFieldHidden ('login_data','')) 298 ->addField( 299 new dcFieldHidden ('blog','')); 300 301 # Context variables 302 $_ctx->allow_pass_change = $core->auth->allowPassChange(); 303 $_ctx->change_pwd = $core->auth->allowPassChange() && $form->new_pwd != '' && $form->new_pwd_c != '' && $form->login_data != ''; 304 $_ctx->recover = $form->recover = $core->auth->allowPassChange() && !empty($_REQUEST['recover']); 305 $_ctx->setSafeMode(!empty($_REQUEST['safe_mode'])); 306 $form->safe_mode = !empty($_REQUEST['safe_mode']); 307 $_ctx->akey = false; 308 309 # If we have no POST login informations and have COOKIE login informations, go throug auth process 310 if ($form->user_id == '' && $form->user_pwd == '' 311 && isset($_COOKIE['dc_admin']) && strlen($_COOKIE['dc_admin']) == 104) { 312 61 313 # If we have a remember cookie, go through auth process with user_key 62 314 $user_id = substr($_COOKIE['dc_admin'],40); 63 315 $user_id = @unpack('a32',@pack('H*',$user_id)); 64 if (is_array($user_id))65 {316 317 if (is_array($user_id)) { 66 318 $user_id = $user_id[1]; 67 319 $user_key = substr($_COOKIE['dc_admin'],0,40); 68 $user_pwd = null; 69 } 70 else 71 { 72 $user_id = null; 73 } 74 } 75 76 # Recover password 77 if ($recover && !empty($_POST['user_id']) && !empty($_POST['user_email'])) 78 { 79 $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; 80 $user_email = !empty($_POST['user_email']) ? $_POST['user_email'] : ''; 81 try 82 { 83 $recover_key = $core->auth->setRecoverKey($user_id,$user_email); 84 85 $subject = mail::B64Header('DotClear '.__('Password reset')); 86 $message = 87 __('Someone has requested to reset the password for the following site and username.')."\n\n". 88 $page_url."\n".__('Username:').' '.$user_id."\n\n". 89 __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.')."\n". 90 $page_url.'?akey='.$recover_key; 91 92 $headers[] = 'From: '.(defined('DC_ADMIN_MAILFROM') && DC_ADMIN_MAILFROM ? DC_ADMIN_MAILFROM : 'dotclear@local'); 93 $headers[] = 'Content-Type: text/plain; charset=UTF-8;'; 94 95 mail::sendMail($user_email,$subject,$message,$headers); 96 $msg = sprintf(__('The e-mail was sent successfully to %s.'),$user_email); 97 } 98 catch (Exception $e) 99 { 100 $err = $e->getMessage(); 101 } 102 } 103 # Send new password 104 elseif ($akey) 105 { 106 try 107 { 108 $recover_res = $core->auth->recoverUserPassword($akey); 109 110 $subject = mb_encode_mimeheader('DotClear '.__('Your new password'),'UTF-8','B'); 111 $message = 112 __('Username:').' '.$recover_res['user_id']."\n". 113 __('Password:').' '.$recover_res['new_pass']."\n\n". 114 preg_replace('/\?(.*)$/','',$page_url); 115 116 $headers[] = 'From: dotclear@'.$_SERVER['HTTP_HOST']; 117 $headers[] = 'Content-Type: text/plain; charset=UTF-8;'; 118 119 mail::sendMail($recover_res['user_email'],$subject,$message,$headers); 120 $msg = __('Your new password is in your mailbox.'); 121 } 122 catch (Exception $e) 123 { 124 $err = $e->getMessage(); 125 } 126 } 127 # Change password and retry to log 128 elseif ($change_pwd) 129 { 130 try 131 { 132 $tmp_data = explode('/',$_POST['login_data']); 133 if (count($tmp_data) != 3) { 134 throw new Exception(); 135 } 136 $data = array( 137 'user_id'=>base64_decode($tmp_data[0]), 138 'cookie_admin'=>$tmp_data[1], 139 'user_remember'=>$tmp_data[2]=='1' 140 ); 141 if ($data['user_id'] === false) { 142 throw new Exception(); 143 } 144 145 # Check login informations 146 $check_user = false; 147 if (isset($data['cookie_admin']) && strlen($data['cookie_admin']) == 104) 148 { 149 $user_id = substr($data['cookie_admin'],40); 150 $user_id = @unpack('a32',@pack('H*',$user_id)); 151 if (is_array($user_id)) 152 { 153 $user_id = $user_id[1]; 154 $user_key = substr($data['cookie_admin'],0,40); 155 $check_user = $core->auth->checkUser($user_id,null,$user_key) === true; 156 } 157 } 158 159 if (!$core->auth->allowPassChange() || !$check_user) { 160 $change_pwd = false; 161 throw new Exception(); 162 } 163 164 if ($_POST['new_pwd'] != $_POST['new_pwd_c']) { 165 throw new Exception(__("Passwords don't match")); 166 } 167 168 if ($core->auth->checkUser($user_id,$_POST['new_pwd']) === true) { 169 throw new Exception(__("You didn't change your password.")); 170 } 171 172 $cur = $core->con->openCursor($core->prefix.'user'); 173 $cur->user_change_pwd = 0; 174 $cur->user_pwd = $_POST['new_pwd']; 175 $core->updUser($core->auth->userID(),$cur); 176 177 $core->session->start(); 178 $_SESSION['sess_user_id'] = $user_id; 179 $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 180 181 if ($data['user_remember']) 182 { 183 setcookie('dc_admin',$data['cookie_admin'],strtotime('+15 days'),'','',DC_ADMIN_SSL); 184 } 185 186 http::redirect('index.php'); 187 } 188 catch (Exception $e) 189 { 190 $err = $e->getMessage(); 191 } 192 } 193 # Try to log 194 elseif ($user_id !== null && ($user_pwd !== null || $user_key !== null)) 195 { 196 # We check the user 197 $check_user = $core->auth->checkUser($user_id,$user_pwd,$user_key) === true; 198 199 $cookie_admin = http::browserUID(DC_MASTER_KEY.$user_id. 200 crypt::hmac(DC_MASTER_KEY,$user_pwd)).bin2hex(pack('a32',$user_id)); 201 202 if ($check_user && $core->auth->mustChangePassword()) 203 { 204 $login_data = join('/',array( 205 base64_encode($user_id), 206 $cookie_admin, 207 empty($_POST['user_remember'])?'0':'1' 208 )); 209 210 if (!$core->auth->allowPassChange()) { 211 $err = __('You have to change your password before you can login.'); 212 } else { 213 $err = __('In order to login, you have to change your password now.'); 214 $change_pwd = true; 215 } 216 } 217 elseif ($check_user && !empty($_POST['safe_mode']) && !$core->auth->isSuperAdmin()) 218 { 219 $err = __('Safe Mode can only be used for super administrators.'); 220 } 221 elseif ($check_user) 222 { 223 $core->session->start(); 224 $_SESSION['sess_user_id'] = $user_id; 225 $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 226 227 if (!empty($_POST['blog'])) { 228 $_SESSION['sess_blog_id'] = $_POST['blog']; 229 } 230 231 if (!empty($_POST['safe_mode']) && $core->auth->isSuperAdmin()) { 232 $_SESSION['sess_safe_mode'] = true; 233 } 234 235 if (!empty($_POST['user_remember'])) { 236 setcookie('dc_admin',$cookie_admin,strtotime('+15 days'),'','',DC_ADMIN_SSL); 237 } 238 239 http::redirect('index.php'); 240 } 241 else 242 { 243 if (isset($_COOKIE['dc_admin'])) { 244 unset($_COOKIE['dc_admin']); 245 setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL); 246 } 247 $err = __('Wrong username or password'); 248 } 320 $user_pwd = ''; 321 322 adminPageAuth::process($form,$user_id,$user_pwd,$user_key); 323 } 324 } 325 # If we have an akey, go throug send password process 326 elseif ($core->auth->allowPassChange() && !empty($_GET['akey'])) { 327 adminPageAuth::send($_GET['akey']); 249 328 } 250 329 251 330 if (isset($_GET['user'])) { 252 $user_id = $_GET['user']; 253 } 254 255 header('Content-Type: text/html; charset=UTF-8'); 331 $form->user_id = $_GET['user']; 332 } 333 334 $form->setup(); 335 336 $core->tpl->display('auth.html.twig'); 256 337 ?> 257 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">258 <html xmlns="http://www.w3.org/1999/xhtml"259 xml:lang="<?php echo $dlang; ?>" lang="<?php echo $dlang; ?>">260 <head>261 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />262 <meta http-equiv="Content-Script-Type" content="text/javascript" />263 <meta http-equiv="Content-Style-Type" content="text/css" />264 <meta http-equiv="Content-Language" content="<?php echo $dlang; ?>" />265 <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />266 <meta name="GOOGLEBOT" content="NOSNIPPET" />267 <title><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></title>268 269 <?php270 echo dcPage::jsLoadIE7();271 echo dcPage::jsCommon();272 ?>273 274 <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />275 276 <?php277 # --BEHAVIOR-- loginPageHTMLHead278 $core->callBehavior('loginPageHTMLHead');279 ?>280 281 <script type="text/javascript">282 //<![CDATA[283 $(window).load(function() {284 var uid = $('input[name=user_id]');285 var upw = $('input[name=user_pwd]');286 uid.focus();287 288 if (upw.length == 0) { return; }289 290 if ($.browser.mozilla) {291 uid.keypress(processKey);292 } else {293 uid.keydown(processKey);294 }295 function processKey(evt) {296 if (evt.keyCode == 13 && upw.val() == '') {297 upw.focus();298 return false;299 }300 return true;301 };302 $.cookie('dc_admin_test_cookie',true);303 if ($.cookie('dc_admin_test_cookie')) {304 $('#cookie_help').hide();305 $.cookie('dc_admin_test_cookie', '', {'expires': -1});306 } else {307 $('#cookie_help').show();308 }309 $('#issue #more').toggleWithLegend($('#issue').children().not('#more'));310 });311 //]]>312 </script>313 </head>314 315 <body id="dotclear-admin" class="auth">316 317 <form action="auth.php" method="post" id="login-screen">318 <h1><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></h1>319 320 <?php321 if ($err) {322 echo '<div class="error">'.$err.'</div>';323 }324 if ($msg) {325 echo '<p class="message">'.$msg.'</p>';326 }327 328 if ($akey)329 {330 echo '<p><a href="auth.php">'.__('Back to login screen').'</a></p>';331 }332 elseif ($recover)333 {334 echo335 '<fieldset><legend>'.__('Request a new password').'</legend>'.336 '<p><label for="user_id">'.__('Username:').'</label> '.337 form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id)).'</p>'.338 339 '<p><label for="user_email">'.__('Email:').'</label> '.340 form::field(array('user_email','user_email'),20,255,html::escapeHTML($user_email)).'</p>'.341 342 '<p><input type="submit" value="'.__('recover').'" />'.343 form::hidden(array('recover'),1).'</p>'.344 '</fieldset>'.345 346 '<div id="issue">'.347 '<p><a href="auth.php">'.__('Back to login screen').'</a></p></div>';348 }349 elseif ($change_pwd)350 {351 echo352 '<fieldset><legend>'.__('Change your password').'</legend>'.353 '<p><label for="new_pwd">'.__('New password:').'</label> '.354 form::password(array('new_pwd','new_pwd'),20,255).'</p>'.355 356 '<p><label for="new_pwd_c">'.__('Confirm password:').'</label> '.357 form::password(array('new_pwd_c','new_pwd_c'),20,255).'</p>'.358 '</fielset>'.359 360 '<p><input type="submit" value="'.__('change').'" />'.361 form::hidden('login_data',$login_data).'</p>';362 }363 else364 {365 if (is_callable(array($core->auth,'authForm')))366 {367 echo $core->auth->authForm($user_id);368 }369 else370 {371 if ($safe_mode) {372 echo '<fieldset>';373 echo '<legend>'.__('Safe mode login').'</legend>';374 echo375 '<p class="form-note info">'.376 __('This mode allows you to login without activating any of your plugins. This may be useful to solve compatibility problems').' <br />'.377 __('Disable or delete any plugin suspected to cause trouble, then log out and log back in normally.').378 '</p>';379 }380 else {381 echo '<div class="fieldset">';382 }383 384 echo385 '<p><label for="user_id">'.__('Username:').'</label> '.386 form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id)).'</p>'.387 388 '<p><label for="user_pwd">'.__('Password:').'</label> '.389 form::password(array('user_pwd','user_pwd'),20,255).'</p>'.390 391 '<p>'.392 form::checkbox(array('user_remember','user_remember'),1).393 '<label for="user_remember" class="classic">'.394 __('Remember my ID on this computer').'</label></p>'.395 396 '<p><input type="submit" value="'.__('log in').'" /></p>';397 398 if (!empty($_REQUEST['blog'])) {399 echo form::hidden('blog',html::escapeHTML($_REQUEST['blog']));400 }401 if($safe_mode) {402 echo403 form::hidden('safe_mode',1).404 '</fieldset>';405 }406 else {407 echo '</div>';408 }409 echo410 '<p id="cookie_help" class="error">'.__('You must accept cookies in order to use the private area.').'</p>';411 412 echo '<div id="issue">';413 414 if ($safe_mode) {415 echo416 '<p><a href="auth.php" id="normal_mode_link">'.__('Get back to normal authentication').'</a></p>';417 } else {418 echo '<p id="more"><strong>'.__('Connection issue?').'</strong></p>';419 if ($core->auth->allowPassChange()) {420 echo '<p><a href="auth.php?recover=1">'.__('I forgot my password').'</a></p>';421 }422 echo '<p><a href="auth.php?safe_mode=1" id="safe_mode_link">'.__('I want to log in in safe mode').'</a></p>';423 }424 425 echo '</div>';426 }427 }428 ?>429 </form>430 </body>431 </html> -
admin/index.php
r1077 r1099 15 15 exit; 16 16 } 17 if (!empty($_GET['tf'])) { 18 define('DC_CONTEXT_ADMIN',true); 19 require dirname(__FILE__).'/../inc/load_theme_file.php'; 20 exit; 21 } 17 22 18 23 require dirname(__FILE__).'/../inc/admin/prepend.php'; … … 43 48 $plugins_install = $core->plugins->installModules(); 44 49 50 # Send plugins install messages to templates 51 if (!empty($plugins_install['success'])) { 52 $_ctx->addMessagesList(__('Following plugins have been installed:'),$plugins_install['success']); 53 } 54 if (!empty($plugins_install['failure'])) { 55 $_ctx->addMessagesList(__('Following plugins have not been installed:'),$plugins_install['failure']); 56 } 57 58 # Send plugins errors messages to templates 59 $_ctx->modules_errors = $core->auth->isSuperAdmin() ? $core->plugins->getErrors() : array(); 60 61 # Send Dotclear updates notifications to tempaltes 62 $_ctx->updater = array(); 63 if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) { 64 65 $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); 66 $new_v = $updater->check(DC_VERSION); 67 $version_info = $new_v ? $updater->getInfoURL() : ''; 68 69 if ($updater->getNotify() && $new_v) { 70 $_ctx->updater = array( 71 'new_version' => $new_v, 72 'version_info' => $version_info 73 ); 74 } 75 } 76 45 77 # Check dashboard module prefs 46 78 $ws = $core->auth->user_prefs->addWorkspace('dashboard'); 79 80 # Doclinks prefs 47 81 if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) { 48 82 if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) { … … 51 85 $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean'); 52 86 } 87 88 # Send doclinks to templates 89 $_ctx->dashboard_doclinks = array(); 90 if ($core->auth->user_prefs->dashboard->doclinks && !empty($__resources['doc'])) { 91 $_ctx->dashboard_doclinks = $__resources['doc']; 92 } 93 94 # Dcnews prefs 53 95 if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) { 54 96 if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) { … … 57 99 $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean'); 58 100 } 101 102 # Send dcnews to templates 103 $_ctx->dashboard_dcnews = array(); 104 if ($core->auth->user_prefs->dashboard->dcnews && !empty($__resources['rss_news'])) { 105 try 106 { 107 $feed_reader = new feedReader; 108 $feed_reader->setCacheDir(DC_TPL_CACHE); 109 $feed_reader->setTimeout(2); 110 $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); 111 $feed = $feed_reader->parse($__resources['rss_news']); 112 if ($feed) { 113 $items = array(); 114 $i = 1; 115 foreach ($feed->items as $item) { 116 $items[] = array( 117 'title' => $item->title, 118 'link' => isset($item->link) ? $item->link : '', 119 'date' => dt::dt2str(__('%d %B %Y'),$item->pubdate,'Europe/Paris'), 120 'content' => html::clean($item->content) 121 ); 122 $i++; 123 if ($i > 3) { break; } 124 } 125 $_ctx->dashboard_dcnews = $items; 126 } 127 } 128 catch (Exception $e) {} 129 } 130 131 # Quick entry prefs 59 132 if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) { 60 133 if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) { … … 62 135 } 63 136 $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean'); 137 } 138 139 # Send quick entry to templates 140 $_ctx->dashboard_quickentry = false; 141 if ($core->auth->user_prefs->dashboard->quickentry &&$core->auth->check('usage,contentadmin',$core->blog->id)) 142 { 143 $categories_combo = array(' ' => ''); 144 try { 145 $categories = $core->blog->getCategories(array('post_type'=>'post')); 146 while ($categories->fetch()) { 147 $categories_combo[$categories->cat_id] = 148 str_repeat(' ',$categories->level-1). 149 ($categories->level-1 == 0 ? '' : '• '). 150 html::escapeHTML($categories->cat_title); 151 } 152 } catch (Exception $e) { } 153 154 $form = new dcForm($core,array('quickentry','quick-entry'),'post.php'); 155 $form 156 ->addField( 157 new dcFieldText('post_title','', array( 158 'size' => 20, 159 'required' => true, 160 'label' => __('Title')))) 161 ->addField( 162 new dcFieldTextArea('post_content','', array( 163 'required' => true, 164 'label' => __("Content:")))) 165 ->addField( 166 new dcFieldCombo('cat_id','',$categories_combo,array( 167 "label" => __('Category:')))) 168 ->addField( 169 new dcFieldSubmit('save',__('Save'),array( 170 'action' => 'savePost'))) 171 ->addField( 172 new dcFieldHidden ('post_status',-2)) 173 ->addField( 174 new dcFieldHidden ('post_format',$core->auth->getOption('post_format'))) 175 ->addField( 176 new dcFieldHidden ('post_excerpt','')) 177 ->addField( 178 new dcFieldHidden ('post_lang',$core->auth->getInfo('user_lang'))) 179 ->addField( 180 new dcFieldHidden ('post_notes','')) 181 ; 182 if ($core->auth->check('publish',$core->blog->id)) { 183 $form->addField( 184 new dcFieldHidden ('save-publish',__('Save and publish'))); 185 } 186 187 $_ctx->dashboard_quickentry = true; 64 188 } 65 189 … … 118 242 } 119 243 120 # Latest news for dashboard 244 # Send dashboard icons to templates 245 $icons = array(); 246 foreach ($__dashboard_icons as $i) { 247 $icons[] = array( 248 'title' => $i[0], 249 'url' => $i[1], 250 'img' => dc_admin_icon_url($i[2]) 251 ); 252 } 253 $_ctx->dashboard_icons = $icons; 254 255 # Dashboard items 121 256 $__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject)); 122 123 # Documentation links124 $dashboardItem = 0;125 if ($core->auth->user_prefs->dashboard->doclinks) {126 if (!empty($__resources['doc']))127 {128 $doc_links = '<h3>'.__('Documentation and support').'</h3><ul>';129 130 foreach ($__resources['doc'] as $k => $v) {131 $doc_links .= '<li><a href="'.$v.'" title="'.$k.' '.__('(external link)').'">'.$k.'</a></li>';132 }133 134 $doc_links .= '</ul>';135 $__dashboard_items[$dashboardItem][] = $doc_links;136 $dashboardItem++;137 }138 }139 140 if ($core->auth->user_prefs->dashboard->dcnews) {141 try142 {143 if (empty($__resources['rss_news'])) {144 throw new Exception();145 }146 147 $feed_reader = new feedReader;148 $feed_reader->setCacheDir(DC_TPL_CACHE);149 $feed_reader->setTimeout(2);150 $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');151 $feed = $feed_reader->parse($__resources['rss_news']);152 if ($feed)153 {154 $latest_news = '<h3>'.__('Latest news').'</h3><dl id="news">';155 $i = 1;156 foreach ($feed->items as $item)157 {158 $dt = isset($item->link) ? '<a href="'.$item->link.'" title="'.$item->title.' '.__('(external link)').'">'.159 $item->title.'</a>' : $item->title;160 161 if ($i < 3) {162 $latest_news .=163 '<dt>'.$dt.'</dt>'.164 '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.165 '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';166 } else {167 $latest_news .=168 '<dt>'.$dt.'</dt>'.169 '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';170 }171 $i++;172 if ($i > 3) { break; }173 }174 $latest_news .= '</dl>';175 $__dashboard_items[$dashboardItem][] = $latest_news;176 $dashboardItem++;177 }178 }179 catch (Exception $e) {}180 }181 182 257 $core->callBehavior('adminDashboardItems', $core, $__dashboard_items); 183 258 259 # Send dashboard items to templates 260 $items = array(); 261 foreach ($__dashboard_items as $i) { 262 if ($i->count() > 0) { 263 foreach ($i as $v) { 264 $items[] = $v; 265 } 266 } 267 } 268 $_ctx->dashboard_items = $items; 269 184 270 # Dashboard content 185 $dashboardContents = '';186 271 $__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject)); 187 272 $core->callBehavior('adminDashboardContents', $core, $__dashboard_contents); 188 273 189 /* DISPLAY 190 -------------------------------------------------------- */ 191 dcPage::open(__('Dashboard'), 192 dcPage::jsToolBar(). 193 dcPage::jsLoad('js/_index.js'). 194 # --BEHAVIOR-- adminDashboardHeaders 195 $core->callBehavior('adminDashboardHeaders') 196 ); 197 198 echo '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.__('Dashboard').'</span></h2>'; 199 200 if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->blog_count > 1) { 201 echo 202 '<p><a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a></p>'; 203 } 204 274 # Send dashboard contents to templates 275 $contents = array(); 276 foreach ($__dashboard_contents as $i) { 277 if ($i->count() > 0) { 278 foreach ($i as $v) { 279 $contents[] = $v; 280 } 281 } 282 } 283 $_ctx->dashboard_contents = $contents; 284 285 # Blog status message 205 286 if ($core->blog->status == 0) { 206 echo '<p class="static-msg">'.__('This blog is offline').'</p>';287 $_ctx->addMessageStatic(__('This blog is offline')); 207 288 } elseif ($core->blog->status == -1) { 208 echo '<p class="static-msg">'.__('This blog is removed').'</p>'; 209 } 210 289 $_ctx->addMessageStatic(__('This blog is removed')); 290 } 291 292 # Config errors messages 211 293 if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) { 212 echo 213 '<p class="static-msg">'. 214 sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL'). 215 ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.'). 216 '</p>'; 217 } 218 294 $_ctx->addMessageStatic( 295 sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').' '. 296 __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') 297 ); 298 } 219 299 if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) { 220 echo 221 '<p class="static-msg">'. 222 sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM'). 223 ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.'). 224 '</p>'; 225 } 226 227 # Plugins install messages 228 if (!empty($plugins_install['success'])) 229 { 230 echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; 231 foreach ($plugins_install['success'] as $k => $v) { 232 echo '<li>'.$k.'</li>'; 233 } 234 echo '</ul></div>'; 235 } 236 if (!empty($plugins_install['failure'])) 237 { 238 echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; 239 foreach ($plugins_install['failure'] as $k => $v) { 240 echo '<li>'.$k.' ('.$v.')</li>'; 241 } 242 echo '</ul></div>'; 243 } 244 245 # Dashboard columns (processed first, as we need to know the result before displaying the icons.) 246 $dashboardItems = ''; 247 248 # Dotclear updates notifications 249 if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) 250 { 251 $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); 252 $new_v = $updater->check(DC_VERSION); 253 $version_info = $new_v ? $updater->getInfoURL() : ''; 254 255 if ($updater->getNotify() && $new_v) { 256 $dashboardItems .= 257 '<div id="upg-notify" class="static-msg"><p>'.sprintf(__('Dotclear %s is available!'),$new_v).'</p> '. 258 '<ul><li><strong><a href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a></strong>'. 259 '</li><li><a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'. 260 ($version_info ? ' </li><li><a href="'.$version_info.'">'.__('information about this version').'</a>' : ''). 261 '</li></ul></div>'; 262 } 263 } 264 265 # Errors modules notifications 266 if ($core->auth->isSuperAdmin()) 267 { 268 $list = array(); 269 foreach ($core->plugins->getErrors() as $k => $error) { 270 $list[] = '<li>'.$error.'</li>'; 271 } 272 273 if (count($list) > 0) { 274 $dashboardItems .= 275 '<div id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '. 276 '<ul>'.implode("\n",$list).'</ul></div>'; 277 } 278 279 } 280 281 foreach ($__dashboard_items as $i) 282 { 283 if ($i->count() > 0) 284 { 285 $dashboardItems .= '<div>'; 286 foreach ($i as $v) { 287 $dashboardItems .= $v; 288 } 289 $dashboardItems .= '</div>'; 290 } 291 } 292 293 # Dashboard icons 294 echo '<div id="dashboard-main"'.($dashboardItems ? '' : ' class="fullwidth"').'><div id="icons">'; 295 foreach ($__dashboard_icons as $i) 296 { 297 echo 298 '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'. 299 '<br /><span>'.$i[0].'</span></a></p>'; 300 } 301 echo '</div>'; 302 303 if ($core->auth->user_prefs->dashboard->quickentry) { 304 if ($core->auth->check('usage,contentadmin',$core->blog->id)) 305 { 306 $categories_combo = array(' ' => ''); 307 try { 308 $categories = $core->blog->getCategories(array('post_type'=>'post')); 309 while ($categories->fetch()) { 310 $categories_combo[] = new formSelectOption( 311 str_repeat(' ',$categories->level-1). 312 ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), 313 $categories->cat_id 314 ); 315 } 316 } catch (Exception $e) { } 317 318 echo 319 '<div id="quick">'. 320 '<h3>'.__('Quick entry').'</h3>'. 321 '<form id="quick-entry" action="post.php" method="post">'. 322 '<fieldset><legend>'.__('New entry').'</legend>'. 323 '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:'). 324 form::field('post_title',20,255,'','maximal'). 325 '</label></p>'. 326 '<p class="area"><label class="required" '. 327 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 328 form::textarea('post_content',50,7). 329 '</p>'. 330 '<p><label for="cat_id" class="classic">'.__('Category:').' '. 331 form::combo('cat_id',$categories_combo).'</label></p>'. 332 '<p><input type="submit" value="'.__('Save').'" name="save" /> '. 333 ($core->auth->check('publish',$core->blog->id) 334 ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />' 335 : ''). 336 $core->formNonce(). 337 form::hidden('post_status',-2). 338 form::hidden('post_format',$core->auth->getOption('post_format')). 339 form::hidden('post_excerpt',''). 340 form::hidden('post_lang',$core->auth->getInfo('user_lang')). 341 form::hidden('post_notes',''). 342 '</p>'. 343 '</fieldset>'. 344 '</form>'. 345 '</div>'; 346 } 347 } 348 349 foreach ($__dashboard_contents as $i) 350 { 351 if ($i->count() > 0) 352 { 353 $dashboardContents .= '<div>'; 354 foreach ($i as $v) { 355 $dashboardContents .= $v; 356 } 357 $dashboardContents .= '</div>'; 358 } 359 } 360 echo ($dashboardContents ? '<div id="dashboard-contents">'.$dashboardContents.'</div>' : ''); 361 362 echo '</div>'; 363 364 echo ($dashboardItems ? '<div id="dashboard-items">'.$dashboardItems.'</div>' : ''); 365 366 dcPage::close(); 300 $_ctx->addMessageStatic( 301 sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').' '. 302 __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') 303 ); 304 } 305 306 $_ctx->fillPageTitle(__('Dashboard')); 307 $core->tpl->display('index.html.twig'); 367 308 ?> -
admin/plugin.php
r500 r1089 15 15 dcPage::check('usage,contentadmin'); 16 16 17 $has_content = false; 17 18 $p_file = ''; 18 19 $p = !empty($_REQUEST['p']) ? $_REQUEST['p'] : null; 19 $popup = (integer) !empty($_REQUEST['popup']); 20 21 if ($popup) { 22 $open_f = array('dcPage','openPopup'); 23 $close_f = array('dcPage','closePopup'); 24 } else { 25 $open_f = array('dcPage','open'); 26 $close_f = array('dcPage','close'); 27 } 20 $popup = $_ctx->popup = (integer) !empty($_REQUEST['popup']); 28 21 29 22 if ($core->plugins->moduleExists($p)) { 30 23 $p_file = $core->plugins->moduleRoot($p).'/index.php'; 31 24 } 25 if (file_exists($p_file)) { 32 26 33 if (file_exists($p_file)) 34 { 35 # Loading plugin 27 //* Keep this for old style plugins using dcPage 28 if ($popup) { 29 $open_f = array('dcPage','openPopup'); 30 $close_f = array('dcPage','closePopup'); 31 } else { 32 $open_f = array('dcPage','open'); 33 $close_f = array('dcPage','close'); 34 } 35 36 36 $p_info = $core->plugins->getModules($p); 37 38 37 $p_url = 'plugin.php?p='.$p; 39 40 $p_title = 'no content - plugin'; 41 $p_head = ''; 42 $p_content = '<p>'.__('No content found on this plugin.').'</p>'; 43 38 $p_title = $p_head = $p_content = ''; 39 //*/ 40 # Get page content 44 41 ob_start(); 45 42 include $p_file; 46 43 $res = ob_get_contents(); 47 44 ob_end_clean(); 48 49 if (preg_match('|<head>(.*?)</head|ms',$res,$m)) { 50 if (preg_match('|<title>(.*?)</title>|ms',$m[1],$mt)) { 51 $p_title = $mt[1]; 52 } 45 46 # Check context and display 47 if ($_ctx->hasPageTitle() && !empty($res)) { 48 $has_content = true; 49 echo $res; 50 } 51 //* Keep this for old style plugins using dcPage 52 elseif (!$_ctx->hasPageTitle()) { 53 53 54 if (preg_match_all('|(<script.*?>.*?</script>)|ms',$m[1],$ms)) { 55 foreach ($ms[1] as $v) { 56 $p_head .= $v."\n"; 54 if (preg_match('|<head>(.*?)</head|ms',$res,$m)) { 55 if (preg_match('|<title>(.*?)</title>|ms',$m[1],$mt)) { 56 $p_title = $mt[1]; 57 } 58 59 if (preg_match_all('|(<script.*?>.*?</script>)|ms',$m[1],$ms)) { 60 foreach ($ms[1] as $v) { 61 $p_head .= $v."\n"; 62 } 63 } 64 65 if (preg_match_all('|(<style.*?>.*?</style>)|ms',$m[1],$ms)) { 66 foreach ($ms[1] as $v) { 67 $p_head .= $v."\n"; 68 } 69 } 70 71 if (preg_match_all('|(<link.*?/>)|ms',$m[1],$ms)) { 72 foreach ($ms[1] as $v) { 73 $p_head .= $v."\n"; 74 } 57 75 } 58 76 } 59 77 60 if (preg_match_all('|(<style.*?>.*?</style>)|ms',$m[1],$ms)) { 61 foreach ($ms[1] as $v) { 62 $p_head .= $v."\n"; 63 } 64 } 65 66 if (preg_match_all('|(<link.*?/>)|ms',$m[1],$ms)) { 67 foreach ($ms[1] as $v) { 68 $p_head .= $v."\n"; 69 } 78 if (preg_match('|<body.*?>(.+)</body>|ms',$res,$m)) { 79 $p_content = $m[1]; 80 81 call_user_func($open_f,$p_title,$p_head); 82 echo $p_content; 83 call_user_func($close_f); 84 85 $has_content = true; 70 86 } 71 87 } 72 73 if (preg_match('|<body.*?>(.+)</body>|ms',$res,$m)) { 74 $p_content = $m[1]; 75 } 76 77 call_user_func($open_f,$p_title,$p_head); 78 echo $p_content; 79 call_user_func($close_f); 88 //*/ 80 89 } 81 else 82 { 83 call_user_func($open_f,__('Plugin not found')); 84 85 echo '<h2 class="page-title">'.__('Plugin not found').'</h2>'; 86 87 echo '<p>'.__('The plugin you reached does not exist or does not have an admin page.').'</p>'; 88 89 call_user_func($close_f); 90 # No plugin or content found 91 if (!$has_content) { 92 $_ctx->fillPageTitle(__('Plugin not found')); 93 $_ctx->addError(__('The plugin you reached does not exist or does not have an admin page.')); 94 $core->tpl->display('plugin.html.twig'); 90 95 } 91 96 ?> -
admin/post.php
r1068 r1089 15 15 dcPage::check('usage,contentadmin'); 16 16 17 $post_id = ''; 18 $cat_id = ''; 19 $post_dt = ''; 20 $post_format = $core->auth->getOption('post_format'); 21 $post_password = ''; 22 $post_url = ''; 23 $post_lang = $core->auth->getInfo('user_lang'); 24 $post_title = ''; 25 $post_excerpt = ''; 26 $post_excerpt_xhtml = ''; 27 $post_content = ''; 28 $post_content_xhtml = ''; 29 $post_notes = ''; 30 $post_status = $core->auth->getInfo('user_post_status'); 31 $post_selected = false; 32 $post_open_comment = $core->blog->settings->system->allow_comments; 33 $post_open_tb = $core->blog->settings->system->allow_trackbacks; 17 function savePost($form) { 18 global $_ctx; 19 $_ctx->setAlert('save'); 20 21 } 22 23 function deletePost($form) { 24 print_r($form); exit; 25 } 34 26 35 27 $page_title = __('New entry'); … … 47 39 # If user can't publish 48 40 if (!$can_publish) { 49 $ post_status = -2;41 $form->post_status = -2; 50 42 } 51 43 … … 55 47 $categories = $core->blog->getCategories(array('post_type'=>'post')); 56 48 while ($categories->fetch()) { 57 $categories_combo[ ] = new formSelectOption(58 str_repeat(' ',$categories->level-1). ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title),59 $categories->cat_id60 );49 $categories_combo[$categories->cat_id] = 50 str_repeat(' ',$categories->level-1). 51 ($categories->level-1 == 0 ? '' : '• '). 52 html::escapeHTML($categories->cat_title); 61 53 } 62 54 } catch (Exception $e) { } … … 64 56 # Status combo 65 57 foreach ($core->blog->getAllPostStatus() as $k => $v) { 66 $status_combo[$ v] = (string) $k;58 $status_combo[$k] = $v; 67 59 } 68 $img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />';69 60 70 61 # Formaters combo … … 88 79 unset($rs); 89 80 90 # Validation flag 91 $bad_dt = false; 92 81 $form = new dcForm($core,'post','post.php'); 82 $form 83 ->addField( 84 new dcFieldText('post_title','', array( 85 'size' => 20, 86 'required' => true, 87 'label' => __('Title')))) 88 ->addField( 89 new dcFieldTextArea('post_excerpt','', array( 90 'cols' => 50, 91 'rows' => 5, 92 'label' => __("Excerpt:")))) 93 ->addField( 94 new dcFieldTextArea('post_content','', array( 95 'required' => true, 96 'label' => __("Content:")))) 97 ->addField( 98 new dcFieldTextArea('post_notes','', array( 99 'label' => __("Notes")))) 100 ->addField( 101 new dcFieldSubmit('save',__('Save'),array( 102 'action' => 'savePost'))) 103 ->addField( 104 new dcFieldSubmit('delete',__('Delete'),array( 105 'action' => 'deletePost'))) 106 ->addField( 107 new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array( 108 'disabled' => !$can_publish, 109 'label' => __('Entry status:')))) 110 ->addField( 111 new dcFieldCombo('cat_id','',$categories_combo,array( 112 "label" => __('Category:')))) 113 ->addField( 114 new dcFieldText('post_dt','',array( 115 "label" => __('Published on:')))) 116 ->addField( 117 new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array( 118 "label" => __('Text formating:')))) 119 ->addField( 120 new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array( 121 "label" => __('Accept comments')))) 122 ->addField( 123 new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array( 124 "label" => __('Accept trackbacks')))) 125 ->addField( 126 new dcFieldCheckbox ('post_selected',false,array( 127 "label" => __('Selected entry')))) 128 ->addField( 129 new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( 130 "label" => __('Entry lang:')))) 131 ->addField( 132 new dcFieldHidden ('id','')) 133 ; 93 134 # Get entry informations 94 135 if (!empty($_REQUEST['id'])) … … 105 146 else 106 147 { 107 $post_id = $post->post_id; 108 $cat_id = $post->cat_id; 109 $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 110 $post_format = $post->post_format; 111 $post_password = $post->post_password; 112 $post_url = $post->post_url; 113 $post_lang = $post->post_lang; 114 $post_title = $post->post_title; 115 $post_excerpt = $post->post_excerpt; 116 $post_excerpt_xhtml = $post->post_excerpt_xhtml; 117 $post_content = $post->post_content; 118 $post_content_xhtml = $post->post_content_xhtml; 119 $post_notes = $post->post_notes; 120 $post_status = $post->post_status; 121 $post_selected = (boolean) $post->post_selected; 122 $post_open_comment = (boolean) $post->post_open_comment; 123 $post_open_tb = (boolean) $post->post_open_tb; 148 $form->id = $post->post_id; 149 $form->cat_id = $post->cat_id; 150 $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 151 $form->post_format = $post->post_format; 152 $form->post_password = $post->post_password; 153 $form->post_url = $post->post_url; 154 $form->post_lang = $post->post_lang; 155 $form->post_title = $post->post_title; 156 $form->post_excerpt = $post->post_excerpt; 157 $form->post_excerpt_xhtml = $post->post_excerpt_xhtml; 158 $form->post_content = $post->post_content; 159 $form->post_content_xhtml = $post->post_content_xhtml; 160 $form->post_notes = $post->post_notes; 161 $form->post_status = $post->post_status; 162 $form->post_selected = (boolean) $post->post_selected; 163 $form->post_open_comment = (boolean) $post->post_open_comment; 164 $form->post_open_tb = (boolean) $post->post_open_tb; 165 $form->can_edit_post = $post->isEditable(); 166 $form->can_delete= $post->isDeletable(); 124 167 125 $page_title = __('Edit entry');126 127 $can_edit_post = $post->isEditable();128 $can_delete= $post->isDeletable();129 130 $next_rs = $core->blog->getNextPost($post,1);131 $prev_rs = $core->blog->getNextPost($post,-1);132 133 if ($next_rs !== null) {134 $next_link = sprintf($post_link,$next_rs->post_id,135 html::escapeHTML($next_rs->post_title),__('next entry').' »');136 $next_headlink = sprintf($post_headlink,'next',137 html::escapeHTML($next_rs->post_title),$next_rs->post_id);138 }139 140 if ($prev_rs !== null) {141 $prev_link = sprintf($post_link,$prev_rs->post_id,142 html::escapeHTML($prev_rs->post_title),'« '.__('previous entry'));143 $prev_headlink = sprintf($post_headlink,'previous',144 html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);145 }146 147 try {148 $core->media = new dcMedia($core);149 } catch (Exception $e) {}150 168 } 151 169 } 152 170 153 # Format excerpt and content 154 if (!empty($_POST) && $can_edit_post) 155 { 156 $post_format = $_POST['post_format']; 157 $post_excerpt = $_POST['post_excerpt']; 158 $post_content = $_POST['post_content']; 159 160 $post_title = $_POST['post_title']; 161 162 $cat_id = (integer) $_POST['cat_id']; 163 164 if (isset($_POST['post_status'])) { 165 $post_status = (integer) $_POST['post_status']; 166 } 167 168 if (empty($_POST['post_dt'])) { 169 $post_dt = ''; 170 } else { 171 try 172 { 173 $post_dt = strtotime($_POST['post_dt']); 174 if ($post_dt == false || $post_dt == -1) { 175 $bad_dt = true; 176 throw new Exception(__('Invalid publication date')); 177 } 178 $post_dt = date('Y-m-d H:i',$post_dt); 179 } 180 catch (Exception $e) 181 { 182 $core->error->add($e->getMessage()); 183 } 184 } 185 186 $post_open_comment = !empty($_POST['post_open_comment']); 187 $post_open_tb = !empty($_POST['post_open_tb']); 188 $post_selected = !empty($_POST['post_selected']); 189 $post_lang = $_POST['post_lang']; 190 $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; 191 192 $post_notes = $_POST['post_notes']; 193 194 if (isset($_POST['post_url'])) { 195 $post_url = $_POST['post_url']; 196 } 197 198 $core->blog->setPostContent( 199 $post_id,$post_format,$post_lang, 200 $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 201 ); 202 } 203 204 # Delete post 205 if (!empty($_POST['delete']) && $can_delete) 206 { 207 try { 208 # --BEHAVIOR-- adminBeforePostDelete 209 $core->callBehavior('adminBeforePostDelete',$post_id); 210 $core->blog->delPost($post_id); 211 http::redirect('posts.php'); 212 } catch (Exception $e) { 213 $core->error->add($e->getMessage()); 214 } 215 } 216 217 # Create or update post 218 if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt) 219 { 220 $cur = $core->con->openCursor($core->prefix.'post'); 221 222 $cur->post_title = $post_title; 223 $cur->cat_id = ($cat_id ? $cat_id : null); 224 $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 225 $cur->post_format = $post_format; 226 $cur->post_password = $post_password; 227 $cur->post_lang = $post_lang; 228 $cur->post_title = $post_title; 229 $cur->post_excerpt = $post_excerpt; 230 $cur->post_excerpt_xhtml = $post_excerpt_xhtml; 231 $cur->post_content = $post_content; 232 $cur->post_content_xhtml = $post_content_xhtml; 233 $cur->post_notes = $post_notes; 234 $cur->post_status = $post_status; 235 $cur->post_selected = (integer) $post_selected; 236 $cur->post_open_comment = (integer) $post_open_comment; 237 $cur->post_open_tb = (integer) $post_open_tb; 238 239 if (isset($_POST['post_url'])) { 240 $cur->post_url = $post_url; 241 } 242 243 # Update post 244 if ($post_id) 245 { 246 try 247 { 248 # --BEHAVIOR-- adminBeforePostUpdate 249 $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); 250 251 $core->blog->updPost($post_id,$cur); 252 253 # --BEHAVIOR-- adminAfterPostUpdate 254 $core->callBehavior('adminAfterPostUpdate',$cur,$post_id); 255 256 http::redirect('post.php?id='.$post_id.'&upd=1'); 257 } 258 catch (Exception $e) 259 { 260 $core->error->add($e->getMessage()); 261 } 262 } 263 else 264 { 265 $cur->user_id = $core->auth->userID(); 266 267 try 268 { 269 # --BEHAVIOR-- adminBeforePostCreate 270 $core->callBehavior('adminBeforePostCreate',$cur); 271 272 $return_id = $core->blog->addPost($cur); 273 274 # --BEHAVIOR-- adminAfterPostCreate 275 $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 276 277 http::redirect('post.php?id='.$return_id.'&crea=1'); 278 } 279 catch (Exception $e) 280 { 281 $core->error->add($e->getMessage()); 282 } 283 } 284 } 171 $form->setup(); 285 172 286 173 /* DISPLAY … … 294 181 } 295 182 296 dcPage::open($page_title.' - '.__('Entries'), 297 dcPage::jsDatePicker(). 298 dcPage::jsToolBar(). 299 dcPage::jsModal(). 300 dcPage::jsMetaEditor(). 301 dcPage::jsLoad('js/_post.js'). 302 dcPage::jsConfirmClose('entry-form','comment-form'). 303 # --BEHAVIOR-- adminPostHeaders 304 $core->callBehavior('adminPostHeaders'). 305 dcPage::jsPageTabs($default_tab). 306 $next_headlink."\n".$prev_headlink 307 ); 183 $_ctx 184 ->fillPageTitle(__('Entries'),'posts.php') 185 ->fillPageTitle($page_title) 186 ->default_tab = $default_tab; 308 187 309 if (!empty($_GET['upd'])) { 310 dcPage::message(__('Entry has been successfully updated.')); 311 } 312 elseif (!empty($_GET['crea'])) { 313 dcPage::message(__('Entry has been successfully created.')); 314 } 315 elseif (!empty($_GET['attached'])) { 316 dcPage::message(__('File has been successfully attached.')); 317 } 318 elseif (!empty($_GET['rmattach'])) { 319 dcPage::message(__('Attachment has been successfully removed.')); 320 } 321 322 if (!empty($_GET['creaco'])) { 323 dcPage::message(__('Comment has been successfully created.')); 324 } 325 326 # XHTML conversion 327 if (!empty($_GET['xconv'])) 328 { 329 $post_excerpt = $post_excerpt_xhtml; 330 $post_content = $post_content_xhtml; 331 $post_format = 'xhtml'; 332 333 dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.')); 334 } 335 336 echo '<h2>'.html::escapeHTML($core->blog->name).' › '.'<a href="posts.php">'.__('Entries').'</a> › <span class="page-title">'.$page_title; 337 if ($post_id) { 338 switch ($post_status) { 339 case 1: 340 $img_status = sprintf($img_status_pattern,__('published'),'check-on.png'); 341 break; 342 case 0: 343 $img_status = sprintf($img_status_pattern,__('unpublished'),'check-off.png'); 344 break; 345 case -1: 346 $img_status = sprintf($img_status_pattern,__('scheduled'),'scheduled.png'); 347 break; 348 case -2: 349 $img_status = sprintf($img_status_pattern,__('pending'),'check-wrn.png'); 350 break; 351 default: 352 $img_status = ''; 353 } 354 echo ' “'.$post_title.'”'.' '.$img_status; 355 } 356 echo '</span></h2>'; 357 358 if ($post_id && $post->post_status == 1) { 359 echo '<p><a href="'.$post->getURL().'" onclick="window.open(this.href);return false;" title="'.$post_title.' ('.__('new window').')'.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>'; 360 } 361 if ($post_id) 362 { 363 echo '<p>'; 364 if ($prev_link) { echo $prev_link; } 365 if ($next_link && $prev_link) { echo ' - '; } 366 if ($next_link) { echo $next_link; } 367 368 # --BEHAVIOR-- adminPostNavLinks 369 $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); 370 371 echo '</p>'; 372 } 373 374 # Exit if we cannot view page 375 if (!$can_view_page) { 376 dcPage::helpBlock('core_post'); 377 dcPage::close(); 378 exit; 379 } 380 381 /* Post form if we can edit post 382 -------------------------------------------------------- */ 383 if ($can_edit_post) 384 { 385 echo '<div class="multi-part" title="'.__('Edit entry').'" id="edit-entry">'; 386 echo '<form action="post.php" method="post" id="entry-form">'; 387 echo '<div id="entry-wrapper">'; 388 echo '<div id="entry-content"><div class="constrained">'; 389 390 echo 391 '<p class="col"><label class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:'). 392 form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). 393 '</label></p>'. 394 395 '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '. 396 form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). 397 '</p>'. 398 399 '<p class="area"><label class="required" '. 400 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 401 form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). 402 '</p>'. 403 404 '<p class="area" id="notes-area"><label for="post_notes">'.__('Notes:').'</label>'. 405 form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). 406 '</p>'; 407 408 # --BEHAVIOR-- adminPostForm 409 $core->callBehavior('adminPostForm',isset($post) ? $post : null); 410 411 echo 412 '<p>'. 413 ($post_id ? form::hidden('id',$post_id) : ''). 414 '<input type="submit" value="'.__('Save').' (s)" '. 415 'accesskey="s" name="save" /> '; 416 if ($post_id) { 417 $preview_url = 418 $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 419 http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 420 '/'.$post->post_url); 421 echo '<a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview').'</a> '; 422 } 423 echo 424 ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). 425 $core->formNonce(). 426 '</p>'; 427 428 echo '</div></div>'; // End #entry-content 429 echo '</div>'; // End #entry-wrapper 430 431 echo '<div id="entry-sidebar">'; 432 433 echo 434 '<p><label for="cat_id">'.__('Category:'). 435 form::combo('cat_id',$categories_combo,$cat_id,'maximal'). 436 '</label></p>'. 437 438 '<p><label for="post_status">'.__('Entry status:'). 439 form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). 440 '</label></p>'. 441 442 '<p><label for="post_dt">'.__('Published on:'). 443 form::field('post_dt',16,16,$post_dt,($bad_dt ? 'invalid' : '')). 444 '</label></p>'. 445 446 '<p><label for="post_format">'.__('Text formating:'). 447 form::combo('post_format',$formaters_combo,$post_format). 448 '</label>'. 449 '</p>'. 450 '<p>'.($post_id && $post_format != 'xhtml' ? '<a id="convert-xhtml" class="button" href="post.php?id='.$post_id.'&xconv=1">'.__('Convert to XHTML').'</a>' : '').'</p>'. 451 452 '<p><label for="post_open_comment" class="classic">'.form::checkbox('post_open_comment',1,$post_open_comment).' '. 453 __('Accept comments').'</label></p>'. 454 ($core->blog->settings->system->allow_comments ? 455 (isContributionAllowed($post_id,strtotime($post_dt),true) ? 456 '' : 457 '<p class="form-note warn">'.__('Warning: Comments are not more accepted for this entry.').'</p>') : 458 '<p class="form-note warn">'.__('Warning: Comments are not accepted on this blog.').'</p>'). 459 460 '<p><label for="post_open_tb" class="classic">'.form::checkbox('post_open_tb',1,$post_open_tb).' '. 461 __('Accept trackbacks').'</label></p>'. 462 ($core->blog->settings->system->allow_trackbacks ? 463 (isContributionAllowed($post_id,strtotime($post_dt),false) ? 464 '' : 465 '<p class="form-note warn">'.__('Warning: Trackbacks are not more accepted for this entry.').'</p>') : 466 '<p class="form-note warn">'.__('Warning: Trackbacks are not accepted on this blog.').'</p>'). 467 468 '<p><label for="post_selected" class="classic">'.form::checkbox('post_selected',1,$post_selected).' '. 469 __('Selected entry').'</label></p>'. 470 471 '<p><label for="post_lang">'.__('Entry lang:'). 472 form::combo('post_lang',$lang_combo,$post_lang). 473 '</label></p>'. 474 475 '<p><label for="post_password">'.__('Entry password:'). 476 form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). 477 '</label></p>'. 478 479 '<div class="lockable">'. 480 '<p><label for="post_url">'.__('Basename:'). 481 form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). 482 '</label></p>'. 483 '<p class="form-note warn">'. 484 __('Warning: If you set the URL manually, it may conflict with another entry.'). 485 '</p>'. 486 '</div>'; 487 488 # --BEHAVIOR-- adminPostFormSidebar 489 $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); 490 491 echo '</div>'; // End #entry-sidebar 492 493 echo '</form>'; 494 495 # --BEHAVIOR-- adminPostForm 496 $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); 497 498 echo '</div>'; 499 500 if ($post_id && $post->post_status == 1) { 501 echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'. 502 __('Ping blogs').'</a></p>'; 503 } 504 505 } 506 507 508 /* Comments and trackbacks 509 -------------------------------------------------------- */ 510 if ($post_id) 511 { 512 $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC'); 513 514 $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0))); 515 $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1))); 516 517 # Actions combo box 518 $combo_action = array(); 519 if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id)) 520 { 521 $combo_action[__('publish')] = 'publish'; 522 $combo_action[__('unpublish')] = 'unpublish'; 523 $combo_action[__('mark as pending')] = 'pending'; 524 $combo_action[__('mark as junk')] = 'junk'; 525 } 526 527 if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id)) 528 { 529 $combo_action[__('Delete')] = 'delete'; 530 } 531 532 # --BEHAVIOR-- adminCommentsActionsCombo 533 $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action)); 534 535 $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty()); 536 537 echo 538 '<div id="comments" class="multi-part" title="'.__('Comments').'">'; 539 540 if ($has_action) { 541 echo '<form action="comments_actions.php" id="form-comments" method="post">'; 542 } 543 544 echo '<h3>'.__('Trackbacks').'</h3>'; 545 546 if (!$trackbacks->isEmpty()) { 547 showComments($trackbacks,$has_action,true); 548 } else { 549 echo '<p>'.__('No trackback').'</p>'; 550 } 551 552 echo '<h3>'.__('Comments').'</h3>'; 553 if (!$comments->isEmpty()) { 554 showComments($comments,$has_action); 555 } else { 556 echo '<p>'.__('No comment').'</p>'; 557 } 558 559 if ($has_action) { 560 echo 561 '<div class="two-cols">'. 562 '<p class="col checkboxes-helpers"></p>'. 563 564 '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. 565 form::combo('action',$combo_action). 566 form::hidden('redir','post.php?id='.$post_id.'&co=1'). 567 $core->formNonce(). 568 '<input type="submit" value="'.__('ok').'" /></p>'. 569 '</div>'. 570 '</form>'; 571 } 572 573 echo '</div>'; 574 } 575 576 /* Add a comment 577 -------------------------------------------------------- */ 578 if ($post_id) 579 { 580 echo 581 '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'. 582 '<h3>'.__('Add a comment').'</h3>'. 583 584 '<form action="comment.php" method="post" id="comment-form">'. 585 '<div class="constrained">'. 586 '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:'). 587 form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))). 588 '</label></p>'. 589 590 '<p><label for="comment_email">'.__('Email:'). 591 form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))). 592 '</label></p>'. 593 594 '<p><label for="comment_site">'.__('Web site:'). 595 form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))). 596 '</label></p>'. 597 598 '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '. 599 __('Comment:').'</label> '. 600 form::textarea('comment_content',50,8,html::escapeHTML('')). 601 '</p>'. 602 603 '<p>'.form::hidden('post_id',$post_id). 604 $core->formNonce(). 605 '<input type="submit" name="add" value="'.__('Save').'" /></p>'. 606 '</div>'. 607 '</form>'. 608 '</div>'; 609 } 610 611 # Controls comments or trakbacks capabilities 612 function isContributionAllowed($id,$dt,$com=true) 613 { 614 global $core; 615 616 if (!$id) { 617 return true; 618 } 619 if ($com) { 620 if (($core->blog->settings->system->comments_ttl == 0) || 621 (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 622 return true; 623 } 624 } else { 625 if (($core->blog->settings->system->trackbacks_ttl == 0) || 626 (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 627 return true; 628 } 629 } 630 return false; 631 } 632 633 # Show comments or trackbacks 634 function showComments($rs,$has_action,$tb=false) 635 { 636 echo 637 '<table class="comments-list"><tr>'. 638 '<th colspan="2">'.__('Author').'</th>'. 639 '<th>'.__('Date').'</th>'. 640 '<th class="nowrap">'.__('IP address').'</th>'. 641 '<th>'.__('Status').'</th>'. 642 '<th> </th>'. 643 '</tr>'; 644 645 while($rs->fetch()) 646 { 647 $comment_url = 'comment.php?id='.$rs->comment_id; 648 649 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 650 switch ($rs->comment_status) { 651 case 1: 652 $img_status = sprintf($img,__('published'),'check-on.png'); 653 break; 654 case 0: 655 $img_status = sprintf($img,__('unpublished'),'check-off.png'); 656 break; 657 case -1: 658 $img_status = sprintf($img,__('pending'),'check-wrn.png'); 659 break; 660 case -2: 661 $img_status = sprintf($img,__('junk'),'junk.png'); 662 break; 663 } 664 665 echo 666 '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 667 ' id="c'.$rs->comment_id.'">'. 668 669 '<td class="nowrap">'. 670 ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 671 '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 672 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 673 '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'. 674 '<td class="nowrap status">'.$img_status.'</td>'. 675 '<td class="nowrap status"><a href="'.$comment_url.'">'. 676 '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'. 677 678 '</tr>'; 679 } 680 681 echo '</table>'; 682 } 683 684 dcPage::helpBlock('core_post','core_wiki'); 685 dcPage::close(); 188 $core->tpl->display('post.html.twig'); 686 189 ?> -
inc/admin/class.dc.menu.php
r691 r1064 14 14 class dcMenu 15 15 { 16 private $items; 16 17 private $id; 17 18 public $title; 19 public $separator; 18 20 19 public function __construct($id,$title,$ itemSpace='')21 public function __construct($id,$title,$separator='') 20 22 { 21 23 $this->id = $id; 22 24 $this->title = $title; 23 $this-> itemSpace = $itemSpace;25 $this->separator = $separator; 24 26 $this->items = array(); 27 } 28 29 public function getID() 30 { 31 return $this->id; 32 } 33 34 public function getTitle() 35 { 36 return $this->title; 37 } 38 39 public function getSeparator() 40 { 41 return $this->separator; 42 } 43 44 public function getItems() 45 { 46 return $this->items; 25 47 } 26 48 … … 39 61 } 40 62 63 protected function itemDef($title,$url,$img,$active,$id=null,$class=null) 64 { 65 if (is_array($url)) { 66 $link = $url[0]; 67 $ahtml = (!empty($url[1])) ? ' '.$url[1] : ''; 68 } else { 69 $link = $url; 70 $ahtml = ''; 71 } 72 73 return array( 74 'title' => $title, 75 'link' => $link, 76 'ahtml' => $ahtml, 77 'img' => dc_admin_icon_url($img), 78 'active' => (boolean) $active, 79 'id' => $id, 80 'class' => $class 81 ); 82 } 83 84 /** 85 @deprecated Use Template engine instead 86 */ 41 87 public function draw() 42 88 { … … 52 98 for ($i=0; $i<count($this->items); $i++) 53 99 { 54 if ($i+1 < count($this->items) && $this-> itemSpace!= '') {55 $res .= preg_replace('|</li>$|',$this-> itemSpace.'</li>',$this->items[$i]);100 if ($i+1 < count($this->items) && $this->separator != '') { 101 $res .= preg_replace('|</li>$|',$this->separator.'</li>',$this->drawItem($this->items[$i])); 56 102 $res .= "\n"; 57 103 } else { 58 $res .= $this-> items[$i]."\n";104 $res .= $this->drawItem($this->items[$i])."\n"; 59 105 } 60 106 } … … 65 111 } 66 112 67 protected function itemDef($title,$url,$img,$active,$id=null,$class=null) 113 /** 114 @deprecated Use Template engine instead 115 */ 116 protected function drawItem($item) 68 117 { 69 if (is_array($url)) {70 $link = $url[0];71 $ahtml = (!empty($url[1])) ? ' '.$url[1] : '';72 } else {73 $link = $url;74 $ahtml = '';75 }76 77 $img = dc_admin_icon_url($img);78 79 118 return 80 '<li'.(($ active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class: '').'"' : '').81 (($i d) ? ' id="'.$id.'"' : '').82 (($i mg) ? ' style="background-image: url('.$img.');"' : '').119 '<li'.(($item['active'] || $item['class']) ? ' class="'.(($item['active']) ? 'active ' : '').(($item['class']) ? $item['class'] : '').'"' : ''). 120 (($item['id']) ? ' id="'.$item['id'].'"' : ''). 121 (($item['img']) ? ' style="background-image: url('.$item['img'].');"' : ''). 83 122 '>'. 84 123 85 '<a href="'.$ link.'"'.$ahtml.'>'.$title.'</a></li>'."\n";124 '<a href="'.$item['link'].'"'.$item['ahtml'].'>'.$item['title'].'</a></li>'."\n"; 86 125 } 87 126 } -
inc/admin/lib.dc.page.php
r1049 r1089 49 49 50 50 # Top of admin page 51 public static function open($title='', $head='') 52 { 53 global $core; 54 55 # List of user's blogs 56 if ($core->auth->blog_count == 1 || $core->auth->blog_count > 20) 57 { 58 $blog_box = 59 '<p>'.__('Blog:').' <strong title="'.html::escapeHTML($core->blog->url).'">'. 60 html::escapeHTML($core->blog->name).'</strong>'; 61 62 if ($core->auth->blog_count > 20) { 63 $blog_box .= ' - <a href="blogs.php">'.__('Change blog').'</a>'; 64 } 65 $blog_box .= '</p>'; 66 } 67 else 68 { 69 $rs_blogs = $core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20)); 70 $blogs = array(); 71 while ($rs_blogs->fetch()) { 72 $blogs[html::escapeHTML($rs_blogs->blog_name.' - '.$rs_blogs->blog_url)] = $rs_blogs->blog_id; 73 } 74 $blog_box = 75 '<p><label for="switchblog" class="classic">'. 76 __('Blogs:').' '. 77 $core->formNonce(). 78 form::combo('switchblog',$blogs,$core->blog->id). 79 '</label></p>'. 80 '<noscript><p><input type="submit" value="'.__('ok').'" /></p></noscript>'; 81 } 82 83 $safe_mode = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode']; 84 85 # Display 86 header('Content-Type: text/html; charset=UTF-8'); 87 echo 88 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '. 89 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n". 90 '<html xmlns="http://www.w3.org/1999/xhtml" '. 91 'xml:lang="'.$core->auth->getInfo('user_lang').'" '. 92 'lang="'.$core->auth->getInfo('user_lang').'">'."\n". 93 "<head>\n". 94 ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'."\n". 95 ' <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n". 96 97 ' <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n". 98 ' <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n". 99 100 self::jsLoadIE7(). 101 ' <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 102 if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') { 103 echo 104 ' <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 105 } 106 107 $core->auth->user_prefs->addWorkspace('interface'); 108 $user_ui_hide_std_favicon = $core->auth->user_prefs->interface->hide_std_favicon; 109 if (!$user_ui_hide_std_favicon) { 110 echo '<link rel="icon" type="image/png" href="images/favicon.png" />'; 111 } 112 113 echo 114 self::jsCommon(). 115 $head; 116 117 # --BEHAVIOR-- adminPageHTMLHead 118 $core->callBehavior('adminPageHTMLHead'); 119 120 echo 121 "</head>\n". 122 '<body id="dotclear-admin'. 123 ($safe_mode ? ' safe-mode' : ''). 124 '">'."\n". 125 126 '<div id="header">'. 127 '<ul id="prelude"><li><a href="#content">'.__('Go to the content').'</a></li><li><a href="#main-menu">'.__('Go to the menu').'</a></li></ul>'."\n". 128 '<div id="top"><h1><a href="index.php">'.DC_VENDOR_NAME.'</a></h1></div>'."\n"; 129 130 echo 131 '<div id="info-boxes">'. 132 '<div id="info-box1">'. 133 '<form action="index.php" method="post">'. 134 $blog_box. 135 '<p><a href="'.$core->blog->url.'" onclick="window.open(this.href);return false;" title="'.__('Go to site').' ('.__('new window').')'.'">'.__('Go to site').' <img src="images/outgoing.png" alt="" /></a>'. 136 '</p></form>'. 137 '</div>'. 138 '<div id="info-box2">'. 139 '<a'.(preg_match('/index.php$/',$_SERVER['REQUEST_URI']) ? ' class="active"' : '').' href="index.php">'.__('My dashboard').'</a>'. 140 '<span> | </span><a'.(preg_match('/preferences.php(\?.*)?$/',$_SERVER['REQUEST_URI']) ? ' class="active"' : '').' href="preferences.php">'.__('My preferences').'</a>'. 141 '<span> | </span><a href="index.php?logout=1" class="logout">'.sprintf(__('Logout %s'),$core->auth->userID()).' <img src="images/logout.png" alt="" /></a>'. 142 '</div>'. 143 '</div>'. 144 '</div>'; 145 146 echo 147 '<div id="wrapper">'."\n". 148 '<div id="main">'."\n". 149 '<div id="content">'."\n"; 150 151 # Safe mode 152 if ($safe_mode) 153 { 154 echo 155 '<div class="error"><h3>'.__('Safe mode').'</h3>'. 156 '<p>'.__('You are in safe mode. All plugins have been temporarily disabled. Remind to log out then log in again normally to get back all functionalities').'</p>'. 157 '</div>'; 158 } 51 public static function open($title='',$head='',$popup=false) 52 { 53 global $core, $_ctx; 54 55 $_ctx->popup = (boolean) $popup; 56 $_ctx->page_header = $head; 57 $_ctx->fillPageTitle($title); 58 59 ob_start(); 60 } 61 62 public static function close() 63 { 64 $res = ob_get_contents(); 65 ob_end_clean(); 66 67 global $core, $_ctx; 159 68 160 69 if ($core->error->flag()) { 161 echo 162 '<div class="error"><p><strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</p></strong>'. 163 $core->error->toHTML(). 164 '</div>'; 165 } 166 } 167 168 public static function close() 169 { 170 global $core; 171 172 $menu =& $GLOBALS['_menu']; 173 174 echo 175 "</div>\n". // End of #content 176 "</div>\n". // End of #main 177 178 '<div id="main-menu">'."\n"; 179 180 foreach ($menu as $k => $v) { 181 echo $menu[$k]->draw(); 182 } 183 184 $text = sprintf(__('Thank you for using %s.'),'<a href="http://dotclear.org/">Dotclear '.DC_VERSION.'</a>'); 185 186 # --BEHAVIOR-- adminPageFooter 187 $textAlt = $core->callBehavior('adminPageFooter',$core,$text); 188 189 echo 190 '</div>'."\n". // End of #main-menu 191 '<div id="footer"><p>'.($textAlt != '' ? $textAlt : $text).'</p></div>'."\n". 192 "</div>\n"; // End of #wrapper 193 194 if (defined('DC_DEV') && DC_DEV === true) { 195 echo self::debugInfo(); 196 } 197 198 echo 199 '</body></html>'; 200 } 201 202 public static function openPopup($title='', $head='') 203 { 204 global $core; 205 206 # Display 207 header('Content-Type: text/html; charset=UTF-8'); 208 echo 209 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '. 210 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n". 211 '<html xmlns="http://www.w3.org/1999/xhtml" '. 212 'xml:lang="'.$core->auth->getInfo('user_lang').'" '. 213 'lang="'.$core->auth->getInfo('user_lang').'">'."\n". 214 "<head>\n". 215 ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'."\n". 216 ' <title>'.$title.' - '.html::escapeHTML($core->blog->name).' - '.html::escapeHTML(DC_VENDOR_NAME).' - '.DC_VERSION.'</title>'."\n". 217 218 ' <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />'."\n". 219 ' <meta name="GOOGLEBOT" content="NOSNIPPET" />'."\n". 220 221 self::jsLoadIE7(). 222 ' <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 223 if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') { 224 echo 225 ' <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 226 } 227 228 echo 229 self::jsCommon(). 230 $head; 231 232 # --BEHAVIOR-- adminPageHTMLHead 233 $core->callBehavior('adminPageHTMLHead'); 234 235 echo 236 "</head>\n". 237 '<body id="dotclear-admin" class="popup">'."\n". 238 239 '<div id="top"><h1>'.DC_VENDOR_NAME.'</h1></div>'."\n"; 240 241 echo 242 '<div id="wrapper">'."\n". 243 '<div id="main">'."\n". 244 '<div id="content">'."\n"; 245 246 if ($core->error->flag()) { 247 echo 248 '<div class="error"><strong>'.__('Errors:').'</strong>'. 249 $core->error->toHTML(). 250 '</div>'; 251 } 70 foreach($core->error->getErrors() as $e) { 71 $_ctx->addError($e); 72 } 73 } 74 $_ctx->page_content = $res; 75 $core->tpl->display('page_layout.html.twig'); 76 } 77 78 public static function openPopup($title='',$head='') 79 { 80 self::open($title,$head,true); 252 81 } 253 82 254 83 public static function closePopup() 255 84 { 256 echo 257 "</div>\n". // End of #content 258 "</div>\n". // End of #main 259 '<div id="footer"><p> </p></div>'."\n". 260 "</div>\n". // End of #wrapper 261 '</body></html>'; 85 self::close(); 262 86 } 263 87 … … 275 99 } 276 100 } 277 return $res;278 }279 280 private static function debugInfo()281 {282 $global_vars = implode(', ',array_keys($GLOBALS));283 284 $res =285 '<div id="debug"><div>'.286 '<p>memory usage: '.memory_get_usage().' ('.files::size(memory_get_usage()).')</p>';287 288 if (function_exists('xdebug_get_profiler_filename'))289 {290 $res .= '<p>Elapsed time: '.xdebug_time_index().' seconds</p>';291 292 $prof_file = xdebug_get_profiler_filename();293 if ($prof_file) {294 $res .= '<p>Profiler file : '.xdebug_get_profiler_filename().'</p>';295 } else {296 $prof_url = http::getSelfURI();297 $prof_url .= (strpos($prof_url,'?') === false) ? '?' : '&';298 $prof_url .= 'XDEBUG_PROFILE';299 $res .= '<p><a href="'.html::escapeURL($prof_url).'">Trigger profiler</a></p>';300 }301 302 /* xdebug configuration:303 zend_extension = /.../xdebug.so304 xdebug.auto_trace = On305 xdebug.trace_format = 0306 xdebug.trace_options = 1307 xdebug.show_mem_delta = On308 xdebug.profiler_enable = 0309 xdebug.profiler_enable_trigger = 1310 xdebug.profiler_output_dir = /tmp311 xdebug.profiler_append = 0312 xdebug.profiler_output_name = timestamp313 */314 }315 316 $res .=317 '<p>Global vars: '.$global_vars.'</p>'.318 '</div></div>';319 320 101 return $res; 321 102 } -
inc/admin/prepend.php
r1069 r1080 375 375 } 376 376 } 377 378 # Add admin default templates path 379 $core->tpl->getLoader()->addPath(dirname(__FILE__).'/default-templates'); 380 # Set admin context 381 $_ctx = new dcAdminContext($core); 382 $core->tpl->addExtension($_ctx); 383 384 # --BEHAVIOR-- adminPrepend 385 $core->callBehavior('adminPrepend',$core,$_ctx); 377 386 ?> -
inc/core/class.dc.core.php
r706 r1099 39 39 public $rest; ///< <b>dcRestServer</b> dcRestServer object 40 40 public $log; ///< <b>dcLog</b> dcLog object 41 public $tpl; ///< <b>Twig_Environment</b> Twig_Environment object 41 42 42 43 private $versions = null; … … 95 96 $this->addFormater('xhtml', create_function('$s','return $s;')); 96 97 $this->addFormater('wiki', array($this,'wikiTransform')); 98 99 $this->loadTemplateEnvironment(); 97 100 } 98 101 … … 118 121 } 119 122 123 /** 124 Create template environment (Twig_Environment instance) 125 126 default-templates path must be added from admin|public/prepend.php with: 127 $core->tpl->getLoader()->addPath('PATH_TO/default-templates'); 128 Selected theme path must be added with: 129 $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 130 */ 131 protected function loadTemplateEnvironment() 132 { 133 # If cache dir is writable, use it. 134 $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 135 if (!is_dir($cache_dir)) { 136 try { 137 files::makeDir($cache_dir); 138 } catch (Exception $e) { 139 $cache_dir = false; 140 } 141 } 142 143 $this->tpl = new Twig_Environment( 144 new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'), 145 array( 146 'auto_reload' => true, 147 'autoescape' => false, 148 'base_template_class' => 'Twig_Template', 149 'cache' => $cache_dir, 150 'charset' => 'UTF-8', 151 'debug' => DC_DEBUG, 152 'optimizations' => -1, 153 'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables! 154 ) 155 ); 156 $this->tpl->addExtension(new dcFormExtension($this)); 157 $this->tpl->addExtension(new dcTabExtension($this)); 158 } 120 159 121 160 /// @name Blog init methods -
inc/prepend.php
r1105 r1106 12 12 13 13 /* ------------------------------------------------------------------------------------------- */ 14 # ClearBricks, DotClear classes auto-loader14 # ClearBricks, Twig, DotClear classes auto-loader 15 15 if (@is_dir('/usr/lib/clearbricks')) { 16 16 define('CLEARBRICKS_PATH','/usr/lib/clearbricks'); … … 46 46 $__autoload['dcWorkspace'] = dirname(__FILE__).'/core/class.dc.workspace.php'; 47 47 $__autoload['dcPrefs'] = dirname(__FILE__).'/core/class.dc.prefs.php'; 48 $__autoload['dcTwigPage'] = dirname(__FILE__).'/core/class.dc.twig.page.php'; 48 49 49 50 $__autoload['rsExtPost'] = dirname(__FILE__).'/core/class.dc.rs.extensions.php'; … … 52 53 $__autoload['rsExtUser'] = dirname(__FILE__).'/core/class.dc.rs.extensions.php'; 53 54 55 $__autoload['dcAdminContext'] = dirname(__FILE__).'/admin/class.dc.admincontext.php'; 54 56 $__autoload['dcMenu'] = dirname(__FILE__).'/admin/class.dc.menu.php'; 55 57 $__autoload['dcPage'] = dirname(__FILE__).'/admin/lib.dc.page.php'; … … 63 65 $__autoload['context'] = dirname(__FILE__).'/public/lib.tpl.context.php'; 64 66 $__autoload['dcUrlHandlers'] = dirname(__FILE__).'/public/lib.urlhandlers.php'; 67 $__autoload['dcForm'] = dirname(__FILE__).'/admin/class.dc.form.php'; 68 $__autoload['dcFormExtension'] = dirname(__FILE__).'/admin/class.dc.form.php'; 69 $__autoload['dcTabExtension'] = dirname(__FILE__).'/admin/class.dc.tab.php'; 65 70 66 71 # Clearbricks extensions 67 72 html::$absolute_regs[] = '/(<param\s+name="movie"\s+value=")(.*?)(")/msu'; 68 73 html::$absolute_regs[] = '/(<param\s+name="FlashVars"\s+value=".*?(?:mp3|flv)=)(.*?)(&|")/msu'; 74 75 if (@is_dir('/usr/lib/twig')) { 76 define('TWIG_PATH','/usr/lib/twig'); 77 } elseif (is_dir(dirname(__FILE__).'/libs/twig')) { 78 define('TWIG_PATH',dirname(__FILE__).'/libs/twig'); 79 } elseif (isset($_SERVER['TWIG_PATH']) && is_dir($_SERVER['TWIG_PATH'])) { 80 define('TWIG_PATH',$_SERVER['TWIG_PATH']); 81 } 82 83 if (!defined('TWIG_PATH') || !is_dir(TWIG_PATH)) { 84 exit('No Twig path defined'); 85 } 86 require TWIG_PATH.'/Autoloader.php'; 87 Twig_Autoloader::register(); 88 69 89 /* ------------------------------------------------------------------------------------------- */ 70 90 -
plugins/aboutConfig/_admin.php
r270 r1070 15 15 preg_match('/plugin.php\?p=aboutConfig(&.*)?$/',$_SERVER['REQUEST_URI']), 16 16 $core->auth->isSuperAdmin()); 17 18 $core->tpl->getLoader()->addPath(dirname(__FILE__).'/admtpl/','aboutConfig'); 17 19 ?> -
plugins/aboutConfig/index.php
r907 r1089 12 12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 13 13 14 # Local navigation 15 if (!empty($_POST['gs_nav'])) { 16 http::redirect($p_url.$_POST['gs_nav']); 17 exit; 18 } 19 if (!empty($_POST['ls_nav'])) { 20 http::redirect($p_url.$_POST['ls_nav']); 21 exit; 22 } 23 24 # Local settings update 25 if (!empty($_POST['s']) && is_array($_POST['s'])) 14 class adminPageAboutConfig 26 15 { 27 try 16 public static $p_url = 'plugin.php?p=aboutConfig'; 17 18 # Update local settings 19 public static function updLocal($form) 28 20 { 29 foreach ($_POST['s'] as $ns => $s) 30 { 31 $core->blog->settings->addNamespace($ns); 21 self::updSettings($form); 22 } 23 24 # Update global settings 25 public static function updGlobal($form) 26 { 27 self::updSettings($form,true); 28 } 29 30 # Update settings 31 protected static function updSettings($form,$global=false) 32 { 33 global $core,$_ctx; 34 35 $part = $global ? 'global' : 'local'; 36 $prefix = $part.'_'; 37 38 try { 39 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 40 $core->blog->settings->addNamespace($ns); 41 $ns_settings = $global ? 42 $namespace->dumpGlobalSettings() : $namespace->dumpSettings(); 43 44 foreach ($ns_settings as $k => $v) { 45 // need to cast type 46 $f = (string) $form->{$prefix.$ns.'_'.$k}; 47 settype($f,$v['type']); 48 49 $core->blog->settings->$ns->put($k,$f,null,null,true,$global); 50 $form->{$prefix.$ns.'_'.$k} = $f; 51 } 52 } 53 $core->blog->triggerBlog(); 32 54 33 foreach ($s as $k => $v) { 34 $core->blog->settings->$ns->put($k,$v); 35 } 36 37 $core->blog->triggerBlog(); 55 http::redirect(self::$p_url.'&upd=1&part='.$part); 56 } 57 catch (Exception $e) { 58 $_ctx->addError($e->getMessage()); 59 } 60 } 61 62 # Set nav and settings forms 63 public static function setForms($global=false) 64 { 65 global $core, $_ctx; 66 67 $prefix = $global ? 'global_' : 'local_'; 68 $action = $global ? 'updGlobal' : 'updLocal'; 69 70 if (!empty($_POST[$prefix.'nav'])) { 71 http::redirect(self::$p_url.$_POST[$prefix.'nav']); 72 exit; 38 73 } 39 74 40 http::redirect($p_url.'&upd=1'); 41 } 42 catch (Exception $e) 43 { 44 $core->error->add($e->getMessage()); 75 $nav_form = new dcForm($core,$prefix.'nav_form','plugin.php'); 76 $settings_form = new dcForm($core,$prefix.'settings_form','plugin.php'); 77 78 $settings = $combo = array(); 79 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 80 $ns_settings = $global ? 81 $namespace->dumpGlobalSettings() : $namespace->dumpSettings(); 82 83 foreach ($ns_settings as $k => $v) { 84 $settings[$ns][$k] = $v; 85 } 86 } 87 88 ksort($settings); 89 foreach ($settings as $ns => $s) { 90 $combo['#'.$prefix.$ns] = $ns; 91 ksort($s); 92 foreach ($s as $k => $v) { 93 if ($v['type'] == 'boolean') { 94 $settings_form->addField( 95 new dcFieldCombo($prefix.$ns.'_'.$k, 96 '',array(1 => __('yes'),0 => __('no')))); 97 } 98 else { 99 $settings_form->addField( 100 new dcFieldText($prefix.$ns.'_'.$k,'')); 101 } 102 $settings_form->{$prefix.$ns.'_'.$k} = $v['value']; 103 } 104 } 105 106 $nav_form 107 ->addField( 108 new dcFieldCombo($prefix.'nav','',$combo,array( 109 "label" => __('Goto:')))) 110 ->addField( 111 new dcFieldSubmit($prefix.'nav_submit',__('OK'))) 112 ->addField( 113 new dcFieldHidden ('p','aboutConfig')) 114 ; 115 116 $settings_form 117 ->addField( 118 new dcFieldSubmit($prefix.'submit',__('Save'),array( 119 'action' => array('adminPageAboutConfig',$action)))) 120 ->addField( 121 new dcFieldHidden ('p','aboutConfig')) 122 ; 123 124 $_ctx->{$prefix.'settings'} = $settings; 125 126 $nav_form->setup(); 127 $settings_form->setup(); 45 128 } 46 129 } 47 130 48 # Global settings update 49 if (!empty($_POST['gs']) && is_array($_POST['gs'])) 50 { 51 try 52 { 53 foreach ($_POST['gs'] as $ns => $s) 54 { 55 $core->blog->settings->addNamespace($ns); 56 57 foreach ($s as $k => $v) { 58 $core->blog->settings->$ns->put($k,$v,null,null,true,true); 59 } 60 61 $core->blog->triggerBlog(); 62 } 63 64 http::redirect($p_url.'&upd=1&part=global'); 65 } 66 catch (Exception $e) 67 { 68 $core->error->add($e->getMessage()); 69 } 131 # Local settings forms 132 adminPageAboutConfig::setForms(); 133 134 # Global settings forms 135 adminPageAboutConfig::setForms(true); 136 137 # Commons 138 if (!empty($_GET['upd'])) { 139 $_ctx->setAlert(__('Configuration successfully updated')); 70 140 } 71 72 $part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 73 74 function settingLine($id,$s,$ns,$field_name,$strong_label) 75 { 76 if ($s['type'] == 'boolean') { 77 $field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id), 78 array(__('yes') => 1, __('no') => 0),$s['value']); 79 } else { 80 $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),40,null, 81 html::escapeHTML($s['value'])); 82 } 83 84 $slabel = $strong_label ? '<strong>%s</strong>' : '%s'; 85 86 return 87 '<tr>'. 88 '<td scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'. 89 '<td>'.$field.'</td>'. 90 '<td>'.$s['type'].'</td>'. 91 '<td>'.html::escapeHTML($s['label']).'</td>'. 92 '</tr>'; 141 if (!empty($_GET['upda'])) { 142 $_ctx->setAlert(__('Settings definition successfully updated')); 93 143 } 144 $_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 145 $_ctx->fillPageTitle('about:config'); 146 $core->tpl->display('@aboutConfig/index.html.twig'); 94 147 ?> 95 <html>96 <head>97 <title>about:config</title>98 <?php echo dcPage::jsPageTabs($part); ?>99 <style type="text/css">100 table.settings { border: 1px solid #999; margin-bottom: 2em; }101 table.settings th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; }102 p.anchor-nav {float: right; }103 </style>104 <script type="text/javascript">105 //<![CDATA[106 $(function() {107 $("#gs_submit").hide();108 $("#ls_submit").hide();109 $("#gs_nav").change(function() {110 window.location = $("#gs_nav option:selected").val();111 })112 $("#ls_nav").change(function() {113 window.location = $("#ls_nav option:selected").val();114 })115 });116 //]]>117 </script>118 </head>119 120 <body>121 <?php122 if (!empty($_GET['upd'])) {123 dcPage::message(__('Configuration successfully updated'));124 }125 126 if (!empty($_GET['upda'])) {127 dcPage::message(__('Settings definition successfully updated'));128 }129 ?>130 <h2><?php echo html::escapeHTML($core->blog->name); ?> › <span class="page-title">about:config</span></h2>131 132 <div id="local" class="multi-part" title="<?php echo __('blog settings'); ?>">133 134 <?php135 $table_header = '<table class="settings" id="%s"><caption>%s</caption>'.136 '<thead>'.137 '<tr>'."\n".138 ' <th class="nowrap">Setting ID</th>'."\n".139 ' <th>'.__('Value').'</th>'."\n".140 ' <th>'.__('Type').'</th>'."\n".141 ' <th class="maximalx">'.__('Description').'</th>'."\n".142 '</tr>'."\n".143 '</thead>'."\n".144 '<tbody>';145 $table_footer = '</tbody></table>';146 147 $settings = array();148 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {149 foreach ($namespace->dumpSettings() as $k => $v) {150 $settings[$ns][$k] = $v;151 }152 }153 ksort($settings);154 if (count($settings) > 0) {155 $ns_combo = array();156 foreach ($settings as $ns => $s) {157 $ns_combo[$ns] = '#l_'.$ns;158 }159 echo160 '<form action="plugin.php" method="post">'.161 '<p class="anchor-nav">'.162 '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo).163 ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'.164 '<input type="hidden" name="p" value="aboutConfig" />'.165 $core->formNonce().'</p></form>';166 }167 ?>168 169 <form action="plugin.php" method="post">170 171 <?php172 foreach ($settings as $ns => $s)173 {174 ksort($s);175 echo sprintf($table_header,'l_'.$ns,$ns);176 foreach ($s as $k => $v)177 {178 echo settingLine($k,$v,$ns,'s',!$v['global']);179 }180 echo $table_footer;181 }182 ?>183 184 <p><input type="submit" value="<?php echo __('Save'); ?>" />185 <input type="hidden" name="p" value="aboutConfig" />186 <?php echo $core->formNonce(); ?></p>187 </form>188 </div>189 190 <div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">191 192 <?php193 $settings = array();194 195 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {196 foreach ($namespace->dumpGlobalSettings() as $k => $v) {197 $settings[$ns][$k] = $v;198 }199 }200 201 ksort($settings);202 203 if (count($settings) > 0) {204 $ns_combo = array();205 foreach ($settings as $ns => $s) {206 $ns_combo[$ns] = '#g_'.$ns;207 }208 echo209 '<form action="plugin.php" method="post">'.210 '<p class="anchor-nav">'.211 '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).212 ' <input type="submit" value="'.__('Ok').'" id="gs_submit" />'.213 '<input type="hidden" name="p" value="aboutConfig" />'.214 $core->formNonce().'</p></form>';215 }216 ?>217 218 <form action="plugin.php" method="post">219 220 <?php221 foreach ($settings as $ns => $s)222 {223 ksort($s);224 echo sprintf($table_header,'g_'.$ns,$ns);225 foreach ($s as $k => $v)226 {227 echo settingLine($k,$v,$ns,'gs',false);228 }229 echo $table_footer;230 }231 ?>232 233 <p><input type="submit" value="<?php echo __('Save'); ?>" />234 <input type="hidden" name="p" value="aboutConfig" />235 <?php echo $core->formNonce(); ?></p>236 </form>237 </div>238 239 </body>240 </html>
Note: See TracChangeset
for help on using the changeset viewer.