Dotclear


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/widgets/class.widgets.php

    r2395 r1474  
    139139     public $append_callback = null; 
    140140     private $settings = array(); 
    141      private $advance_id; 
    142      private $advanced_settings = array(); 
    143141      
    144142     public function serialize($order) { 
     
    146144          foreach ($this->settings as $k=>$v) 
    147145               $values[$k]=$v['value']; 
    148           foreach ($this->advanced_settings as $k=>$v) 
    149                $values[$k]=$v['value']; 
    150146          $values['id']=$this->id; 
    151147          $values['order']=$order; 
     
    193189     public function __get($n) 
    194190     { 
    195           $setting = null; 
    196191          if (isset($this->settings[$n])) { 
    197                $setting = $this->settings[$n]['value']; 
    198           } else if (isset($this->advanced_settings[$n])) { 
    199                $setting = $this->advanced_settings[$n]['value']; 
    200           } 
    201           return $setting; 
     192               return $this->settings[$n]['value']; 
     193          } 
     194          return null; 
    202195     } 
    203196      
     
    206199          if (isset($this->settings[$n])) { 
    207200               $this->settings[$n]['value'] = $v; 
    208           } else if (isset($this->advanced_settings[$n])) { 
    209                $this->advanced_settings[$n]['value'] = $v; 
    210201          } 
    211202     } 
     
    231222     } 
    232223      
    233      public function advanced_setting($name,$title,$value,$type='text') 
    234      { 
    235           if ($type == 'combo' || $type == 'radio') { 
    236                $options = @func_get_arg(4); 
    237                if (!is_array($options)) { 
    238                     return false; 
    239                } 
    240           } 
    241            
    242           $this->advanced_settings[$name] = array( 
    243                'title' => $title, 
    244                'type' => $type, 
    245                'value' => $value 
    246           ); 
    247            
    248           if (isset($options)) { 
    249                $this->advanced_settings[$name]['options'] = $options; 
    250           } 
    251      } 
    252       
    253      public function advance_settings() 
    254      { 
    255           return $this->advanced_settings; 
    256      } 
    257       
    258224     public function settings() 
    259225     { 
     
    266232          foreach ($this->settings as $id => $s) 
    267233          { 
    268                $res .= $this->formSetting($id,$s,$pr,$i=0); 
     234               $wfid = "wf-".$i; 
     235               $iname = $pr ? $pr.'['.$id.']' : $id; 
     236               switch ($s['type']) 
     237               { 
     238                    case 'text': 
     239                         $res .= 
     240                         '<p><label for="'.$wfid.'">'.$s['title'].'</label> '. 
     241                         form::field(array($iname,$wfid),20,255,html::escapeHTML($s['value']),'maximal'). 
     242                         '</p>'; 
     243                         break; 
     244                    case 'textarea': 
     245                         $res .= 
     246                         '<p><label for="'.$wfid.'">'.$s['title'].'</label> '. 
     247                         form::textarea(array($iname,$wfid),30,5,html::escapeHTML($s['value']),'maximal'). 
     248                         '</p>'; 
     249                         break; 
     250                    case 'check': 
     251                         $res .= 
     252                         '<p>'.form::hidden(array($iname),'0'). 
     253                         '<label class="classic" for="'.$wfid.'">'. 
     254                         form::checkbox(array($iname,$wfid),'1',$s['value']).' '.$s['title']. 
     255                         '</label></p>'; 
     256                         break; 
     257                    case 'combo': 
     258                         $res .= 
     259                         '<p><label for="'.$wfid.'">'.$s['title'].'</label> '. 
     260                         form::combo(array($iname,$wfid),$s['options'],$s['value']). 
     261                         '</p>'; 
     262                         break; 
     263               } 
    269264               $i++; 
    270           } 
    271            
    272           if ( count($this->advanced_settings) > 0 ) 
    273           { 
    274                $res .= '<div class="widgetAdvancedSettings">'; 
    275                $res .= '<h5>'.__('Réglages avancés').'</h5>'; 
    276            
    277                foreach ($this->advanced_settings as $id => $s) 
    278                { 
    279                     $res .= $this->formSetting($id,$s,$pr,$i); 
    280                     $i++; 
    281                } 
    282                 
    283                $res .= '</div>'; 
    284           } 
    285            
    286           return $res; 
    287      } 
    288       
    289      public function formSetting($id,$s,$pr='',&$i=0) 
    290      { 
    291           $res = ''; 
    292           $wfid = "wf-".$i; 
    293           $iname = $pr ? $pr.'['.$id.']' : $id; 
    294           switch ($s['type']) 
    295           { 
    296                case 'text': 
    297                     $res .= 
    298                     '<p><label for="'.$wfid.'">'.$s['title'].'</label> '. 
    299                     form::field(array($iname,$wfid),20,255,html::escapeHTML($s['value']),'maximal'). 
    300                     '</p>'; 
    301                     break; 
    302                case 'textarea': 
    303                     $res .= 
    304                     '<p><label for="'.$wfid.'">'.$s['title'].'</label> '. 
    305                     form::textarea(array($iname,$wfid),30,5,html::escapeHTML($s['value']),'maximal'). 
    306                     '</p>'; 
    307                     break; 
    308                case 'check': 
    309                     $res .= 
    310                     '<p>'.form::hidden(array($iname),'0'). 
    311                     '<label class="classic" for="'.$wfid.'">'. 
    312                     form::checkbox(array($iname,$wfid),'1',$s['value']).' '.$s['title']. 
    313                     '</label></p>'; 
    314                     break; 
    315                case 'radio': 
    316                     $res .= '<p>'.($s['title'] ? '<label class="classic">'.$s['title'].'</label><br/>' : ''); 
    317                     if(!empty($s['options'])) { 
    318                          foreach ($s['options'] as $k => $v) { 
    319                               $res .= $k > 0 ? '<br/>' : ''; 
    320                               $res .= 
    321                               '<label class="classic" for="'.$wfid.'-'.$k.'">'. 
    322                               form::radio(array($iname,$wfid.'-'.$k),$v[1],$s['value'] == $v[1]).' '.$v[0]. 
    323                               '</label>'; 
    324                          } 
    325                     } 
    326                     $res .= '</p>'; 
    327                     break; 
    328                case 'combo': 
    329                     $res .= 
    330                     '<p><label for="'.$wfid.'">'.$s['title'].'</label> '. 
    331                     form::combo(array($iname,$wfid),$s['options'],$s['value']). 
    332                     '</p>'; 
    333                     break; 
    334265          } 
    335266           
Note: See TracChangeset for help on using the changeset viewer.

Sites map