source: trunk/workflow/inc/smarty/wf_plugins/function.wf_fckeditor.php @ 8248

Revision 8248, 4.2 KB checked in by angelo, 10 years ago (diff)

Ticket #3493 - Atualizar bibioteca CKEditor do Expresso

Line 
1<?php
2/**
3* Este plugin insere o editor FCKeditor para edição de texto rico (RTF).
4* Requires PHP >= 4.3.0
5* @package Smarty
6* @subpackage wf_plugins
7* @version 1.0
8* @author  gazoot (gazoot care of gmail dot com)
9* @author  Sidnei Augusto Drovetto Jr. - drovetto@gmail.com (revision)
10* @param object &$smarty Instância do objeto smarty em uso
11* @param array $params Parameters array. (Default values for optional parameters are taken from fckeditor.js)<br>
12*  All other parameters used in the function will be put into the<br>
13*  configuration section,CustomConfigurationsPath is useful for example.
14* - name Editor instance name (form field name)
15* - value optional data that control will start with, default is taken from the javascript file
16* - width optional width (css units)
17* - height optional height (css units)
18* - toolbar_set optional what toolbar to use from configuration
19* - check_browser optional check the browser compatibility when rendering the editor
20* - display_errors optional show error messages on errors while rendering the editor
21* @link http://wiki.fckeditor.net/Developer%27s_Guide/Configuration/Configurations_File for more configuration info.
22* @return string $out codigo que insere o FCKeditor
23* @access public
24*/
25function smarty_function_wf_fckeditor($params, &$smarty)
26{
27    /* check for missing parameters */
28        if(!isset($params['name']) || empty($params['name']))
29                $smarty->trigger_error('wf_fckeditor: required parameter "name" missing');
30
31    /* convert the parameters from our naming convention to the one used by the FCKEditor */
32    $paramsConversion = array(
33        'name' =>'InstanceName',
34        'value' => 'Value',
35        'width' => 'Width',
36        'height' => 'Height',
37        'toolbar_set' => 'ToolbarSet',
38        'check_browser' => 'CheckBrowser',
39        'display_errors' => 'DisplayErrors'
40    );
41
42    $paramsCopy = $params;
43    foreach ($paramsConversion as $before => $after)
44    {
45        if (isset($params[$before]))
46        {
47            unset($params[$before]);
48            $params[$after] = $paramsCopy[$before];
49        }
50    }
51
52        static $base_arguments = array();
53        static $config_arguments = array();
54
55        // Test if editor has been loaded before
56        if(!count($base_arguments)) $init = TRUE;
57        else $init = FALSE;
58
59        // BasePath must be specified once.
60    $base_arguments['BasePath'] = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'library' . SEP . 'ckeditor' . SEP;
61
62        $base_arguments['InstanceName'] = $params['InstanceName'];
63
64        if(isset($params['Value'])) $base_arguments['Value'] = $params['Value'];
65        if(isset($params['Width'])) $base_arguments['Width'] = $params['Width'];
66        if(isset($params['Height'])) $base_arguments['Height'] = $params['Height'];
67        if(isset($params['ToolbarSet'])) $base_arguments['ToolbarSet'] = $params['ToolbarSet'];
68        if(isset($params['CheckBrowser'])) $base_arguments['CheckBrowser'] = $params['CheckBrowser'];
69    if(isset($params['DisplayErrors'])) $base_arguments['DisplayErrors'] = $params['DisplayErrors'];
70
71        // Use all other parameters for the config array (replace if needed)
72        $other_arguments = array_diff_assoc($params, $base_arguments);
73        $config_arguments = array_merge($config_arguments, $other_arguments);
74
75        $out = '';
76
77        if($init)
78        {
79                $out .= '<script type="text/javascript" src="' . $base_arguments['BasePath'] . 'ckeditor.js"></script>';
80        }
81        $out .= '<textarea cols="80" id="'.$base_arguments['InstanceName'].'" name="'.$base_arguments['InstanceName'].'" rows="10">'.$base_arguments['Value'].'</textarea>';
82
83        $out .= '<script type="text/javascript">'.
84                                'CKEDITOR.replace( \''.$base_arguments['InstanceName'].'\',{'.
85                                        'removePlugins : \'elementspath\','.
86                                        'skin : \'moono_blue\','.
87                                        'toolbar : \'Full\''.
88                                        '}'.
89                                ');';
90
91        foreach($base_arguments as $key => $value)
92        {
93                if(!is_bool($value))
94                {
95                        // Fix newlines, javascript cannot handle multiple line strings very well.
96                        $value = '"' . preg_replace("/[\r\n]+/", '" + $0"', addslashes($value)) . '"';
97                }
98                $out .= "CKEDITOR.$key = $value; ";
99        }
100
101        foreach($config_arguments as $key => $value)
102        {
103                if(!is_bool($value))
104                {
105                        $value = '"' . preg_replace("/[\r\n]+/", '" + $0"', addslashes($value)) . '"';
106                }
107                $out .= "CKEDITOR.config[\"$key\"] = $value; ";
108        }
109
110        $out .= "</script>\n";
111
112        return $out;
113}
114?>
Note: See TracBrowser for help on using the repository browser.