Dotclear


Ignore:
Timestamp:
03/08/13 15:37:34 (12 years ago)
Author:
Dsls <dsls@…>
Branch:
twig
Message:

Oops, I did it again (c).

Fist draft of merge from formfilters to dctwig. lists need to be broken up too.

From now all post lists are broken.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/class.dc.form.php

    r1090 r1147  
    1313 
    1414/** 
    15  * Template form node 
    16  */ 
     15* dcFormNode 
     16* 
     17* @uses     Twig_Node 
     18* 
     19*/ 
    1720class dcFormNode extends Twig_Node 
    1821{ 
     
    3033     { 
    3134          $compiler 
    32                ->addDebugInfo($this) 
    33                ->write("\$context['dc_form']->beginForm('". 
    34                     $this->getAttribute('name')."');\n") 
     35               ->addDebugInfo($this); 
     36          $compiler 
     37               ->write("\$context['dc_form']->beginForm(") 
     38               ->subcompile($this->getAttribute('name')) 
     39               ->write(");\n"); 
     40          $compiler 
    3541               ->subcompile($this->getNode('body')) 
    3642               ->write("\$context['dc_form']->renderHiddenWidgets();\n") 
     
    4955          $lineno = $token->getLine(); 
    5056          $stream = $this->parser->getStream(); 
    51           $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); 
     57          $name = $this->parser->getExpressionParser()->parseExpression(); 
    5258          $stream->expect(Twig_Token::BLOCK_END_TYPE); 
    5359          $body = $this->parser->subparse(array($this,'decideBlockEnd'),true); 
     
    7783     protected $core; 
    7884     protected $twig; 
    79      protected $blocks; 
    8085     protected $forms; 
    8186     protected $currentForm; 
     87     protected $blocks; 
    8288      
    8389     public function __construct($core) 
     
    96102     } 
    97103      
     104     public function addTemplate($tpl) { 
     105          $t = $this->twig->loadTemplate($tpl); 
     106          $this->blocks = array_merge($this->blocks,$t->getBlocks()); 
     107     } 
     108 
    98109     public function getGlobals() 
    99110     { 
     
    137148     } 
    138149      
    139      public function renderWidget($name,$attributes=array()) 
     150     public function renderBlock($name,$attr) { 
     151          echo $this->template->renderBlock( 
     152               $name, 
     153               $attr, 
     154               $this->blocks 
     155          ); 
     156     } 
     157 
     158     public function getCurrentForm() { 
     159          return $this->currentForm; 
     160     } 
     161 
     162     public function renderWidget($name,$attributes=array(),$extra=array()) 
    140163     { 
    141164          $field = $this->currentForm->$name; 
    142165          if ($field) { 
    143                echo $this->template->renderBlock( 
     166               $attr = $field->getAttributes(); 
     167               if (isset($attr['attr'])) { 
     168                    $attr['attr'] = array_merge($attr['attr'],$attributes); 
     169               } else { 
     170                    $attr['attr'] = $attributes; 
     171               } 
     172               $this->renderBlock( 
    144173                    $field->getWidgetBlock(), 
    145174                    array_merge( 
    146                          $field->getAttributes(), 
    147                          array('attr' => $attributes) 
    148                     ), 
    149                     $this->blocks 
     175                         $attr, 
     176                         $extra 
     177                    ) 
    150178               ); 
    151179          } 
     
    197225 
    198226/** 
    199  * Template form 
    200  */ 
     227* dcForm - Template form 
     228* 
     229*/ 
    201230class dcForm 
    202231{ 
     
    211240     protected $errors; 
    212241      
    213      private function addNonce() 
     242 
     243    /** 
     244     * addNonce -- adds dc nonce to form fields 
     245     *  
     246     * @access protected 
     247     * 
     248     * @return nothing 
     249     */ 
     250     protected function addNonce() 
    214251     { 
    215252          $this->addField( 
     
    219256     } 
    220257      
    221      protected function getNID($nid) 
     258 
     259    /** 
     260     * Defines Name & ID from field 
     261     *  
     262     * @param mixed $nid either an array (name, id) or a string (name only, id will be set to null). 
     263     * 
     264     * @access protected 
     265     * 
     266     * @return nothing. 
     267     */ 
     268     protected function setNID($nid) 
    222269     { 
    223270          if (is_array($nid)) { 
     
    231278     } 
    232279      
     280     public function getContext() { 
     281          return array(); 
     282     } 
     283 
     284    /** 
     285     * Class constructor 
     286     *  
     287     * @param mixed  $core   dotclear core 
     288     * @param mixed  $name   form name 
     289     * @param mixed  $action form action 
     290     * @param string $method form method ('GET' or 'POST') 
     291     * 
     292     * @access public 
     293     * 
     294     * @return mixed Value. 
     295     */ 
    233296     public function __construct($core,$name,$action,$method='POST') 
    234297     { 
    235298          $this->core = $core; 
    236           $this->getNID($name); 
     299          $this->setNID($name); 
    237300          $this->method = $method; 
    238301          $this->action = $action; 
     
    247310     } 
    248311      
     312 
     313    /** 
     314     * Returns form name 
     315     *  
     316     * @access public 
     317     * 
     318     * @return mixed Value. 
     319     */ 
    249320     public function getName() 
    250321     { 
     
    270341     } 
    271342      
     343     public function removeField(dcField $f) { 
     344          $n = $f->getName(); 
     345          if (isset($this->fields[$n])){ 
     346               unset($this->fields[$n]); 
     347          } 
     348 
     349     } 
     350     public function renameField($field,$newname) { 
     351          $oldname = $field->getName(); 
     352          if (isset($this->fields[$oldname])) { 
     353               unset($this->fields[$oldname]); 
     354               $field->setName($newname); 
     355               $this->fields[$newname] = $field; 
     356          } 
     357          //print_r($this->fields); 
     358     } 
    272359     public function begin() 
    273360     { 
     
    292379     public function __get($name) 
    293380     { 
    294           return isset($this->fields[$name]) ?  
     381          return isset($this->fields[$name]) ? 
    295382               $this->fields[$name] : null; 
    296383     } 
    297       
     384 
    298385     public function __set($name,$value) 
    299386     { 
     
    302389          } 
    303390     } 
    304       
     391 
    305392     public function isSubmitted() 
    306393     { 
    307394          $from = $this->method == 'POST' ? $_POST : $_GET; 
    308           echo "form fields :\n"; 
    309      } 
    310       
    311      public function setup() 
    312      { 
     395     } 
     396 
     397     protected function setupFields() { 
    313398          $from = $this->method == 'POST' ? $_POST : $_GET; 
    314399          foreach ($this->fields as $f) { 
    315400               $f->setup($from); 
    316401          } 
     402     } 
     403 
     404     protected function handleActions($submitted) { 
     405          foreach ($submitted as $f) { 
     406               $action = $f->getAction(); 
     407               if ($action != NULL) { 
     408                    $ret = call_user_func($action,$this); 
     409               } 
     410          } 
     411     } 
     412 
     413     protected function getSubmittedFields() { 
     414          $s = array(); 
    317415          foreach ($this->submitfields as $f) { 
    318416               if ($f->isDefined()) { 
    319                     $ret = call_user_func($f->getAction(),$this); 
    320                     return; 
     417                    $s[$f->getName()] = $f; 
    321418               } 
    322419          } 
    323      } 
    324       
     420          return $s; 
     421     } 
     422 
     423     public function setup() 
     424     { 
     425          $this->setupFields(); 
     426          $submitted = $this->getSubmittedFields(); 
     427          $this->handleActions($submitted); 
     428     } 
     429 
    325430     public function check() 
    326431     { 
     
    352457     protected $defined; 
    353458      
    354      protected function getNID($nid) 
     459     protected function setNID($nid) 
    355460     { 
    356461          if (is_array($nid)) { 
     
    365470     public function __construct($name,$value,$attributes=array()) 
    366471     { 
    367           $this->getNID($name); 
     472          $this->setNID($name); 
    368473          $this->attributes = $attributes; 
    369           $this->value = $value; 
     474          $this->setValue($value); 
    370475          $this->attributes['name'] = $this->name; 
    371476          $this->attributes['id'] = $this->id; 
     477          $this->defined = false; 
     478     } 
     479      
     480     public function setValue($value) { 
     481          $this->value = $value; 
    372482          $this->attributes['value'] = $this->value; 
    373           $this->defined = false; 
    374      } 
    375       
     483     } 
     484 
     485     public function getValue() { 
     486          return $this->value; 
     487     } 
     488 
    376489     public function __toString() 
    377490     { 
     
    395508          return $this->name; 
    396509     } 
    397       
     510     public function setName($name) { 
     511          $this->setNID($name); 
     512          $this->attributes['name'] = $this->name; 
     513          $this->attributes['id'] = $this->id; 
     514     } 
     515 
    398516     public function check() 
    399517     { 
     
    406524     } 
    407525      
     526     public function parseValue($from) { 
     527          if (isset($from[$this->id])) { 
     528               return $from[$this->id]; 
     529          } 
     530          return null; 
     531     } 
     532 
    408533     public function setup($from) 
    409534     { 
    410           if (isset($from[$this->id])) { 
    411                $this->value = $from[$this->id]; 
     535          $value = $this->parseValue($from); 
     536          if ($value !== null) { 
     537               $this->setValue($value); 
    412538               $this->defined = true; 
    413539          } 
     
    488614          if (isset($attributes['action'])) { 
    489615               $this->action = $attributes['action']; 
     616          } else { 
     617               $this->action = NULL; 
    490618          } 
    491619     } 
     
    527655     } 
    528656 
     657     public function parseValue($from) { 
     658 
     659          $v = parent::parseValue($from); 
     660          if (!isset($this->options[$v])) { 
     661               return $this->value; 
     662          } else { 
     663               return $v; 
     664          } 
     665     } 
    529666} 
    530667?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map