Dotclear


Ignore:
Files:
375 added
13 edited

Legend:

Unmodified
Added
Removed
  • admin/auth.php

    r2311 r2313  
    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 { 
    27      l10n::lang($dlang); 
     24if ($dlang != 'en' && preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$dlang)) { 
    2825     l10n::set(dirname(__FILE__).'/../locales/'.$dlang.'/main'); 
    2926} 
    30  
    31 $page_url = http::getHost().$_SERVER['REQUEST_URI']; 
    32  
    33 $change_pwd = $core->auth->allowPassChange() && isset($_POST['new_pwd']) && isset($_POST['new_pwd_c']) && isset($_POST['login_data']); 
    34 $login_data = !empty($_POST['login_data']) ? html::escapeHTML($_POST['login_data']) : null; 
    35 $recover = $core->auth->allowPassChange() && !empty($_REQUEST['recover']); 
    36 $safe_mode = !empty($_REQUEST['safe_mode']); 
    37 $akey = $core->auth->allowPassChange() && !empty($_GET['akey']) ? $_GET['akey'] : null; 
    38 $user_id = $user_pwd = $user_key = $user_email = null; 
    39 $err = $msg = null; 
    4027 
    4128# Auto upgrade 
     
    4431     try { 
    4532          if (($changes = dotclearUpgrade($core)) !== false) { 
    46                $msg = __('Dotclear has been upgraded.').'<!-- '.$changes.' -->'; 
    47           } 
    48      } catch (Exception $e) { 
    49           $err = $e->getMessage(); 
    50      } 
    51 } 
    52  
    53 # If we have POST login informations, go throug auth process 
    54 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 
    5545{ 
    56      $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; 
    57      $user_pwd = !empty($_POST['user_pwd']) ? $_POST['user_pwd'] : null; 
    58 } 
    59 # If we have COOKIE login informations, go throug auth process 
    60 elseif (isset($_COOKIE['dc_admin']) && strlen($_COOKIE['dc_admin']) == 104) 
    61 { 
     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               "maxlength" => 32))) 
     269     ->addField( 
     270          new dcFieldPassword('user_pwd','',array( 
     271               "label" => __('Password:')))) 
     272     ->addField( 
     273          new dcFieldText('user_email','',array( 
     274               "label" => __('Email:')))) 
     275     ->addField( 
     276          new dcFieldPassword('new_pwd','',array( 
     277               "label" => __('New password:')))) 
     278     ->addField( 
     279          new dcFieldPassword('new_pwd_c','',array( 
     280               "label" => __('Confirm password:')))) 
     281     ->addField( 
     282          new dcFieldCheckbox ('user_remember',1,array( 
     283               "label" => __('Remember my ID on this computer')))) 
     284     ->addField( 
     285          new dcFieldSubmit('auth_login',__('log in'),array( 
     286               'action' => array('adminPageAuth','login')))) 
     287     ->addField( 
     288          new dcFieldSubmit('auth_recover',__('recover'),array( 
     289               'action' => array('adminPageAuth','recover')))) 
     290     ->addField( 
     291          new dcFieldSubmit('auth_change',__('change'),array( 
     292               'action' => array('adminPageAuth','change')))) 
     293     ->addField( 
     294          new dcFieldHidden ('safe_mode','0')) 
     295     ->addField( 
     296          new dcFieldHidden ('recover','0')) 
     297     ->addField( 
     298          new dcFieldHidden ('login_data','')) 
     299     ->addField( 
     300          new dcFieldHidden ('blog','')); 
     301 
     302# Context variables 
     303$_ctx->allow_pass_change = $core->auth->allowPassChange(); 
     304$_ctx->change_pwd = $core->auth->allowPassChange() && $form->new_pwd != '' && $form->new_pwd_c != '' && $form->login_data != ''; 
     305$_ctx->recover = $form->recover = $core->auth->allowPassChange() && !empty($_REQUEST['recover']); 
     306$_ctx->setSafeMode(!empty($_REQUEST['safe_mode']));  
     307$form->safe_mode = !empty($_REQUEST['safe_mode']); 
     308$_ctx->akey = false; 
     309$_ctx->dlang = $dlang; 
     310 
     311# If we have no POST login informations and have COOKIE login informations, go throug auth process 
     312if ($form->user_id == '' && $form->user_pwd == ''  
     313 && isset($_COOKIE['dc_admin']) && strlen($_COOKIE['dc_admin']) == 104) { 
     314 
    62315     # If we have a remember cookie, go through auth process with user_key 
    63316     $user_id = substr($_COOKIE['dc_admin'],40); 
    64317     $user_id = @unpack('a32',@pack('H*',$user_id)); 
    65      if (is_array($user_id)) 
    66      { 
     318      
     319     if (is_array($user_id)) { 
    67320          $user_id = $user_id[1]; 
    68321          $user_key = substr($_COOKIE['dc_admin'],0,40); 
    69           $user_pwd = null; 
    70      } 
    71      else 
    72      { 
    73           $user_id = null; 
    74      } 
    75 } 
    76  
    77 # Recover password 
    78 if ($recover && !empty($_POST['user_id']) && !empty($_POST['user_email'])) 
    79 { 
    80      $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; 
    81      $user_email = !empty($_POST['user_email']) ? $_POST['user_email'] : ''; 
    82      try 
    83      { 
    84           $recover_key = $core->auth->setRecoverKey($user_id,$user_email); 
    85            
    86           $subject = mail::B64Header('DotClear '.__('Password reset')); 
    87           $message = 
    88           __('Someone has requested to reset the password for the following site and username.')."\n\n". 
    89           $page_url."\n".__('Username:').' '.$user_id."\n\n". 
    90           __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.')."\n". 
    91           $page_url.'?akey='.$recover_key; 
    92            
    93           $headers[] = 'From: '.(defined('DC_ADMIN_MAILFROM') && DC_ADMIN_MAILFROM ? DC_ADMIN_MAILFROM : 'dotclear@local'); 
    94           $headers[] = 'Content-Type: text/plain; charset=UTF-8;'; 
    95            
    96           mail::sendMail($user_email,$subject,$message,$headers); 
    97           $msg = sprintf(__('The e-mail was sent successfully to %s.'),$user_email); 
    98      } 
    99      catch (Exception $e) 
    100      { 
    101           $err = $e->getMessage(); 
    102      } 
    103 } 
    104 # Send new password 
    105 elseif ($akey) 
    106 { 
    107      try 
    108      { 
    109           $recover_res = $core->auth->recoverUserPassword($akey); 
    110            
    111           $subject = mb_encode_mimeheader('DotClear '.__('Your new password'),'UTF-8','B'); 
    112           $message = 
    113           __('Username:').' '.$recover_res['user_id']."\n". 
    114           __('Password:').' '.$recover_res['new_pass']."\n\n". 
    115           preg_replace('/\?(.*)$/','',$page_url); 
    116            
    117           $headers[] = 'From: dotclear@'.$_SERVER['HTTP_HOST']; 
    118           $headers[] = 'Content-Type: text/plain; charset=UTF-8;'; 
    119            
    120           mail::sendMail($recover_res['user_email'],$subject,$message,$headers); 
    121           $msg = __('Your new password is in your mailbox.'); 
    122      } 
    123      catch (Exception $e) 
    124      { 
    125           $err = $e->getMessage(); 
    126      } 
    127 } 
    128 # Change password and retry to log 
    129 elseif ($change_pwd) 
    130 { 
    131      try 
    132      { 
    133           $tmp_data = explode('/',$_POST['login_data']); 
    134           if (count($tmp_data) != 3) { 
    135                throw new Exception(); 
    136           } 
    137           $data = array( 
    138                'user_id'=>base64_decode($tmp_data[0]), 
    139                'cookie_admin'=>$tmp_data[1], 
    140                'user_remember'=>$tmp_data[2]=='1' 
    141           ); 
    142           if ($data['user_id'] === false) { 
    143                throw new Exception(); 
    144           } 
    145            
    146      # Check login informations 
    147      $check_user = false; 
    148      if (isset($data['cookie_admin']) && strlen($data['cookie_admin']) == 104) 
    149      { 
    150           $user_id = substr($data['cookie_admin'],40); 
    151           $user_id = @unpack('a32',@pack('H*',$user_id)); 
    152           if (is_array($user_id)) 
    153           { 
    154                $user_id = $user_id[1]; 
    155                $user_key = substr($data['cookie_admin'],0,40); 
    156                $check_user = $core->auth->checkUser($user_id,null,$user_key) === true; 
    157           } 
    158      } 
    159       
    160           if (!$core->auth->allowPassChange() || !$check_user) { 
    161                $change_pwd = false; 
    162                throw new Exception(); 
    163           } 
    164            
    165           if ($_POST['new_pwd'] != $_POST['new_pwd_c']) { 
    166                throw new Exception(__("Passwords don't match")); 
    167           } 
    168            
    169           if ($core->auth->checkUser($user_id,$_POST['new_pwd']) === true) { 
    170                throw new Exception(__("You didn't change your password.")); 
    171           } 
    172            
    173           $cur = $core->con->openCursor($core->prefix.'user'); 
    174           $cur->user_change_pwd = 0; 
    175           $cur->user_pwd = $_POST['new_pwd']; 
    176           $core->updUser($core->auth->userID(),$cur); 
    177            
    178           $core->session->start(); 
    179           $_SESSION['sess_user_id'] = $user_id; 
    180           $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 
    181            
    182           if ($data['user_remember']) 
    183           { 
    184                setcookie('dc_admin',$data['cookie_admin'],strtotime('+15 days'),'','',DC_ADMIN_SSL); 
    185           } 
    186            
    187           http::redirect('index.php'); 
    188      } 
    189      catch (Exception $e) 
    190      { 
    191           $err = $e->getMessage(); 
    192      } 
    193 } 
    194 # Try to log 
    195 elseif ($user_id !== null && ($user_pwd !== null || $user_key !== null)) 
    196 { 
    197      # We check the user 
    198      $check_user = $core->auth->checkUser($user_id,$user_pwd,$user_key,false) === true; 
    199      if ($check_user) { 
    200           $check_perms = $core->auth->findUserBlog() !== false; 
    201      } else { 
    202           $check_perms = false; 
    203      } 
    204       
    205      $cookie_admin = http::browserUID(DC_MASTER_KEY.$user_id. 
    206           crypt::hmac(DC_MASTER_KEY,$user_pwd)).bin2hex(pack('a32',$user_id)); 
    207       
    208      if ($check_perms && $core->auth->mustChangePassword()) 
    209      { 
    210           $login_data = join('/',array( 
    211                base64_encode($user_id), 
    212                $cookie_admin, 
    213                empty($_POST['user_remember'])?'0':'1' 
    214           )); 
    215            
    216           if (!$core->auth->allowPassChange()) { 
    217                $err = __('You have to change your password before you can login.'); 
    218           } else { 
    219                $err = __('In order to login, you have to change your password now.'); 
    220                $change_pwd = true; 
    221           } 
    222      } 
    223      elseif ($check_perms && !empty($_POST['safe_mode']) && !$core->auth->isSuperAdmin())  
    224      { 
    225           $err = __('Safe Mode can only be used for super administrators.'); 
    226      } 
    227      elseif ($check_perms) 
    228      { 
    229           $core->session->start(); 
    230           $_SESSION['sess_user_id'] = $user_id; 
    231           $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 
    232            
    233           if (!empty($_POST['blog'])) { 
    234                $_SESSION['sess_blog_id'] = $_POST['blog']; 
    235           } 
    236            
    237           if (!empty($_POST['safe_mode']) && $core->auth->isSuperAdmin()) { 
    238                $_SESSION['sess_safe_mode'] = true; 
    239           } 
    240            
    241           if (!empty($_POST['user_remember'])) { 
    242                setcookie('dc_admin',$cookie_admin,strtotime('+15 days'),'','',DC_ADMIN_SSL); 
    243           } 
    244            
    245           http::redirect('index.php'); 
    246      } 
    247      else 
    248      { 
    249           if (isset($_COOKIE['dc_admin'])) { 
    250                unset($_COOKIE['dc_admin']); 
    251                setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL); 
    252           } 
    253           if ($check_user) { 
    254                $err = __('Insufficient permissions'); 
    255           } else { 
    256                $err = __('Wrong username or password'); 
    257           } 
    258      } 
     322          $user_pwd = ''; 
     323           
     324          adminPageAuth::process($form,$user_id,$user_pwd,$user_key); 
     325     } 
     326} 
     327# If we have an akey, go throug send password process 
     328elseif ($core->auth->allowPassChange() && !empty($_GET['akey'])) { 
     329     adminPageAuth::send($_GET['akey']); 
    259330} 
    260331 
    261332if (isset($_GET['user'])) { 
    262      $user_id = $_GET['user']; 
    263 } 
    264  
    265 header('Content-Type: text/html; charset=UTF-8'); 
     333     $form->user_id = $_GET['user']; 
     334} 
     335 
     336$form->setup(); 
     337 
     338$core->tpl->display('auth.html.twig'); 
    266339?> 
    267 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    268 <html xmlns="http://www.w3.org/1999/xhtml" 
    269 xml:lang="<?php echo $dlang; ?>" lang="<?php echo $dlang; ?>"> 
    270 <head> 
    271   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    272   <meta http-equiv="Content-Script-Type" content="text/javascript" /> 
    273   <meta http-equiv="Content-Style-Type" content="text/css" /> 
    274   <meta http-equiv="Content-Language" content="<?php echo $dlang; ?>" /> 
    275   <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" /> 
    276   <meta name="GOOGLEBOT" content="NOSNIPPET" /> 
    277   <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    278   <title><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></title> 
    279   <link rel="icon" type="image/png" href="images/favicon96-logout.png" /> 
    280   <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> 
    281  
    282    
    283 <?php 
    284 echo dcPage::jsLoadIE7(); 
    285 echo dcPage::jsCommon(); 
    286 ?> 
    287    
    288      <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" /> 
    289        
    290   <?php 
    291   # --BEHAVIOR-- loginPageHTMLHead 
    292   $core->callBehavior('loginPageHTMLHead'); 
    293   ?> 
    294    
    295   <script type="text/javascript"> 
    296   //<![CDATA[ 
    297   $(window).load(function() { 
    298     var uid = $('input[name=user_id]'); 
    299     var upw = $('input[name=user_pwd]'); 
    300     uid.focus(); 
    301      
    302     if (upw.length == 0) { return; } 
    303      
    304     uid.keypress(processKey); 
    305  
    306     function processKey(evt) { 
    307       if (evt.which == 13 && upw.val() == '') { 
    308          upw.focus(); 
    309          return false; 
    310       } 
    311       return true; 
    312     }; 
    313     $.cookie('dc_admin_test_cookie',true); 
    314     if ($.cookie('dc_admin_test_cookie')) { 
    315       $('#cookie_help').hide(); 
    316       $.cookie('dc_admin_test_cookie', '', {'expires': -1}); 
    317     } else { 
    318       $('#cookie_help').show(); 
    319     } 
    320     $('#issue #more').toggleWithLegend($('#issue').children().not('#more')); 
    321   }); 
    322   //]]> 
    323   </script> 
    324 </head> 
    325  
    326 <body id="dotclear-admin" class="auth"> 
    327  
    328 <form action="auth.php" method="post" id="login-screen"> 
    329 <h1><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></h1> 
    330  
    331 <?php 
    332 if ($err) { 
    333      echo '<div class="error">'.$err.'</div>'; 
    334 } 
    335 if ($msg) { 
    336      echo '<p class="success">'.$msg.'</p>'; 
    337 } 
    338  
    339 if ($akey) 
    340 { 
    341      echo '<p><a href="auth.php">'.__('Back to login screen').'</a></p>'; 
    342 } 
    343 elseif ($recover) 
    344 { 
    345      echo 
    346      '<div class="fieldset"><h2>'.__('Request a new password').'</h2>'. 
    347      '<p><label for="user_id">'.__('Username:').'</label> '. 
    348      form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id)).'</p>'. 
    349       
    350      '<p><label for="user_email">'.__('Email:').'</label> '. 
    351      form::field(array('user_email','user_email'),20,255,html::escapeHTML($user_email)).'</p>'. 
    352       
    353      '<p><input type="submit" value="'.__('recover').'" />'. 
    354      form::hidden(array('recover'),1).'</p>'. 
    355      '</div>'. 
    356       
    357      '<div id="issue">'. 
    358      '<p><a href="auth.php">'.__('Back to login screen').'</a></p>'. 
    359      '</div>'; 
    360 } 
    361 elseif ($change_pwd) 
    362 { 
    363      echo 
    364      '<div class="fieldset"><h2>'.__('Change your password').'</h2>'. 
    365      '<p><label for="new_pwd">'.__('New password:').'</label> '. 
    366      form::password(array('new_pwd','new_pwd'),20,255).'</p>'. 
    367       
    368      '<p><label for="new_pwd_c">'.__('Confirm password:').'</label> '. 
    369      form::password(array('new_pwd_c','new_pwd_c'),20,255).'</p>'. 
    370      '</div>'. 
    371       
    372      '<p><input type="submit" value="'.__('change').'" />'. 
    373      form::hidden('login_data',$login_data).'</p>'; 
    374 } 
    375 else 
    376 { 
    377      if (is_callable(array($core->auth,'authForm'))) 
    378      { 
    379           echo $core->auth->authForm($user_id); 
    380      } 
    381      else 
    382      { 
    383           if ($safe_mode) { 
    384                echo '<div class="fieldset">'; 
    385                echo '<h2>'.__('Safe mode login').'</h2>'; 
    386                echo  
    387                     '<p class="form-note">'. 
    388                     __('This mode allows you to login without activating any of your plugins. This may be useful to solve compatibility problems').'&nbsp;</p>'. 
    389                     '<p class="form-note">'.__('Disable or delete any plugin suspected to cause trouble, then log out and log back in normally.'). 
    390                     '</p>'; 
    391           } 
    392           else { 
    393                echo '<div class="fieldset">'; 
    394           } 
    395  
    396           echo 
    397           '<p><label for="user_id">'.__('Username:').'</label> '. 
    398           form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id)).'</p>'. 
    399            
    400           '<p><label for="user_pwd">'.__('Password:').'</label> '. 
    401           form::password(array('user_pwd','user_pwd'),20,255).'</p>'. 
    402            
    403           '<p>'. 
    404           form::checkbox(array('user_remember','user_remember'),1). 
    405           '<label for="user_remember" class="classic">'. 
    406           __('Remember my ID on this computer').'</label></p>'. 
    407            
    408           '<p><input type="submit" value="'.__('log in').'" class="login" /></p>'; 
    409            
    410           if (!empty($_REQUEST['blog'])) { 
    411                echo form::hidden('blog',html::escapeHTML($_REQUEST['blog'])); 
    412           } 
    413           if($safe_mode) { 
    414                echo  
    415                form::hidden('safe_mode',1). 
    416                '</div>'; 
    417           } 
    418           else { 
    419                echo '</div>'; 
    420           } 
    421           echo 
    422           '<p id="cookie_help" class="error">'.__('You must accept cookies in order to use the private area.').'</p>'; 
    423  
    424           echo '<div id="issue">'; 
    425            
    426           if ($safe_mode) { 
    427                echo 
    428                '<p><a href="auth.php" id="normal_mode_link">'.__('Get back to normal authentication').'</a></p>'; 
    429           } else { 
    430                echo '<p id="more"><strong>'.__('Connection issue?').'</strong></p>'; 
    431                if ($core->auth->allowPassChange()) { 
    432                     echo '<p><a href="auth.php?recover=1">'.__('I forgot my password').'</a></p>'; 
    433                } 
    434                echo '<p><a href="auth.php?safe_mode=1" id="safe_mode_link">'.__('I want to log in in safe mode').'</a></p>'; 
    435           } 
    436            
    437           echo '</div>'; 
    438      } 
    439 } 
    440 ?> 
    441 </form> 
    442 </body> 
    443 </html> 
  • admin/index.php

    r2240 r2313  
    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} 
    59 if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) { 
    60      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'); 
    64 } 
    65  
    66 // Handle folded/unfolded sections in admin from user preferences 
    67 $ws = $core->auth->user_prefs->addWorkspace('toggles'); 
    68 if (!$core->auth->user_prefs->toggles->prefExists('unfolded_sections')) { 
    69      $core->auth->user_prefs->toggles->put('unfolded_sections','','string','Folded sections in admin',null,true); 
    70 } 
    71  
    72  
    73 # Dashboard icons 
    74 $__dashboard_icons = new ArrayObject(); 
    75  
    76 $favs = $core->favs->getUserFavorites(); 
    77 $core->favs->appendDashboardIcons($__dashboard_icons); 
    78  
    79 # Check plugins and themes update from repository 
    80 function dc_check_store_update($mod, $url, $img, $icon) 
    81 { 
    82      $repo = new dcStore($mod, $url); 
    83      $upd = $repo->get(true); 
    84      if (!empty($upd)) { 
    85           $icon[0] .= '<br />'.sprintf(__('An update is available', '%s updates are available.', count($upd)),count($upd)); 
    86           $icon[1] .= '#update'; 
    87           $icon[2] = 'images/menu/'.$img.'-b-update.png'; 
    88      } 
    89 } 
    90 if (isset($__dashboard_icons['plugins'])) { 
    91      dc_check_store_update($core->plugins, $core->blog->settings->system->store_plugin_url, 'plugins', $__dashboard_icons['plugins']); 
    92 } 
    93 if (isset($__dashboard_icons['blog_theme'])) { 
    94      $themes = new dcThemes($core); 
    95      $themes->loadModules($core->blog->themes_path, null); 
    96      dc_check_store_update($themes, $core->blog->settings->system->store_theme_url, 'blog-theme', $__dashboard_icons['blog_theme']); 
    97 } 
    98  
    99 # Latest news for dashboard 
    100 $__dashboard_items = new ArrayObject(array(new ArrayObject(),new ArrayObject())); 
    101  
    102 $dashboardItem = 0; 
    103  
    104 if ($core->auth->user_prefs->dashboard->dcnews) { 
     101 
     102# Send dcnews to templates 
     103$_ctx->dashboard_dcnews = array(); 
     104if ($core->auth->user_prefs->dashboard->dcnews && !empty($__resources['rss_news'])) { 
    105105     try 
    106106     { 
    107           if (empty($__resources['rss_news'])) { 
    108                throw new Exception(); 
    109           } 
    110       
    111107          $feed_reader = new feedReader; 
    112108          $feed_reader->setCacheDir(DC_TPL_CACHE); 
     
    114110          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); 
    115111          $feed = $feed_reader->parse($__resources['rss_news']); 
    116           if ($feed) 
    117           { 
    118                $latest_news = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">'; 
     112          if ($feed) { 
     113               $items = array(); 
    119114               $i = 1; 
    120                foreach ($feed->items as $item) 
    121                { 
    122                     $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'. 
    123                          $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title; 
    124                 
    125                     if ($i < 3) { 
    126                          $latest_news .= 
    127                          '<dt>'.$dt.'</dt>'. 
    128                          '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '. 
    129                          '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>'; 
    130                     } else { 
    131                          $latest_news .= 
    132                          '<dt>'.$dt.'</dt>'. 
    133                          '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>'; 
    134                     } 
     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                    ); 
    135122                    $i++; 
    136                     if ($i > 2) { break; } 
     123                    if ($i > 3) { break; } 
    137124               } 
    138                $latest_news .= '</dl></div>'; 
    139                $__dashboard_items[$dashboardItem][] = $latest_news; 
    140                $dashboardItem++; 
     125               $_ctx->dashboard_dcnews = $items; 
    141126          } 
    142127     } 
     
    144129} 
    145130 
    146 # Documentation links 
    147 if ($core->auth->user_prefs->dashboard->doclinks) { 
    148      if (!empty($__resources['doc'])) 
    149      { 
    150           $doc_links = '<div class="box small dc-box"><h3>'.__('Documentation and support').'</h3><ul>'; 
     131# Quick entry prefs 
     132if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) { 
     133     if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) { 
     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) { } 
    151153      
    152           foreach ($__resources['doc'] as $k => $v) { 
    153                $doc_links .= '<li><a class="outgoing" href="'.$v.'" title="'.$k.'">'.$k. 
    154                ' <img src="images/outgoing-blue.png" alt="" /></a></li>'; 
    155           } 
     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     } 
    156186      
    157           $doc_links .= '</ul></div>'; 
    158           $__dashboard_items[$dashboardItem][] = $doc_links; 
    159           $dashboardItem++; 
    160      } 
    161 } 
    162  
     187     $_ctx->dashboard_quickentry = true; 
     188} 
     189 
     190# Dashboard icons 
     191$__dashboard_icons = new ArrayObject(); 
     192 
     193# Dashboard favorites 
     194$post_count = $core->blog->getPosts(array(),true)->f(0); 
     195$str_entries = ($post_count > 1) ? __('%d entries') : __('%d entry'); 
     196 
     197$comment_count = $core->blog->getComments(array(),true)->f(0); 
     198$str_comments = ($comment_count > 1) ? __('%d comments') : __('%d comment'); 
     199 
     200$ws = $core->auth->user_prefs->addWorkspace('favorites'); 
     201$count = 0; 
     202foreach ($ws->dumpPrefs() as $k => $v) { 
     203     // User favorites only 
     204     if (!$v['global']) { 
     205          $fav = unserialize($v['value']); 
     206          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { 
     207               if (dc_valid_fav($fav['url'])) { 
     208                    $count++; 
     209                    $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) :  
     210                         ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title'])); 
     211                    $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon'])); 
     212 
     213                    # Let plugins set their own title for favorite on dashboard 
     214                    $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]); 
     215               } 
     216          } 
     217     } 
     218}     
     219if (!$count) { 
     220     // Global favorites if any 
     221     foreach ($ws->dumpPrefs() as $k => $v) { 
     222          $fav = unserialize($v['value']); 
     223          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { 
     224               if (dc_valid_fav($fav['url'])) { 
     225                    $count++; 
     226                    $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) :  
     227                         ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title'])); 
     228                    $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon'])); 
     229 
     230                    # Let plugins set their own title for favorite on dashboard 
     231                    $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]); 
     232               } 
     233          } 
     234     } 
     235} 
     236if (!$count) { 
     237     // No user or global favorites, add "user pref" and "new entry" fav 
     238     if ($core->auth->check('usage,contentadmin',$core->blog->id)) { 
     239          $__dashboard_icons['new_post'] = new ArrayObject(array(__('New entry'),'post.php','images/menu/edit-b.png')); 
     240     } 
     241     $__dashboard_icons['prefs'] = new ArrayObject(array(__('My preferences'),'preferences.php','images/menu/user-pref-b.png')); 
     242} 
     243 
     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 
     256$__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject)); 
    163257$core->callBehavior('adminDashboardItems', $core, $__dashboard_items); 
    164258 
     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 
    165270# Dashboard content 
    166 $dashboardContents = ''; 
    167271$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject)); 
    168272$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents); 
    169273 
    170 /* DISPLAY 
    171 -------------------------------------------------------- */ 
    172 dcPage::open(__('Dashboard'), 
    173      dcPage::jsToolBar(). 
    174      dcPage::jsLoad('js/_index.js'). 
    175      # --BEHAVIOR-- adminDashboardHeaders 
    176      $core->callBehavior('adminDashboardHeaders'), 
    177      dcPage::breadcrumb( 
    178           array( 
    179           __('Dashboard').' : '.html::escapeHTML($core->blog->name) => '' 
    180           ), 
    181           array('home_link' =>false) 
    182      ) 
    183 ); 
    184  
    185 # Dotclear updates notifications 
    186 if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) 
    187 { 
    188      $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); 
    189      $new_v = $updater->check(DC_VERSION); 
    190      $version_info = $new_v ? $updater->getInfoURL() : ''; 
    191  
    192      if ($updater->getNotify() && $new_v) { 
    193           echo 
    194           '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '. 
    195           '<p><a class="button submit" href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a> '. 
    196           '<a class="button" href="update.php?hide_msg=1">'.__('Remind me later').'</a>'. 
    197           ($version_info ? ' </p>'. 
    198           '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'. 
    199           '</div>'; 
    200      } 
    201 } 
    202  
    203 if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) { 
    204      echo 
    205      '<p><a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a></p>'; 
    206 } 
    207  
     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 
    208286if ($core->blog->status == 0) { 
    209      echo '<p class="static-msg">'.__('This blog is offline').'.</p>'; 
     287     $_ctx->addMessageStatic(__('This blog is offline')); 
    210288} elseif ($core->blog->status == -1) { 
    211      echo '<p class="static-msg">'.__('This blog is removed').'.</p>'; 
    212 } 
    213  
     289     $_ctx->addMessageStatic(__('This blog is removed')); 
     290} 
     291 
     292# Config errors messages 
    214293if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) { 
    215      echo 
    216      '<p class="static-msg">'. 
    217      sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL'). 
    218      ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.'). 
    219      '</p>'; 
    220 } 
    221  
     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} 
    222299if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) { 
    223      echo 
    224      '<p class="static-msg">'. 
    225      sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM'). 
    226      ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.'). 
    227      '</p>'; 
    228 } 
    229  
    230 $err = array(); 
    231  
    232 # Check cache directory 
    233 if ( $core->auth->isSuperAdmin() ) { 
    234      if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) { 
    235           $err[] = '<p>'.__("The cache directory does not exist or is not writable. You must create this directory with sufficient rights and affect this location to \"DC_TPL_CACHE\" in inc/config.php file.").'</p>'; 
    236      } 
    237 } else { 
    238      if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) { 
    239           $err[] = '<p>'.__("The cache directory does not exist or is not writable. You should contact your administrator.").'</p>'; 
    240      } 
    241 } 
    242  
    243 # Check public directory 
    244 if ( $core->auth->isSuperAdmin() ) { 
    245      if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) { 
    246           $err[] = '<p>'.__("There is no writable directory /public/ at the location set in about:config \"public_path\". You must create this directory with sufficient rights (or change this setting).").'</p>'; 
    247      } 
    248 } else { 
    249      if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) { 
    250           $err[] = '<p>'.__("There is no writable root directory for the media manager. You should contact your administrator.").'</p>'; 
    251      } 
    252 } 
    253  
    254 # Error list 
    255 if (count($err) > 0) { 
    256      echo '<div class="error"><p><strong>Erreur&nbsp;:</strong></p>'. 
    257      '<ul><li>'.implode("</li><li>",$err).'</li></ul></div>'; 
    258 } 
    259  
    260 # Plugins install messages 
    261 if (!empty($plugins_install['success'])) 
    262 { 
    263      echo '<div class="success">'.__('Following plugins have been installed:').'<ul>'; 
    264      foreach ($plugins_install['success'] as $k => $v) { 
    265           echo '<li>'.$k.'</li>'; 
    266      } 
    267      echo '</ul></div>'; 
    268 } 
    269 if (!empty($plugins_install['failure'])) 
    270 { 
    271      echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; 
    272      foreach ($plugins_install['failure'] as $k => $v) { 
    273           echo '<li>'.$k.' ('.$v.')</li>'; 
    274      } 
    275      echo '</ul></div>'; 
    276 } 
    277 # Errors modules notifications 
    278 if ($core->auth->isSuperAdmin()) 
    279 { 
    280      $list = $core->plugins->getErrors(); 
    281      if (!empty($list)) { 
    282           echo  
    283           '<div class="error" id="module-errors" class="error"><p>'.__('Errors have occured with following plugins:').'</p> '. 
    284           '<ul><li>'.implode("</li>\n<li>", $list).'</li></ul></div>'; 
    285      } 
    286 } 
    287  
    288 # Dashboard columns (processed first, as we need to know the result before displaying the icons.) 
    289 $dashboardItems = ''; 
    290  
    291 foreach ($__dashboard_items as $i) 
    292 {     
    293      if ($i->count() > 0) 
    294      { 
    295           $dashboardItems .= ''; 
    296           foreach ($i as $v) { 
    297                $dashboardItems .= $v; 
    298           } 
    299           $dashboardItems .= ''; 
    300      } 
    301 } 
    302  
    303 # Dashboard elements 
    304 echo '<div id="dashboard-main">'; 
    305  
    306 # Dashboard icons 
    307 echo '<div id="icons">'; 
    308 foreach ($__dashboard_icons as $i) 
    309 { 
    310      echo 
    311      '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'. 
    312      '<br /><span>'.$i[0].'</span></a></p>'; 
    313 } 
    314 echo '</div>'; 
    315  
    316 if ($core->auth->user_prefs->dashboard->quickentry) { 
    317      if ($core->auth->check('usage,contentadmin',$core->blog->id)) 
    318      { 
    319           # Getting categories 
    320           $categories_combo = dcAdminCombos::getCategoriesCombo( 
    321                $core->blog->getCategories(array('post_type'=>'post')) 
    322           ); 
    323       
    324           echo 
    325           '<div id="quick">'. 
    326           '<h3>'.__('Quick entry').'</h3>'. 
    327           '<form id="quick-entry" action="post.php" method="post" class="fieldset">'. 
    328           '<h4>'.__('New entry').'</h4>'. 
    329           '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'. 
    330           form::field('post_title',20,255,'','maximal'). 
    331           '</p>'. 
    332           '<p class="area"><label class="required" '. 
    333           'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 
    334           form::textarea('post_content',50,7). 
    335           '</p>'. 
    336           '<p><label for="cat_id" class="classic">'.__('Category:').'</label> '. 
    337           form::combo('cat_id',$categories_combo).'</p>'. 
    338           ($core->auth->check('categories', $core->blog->id) 
    339                ? '<div>'. 
    340                '<p id="new_cat" class="q-cat">'.__('Add a new category').'</p>'. 
    341                '<p class="q-cat"><label for="new_cat_title">'.__('Title:').'</label> '. 
    342                form::field('new_cat_title',30,255,'','').'</p>'. 
    343                '<p class="q-cat"><label for="new_cat_parent">'.__('Parent:').'</label> '. 
    344                form::combo('new_cat_parent',$categories_combo,'',''). 
    345                '</p>'. 
    346                '<p class="form-note info clear">'.__('This category will be created when you will save your post.').'</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 .= ''; 
    370           foreach ($i as $v) { 
    371                $dashboardContents .= $v; 
    372           } 
    373           $dashboardContents .= ''; 
    374      } 
    375 } 
    376  
    377 if ($dashboardContents != '' || $dashboardItems != '') { 
    378      echo  
    379      '<div id="dashboard-boxes">'. 
    380      '<div class="db-items">'.$dashboardItems.$dashboardContents.'</div>'. 
    381      '</div>';       
    382 } 
    383  
    384 echo '</div>'; #end dashboard-main 
    385  
    386 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'); 
    387308?> 
  • admin/plugin.php

    r2166 r2313  
    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                     __('Plugin not found') => '' 
    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

    r2256 r2313  
    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 
    52142# Getting categories 
    53 $categories_combo = dcAdminCombos::getCategoriesCombo( 
    54      $core->blog->getCategories(array('post_type'=>'post')) 
    55 ); 
    56  
    57 $status_combo = dcAdminCombos::getPostStatusesCombo(); 
    58  
    59 $img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />'; 
     143$categories_combo = array('&nbsp;' => ''); 
     144try { 
     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# Status combo 
     155foreach ($core->blog->getAllPostStatus() as $k => $v) { 
     156     $status_combo[$k] = $v; 
     157} 
    60158 
    61159# Formaters combo 
    62 $formaters_combo = dcAdminCombos::getFormatersCombo(); 
     160foreach ($core->getFormaters() as $v) { 
     161     $formaters_combo[$v] = $v; 
     162} 
    63163 
    64164# Languages combo 
    65165$rs = $core->blog->getLangs(array('order'=>'asc')); 
    66 $lang_combo = dcAdminCombos::getLangsCombo($rs,true); 
    67  
    68 # Validation flag 
    69 $bad_dt = false; 
    70  
    71 # Trackbacks 
    72 $TB = new dcTrackback($core); 
    73 $tb_urls = $tb_excerpt = ''; 
    74  
     166$all_langs = l10n::getISOcodes(0,1); 
     167$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1)); 
     168while ($rs->fetch()) { 
     169     if (isset($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]); 
     172     } else { 
     173          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 
     174     } 
     175} 
     176unset($all_langs); 
     177unset($rs); 
     178 
     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; 
    75249# Get entry informations 
    76250if (!empty($_REQUEST['id'])) 
    77251{ 
    78      $page_title = __('Edit entry'); 
    79       
    80252     $params['post_id'] = $_REQUEST['id']; 
    81253      
     
    89261     else 
    90262     { 
    91           $post_id = $post->post_id; 
    92           $cat_id = $post->cat_id; 
    93           $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 
    94           $post_format = $post->post_format; 
    95           $post_password = $post->post_password; 
    96           $post_url = $post->post_url; 
    97           $post_lang = $post->post_lang; 
    98           $post_title = $post->post_title; 
    99           $post_excerpt = $post->post_excerpt; 
    100           $post_excerpt_xhtml = $post->post_excerpt_xhtml; 
    101           $post_content = $post->post_content; 
    102           $post_content_xhtml = $post->post_content_xhtml; 
    103           $post_notes = $post->post_notes; 
    104           $post_status = $post->post_status; 
    105           $post_selected = (boolean) $post->post_selected; 
    106           $post_open_comment = (boolean) $post->post_open_comment; 
    107           $post_open_tb = (boolean) $post->post_open_tb; 
    108            
    109           $can_edit_post = $post->isEditable(); 
    110           $can_delete= $post->isDeletable(); 
    111            
     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(); 
    112282          $next_rs = $core->blog->getNextPost($post,1); 
    113283          $prev_rs = $core->blog->getNextPost($post,-1); 
    114284           
    115285          if ($next_rs !== null) { 
    116                $next_link = sprintf($post_link,$next_rs->post_id, 
    117                     html::escapeHTML($next_rs->post_title),__('Next entry').'&nbsp;&#187;'); 
    118                $next_headlink = sprintf($post_headlink,'next', 
    119                     html::escapeHTML($next_rs->post_title),$next_rs->post_id); 
    120           } 
     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); 
    121302           
    122           if ($prev_rs !== null) { 
    123                $prev_link = sprintf($post_link,$prev_rs->post_id, 
    124                     html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('Previous entry')); 
    125                $prev_headlink = sprintf($post_headlink,'previous', 
    126                     html::escapeHTML($prev_rs->post_title),$prev_rs->post_id); 
    127           } 
    128            
    129           try { 
    130                $core->media = new dcMedia($core); 
    131           } catch (Exception $e) { 
    132                $core->error->add($e->getMessage()); 
    133           } 
    134  
    135           # Sanitize trackbacks excerpt 
    136           $tb_excerpt = empty($_POST['tb_excerpt']) ?  
    137                $post_excerpt_xhtml.' '.$post_content_xhtml : 
    138                $_POST['tb_excerpt']; 
    139           $tb_excerpt = html::decodeEntities(html::clean($tb_excerpt)); 
    140           $tb_excerpt = text::cutString(html::escapeHTML($tb_excerpt), 255); 
    141           $tb_excerpt = preg_replace('/\s+/ms', ' ', $tb_excerpt); 
    142      } 
    143 } 
    144 if (isset($_REQUEST['section']) && $_REQUEST['section']=='trackbacks') { 
    145      $anchor = 'trackbacks'; 
    146 } else { 
    147      $anchor = 'comments'; 
    148 }     
    149  
    150 $comments_actions_page = new dcCommentsActionsPage($core,'post.php',array('id' => $post_id, '_ANCHOR'=>$anchor,'section' => $anchor)); 
    151  
    152 if ($comments_actions_page->process()) { 
    153      return; 
    154 } 
    155  
    156 # Ping blogs 
    157 if (!empty($_POST['ping'])) 
    158 { 
    159      if (!empty($_POST['tb_urls']) && $post_id && $post_status == 1 && $can_edit_post) 
    160      { 
    161           $tb_urls = $_POST['tb_urls']; 
    162           $tb_urls = str_replace("\r", '', $tb_urls); 
    163           $tb_post_title = html::escapeHTML(trim(html::clean($post_title))); 
    164            
    165           foreach (explode("\n", $tb_urls) as $tb_url) 
    166           { 
    167                try { 
    168                     $TB->ping($tb_url, $post_id, $tb_post_title, $tb_excerpt, $post_url); 
    169                } catch (Exception $e) { 
    170                     $core->error->add($e->getMessage()); 
    171                } 
    172           } 
    173            
    174           if (!$core->error->flag()) { 
    175                dcPage::addSuccessNotice(__('All pings sent.')); 
    176                http::redirect('post.php?id='.$post_id.'&tb=1'); 
    177           } 
    178      } 
    179 } 
    180  
    181 # Format excerpt and content 
    182 elseif (!empty($_POST) && $can_edit_post) 
    183 { 
    184      $post_format = $_POST['post_format']; 
    185      $post_excerpt = $_POST['post_excerpt']; 
    186      $post_content = $_POST['post_content']; 
    187       
    188      $post_title = $_POST['post_title']; 
    189       
    190      $cat_id = (integer) $_POST['cat_id']; 
    191       
    192      if (isset($_POST['post_status'])) { 
    193           $post_status = (integer) $_POST['post_status']; 
    194      } 
    195       
    196      if (empty($_POST['post_dt'])) { 
    197           $post_dt = ''; 
    198      } else { 
    199           try 
    200           { 
    201                $post_dt = strtotime($_POST['post_dt']); 
    202                if ($post_dt == false || $post_dt == -1) { 
    203                     $bad_dt = true; 
    204                     throw new Exception(__('Invalid publication date')); 
    205                } 
    206                $post_dt = date('Y-m-d H:i',$post_dt); 
    207           } 
    208           catch (Exception $e) 
    209           { 
    210                $core->error->add($e->getMessage()); 
    211           } 
    212      } 
    213       
    214      $post_open_comment = !empty($_POST['post_open_comment']); 
    215      $post_open_tb = !empty($_POST['post_open_tb']); 
    216      $post_selected = !empty($_POST['post_selected']); 
    217      $post_lang = $_POST['post_lang']; 
    218      $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; 
    219       
    220      $post_notes = $_POST['post_notes']; 
    221       
    222      if (isset($_POST['post_url'])) { 
    223           $post_url = $_POST['post_url']; 
    224      } 
    225       
    226      $core->blog->setPostContent( 
    227           $post_id,$post_format,$post_lang, 
    228           $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 
    229      ); 
    230 } 
    231  
    232 # Delete post 
    233 if (!empty($_POST['delete']) && $can_delete) 
    234 { 
    235      try { 
    236           # --BEHAVIOR-- adminBeforePostDelete 
    237           $core->callBehavior('adminBeforePostDelete',$post_id); 
    238           $core->blog->delPost($post_id); 
    239           http::redirect('posts.php'); 
    240      } catch (Exception $e) { 
    241           $core->error->add($e->getMessage()); 
    242      } 
    243 } 
    244  
    245 # Create or update post 
    246 if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt) 
    247 { 
    248      # Create category 
    249      if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { 
    250       
    251           $cur_cat = $core->con->openCursor($core->prefix.'category'); 
    252           $cur_cat->cat_title = $_POST['new_cat_title']; 
    253           $cur_cat->cat_url = ''; 
    254            
    255           $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 
    256            
    257           # --BEHAVIOR-- adminBeforeCategoryCreate 
    258           $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 
    259            
    260           $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 
    261            
    262           # --BEHAVIOR-- adminAfterCategoryCreate 
    263           $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id); 
    264      } 
    265       
    266      $cur = $core->con->openCursor($core->prefix.'post'); 
    267       
    268      $cur->post_title = $post_title; 
    269      $cur->cat_id = ($cat_id ? $cat_id : null); 
    270      $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 
    271      $cur->post_format = $post_format; 
    272      $cur->post_password = $post_password; 
    273      $cur->post_lang = $post_lang; 
    274      $cur->post_title = $post_title; 
    275      $cur->post_excerpt = $post_excerpt; 
    276      $cur->post_excerpt_xhtml = $post_excerpt_xhtml; 
    277      $cur->post_content = $post_content; 
    278      $cur->post_content_xhtml = $post_content_xhtml; 
    279      $cur->post_notes = $post_notes; 
    280      $cur->post_status = $post_status; 
    281      $cur->post_selected = (integer) $post_selected; 
    282      $cur->post_open_comment = (integer) $post_open_comment; 
    283      $cur->post_open_tb = (integer) $post_open_tb; 
    284       
    285      if (isset($_POST['post_url'])) { 
    286           $cur->post_url = $post_url; 
    287      } 
    288       
    289      # Update post 
    290      if ($post_id) 
    291      { 
    292           try 
    293           { 
    294                # --BEHAVIOR-- adminBeforePostUpdate 
    295                $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); 
    296                 
    297                $core->blog->updPost($post_id,$cur); 
    298                 
    299                # --BEHAVIOR-- adminAfterPostUpdate 
    300                $core->callBehavior('adminAfterPostUpdate',$cur,$post_id); 
    301                dcPage::addSuccessNotice (sprintf('The post "%s" has been successfully updated',html::escapeHTML($cur->post_title))); 
    302                http::redirect('post.php?id='.$post_id); 
    303           } 
    304           catch (Exception $e) 
    305           { 
    306                $core->error->add($e->getMessage()); 
    307           } 
    308      } 
    309      else 
    310      { 
    311           $cur->user_id = $core->auth->userID(); 
    312            
    313           try 
    314           { 
    315                # --BEHAVIOR-- adminBeforePostCreate 
    316                $core->callBehavior('adminBeforePostCreate',$cur); 
    317                 
    318                $return_id = $core->blog->addPost($cur); 
    319                 
    320                # --BEHAVIOR-- adminAfterPostCreate 
    321                $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 
    322  
    323                dcPage::addSuccessNotice(__('Entry has been successfully created.')); 
    324                http::redirect('post.php?id='.$return_id); 
    325           } 
    326           catch (Exception $e) 
    327           { 
    328                $core->error->add($e->getMessage()); 
    329           } 
    330      } 
    331 } 
    332  
    333 # Getting categories 
    334 $categories_combo = dcAdminCombos::getCategoriesCombo( 
    335      $core->blog->getCategories(array('post_type'=>'post')) 
    336 ); 
     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; 
     355 
    337356/* DISPLAY 
    338357-------------------------------------------------------- */ 
     
    344363     $default_tab = 'comments'; 
    345364} 
    346 elseif (!empty($_GET['tb'])) { 
    347      $default_tab = 'trackbacks'; 
    348 } 
    349  
    350 if ($post_id) { 
    351      switch ($post_status) { 
    352           case 1: 
    353                $img_status = sprintf($img_status_pattern,__('Published'),'check-on.png'); 
    354                break; 
    355           case 0: 
    356                $img_status = sprintf($img_status_pattern,__('Unpublished'),'check-off.png'); 
    357                break; 
    358           case -1: 
    359                $img_status = sprintf($img_status_pattern,__('Scheduled'),'scheduled.png'); 
    360                break; 
    361           case -2: 
    362                $img_status = sprintf($img_status_pattern,__('Pending'),'check-wrn.png'); 
    363                break; 
    364           default: 
    365                $img_status = ''; 
    366      } 
    367      $edit_entry_str = __('&ldquo;%s&rdquo;'); 
    368      $page_title_edit = sprintf($edit_entry_str, html::escapeHTML($post_title)).' '.$img_status; 
    369 } else { 
    370      $img_status = ''; 
    371 } 
    372  
    373  
    374 dcPage::open($page_title.' - '.__('Entries'), 
    375      dcPage::jsDatePicker(). 
    376      dcPage::jsToolBar(). 
    377      dcPage::jsModal(). 
    378      dcPage::jsMetaEditor(). 
    379      dcPage::jsLoad('js/_post.js'). 
    380      dcPage::jsConfirmClose('entry-form','comment-form'). 
    381      # --BEHAVIOR-- adminPostHeaders 
    382      $core->callBehavior('adminPostHeaders'). 
    383      dcPage::jsPageTabs($default_tab). 
    384      $next_headlink."\n".$prev_headlink, 
    385      dcPage::breadcrumb( 
     365$page_title_edit = __('Edit entry'); 
     366$_ctx 
     367     ->setBreadCrumb( 
    386368          array( 
    387369               html::escapeHTML($core->blog->name) => '', 
    388370               __('Entries') => 'posts.php', 
    389371               ($post_id ? $page_title_edit : $page_title) => '' 
    390           )) 
    391 ); 
     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} 
    392379 
    393380if (!empty($_GET['upd'])) { 
    394      dcPage::success(__('Entry has been successfully updated.')); 
     381     $_ctx->setAlert(__('Entry has been successfully updated.')); 
    395382} 
    396383elseif (!empty($_GET['crea'])) { 
    397      dcPage::success(__('Entry has been successfully created.')); 
     384     $_ctx->setAlert(__('Entry has been successfully created.')); 
    398385} 
    399386elseif (!empty($_GET['attached'])) { 
    400      dcPage::success(__('File has been successfully attached.')); 
     387     $_ctx->setAlert(__('File has been successfully attached.')); 
    401388} 
    402389elseif (!empty($_GET['rmattach'])) { 
    403      dcPage::success(__('Attachment has been successfully removed.')); 
    404 } 
    405  
     390     $_ctx->setAlert(__('Attachment has been successfully removed.')); 
     391} 
    406392if (!empty($_GET['creaco'])) { 
    407      dcPage::success(__('Comment has been successfully created.')); 
    408 } 
    409 if (!empty($_GET['tbsent'])) { 
    410      dcPage::success(__('All pings sent.')); 
    411 } 
    412  
    413 # XHTML conversion 
    414 if (!empty($_GET['xconv'])) 
    415 { 
    416      $post_excerpt = $post_excerpt_xhtml; 
    417      $post_content = $post_content_xhtml; 
    418      $post_format = 'xhtml'; 
    419       
    420      dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.')); 
    421 } 
    422  
    423 if ($post_id && $post->post_status == 1) { 
    424      echo '<p><a class="onblog_link outgoing" href="'.$post->getURL().'" title="'.$post_title.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>'; 
    425 } 
    426 if ($post_id) 
    427 { 
    428      echo '<p class="nav_prevnext">'; 
    429      if ($prev_link) { echo $prev_link; } 
    430      if ($next_link && $prev_link) { echo ' | '; } 
    431      if ($next_link) { echo $next_link; } 
    432       
    433      # --BEHAVIOR-- adminPostNavLinks 
    434      $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); 
    435       
    436      echo '</p>'; 
    437 } 
    438  
    439 # Exit if we cannot view page 
    440 if (!$can_view_page) { 
    441      dcPage::helpBlock('core_post'); 
    442      dcPage::close(); 
    443      exit; 
    444 } 
    445 /* Post form if we can edit post 
    446 -------------------------------------------------------- */ 
    447 if ($can_edit_post) 
    448 { 
    449      $sidebar_items = new ArrayObject(array( 
    450           'status-box' => array( 
    451                'title' => __('Status'), 
    452                'items' => array( 
    453                     'post_status' =>  
    454                          '<p class="entry-status"><label for="post_status" class="ib">'.__('Entry status').' '.$img_status.'</label>'. 
    455                          form::combo('post_status',$status_combo,$post_status,'maximal','',!$can_publish). 
    456                          '</p>', 
    457                     'post_dt' =>  
    458                          '<p><label for="post_dt" class="ib">'.__('Publication date and hour').'</label>'. 
    459                          form::field('post_dt',16,16,$post_dt,($bad_dt ? 'invalid' : '')). 
    460                          '</p>', 
    461                     'post_lang' => 
    462                          '<p><label for="post_lang" class="ib">'.__('Entry language').'</label>'. 
    463                          form::combo('post_lang',$lang_combo,$post_lang). 
    464                          '</p>', 
    465                     'post_format' => 
    466                          '<div>'. 
    467                          '<h5 id="label_format"><label for="post_format" class="ib">'.__('Text formatting').'</label></h5>'. 
    468                          '<p>'.form::combo('post_format',$formaters_combo,$post_format,'maximal'). 
    469                          '</p>'. 
    470                          '<p class="format_control control_no_xhtml">'. 
    471                          '<a id="convert-xhtml" class="button'.($post_id && $post_format != 'wiki' ? ' hide' : '').'" href="post.php?id='.$post_id.'&amp;xconv=1">'. 
    472                          __('Convert to XHTML').'</a></p></div>')), 
    473           'metas-box' => array( 
    474                'title' => __('Filing'), 
    475                'items' => array( 
    476                     'post_selected' =>  
    477                          '<p><label for="post_selected" class="classic">'. 
    478                          form::checkbox('post_selected',1,$post_selected).' '. 
    479                          __('Selected entry').'</label></p>', 
    480                     'cat_id' => 
    481                          '<div>'. 
    482                          '<h5 id="label_cat_id">'.__('Category').'</h5>'. 
    483                          '<p><label for="cat_id">'.__('Category:').'</label>'. 
    484                          form::combo('cat_id',$categories_combo,$cat_id,'maximal'). 
    485                          '</p>'. 
    486                          ($core->auth->check('categories', $core->blog->id) ? 
    487                               '<div>'. 
    488                               '<h5 id="create_cat">'.__('Add a new category').'</h5>'. 
    489                               '<p><label for="new_cat_title">'.__('Title:').' '. 
    490                               form::field('new_cat_title',30,255,'','maximal').'</label></p>'. 
    491                               '<p><label for="new_cat_parent">'.__('Parent:').' '. 
    492                               form::combo('new_cat_parent',$categories_combo,'','maximal'). 
    493                               '</label></p>'. 
    494                               '</div>' 
    495                          : ''). 
    496                          '</div>')), 
    497           'options-box' => array( 
    498                'title' => __('Options'), 
    499                'items' => array( 
    500                     'post_open_comment_tb' => 
    501                          '<div>'. 
    502                          '<h5 id="label_comment_tb">'.__('Comments and trackbacks list').'</h5>'. 
    503                          '<p><label for="post_open_comment" class="classic">'. 
    504                          form::checkbox('post_open_comment',1,$post_open_comment).' '. 
    505                          __('Accept comments').'</label></p>'. 
    506                          ($core->blog->settings->system->allow_comments ?  
    507                               (isContributionAllowed($post_id,strtotime($post_dt),true) ?  
    508                                    '' : 
    509                                    '<p class="form-note warn">'. 
    510                                    __('Warning: Comments are not more accepted for this entry.').'</p>') :  
    511                               '<p class="form-note warn">'. 
    512                               __('Comments are not accepted on this blog so far.').'</p>'). 
    513                          '<p><label for="post_open_tb" class="classic">'. 
    514                          form::checkbox('post_open_tb',1,$post_open_tb).' '. 
    515                          __('Accept trackbacks').'</label></p>'. 
    516                          ($core->blog->settings->system->allow_trackbacks ?  
    517                               (isContributionAllowed($post_id,strtotime($post_dt),false) ?  
    518                                    '' : 
    519                                    '<p class="form-note warn">'. 
    520                                    __('Warning: Trackbacks are not more accepted for this entry.').'</p>') :  
    521                               '<p class="form-note warn">'.__('Trackbacks are not accepted on this blog so far.').'</p>'). 
    522                          '</div>', 
    523                     'post_password' => 
    524                          '<p><label for="post_password" class="ib">'.__('Password').'</label>'. 
    525                          form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). 
    526                          '</p>', 
    527                     'post_url' => 
    528                          '<div class="lockable">'. 
    529                          '<p><label for="post_url" class="ib">'.__('Edit basename').'</label>'. 
    530                          form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). 
    531                          '</p>'. 
    532                          '<p class="form-note warn">'. 
    533                          __('Warning: If you set the URL manually, it may conflict with another entry.'). 
    534                          '</p></div>' 
    535      )))); 
    536  
    537      $main_items = new ArrayObject(array( 
    538           "post_title" => 
    539                '<p class="col">'. 
    540                '<label class="required no-margin"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'. 
    541                form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). 
    542                '</p>', 
    543            
    544           "post_excerpt" => 
    545                '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').' <span class="form-note">'. 
    546                __('Introduction to the post.').'</span></label> '. 
    547                form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). 
    548                '</p>', 
    549            
    550           "post_content" => 
    551                '<p class="area" id="content-area"><label class="required" '. 
    552                'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 
    553                form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). 
    554                '</p>', 
    555            
    556           "post_notes" => 
    557                '<p class="area" id="notes-area"><label for="post_notes">'.__('Personal notes:').' <span class="form-note">'. 
    558                __('Unpublished notes.').'</span></label>'. 
    559                form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). 
    560                '</p>' 
    561           ) 
    562      ); 
    563       
    564      # --BEHAVIOR-- adminPostFormItems 
    565      $core->callBehavior('adminPostFormItems',$main_items,$sidebar_items, isset($post) ? $post : null); 
    566  
    567      echo '<div class="multi-part" title="'.($post_id ? __('Edit entry') : __('New entry')).'" id="edit-entry">'; 
    568      echo '<form action="post.php" method="post" id="entry-form">'; 
    569      echo '<div id="entry-wrapper">'; 
    570      echo '<div id="entry-content"><div class="constrained">'; 
    571  
    572      echo '<h3 class="out-of-screen-if-js">'.__('Edit post').'</h3>'; 
    573       
    574      foreach ($main_items as $id => $item) { 
    575           echo $item; 
    576      } 
    577  
    578      # --BEHAVIOR-- adminPostForm (may be deprecated) 
    579      $core->callBehavior('adminPostForm',isset($post) ? $post : null); 
    580       
    581      echo 
    582      '<p class="border-top">'. 
    583      ($post_id ? form::hidden('id',$post_id) : ''). 
    584      '<input type="submit" value="'.__('Save').' (s)" '. 
    585      'accesskey="s" name="save" /> '; 
    586      if ($post_id) { 
    587           $preview_url = 
    588           $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 
    589           http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 
    590           '/'.$post->post_url); 
    591           echo '<a id="post-preview" href="'.$preview_url.'" class="button" accesskey="p">'.__('Preview').' (p)'.'</a> '; 
    592      } else { 
    593           echo 
    594           '<a id="post-cancel" href="index.php" class="button" accesskey="c">'.__('Cancel').' (c)</a>'; 
    595      } 
    596  
    597      echo 
    598      ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). 
    599      $core->formNonce(). 
    600      '</p>'; 
    601       
    602      echo '</div></div>';          // End #entry-content 
    603      echo '</div>';      // End #entry-wrapper 
    604  
    605      echo '<div id="entry-sidebar">'; 
    606       
    607      foreach ($sidebar_items as $id => $c) { 
    608           echo '<div id="'.$id.'" class="sb-box">'. 
    609                '<h4>'.$c['title'].'</h4>'; 
    610           foreach ($c['items'] as $e_name=>$e_content) { 
    611                echo $e_content; 
    612           } 
    613           echo '</div>'; 
    614      } 
    615       
    616       
    617      # --BEHAVIOR-- adminPostFormSidebar (may be deprecated) 
    618      $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); 
    619      echo '</div>';      // End #entry-sidebar 
    620  
    621      echo '</form>'; 
    622       
    623      # --BEHAVIOR-- adminPostForm 
    624      $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); 
    625       
    626      echo '</div>'; 
    627 } 
    628  
    629 if ($post_id) 
    630 { 
    631      /* Comments 
    632      -------------------------------------------------------- */ 
    633  
    634      $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC'); 
    635       
    636      $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0))); 
    637            
    638      echo 
    639      '<div id="comments" class="clear multi-part" title="'.__('Comments').'">'; 
    640      $combo_action = $comments_actions_page->getCombo();     
    641      $has_action = !empty($combo_action) && !$comments->isEmpty(); 
    642      echo  
    643      '<p class="top-add"><a class="button add" href="#comment-form">'.__('Add a comment').'</a></p>'; 
    644       
    645      if ($has_action) { 
    646           echo '<form action="post.php" id="form-comments" method="post">'; 
    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(array('section'),'comments'). 
    664           form::hidden(array('id'),$post_id). 
    665           $core->formNonce(). 
    666           '<input type="submit" value="'.__('ok').'" /></p>'. 
    667           '</div>'. 
    668           '</form>'; 
    669      } 
    670      /* Add a comment 
    671      -------------------------------------------------------- */ 
    672  
    673      echo 
    674      '<div class="fieldset clear">'. 
    675      '<h3>'.__('Add a comment').'</h3>'. 
    676       
    677      '<form action="comment.php" method="post" id="comment-form">'. 
    678      '<div class="constrained">'. 
    679      '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').'</label>'. 
    680      form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))). 
    681      '</p>'. 
    682       
    683      '<p><label for="comment_email">'.__('Email:').'</label>'. 
    684      form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))). 
    685      '</p>'. 
    686       
    687      '<p><label for="comment_site">'.__('Web site:').'</label>'. 
    688      form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))). 
    689      '</p>'. 
    690       
    691      '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '. 
    692      __('Comment:').'</label> '. 
    693      form::textarea('comment_content',50,8,html::escapeHTML('')). 
    694      '</p>'. 
    695       
    696      '<p>'. 
    697      form::hidden('post_id',$post_id). 
    698      $core->formNonce(). 
    699      '<input type="submit" name="add" value="'.__('Save').'" /></p>'. 
    700      '</div>'. #constrained 
    701  
    702      '</form>'. 
    703      '</div>'. #add comment 
    704      '</div>'; #comments 
    705 } 
    706  
    707 if ($post_id && $post_status == 1) 
    708 { 
    709      /* Trackbacks 
    710      -------------------------------------------------------- */ 
    711  
    712      $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC'); 
    713      $trackbacks = $core->blog->getComments(array_merge($params, array('comment_trackback' => 1))); 
    714       
    715      # Actions combo box 
    716      $combo_action = $comments_actions_page->getCombo();     
    717      $has_action = !empty($combo_action) && !$trackbacks->isEmpty(); 
    718       
    719      if (!empty($_GET['tb_auto'])) { 
    720           $tb_urls = implode("\n", $TB->discover($post_excerpt_xhtml.' '.$post_content_xhtml)); 
    721      } 
    722       
    723      # Display tab 
    724      echo 
    725      '<div id="trackbacks" class="clear multi-part" title="'.__('Trackbacks').'">'; 
    726       
    727      # tracbacks actions 
    728      if ($has_action) { 
    729           echo '<form action="post.php" id="form-trackbacks" method="post">'; 
    730      } 
    731       
    732      echo '<h3>'.__('Trackbacks received').'</h3>'; 
    733       
    734      if (!$trackbacks->isEmpty()) { 
    735           showComments($trackbacks, $has_action, true); 
    736      } else { 
    737           echo '<p>'.__('No trackback').'</p>'; 
    738      } 
    739       
    740      if ($has_action) { 
    741           echo 
    742           '<div class="two-cols">'. 
    743           '<p class="col checkboxes-helpers"></p>'. 
    744            
    745           '<p class="col right"><label for="action" class="classic">'.__('Selected trackbacks action:').'</label> '. 
    746           form::combo('action', $combo_action). 
    747           form::hidden('id',$post_id). 
    748           form::hidden(array('section'),'trackbacks'). 
    749           $core->formNonce(). 
    750           '<input type="submit" value="'.__('ok').'" /></p>'. 
    751           '</div>'. 
    752           '</form>'; 
    753      } 
    754       
    755      /* Add trackbacks 
    756      -------------------------------------------------------- */ 
    757      if ($can_edit_post && $post->post_status) { 
    758           echo 
    759           '<div class="fieldset clear">'; 
    760  
    761           echo 
    762           '<h3>'.__('Ping blogs').'</h3>'. 
    763           '<form action="post.php?id='.$post_id.'" id="trackback-form" method="post">'. 
    764           '<p><label for="tb_urls" class="area">'.__('URLs to ping:').'</label>'. 
    765           form::textarea('tb_urls', 60, 5, $tb_urls). 
    766           '</p>'. 
    767  
    768           '<p><label for="tb_excerpt" class="area">'.__('Excerpt to send:').'</label>'. 
    769           form::textarea('tb_excerpt', 60, 5, $tb_excerpt).'</p>'. 
    770  
    771           '<p>'. 
    772           $core->formNonce(). 
    773           '<input type="submit" name="ping" value="'.__('Ping blogs').'" />'. 
    774           (empty($_GET['tb_auto']) ?  
    775                '&nbsp;&nbsp;<a class="button" href="'. 
    776                'post.php?id='.$post_id.'&amp;tb_auto=1&amp;tb=1'. 
    777                '">'.__('Auto discover ping URLs').'</a>' 
    778           : ''). 
    779           '</p>'. 
    780           '</form>'; 
    781  
    782           $pings = $TB->getPostPings($post_id); 
    783  
    784           if (!$pings->isEmpty()) 
    785           { 
    786                echo '<h3>'.__('Previously sent pings').'</h3>'; 
    787                 
    788                echo '<ul class="nice">'; 
    789                while ($pings->fetch()) { 
    790                     echo 
    791                     '<li>'.dt::dt2str(__('%Y-%m-%d %H:%M'), $pings->ping_dt).' - '. 
    792                     $pings->ping_url.'</li>'; 
    793                } 
    794                echo '</ul>'; 
    795           } 
    796  
    797           echo '</div>'; 
    798      } 
    799  
    800      echo '</div>'; #trackbacks 
    801 } 
    802  
    803 # Controls comments or trakbacks capabilities 
    804 function isContributionAllowed($id,$dt,$com=true) 
    805 { 
    806      global $core; 
    807  
    808      if (!$id) { 
    809           return true; 
    810      } 
    811      if ($com) { 
    812           if (($core->blog->settings->system->comments_ttl == 0) ||  
    813                (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 
    814                return true; 
    815           } 
    816      } else { 
    817           if (($core->blog->settings->system->trackbacks_ttl == 0) ||  
    818                (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 
    819                return true; 
    820           } 
    821      } 
    822      return false; 
    823 } 
    824  
    825 # Show comments or trackbacks 
    826 function showComments($rs,$has_action,$tb=false) 
    827 { 
    828      echo 
    829      '<div class="table-outer">'. 
    830      '<table class="comments-list"><tr>'. 
    831      '<th colspan="2" class="first">'.__('Author').'</th>'. 
    832      '<th>'.__('Date').'</th>'. 
    833      '<th class="nowrap">'.__('IP address').'</th>'. 
    834      '<th>'.__('Status').'</th>'. 
    835      '<th>'.__('Edit').'</th>'. 
    836      '</tr>'; 
    837      $comments = array(); 
    838      if (isset($_REQUEST['comments'])) { 
    839           foreach ($_REQUEST['comments'] as $v) { 
    840                $comments[(integer)$v]=true; 
    841           } 
    842      }               
    843       
    844      while($rs->fetch()) 
    845      { 
    846           $comment_url = 'comment.php?id='.$rs->comment_id; 
    847            
    848           $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
    849           switch ($rs->comment_status) { 
    850                case 1: 
    851                     $img_status = sprintf($img,__('Published'),'check-on.png'); 
    852                     break; 
    853                case 0: 
    854                     $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 
    855                     break; 
    856                case -1: 
    857                     $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 
    858                     break; 
    859                case -2: 
    860                     $img_status = sprintf($img,__('Junk'),'junk.png'); 
    861                     break; 
    862           } 
    863            
    864           echo 
    865           '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 
    866           ' id="c'.$rs->comment_id.'">'. 
    867            
    868           '<td class="nowrap">'. 
    869           ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,isset($comments[$rs->comment_id]),'','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 
    870           '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 
    871           '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 
    872           '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'. 
    873           '<td class="nowrap status">'.$img_status.'</td>'. 
    874           '<td class="nowrap status"><a href="'.$comment_url.'">'. 
    875           '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /> '.__('Edit').'</a></td>'. 
    876            
    877           '</tr>'; 
    878      } 
    879       
    880      echo '</table></div>'; 
    881 } 
    882  
    883 dcPage::helpBlock('core_post','core_trackbacks','core_wiki'); 
    884 dcPage::close(); 
     393     $_ctx->setAlert(__('Comment has been successfully created.')); 
     394}     
     395      
     396$core->tpl->display('post.html.twig'); 
    885397?> 
  • admin/posts.php

    r2312 r2313  
    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 
     
    4747{ 
    4848     # Filter form we'll put in html_block 
    49      $users_combo = array_merge( 
    50           array('-' => ''), 
    51           dcAdminCombos::getUsersCombo($users) 
    52      ); 
    53  
    54      $categories_combo = array_merge( 
    55           array( 
    56                new formSelectOption('-',''), 
    57                new formSelectOption(__('(No cat)'),'NULL')),           
    58           dcAdminCombos::getCategoriesCombo($categories,false) 
    59      ); 
    60      $categories_values = array(); 
    61      foreach ($categories_combo as $cat) { 
    62           if (isset($cat->value)) { 
    63                $categories_values[$cat->value]=true; 
     49     $users_combo = $categories_combo = array(); 
     50     while ($users->fetch()) 
     51     { 
     52          $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, 
     53          $users->user_firstname,$users->user_displayname); 
     54           
     55          if ($user_cn != $users->user_id) { 
     56               $user_cn .= ' ('.$users->user_id.')'; 
    6457          } 
     58           
     59          $users_combo[$user_cn] = $users->user_id;  
    6560     } 
    6661      
    67      $status_combo = array_merge( 
    68           array('-' => ''), 
    69           dcAdminCombos::getPostStatusesCombo()    
     62 
     63# Getting categories 
     64$categories_combo = array(); 
     65try { 
     66     $categories = $core->blog->getCategories(array('post_type'=>'post')); 
     67     while ($categories->fetch()) { 
     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); 
     72     } 
     73} catch (Exception $e) { } 
     74     $status_combo = array( 
     75     ); 
     76     foreach ($core->blog->getAllPostStatus() as $k => $v) { 
     77          $status_combo[(string) $k] = (string)$v; 
     78     } 
     79      
     80     $selected_combo = array( 
     81     '1' => __('is selected'), 
     82     '0' => __('is not selected') 
    7083     ); 
    7184      
    72      $selected_combo = array( 
    73      '-' => '', 
    74      __('Selected') => '1', 
    75      __('Not selected') => '0' 
    76      ); 
     85     # Months array 
     86     while ($dates->fetch()) { 
     87          $dt_m_combo[$dates->year().$dates->month()] = dt::str('%B %Y',$dates->ts()); 
     88     } 
    7789      
    78      $attachment_combo = array( 
    79      '-' => '', 
    80      __('With attachments') => '1', 
    81      __('Without attachments') => '0' 
    82      ); 
     90     while ($langs->fetch()) { 
     91          $lang_combo[$langs->post_lang] = $langs->post_lang; 
     92     } 
     93} 
     94$form = new dcForm($core,'post','post.php'); 
    8395 
    84      # Months array 
    85      $dt_m_combo = array_merge( 
    86           array('-' => ''), 
    87           dcAdminCombos::getDatesCombo($dates) 
    88      ); 
    89       
    90      $lang_combo = array_merge( 
    91           array('-' => ''), 
    92           dcAdminCombos::getLangsCombo($langs,false)    
    93      ); 
    94       
    95      $sortby_combo = array( 
    96      __('Date') => 'post_dt', 
    97      __('Title') => 'post_title', 
    98      __('Category') => 'cat_title', 
    99      __('Author') => 'user_id', 
    100      __('Status') => 'post_status', 
    101      __('Selected') => 'post_selected', 
    102      __('Number of comments') => 'nb_comment', 
    103      __('Number of trackbacks') => 'nb_trackback' 
    104      ); 
    105       
    106      $order_combo = array( 
    107      __('Descending') => 'desc', 
    108      __('Ascending') => 'asc' 
     96 
     97# Actions combo box 
     98$combo_action = array(); 
     99if ($core->auth->check('publish,contentadmin',$core->blog->id)) 
     100{ 
     101     $combo_action[__('Status')] = array( 
     102          __('Publish') => 'publish', 
     103          __('Unpublish') => 'unpublish', 
     104          __('Schedule') => 'schedule', 
     105          __('Mark as pending') => 'pending' 
    109106     ); 
    110107} 
    111  
    112 # Actions combo box 
    113  
    114 $posts_actions_page = new dcPostsActionsPage($core,'posts.php'); 
    115  
    116 if ($posts_actions_page->process()) { 
    117      return; 
     108$combo_action[__('Mark')] = array( 
     109     __('Mark as selected') => 'selected', 
     110     __('Mark as unselected') => 'unselected' 
     111); 
     112$combo_action[__('Change')] = array( 
     113     __('Change category') => 'category', 
     114     __('Change language') => 'lang'); 
     115if ($core->auth->check('admin',$core->blog->id)) 
     116{ 
     117     $combo_action[__('Change')] = array_merge($combo_action[__('Change')], 
     118          array(__('Change author') => 'author')); 
     119} 
     120if ($core->auth->check('delete,contentadmin',$core->blog->id)) 
     121{ 
     122     $combo_action[__('Delete')] = array(__('Delete') => 'delete'); 
    118123} 
    119124 
    120 /* Get posts 
    121 -------------------------------------------------------- */ 
    122 $user_id = !empty($_GET['user_id']) ?   $_GET['user_id'] : ''; 
    123 $cat_id = !empty($_GET['cat_id']) ?     $_GET['cat_id'] : ''; 
    124 $status = isset($_GET['status']) ? $_GET['status'] : ''; 
    125 $selected = isset($_GET['selected']) ?  $_GET['selected'] : ''; 
    126 $attachment = isset($_GET['attachment']) ?   $_GET['attachment'] : ''; 
    127 $month = !empty($_GET['month']) ?       $_GET['month'] : ''; 
    128 $lang = !empty($_GET['lang']) ?         $_GET['lang'] : ''; 
    129 $sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'post_dt'; 
    130 $order = !empty($_GET['order']) ?       $_GET['order'] : 'desc'; 
     125# --BEHAVIOR-- adminPostsActionsCombo 
     126$core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); 
    131127 
    132 $show_filters = false; 
    133128 
    134 $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; 
    135 $nb_per_page =  30; 
    136129 
    137 if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { 
    138      if ($nb_per_page != $_GET['nb']) { 
    139           $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); 
    140135     } 
    141      $nb_per_page = (integer) $_GET['nb']; 
    142136} 
    143137 
    144 $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); 
    145 $params['no_content'] = true; 
     138class PostsFetcher extends dcListFetcher { 
    146139 
    147 # - User filter 
    148 if ($user_id !== '' && in_array($user_id,$users_combo)) { 
    149      $params['user_id'] = $user_id; 
    150      $show_filters = true; 
    151 } else { 
    152      $user_id=''; 
    153 } 
     140     public function getEntries($params,$offset,$limit) { 
     141          $params['limit'] = array($offset,$limit); 
     142          return $this->core->blog->getPosts($params); 
     143     } 
    154144 
    155 # - Categories filter 
    156 if ($cat_id !== '' && isset($categories_values[$cat_id])) { 
    157      $params['cat_id'] = $cat_id; 
    158      $show_filters = true; 
    159 } else { 
    160      $cat_id=''; 
    161 } 
    162  
    163 # - Status filter 
    164 if ($status !== '' && in_array($status,$status_combo)) { 
    165      $params['post_status'] = $status; 
    166      $show_filters = true; 
    167 } else { 
    168      $status=''; 
    169 } 
    170  
    171 # - Selected filter 
    172 if ($selected !== '' && in_array($selected,$selected_combo)) { 
    173      $params['post_selected'] = $selected; 
    174      $show_filters = true; 
    175 } else { 
    176      $selected=''; 
    177 } 
    178  
    179 # - Selected filter 
    180 if ($attachment !== '' && in_array($attachment,$attachment_combo)) { 
    181      $params['media'] = $attachment; 
    182      $params['link_type'] = 'attachment'; 
    183      $show_filters = true; 
    184 } else { 
    185      $attachment=''; 
    186 } 
    187  
    188 # - Month filter 
    189 if ($month !== '' && in_array($month,$dt_m_combo)) { 
    190      $params['post_month'] = substr($month,4,2); 
    191      $params['post_year'] = substr($month,0,4); 
    192      $show_filters = true; 
    193 } else { 
    194      $month=''; 
    195 } 
    196  
    197 # - Lang filter 
    198 if ($lang !== '' && in_array($lang,$lang_combo)) { 
    199      $params['post_lang'] = $lang; 
    200      $show_filters = true; 
    201 } else { 
    202      $lang=''; 
    203 } 
    204  
    205 # - Sortby and order filter 
    206 if ($sortby !== '' && in_array($sortby,$sortby_combo)) { 
    207      if ($order !== '' && in_array($order,$order_combo)) { 
    208           $params['order'] = $sortby.' '.$order; 
    209      } else { 
    210           $order='desc'; 
     145     public function getEntriesCount($params) { 
     146          $count = $this->core->blog->getPosts($params,true); 
     147          return $count->f(0); 
    211148     } 
    212       
    213      if ($sortby != 'post_dt' || $order != 'desc') { 
    214           $show_filters = true; 
    215      } 
    216 } else { 
    217      $sortby='post_dt'; 
    218      $order='desc'; 
    219 } 
    220  
    221 # Get posts 
    222 try { 
    223      $posts = $core->blog->getPosts($params); 
    224      $counter = $core->blog->getPosts($params,true); 
    225      $post_list = new adminPostList($core,$posts,$counter->f(0)); 
    226 } catch (Exception $e) { 
    227      $core->error->add($e->getMessage()); 
    228149} 
    229150 
    230151/* DISPLAY 
    231152-------------------------------------------------------- */ 
     153$filterSet = new dcFilterSet($core,'fposts','posts.php'); 
    232154 
    233 $form_filter_title = __('Show filters and display options'); 
    234 $starting_script  = dcPage::jsLoad('js/_posts_list.js'); 
    235 $starting_script .= dcPage::jsLoad('js/filter-controls.js'); 
    236 $starting_script .= 
    237      '<script type="text/javascript">'."\n". 
    238      "//<![CDATA["."\n". 
    239      dcPage::jsVar('dotclear.msg.show_filters', $show_filters ? 'true':'false')."\n". 
    240      dcPage::jsVar('dotclear.msg.filter_posts_list',$form_filter_title)."\n". 
    241      dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". 
    242      "//]]>". 
    243      "</script>"; 
     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)); 
    244172 
    245 dcPage::open(__('Entries'),$starting_script, 
    246      dcPage::breadcrumb( 
    247           array( 
    248                html::escapeHTML($core->blog->name) => '', 
    249                __('Entries') => '' 
    250           )) 
    251 ); 
    252 if (!empty($_GET['upd'])) { 
    253      dcPage::success(__('Selected entries have been successfully updated.')); 
    254 } elseif (!empty($_GET['del'])) { 
    255      dcPage::success(__('Selected entries have been successfully deleted.')); 
    256 } 
    257 if (!$core->error->flag()) 
    258 { 
    259      echo 
    260      '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'. 
    261      '<form action="posts.php" method="get" id="filters-form">'. 
    262      '<h3 class="out-of-screen-if-js">'.$form_filter_title.'</h3>'. 
    263173 
    264      '<div class="table">'. 
    265      '<div class="cell">'. 
    266      '<h4>'.__('Filters').'</h4>'. 
    267      '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. 
    268      form::combo('user_id',$users_combo,$user_id).'</p>'. 
    269      '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. 
    270      form::combo('cat_id',$categories_combo,$cat_id).'</p>'. 
    271      '<p><label for="status" class="ib">'.__('Status:').'</label> ' . 
    272      form::combo('status',$status_combo,$status).'</p> '. 
    273      '</div>'. 
    274       
    275      '<div class="cell filters-sibling-cell">'. 
    276      '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. 
    277      form::combo('selected',$selected_combo,$selected).'</p>'. 
    278      '<p><label for="attachment" class="ib">'.__('Attachments:').'</label> '. 
    279      form::combo('attachment',$attachment_combo,$attachment).'</p>'. 
    280      '<p><label for="month" class="ib">'.__('Month:').'</label> '. 
    281      form::combo('month',$dt_m_combo,$month).'</p>'. 
    282      '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. 
    283      form::combo('lang',$lang_combo,$lang).'</p> '. 
    284      '</div>'. 
    285       
    286      '<div class="cell filters-options">'. 
    287      '<h4>'.__('Display options').'</h4>'. 
    288      '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. 
    289      form::combo('sortby',$sortby_combo,$sortby).'</p>'. 
    290      '<p><label for="order" class="ib">'.__('Sort:').'</label> '. 
    291      form::combo('order',$order_combo,$order).'</p>'. 
    292      '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. 
    293      form::field('nb',3,3,$nb_per_page).' '. 
    294      __('entries per page').'</label></p>'. 
    295      '</div>'. 
    296      '</div>'. 
     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'); 
    297178 
    298      '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. 
    299      '<br class="clear" /></p>'. //Opera sucks 
    300      '</form>'; 
    301       
    302      # Show posts 
    303      $post_list->display($page,$nb_per_page, 
    304      '<form action="posts.php" method="post" id="form-entries">'. 
    305       
    306      '%s'. 
    307       
    308      '<div class="two-cols">'. 
    309      '<p class="col checkboxes-helpers"></p>'. 
    310       
    311      '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. 
    312      form::combo('action',$posts_actions_page->getCombo()). 
    313      '<input type="submit" value="'.__('ok').'" /></p>'. 
    314      form::hidden(array('user_id'),$user_id). 
    315      form::hidden(array('cat_id'),$cat_id). 
    316      form::hidden(array('status'),$status). 
    317      form::hidden(array('selected'),$selected). 
    318      form::hidden(array('attachment'),$attachment). 
    319      form::hidden(array('month'),$month). 
    320      form::hidden(array('lang'),$lang). 
    321      form::hidden(array('sortby'),$sortby). 
    322      form::hidden(array('order'),$order). 
    323      form::hidden(array('page'),$page). 
    324      form::hidden(array('nb'),$nb_per_page). 
    325      $core->formNonce(). 
    326      '</div>'. 
    327      '</form>', 
    328      $show_filters 
    329      ); 
    330 } 
     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')); 
    331186 
    332 dcPage::helpBlock('core_posts'); 
    333 dcPage::close(); 
     187 
     188$lposts->setup(); 
     189 
     190$_ctx 
     191     ->setBreadCrumb(array(__('Entries') => 'posts.php')); 
     192 
     193 
     194$core->tpl->display('posts.html.twig'); 
     195 
    334196 
    335197?> 
  • 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

    r2306 r2313  
    9999 
    100100          self::jsLoadIE7(). 
    101           '  <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 
     101          '    <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 
    102102          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') { 
    103103               echo 
    104                '  <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 
     104               '    <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 
    105105          } 
    106106 
     
    112112               '<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />'; 
    113113          } 
     114 
    114115          echo 
    115116          self::jsCommon(). 
     
    307308 
    308309          self::jsLoadIE7(). 
    309           '    <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 
     310          '    <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />'."\n"; 
    310311          if (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl') { 
    311312               echo 
    312                '    <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 
     313               '    <link rel="stylesheet" href="style/default-rtl.css" type="text/css" media="screen" />'."\n"; 
    313314          } 
    314315 
     
    571572          "//<![CDATA[\n". 
    572573          self::jsVar('dotclear.nonce',$GLOBALS['core']->getNonce()). 
     574 
    573575          self::jsVar('dotclear.img_plus_src','images/expand.png'). 
    574576          self::jsVar('dotclear.img_plus_alt',__('uncover')). 
     
    577579          self::jsVar('dotclear.img_menu_on','images/menu_on.png'). 
    578580          self::jsVar('dotclear.img_menu_off','images/menu_off.png'). 
    579            
     581 
    580582          self::jsVar('dotclear.img_plus_theme_src','images/plus-theme.png'). 
    581583          self::jsVar('dotclear.img_plus_theme_alt',__('uncover')). 
     
    682684          self::jsVar('dotclear.msg.module_tags', 
    683685               __('Tags:')). 
    684                "\n//]]>\n". 
     686          "\n//]]>\n". 
    685687          "</script>\n"; 
    686688     } 
     
    722724               $default = "'".html::escapeJS($default)."'"; 
    723725          } 
    724            
     726 
    725727          return 
    726728          self::jsLoad('js/jquery/jquery.pageTabs.js'). 
     
    744746     public static function jsModal() 
    745747     { 
    746           return 
    747           '<link rel="stylesheet" type="text/css" href="style/modal/modal.css" />'."\n". 
    748           self::jsLoad('js/jquery/jquery.modal.js'). 
    749           '<script type="text/javascript">'."\n". 
    750           "//<![CDATA[\n". 
    751           self::jsVar('$.modal.prototype.params.loader_img','style/modal/loader.gif'). 
    752           self::jsVar('$.modal.prototype.params.close_img','style/modal/close.png'). 
    753           "\n//]]>\n". 
    754           "</script>\n"; 
     748     return 
     749     '<link rel="stylesheet" type="text/css" href="style/modal/modal.css" />'."\n". 
     750     self::jsLoad('js/jquery/jquery.modal.js'). 
     751     '<script type="text/javascript">'."\n". 
     752     "//<![CDATA[\n". 
     753     self::jsVar('$.modal.prototype.params.loader_img','style/modal/loader.gif'). 
     754     self::jsVar('$.modal.prototype.params.close_img','style/modal/close.png'). 
     755     "\n//]]>\n". 
     756     "</script>\n"; 
    755757     } 
    756758 
    757759     public static function jsColorPicker() 
    758760     { 
    759           return 
    760           '<link rel="stylesheet" type="text/css" href="style/farbtastic/farbtastic.css" />'."\n". 
    761           self::jsLoad('js/jquery/jquery.farbtastic.js'). 
    762           self::jsLoad('js/color-picker.js'); 
     761     return 
     762     '<link rel="stylesheet" type="text/css" href="style/farbtastic/farbtastic.css" />'."\n". 
     763     self::jsLoad('js/jquery/jquery.farbtastic.js'). 
     764     self::jsLoad('js/color-picker.js'); 
    763765     } 
    764766 
    765767     public static function jsDatePicker() 
    766768     { 
    767           return 
    768           '<link rel="stylesheet" type="text/css" href="style/date-picker.css" />'."\n". 
    769           self::jsLoad('js/date-picker.js'). 
    770           '<script type="text/javascript">'."\n". 
    771           "//<![CDATA[\n". 
    772  
    773           "datePicker.prototype.months[0] = '".html::escapeJS(__('January'))."'; ". 
    774           "datePicker.prototype.months[1] = '".html::escapeJS(__('February'))."'; ". 
    775           "datePicker.prototype.months[2] = '".html::escapeJS(__('March'))."'; ". 
    776           "datePicker.prototype.months[3] = '".html::escapeJS(__('April'))."'; ". 
    777           "datePicker.prototype.months[4] = '".html::escapeJS(__('May'))."'; ". 
    778           "datePicker.prototype.months[5] = '".html::escapeJS(__('June'))."'; ". 
    779           "datePicker.prototype.months[6] = '".html::escapeJS(__('July'))."'; ". 
    780           "datePicker.prototype.months[7] = '".html::escapeJS(__('August'))."'; ". 
    781           "datePicker.prototype.months[8] = '".html::escapeJS(__('September'))."'; ". 
    782           "datePicker.prototype.months[9] = '".html::escapeJS(__('October'))."'; ". 
    783           "datePicker.prototype.months[10] = '".html::escapeJS(__('November'))."'; ". 
    784           "datePicker.prototype.months[11] = '".html::escapeJS(__('December'))."'; ". 
    785  
    786           "datePicker.prototype.days[0] = '".html::escapeJS(__('Monday'))."'; ". 
    787           "datePicker.prototype.days[1] = '".html::escapeJS(__('Tuesday'))."'; ". 
    788           "datePicker.prototype.days[2] = '".html::escapeJS(__('Wednesday'))."'; ". 
    789           "datePicker.prototype.days[3] = '".html::escapeJS(__('Thursday'))."'; ". 
    790           "datePicker.prototype.days[4] = '".html::escapeJS(__('Friday'))."'; ". 
    791           "datePicker.prototype.days[5] = '".html::escapeJS(__('Saturday'))."'; ". 
    792           "datePicker.prototype.days[6] = '".html::escapeJS(__('Sunday'))."'; ". 
    793  
    794           "datePicker.prototype.img_src = 'images/date-picker.png'; ". 
    795  
    796           "datePicker.prototype.close_msg = '".html::escapeJS(__('close'))."'; ". 
    797           "datePicker.prototype.now_msg = '".html::escapeJS(__('now'))."'; ". 
    798  
    799           "\n//]]>\n". 
    800           "</script>\n"; 
     769     return 
     770     '<link rel="stylesheet" type="text/css" href="style/date-picker.css" />'."\n". 
     771     self::jsLoad('js/date-picker.js'). 
     772     '<script type="text/javascript">'."\n". 
     773     "//<![CDATA[\n". 
     774 
     775     "datePicker.prototype.months[0] = '".html::escapeJS(__('January'))."'; ". 
     776     "datePicker.prototype.months[1] = '".html::escapeJS(__('February'))."'; ". 
     777     "datePicker.prototype.months[2] = '".html::escapeJS(__('March'))."'; ". 
     778     "datePicker.prototype.months[3] = '".html::escapeJS(__('April'))."'; ". 
     779     "datePicker.prototype.months[4] = '".html::escapeJS(__('May'))."'; ". 
     780     "datePicker.prototype.months[5] = '".html::escapeJS(__('June'))."'; ". 
     781     "datePicker.prototype.months[6] = '".html::escapeJS(__('July'))."'; ". 
     782     "datePicker.prototype.months[7] = '".html::escapeJS(__('August'))."'; ". 
     783     "datePicker.prototype.months[8] = '".html::escapeJS(__('September'))."'; ". 
     784     "datePicker.prototype.months[9] = '".html::escapeJS(__('October'))."'; ". 
     785     "datePicker.prototype.months[10] = '".html::escapeJS(__('November'))."'; ". 
     786     "datePicker.prototype.months[11] = '".html::escapeJS(__('December'))."'; ". 
     787 
     788     "datePicker.prototype.days[0] = '".html::escapeJS(__('Monday'))."'; ". 
     789     "datePicker.prototype.days[1] = '".html::escapeJS(__('Tuesday'))."'; ". 
     790     "datePicker.prototype.days[2] = '".html::escapeJS(__('Wednesday'))."'; ". 
     791     "datePicker.prototype.days[3] = '".html::escapeJS(__('Thursday'))."'; ". 
     792     "datePicker.prototype.days[4] = '".html::escapeJS(__('Friday'))."'; ". 
     793     "datePicker.prototype.days[5] = '".html::escapeJS(__('Saturday'))."'; ". 
     794     "datePicker.prototype.days[6] = '".html::escapeJS(__('Sunday'))."'; ". 
     795 
     796     "datePicker.prototype.img_src = 'images/date-picker.png'; ". 
     797 
     798     "datePicker.prototype.close_msg = '".html::escapeJS(__('close'))."'; ". 
     799     "datePicker.prototype.now_msg = '".html::escapeJS(__('now'))."'; ". 
     800 
     801     "\n//]]>\n". 
     802     "</script>\n"; 
    801803     } 
    802804 
    803805     public static function jsToolBar() 
    804806     { 
    805           $res = 
    806           '<link rel="stylesheet" type="text/css" href="style/jsToolBar/jsToolBar.css" />'. 
    807           '<script type="text/javascript" src="js/jsToolBar/jsToolBar.js"></script>'; 
    808  
    809           if (isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('enable_wysiwyg')) { 
    810                $res .= '<script type="text/javascript" src="js/jsToolBar/jsToolBar.wysiwyg.js"></script>'; 
    811           } 
    812  
    813           $res .= 
    814           '<script type="text/javascript" src="js/jsToolBar/jsToolBar.dotclear.js"></script>'. 
    815           '<script type="text/javascript">'."\n". 
    816           "//<![CDATA[\n". 
    817           "jsToolBar.prototype.dialog_url = 'popup.php'; ". 
    818           "jsToolBar.prototype.iframe_css = '". 
    819           'body{'. 
    820           'font: 12px "DejaVu Sans","Lucida Grande","Lucida Sans Unicode",Arial,sans-serif;'. 
    821           'color : #000;'. 
    822           'background: #f9f9f9;'. 
    823           'margin: 0;'. 
    824           'padding : 2px;'. 
    825           'border: none;'. 
    826           (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl' ? 'direction:rtl;' : ''). 
    827           '}'. 
    828           'pre, code, kbd, samp {'. 
    829           'font-family:"Courier New",Courier,monospace;'. 
    830           'font-size : 1.1em;'. 
    831           '}'. 
    832           'code {'. 
    833           'color : #666;'. 
    834           'font-weight : bold;'. 
    835           '}'. 
    836           'body > p:first-child {'. 
    837           'margin-top: 0;'. 
    838           '}'. 
    839           "'; ". 
    840           "jsToolBar.prototype.base_url = '".html::escapeJS($GLOBALS['core']->blog->host)."'; ". 
    841           "jsToolBar.prototype.switcher_visual_title = '".html::escapeJS(__('visual'))."'; ". 
    842           "jsToolBar.prototype.switcher_source_title = '".html::escapeJS(__('source'))."'; ". 
    843           "jsToolBar.prototype.legend_msg = '". 
    844           html::escapeJS(__('You can use the following shortcuts to format your text.'))."'; ". 
    845           "jsToolBar.prototype.elements.blocks.options.none = '".html::escapeJS(__('-- none --'))."'; ". 
    846           "jsToolBar.prototype.elements.blocks.options.nonebis = '".html::escapeJS(__('-- block format --'))."'; ". 
    847           "jsToolBar.prototype.elements.blocks.options.p = '".html::escapeJS(__('Paragraph'))."'; ". 
    848           "jsToolBar.prototype.elements.blocks.options.h1 = '".html::escapeJS(__('Level 1 header'))."'; ". 
    849           "jsToolBar.prototype.elements.blocks.options.h2 = '".html::escapeJS(__('Level 2 header'))."'; ". 
    850           "jsToolBar.prototype.elements.blocks.options.h3 = '".html::escapeJS(__('Level 3 header'))."'; ". 
    851           "jsToolBar.prototype.elements.blocks.options.h4 = '".html::escapeJS(__('Level 4 header'))."'; ". 
    852           "jsToolBar.prototype.elements.blocks.options.h5 = '".html::escapeJS(__('Level 5 header'))."'; ". 
    853           "jsToolBar.prototype.elements.blocks.options.h6 = '".html::escapeJS(__('Level 6 header'))."'; ". 
    854           "jsToolBar.prototype.elements.strong.title = '".html::escapeJS(__('Strong emphasis'))."'; ". 
    855           "jsToolBar.prototype.elements.em.title = '".html::escapeJS(__('Emphasis'))."'; ". 
    856           "jsToolBar.prototype.elements.ins.title = '".html::escapeJS(__('Inserted'))."'; ". 
    857           "jsToolBar.prototype.elements.del.title = '".html::escapeJS(__('Deleted'))."'; ". 
    858           "jsToolBar.prototype.elements.quote.title = '".html::escapeJS(__('Inline quote'))."'; ". 
    859           "jsToolBar.prototype.elements.code.title = '".html::escapeJS(__('Code'))."'; ". 
    860           "jsToolBar.prototype.elements.br.title = '".html::escapeJS(__('Line break'))."'; ". 
    861           "jsToolBar.prototype.elements.blockquote.title = '".html::escapeJS(__('Blockquote'))."'; ". 
    862           "jsToolBar.prototype.elements.pre.title = '".html::escapeJS(__('Preformated text'))."'; ". 
    863           "jsToolBar.prototype.elements.ul.title = '".html::escapeJS(__('Unordered list'))."'; ". 
    864           "jsToolBar.prototype.elements.ol.title = '".html::escapeJS(__('Ordered list'))."'; ". 
    865  
    866           "jsToolBar.prototype.elements.link.title = '".html::escapeJS(__('Link'))."'; ". 
    867           "jsToolBar.prototype.elements.link.href_prompt = '".html::escapeJS(__('URL?'))."'; ". 
    868           "jsToolBar.prototype.elements.link.hreflang_prompt = '".html::escapeJS(__('Language?'))."'; ". 
    869  
    870           "jsToolBar.prototype.elements.img.title = '".html::escapeJS(__('External image'))."'; ". 
    871           "jsToolBar.prototype.elements.img.src_prompt = '".html::escapeJS(__('URL?'))."'; ". 
    872  
    873           "jsToolBar.prototype.elements.img_select.title = '".html::escapeJS(__('Media chooser'))."'; ". 
    874           "jsToolBar.prototype.elements.post_link.title = '".html::escapeJS(__('Link to an entry'))."'; "; 
    875  
    876           if (!$GLOBALS['core']->auth->check('media,media_admin',$GLOBALS['core']->blog->id)) { 
    877                $res .= "jsToolBar.prototype.elements.img_select.disabled = true;\n"; 
    878           } 
    879  
    880           $res .= 
    881           "\n//]]>\n". 
    882           "</script>\n"; 
    883  
    884           return $res; 
     807     $res = 
     808     '<link rel="stylesheet" type="text/css" href="style/jsToolBar/jsToolBar.css" />'. 
     809     '<script type="text/javascript" src="js/jsToolBar/jsToolBar.js"></script>'; 
     810 
     811     if (isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('enable_wysiwyg')) { 
     812          $res .= '<script type="text/javascript" src="js/jsToolBar/jsToolBar.wysiwyg.js"></script>'; 
     813     } 
     814 
     815     $res .= 
     816     '<script type="text/javascript" src="js/jsToolBar/jsToolBar.dotclear.js"></script>'. 
     817     '<script type="text/javascript">'."\n". 
     818     "//<![CDATA[\n". 
     819     "jsToolBar.prototype.dialog_url = 'popup.php'; ". 
     820     "jsToolBar.prototype.iframe_css = '". 
     821     'body{'. 
     822     'font: 12px "DejaVu Sans","Lucida Grande","Lucida Sans Unicode",Arial,sans-serif;'. 
     823     'color : #000;'. 
     824     'background: #f9f9f9;'. 
     825     'margin: 0;'. 
     826     'padding : 2px;'. 
     827     'border: none;'. 
     828     (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl' ? 'direction:rtl;' : ''). 
     829     '}'. 
     830     'pre, code, kbd, samp {'. 
     831     'font-family:"Courier New",Courier,monospace;'. 
     832     'font-size : 1.1em;'. 
     833     '}'. 
     834     'code {'. 
     835     'color : #666;'. 
     836     'font-weight : bold;'. 
     837     '}'. 
     838     'body > p:first-child {'. 
     839     'margin-top: 0;'. 
     840     '}'. 
     841     "'; ". 
     842     "jsToolBar.prototype.base_url = '".html::escapeJS($GLOBALS['core']->blog->host)."'; ". 
     843     "jsToolBar.prototype.switcher_visual_title = '".html::escapeJS(__('visual'))."'; ". 
     844     "jsToolBar.prototype.switcher_source_title = '".html::escapeJS(__('source'))."'; ". 
     845     "jsToolBar.prototype.legend_msg = '". 
     846     html::escapeJS(__('You can use the following shortcuts to format your text.'))."'; ". 
     847     "jsToolBar.prototype.elements.blocks.options.none = '".html::escapeJS(__('-- none --'))."'; ". 
     848     "jsToolBar.prototype.elements.blocks.options.nonebis = '".html::escapeJS(__('-- block format --'))."'; ". 
     849     "jsToolBar.prototype.elements.blocks.options.p = '".html::escapeJS(__('Paragraph'))."'; ". 
     850     "jsToolBar.prototype.elements.blocks.options.h1 = '".html::escapeJS(__('Level 1 header'))."'; ". 
     851     "jsToolBar.prototype.elements.blocks.options.h2 = '".html::escapeJS(__('Level 2 header'))."'; ". 
     852     "jsToolBar.prototype.elements.blocks.options.h3 = '".html::escapeJS(__('Level 3 header'))."'; ". 
     853     "jsToolBar.prototype.elements.blocks.options.h4 = '".html::escapeJS(__('Level 4 header'))."'; ". 
     854     "jsToolBar.prototype.elements.blocks.options.h5 = '".html::escapeJS(__('Level 5 header'))."'; ". 
     855     "jsToolBar.prototype.elements.blocks.options.h6 = '".html::escapeJS(__('Level 6 header'))."'; ". 
     856     "jsToolBar.prototype.elements.strong.title = '".html::escapeJS(__('Strong emphasis'))."'; ". 
     857     "jsToolBar.prototype.elements.em.title = '".html::escapeJS(__('Emphasis'))."'; ". 
     858     "jsToolBar.prototype.elements.ins.title = '".html::escapeJS(__('Inserted'))."'; ". 
     859     "jsToolBar.prototype.elements.del.title = '".html::escapeJS(__('Deleted'))."'; ". 
     860     "jsToolBar.prototype.elements.quote.title = '".html::escapeJS(__('Inline quote'))."'; ". 
     861     "jsToolBar.prototype.elements.code.title = '".html::escapeJS(__('Code'))."'; ". 
     862     "jsToolBar.prototype.elements.br.title = '".html::escapeJS(__('Line break'))."'; ". 
     863     "jsToolBar.prototype.elements.blockquote.title = '".html::escapeJS(__('Blockquote'))."'; ". 
     864     "jsToolBar.prototype.elements.pre.title = '".html::escapeJS(__('Preformated text'))."'; ". 
     865     "jsToolBar.prototype.elements.ul.title = '".html::escapeJS(__('Unordered list'))."'; ". 
     866     "jsToolBar.prototype.elements.ol.title = '".html::escapeJS(__('Ordered list'))."'; ". 
     867 
     868     "jsToolBar.prototype.elements.link.title = '".html::escapeJS(__('Link'))."'; ". 
     869     "jsToolBar.prototype.elements.link.href_prompt = '".html::escapeJS(__('URL?'))."'; ". 
     870     "jsToolBar.prototype.elements.link.hreflang_prompt = '".html::escapeJS(__('Language?'))."'; ". 
     871 
     872     "jsToolBar.prototype.elements.img.title = '".html::escapeJS(__('External image'))."'; ". 
     873     "jsToolBar.prototype.elements.img.src_prompt = '".html::escapeJS(__('URL?'))."'; ". 
     874 
     875     "jsToolBar.prototype.elements.img_select.title = '".html::escapeJS(__('Media chooser'))."'; ". 
     876     "jsToolBar.prototype.elements.post_link.title = '".html::escapeJS(__('Link to an entry'))."'; "; 
     877 
     878     if (!$GLOBALS['core']->auth->check('media,media_admin',$GLOBALS['core']->blog->id)) { 
     879          $res .= "jsToolBar.prototype.elements.img_select.disabled = true;\n"; 
     880     } 
     881 
     882     $res .= 
     883     "\n//]]>\n". 
     884     "</script>\n"; 
     885 
     886     return $res; 
    885887     } 
    886888 
    887889     public static function jsUpload($params=array(),$base_url=null) 
    888890     { 
    889           if (!$base_url) { 
    890                $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/','',$_SERVER['REQUEST_URI']))).'/'; 
    891           } 
    892  
    893           $params = array_merge($params,array( 
    894                'sess_id='.session_id(), 
    895                'sess_uid='.$_SESSION['sess_browser_uid'], 
    896                'xd_check='.$GLOBALS['core']->getNonce() 
     891     if (!$base_url) { 
     892          $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/','',$_SERVER['REQUEST_URI']))).'/'; 
     893     } 
     894 
     895     $params = array_merge($params,array( 
     896          'sess_id='.session_id(), 
     897          'sess_uid='.$_SESSION['sess_browser_uid'], 
     898          'xd_check='.$GLOBALS['core']->getNonce() 
    897899          )); 
    898900 
    899           return 
    900           '<script type="text/javascript">'."\n". 
    901           "//<![CDATA[\n". 
    902           "dotclear.jsUpload = {};\n". 
    903           "dotclear.jsUpload.msg = {};\n". 
    904           self::jsVar('dotclear.msg.enhanced_uploader_activate',__('Temporarily activate enhanced uploader')). 
    905           self::jsVar('dotclear.msg.enhanced_uploader_disable',__('Temporarily disable enhanced uploader')). 
    906           self::jsVar('dotclear.jsUpload.msg.limit_exceeded',__('Limit exceeded.')). 
    907           self::jsVar('dotclear.jsUpload.msg.size_limit_exceeded',__('File size exceeds allowed limit.')). 
    908           self::jsVar('dotclear.jsUpload.msg.canceled',__('Canceled.')). 
    909           self::jsVar('dotclear.jsUpload.msg.http_error',__('HTTP Error:')). 
    910           self::jsVar('dotclear.jsUpload.msg.error',__('Error:')). 
    911           self::jsVar('dotclear.jsUpload.msg.choose_file',__('Choose file')). 
    912           self::jsVar('dotclear.jsUpload.msg.choose_files',__('Choose files')). 
    913           self::jsVar('dotclear.jsUpload.msg.cancel',__('Cancel')). 
    914           self::jsVar('dotclear.jsUpload.msg.clean',__('Clean')). 
    915           self::jsVar('dotclear.jsUpload.msg.upload',__('Upload')). 
     901     return 
     902     '<script type="text/javascript">'."\n". 
     903     "//<![CDATA[\n". 
     904     "dotclear.jsUpload = {};\n". 
     905     "dotclear.jsUpload.msg = {};\n". 
     906     self::jsVar('dotclear.msg.enhanced_uploader_activate',__('Temporarily activate enhanced uploader')). 
     907     self::jsVar('dotclear.msg.enhanced_uploader_disable',__('Temporarily disable enhanced uploader')). 
     908     self::jsVar('dotclear.jsUpload.msg.limit_exceeded',__('Limit exceeded.')). 
     909     self::jsVar('dotclear.jsUpload.msg.size_limit_exceeded',__('File size exceeds allowed limit.')). 
     910     self::jsVar('dotclear.jsUpload.msg.canceled',__('Canceled.')). 
     911     self::jsVar('dotclear.jsUpload.msg.http_error',__('HTTP Error:')). 
     912     self::jsVar('dotclear.jsUpload.msg.error',__('Error:')). 
     913     self::jsVar('dotclear.jsUpload.msg.choose_file',__('Choose file')). 
     914     self::jsVar('dotclear.jsUpload.msg.choose_files',__('Choose files')). 
     915     self::jsVar('dotclear.jsUpload.msg.cancel',__('Cancel')). 
     916     self::jsVar('dotclear.jsUpload.msg.clean',__('Clean')). 
     917     self::jsVar('dotclear.jsUpload.msg.upload',__('Upload')). 
    916918          self::jsVar('dotclear.jsUpload.msg.send',__('Send')). 
    917919          self::jsVar('dotclear.jsUpload.msg.file_successfully_uploaded',__('File successfully uploaded.')). 
    918           self::jsVar('dotclear.jsUpload.msg.no_file_in_queue',__('No file in queue.')). 
    919           self::jsVar('dotclear.jsUpload.msg.file_in_queue',__('1 file in queue.')). 
    920           self::jsVar('dotclear.jsUpload.msg.files_in_queue',__('%d files in queue.')). 
    921           self::jsVar('dotclear.jsUpload.msg.queue_error',__('Queue error:')). 
    922           self::jsVar('dotclear.jsUpload.base_url',$base_url). 
    923           "\n//]]>\n". 
     920     self::jsVar('dotclear.jsUpload.msg.no_file_in_queue',__('No file in queue.')). 
     921     self::jsVar('dotclear.jsUpload.msg.file_in_queue',__('1 file in queue.')). 
     922     self::jsVar('dotclear.jsUpload.msg.files_in_queue',__('%d files in queue.')). 
     923     self::jsVar('dotclear.jsUpload.msg.queue_error',__('Queue error:')). 
     924     self::jsVar('dotclear.jsUpload.base_url',$base_url). 
     925     "\n//]]>\n". 
    924926          "</script>\n". 
    925927 
     
    938940     public static function jsToolMan() 
    939941     { 
    940           return 
    941           '<script type="text/javascript" src="js/tool-man/core.js"></script>'. 
    942           '<script type="text/javascript" src="js/tool-man/events.js"></script>'. 
    943           '<script type="text/javascript" src="js/tool-man/css.js"></script>'. 
    944           '<script type="text/javascript" src="js/tool-man/coordinates.js"></script>'. 
    945           '<script type="text/javascript" src="js/tool-man/drag.js"></script>'. 
    946           '<script type="text/javascript" src="js/tool-man/dragsort.js"></script>'. 
    947           '<script type="text/javascript" src="js/dragsort-tablerows.js"></script>'; 
     942     return 
     943     '<script type="text/javascript" src="js/tool-man/core.js"></script>'. 
     944     '<script type="text/javascript" src="js/tool-man/events.js"></script>'. 
     945     '<script type="text/javascript" src="js/tool-man/css.js"></script>'. 
     946     '<script type="text/javascript" src="js/tool-man/coordinates.js"></script>'. 
     947     '<script type="text/javascript" src="js/tool-man/drag.js"></script>'. 
     948     '<script type="text/javascript" src="js/tool-man/dragsort.js"></script>'. 
     949     '<script type="text/javascript" src="js/dragsort-tablerows.js"></script>'; 
    948950     } 
    949951 
    950952     public static function jsMetaEditor() 
    951953     { 
    952           return 
    953           '<script type="text/javascript" src="js/meta-editor.js"></script>'; 
     954     return 
     955     '<script type="text/javascript" src="js/meta-editor.js"></script>'; 
    954956     } 
    955957} 
  • inc/admin/prepend.php

    r2277 r2313  
    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 
     
    219219     $core->plugins->loadModules(DC_PLUGINS_ROOT,'admin',$_lang); 
    220220     $core->favs->setup(); 
    221       
     221 
    222222     if (!$user_ui_nofavmenu) { 
    223223          $core->favs->appendMenu($_menu); 
     
    273273          $core->auth->isSuperAdmin() || 
    274274          $core->auth->check('usage,contentadmin',$core->blog->id) && $core->auth->getBlogCount() > 1); 
    275       
     275 
    276276     if (empty($core->blog->settings->system->jquery_migrate_mute)) { 
    277277          $core->blog->settings->system->put('jquery_migrate_mute', true, 'boolean', 'Mute warnings for jquery migrate plugin ?', false); 
    278278     } 
    279279} 
     280 
     281# Add admin default templates path 
     282$core->tpl->getLoader()->addPath(dirname(__FILE__).'/default-templates'); 
     283# Set admin context 
     284$_ctx = new dcAdminContext($core); 
     285$core->tpl->addExtension($_ctx); 
     286 
     287# --BEHAVIOR-- adminPrepend 
     288$core->callBehavior('adminPrepend',$core,$_ctx); 
    280289?> 
  • inc/core/class.dc.blog.php

    r2312 r2313  
    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); 
     
    875875           
    876876          if (!empty($params['user_id'])) { 
    877                $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
     877               $strReq .= "AND U.user_id ".$this->con->in($params['user_id'])." "; 
    878878          } 
    879879           
     
    969969                    $strReq .= 'ORDER BY post_dt DESC '; 
    970970               } 
    971           } 
    972            
    973           if (!$count_only && !empty($params['limit'])) { 
    974                $strReq .= $this->con->limit($params['limit']); 
     971               if (!empty($params['limit'])) { 
     972                    $strReq .= $this->con->limit($params['limit']); 
     973               } 
    975974          } 
    976975           
  • inc/core/class.dc.core.php

    r2198 r2313  
    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; 
     
    9798          $this->addFormater('xhtml', create_function('$s','return $s;')); 
    9899          $this->addFormater('wiki', array($this,'wikiTransform')); 
     100          $this->loadTemplateEnvironment(); 
    99101     } 
    100102      
     
    120122     } 
    121123      
     124     /** 
     125     Create template environment (Twig_Environment instance) 
     126      
     127     default-templates path must be added from admin|public/prepend.php with: 
     128     $core->tpl->getLoader()->addPath('PATH_TO/default-templates'); 
     129     Selected theme path must be added with: 
     130     $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 
     131     */ 
     132     public function loadTemplateEnvironment() 
     133     { 
     134          $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 
     135          if (!is_dir($cache_dir)) { 
     136               try { 
     137                    files::makeDir($cache_dir); 
     138               } catch (Exception $e) { 
     139                    $cache_dir = false; 
     140               } 
     141          } 
     142           
     143          $this->tpl = new Twig_Environment( 
     144               new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'), 
     145               array( 
     146                    'auto_reload' => true, 
     147                    'autoescape' => false, 
     148                    'base_template_class' => 'Twig_Template', 
     149                    'cache' => $cache_dir,  
     150                    'charset' => 'UTF-8', 
     151                    'debug' => DC_DEBUG, 
     152                    'optimizations' => -1, 
     153                    'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables! 
     154               ) 
     155          ); 
     156          $this->tpl->addExtension(new dcFormExtension($this)); 
     157          $this->tpl->addExtension(new dcTabExtension($this)); 
     158     } 
    122159      
    123160     /// @name Blog init methods 
  • inc/prepend.php

    r2286 r2313  
    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$__autoload['dcStore']             = dirname(__FILE__).'/core/class.dc.store.php'; 
    4950$__autoload['dcStoreReader']       = dirname(__FILE__).'/core/class.dc.store.reader.php'; 
     
    5657$__autoload['rsExtUser']                = dirname(__FILE__).'/core/class.dc.rs.extensions.php'; 
    5758 
     59$__autoload['dcAdminContext']                = dirname(__FILE__).'/admin/class.dc.admincontext.php'; 
    5860$__autoload['dcMenu']                   = dirname(__FILE__).'/admin/class.dc.menu.php'; 
    5961$__autoload['dcPage']                   = dirname(__FILE__).'/admin/lib.dc.page.php'; 
     
    7476$__autoload['dcCommentsActionsPage']              = dirname(__FILE__).'/admin/actions/class.dcactioncomments.php'; 
    7577$__autoload['dcActionsPage']            = dirname(__FILE__).'/admin/actions/class.dcaction.php'; 
     78$__autoload['dcForm']              = dirname(__FILE__).'/admin/class.dc.form.php'; 
     79$__autoload['dcFormExtension']               = dirname(__FILE__).'/admin/class.dc.form.php'; 
     80$__autoload['dcTabExtension']           = dirname(__FILE__).'/admin/class.dc.tab.php'; 
     81$__autoload['dcItemList']               = dirname(__FILE__).'/admin/class.dc.list.php'; 
     82$__autoload['dcListFetcher']            = dirname(__FILE__).'/admin/class.dc.list.php'; 
     83 
     84foreach (array('dcFilterSet', 'dcFilter','dcFilterCombo','dcFilterText','dcFilterBoolean') as $c) { 
     85     $__autoload[$c] = dirname(__FILE__).'/admin/class.dc.filter.php'; 
     86} 
    7687 
    7788# Clearbricks extensions 
    7889html::$absolute_regs[] = '/(<param\s+name="movie"\s+value=")(.*?)(")/msu'; 
    7990html::$absolute_regs[] = '/(<param\s+name="FlashVars"\s+value=".*?(?:mp3|flv)=)(.*?)(&|")/msu'; 
     91 
     92if (@is_dir('/usr/lib/twig')) { 
     93     define('TWIG_PATH','/usr/lib/Twig'); 
     94} elseif (is_dir(dirname(__FILE__).'/libs/Twig')) { 
     95     define('TWIG_PATH',dirname(__FILE__).'/libs/Twig'); 
     96} elseif (isset($_SERVER['TWIG_PATH']) && is_dir($_SERVER['TWIG_PATH'])) { 
     97     define('TWIG_PATH',$_SERVER['TWIG_PATH']); 
     98} 
     99 
     100if (!defined('TWIG_PATH') || !is_dir(TWIG_PATH)) { 
     101     exit('No Twig path defined'); 
     102} 
     103require TWIG_PATH.'/Autoloader.php'; 
     104Twig_Autoloader::register(); 
     105 
    80106/* ------------------------------------------------------------------------------------------- */ 
    81107 
     
    134160# Constants 
    135161define('DC_ROOT',path::real(dirname(__FILE__).'/..')); 
    136 define('DC_VERSION','2.6-dev'); 
     162define('DC_VERSION','2.99-dev'); 
    137163define('DC_DIGESTS',dirname(__FILE__).'/digests'); 
    138164define('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

    r2256 r2313  
    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); 
     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; 
     73          } 
     74           
     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; 
    3585               } 
    36                 
    37                $core->blog->triggerBlog(); 
    3886          } 
    39  
    40           dcPage::addSuccessNotice(__('Configuration successfully updated')); 
    41           http::redirect($p_url); 
    42      } 
    43      catch (Exception $e) 
    44      { 
    45           $core->error->add($e->getMessage()); 
     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(); 
    46128     } 
    47129} 
    48130 
    49 # Global settings update 
    50 if (!empty($_POST['gs']) && is_array($_POST['gs'])) 
    51 { 
    52      try 
    53      { 
    54           foreach ($_POST['gs'] as $ns => $s) 
    55           { 
    56                $core->blog->settings->addNamespace($ns); 
    57                 
    58                foreach ($s as $k => $v)      { 
    59                     $core->blog->settings->$ns->put($k,$v,null,null,true,true); 
    60                } 
    61                 
    62                $core->blog->triggerBlog(); 
    63           } 
    64            
    65           dcPage::addSuccessNotice(__('Configuration successfully updated')); 
    66           http::redirect($p_url.'&part=global'); 
    67      } 
    68      catch (Exception $e) 
    69      { 
    70           $core->error->add($e->getMessage()); 
    71      } 
     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')); 
    72140} 
    73  
    74 $part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 
    75  
    76 function settingLine($id,$s,$ns,$field_name,$strong_label) 
    77 { 
    78      if ($s['type'] == 'boolean') { 
    79           $field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id), 
    80           array(__('yes') => 1, __('no') => 0),$s['value'] ? 1 : 0); 
    81      } else { 
    82           $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id),40,null, 
    83           html::escapeHTML($s['value'])); 
    84      } 
    85       
    86      $slabel = $strong_label ? '<strong>%s</strong>' : '%s'; 
    87       
    88      return 
    89      '<tr class="line">'. 
    90      '<td scope="row"><label for="'.$field_name.'_'.$ns.'_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'. 
    91      '<td>'.$field.'</td>'. 
    92      '<td>'.$s['type'].'</td>'. 
    93      '<td>'.html::escapeHTML($s['label']).'</td>'. 
    94      '</tr>'; 
     141if (!empty($_GET['upda'])) { 
     142     $_ctx->setAlert(__('Settings definition successfully updated')); 
    95143} 
     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'); 
    96147?> 
    97 <html> 
    98 <head> 
    99   <title>about:config</title> 
    100   <?php echo dcPage::jsPageTabs($part); ?> 
    101   <script type="text/javascript"> 
    102      //<![CDATA[ 
    103      $(function() { 
    104           $("#gs_submit").hide(); 
    105           $("#ls_submit").hide(); 
    106           $("#gs_nav").change(function() { 
    107                window.location = $("#gs_nav option:selected").val(); 
    108           }) 
    109           $("#ls_nav").change(function() { 
    110                window.location = $("#ls_nav option:selected").val(); 
    111           }) 
    112      }); 
    113      //]]> 
    114      </script> 
    115 </head> 
    116  
    117 <body> 
    118 <?php 
    119 echo dcPage::breadcrumb( 
    120      array( 
    121           __('System') => '', 
    122           html::escapeHTML($core->blog->name) => '', 
    123           __('about:config') => '' 
    124      )). 
    125      dcPage::notices(); 
    126 ?> 
    127  
    128 <div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>"> 
    129 <h3 class="out-of-screen-if-js"><?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?></h3> 
    130  
    131 <?php 
    132 $table_header = '<div class="table-outer"><table class="settings" id="%s"><caption class="as_h3">%s</caption>'. 
    133 '<thead>'. 
    134 '<tr>'."\n". 
    135 '  <th class="nowrap">Setting ID</th>'."\n". 
    136 '  <th>'.__('Value').'</th>'."\n". 
    137 '  <th>'.__('Type').'</th>'."\n". 
    138 '  <th class="maximalx">'.__('Description').'</th>'."\n". 
    139 '</tr>'."\n". 
    140 '</thead>'."\n". 
    141 '<tbody>'; 
    142 $table_footer = '</tbody></table></div>'; 
    143  
    144 $settings = array(); 
    145 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    146      foreach ($namespace->dumpSettings() as $k => $v) { 
    147           $settings[$ns][$k] = $v; 
    148      } 
    149 } 
    150 ksort($settings); 
    151 if (count($settings) > 0) { 
    152      $ns_combo = array(); 
    153      foreach ($settings as $ns => $s) { 
    154           $ns_combo[$ns] = '#l_'.$ns; 
    155      } 
    156      echo  
    157           '<form action="plugin.php" method="post">'. 
    158           '<p class="anchor-nav">'. 
    159           '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo). 
    160           ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'. 
    161           '<input type="hidden" name="p" value="aboutConfig" />'. 
    162           $core->formNonce().'</p></form>'; 
    163 } 
    164 ?> 
    165  
    166 <form action="plugin.php" method="post"> 
    167  
    168 <?php 
    169 foreach ($settings as $ns => $s) 
    170 { 
    171      ksort($s); 
    172      echo sprintf($table_header,'l_'.$ns,$ns); 
    173      foreach ($s as $k => $v) 
    174      { 
    175           echo settingLine($k,$v,$ns,'s',!$v['global']); 
    176      } 
    177      echo $table_footer; 
    178 } 
    179 ?> 
    180  
    181 <p><input type="submit" value="<?php echo __('Save'); ?>" /> 
    182 <input type="hidden" name="p" value="aboutConfig" /> 
    183 <?php echo $core->formNonce(); ?></p> 
    184 </form> 
    185 </div> 
    186  
    187 <div id="global" class="multi-part" title="<?php echo __('Global settings'); ?>"> 
    188 <h3 class="out-of-screen-if-js"><?php echo __('Global settings'); ?></h3> 
    189  
    190 <?php 
    191 $settings = array(); 
    192  
    193 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    194      foreach ($namespace->dumpGlobalSettings() as $k => $v) { 
    195           $settings[$ns][$k] = $v; 
    196      } 
    197 } 
    198  
    199 ksort($settings); 
    200  
    201 if (count($settings) > 0) { 
    202      $ns_combo = array(); 
    203      foreach ($settings as $ns => $s) { 
    204           $ns_combo[$ns] = '#g_'.$ns; 
    205      } 
    206      echo  
    207           '<form action="plugin.php" method="post">'. 
    208           '<p class="anchor-nav">'. 
    209           '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).' '. 
    210           '<input type="submit" value="'.__('Ok').'" id="gs_submit" />'. 
    211           '<input type="hidden" name="p" value="aboutConfig" />'. 
    212           $core->formNonce().'</p></form>'; 
    213 } 
    214 ?> 
    215  
    216 <form action="plugin.php" method="post"> 
    217  
    218 <?php 
    219 foreach ($settings as $ns => $s) 
    220 { 
    221      ksort($s); 
    222      echo sprintf($table_header,'g_'.$ns,$ns); 
    223      foreach ($s as $k => $v) 
    224      { 
    225           echo settingLine($k,$v,$ns,'gs',false); 
    226      } 
    227      echo $table_footer; 
    228 } 
    229 ?> 
    230  
    231 <p><input type="submit" value="<?php echo __('Save'); ?>" /> 
    232 <input type="hidden" name="p" value="aboutConfig" /> 
    233 <?php echo $core->formNonce(); ?></p> 
    234 </form> 
    235 </div> 
    236  
    237 </body> 
    238 </html> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map