Changeset 13273

Show
Ignore:
Timestamp:
11/05/07 14:03:17 (1 year ago)
Author:
w_i
Message:

Added configuration possibility to fckeditor -widget. Closes #176

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.datamanager2/config/config.inc

    r13194 r13273  
    1111 
    1212'include_metadata_required' => false, 
     13 
    1314/* This is passed to sprintf, use %s where file name should be */ 
    1415'type_blobs_avscan_command' => '', 
     
    1617'type_blobs_avscan_command' => 'clamscan --stdout -i --no-summary %s', 
    1718*/ 
     19 
     20'fck_static_toolbar_sets' => array 
     21( 
     22    'Default', 
     23    'Basic', 
     24), 
     25'fck_default_toolbar_set_contents' => array 
     26( 
     27    'dm2' => array 
     28    ( 
     29        array( 'Bold', 'Italic', 'Underline', 'StrikeThrough', '-', 'OrderedList', 'UnorderedList', '-', 'Outdent', 'Indent' ), 
     30        array( 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull' ), 
     31        array( 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteWord', ), 
     32        array( 'Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'), 
     33        array( 'Print', '-', 'FitWindow', '-', 'Source' ), 
     34        '/', 
     35        array( 'FontFormat' ), 
     36        array( 'Link', 'Unlink', 'Anchor' ), 
     37        array( 'Image', 'Flash', 'SpecialChar'), 
     38    ), 
     39    'simple' => array 
     40    ( 
     41        array( 'Bold', 'Italic', 'Underline', 'StrikeThrough', '-', 'OrderedList', 'UnorderedList', '-', 'Outdent', 'Indent' ), 
     42        array( 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull' ), 
     43        array( 'FitWindow', '-', 'Source' ), 
     44        '/', 
     45        array( 'Link', 'Unlink', 'Anchor' ), 
     46        array( 'Image', 'SpecialChar'), 
     47    ), 
     48    'abstract' => array 
     49    ( 
     50        array( 'Bold', 'Italic', '-', 'OrderedList', 'UnorderedList', '-', 'Link', 'Unlink' ), 
     51    ), 
     52    'all' => array 
     53    ( 
     54        array( 'Source','DocProps','-','Save','NewPage','Preview','-','Templates' ), 
     55        array( 'Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck' ), 
     56        array( 'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat' ), 
     57        array( 'Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField' ), 
     58        '/', 
     59        array( 'Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript' ), 
     60        array( 'OrderedList','UnorderedList','-','Outdent','Indent' ), 
     61        array( 'JustifyLeft','JustifyCenter','JustifyRight','JustifyFull' ), 
     62        array( 'Link','Unlink','Anchor' ), 
     63        array( 'Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'), 
     64        '/', 
     65        array( 'Style','FontFormat','FontName','FontSize' ), 
     66        array( 'TextColor','BGColor' ), 
     67        array( 'FitWindow','-','About' ), 
     68    ), 
     69), 
     70'fck_default_config_snippet' => 'file://midcom/helper/datamanager2/config/fckeditor_default.inc', 
  • trunk/midcom/midcom.helper.datamanager2/config/manifest.inc

    r13176 r13273  
    3535            'role' => 'developer', 
    3636        ), 
     37        'w_i' => array 
     38        ( 
     39            'name' => 'Jerry Jalava', 
     40            'email' => 'jerry.jalava@gmail.com', 
     41            'role' => 'lead', 
     42        ), 
    3743    ), 
    3844    'dependencies' => array 
  • trunk/midcom/midcom.helper.datamanager2/widget/fckeditor.php

    r12166 r13273  
    2525 * <b>Available configuration options:</b> 
    2626 * 
    27  * - All of the textarea baseclass. The height default has been changed to 25, the width default 
    28  *   to 80
     27 * - All of the textarea baseclass. The height default has been changed to 450, the width default 
     28 *   to 800
    2929 * - <i>string fck_config_snippet:</i> Indicates the name of the snippet which holds the base 
    3030 *   configuration. This is looked up in the DM2 directory in SG-Config. This defaults to 
     
    4747{ 
    4848    /** 
     49     * Width of the editor. 
     50     * 
     51     * @var int 
     52     * @access public 
     53     */ 
     54    var $width = null; 
     55 
     56    /** 
     57     * Height of the editor. 
     58     * 
     59     * @var int 
     60     * @access public 
     61     */ 
     62    var $height = null; 
     63 
     64    /** 
    4965     * The FCK configuration snippet to use. Argument must be applicable to use with 
    5066     * midcom_get_snippet_content. 
     
    5975     * @var string 
    6076     */ 
    61     var $local_config = ''; 
     77    var $local_config = null; 
     78     
     79    /** 
     80     * Local js configuration to be added to the config snippet. 
     81     * 
     82     * @var string 
     83     */ 
     84    var $local_js_config = null; 
    6285 
    6386    /** 
    6487     * Which theme will the editor use to render itself 
    6588     * 
    66      * @var string : valid values: default, office and silver 
     89     * @var string : valid values: default, office2003 and silver 
    6790     */ 
    6891    var $theme = null; 
     
    7396     * @var string : valid values: Default or Basic 
    7497     */ 
    75     var $toolbar_set = "Default"; 
    76      
    77     /** 
    78      * Should the midcom image dialog be used instead of the normal? 
    79      * @var boolean defaults to true. 
    80      */ 
    81     var $use_midcom_imagedialog = true; 
    82      
    83     var $editor; 
     98    var $toolbar_set = null; 
     99    var $toolbar_set_content = array(); 
     100     
     101    var $_static_toolbar_sets = array( 
     102        'Default', 
     103        'Basic', 
     104    ); 
     105    var $_default_toolbar_set_contents = array(); 
     106     
     107    var $_editor; 
    84108     
    85109    var $configuration = array(); 
    86110     
    87111    var $fckeditor_path = null; 
    88      
    89     /** 
    90      * Adds the external HTML dependencies, both JS and CSS. A static flag prevents 
    91      * multiple insertions of these dependencies. 
    92      * 
    93      * @access private 
    94      */ 
    95     function _add_external_html_elements() 
    96     { 
    97         static $executed = false; 
    98  
    99         if ($executed) 
    100         { 
    101             return; 
    102         } 
    103  
    104         $executed = true; 
    105     } 
    106112 
    107113    /** 
     
    110116    function _add_initscript() 
    111117    { 
    112  
    113         $this->configuration['fckconfig'] = midcom_get_snippet_content_graceful($this->fck_config_snippet); 
    114          
    115         if (! $this->configuration['fckconfig']) 
    116         { 
    117             $this->_get_configuration(); 
    118         } 
     118        $this->_get_configuration(); 
    119119                 
    120120        $language = $_MIDCOM->i18n->get_current_language(); 
     
    132132     */ 
    133133    function _get_configuration() 
    134     {    
    135         $valid_sets = array( 
    136             'Default'   => true, 
    137             'Basic' => true, 
    138         ); 
    139          
    140         if (array_key_exists($this->toolbar_set, $valid_sets)) 
     134    { 
     135        $this->toolbar_set_contents = $this->_default_toolbar_set_contents; 
     136         
     137        if (! empty($this->local_config))         
     138        { 
     139            $this->configuration['fckconfig'] = $this->local_config;             
     140        } 
     141 
     142        if (! empty($this->local_js_config))         
     143        { 
     144            $this->configuration['js_config'] = $this->local_js_config;             
     145        } 
     146 
     147        if (!is_null($this->toolbar_set)) 
    141148        { 
    142149            $this->configuration['toolbar_set'] = $this->toolbar_set; 
    143         } 
    144         else 
    145         { 
    146             $this->configuration['toolbar_set'] = 'Default'; 
    147         } 
    148          
    149         if ($this->fck_config_snippet != '')  
    150         { 
    151             $this->configuration['toolbar_set'] = 'Custom'; 
    152             $this->configuration['toolbar_set_content'] = $this->fck_config_snippet; 
    153         } 
    154  
    155         $this->height = 450;             
    156         $this->width = 800; 
    157          
    158         $this->configuration['width'] = $this->width; 
    159         $this->configuration['height'] = $this->height; 
    160          
    161         $this->configuration['fckconfig'] = array(); 
    162     } 
    163  
    164     /** 
    165      * Returns the Default configuraiton: 
    166      * 
    167      * @return string The default configuration 
    168      * @access private 
    169      */ 
    170     function _get_default_configuration() 
    171     { 
    172         $this->configuration['toolbar_set'] = 'Default'; 
    173     } 
    174  
    175     /** 
    176      * Returns the "basic" configuration 
    177      */ 
    178     function _get_basic_configuration () 
    179     { 
    180         $this->configuration['toolbar_set'] = 'Basic'; 
     150        }         
     151         
     152        $this->configuration['width'] = "800px"; 
     153        $this->configuration['height'] = "450px"; 
     154                 
     155        if (! is_null($this->width)) 
     156        { 
     157            if (is_numeric($this->width)) 
     158            { 
     159                $this->width = "{$this->width}px"; 
     160            } 
     161            $this->configuration['width'] = $this->width; 
     162        } 
     163        if (! is_null($this->height)) 
     164        { 
     165            if (is_numeric($this->height)) 
     166            { 
     167                $this->height = "{$this->height}px"; 
     168            } 
     169            $this->configuration['height'] = $this->height; 
     170        } 
     171         
     172        if ($this->fck_config_snippet != '') 
     173        { 
     174            $data = midcom_get_snippet_content($this->fck_config_snippet); 
     175            $result = eval ("\$snippet_config = Array ( {$data}\n );"); 
     176            if ($result === false) 
     177            { 
     178                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 
     179                    "Failed to parse the config file in '{$this->fck_config_snippet}', see above for PHP errors."); 
     180                // This will exit. 
     181            } 
     182 
     183            if (isset($snippet_config['fckconfig'])) 
     184            { 
     185                $this->configuration['fckconfig'] = $snippet_config['fckconfig']; 
     186                if (! empty($this->local_config)) 
     187                { 
     188                    $this->configuration['fckconfig'] = array_merge($this->configuration['fckconfig'], $this->local_config);             
     189                } 
     190            } 
     191             
     192            if (isset($snippet_config['js_config'])) 
     193            { 
     194                $this->configuration['js_config'] = $snippet_config['js_config']; 
     195                if (! empty($this->local_js_config)) 
     196                { 
     197                    $this->configuration['js_config'] = array_merge($this->configuration['js_config'], $this->local_js_config);             
     198                } 
     199            } 
     200             
     201            if (   isset($snippet_config['toolbar_set']) 
     202                && is_null($this->toolbar_set)) 
     203            { 
     204                $this->configuration['toolbar_set'] = $snippet_config['toolbar_set']; 
     205            } 
     206             
     207            if (   isset($snippet_config['toolbar_set_content']) 
     208                && !empty($snippet_config['toolbar_set_content'])) 
     209            { 
     210                $this->toolbar_set_contents = array_merge($this->toolbar_set_content, $snippet_config['toolbar_set_content']); 
     211            }            
     212             
     213            if (   isset($snippet_config['width']) 
     214                && is_null($this->width)) 
     215            { 
     216                $this->configuration['width'] = $snippet_config['width']; 
     217            } 
     218             
     219            if (   isset($snippet_config['height']) 
     220                && is_null($this->height)) 
     221            { 
     222                $this->configuration['height'] = $snippet_config['height']; 
     223            } 
     224        } 
     225         
     226        if (! empty($this->toolbar_set_content)) 
     227        { 
     228            $this->toolbar_set_contents = array_merge( 
     229                $this->toolbar_set_contents, 
     230                array 
     231                ( 
     232                    $this->configuration['toolbar_set'] => $this->toolbar_set_content 
     233                ) 
     234            );             
     235        } 
     236         
     237        if (   !in_array($this->toolbar_set, $this->_static_toolbar_sets) 
     238            && isset($this->toolbar_set_contents[$this->configuration['toolbar_set']])) 
     239        { 
     240            $this->configuration['toolbar_set_content'] = $this->toolbar_set_contents[$this->configuration['toolbar_set']]; 
     241        } 
     242         
     243        if (empty($this->configuration['fckconfig'])) 
     244        { 
     245            $this->configuration['fckconfig'] = array 
     246            ( 
     247                'SkinPath' => 'editor/skins/office2003/', 
     248                'DefaultLanguage' => 'en-uk', 
     249                'UseBROnCarriageReturn' => 'false', 
     250                'StartupFocus' => 'false', 
     251            ); 
     252        } 
     253         
     254        $this->configuration['fckconfig']['CustomConfigurationsPath'] = $this->_resolve_custom_config_path(); 
     255         
     256    } 
     257     
     258    function _resolve_custom_config_path() 
     259    { 
     260        $prefix = $_MIDCOM->get_host_prefix(); 
     261        $config_str = ''; 
     262         
     263        $tmp_config = $this->configuration['js_config']; 
     264         
     265        if (isset($this->configuration['toolbar_set_content'])) 
     266        { 
     267            $tmp_config['toolbar_set'] = $this->configuration['toolbar_set']; 
     268            $tmp_config['toolbar_content'] = $this->configuration['toolbar_set_content']; 
     269        } 
     270         
     271        //var_dump($tmp_config); 
     272         
     273        $config_str = base64_encode(serialize($tmp_config)); 
     274         
     275        return "{$prefix}midcom-exec-midcom.helper.datamanager2/fckeditor/config.php?config_str={$config_str}"; 
    181276    } 
    182277     
     
    188283     * from the config file at this point. 
    189284     * 
    190      * @todo make overrideable. 
    191285     * @access private 
    192286     */ 
     
    194288    { 
    195289        parent::_on_configuring(); 
    196                  
    197         $this->theme = $this->_config->get('fck_default_theme'); 
    198         $this->toolbar_set = $this->_config->get('fck_default_toolbar_set'); 
     290         
     291        $this->configuration['fckconfig'] = array 
     292        ( 
     293            'SkinPath' => 'editor/skins/office2003/', 
     294            'DefaultLanguage' => 'en-uk', 
     295            'UseBROnCarriageReturn' => 'false', 
     296            'StartupFocus' => 'false', 
     297        ); 
     298         
     299        $this->_static_toolbar_sets = $this->_config->get('fck_static_toolbar_sets'); 
     300        $this->_default_toolbar_set_contents = $this->_config->get('fck_default_toolbar_set_contents'); 
    199301        $this->fck_config_snippet = $this->_config->get('fck_default_config_snippet'); 
    200302         
     
    208310     */ 
    209311    function _on_initialize () 
    210     { 
    211         if (!$this->toolbar_set) 
    212         { 
    213             $this->toolbar_set = 'Default'; 
    214         } 
    215          
     312    {         
    216313        if ($this->_initialize_dependencies) 
    217314        { 
    218             $this->_add_external_html_elements(); 
    219315            $this->_add_initscript(); 
    220316        } 
     
    236332        if (!$this->_initialize_dependencies) 
    237333        { 
    238             $this->_add_external_html_elements(); 
    239334            $this->_add_initscript(); 
    240335        } 
     
    246341        ); 
    247342 
    248         $this->editor = $this->_form->addElement( 
     343        $this->_editor = $this->_form->addElement( 
    249344            'fckeditor', 
    250345            $this->name, 
     
    253348        ); 
    254349 
    255         $this->editor->setFCKProps( 
     350        $this->_editor->setFCKProps( 
    256351            $this->configuration['basepath'], 
    257352            $this->configuration['toolbar_set'],