Dotclear

Changeset 2679:bae19d3adbc4 for inc


Ignore:
Timestamp:
03/05/14 21:04:23 (11 years ago)
Author:
Nicolas <nikrou77@…>
Branch:
default
Message:

Addresses #1896 : add choice of editor in preferences
Keeps old functions in core addFormater(), callFormater() for compatibility.

Location:
inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.admincombos.php

    r2566 r2679  
    5151     */ 
    5252     public static function getPostStatusesCombo() { 
    53           $status_combo =  array(); 
     53          $status_combo =      array(); 
    5454          foreach (self::$core->blog->getAllPostStatus() as $k => $v) { 
    5555               $status_combo[$v] = (string) $k; 
     
    141141 
    142142     /** 
    143      Returns a combo containing all available formaters in admin 
    144  
    145      @return   <b>array</b> the combo box (form::combo -compatible format) 
    146      */ 
    147      public static function getFormatersCombo() { 
    148           foreach (self::$core->getFormaters() as $v) { 
    149                $formaters_combo[$v] = $v; 
    150           } 
     143     Returns a combo containing all available editors in admin 
     144 
     145     @return   <b>array</b> the combo box (form::combo -compatible format) 
     146     */ 
     147     public static function getEditorsCombo() 
     148     { 
     149          $editors_combo = array(); 
     150 
     151          foreach (self::$core->getEditors() as $v) { 
     152               $editors_combo[$v] = $v; 
     153          } 
     154           
     155          return $editors_combo; 
     156     } 
     157 
     158     /** 
     159     Returns a combo containing all available formaters by editor in admin 
     160 
     161     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...) 
     162     @return   <b>array</b> the combo box (form::combo -compatible format) 
     163     */ 
     164     public static function getFormatersCombo($editor_id='') 
     165     { 
     166          $formaters_combo = array(); 
     167 
     168        if (!empty($editor_id)) { 
     169            foreach (self::$core->getFormaters($editor_id) as $formater) { 
     170                $formaters_combo[$formater] = $formater; 
     171            } 
     172        } else { 
     173            foreach (self::$core->getFormaters() as $editor => $formaters) { 
     174                foreach ($formaters as $formater) { 
     175                    $formaters_combo[$editor][$formater] = $formater; 
     176                } 
     177            } 
     178        } 
     179 
    151180          return $formaters_combo; 
    152181     } 
  • inc/core/class.dc.core.php

    r2641 r2679  
    101101 
    102102          $this->log = new dcLog($this); 
    103  
    104           $this->addFormater('xhtml', create_function('$s','return $s;')); 
    105           $this->addFormater('wiki', array($this,'wikiTransform')); 
    106103     } 
    107104 
     
    211208     //@} 
    212209 
    213  
    214210     /// @name Text Formatters methods 
    215211     //@{ 
     
    219215     argument: the string to transform. It returns the transformed string. 
    220216 
     217     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...) 
     218     @param    name      <b>string</b>  Formater name 
     219     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback 
     220     */ 
     221     public function addEditorFormater($editor_id,$name,$func) 
     222     { 
     223          if (is_callable($func)) { 
     224               $this->formaters[$editor_id][$name] = $func; 
     225          } 
     226     } 
     227 
     228     /// @name Text Formatters methods 
     229     //@{ 
     230     /** 
     231     Adds a new text formater which will call the function <var>$func</var> to 
     232     transform text. The function must be a valid callback and takes one 
     233     argument: the string to transform. It returns the transformed string. 
     234 
    221235     @param    name      <b>string</b>       Formater name 
    222236     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback 
     
    224238     public function addFormater($name,$func) 
    225239     { 
    226           if (is_callable($func)) { 
    227                $this->formaters[$name] = $func; 
    228           } 
    229      } 
    230  
    231      /** 
    232      Returns formaters list. 
    233  
     240          $this->addEditorFormater('dcLegacyEditor',$name,$func); 
     241     } 
     242 
     243     /** 
     244     Returns editors list 
     245 
     246     @return   <b>array</b> An array of editors values. 
     247     */ 
     248     public function getEditors() 
     249     { 
     250          $editors = array(); 
     251 
     252          foreach (array_keys($this->formaters) as $editor_id) { 
     253               $editors[$editor_id] = $this->plugins->moduleInfo($editor_id,'name'); 
     254          } 
     255 
     256          return $editors; 
     257     } 
     258 
     259     /** 
     260     Returns formaters list by editor 
     261 
     262     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...) 
    234263     @return   <b>array</b> An array of formaters names in values. 
    235264     */ 
    236      public function getFormaters() 
    237      { 
    238           return array_keys($this->formaters); 
     265     public function getFormaters($editor_id='') 
     266     { 
     267          $formaters_list = array(); 
     268 
     269          if (!empty($editor_id) && isset($this->formaters[$editor_id])) { 
     270               $formaters_list = array_keys($this->formaters[$editor_id]); 
     271          } else { 
     272               foreach ($this->formaters as $editor => $formaters) { 
     273                    $formaters_list[$editor] = array_keys($formaters); 
     274               } 
     275          } 
     276 
     277          return $formaters_list; 
    239278     } 
    240279 
     
    243282     transformed using that formater. 
    244283 
     284     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...) 
    245285     @param    name      <b>string</b>       Formater name 
    246286     @param    str       <b>string</b>       String to transform 
    247287     @return   <b>string</b>  String transformed 
    248288     */ 
     289     public function callEditorFormater($editor_id,$name,$str) 
     290     { 
     291          if (isset($this->formaters[$editor_id]) && isset($this->formaters[$editor_id][$name])) { 
     292               return call_user_func($this->formaters[$editor_id][$name],$str); 
     293          } 
     294 
     295          return $str; 
     296     } 
     297     //@} 
     298 
     299     /** 
     300     If <var>$name</var> is a valid formater, it returns <var>$str</var> 
     301     transformed using that formater. 
     302 
     303     @param    name      <b>string</b>       Formater name 
     304     @param    str       <b>string</b>       String to transform 
     305     @return   <b>string</b>  String transformed 
     306     */ 
    249307     public function callFormater($name,$str) 
    250308     { 
    251           if (isset($this->formaters[$name])) { 
    252                return call_user_func($this->formaters[$name],$str); 
    253           } 
    254  
    255           return $str; 
     309          return $this->callEditorFormater('dcLegacyEditor',$name,$str); 
    256310     } 
    257311     //@} 
     
    648702        - [url] => Blog URL 
    649703        - [p] 
    650           - [permission] => true 
     704          - [permission] => true 
    651705          - ... 
    652706 
     
    816870        - [super] => (true|false) super admin 
    817871        - [p] 
    818           - [permission] => true 
     872          - [permission] => true 
    819873          - ... 
    820874 
     
    14841538     /** 
    14851539      Return elapsed time since script has been started 
    1486       @param   $mtime <b>float</b> timestamp (microtime format) to evaluate delta from 
    1487                                      current time is taken if null 
    1488       @return <b>float</b>        elapsed time 
     1540      @param     $mtime <b>float</b> timestamp (microtime format) to evaluate delta from 
     1541                                          current time is taken if null 
     1542      @return <b>float</b>          elapsed time 
    14891543      */ 
    14901544     public function getElapsedTime ($mtime=null) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map