Dotclear

Changeset 1414:ce67e9c592b7


Ignore:
Timestamp:
08/16/13 15:48:37 (12 years ago)
Author:
Dsls
Branch:
twig
Message:
  • reworked breadcrumb
  • tuned checkboxes (need to see if it works for multiple values)
  • magic methods for dcForm are more intuitive now, getField method added
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • admin/index.php

    r1413 r1414  
    304304} 
    305305 
    306 $_ctx->fillPageTitle(__('Dashboard')); 
     306$_ctx->setBreadCrumb(__('Dashboard').' : '.html::escapeHTML($core->blog->name), false); 
    307307$core->tpl->display('index.html.twig'); 
    308308?> 
  • admin/js/_post.js

    r1280 r1414  
    127127               fn: function() { excerptTb.switchMode(formatField.value); }, 
    128128               cookie: 'dcx_post_excerpt', 
    129                hide: $('#post_excerpt').val() == '' 
     129               hide: $('#post_excerpt').val() == '', 
     130               legend_click: true 
    130131          }); 
    131132           
  • admin/plugin.php

    r1413 r1414  
    9090# No plugin or content found 
    9191if (!$has_content) { 
    92      $_ctx->fillPageTitle(__('Plugin not found')); 
     92     $_ctx->setBreadcrumb(__('Plugin not found')); 
    9393     $_ctx->addError(__('The plugin you reached does not exist or does not have an admin page.')); 
    9494     $core->tpl->display('plugin.html.twig'); 
  • admin/post.php

    r1413 r1414  
    1515dcPage::check('usage,contentadmin'); 
    1616 
    17 function savePost($form) { 
    18      global $_ctx; 
    19      $_ctx->setAlert('save'); 
    20  
    21 } 
    22  
    23 function deletePost($form) { 
    24      print_r($form); exit; 
     17class PostActions  
     18{ 
     19     public static function savePost($form) { 
     20          global $_ctx, $core; 
     21          try { 
     22               $form->check($_ctx); 
     23               $_ctx->setAlert('save'); 
     24               $form->cat_id = (integer) $form->cat_id; 
     25      
     26               if (!empty($form->post_dt)) { 
     27                    try 
     28                    { 
     29                         $post_dt = strtotime($form->post_dt); 
     30                         if ($post_dt == false || $post_dt == -1) { 
     31                              $bad_dt = true; 
     32                              throw new Exception(__('Invalid publication date')); 
     33                         } 
     34                         $form->post_dt = date('Y-m-d H:i',$post_dt); 
     35                    } 
     36                    catch (Exception $e) 
     37                    { 
     38                         $core->error->add($e->getMessage()); 
     39                    } 
     40               } 
     41               $post_excerpt = $form->post_excerpt; 
     42               $post_content = $form->post_content; 
     43               $post_excerpt_xhtml = ''; 
     44               $post_content_xhtml = ''; 
     45               $core->blog->setPostContent( 
     46                    $form->id,$form->post_format,$form->post_lang, 
     47                    $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 
     48               ); 
     49               $form->post_excerpt = $post_excerpt; 
     50               $form->post_content = $post_content; 
     51               $form->post_excerpt_xhtml = $post_excerpt_xhtml; 
     52               $form->post_content_xhtml = $post_content_xhtml; 
     53                
     54               $cur = $core->con->openCursor($core->prefix.'post'); 
     55      
     56               $cur->post_title = $form->post_title; 
     57               $cur->cat_id = $form->cat_id ? $form->cat_id : null; 
     58               $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : ''; 
     59               $cur->post_format = $form->post_format; 
     60               $cur->post_password = $form->post_password; 
     61               $cur->post_lang = $form->post_lang; 
     62               $cur->post_title = $form->post_title; 
     63               $cur->post_excerpt = $form->post_excerpt; 
     64               $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml; 
     65               $cur->post_content = $form->post_content; 
     66               $cur->post_content_xhtml = $form->post_content_xhtml; 
     67               $cur->post_notes = $form->post_notes; 
     68               $cur->post_status = $form->post_status; 
     69               $cur->post_selected = (integer) $form->post_selected; 
     70               $cur->post_open_comment = (integer) $form->post_open_comment; 
     71               $cur->post_open_tb = (integer) $form->post_open_tb; 
     72      
     73               if (!empty($form->post_url)) { 
     74                    $cur->post_url = $form->post_url; 
     75               } 
     76      
     77               # Update post 
     78               if ($form->id) 
     79               { 
     80                    # --BEHAVIOR-- adminBeforePostUpdate 
     81                    $core->callBehavior('adminBeforePostUpdate',$cur,$form->id); 
     82                     
     83                    $core->blog->updPost($form->id,$cur); 
     84                     
     85                    # --BEHAVIOR-- adminAfterPostUpdate 
     86                    $core->callBehavior('adminAfterPostUpdate',$cur,$form->id); 
     87                     
     88                    http::redirect('post.php?id='.$form->id.'&upd=1'); 
     89               } 
     90               else 
     91               { 
     92                    $cur->user_id = $core->auth->userID(); 
     93                                        # --BEHAVIOR-- adminBeforePostCreate 
     94                    $core->callBehavior('adminBeforePostCreate',$cur); 
     95                     
     96                    $return_id = $core->blog->addPost($cur); 
     97                     
     98                    # --BEHAVIOR-- adminAfterPostCreate 
     99                    $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 
     100                     
     101                    http::redirect('post.php?id='.$return_id.'&crea=1'); 
     102               } 
     103 
     104     } catch (Exception $e) { 
     105          $ctx->setError($e->getMessage()); 
     106     } 
     107} 
     108     function deletePost($form) { 
     109          echo $form->id->getValue(); exit; 
     110     } 
    25111} 
    26112 
    27113$page_title = __('New entry'); 
    28  
     114$post_id=''; 
    29115$can_view_page = true; 
    30116$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); 
     
    67153$rs = $core->blog->getLangs(array('order'=>'asc')); 
    68154$all_langs = l10n::getISOcodes(0,1); 
    69 $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); 
     155$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1)); 
    70156while ($rs->fetch()) { 
    71157     if (isset($all_langs[$rs->post_lang])) { 
    72           $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; 
    73           unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); 
     158          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 
     159          unset($lang_combo[__('Available')][$rs->post_lang]); 
    74160     } else { 
    75           $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; 
     161          $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 
    76162     } 
    77163} 
     
    83169     ->addField( 
    84170          new dcFieldText('post_title','', array( 
    85                'size'         => 20, 
     171               'maxlength'         => 255, 
    86172               'required'     => true, 
    87173               'label'        => __('Title')))) 
     
    100186     ->addField( 
    101187          new dcFieldSubmit('save',__('Save'),array( 
    102                'action' => 'savePost'))) 
     188               'action' => array('PostActions','savePost')))) 
    103189     ->addField( 
    104190          new dcFieldSubmit('delete',__('Delete'),array( 
     
    124210               "label" => __('Accept trackbacks')))) 
    125211     ->addField( 
    126           new dcFieldCheckbox ('post_selected',false,array( 
     212          new dcFieldCheckbox ('post_selected',array(1=>false),array( 
    127213               "label" => __('Selected entry')))) 
    128214     ->addField( 
     
    225311     $default_tab = 'comments'; 
    226312} 
    227  
     313$page_title_edit = __('Edit entry'); 
    228314$_ctx 
    229      ->fillPageTitle(html::escapeHTML($core->blog->name)) 
    230      ->fillPageTitle(__('Entries'),'posts.php') 
    231      ->fillPageTitle($page_title) 
     315     ->setBreadCrumb( 
     316          array( 
     317               html::escapeHTML($core->blog->name) => '', 
     318               __('Entries') => 'posts.php', 
     319               ($post_id ? $page_title_edit : $page_title) => '' 
     320     )) 
    232321     ->default_tab = $default_tab; 
    233322 
  • admin/posts.php

    r1413 r1414  
    187187 
    188188$_ctx 
    189      ->fillPageTitle(__('Entries'),'posts.php'); 
     189     ->setBreadCrumb(array(__('Entries') => 'posts.php')); 
    190190 
    191191 
  • inc/admin/class.dc.admincontext.php

    r1319 r1414  
    354354      
    355355     /** 
    356      Fill the page title 
     356     Add a section to the breadcrumb 
    357357      
    358358     $title can be:  
     
    365365     @return object self 
    366366     */ 
    367      public function fillPageTitle($title,$url='') 
    368      { 
    369           if (is_bool($title)) { 
    370                $this->protected_globals['page_global'] = $title; 
    371           } 
    372           elseif (null === $title) { 
    373                $this->protected_globals['page_global'] = false; 
    374                $this->protected_globals['page_title'] = array(); 
    375           } 
    376           else { 
    377                $this->protected_globals['page_title'][] = array( 
    378                     'title' => $title, 
    379                     'link' => $url 
    380                ); 
     367     public function appendBreadCrumbItem($title,$url='',$class='') 
     368     { 
     369          $this->protected_globals['page_title'][] = array( 
     370               'title' => $title, 
     371               'link' => $url, 
     372               'class' => $class 
     373          ); 
     374     } 
     375      
     376     /** 
     377     Fill the page title 
     378      
     379     $title can be:  
     380     a string for page title part or  
     381     TRUE to add blog name at the begining of title or 
     382     NULL to empty/reset title 
     383      
     384     @param mixed $title A title part 
     385     @param boolean $url Link of the title part 
     386     @return object self 
     387     */ 
     388     public function setBreadCrumb($breadcrumb, $with_home_link=true) 
     389     { 
     390          if ($with_home_link) { 
     391               $this->appendBreadCrumbItem('<img src="style/dashboard.png" alt="" />','index.php','go_home'); 
     392          } else { 
     393               $this->appendBreadCrumbItem('<img src="style/dashboard-alt.png" alt="" />'.$breadcrumb); 
     394               return $this; 
     395          } 
     396          if (is_array($breadcrumb)) { 
     397               foreach ($breadcrumb as $title => $bc) { 
     398                    $this->appendBreadCrumbItem($title,$bc); 
     399               } 
     400          } else { 
     401               $this->appendBreadcrumbItem($breadcrumb); 
    381402          } 
    382403          return $this; 
  • inc/admin/class.dc.form.php

    r1319 r1414  
    277277     public function renderField($name,$attributes=array(),$extra=array()) 
    278278     { 
    279           $field = $this->currentForm->$name; 
     279          $field = $this->currentForm->getField($name); 
    280280          if ($field) { 
    281281               $attr = $field->getAttributes($attributes); 
     
    396396     /** @var array(dcField) list of form errors */ 
    397397     protected $errors; 
    398  
     398     /** @var array() list of form properties */ 
     399     protected $properties; 
     400      
     401      
    399402    /** 
    400403     * Class constructor 
     
    420423          $this->hiddenfields = array(); 
    421424          $this->errors = array(); 
     425          $this->properties = array(); 
    422426          if ($method == 'POST') { 
    423427               $this->addNonce(); 
     
    425429     } 
    426430 
     431      
     432    /** 
     433     * setProperty - sets form property 
     434     *  
     435     * @param string $name the property name. 
     436     * @param mixed $value the property value. 
     437     * 
     438     * @access public 
     439     */ 
     440     public function setProperty($prop,$value) { 
     441          $this->properties[$prop]=$value; 
     442     } 
     443      
     444    /** 
     445     * getProperty - gets form property 
     446     *  
     447     * @param string $name the property name. 
     448      * 
     449     * @return mixed the property value, null if no property found. 
     450     * @access public 
     451     */    
     452     public function getProperty($prop) { 
     453          if (isset($this->properties[$prop])) { 
     454               return $this->properties[$prop]; 
     455          } else { 
     456               return null; 
     457          } 
     458     } 
    427459    /** 
    428460     * addTemplate - Adds a template file to enrich form fields 
     
    532564     } 
    533565 
     566    /** 
     567     * getField - retrieves a field form form 
     568     * 
     569     * @param string the field name 
     570     * 
     571     * @access public 
     572     * 
     573     * @return dcForm the requested field 
     574     */    
     575      public function getField($name) { 
     576          if (isset($this->fields[$name])) { 
     577               return $this->fields[$name]; 
     578          } else { 
     579               return null; 
     580          } 
     581     } 
     582      
    534583    /** 
    535584     * removeField - removes a field 
     
    634683     public function __get($name) 
    635684     { 
    636           return isset($this->fields[$name]) ? 
    637                $this->fields[$name] : null; 
     685          if (isset($this->fields[$name])) { 
     686               $f = $this->fields[$name]; 
     687               if ($f->isMultiple()) { 
     688                    return $f->getValues(); 
     689               } else { 
     690                    return $f->getValue(); 
     691               } 
     692          } else { 
     693               return $this->getProperty($name); 
     694          } 
    638695     } 
    639696 
     
    650707     { 
    651708          if (isset($this->fields[$name])) { 
    652                $this->fields[$name]->setValue($value); 
    653           } 
    654      } 
    655  
    656 /*   public function isSubmitted() 
    657      { 
    658           $from = $this->method == 'POST' ? $_POST : $_GET; 
    659      } 
    660 */ 
     709               $f = $this->fields[$name]; 
     710               if ($f->isMultiple()) { 
     711                    $this->fields[$name]->setValues($value); 
     712               } else { 
     713                    $this->fields[$name]->setValue($value); 
     714               } 
     715          } else { 
     716               $this->setProperty($name,$value); 
     717          } 
     718     } 
    661719 
    662720    /** 
     
    667725     protected function setupFields() { 
    668726          $from = $this->method == 'POST' ? $_POST : $_GET; 
    669           foreach ($this->fields as $f) { 
    670                $f->setup($from); 
     727          if (!empty($from)) { 
     728               foreach ($this->fields as $f) { 
     729                    $f->setup($from); 
     730               } 
    671731          } 
    672732     } 
     
    680740     */ 
    681741     protected function handleActions($submitted) { 
     742          $hasActions = false; 
    682743          foreach ($submitted as $f) { 
    683744               $action = $f->getAction(); 
    684745               if ($action != NULL) { 
     746                    if (!$hasActions) { 
     747                         $this->core->callBehavior('coreBeforeFormSubmit',$this); 
     748                    } 
     749                    $hasActions = true; 
    685750                    $ret = call_user_func($action,$this); 
    686751               } 
     752          } 
     753          if ($hasActions) { 
     754               $this->core->callBehavior('coreAfterFormSubmit',$this); 
    687755          } 
    688756     } 
     
    706774 
    707775    /** 
     776     * isSubmitted - returns whether form has been submitted or not 
     777     * 
     778     * @access public 
     779     * 
     780     * @return boolean true if the form has been submitted. 
     781     */    
     782     public function isSubmitted() { 
     783          foreach ($this->submitfields as $f) { 
     784               if ($f->isDefined()) { 
     785                    return true; 
     786               } 
     787          } 
     788          return false;        
     789     } 
     790      
     791    /** 
    708792     * setup - sets up the form, given the parameters given to the page 
    709793     *              should be called after fields have been defined. 
     
    726810     * @access public 
    727811     */ 
    728      public function check() 
    729      { 
     812     public function check(dcAdminContext $ctx) 
     813     { 
     814          $valid = true; 
    730815          foreach ($this->fields as $f) { 
    731816               try { 
     
    733818               } 
    734819               catch (InvalidFieldException $e) { 
    735                     $this->errors[] = $e->getMessage(); 
     820                    $valid = false; 
     821                    $ctx->addError($e->getMessage()); 
    736822               } 
     823          } 
     824          if (!$valid) { 
     825               throw new InvalidFieldException ("Some fields are missing"); 
    737826          } 
    738827     } 
     
    796885 
    797886    /** 
     887     * defines whether a field is multiple or not 
     888     * 
     889     * @param boolean true if the field is multiple 
     890      * 
     891     * @access public 
     892     */ 
     893     public function setMultiple($m=true) { 
     894          $this->multiple = $m; 
     895     } 
     896      
     897    /** 
     898     * Returns whether can have multiple values or not 
     899     * 
     900     * @return boolean true if the field has multiple values 
     901      * 
     902     * @access public 
     903     */ 
     904     public function isMultiple($m=true) { 
     905          return $this->multiple; 
     906     } 
     907 
     908    /** 
    798909     * setNID - defines fiels name & id 
    799910     * 
     
    9051016     abstract public function getWidgetBlock(); 
    9061017      
     1018     public function isEmpty() { 
     1019          return (count($this->values) == 0) || empty($this->values[0]); 
     1020     } 
    9071021 
    9081022    /** 
     
    9771091     public function check() 
    9781092     { 
    979           if (!$this->defined && $this->options['mandatory']) { 
    980                throw new InvalidFieldException(sprintf( 
    981                     'Field "%s" is mandatory', 
    982                     $this->attributes['label']) 
    983                ); 
     1093          if (isset($this->options ['required']) && $this->options['required']) { 
     1094               if (!$this->defined || $this->isEmpty()) { 
     1095                    throw new InvalidFieldException(sprintf( 
     1096                         'Field "%s" is mandatory', 
     1097                         $this->options['label']) 
     1098                    ); 
     1099               } 
    9841100          } 
    9851101     } 
     
    10881204class dcFieldCheckbox extends dcField 
    10891205{ 
     1206     protected $checked; 
     1207      
     1208     public function __construct($name,$values,$options=array()) 
     1209     { 
     1210          $val = array(); 
     1211          if (!is_array($values)) { 
     1212               $values = array("1" => !empty($values)); 
     1213          } 
     1214          $this->checked = $values; 
     1215          parent::__construct($name,array_keys($values),$options); 
     1216     } 
     1217 
     1218    /** 
     1219     * setValue - sets field value 
     1220     * 
     1221     * @param mixed $value  field value. 
     1222     * @param int   $offset value offset to define (default 0). 
     1223     * 
     1224     * @access public 
     1225     */ 
     1226     public function setValue($value,$offset=0) { 
     1227          $this->checked[$this->values[0]] = $value; 
     1228     } 
     1229      
     1230     public function getValue($offset=0) { 
     1231          $val = parent::getValue($offset); 
     1232          if (isset($this->checked[$val])) { 
     1233               return $this->checked[$val]?$val:false; 
     1234          } else { 
     1235               return false; 
     1236          } 
     1237     } 
     1238      
     1239     public function getAttributes($options) 
     1240     { 
     1241          $a = parent::getAttributes($options); 
     1242           
     1243          $val = $a['value']; 
     1244          if (isset($this->checked[$val]) && $this->checked[$val]) { 
     1245               $a['checked']='checked'; 
     1246          } 
     1247          return $a; 
     1248     } 
     1249 
     1250     public function setup($from) 
     1251     { 
     1252          $values = $this->parseValues($from); 
     1253          foreach ($this->checked as $k=>&$v) { 
     1254               $v=false; 
     1255          } 
     1256          foreach ($values as $v) { 
     1257               $this->checked[$v] = true; 
     1258          } 
     1259          $this->setValues(array_keys($this->checked)); 
     1260     } 
     1261 
    10901262     public function getWidgetBlock() 
    10911263     { 
     
    10941266 
    10951267     public function getDefaultValue() { 
    1096           return 0; 
     1268          return false; 
    10971269     } 
    10981270} 
     
    11391311{ 
    11401312     protected $combo; 
     1313     protected $combo_values; 
    11411314 
    11421315     public function __construct($name,$value,$combo,$options=array()) 
    11431316     { 
    11441317          $this->combo = $combo; 
     1318          $this->combo_values = $combo; 
     1319          foreach ($combo as $k=>$v) { 
     1320               if (is_array($v)) { 
     1321                    unset($this->combo_values[$k]); 
     1322                    $this->combo_values = array_merge($v,$this->combo_values); 
     1323               } 
     1324          } 
    11451325          parent::__construct($name,$value,$options); 
    11461326     } 
     
    11611341          } 
    11621342          foreach ($values as &$v) { 
    1163                if (!isset($this->combo[$v])) 
    1164                $v = $this->getDefaultValue(); 
     1343               if (!isset($this->combo_values[$v])) { 
     1344                    $v = $this->getDefaultValue(); 
     1345               } 
    11651346          } 
    11661347          return $values; 
  • inc/admin/default-templates/forms/form_layout.html.twig

    r1319 r1414  
    5757{% block field_attr %} 
    5858{% spaceless %} 
    59  {% if id %}id="{{id}}"{% endif %} name="{{name}}" {% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if maxlength %} maxlength="{{ maxlength }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %} 
     59 {% if id %}id="{{id}}"{% endif %} name="{{name}}" {% if read_only %} disabled="disabled"{% endif %}{#{% if required %} required="required"{% endif %}#}{% if maxlength %} maxlength="{{ maxlength }}"{% endif %}{% if checked %} checked="{{ checked }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %} 
    6060    {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %} 
    6161{% endspaceless %} 
  • inc/admin/default-templates/layout.html.twig

    r1319 r1414  
    55     {% block header %} 
    66     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    7      <title>{% block title %}{% for part in page_title %}{{ part.title }} - {% endfor %}{% if current_blog.name is not empty %}{{current_blog.name}} - {% endif %}{{vendor_name}} - {{version}}{% endblock %}</title> 
     7     <title>{% block title %}{{  (page_title|last).title|striptags }} - {% if current_blog.name is not empty %}{{current_blog.name}} - {% endif %}{{vendor_name}} - {{version}}{% endblock %}</title> 
    88     <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" /> 
    99     <meta name="GOOGLEBOT" content="NOSNIPPET" /> 
     
    5959                    {% endif %} 
    6060                    <h2> 
    61                          {%- if not page_global %}{{current_blog.name}} &rsaquo; {% endif %} 
     61                         {#{%- if not page_global %}{{current_blog.name}} &rsaquo; {% endif %}#} 
    6262                         {%- for part in page_title %} 
    6363                              {%- if loop.last %}<span class="page-title">{% endif %} 
    64                               {%- if part.link is not empty %}<a href="{{ part.link }}">{{ part.title }}</a>{% else %}{{ part.title }}{% endif %} 
    65                               {%- if loop.last %}</span>{% else %} &rsaquo; {% endif %} 
     64                              {%- if part.link is not empty %}<a href="{{ part.link }}"{% if part.class is not empty %} class="{{part.class}}"{% endif %}>{{ part.title }}</a>{% else %}{{ part.title }}{% endif %} 
     65                              {%- if loop.last %}</span>{% else %} {% if loop.index0 == 1 %} : {% else %} &rsaquo; {% endif %}{% endif %} 
    6666                         {%- endfor -%} 
    6767                    </h2> 
  • plugins/aboutConfig/index.php

    r1315 r1414  
    143143} 
    144144$_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 
    145 $_ctx->fillPageTitle('about:config'); 
     145$_ctx->setBreadCrumb('about:config'); 
    146146$core->tpl->display('@aboutConfig/index.html.twig'); 
    147147?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map