Dotclear


Ignore:
Files:
375 added
13 edited

Legend:

Unmodified
Added
Removed
  • admin/auth.php

    r1484 r1492  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1414 
    1515# If we have a session cookie, go to index.php 
    16 if (isset($_SESSION['sess_user_id'])) 
    17 { 
     16if (isset($_SESSION['sess_user_id'])) { 
    1817     http::redirect('index.php'); 
    1918} 
     
    2322$dlang = http::getAcceptLanguage(); 
    2423$dlang = ($dlang == '' ? 'en' : $dlang); 
    25 if ($dlang != 'en' && preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$dlang)) 
    26 { 
     24if ($dlang != 'en' && preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$dlang)) { 
    2725     l10n::set(dirname(__FILE__).'/../locales/'.$dlang.'/main'); 
    2826} 
    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; 
    3927 
    4028# Auto upgrade 
     
    4331     try { 
    4432          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/** 
     42Actions for authentication on admin pages 
     43*/ 
     44class adminPageAuth 
    5445{ 
    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_remember',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 
     310if ($form->user_id == '' && $form->user_pwd == ''  
     311 && isset($_COOKIE['dc_admin']) && strlen($_COOKIE['dc_admin']) == 104) { 
     312 
    61313     # If we have a remember cookie, go through auth process with user_key 
    62314     $user_id = substr($_COOKIE['dc_admin'],40); 
    63315     $user_id = @unpack('a32',@pack('H*',$user_id)); 
    64      if (is_array($user_id)) 
    65      { 
     316      
     317     if (is_array($user_id)) { 
    66318          $user_id = $user_id[1]; 
    67319          $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 
     326elseif ($core->auth->allowPassChange() && !empty($_GET['akey'])) { 
     327     adminPageAuth::send($_GET['akey']); 
    249328} 
    250329 
    251330if (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'); 
    256337?> 
    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   <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    268   <title><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></title> 
    269    
    270 <?php 
    271 echo dcPage::jsLoadIE7(); 
    272 echo dcPage::jsCommon(); 
    273 ?> 
    274    
    275      <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" /> 
    276        
    277   <?php 
    278   # --BEHAVIOR-- loginPageHTMLHead 
    279   $core->callBehavior('loginPageHTMLHead'); 
    280   ?> 
    281    
    282   <script type="text/javascript"> 
    283   //<![CDATA[ 
    284   $(window).load(function() { 
    285     var uid = $('input[name=user_id]'); 
    286     var upw = $('input[name=user_pwd]'); 
    287     uid.focus(); 
    288      
    289     if (upw.length == 0) { return; } 
    290      
    291     if ($.browser.mozilla) { 
    292       uid.keypress(processKey); 
    293     } else { 
    294       uid.keydown(processKey); 
    295     } 
    296     function processKey(evt) { 
    297       if (evt.keyCode == 13 && upw.val() == '') { 
    298          upw.focus(); 
    299          return false; 
    300       } 
    301       return true; 
    302     }; 
    303     $.cookie('dc_admin_test_cookie',true); 
    304     if ($.cookie('dc_admin_test_cookie')) { 
    305       $('#cookie_help').hide(); 
    306       $.cookie('dc_admin_test_cookie', '', {'expires': -1}); 
    307     } else { 
    308       $('#cookie_help').show(); 
    309     } 
    310     $('#issue #more').toggleWithLegend($('#issue').children().not('#more')); 
    311   }); 
    312   //]]> 
    313   </script> 
    314 </head> 
    315  
    316 <body id="dotclear-admin" class="auth"> 
    317  
    318 <form action="auth.php" method="post" id="login-screen"> 
    319 <h1><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></h1> 
    320  
    321 <?php 
    322 if ($err) { 
    323      echo '<div class="error">'.$err.'</div>'; 
    324 } 
    325 if ($msg) { 
    326      echo '<p class="message">'.$msg.'</p>'; 
    327 } 
    328  
    329 if ($akey) 
    330 { 
    331      echo '<p><a href="auth.php">'.__('Back to login screen').'</a></p>'; 
    332 } 
    333 elseif ($recover) 
    334 { 
    335      echo 
    336      '<div class="fieldset"><h2>'.__('Request a new password').'</h2>'. 
    337      '<p><label for="user_id">'.__('Username:').'</label> '. 
    338      form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id)).'</p>'. 
    339       
    340      '<p><label for="user_email">'.__('Email:').'</label> '. 
    341      form::field(array('user_email','user_email'),20,255,html::escapeHTML($user_email)).'</p>'. 
    342       
    343      '<p><input type="submit" value="'.__('recover').'" />'. 
    344      form::hidden(array('recover'),1).'</p>'. 
    345      '</div>'. 
    346       
    347      '<div id="issue">'. 
    348      '<p><a href="auth.php">'.__('Back to login screen').'</a></p>'. 
    349      '</div>'; 
    350 } 
    351 elseif ($change_pwd) 
    352 { 
    353      echo 
    354      '<div class="fieldset"><h2>'.__('Change your password').'</h2>'. 
    355      '<p><label for="new_pwd">'.__('New password:').'</label> '. 
    356      form::password(array('new_pwd','new_pwd'),20,255).'</p>'. 
    357       
    358      '<p><label for="new_pwd_c">'.__('Confirm password:').'</label> '. 
    359      form::password(array('new_pwd_c','new_pwd_c'),20,255).'</p>'. 
    360      '</div>'. 
    361       
    362      '<p><input type="submit" value="'.__('change').'" />'. 
    363      form::hidden('login_data',$login_data).'</p>'; 
    364 } 
    365 else 
    366 { 
    367      if (is_callable(array($core->auth,'authForm'))) 
    368      { 
    369           echo $core->auth->authForm($user_id); 
    370      } 
    371      else 
    372      { 
    373           if ($safe_mode) { 
    374                echo '<div class="fieldset">'; 
    375                echo '<h2>'.__('Safe mode login').'</h2>'; 
    376                echo  
    377                     '<p class="form-note">'. 
    378                     __('This mode allows you to login without activating any of your plugins. This may be useful to solve compatibility problems').'&nbsp;</p>'. 
    379                     '<p class="form-note">'.__('Disable or delete any plugin suspected to cause trouble, then log out and log back in normally.'). 
    380                     '</p>'; 
    381           } 
    382           else { 
    383                echo '<div class="fieldset">'; 
    384           } 
    385  
    386           echo 
    387           '<p><label for="user_id">'.__('Username:').'</label> '. 
    388           form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id)).'</p>'. 
    389            
    390           '<p><label for="user_pwd">'.__('Password:').'</label> '. 
    391           form::password(array('user_pwd','user_pwd'),20,255).'</p>'. 
    392            
    393           '<p>'. 
    394           form::checkbox(array('user_remember','user_remember'),1). 
    395           '<label for="user_remember" class="classic">'. 
    396           __('Remember my ID on this computer').'</label></p>'. 
    397            
    398           '<p><input class="add button" type="submit" value="'.__('log in').'" /></p>'; 
    399            
    400           if (!empty($_REQUEST['blog'])) { 
    401                echo form::hidden('blog',html::escapeHTML($_REQUEST['blog'])); 
    402           } 
    403           if($safe_mode) { 
    404                echo  
    405                form::hidden('safe_mode',1). 
    406                '</div>'; 
    407           } 
    408           else { 
    409                echo '</div>'; 
    410           } 
    411           echo 
    412           '<p id="cookie_help" class="error">'.__('You must accept cookies in order to use the private area.').'</p>'; 
    413  
    414           echo '<div id="issue">'; 
    415            
    416           if ($safe_mode) { 
    417                echo 
    418                '<p><a href="auth.php" id="normal_mode_link">'.__('Get back to normal authentication').'</a></p>'; 
    419           } else { 
    420                echo '<p id="more"><strong>'.__('Connection issue?').'</strong></p>'; 
    421                if ($core->auth->allowPassChange()) { 
    422                     echo '<p><a href="auth.php?recover=1">'.__('I forgot my password').'</a></p>'; 
    423                } 
    424                echo '<p><a href="auth.php?safe_mode=1" id="safe_mode_link">'.__('I want to log in in safe mode').'</a></p>'; 
    425           } 
    426            
    427           echo '</div>'; 
    428      } 
    429 } 
    430 ?> 
    431 </form> 
    432 </body> 
    433 </html> 
  • admin/index.php

    r1499 r1506  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1313if (!empty($_GET['pf'])) { 
    1414     require dirname(__FILE__).'/../inc/load_plugin_file.php'; 
     15     exit; 
     16} 
     17if (!empty($_GET['tf'])) { 
     18     define('DC_CONTEXT_ADMIN',true); 
     19     require dirname(__FILE__).'/../inc/load_theme_file.php'; 
    1520     exit; 
    1621} 
     
    4348$plugins_install = $core->plugins->installModules(); 
    4449 
     50# Send plugins install messages to templates 
     51if (!empty($plugins_install['success'])) { 
     52     $_ctx->addMessagesList(__('Following plugins have been installed:'),$plugins_install['success']); 
     53} 
     54if (!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(); 
     63if ($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 
    4577# Check dashboard module prefs 
    4678$ws = $core->auth->user_prefs->addWorkspace('dashboard'); 
     79 
     80# Doclinks prefs 
    4781if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) { 
    4882     if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) { 
     
    5185     $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean'); 
    5286} 
     87 
     88# Send doclinks to templates 
     89$_ctx->dashboard_doclinks = array(); 
     90if ($core->auth->user_prefs->dashboard->doclinks && !empty($__resources['doc'])) { 
     91     $_ctx->dashboard_doclinks = $__resources['doc']; 
     92} 
     93 
     94# Dcnews prefs 
    5395if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) { 
    5496     if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) { 
     
    5799     $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean'); 
    58100} 
     101 
     102# Send dcnews to templates 
     103$_ctx->dashboard_dcnews = array(); 
     104if ($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 
    59132if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) { 
    60133     if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) { 
    61           $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean','',null,true); 
    62      } 
    63      $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean'); 
     134          $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean','',null,true); 
     135     } 
     136     $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean'); 
     137} 
     138 
     139# Send quick entry to templates 
     140$_ctx->dashboard_quickentry = false; 
     141if ($core->auth->user_prefs->dashboard->quickentry &&$core->auth->check('usage,contentadmin',$core->blog->id)) 
     142{ 
     143     $categories_combo = array('&nbsp;' => ''); 
     144     try { 
     145          $categories = $core->blog->getCategories(array('post_type'=>'post')); 
     146          while ($categories->fetch()) { 
     147               $categories_combo[$categories->cat_id] =  
     148                    str_repeat('&nbsp;&nbsp;',$categories->level-1). 
     149                    ($categories->level-1 == 0 ? '' : '&bull; '). 
     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; 
    64188} 
    65189 
     
    118242} 
    119243 
    120 # Latest news for dashboard 
     244# Send dashboard icons to templates 
     245$icons = array(); 
     246foreach ($__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 
    121256$__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject)); 
    122  
    123 $dashboardItem = 0; 
    124  
    125 if ($core->auth->user_prefs->dashboard->dcnews) { 
    126      try 
    127      { 
    128           if (empty($__resources['rss_news'])) { 
    129                throw new Exception(); 
    130           } 
    131       
    132           $feed_reader = new feedReader; 
    133           $feed_reader->setCacheDir(DC_TPL_CACHE); 
    134           $feed_reader->setTimeout(2); 
    135           $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); 
    136           $feed = $feed_reader->parse($__resources['rss_news']); 
    137           if ($feed) 
    138           { 
    139                $latest_news = '<h3>'.__('Latest news').'</h3><dl id="news">'; 
    140                $i = 1; 
    141                foreach ($feed->items as $item) 
    142                { 
    143                     $dt = isset($item->link) ? '<a href="'.$item->link.'" title="'.$item->title.' '.__('(external link)').'">'. 
    144                          $item->title.'</a>' : $item->title; 
    145                 
    146                     if ($i < 3) { 
    147                          $latest_news .= 
    148                          '<dt>'.$dt.'</dt>'. 
    149                          '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '. 
    150                          '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>'; 
    151                     } else { 
    152                          $latest_news .= 
    153                          '<dt>'.$dt.'</dt>'. 
    154                          '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>'; 
    155                     } 
    156                     $i++; 
    157                     if ($i > 3) { break; } 
    158                } 
    159                $latest_news .= '</dl>'; 
    160                $__dashboard_items[$dashboardItem][] = $latest_news; 
    161                $dashboardItem++; 
    162           } 
    163      } 
    164      catch (Exception $e) {} 
    165 } 
    166  
    167 # Documentation links 
    168 if ($core->auth->user_prefs->dashboard->doclinks) { 
    169      if (!empty($__resources['doc'])) 
    170      { 
    171           $doc_links = '<h3>'.__('Documentation and support').'</h3><ul>'; 
    172       
    173           foreach ($__resources['doc'] as $k => $v) { 
    174                $doc_links .= '<li><a href="'.$v.'" title="'.$k.' '.__('(external link)').'">'.$k.'</a></li>'; 
    175           } 
    176       
    177           $doc_links .= '</ul>'; 
    178           $__dashboard_items[$dashboardItem][] = $doc_links; 
    179           $dashboardItem++; 
    180      } 
    181 } 
    182  
    183257$core->callBehavior('adminDashboardItems', $core, $__dashboard_items); 
    184258 
     259# Send dashboard items to templates 
     260$items = array(); 
     261foreach ($__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 
    185270# Dashboard content 
    186 $dashboardContents = ''; 
    187271$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject)); 
    188272$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents); 
    189273 
    190 /* DISPLAY 
    191 -------------------------------------------------------- */ 
    192 dcPage::open(__('Dashboard'), 
    193      dcPage::jsToolBar(). 
    194      dcPage::jsLoad('js/_index.js'). 
    195      # --BEHAVIOR-- adminDashboardHeaders 
    196      $core->callBehavior('adminDashboardHeaders'), 
    197      dcPage::breadcrumb( 
    198           array( 
    199           '<span class="page-title">'.__('Dashboard').' : '.html::escapeHTML($core->blog->name).'</span>' => '' 
    200           ), 
    201           false) 
    202 ); 
    203  
    204 # Dotclear updates notifications 
    205 if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) 
    206 { 
    207      $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); 
    208      $new_v = $updater->check(DC_VERSION); 
    209      $version_info = $new_v ? $updater->getInfoURL() : ''; 
    210  
    211      if ($updater->getNotify() && $new_v) { 
    212           $message = 
    213           '<div><p>'.sprintf(__('Dotclear %s is available!'),$new_v).'</p> '. 
    214           '<ul><li><strong><a href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a></strong>'. 
    215           '</li><li><a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'. 
    216           ($version_info ? ' </li><li><a href="'.$version_info.'">'.__('information about this version').'</a>' : ''). 
    217           '</li></ul></div>'; 
    218           dcPage::message($message,false,true); 
    219      } 
    220 } 
    221  
    222 if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->blog_count > 1) { 
    223      echo 
    224      '<p><a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a></p>'; 
    225 } 
    226  
     274# Send dashboard contents to templates 
     275$contents = array(); 
     276foreach ($__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 
    227286if ($core->blog->status == 0) { 
    228      echo '<p class="static-msg">'.__('This blog is offline').'</p>'; 
     287     $_ctx->addMessageStatic(__('This blog is offline')); 
    229288} elseif ($core->blog->status == -1) { 
    230      echo '<p class="static-msg">'.__('This blog is removed').'</p>'; 
    231 } 
    232  
     289     $_ctx->addMessageStatic(__('This blog is removed')); 
     290} 
     291 
     292# Config errors messages 
    233293if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) { 
    234      echo 
    235      '<p class="static-msg">'. 
    236      sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL'). 
    237      ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.'). 
    238      '</p>'; 
    239 } 
    240  
     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} 
    241299if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) { 
    242      echo 
    243      '<p class="static-msg">'. 
    244      sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM'). 
    245      ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.'). 
    246      '</p>'; 
    247 } 
    248  
    249 # Plugins install messages 
    250 if (!empty($plugins_install['success'])) 
    251 { 
    252      echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; 
    253      foreach ($plugins_install['success'] as $k => $v) { 
    254           echo '<li>'.$k.'</li>'; 
    255      } 
    256      echo '</ul></div>'; 
    257 } 
    258 if (!empty($plugins_install['failure'])) 
    259 { 
    260      echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; 
    261      foreach ($plugins_install['failure'] as $k => $v) { 
    262           echo '<li>'.$k.' ('.$v.')</li>'; 
    263      } 
    264      echo '</ul></div>'; 
    265 } 
    266  
    267 # Dashboard columns (processed first, as we need to know the result before displaying the icons.) 
    268 $dashboardItems = ''; 
    269  
    270 # Errors modules notifications 
    271 if ($core->auth->isSuperAdmin()) 
    272 { 
    273      $list = array(); 
    274      foreach ($core->plugins->getErrors() as $k => $error) { 
    275           $list[] = '<li>'.$error.'</li>'; 
    276      } 
    277       
    278      if (count($list) > 0) { 
    279           $dashboardItems .= 
    280           '<div id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '. 
    281           '<ul>'.implode("\n",$list).'</ul></div>'; 
    282      } 
    283       
    284 } 
    285  
    286 foreach ($__dashboard_items as $i) 
    287 {     
    288      if ($i->count() > 0) 
    289      { 
    290           $dashboardItems .= '<div class="db-item">'; 
    291           foreach ($i as $v) { 
    292                $dashboardItems .= $v; 
    293           } 
    294           $dashboardItems .= '</div>'; 
    295      } 
    296 } 
    297  
    298 # Dashboard icons 
    299 echo '<div id="dashboard-main"'.($dashboardItems ? '' : ' class="fullwidth"').'><div id="icons">'; 
    300 foreach ($__dashboard_icons as $i) 
    301 { 
    302      echo 
    303      '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'. 
    304      '<br /><span>'.$i[0].'</span></a></p>'; 
    305 } 
    306 echo '</div>'; 
    307  
    308 if ($core->auth->user_prefs->dashboard->quickentry) { 
    309      if ($core->auth->check('usage,contentadmin',$core->blog->id)) 
    310      { 
    311           # Getting categories 
    312           $categories_combo = array(__('(No cat)') => ''); 
    313           try { 
    314                $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    315                if (!$categories->isEmpty()) { 
    316                     while ($categories->fetch()) { 
    317                          $catparents_combo[] = $categories_combo[] = new formSelectOption( 
    318                               str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    319                               $categories->cat_id 
    320                          ); 
    321                     } 
    322                } 
    323           } catch (Exception $e) { } 
    324       
    325           echo 
    326           '<div id="quick">'. 
    327           '<h3>'.__('Quick entry').'</h3>'. 
    328           '<form id="quick-entry" action="post.php" method="post" class="fieldset">'. 
    329           '<h4>'.__('New entry').'</h4>'. 
    330           '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'. 
    331           form::field('post_title',20,255,'','maximal'). 
    332           '</p>'. 
    333           '<p class="area"><label class="required" '. 
    334           'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 
    335           form::textarea('post_content',50,7). 
    336           '</p>'. 
    337           '<p><label for="cat_id" class="classic">'.__('Category:').' '. 
    338           form::combo('cat_id',$categories_combo).'</label></p>'. 
    339           ($core->auth->check('categories', $core->blog->id) 
    340                ? '<div>'. 
    341                '<p id="new_cat">'.__('Add a new category').'</p>'. 
    342                '<p><label for="new_cat_title">'.__('Title:').' '. 
    343                form::field('new_cat_title',30,255,'','maximal').'</label></p>'. 
    344                '<p><label for="new_cat_parent">'.__('Parent:').' '. 
    345                form::combo('new_cat_parent',$categories_combo,'','maximal'). 
    346                '</label></p>'. 
    347                '</div>' 
    348                : ''). 
    349           '<p><input type="submit" value="'.__('Save').'" name="save" /> '. 
    350           ($core->auth->check('publish',$core->blog->id) 
    351                ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />' 
    352                : ''). 
    353           $core->formNonce(). 
    354           form::hidden('post_status',-2). 
    355           form::hidden('post_format',$core->auth->getOption('post_format')). 
    356           form::hidden('post_excerpt',''). 
    357           form::hidden('post_lang',$core->auth->getInfo('user_lang')). 
    358           form::hidden('post_notes',''). 
    359           '</p>'. 
    360           '</form>'. 
    361           '</div>'; 
    362      } 
    363 } 
    364  
    365 foreach ($__dashboard_contents as $i) 
    366 {     
    367      if ($i->count() > 0) 
    368      { 
    369           $dashboardContents .= '<div>'; 
    370           foreach ($i as $v) { 
    371                $dashboardContents .= $v; 
    372           } 
    373           $dashboardContents .= '</div>'; 
    374      } 
    375 } 
    376 echo ($dashboardContents ? '<div id="dashboard-contents">'.$dashboardContents.'</div>' : ''); 
    377  
    378 echo '</div>'; 
    379  
    380 echo ($dashboardItems ? '<div id="dashboard-items">'.$dashboardItems.'</div>' : ''); 
    381  
    382 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->setBreadCrumb(__('Dashboard').' : '.html::escapeHTML($core->blog->name), false); 
     307$core->tpl->display('index.html.twig'); 
    383308?> 
  • admin/plugin.php

    r1358 r1490  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1515dcPage::check('usage,contentadmin'); 
    1616 
     17$has_content = false; 
    1718$p_file = ''; 
    1819$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']); 
    2821 
    2922if ($core->plugins->moduleExists($p)) { 
    3023     $p_file = $core->plugins->moduleRoot($p).'/index.php'; 
    3124} 
     25if (file_exists($p_file)) { 
    3226 
    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      
    3636     $p_info = $core->plugins->getModules($p); 
    37       
    3837     $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 
    4441     ob_start(); 
    4542     include $p_file; 
    4643     $res = ob_get_contents(); 
    4744     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()) { 
    5353           
    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                    } 
    5775               } 
    5876          } 
    5977           
    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; 
    7086          } 
    7187     } 
    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//*/ 
    8089} 
    81 else 
    82 { 
    83      call_user_func($open_f,__('Plugin not found'),'', 
    84           dcPage::breadcrumb( 
    85                array( 
    86                     __('System') => '', 
    87                     '<span class="page-title">'.__('Plugin not found').'</span>' => '' 
    88                )) 
    89      ); 
    90       
    91      echo '<p>'.__('The plugin you reached does not exist or does not have an admin page.').'</p>'; 
    92       
    93      call_user_func($close_f); 
     90# No plugin or content found 
     91if (!$has_content) { 
     92     $_ctx->setBreadcrumb(__('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'); 
    9495} 
    9596?> 
  • admin/post.php

    r1468 r1498  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1515dcPage::check('usage,contentadmin'); 
    1616 
    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; 
     17class PostActions  
     18{ 
     19     public static function savePost($form) { 
     20          global $_ctx, $core; 
     21          if (!$form->can_edit_post) { 
     22               return; 
     23          } 
     24          try { 
     25               $form->check($_ctx); 
     26               $form->cat_id = (integer) $form->cat_id; 
     27      
     28               if (!empty($form->post_dt)) { 
     29                    try 
     30                    { 
     31                         $post_dt = strtotime($form->post_dt); 
     32                         if ($post_dt == false || $post_dt == -1) { 
     33                              $bad_dt = true; 
     34                              throw new Exception(__('Invalid publication date')); 
     35                         } 
     36                         $form->post_dt = date('Y-m-d H:i',$post_dt); 
     37                    } 
     38                    catch (Exception $e) 
     39                    { 
     40                         $core->error->add($e->getMessage()); 
     41                    } 
     42               } 
     43               $post_excerpt = $form->post_excerpt; 
     44               $post_content = $form->post_content; 
     45               $post_excerpt_xhtml = ''; 
     46               $post_content_xhtml = ''; 
     47               $core->blog->setPostContent( 
     48                    $form->id,$form->post_format,$form->post_lang, 
     49                    $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 
     50               ); 
     51               $form->post_excerpt = $post_excerpt; 
     52               $form->post_content = $post_content; 
     53               $form->post_excerpt_xhtml = $post_excerpt_xhtml; 
     54               $form->post_content_xhtml = $post_content_xhtml; 
     55                
     56               $cur = $core->con->openCursor($core->prefix.'post'); 
     57      
     58               $cur->post_title = $form->post_title; 
     59               $cur->cat_id = $form->cat_id ? $form->cat_id : null; 
     60               $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : ''; 
     61               $cur->post_format = $form->post_format; 
     62               $cur->post_password = $form->post_password; 
     63               $cur->post_lang = $form->post_lang; 
     64               $cur->post_title = $form->post_title; 
     65               $cur->post_excerpt = $form->post_excerpt; 
     66               $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml; 
     67               $cur->post_content = $form->post_content; 
     68               $cur->post_content_xhtml = $form->post_content_xhtml; 
     69               $cur->post_notes = $form->post_notes; 
     70               $cur->post_status = $form->post_status; 
     71               $cur->post_selected = (integer) $form->post_selected; 
     72               $cur->post_open_comment = (integer) $form->post_open_comment; 
     73               $cur->post_open_tb = (integer) $form->post_open_tb; 
     74      
     75               if (!empty($form->post_url)) { 
     76                    $cur->post_url = $form->post_url; 
     77               } 
     78      
     79               # Update post 
     80               if ($form->id) 
     81               { 
     82                    # --BEHAVIOR-- adminBeforePostUpdate 
     83                    $core->callBehavior('adminBeforePostUpdate',$cur,$form->id); 
     84                     
     85                    $core->blog->updPost($form->id,$cur); 
     86                     
     87                    # --BEHAVIOR-- adminAfterPostUpdate 
     88                    $core->callBehavior('adminAfterPostUpdate',$cur,$form->id); 
     89                    http::redirect('post.php?id='.$form->id.'&upd=1'); 
     90               } 
     91               else 
     92               { 
     93                    $cur->user_id = $core->auth->userID(); 
     94                                        # --BEHAVIOR-- adminBeforePostCreate 
     95                    $core->callBehavior('adminBeforePostCreate',$cur); 
     96                     
     97                    $return_id = $core->blog->addPost($cur); 
     98                     
     99                    # --BEHAVIOR-- adminAfterPostCreate 
     100                    $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 
     101                     
     102                    http::redirect('post.php?id='.$return_id.'&crea=1'); 
     103               } 
     104 
     105          } catch (Exception $e) { 
     106               $_ctx->addError($e->getMessage()); 
     107          } 
     108     } 
     109     public static function deletePost($form) { 
     110          global $core,$_ctx; 
     111          if ($form->can_delete) { 
     112               try { 
     113                    $post_id = $form->id; 
     114                    $core->callBehavior('adminBeforePostDelete',$post_id); 
     115                    $core->blog->delPost($post_id); 
     116                    http::redirect('posts.php'); 
     117                    exit; 
     118               } catch (Exception $e) { 
     119                    $_ctx->addError($e->getMessage()); 
     120               } 
     121          } 
     122     } 
     123} 
    34124 
    35125$page_title = __('New entry'); 
    36  
     126$post_id=''; 
    37127$can_view_page = true; 
    38128$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); 
     
    47137# If user can't publish 
    48138if (!$can_publish) { 
    49      $post_status = -2; 
     139     $form->post_status = -2; 
    50140} 
    51141 
     
    55145     $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    56146     while ($categories->fetch()) { 
    57           $categories_combo[] = new formSelectOption( 
    58                str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    59                $categories->cat_id 
    60           ); 
     147          $categories_combo[$categories->cat_id] =  
     148               str_repeat('&nbsp;&nbsp;',$categories->level-1). 
     149               ($categories->level-1 == 0 ? '' : '&bull; '). 
     150               html::escapeHTML($categories->cat_title); 
    61151     } 
    62152} catch (Exception $e) { } 
     
    64154# Status combo 
    65155foreach ($core->blog->getAllPostStatus() as $k => $v) { 
    66      $status_combo[$v] = (string) $k; 
    67 } 
    68 $img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />'; 
     156     $status_combo[$k] = $v; 
     157} 
    69158 
    70159# Formaters combo 
     
    76165$rs = $core->blog->getLangs(array('order'=>'asc')); 
    77166$all_langs = l10n::getISOcodes(0,1); 
    78 $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); 
     167$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1)); 
    79168while ($rs->fetch()) { 
    80169     if (isset($all_langs[$rs->post_lang])) { 
    81           $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; 
    82           unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); 
     170          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 
     171          unset($lang_combo[__('Available')][$rs->post_lang]); 
    83172     } else { 
    84           $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; 
     173          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 
    85174     } 
    86175} 
     
    88177unset($rs); 
    89178 
    90 # Validation flag 
    91 $bad_dt = false; 
    92  
     179$form = new dcForm($core,'post','post.php'); 
     180$form 
     181     ->addField( 
     182          new dcFieldText('post_title','', array( 
     183               'maxlength'         => 255, 
     184               'required'     => true, 
     185               'label'        => __('Title:')))) 
     186     ->addField( 
     187          new dcFieldTextArea('post_excerpt','', array( 
     188               'cols'         => 50, 
     189               'rows'         => 5, 
     190               'label'        => __("Excerpt:").'<span class="form-note">'. 
     191               __('Add an introduction to the post.').'</span>'))) 
     192     ->addField( 
     193          new dcFieldTextArea('post_content','', array( 
     194               'required'     => true, 
     195               'label'        => __("Content:")))) 
     196     ->addField( 
     197          new dcFieldTextArea('post_notes','', array( 
     198               'label'        => __("Notes")))) 
     199     ->addField( 
     200          new dcFieldSubmit('save',__('Save'),array( 
     201               'action' => array('PostActions','savePost')))) 
     202     ->addField( 
     203          new dcFieldSubmit('delete',__('Delete'),array( 
     204               'action' => array('PostActions','deletePost')))) 
     205     ->addField( 
     206          new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array( 
     207               'disabled' => !$can_publish, 
     208               'label' => __('Entry status')))) 
     209     ->addField( 
     210          new dcFieldCombo('cat_id','',$categories_combo,array( 
     211               "label" => __('Category')))) 
     212     ->addField( 
     213          new dcFieldCombo('new_cat_parent','',$categories_combo,array( 
     214               "label" => __('Parent:')))) 
     215     ->addField( 
     216          new dcFieldText('new_cat_title','', array( 
     217               'maxlength'         => 255, 
     218               'label'        => __('Title')))) 
     219           
     220     ->addField( 
     221          new dcFieldText('post_dt','',array( 
     222               "label" => __('Publication date and hour')))) 
     223     ->addField( 
     224          new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array( 
     225               "label" => __('Text formating')))) 
     226     ->addField( 
     227          new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array( 
     228               "label" => __('Accept comments')))) 
     229     ->addField( 
     230          new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array( 
     231               "label" => __('Accept trackbacks')))) 
     232     ->addField( 
     233          new dcFieldCheckbox ('post_selected',array(1=>false),array( 
     234               "label" => __('Selected entry')))) 
     235     ->addField( 
     236          new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( 
     237               "label" => __('Entry lang:')))) 
     238     ->addField( 
     239          new dcFieldText('post_password','',array( 
     240               "maxlength" => 32, 
     241               "label" => __('Entry password:')))) 
     242     ->addField( 
     243          new dcFieldText('post_url','',array( 
     244               "maxlength" => 255, 
     245               "label" => __('Basename:')))) 
     246     ->addField( 
     247          new dcFieldHidden ('id','')) 
     248; 
    93249# Get entry informations 
    94250if (!empty($_REQUEST['id'])) 
    95251{ 
    96      $page_title = __('Edit entry'); 
    97       
    98252     $params['post_id'] = $_REQUEST['id']; 
    99253      
     
    107261     else 
    108262     { 
    109           $post_id = $post->post_id; 
    110           $cat_id = $post->cat_id; 
    111           $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 
    112           $post_format = $post->post_format; 
    113           $post_password = $post->post_password; 
    114           $post_url = $post->post_url; 
    115           $post_lang = $post->post_lang; 
    116           $post_title = $post->post_title; 
    117           $post_excerpt = $post->post_excerpt; 
    118           $post_excerpt_xhtml = $post->post_excerpt_xhtml; 
    119           $post_content = $post->post_content; 
    120           $post_content_xhtml = $post->post_content_xhtml; 
    121           $post_notes = $post->post_notes; 
    122           $post_status = $post->post_status; 
    123           $post_selected = (boolean) $post->post_selected; 
    124           $post_open_comment = (boolean) $post->post_open_comment; 
    125           $post_open_tb = (boolean) $post->post_open_tb; 
    126            
    127           $can_edit_post = $post->isEditable(); 
    128           $can_delete= $post->isDeletable(); 
    129            
     263          $form->id = $post_id = $post->post_id; 
     264          $form->cat_id = $post->cat_id; 
     265          $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 
     266          $form->post_format = $post->post_format; 
     267          $form->post_password = $post->post_password; 
     268          $form->post_url = $post->post_url; 
     269          $form->post_lang = $post->post_lang; 
     270          $form->post_title = $post->post_title; 
     271          $form->post_excerpt = $post->post_excerpt; 
     272          $form->post_excerpt_xhtml = $post->post_excerpt_xhtml; 
     273          $form->post_content = $post->post_content; 
     274          $form->post_content_xhtml = $post->post_content_xhtml; 
     275          $form->post_notes = $post->post_notes; 
     276          $form->post_status = $post->post_status; 
     277          $form->post_selected = (boolean) $post->post_selected; 
     278          $form->post_open_comment = (boolean) $post->post_open_comment; 
     279          $form->post_open_tb = (boolean) $post->post_open_tb; 
     280          $form->can_edit_post = $post->isEditable(); 
     281          $form->can_delete= $post->isDeletable(); 
    130282          $next_rs = $core->blog->getNextPost($post,1); 
    131283          $prev_rs = $core->blog->getNextPost($post,-1); 
    132284           
    133285          if ($next_rs !== null) { 
    134                $next_link = sprintf($post_link,$next_rs->post_id, 
    135                     html::escapeHTML($next_rs->post_title),__('Next entry').'&nbsp;&#187;'); 
    136                $next_headlink = sprintf($post_headlink,'next', 
    137                     html::escapeHTML($next_rs->post_title),$next_rs->post_id); 
    138           } 
     286               $_ctx->next_post = array('id' => $next_rs->post_id,'title' => $next_rs->post_title); 
     287          } 
     288          if ($prev_rs !== null) { 
     289               $_ctx->prev_post = array('id' => $prev_rs->post_id,'title' => $prev_rs->post_title); 
     290          } 
     291          $page_title = __('Edit entry'); 
     292 
     293     } 
     294} 
     295if ($post_id) { 
     296     $_ctx->post_id = $post->post_id; 
     297 
     298     $_ctx->preview_url = 
     299          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 
     300          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 
     301          '/'.$post->post_url); 
    139302           
    140           if ($prev_rs !== null) { 
    141                $prev_link = sprintf($post_link,$prev_rs->post_id, 
    142                     html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('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      } 
    151 } 
    152  
    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      # Create category 
    221      if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { 
    222       
    223           $cur_cat = $core->con->openCursor($core->prefix.'category'); 
    224           $cur_cat->cat_title = $_POST['new_cat_title']; 
    225           $cur_cat->cat_url = ''; 
    226            
    227           $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 
    228            
    229           # --BEHAVIOR-- adminBeforeCategoryCreate 
    230           $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 
    231            
    232           $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 
    233            
    234           # --BEHAVIOR-- adminAfterCategoryCreate 
    235           $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id); 
    236      } 
    237       
    238      $cur = $core->con->openCursor($core->prefix.'post'); 
    239       
    240      $cur->post_title = $post_title; 
    241      $cur->cat_id = ($cat_id ? $cat_id : null); 
    242      $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 
    243      $cur->post_format = $post_format; 
    244      $cur->post_password = $post_password; 
    245      $cur->post_lang = $post_lang; 
    246      $cur->post_title = $post_title; 
    247      $cur->post_excerpt = $post_excerpt; 
    248      $cur->post_excerpt_xhtml = $post_excerpt_xhtml; 
    249      $cur->post_content = $post_content; 
    250      $cur->post_content_xhtml = $post_content_xhtml; 
    251      $cur->post_notes = $post_notes; 
    252      $cur->post_status = $post_status; 
    253      $cur->post_selected = (integer) $post_selected; 
    254      $cur->post_open_comment = (integer) $post_open_comment; 
    255      $cur->post_open_tb = (integer) $post_open_tb; 
    256       
    257      if (isset($_POST['post_url'])) { 
    258           $cur->post_url = $post_url; 
    259      } 
    260       
    261      # Update post 
    262      if ($post_id) 
    263      { 
    264           try 
    265           { 
    266                # --BEHAVIOR-- adminBeforePostUpdate 
    267                $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); 
    268                 
    269                $core->blog->updPost($post_id,$cur); 
    270                 
    271                # --BEHAVIOR-- adminAfterPostUpdate 
    272                $core->callBehavior('adminAfterPostUpdate',$cur,$post_id); 
    273                 
    274                http::redirect('post.php?id='.$post_id.'&upd=1'); 
    275           } 
    276           catch (Exception $e) 
    277           { 
    278                $core->error->add($e->getMessage()); 
    279           } 
    280      } 
    281      else 
    282      { 
    283           $cur->user_id = $core->auth->userID(); 
    284            
    285           try 
    286           { 
    287                # --BEHAVIOR-- adminBeforePostCreate 
    288                $core->callBehavior('adminBeforePostCreate',$cur); 
    289                 
    290                $return_id = $core->blog->addPost($cur); 
    291                 
    292                # --BEHAVIOR-- adminAfterPostCreate 
    293                $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 
    294                 
    295                http::redirect('post.php?id='.$return_id.'&crea=1'); 
    296           } 
    297           catch (Exception $e) 
    298           { 
    299                $core->error->add($e->getMessage()); 
    300           } 
    301      } 
    302 } 
    303  
    304 # Getting categories 
    305 $categories_combo = array(__('(No cat)') => ''); 
    306 try { 
    307      $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    308      if (!$categories->isEmpty()) { 
    309           while ($categories->fetch()) { 
    310                $catparents_combo[] = $categories_combo[] = new formSelectOption( 
    311                     str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    312                     $categories->cat_id 
    313                ); 
    314           } 
    315      } 
    316 } catch (Exception $e) { } 
     303      
     304     $form_comment = new dcForm($core,'add-comment','comment.php'); 
     305     $form_comment 
     306          ->addField( 
     307               new dcFieldText('comment_author','', array( 
     308                    'maxlength'         => 255, 
     309                    'required'     => true, 
     310                    'label'        => __('Name:')))) 
     311          ->addField( 
     312               new dcFieldText('comment_email','', array( 
     313                    'maxlength'         => 255, 
     314                    'required'     => true, 
     315                    'label'        => __('Email:')))) 
     316          ->addField( 
     317               new dcFieldText('comment_site','', array( 
     318                    'maxlength'         => 255, 
     319                    'label'        => __('Web site:')))) 
     320          ->addField( 
     321               new dcFieldTextArea('comment_content','', array( 
     322                    'required'     => true, 
     323                    'label'        => __('Comment:')))) 
     324          ->addField( 
     325               new dcFieldHidden('post_id',$post_id)) 
     326          ->addField( 
     327               new dcFieldSubmit('add',__('Save'),array( 
     328                    'action' => 'addComment'))) 
     329          ; 
     330 
     331      
     332} 
     333 
     334$form->setup(); 
     335 
     336$sidebar_blocks = new ArrayObject(array( 
     337     'status-box' => array( 
     338          'title' => __('Status'), 
     339          'items' => array('post_status','post_dt','post_lang','post_format')), 
     340     'metas-box' => array( 
     341          'title' => __('Ordering'), 
     342          'items' => array('post_selected','cat_id')), 
     343     'options-box' => array( 
     344          'title' => __('Options'), 
     345          'items' => array('post_open_comment','post_open_tb','post_password','post_url')) 
     346)); 
     347 
     348$main_blocks = new ArrayObject(array( 
     349     "post_title","post_excerpt","post_content","post_notes" 
     350)); 
     351 
     352 
     353$_ctx->sidebar_blocks = $sidebar_blocks; 
     354$_ctx->main_blocks = $main_blocks; 
    317355 
    318356/* DISPLAY 
     
    325363     $default_tab = 'comments'; 
    326364} 
    327  
    328 if ($post_id) { 
    329      switch ($post_status) { 
    330           case 1: 
    331                $img_status = sprintf($img_status_pattern,__('Published'),'check-on.png'); 
    332                break; 
    333           case 0: 
    334                $img_status = sprintf($img_status_pattern,__('Unpublished'),'check-off.png'); 
    335                break; 
    336           case -1: 
    337                $img_status = sprintf($img_status_pattern,__('Scheduled'),'scheduled.png'); 
    338                break; 
    339           case -2: 
    340                $img_status = sprintf($img_status_pattern,__('Pending'),'check-wrn.png'); 
    341                break; 
    342           default: 
    343                $img_status = ''; 
    344      } 
    345      $edit_entry_str = __('&ldquo;%s&rdquo;'); 
    346      $page_title_edit = sprintf($edit_entry_str, html::escapeHTML($post_title)).' '.$img_status; 
    347 } else { 
    348      $img_status = ''; 
    349 } 
    350  
    351  
    352 dcPage::open($page_title.' - '.__('Entries'), 
    353      dcPage::jsDatePicker(). 
    354      dcPage::jsToolBar(). 
    355      dcPage::jsModal(). 
    356      dcPage::jsMetaEditor(). 
    357      dcPage::jsLoad('js/_post.js'). 
    358      dcPage::jsConfirmClose('entry-form','comment-form'). 
    359      # --BEHAVIOR-- adminPostHeaders 
    360      $core->callBehavior('adminPostHeaders'). 
    361      dcPage::jsPageTabs($default_tab). 
    362      $next_headlink."\n".$prev_headlink, 
    363      dcPage::breadcrumb( 
     365$page_title_edit = __('Edit entry'); 
     366$_ctx 
     367     ->setBreadCrumb( 
    364368          array( 
    365369               html::escapeHTML($core->blog->name) => '', 
    366370               __('Entries') => 'posts.php', 
    367                '<span class="page-title">'.($post_id ? $page_title_edit : $page_title).'</span>' => '' 
    368           )) 
    369 ); 
     371               ($post_id ? $page_title_edit : $page_title) => '' 
     372     )) 
     373     ->default_tab = $default_tab; 
     374$_ctx->post_status = $form->post_status; 
     375$_ctx->post_title = $form->post_title; 
     376if ($form->post_status == 1) { 
     377     $_ctx->post_url = $post->getURL(); 
     378} 
    370379 
    371380if (!empty($_GET['upd'])) { 
    372      dcPage::message(__('Entry has been successfully updated.')); 
     381     $_ctx->setAlert(__('Entry has been successfully updated.')); 
    373382} 
    374383elseif (!empty($_GET['crea'])) { 
    375      dcPage::message(__('Entry has been successfully created.')); 
     384     $_ctx->setAlert(__('Entry has been successfully created.')); 
    376385} 
    377386elseif (!empty($_GET['attached'])) { 
    378      dcPage::message(__('File has been successfully attached.')); 
     387     $_ctx->setAlert(__('File has been successfully attached.')); 
    379388} 
    380389elseif (!empty($_GET['rmattach'])) { 
    381      dcPage::message(__('Attachment has been successfully removed.')); 
    382 } 
    383  
     390     $_ctx->setAlert(__('Attachment has been successfully removed.')); 
     391} 
    384392if (!empty($_GET['creaco'])) { 
    385      dcPage::message(__('Comment has been successfully created.')); 
    386 } 
    387  
    388 # XHTML conversion 
    389 if (!empty($_GET['xconv'])) 
    390 { 
    391      $post_excerpt = $post_excerpt_xhtml; 
    392      $post_content = $post_content_xhtml; 
    393      $post_format = 'xhtml'; 
    394       
    395      dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.')); 
    396 } 
    397  
    398 if ($post_id && $post->post_status == 1) { 
    399      echo '<p><a class="onblog_link" 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>'; 
    400 } 
    401 if ($post_id) 
    402 { 
    403      echo '<p class="nav_prevnext">'; 
    404      if ($prev_link) { echo $prev_link; } 
    405      if ($next_link && $prev_link) { echo ' | '; } 
    406      if ($next_link) { echo $next_link; } 
    407       
    408      # --BEHAVIOR-- adminPostNavLinks 
    409      $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); 
    410       
    411      echo '</p>'; 
    412 } 
    413  
    414 # Exit if we cannot view page 
    415 if (!$can_view_page) { 
    416      dcPage::helpBlock('core_post'); 
    417      dcPage::close(); 
    418      exit; 
    419 } 
    420 /* Post form if we can edit post 
    421 -------------------------------------------------------- */ 
    422 if ($can_edit_post) 
    423 { 
    424      $sidebar_items = new ArrayObject(array( 
    425           'status-box' => array( 
    426                'title' => __('Status'), 
    427                'items' => array( 
    428                     'post_status' =>  
    429                          '<p class="entry-status"><label for="post_status" class="ib">'.__('Entry status').' '.$img_status.'</label>'. 
    430                          form::combo('post_status',$status_combo,$post_status,'maximal','',!$can_publish). 
    431                          '</p>', 
    432                     'post_dt' =>  
    433                          '<p><label for="post_dt" class="ib">'.__('Publication date and hour').'</label>'. 
    434                          form::field('post_dt',16,16,$post_dt,($bad_dt ? 'invalid' : '')). 
    435                          '</p>', 
    436                     'post_lang' => 
    437                          '<p><label for="post_lang" class="ib">'.__('Entry lang').'</label>'. 
    438                          form::combo('post_lang',$lang_combo,$post_lang). 
    439                          '</p>', 
    440                     'post_format' => 
    441                          '<p><label for="post_format" class="ib">'.__('Text formating').'</label>'. 
    442                          form::combo('post_format',$formaters_combo,$post_format,'maximal'). 
    443                          '</p>'. 
    444                          '<p>'.($post_id && $post_format != 'xhtml' ?  
    445                          '<a id="convert-xhtml" class="button maximal" href="post.php?id='.$post_id.'&amp;xconv=1">'. 
    446                          __('Convert to XHTML').'</a>' : '').'</p>')), 
    447           'metas-box' => array( 
    448                'title' => __('Ordering'), 
    449                'items' => array( 
    450                     'post_selected' =>  
    451                          '<p><label for="post_selected" class="classic">'. 
    452                          form::checkbox('post_selected',1,$post_selected).' '. 
    453                          __('Selected entry').'</label></p>', 
    454                     'cat_id' => 
    455                          '<p><label for="cat_id" class="ib">'.__('Category').'</label>'. 
    456                          form::combo('cat_id',$categories_combo,$cat_id,'maximal'). 
    457                          '</p>'. 
    458                          ($core->auth->check('categories', $core->blog->id) ? 
    459                               '<div>'. 
    460                               '<p id="new_cat">'.__('Add a new category').'</p>'. 
    461                               '<p><label for="new_cat_title">'.__('Title:').' '. 
    462                               form::field('new_cat_title',30,255,'','maximal').'</label></p>'. 
    463                               '<p><label for="new_cat_parent">'.__('Parent:').' '. 
    464                               form::combo('new_cat_parent',$categories_combo,'','maximal'). 
    465                               '</label></p>'. 
    466                               '</div>' 
    467                          : ''))), 
    468           'options-box' => array( 
    469                'title' => __('Options'), 
    470                'items' => array( 
    471                     'post_open_comment' => 
    472                          '<p><label for="post_open_comment" class="classic">'. 
    473                          form::checkbox('post_open_comment',1,$post_open_comment).' '. 
    474                          __('Accept comments').'</label></p>'. 
    475                          ($core->blog->settings->system->allow_comments ?  
    476                               (isContributionAllowed($post_id,strtotime($post_dt),true) ?  
    477                                    '' : 
    478                                    '<p class="form-note warn">'. 
    479                                    __('Warning: Comments are not more accepted for this entry.').'</p>') :  
    480                               '<p class="form-note warn">'. 
    481                               __('Warning: Comments are not accepted on this blog.').'</p>'), 
    482                     'post_open_tb' => 
    483                          '<p><label for="post_open_tb" class="classic">'. 
    484                          form::checkbox('post_open_tb',1,$post_open_tb).' '. 
    485                          __('Accept trackbacks').'</label></p>'. 
    486                          ($core->blog->settings->system->allow_trackbacks ?  
    487                               (isContributionAllowed($post_id,strtotime($post_dt),false) ?  
    488                                    '' : 
    489                                    '<p class="form-note warn">'. 
    490                                    __('Warning: Trackbacks are not more accepted for this entry.').'</p>') :  
    491                               '<p class="form-note warn">'.__('Warning: Trackbacks are not accepted on this blog.').'</p>'), 
    492                     'post_password' => 
    493                          '<p><label for="post_password" class="ib">'.__('Password').'</label>'. 
    494                          form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). 
    495                          '</p>', 
    496                     'post_url' => 
    497                          '<div class="lockable">'. 
    498                          '<p><label for="post_url" class="ib">'.__('Edit basename').'</label>'. 
    499                          form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). 
    500                          '</p>'. 
    501                          '<p class="form-note warn">'. 
    502                          __('Warning: If you set the URL manually, it may conflict with another entry.'). 
    503                          '</p></div>' 
    504      )))); 
    505  
    506      $main_items = new ArrayObject(array( 
    507           "post_title" => 
    508                '<p class="col">'. 
    509                '<label class="required no-margin"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'. 
    510                form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). 
    511                '</p>', 
    512            
    513           "post_excerpt" => 
    514                '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'<span class="form-note">'. 
    515                __('Add an introduction to the post.').'</span></label> '. 
    516                form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). 
    517                '</p>', 
    518            
    519           "post_content" => 
    520                '<p class="area"><label class="required" '. 
    521                'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 
    522                form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). 
    523                '</p>', 
    524            
    525           "post_notes" => 
    526                '<p class="area" id="notes-area"><label for="post_notes">'.__('Personal notes:').'<span class="form-note">'. 
    527                __('Add unpublished notes.').'</span></label>'. 
    528                form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). 
    529                '</p>' 
    530           ) 
    531      ); 
    532       
    533      # --BEHAVIOR-- adminPostFormItems 
    534      $core->callBehavior('adminPostFormItems',$main_items,$sidebar_items, isset($post) ? $post : null); 
    535  
    536      echo '<div class="multi-part" title="'.($post_id ? __('Edit entry') : __('New entry')).'" id="edit-entry">'; 
    537      echo '<form action="post.php" method="post" id="entry-form">'; 
    538      echo '<div id="entry-wrapper">'; 
    539      echo '<div id="entry-content"><div class="constrained">'; 
    540  
    541      echo '<h3 class="hidden">'.__('Edit post').'</h3>'; 
    542       
    543      foreach ($main_items as $id => $item) { 
    544           echo $item; 
    545      } 
    546  
    547      # --BEHAVIOR-- adminPostForm (may be deprecated) 
    548      $core->callBehavior('adminPostForm',isset($post) ? $post : null); 
    549       
    550      echo 
    551      '<p class="border-top">'. 
    552      ($post_id ? form::hidden('id',$post_id) : ''). 
    553      '<input type="submit" value="'.__('Save').' (s)" '. 
    554      'accesskey="s" name="save" /> '; 
    555      if ($post_id) { 
    556           $preview_url = 
    557           $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 
    558           http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 
    559           '/'.$post->post_url); 
    560           echo '<a id="post-preview" href="'.$preview_url.'" class="button" accesskey="p">'.__('Preview').' (p)'.'</a> '; 
    561      } else { 
    562           echo 
    563           '<a id="post-cancel" href="index.php" class="button" accesskey="c">'.__('Cancel').' (c)</a>'; 
    564      } 
    565  
    566      echo 
    567      ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). 
    568      $core->formNonce(). 
    569      '</p>'; 
    570       
    571      echo '</div></div>';          // End #entry-content 
    572      echo '</div>';      // End #entry-wrapper 
    573  
    574      echo '<div id="entry-sidebar">'; 
    575       
    576      foreach ($sidebar_items as $id => $c) { 
    577           echo '<div id="'.$id.'" class="box">'. 
    578                '<h4>'.$c['title'].'</h4>'; 
    579           foreach ($c['items'] as $e_name=>$e_content) { 
    580                echo $e_content; 
    581           } 
    582           echo '</div>'; 
    583      } 
    584       
    585       
    586      # --BEHAVIOR-- adminPostFormSidebar (may be deprecated) 
    587      $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); 
    588      echo '</div>';      // End #entry-sidebar 
    589  
    590      echo '</form>'; 
    591       
    592      # --BEHAVIOR-- adminPostForm 
    593      $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); 
    594       
    595      echo '</div>'; 
    596       
    597      if ($post_id && $post->post_status == 1) { 
    598           echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'. 
    599           __('Ping blogs').'</a></p>'; 
    600      } 
    601       
    602 } 
    603  
    604  
    605 /* Comments and trackbacks 
    606 -------------------------------------------------------- */ 
    607 if ($post_id) 
    608 { 
    609      $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC'); 
    610       
    611      $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0))); 
    612      $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1))); 
    613       
    614      # Actions combo box 
    615      $combo_action = array(); 
    616      if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id)) 
    617      { 
    618           $combo_action[__('Publish')] = 'publish'; 
    619           $combo_action[__('Unpublish')] = 'unpublish'; 
    620           $combo_action[__('Mark as pending')] = 'pending'; 
    621           $combo_action[__('Mark as junk')] = 'junk'; 
    622      } 
    623       
    624      if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id)) 
    625      { 
    626           $combo_action[__('Delete')] = 'delete'; 
    627      } 
    628       
    629      # --BEHAVIOR-- adminCommentsActionsCombo 
    630      $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action)); 
    631       
    632      $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty()); 
    633       
    634      echo 
    635      '<div id="comments" class="multi-part" title="'.__('Comments').'">'; 
    636       
    637      if ($has_action) { 
    638           echo '<form action="comments_actions.php" id="form-comments" method="post">'; 
    639      } 
    640       
    641      echo '<h3>'.__('Trackbacks').'</h3>'; 
    642       
    643      if (!$trackbacks->isEmpty()) { 
    644           showComments($trackbacks,$has_action,true); 
    645      } else { 
    646           echo '<p>'.__('No trackback').'</p>'; 
    647      } 
    648       
    649      echo '<h3>'.__('Comments').'</h3>'; 
    650      if (!$comments->isEmpty()) { 
    651           showComments($comments,$has_action); 
    652      } else { 
    653           echo '<p>'.__('No comment').'</p>'; 
    654      } 
    655       
    656      if ($has_action) { 
    657           echo 
    658           '<div class="two-cols">'. 
    659           '<p class="col checkboxes-helpers"></p>'. 
    660            
    661           '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. 
    662           form::combo('action',$combo_action). 
    663           form::hidden('redir','post.php?id='.$post_id.'&amp;co=1'). 
    664           $core->formNonce(). 
    665           '<input type="submit" value="'.__('ok').'" /></p>'. 
    666           '</div>'. 
    667           '</form>'; 
    668      } 
    669       
    670      echo '</div>'; 
    671 } 
    672  
    673 /* Add a comment 
    674 -------------------------------------------------------- */ 
    675 if ($post_id) 
    676 { 
    677      echo 
    678      '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'. 
    679      '<h3>'.__('Add a comment').'</h3>'. 
    680       
    681      '<form action="comment.php" method="post" id="comment-form">'. 
    682      '<div class="constrained">'. 
    683      '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').'</label>'. 
    684      form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))). 
    685      '</p>'. 
    686       
    687      '<p><label for="comment_email">'.__('Email:').'</label>'. 
    688      form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))). 
    689      '</p>'. 
    690       
    691      '<p><label for="comment_site">'.__('Web site:').'</label>'. 
    692      form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))). 
    693      '</p>'. 
    694       
    695      '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '. 
    696      __('Comment:').'</label> '. 
    697      form::textarea('comment_content',50,8,html::escapeHTML('')). 
    698      '</p>'. 
    699       
    700      '<p>'.form::hidden('post_id',$post_id). 
    701      $core->formNonce(). 
    702      '<input type="submit" name="add" value="'.__('Save').'" /></p>'. 
    703      '</div>'. 
    704      '</form>'. 
    705      '</div>'; 
    706 } 
    707  
    708 # Controls comments or trakbacks capabilities 
    709 function isContributionAllowed($id,$dt,$com=true) 
    710 { 
    711      global $core; 
    712  
    713      if (!$id) { 
    714           return true; 
    715      } 
    716      if ($com) { 
    717           if (($core->blog->settings->system->comments_ttl == 0) ||  
    718                (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 
    719                return true; 
    720           } 
    721      } else { 
    722           if (($core->blog->settings->system->trackbacks_ttl == 0) ||  
    723                (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 
    724                return true; 
    725           } 
    726      } 
    727      return false; 
    728 } 
    729  
    730 # Show comments or trackbacks 
    731 function showComments($rs,$has_action,$tb=false) 
    732 { 
    733      echo 
    734      '<table class="comments-list"><tr>'. 
    735      '<th colspan="2">'.__('Author').'</th>'. 
    736      '<th>'.__('Date').'</th>'. 
    737      '<th class="nowrap">'.__('IP address').'</th>'. 
    738      '<th>'.__('Status').'</th>'. 
    739      '<th>&nbsp;</th>'. 
    740      '</tr>'; 
    741       
    742      while($rs->fetch()) 
    743      { 
    744           $comment_url = 'comment.php?id='.$rs->comment_id; 
    745            
    746           $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
    747           switch ($rs->comment_status) { 
    748                case 1: 
    749                     $img_status = sprintf($img,__('Published'),'check-on.png'); 
    750                     break; 
    751                case 0: 
    752                     $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 
    753                     break; 
    754                case -1: 
    755                     $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 
    756                     break; 
    757                case -2: 
    758                     $img_status = sprintf($img,__('Junk'),'junk.png'); 
    759                     break; 
    760           } 
    761            
    762           echo 
    763           '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 
    764           ' id="c'.$rs->comment_id.'">'. 
    765            
    766           '<td class="nowrap">'. 
    767           ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 
    768           '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 
    769           '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 
    770           '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'. 
    771           '<td class="nowrap status">'.$img_status.'</td>'. 
    772           '<td class="nowrap status"><a href="'.$comment_url.'">'. 
    773           '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'. 
    774            
    775           '</tr>'; 
    776      } 
    777       
    778      echo '</table>'; 
    779 } 
    780  
    781 dcPage::helpBlock('core_post','core_trackbacks','core_wiki'); 
    782 dcPage::close(); 
     393     $_ctx->setAlert(__('Comment has been successfully created.')); 
     394}     
     395      
     396$core->tpl->display('post.html.twig'); 
    783397?> 
  • admin/posts.php

    r1476 r1498  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212 
    1313require dirname(__FILE__).'/../inc/admin/prepend.php'; 
    14  
     14global $_ctx; 
    1515dcPage::check('usage,contentadmin'); 
    1616 
     
    4848     # Filter form we'll put in html_block 
    4949     $users_combo = $categories_combo = array(); 
    50      $users_combo['-'] = $categories_combo['-'] = ''; 
    5150     while ($users->fetch()) 
    5251     { 
     
    6160     } 
    6261      
    63      $categories_combo[__('None')] = 'NULL'; 
     62 
     63# Getting categories 
     64$categories_combo = array(); 
     65try { 
     66     $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    6467     while ($categories->fetch()) { 
    65           $categories_combo[str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; '). 
    66                html::escapeHTML($categories->cat_title). 
    67                ' ('.$categories->nb_post.')'] = $categories->cat_id; 
     68          $categories_combo[$categories->cat_id] =  
     69               str_repeat('&nbsp;&nbsp;',$categories->level-1). 
     70               ($categories->level-1 == 0 ? '' : '&bull; '). 
     71               html::escapeHTML($categories->cat_title); 
    6872     } 
    69       
     73} catch (Exception $e) { } 
    7074     $status_combo = array( 
    71      '-' => '' 
    7275     ); 
    7376     foreach ($core->blog->getAllPostStatus() as $k => $v) { 
    74           $status_combo[$v] = (string) $k; 
     77          $status_combo[(string) $k] = (string)$v; 
    7578     } 
    7679      
    7780     $selected_combo = array( 
    78      '-' => '', 
    79      __('Selected') => '1', 
    80      __('Not selected') => '0' 
     81     '1' => __('is selected'), 
     82     '0' => __('is not selected') 
    8183     ); 
    8284      
    8385     # Months array 
    84      $dt_m_combo['-'] = ''; 
    8586     while ($dates->fetch()) { 
    86           $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); 
     87          $dt_m_combo[$dates->year().$dates->month()] = dt::str('%B %Y',$dates->ts()); 
    8788     } 
    8889      
    89      $lang_combo['-'] = ''; 
    9090     while ($langs->fetch()) { 
    9191          $lang_combo[$langs->post_lang] = $langs->post_lang; 
    9292     } 
    93       
    94      $sortby_combo = array( 
    95      __('Date') => 'post_dt', 
    96      __('Title') => 'post_title', 
    97      __('Category') => 'cat_title', 
    98      __('Author') => 'user_id', 
    99      __('Status') => 'post_status', 
    100      __('Selected') => 'post_selected' 
    101      ); 
    102       
    103      $order_combo = array( 
    104      __('Descending') => 'desc', 
    105      __('Ascending') => 'asc' 
    106      ); 
    10793} 
     94$form = new dcForm($core,'post','post.php'); 
     95 
    10896 
    10997# Actions combo box 
     
    138126$core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); 
    139127 
    140 /* Get posts 
    141 -------------------------------------------------------- */ 
    142 $user_id = !empty($_GET['user_id']) ?   $_GET['user_id'] : ''; 
    143 $cat_id = !empty($_GET['cat_id']) ?     $_GET['cat_id'] : ''; 
    144 $status = isset($_GET['status']) ? $_GET['status'] : ''; 
    145 $selected = isset($_GET['selected']) ?  $_GET['selected'] : ''; 
    146 $month = !empty($_GET['month']) ?       $_GET['month'] : ''; 
    147 $lang = !empty($_GET['lang']) ?         $_GET['lang'] : ''; 
    148 $sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'post_dt'; 
    149 $order = !empty($_GET['order']) ?       $_GET['order'] : 'desc'; 
    150128 
    151 $show_filters = false; 
    152129 
    153 $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; 
    154 $nb_per_page =  30; 
    155  
    156 if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { 
    157      if ($nb_per_page != $_GET['nb']) { 
    158           $show_filters = true; 
     130class monthdcFilterCombo extends dcFilterCombo { 
     131     public function applyFilter($params) { 
     132          $month=$this->avalues['values'][0]; 
     133          $params['post_month'] = substr($month,4,2); 
     134          $params['post_year'] = substr($month,0,4); 
    159135     } 
    160      $nb_per_page = (integer) $_GET['nb']; 
    161136} 
    162137 
    163 $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); 
    164 $params['no_content'] = true; 
     138class PostsFetcher extends dcListFetcher { 
    165139 
    166 # - User filter 
    167 if ($user_id !== '' && in_array($user_id,$users_combo)) { 
    168      $params['user_id'] = $user_id; 
    169      $show_filters = true; 
    170 } else { 
    171      $user_id=''; 
    172 } 
     140     public function getEntries($params,$offset,$limit) { 
     141          $params['limit'] = array($offset,$limit); 
     142          return $this->core->blog->getPosts($params); 
     143     } 
    173144 
    174 # - Categories filter 
    175 if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { 
    176      $params['cat_id'] = $cat_id; 
    177      $show_filters = true; 
    178 } else { 
    179      $cat_id=''; 
    180 } 
    181  
    182 # - Status filter 
    183 if ($status !== '' && in_array($status,$status_combo)) { 
    184      $params['post_status'] = $status; 
    185      $show_filters = true; 
    186 } else { 
    187      $status=''; 
    188 } 
    189  
    190 # - Selected filter 
    191 if ($selected !== '' && in_array($selected,$selected_combo)) { 
    192      $params['post_selected'] = $selected; 
    193      $show_filters = true; 
    194 } else { 
    195      $selected=''; 
    196 } 
    197  
    198 # - Month filter 
    199 if ($month !== '' && in_array($month,$dt_m_combo)) { 
    200      $params['post_month'] = substr($month,4,2); 
    201      $params['post_year'] = substr($month,0,4); 
    202      $show_filters = true; 
    203 } else { 
    204      $month=''; 
    205 } 
    206  
    207 # - Lang filter 
    208 if ($lang !== '' && in_array($lang,$lang_combo)) { 
    209      $params['post_lang'] = $lang; 
    210      $show_filters = true; 
    211 } else { 
    212      $lang=''; 
    213 } 
    214  
    215 # - Sortby and order filter 
    216 if ($sortby !== '' && in_array($sortby,$sortby_combo)) { 
    217      if ($order !== '' && in_array($order,$order_combo)) { 
    218           $params['order'] = $sortby.' '.$order; 
    219      } else { 
    220           $order='desc'; 
     145     public function getEntriesCount($params) { 
     146          $count = $this->core->blog->getPosts($params,true); 
     147          return $count->f(0); 
    221148     } 
    222       
    223      if ($sortby != 'post_dt' || $order != 'desc') { 
    224           $show_filters = true; 
    225      } 
    226 } else { 
    227      $sortby='post_dt'; 
    228      $order='desc'; 
    229 } 
    230  
    231 # Get posts 
    232 try { 
    233      $posts = $core->blog->getPosts($params); 
    234      $counter = $core->blog->getPosts($params,true); 
    235      $post_list = new adminPostList($core,$posts,$counter->f(0)); 
    236 } catch (Exception $e) { 
    237      $core->error->add($e->getMessage()); 
    238149} 
    239150 
    240151/* DISPLAY 
    241152-------------------------------------------------------- */ 
    242 $starting_script = dcPage::jsLoad('js/_posts_list.js'); 
    243 if (!$show_filters) { 
    244      $starting_script .= dcPage::jsLoad('js/filter-controls.js'); 
    245 } 
     153$filterSet = new dcFilterSet($core,'fposts','posts.php'); 
    246154 
    247 dcPage::open(__('Entries'),$starting_script, 
    248      dcPage::breadcrumb( 
    249           array( 
    250                html::escapeHTML($core->blog->name) => '', 
    251                '<span class="page-title">'.__('Entries').'</span>' => '' 
    252           )) 
    253 ); 
    254 if (!empty($_GET['upd'])) { 
    255      dcPage::message(__('Selected entries have been successfully updated.')); 
    256 } elseif (!empty($_GET['del'])) { 
    257      dcPage::message(__('Selected entries have been successfully deleted.')); 
    258 } 
    259 if (!$core->error->flag()) 
    260 { 
    261      echo 
    262      '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; 
    263       
    264      if (!$show_filters) { 
    265           echo '<p><a id="filter-control" class="form-control" href="#">'. 
    266           __('Filter posts list').'</a></p>'; 
    267      } 
    268       
    269      echo 
    270      '<form action="posts.php" method="get" id="filters-form">'. 
    271      '<h3>'.__('Filter posts list').'</h3>'. 
     155$filterSet 
     156     ->addFilter(new dcFilterRichCombo( 
     157          'users',__('Author'), __('Author'), 'user_id', $users_combo,array( 
     158               'multiple' => true))) 
     159     ->addFilter(new dcFilterRichCombo( 
     160          'category',__('Category'), __('Category'), 'cat_id', $categories_combo,array( 
     161               'multiple' => true))) 
     162     ->addFilter(new dcFilterRichCombo( 
     163          'post_status',__('Status'), __('Status'), 'post_status', $status_combo)) 
     164     ->addFilter(new dcFilterRichCombo( 
     165          'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo)) 
     166     ->addFilter(new dcFilterCombo( 
     167          'selected',__('Selected'), __('The post : '),'post_selected', $selected_combo)) 
     168     ->addFilter(new monthdcFilterCombo( 
     169          'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))) 
     170     ->addFilter(new dcFilterText( 
     171          'search',__('Contains'),__('The entry contains'), 'search',20,255)); 
    272172 
    273      '<div class="table">'. 
    274      '<div class="cell">'. 
    275      '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. 
    276      form::combo('user_id',$users_combo,$user_id).'</p>'. 
    277      '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. 
    278      form::combo('cat_id',$categories_combo,$cat_id).'</p>'. 
    279      '<p><label for="status" class="ib">'.__('Status:').'</label> ' . 
    280      form::combo('status',$status_combo,$status).'</p> '. 
    281      '</div>'. 
    282       
    283      '<div class="cell">'. 
    284      '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. 
    285      form::combo('selected',$selected_combo,$selected).'</p>'. 
    286      '<p><label for="month" class="ib">'.__('Month:').'</label> '. 
    287      form::combo('month',$dt_m_combo,$month).'</p>'. 
    288      '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. 
    289      form::combo('lang',$lang_combo,$lang).'</p> '. 
    290      '</div>'. 
    291       
    292      '<div class="cell filters-options">'. 
    293      '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. 
    294      form::combo('sortby',$sortby_combo,$sortby).'</p>'. 
    295      '<p><label for="order" class="ib">'.__('Sort:').'</label> '. 
    296      form::combo('order',$order_combo,$order).'</p>'. 
    297      '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. 
    298      form::field('nb',3,3,$nb_per_page).' '. 
    299      __('entries per page').'</label></p>'. 
    300      '</div>'. 
    301      '</div>'. 
    302173 
    303      '<p><input type="submit" value="'.__('Apply filters').'" />'. 
    304      '<br class="clear" /></p>'. //Opera sucks 
    305      '</form>'; 
    306       
    307      # Show posts 
    308      $post_list->display($page,$nb_per_page, 
    309      '<form action="posts_actions.php" method="post" id="form-entries">'. 
    310       
    311      '%s'. 
    312       
    313      '<div class="two-cols">'. 
    314      '<p class="col checkboxes-helpers"></p>'. 
    315       
    316      '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. 
    317      form::combo('action',$combo_action). 
    318      '<input type="submit" value="'.__('ok').'" /></p>'. 
    319      form::hidden(array('user_id'),$user_id). 
    320      form::hidden(array('cat_id'),$cat_id). 
    321      form::hidden(array('status'),$status). 
    322      form::hidden(array('selected'),$selected). 
    323      form::hidden(array('month'),$month). 
    324      form::hidden(array('lang'),$lang). 
    325      form::hidden(array('sortby'),$sortby). 
    326      form::hidden(array('order'),$order). 
    327      form::hidden(array('page'),$page). 
    328      form::hidden(array('nb'),$nb_per_page). 
    329      $core->formNonce(). 
    330      '</div>'. 
    331      '</form>' 
    332      ); 
    333 } 
     174$lfetcher = new PostsFetcher($core); 
     175$lposts = new dcItemList ($core,array('lposts','form-entries'),$lfetcher,'posts_actions.php'); 
     176$lposts->setFilterSet($filterSet); 
     177$lposts->addTemplate('posts_cols.html.twig'); 
    334178 
    335 dcPage::helpBlock('core_posts'); 
    336 dcPage::close(); 
     179$lposts 
     180     ->addColumn(new dcColumn('title',__('Title'),'post_title')) 
     181     ->addColumn(new dcColumn('cat',__('Category'),'cat_title')) 
     182     ->addColumn(new dcColumn('date',__('Date'),'post_date')) 
     183     ->addColumn(new dcColumn('datetime',__('Date and Time'),'post_dt')) 
     184     ->addColumn(new dcColumn('author',__('Author'),'user_id')) 
     185     ->addColumn(new dcColumn('status',__('Status'),'post_status')); 
     186 
     187 
     188$lposts->setup(); 
     189 
     190$_ctx 
     191     ->setBreadCrumb(array(__('Entries') => 'posts.php')); 
     192 
     193 
     194$core->tpl->display('posts.html.twig'); 
     195 
     196 
    337197?> 
  • inc/admin/class.dc.menu.php

    r1179 r1315  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1414class dcMenu 
    1515{ 
     16     private $items; 
    1617     private $id; 
    1718     public $title; 
     19     public $separator; 
    1820      
    19      public function __construct($id,$title,$itemSpace='') 
     21     public function __construct($id,$title,$separator='') 
    2022     { 
    2123          $this->id = $id; 
    2224          $this->title = $title; 
    23           $this->itemSpace = $itemSpace; 
     25          $this->separator = $separator; 
    2426          $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; 
    2547     } 
    2648      
     
    3961     } 
    4062      
     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     */ 
    4187     public function draw() 
    4288     { 
     
    5298          for ($i=0; $i<count($this->items); $i++) 
    5399          { 
    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])); 
    56102                    $res .= "\n"; 
    57103               } else { 
    58                     $res .= $this->items[$i]."\n"; 
     104                    $res .= $this->drawItem($this->items[$i])."\n"; 
    59105               } 
    60106          } 
     
    65111     } 
    66112      
    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) 
    68117     { 
    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            
    79118          return 
    80           '<li'.(($active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class : '').'"' : ''). 
    81           (($id) ? ' id="'.$id.'"' : ''). 
    82           (($img) ? ' 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'].');"' : ''). 
    83122          '>'. 
    84123           
    85           '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n"; 
     124          '<a href="'.$item['link'].'"'.$item['ahtml'].'>'.$item['title'].'</a></li>'."\n"; 
    86125     } 
    87126} 
  • inc/admin/lib.dc.page.php

    r1468 r1492  
    4949 
    5050     # Top of admin page 
    51      public static function open($title='',$head='',$breadcrumb='') 
     51     public static function open($title='', $head='') 
    5252     { 
    5353          global $core; 
     
    159159          } 
    160160 
    161           // Display breadcrumb (if given) before any error message 
    162           echo $breadcrumb; 
    163  
    164161          if ($core->error->flag()) { 
    165162               echo 
    166                '<div class="error"><p><strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</strong></p>'. 
     163               '<div class="error"><p><strong>'.(count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')).'</p></strong>'. 
    167164               $core->error->toHTML(). 
    168165               '</div>'; 
     
    213210     } 
    214211 
    215      public static function openPopup($title='',$head='',$breadcrumb='') 
     212     public static function openPopup($title='', $head='') 
    216213     { 
    217214          global $core; 
     
    258255          '<div id="content">'."\n"; 
    259256 
    260           // display breadcrumb if given 
    261           echo $breadcrumb; 
    262  
    263257          if ($core->error->flag()) { 
    264258               echo 
     
    279273     } 
    280274 
    281      public static function breadcrumb($elements=null,$with_home_link=true,$echo=false) 
     275     public static function breadcrumb($elements=null,$no_home_link=false) 
    282276     { 
    283277          // First item of array elements should be blog's name, System or Plugins 
    284           $res = '<h2>'.($with_home_link ? 
    285                '<a class="go_home" href="index.php"><img src="style/dashboard.png" alt="'.__('Go to dashboard').'" /></a>' : 
    286                '<img src="style/dashboard-alt.png" alt="" />'); 
     278          $res = '<h2>'.($no_home_link ? 
     279               '<img src="style/dashboard-alt.png" alt="" />' : 
     280               '<a class="go_home" href="index.php"><img src="style/dashboard.png" alt="'.__('Go to dashboard').'" /></a>'); 
    287281          $index = 0; 
    288282          foreach ($elements as $element => $url) { 
    289                $res .= ($with_home_link ? ($index == 1 ? ' : ' : ' &rsaquo; ') : ($index == 0 ? ' ' : ' &rsaquo; ')). 
    290                     ($url ? '<a href="'.$url.'">' : '').$element.($url ? '</a>' : ''); 
     283               $res .= ($no_home_link ? ' ' : ($index == 1 ? ' : ' : ' &rsaquo; ')).($url ? '<a href="'.$url.'">' : '').$element.($url ? '</a>' : ''); 
    291284               $index++; 
    292285          } 
    293286          $res .= '</h2>'; 
    294           if ($echo) { 
    295                echo $res; 
    296           } 
    297287          return $res; 
    298288     } 
     
    365355     { 
    366356          $args = func_get_args(); 
    367  
    368           $args = new ArrayObject($args); 
    369  
    370           # --BEHAVIOR-- adminPageHelpBlock 
    371           $GLOBALS['core']->callBehavior('adminPageHelpBlock',$args); 
    372  
    373357          if (empty($args)) { 
    374358               return; 
     
    476460          self::jsVar('dotclear.msg.confirm_delete_post', 
    477461               __("Are you sure you want to delete this entry?")). 
    478           self::jsVar('dotclear.msg.click_to_unlock', 
    479                __("Click here to unlock the field")). 
    480462          self::jsVar('dotclear.msg.confirm_spam_delete', 
    481463               __('Are you sure you want to delete all spams?')). 
     
    508490          self::jsVar('dotclear.msg.confirm_delete_theme', 
    509491               __('Are you sure you want to delete "%s" theme?')). 
    510           self::jsVar('dotclear.msg.confirm_delete_backup', 
    511                __('Are you sure you want to delete this backup?')). 
    512492          self::jsVar('dotclear.msg.zip_file_content', 
    513493               __('Zip file content')). 
     
    529509     { 
    530510          return 
    531           '<!--[if lt IE 9]>'."\n". 
    532           self::jsLoad('js/ie7/IE9.js'). 
     511          '<!--[if lt IE 8]>'."\n". 
     512          self::jsLoad('js/ie7/IE8.js'). 
    533513          '<link rel="stylesheet" type="text/css" href="style/iesucks.css" />'."\n". 
    534514          '<![endif]-->'."\n"; 
     
    732712     '<link rel="stylesheet" type="text/css" href="style/jsUpload/style.css" />'."\n". 
    733713 
     714     '<script id="template-upload" type="text/x-tmpl"> 
     715     {% for (var i=0, file; file=o.files[i]; i++) { %} 
     716     <div class="template-upload fade"> 
     717     <div class="upload-file"> 
     718     <div class="upload-fileinfo"> 
     719          <span class="upload-filename">{%=file.name%}</span> 
     720          <span class="upload-filesize">({%=o.formatFileSize(file.size)%})</span> 
     721          <span class="upload-filecancel cancel">'.__('Cancel').'</span> 
     722          {% if (!o.files.error && !i && !o.options.autoUpload) { %} 
     723          <input type="submit" class="button start"  value="'.__('Send').'"/> 
     724          {% } %} 
     725          <span class="upload-filemsg"></span> 
     726     </div> 
     727     {% if (!o.files.error) { %} 
     728     <div class="upload-progress progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div> 
     729     {% } %} 
     730     </div> 
     731     {% } %} 
     732     </script> 
     733     <!-- The template to display files available for download --> 
     734     <script id="template-download" type="text/x-tmpl"> 
     735     {% for (var i=0, file; file=o.files[i]; i++) { %} 
     736     <div class="template-download fade"> 
     737     <div class="upload-file"> 
     738     <div class="upload-fileinfo"> 
     739          <span class="upload-filename">{%=file.name%}</span> 
     740          <span class="upload-filesize">({%=o.formatFileSize(file.size)%})</span> 
     741          <span class="upload-filemsg{% if (file.error) { %} upload-error{% } %}"> 
     742          {% if (file.error) { %} 
     743          '.__('Error:').' {%=file.error%} 
     744          {% } else { %} 
     745          '.__('File successfully uploaded.').' 
     746          {% } %} 
     747          </span> 
     748     </div> 
     749     <div class="upload-progress"> 
     750          {% if (!file.error) { %} 
     751          <div class="bar" style="width:100%;">100%</div> 
     752          {% } %} 
     753     </div> 
     754     </div> 
     755     {% } %} 
     756     </script>'. 
     757 
     758     self::jsLoad('js/jsUpload/vendor/jquery.ui.widget.js'). 
     759     self::jsLoad('js/jsUpload/tmpl.js'). 
     760     self::jsLoad('js/jsUpload/load-image.js'). 
     761     self::jsLoad('js/jsUpload/jquery.iframe-transport.js'). 
     762     self::jsLoad('js/jsUpload/jquery.fileupload.js'). 
     763     self::jsLoad('js/jsUpload/jquery.fileupload-process.js'). 
     764     self::jsLoad('js/jsUpload/jquery.fileupload-resize.js'). 
     765     self::jsLoad('js/jsUpload/jquery.fileupload-ui.js'). 
     766 
    734767     '<script type="text/javascript">'."\n". 
    735768     "//<![CDATA[\n". 
     
    748781     self::jsVar('dotclear.jsUpload.msg.clean',__('Clean')). 
    749782     self::jsVar('dotclear.jsUpload.msg.upload',__('Upload')). 
    750      self::jsVar('dotclear.jsUpload.msg.send',__('Send')). 
    751      self::jsVar('dotclear.jsUpload.msg.file_successfully_uploaded',__('File successfully uploaded.')). 
    752783     self::jsVar('dotclear.jsUpload.msg.no_file_in_queue',__('No file in queue.')). 
    753784     self::jsVar('dotclear.jsUpload.msg.file_in_queue',__('1 file in queue.')). 
     
    756787     self::jsVar('dotclear.jsUpload.base_url',$base_url). 
    757788     "\n//]]>\n". 
    758      "</script>\n". 
    759  
    760      self::jsLoad('js/jsUpload/vendor/jquery.ui.widget.js'). 
    761      self::jsLoad('js/jsUpload/tmpl.js'). 
    762      self::jsLoad('js/jsUpload/template-upload.js'). 
    763      self::jsLoad('js/jsUpload/template-download.js'). 
    764      self::jsLoad('js/jsUpload/load-image.js'). 
    765      self::jsLoad('js/jsUpload/jquery.iframe-transport.js'). 
    766      self::jsLoad('js/jsUpload/jquery.fileupload.js'). 
    767      self::jsLoad('js/jsUpload/jquery.fileupload-process.js'). 
    768      self::jsLoad('js/jsUpload/jquery.fileupload-resize.js'). 
    769      self::jsLoad('js/jsUpload/jquery.fileupload-ui.js'); 
     789     "</script>\n"; 
    770790} 
    771791 
  • inc/admin/prepend.php

    r1337 r1490  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    286286     $_menu['System']->title = __('System settings'); 
    287287     $_menu['Blog']->title = __('Blog'); 
    288      $_menu['Plugins']->title = __('Plugins'); 
     288     $_menu['Plugins']->title = __('Additional plugins'); 
    289289     if (!$user_ui_nofavmenu) 
    290290          $_menu['Favorites']->title = __('My favorites'); 
     
    375375     } 
    376376} 
     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); 
    377386?> 
  • inc/core/class.dc.blog.php

    r1468 r1492  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    8181               $this->desc = $b->blog_desc; 
    8282               $this->url = $b->blog_url; 
    83                $this->host = http::getHostFromURL($this->url); 
     83               $this->host = preg_replace('|^([a-z]{3,}://)(.*?)/.*$|','$1$2',$this->url); 
    8484               $this->creadt = strtotime($b->blog_creadt); 
    8585               $this->upddt = strtotime($b->blog_upddt); 
     
    842842           
    843843          if (!empty($params['user_id'])) { 
    844                $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
     844               $strReq .= "AND U.user_id ".$this->con->in($params['user_id'])." "; 
    845845          } 
    846846           
     
    926926                    $strReq .= 'ORDER BY post_dt DESC '; 
    927927               } 
    928           } 
    929            
    930           if (!$count_only && !empty($params['limit'])) { 
    931                $strReq .= $this->con->limit($params['limit']); 
     928               if (!empty($params['limit'])) { 
     929                    $strReq .= $this->con->limit($params['limit']); 
     930               } 
    932931          } 
    933932           
  • inc/core/class.dc.core.php

    r1179 r1315  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    3939     public $rest;       ///< <b>dcRestServer</b> dcRestServer object 
    4040     public $log;        ///< <b>dcLog</b>             dcLog object 
     41     public $tpl;        ///< <b>Twig_Environment</b>  Twig_Environment object 
    4142      
    4243     private $versions = null; 
     
    9596          $this->addFormater('xhtml', create_function('$s','return $s;')); 
    9697          $this->addFormater('wiki', array($this,'wikiTransform')); 
     98          $this->loadTemplateEnvironment(); 
    9799     } 
    98100      
     
    118120     } 
    119121      
     122     /** 
     123     Create template environment (Twig_Environment instance) 
     124      
     125     default-templates path must be added from admin|public/prepend.php with: 
     126     $core->tpl->getLoader()->addPath('PATH_TO/default-templates'); 
     127     Selected theme path must be added with: 
     128     $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 
     129     */ 
     130     public function loadTemplateEnvironment() 
     131     { 
     132          $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 
     133          if (!is_dir($cache_dir)) { 
     134               try { 
     135                    files::makeDir($cache_dir); 
     136               } catch (Exception $e) { 
     137                    $cache_dir = false; 
     138               } 
     139          } 
     140           
     141          $this->tpl = new Twig_Environment( 
     142               new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'), 
     143               array( 
     144                    'auto_reload' => true, 
     145                    'autoescape' => false, 
     146                    'base_template_class' => 'Twig_Template', 
     147                    'cache' => $cache_dir,  
     148                    'charset' => 'UTF-8', 
     149                    'debug' => DC_DEBUG, 
     150                    'optimizations' => -1, 
     151                    'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables! 
     152               ) 
     153          ); 
     154          $this->tpl->addExtension(new dcFormExtension($this)); 
     155          $this->tpl->addExtension(new dcTabExtension($this)); 
     156     } 
    120157      
    121158     /// @name Blog init methods 
  • inc/prepend.php

    r1468 r1492  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212 
    1313/* ------------------------------------------------------------------------------------------- */ 
    14 #  ClearBricks, DotClear classes auto-loader 
     14#  ClearBricks, Twig, DotClear classes auto-loader 
    1515if (@is_dir('/usr/lib/clearbricks')) { 
    1616     define('CLEARBRICKS_PATH','/usr/lib/clearbricks'); 
     
    4646$__autoload['dcWorkspace']              = dirname(__FILE__).'/core/class.dc.workspace.php'; 
    4747$__autoload['dcPrefs']                  = dirname(__FILE__).'/core/class.dc.prefs.php'; 
     48$__autoload['dcTwigPage']               = dirname(__FILE__).'/core/class.dc.twig.page.php'; 
    4849 
    4950$__autoload['rsExtPost']                = dirname(__FILE__).'/core/class.dc.rs.extensions.php'; 
     
    5253$__autoload['rsExtUser']                = dirname(__FILE__).'/core/class.dc.rs.extensions.php'; 
    5354 
     55$__autoload['dcAdminContext']                = dirname(__FILE__).'/admin/class.dc.admincontext.php'; 
    5456$__autoload['dcMenu']                   = dirname(__FILE__).'/admin/class.dc.menu.php'; 
    5557$__autoload['dcPage']                   = dirname(__FILE__).'/admin/lib.dc.page.php'; 
     
    6365$__autoload['context']                  = dirname(__FILE__).'/public/lib.tpl.context.php'; 
    6466$__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'; 
     70$__autoload['dcItemList']               = dirname(__FILE__).'/admin/class.dc.list.php'; 
     71$__autoload['dcListFetcher']            = dirname(__FILE__).'/admin/class.dc.list.php'; 
     72 
     73foreach (array('dcFilterSet', 'dcFilter','dcFilterCombo','dcFilterText','dcFilterBoolean') as $c) { 
     74     $__autoload[$c] = dirname(__FILE__).'/admin/class.dc.filter.php'; 
     75} 
    6576 
    6677# Clearbricks extensions 
    6778html::$absolute_regs[] = '/(<param\s+name="movie"\s+value=")(.*?)(")/msu'; 
    6879html::$absolute_regs[] = '/(<param\s+name="FlashVars"\s+value=".*?(?:mp3|flv)=)(.*?)(&|")/msu'; 
     80 
     81if (@is_dir('/usr/lib/twig')) { 
     82     define('TWIG_PATH','/usr/lib/Twig'); 
     83} elseif (is_dir(dirname(__FILE__).'/libs/Twig')) { 
     84     define('TWIG_PATH',dirname(__FILE__).'/libs/Twig'); 
     85} elseif (isset($_SERVER['TWIG_PATH']) && is_dir($_SERVER['TWIG_PATH'])) { 
     86     define('TWIG_PATH',$_SERVER['TWIG_PATH']); 
     87} 
     88 
     89if (!defined('TWIG_PATH') || !is_dir(TWIG_PATH)) { 
     90     exit('No Twig path defined'); 
     91} 
     92require TWIG_PATH.'/Autoloader.php'; 
     93Twig_Autoloader::register(); 
     94 
    6995/* ------------------------------------------------------------------------------------------- */ 
    7096 
     
    123149# Constants 
    124150define('DC_ROOT',path::real(dirname(__FILE__).'/..')); 
    125 define('DC_VERSION','2.6-dev'); 
     151define('DC_VERSION','2.99-dev'); 
    126152define('DC_DIGESTS',dirname(__FILE__).'/digests'); 
    127153define('DC_L10N_ROOT',dirname(__FILE__).'/../locales'); 
  • plugins/aboutConfig/_admin.php

    r1294 r1315  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_CONTEXT_ADMIN')) { return; } 
    1313 
    14 $_menu['System']->addItem('about:config','plugin.php?p=aboutConfig','index.php?pf=aboutConfig/icon.png', 
     14$_menu['Plugins']->addItem('about:config','plugin.php?p=aboutConfig','index.php?pf=aboutConfig/icon.png', 
    1515          preg_match('/plugin.php\?p=aboutConfig(&.*)?$/',$_SERVER['REQUEST_URI']), 
    1616          $core->auth->isSuperAdmin()); 
     17 
     18$core->tpl->getLoader()->addPath(dirname(__FILE__).'/admtpl/','aboutConfig'); 
    1719?> 
  • plugins/aboutConfig/index.php

    r1474 r1492  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_CONTEXT_ADMIN')) { return; } 
    1313 
    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'])) 
     14class adminPageAboutConfig 
    2615{ 
    27      try 
     16     public static $p_url = 'plugin.php?p=aboutConfig'; 
     17      
     18     # Update local settings 
     19     public static function updLocal($form) 
    2820     { 
    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(); 
    3254                
    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; 
    3873          } 
    3974           
    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(); 
    45128     } 
    46129} 
    47130 
    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 
     132adminPageAboutConfig::setForms(); 
     133 
     134# Global settings forms 
     135adminPageAboutConfig::setForms(true); 
     136 
     137# Commons 
     138if (!empty($_GET['upd'])) { 
     139     $_ctx->setAlert(__('Configuration successfully updated')); 
    70140} 
    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'] ? 1 : 0); 
    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 class="line">'. 
    88      '<td scope="row"><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>'; 
     141if (!empty($_GET['upda'])) { 
     142     $_ctx->setAlert(__('Settings definition successfully updated')); 
    93143} 
     144$_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 
     145$_ctx->setBreadCrumb('about:config'); 
     146$core->tpl->display('@aboutConfig/index.html.twig'); 
    94147?> 
    95 <html> 
    96 <head> 
    97   <title>about:config</title> 
    98   <?php echo dcPage::jsPageTabs($part); ?> 
    99   <script type="text/javascript"> 
    100      //<![CDATA[ 
    101      $(function() { 
    102           $("#gs_submit").hide(); 
    103           $("#ls_submit").hide(); 
    104           $("#gs_nav").change(function() { 
    105                window.location = $("#gs_nav option:selected").val(); 
    106           }) 
    107           $("#ls_nav").change(function() { 
    108                window.location = $("#ls_nav option:selected").val(); 
    109           }) 
    110      }); 
    111      //]]> 
    112      </script> 
    113 </head> 
    114  
    115 <body> 
    116 <?php 
    117 echo dcPage::breadcrumb( 
    118      array( 
    119           __('System') => '', 
    120           html::escapeHTML($core->blog->name) => '', 
    121           '<span class="page-title">'.__('about:config').'</span>' => '' 
    122      )); 
    123 if (!empty($_GET['upd'])) { 
    124      dcPage::message(__('Configuration successfully updated')); 
    125 } 
    126  
    127 if (!empty($_GET['upda'])) { 
    128      dcPage::message(__('Settings definition successfully updated')); 
    129 } 
    130 ?> 
    131  
    132 <div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>"> 
    133  
    134  
    135 <?php 
    136 $table_header = '<table class="settings" id="%s"><caption class="as_h3">%s</caption>'. 
    137 '<thead>'. 
    138 '<tr>'."\n". 
    139 '  <th class="nowrap">Setting ID</th>'."\n". 
    140 '  <th>'.__('Value').'</th>'."\n". 
    141 '  <th>'.__('Type').'</th>'."\n". 
    142 '  <th class="maximalx">'.__('Description').'</th>'."\n". 
    143 '</tr>'."\n". 
    144 '</thead>'."\n". 
    145 '<tbody>'; 
    146 $table_footer = '</tbody></table>'; 
    147  
    148 $settings = array(); 
    149 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    150      foreach ($namespace->dumpSettings() as $k => $v) { 
    151           $settings[$ns][$k] = $v; 
    152      } 
    153 } 
    154 ksort($settings); 
    155 if (count($settings) > 0) { 
    156      $ns_combo = array(); 
    157      foreach ($settings as $ns => $s) { 
    158           $ns_combo[$ns] = '#l_'.$ns; 
    159      } 
    160      echo  
    161           '<form action="plugin.php" method="post">'. 
    162           '<p class="anchor-nav">'. 
    163           '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo). 
    164           ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'. 
    165           '<input type="hidden" name="p" value="aboutConfig" />'. 
    166           $core->formNonce().'</p></form>'; 
    167 } 
    168 ?> 
    169  
    170 <form action="plugin.php" method="post"> 
    171  
    172 <?php 
    173 foreach ($settings as $ns => $s) 
    174 { 
    175      ksort($s); 
    176      echo sprintf($table_header,'l_'.$ns,$ns); 
    177      foreach ($s as $k => $v) 
    178      { 
    179           echo settingLine($k,$v,$ns,'s',!$v['global']); 
    180      } 
    181      echo $table_footer; 
    182 } 
    183 ?> 
    184  
    185 <p><input type="submit" value="<?php echo __('Save'); ?>" /> 
    186 <input type="hidden" name="p" value="aboutConfig" /> 
    187 <?php echo $core->formNonce(); ?></p> 
    188 </form> 
    189 </div> 
    190  
    191 <div id="global" class="multi-part" title="<?php echo __('global settings'); ?>"> 
    192  
    193 <?php 
    194 $settings = array(); 
    195  
    196 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    197      foreach ($namespace->dumpGlobalSettings() as $k => $v) { 
    198           $settings[$ns][$k] = $v; 
    199      } 
    200 } 
    201  
    202 ksort($settings); 
    203  
    204 if (count($settings) > 0) { 
    205      $ns_combo = array(); 
    206      foreach ($settings as $ns => $s) { 
    207           $ns_combo[$ns] = '#g_'.$ns; 
    208      } 
    209      echo  
    210           '<form action="plugin.php" method="post">'. 
    211           '<p class="anchor-nav">'. 
    212           '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo). 
    213           ' <input type="submit" value="'.__('Ok').'" id="gs_submit" />'. 
    214           '<input type="hidden" name="p" value="aboutConfig" />'. 
    215           $core->formNonce().'</p></form>'; 
    216 } 
    217 ?> 
    218  
    219 <form action="plugin.php" method="post"> 
    220  
    221 <?php 
    222 foreach ($settings as $ns => $s) 
    223 { 
    224      ksort($s); 
    225      echo sprintf($table_header,'g_'.$ns,$ns); 
    226      foreach ($s as $k => $v) 
    227      { 
    228           echo settingLine($k,$v,$ns,'gs',false); 
    229      } 
    230      echo $table_footer; 
    231 } 
    232 ?> 
    233  
    234 <p><input type="submit" value="<?php echo __('Save'); ?>" /> 
    235 <input type="hidden" name="p" value="aboutConfig" /> 
    236 <?php echo $core->formNonce(); ?></p> 
    237 </form> 
    238 </div> 
    239  
    240 </body> 
    241 </html> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map