Dotclear

Changeset 2679:bae19d3adbc4


Ignore:
Timestamp:
03/05/14 21:04:23 (12 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.

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • admin/js/_preferences.js

    r2566 r2679  
    2020          return true; 
    2121     }); 
     22 
     23     // choose format depending of editor based on formats_by_editor defined in preferences.php 
     24     if (formats_by_editor !== undefined) { 
     25          var _editors = $.parseJSON(formats_by_editor); 
     26      
     27          $('#user_editor').change(function() { 
     28               if (!_editors[$(this).val()]) {return;} 
     29                
     30               $('#user_post_format option').remove(); 
     31               for (var format in _editors[$(this).val()]) { 
     32                    $('#user_post_format').append('<option value="'+format+'">'+format+'</option>'); 
     33               } 
     34          }); 
     35     } 
    2236}); 
  • admin/post.php

    r2666 r2679  
    1919$post_dt = ''; 
    2020$post_format = $core->auth->getOption('post_format'); 
     21$editor = $core->auth->getOption('editor'); 
    2122$post_password = ''; 
    2223$post_url = ''; 
     
    6061 
    6162# Formaters combo 
    62 $formaters_combo = dcAdminCombos::getFormatersCombo(); 
     63$formaters_combo = dcAdminCombos::getFormatersCombo($editor); 
    6364 
    6465# Languages combo 
     
    378379     dcPage::jsMetaEditor(). 
    379380     dcPage::jsLoad('js/_post.js'). 
    380      $core->callBehavior('adminPostEditor'). 
     381     $core->callBehavior('adminPostEditor',$editor). 
    381382     dcPage::jsConfirmClose('entry-form','comment-form'). 
    382383     # --BEHAVIOR-- adminPostHeaders 
  • admin/preferences.php

    r2567 r2679  
    2727 
    2828$user_options = $core->auth->getOptions(); 
     29if (empty($user_options['editor'])) { 
     30    $user_options['editor'] = ''; 
     31} 
    2932 
    3033$core->auth->user_prefs->addWorkspace('dashboard'); 
     
    5861} 
    5962 
     63# Editors combo 
     64$editors_combo = dcAdminCombos::getEditorsCombo(); 
     65$editors = array_keys($editors_combo); 
     66 
    6067# Formaters combo 
    6168$formaters_combo = dcAdminCombos::getFormatersCombo(); 
     69 
     70if (!empty($user_options['editor'])) { 
     71    $formaters_combo_editor = $formaters_combo[$user_options['editor']]; 
     72} elseif (count($editors)!=0) { 
     73    $formaters_combo_editor = $formaters_combo[$editors[0]]; 
     74} else { 
     75    $formaters_combo = array(); 
     76} 
    6277 
    6378$status_combo = dcAdminCombos::getPostStatusescombo(); 
     
    155170          } 
    156171          $user_options['post_format'] = $_POST['user_post_format']; 
     172          $user_options['editor'] = $_POST['user_editor']; 
    157173          $user_options['enable_wysiwyg'] = !empty($_POST['user_wysiwyg']); 
    158174 
     
    317333                    sprintf(__('Password strength: %s'),__('very strong'))."']});\n". 
    318334          "});\n". 
     335        'var formats_by_editor = \''.json_encode($formaters_combo).'\';'. 
    319336          "\n//]]>\n". 
    320337          "</script>\n". 
     
    455472'<h4>'.__('Edition').'</h4>'. 
    456473 
     474'<p class="field"><label for="user_editor">'.__('Preferred editor:').'</label>'. 
     475form::combo('user_editor',$editors_combo,$user_options['editor']).'</p>'. 
     476 
    457477'<p class="field"><label for="user_post_format">'.__('Preferred format:').'</label>'. 
    458 form::combo('user_post_format',$formaters_combo,$user_options['post_format']).'</p>'. 
     478form::combo('user_post_format',$formaters_combo_editor,$user_options['post_format']).'</p>'. 
    459479 
    460480'<p class="field"><label for="user_post_status">'.__('Default entry status:').'</label>'. 
  • 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) { 
  • locales/fr/main.po

    r2666 r2679  
    20302030msgstr "Édition" 
    20312031 
     2032msgid "Preferred editor:" 
     2033msgstr "Editeur préféré :" 
     2034 
    20322035msgid "Preferred format:" 
    20332036msgstr "Format d'édition préféré :" 
  • plugins/dcLegacyEditor/_admin.php

    r2614 r2679  
    2323 
    2424if ($self_ns->active) { 
    25     $core->addBehavior('adminPostEditor',array('dcLegacyEditorBehaviors','adminPostEditor')); 
    26     $core->addBehavior('adminPopupMedia',array('dcLegacyEditorBehaviors','adminPopupMedia')); 
    27     $core->addBehavior('adminPopupLink',array('dcLegacyEditorBehaviors','adminPopupLink')); 
    28     $core->addBehavior('adminPopupPosts',array('dcLegacyEditorBehaviors','adminPopupPosts')); 
     25     $wiki2xhtml = new wiki2xhtml(); 
     26 
     27     $core->addEditorFormater('dcLegacyEditor','xhtml',create_function('$s','return $s;')); 
     28     $core->addEditorFormater('dcLegacyEditor','wiki',array($wiki2xhtml,'transform')); 
     29 
     30     $core->addBehavior('adminPostEditor',array('dcLegacyEditorBehaviors','adminPostEditor')); 
     31     $core->addBehavior('adminPopupMedia',array('dcLegacyEditorBehaviors','adminPopupMedia')); 
     32     $core->addBehavior('adminPopupLink',array('dcLegacyEditorBehaviors','adminPopupLink')); 
     33     $core->addBehavior('adminPopupPosts',array('dcLegacyEditorBehaviors','adminPopupPosts')); 
    2934} 
  • plugins/dcLegacyEditor/inc/dc.legacy.editor.behaviors.php

    r2614 r2679  
    1515     protected static $p_url = 'index.php?pf=dcLegacyEditor'; 
    1616 
    17      public static function adminPostEditor() { 
     17     public static function adminPostEditor($editor) { 
     18          if ($editor!='dcLegacyEditor') {return;} 
     19 
    1820          return 
    1921               self::jsToolBar(). 
Note: See TracChangeset for help on using the changeset viewer.

Sites map