Dotclear

Changeset 2705:bac24f5c42ae


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

Addresses #1896.
Save editor in post meta
Manage editor from preferences
If editor saved in meta post is not the ones chosen in preferences a simple textarea is displayed.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • admin/post.php

    r2694 r2705  
    1919$post_dt = ''; 
    2020$post_format = $core->auth->getOption('post_format'); 
    21 $editor = $core->auth->getOption('editor'); 
     21$post_editor = $core->auth->getOption('editor'); 
    2222$post_password = ''; 
    2323$post_url = ''; 
     
    6161 
    6262# Formaters combo 
    63 $formaters_combo = dcAdminCombos::getFormatersCombo($editor); 
     63$formaters_combo = dcAdminCombos::getFormatersCombo(); 
     64foreach ($formaters_combo as $editor => $formats) { 
     65     foreach ($formats as $format) { 
     66          $formaters_combo[$editor][$format] = "$editor:$format"; 
     67     } 
     68} 
    6469 
    6570# Languages combo 
     
    8388 
    8489# Get entry informations 
    85 if (!empty($_REQUEST['id'])) 
    86 { 
     90if (!empty($_REQUEST['id'])) { 
    8791     $page_title = __('Edit entry'); 
    8892 
     
    9195     $post = $core->blog->getPosts($params); 
    9296 
    93      if ($post->isEmpty()) 
    94      { 
     97     if ($post->isEmpty()) { 
    9598          $core->error->add(__('This entry does not exist.')); 
    9699          $can_view_page = false; 
    97      } 
    98      else 
    99      { 
     100     } else { 
    100101          $post_id = $post->post_id; 
    101102          $cat_id = $post->cat_id; 
    102103          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 
    103104          $post_format = $post->post_format; 
     105        # try to retrieve editor from post meta 
     106        $meta_editor = $core->meta->getMetaStr($post->post_meta,'editor'); 
     107        if (!empty($meta_editor)) { 
     108            $post_editor = $meta_editor; 
     109        } 
    104110          $post_password = $post->post_password; 
    105111          $post_url = $post->post_url; 
     
    190196 
    191197# Format excerpt and content 
    192 elseif (!empty($_POST) && $can_edit_post) 
    193 { 
    194      $post_format = $_POST['post_format']; 
     198elseif (!empty($_POST) && $can_edit_post) { 
     199 
     200     if (strpos($_POST['post_format'], ':')!==false) { 
     201          list($post_editor, $post_format) = explode(':', $_POST['post_format']); 
     202     } else { 
     203          $post_format = $_POST['post_format']; 
     204          $post_editor = ''; 
     205     } 
     206 
    195207     $post_excerpt = $_POST['post_excerpt']; 
    196208     $post_content = $_POST['post_content']; 
     
    280292     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 
    281293     $cur->post_format = $post_format; 
     294     $cur->post_meta = serialize(array('editor' => $post_editor)); 
    282295     $cur->post_password = $post_password; 
    283296     $cur->post_lang = $post_lang; 
     
    298311 
    299312     # Update post 
    300      if ($post_id) 
    301      { 
    302           try 
    303           { 
     313     if ($post_id) { 
     314          try { 
     315            $meta = $core->meta; 
     316            $meta->delPostMeta($post_id,'editor'); 
     317            $meta->setPostMeta($post_id,'editor',$post_editor); 
     318 
    304319               # --BEHAVIOR-- adminBeforePostUpdate 
    305320               $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); 
     
    311326               dcPage::addSuccessNotice (sprintf(__('The post "%s" has been successfully updated'),html::escapeHTML($cur->post_title))); 
    312327               http::redirect('post.php?id='.$post_id); 
    313           } 
    314           catch (Exception $e) 
    315           { 
     328          } catch (Exception $e) { 
    316329               $core->error->add($e->getMessage()); 
    317330          } 
    318      } 
    319      else 
    320      { 
     331     } else { 
    321332          $cur->user_id = $core->auth->userID(); 
    322333 
    323           try 
    324           { 
     334          try { 
    325335               # --BEHAVIOR-- adminBeforePostCreate 
    326336               $core->callBehavior('adminBeforePostCreate',$cur); 
     
    328338               $return_id = $core->blog->addPost($cur); 
    329339 
     340            $meta = $core->meta; 
     341            $meta->delPostMeta($return_id,'editor'); 
     342            $meta->setPostMeta($return_id,'editor',$post_editor); 
     343 
    330344               # --BEHAVIOR-- adminAfterPostCreate 
    331345               $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 
     
    333347               dcPage::addSuccessNotice(__('Entry has been successfully created.')); 
    334348               http::redirect('post.php?id='.$return_id); 
    335           } 
    336           catch (Exception $e) 
    337           { 
     349          } catch (Exception $e) { 
    338350               $core->error->add($e->getMessage()); 
    339351          } 
     
    381393} 
    382394 
     395$admin_post_behavior = ''; 
     396if (($core->auth->getOption('editor')==$post_editor)  
     397    && in_array($post_format, $core->getFormaters($core->auth->getOption('editor')))) { 
     398    $admin_post_behavior = $core->callBehavior('adminPostEditor'); 
     399} 
    383400 
    384401dcPage::open($page_title.' - '.__('Entries'), 
     
    386403     dcPage::jsModal(). 
    387404     dcPage::jsMetaEditor(). 
     405    $admin_post_behavior. 
    388406     dcPage::jsLoad('js/_post.js'). 
    389      $core->callBehavior('adminPostEditor'). 
    390407     dcPage::jsConfirmClose('entry-form','comment-form'). 
    391408     # --BEHAVIOR-- adminPostHeaders 
     
    455472/* Post form if we can edit post 
    456473-------------------------------------------------------- */ 
    457 if ($can_edit_post) 
    458 { 
     474if ($can_edit_post) { 
    459475     if (count($formaters_combo)>0 && ($core->auth->getOption('editor') && $core->auth->getOption('editor')!='')) { 
    460           $post_format_field = form::combo('post_format',$formaters_combo,$post_format,'maximal'); 
     476          // temporay removed until we can switch easily editor 
     477        // $post_format_field = form::combo('post_format',$formaters_combo,"$post_editor:$post_format",'maximal'); 
     478 
     479        $post_format_field = sprintf('%s (%s)', $post_format, $post_editor); 
     480          $post_format_field .= form::hidden('post_format',"$post_editor:$post_format"); 
    461481     } else { 
    462482          $post_format_field = sprintf(__('Choose an active editor in %s.'),  
    463483          '<a href="preferences.php#user-options">'.__('your preferences').'</a>' 
    464484          ); 
     485          $post_format_field .= form::hidden('post_format','xhtml'); 
    465486     } 
    466487 
  • plugins/dcLegacyEditor/js/_post_editor.js

    r2614 r2705  
    11$(function() { 
    22     if ($('#edit-entry').length==0) {return;} 
     3 
     4     // remove editor prefix 
     5     var getPostFormat = function getPostFormat(post_format) { 
     6          return post_format.replace(/[^:]*:/,''); 
     7     }; 
     8     var getPostEditor = function getPostEditor(post_format) { 
     9          return post_format.replace(/:.*/,''); 
     10     }; 
    311 
    412     // Get document format and prepare toolbars 
     
    614     var last_post_format = $(formatField).val(); 
    715     $(formatField).change(function() { 
     16          if (getPostEditor(this.value)!='dcLegacyEditor') { return;} 
     17 
     18          var post_format = getPostFormat(this.value); 
     19 
    820          // Confirm post format change 
    9           if(window.confirm(dotclear.msg.confirm_change_post_format_noconvert)){ 
    10                excerptTb.switchMode(this.value); 
    11                contentTb.switchMode(this.value); 
     21          if (window.confirm(dotclear.msg.confirm_change_post_format_noconvert)) { 
     22               excerptTb.switchMode(post_format); 
     23               contentTb.switchMode(post_format); 
    1224               last_post_format = $(this).val(); 
    13           }else{ 
     25          } else { 
    1426               // Restore last format if change cancelled 
    1527               $(this).val(last_post_format); 
     
    1729 
    1830          $('.format_control > *').addClass('hide'); 
    19           $('.format_control:not(.control_no_'+$(this).val()+') > *').removeClass('hide'); 
     31          $('.format_control:not(.control_no_'+post_format+') > *').removeClass('hide'); 
    2032     }); 
    2133 
     
    2537 
    2638     $('.format_control > *').addClass('hide'); 
    27      $('.format_control:not(.control_no_'+last_post_format+') > *').removeClass('hide'); 
     39     $('.format_control:not(.control_no_'+getPostFormat(last_post_format)+') > *').removeClass('hide'); 
    2840 
    2941     if ($('#comment_content').length>0) { 
     
    4961                    excerpt: excerpt_content, 
    5062                    content: post_content, 
    51                     format: $('#post_format').get(0).value, 
     63                    format: getPostFormat($('#post_format').get(0).value), 
    5264                    lang: $('#post_lang').get(0).value 
    5365               }; 
     
    99111 
    100112          // Load toolbars 
    101           contentTb.switchMode(formatField.value); 
    102           excerptTb.switchMode(formatField.value); 
     113          contentTb.switchMode(getPostFormat(formatField.value)); 
     114          excerptTb.switchMode(getPostFormat(formatField.value)); 
    103115 
    104116          // Check unsaved changes before XHTML conversion 
Note: See TracChangeset for help on using the changeset viewer.

Sites map