source: branches/1.2/workflow/inc/smarty/wf_plugins/function.wf_fckeditor.php @ 1349

Revision 1349, 4.0 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

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 . 'workflow' . SEP . 'js' . SEP . 'fckeditor' . 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'] . 'fckeditor.js"></script>';
80        }
81
82        $out .= "\n<script type=\"text/javascript\">\n";
83        $out .= "var oFCKeditor = new FCKeditor('" . $base_arguments['InstanceName'] . "');\n";
84
85        foreach($base_arguments as $key => $value)
86        {
87                if(!is_bool($value))
88                {
89                        // Fix newlines, javascript cannot handle multiple line strings very well.
90                        $value = '"' . preg_replace("/[\r\n]+/", '" + $0"', addslashes($value)) . '"';
91                }
92                $out .= "oFCKeditor.$key = $value; ";
93        }
94
95        foreach($config_arguments as $key => $value)
96        {
97                if(!is_bool($value))
98                {
99                        $value = '"' . preg_replace("/[\r\n]+/", '" + $0"', addslashes($value)) . '"';
100                }
101                $out .= "oFCKeditor.Config[\"$key\"] = $value; ";
102        }
103
104        $out .= "\noFCKeditor.Create();\n";
105        $out .= "</script>\n";
106
107        return $out;
108}
109?>
Note: See TracBrowser for help on using the repository browser.