2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
42 * Reserved. Contributor(s): ______________________________________..
43 *********************************************************************************/
47 * PHP wrapper class for Javascript driven TinyMCE WYSIWYG HTML editor
50 var $jsroot = "include/javascript/tiny_mce/";
51 var $customConfigFile = 'custom/include/tinyButtonConfig.php';
52 var $buttonConfigs = array(
54 'buttonConfig' => "code,help,separator,bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,
55 justifyfull,separator,forecolor,backcolor,separator,styleselect,formatselect,fontselect,fontsizeselect,",
56 'buttonConfig2' => "cut,copy,paste,pastetext,pasteword,selectall,separator,search,replace,separator,bullist,numlist,separator,outdent,
57 indent,separator,ltr,rtl,separator,undo,redo,separator, link,unlink,anchor,image,separator,sub,sup,separator,charmap,
59 'buttonConfig3' => "tablecontrols,separator,advhr,hr,removeformat,separator,insertdate,inserttime,separator,preview"),
60 'email_compose' => array(
61 'buttonConfig' => "code,help,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,
62 justifyfull,separator,forecolor,backcolor,separator,styleselect,formatselect,fontselect,fontsizeselect,",
63 'buttonConfig2' => "",
64 'buttonConfig3' => ""),
65 'email_compose_light' => array(
66 'buttonConfig' => "code,help,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,
67 justifyfull,separator,forecolor,backcolor,separator,styleselect,formatselect,fontselect,fontsizeselect,",
68 'buttonConfig2' => "",
69 'buttonConfig3' => ""),
72 var $pluginsConfig = array(
73 'email_compose_light' => 'insertdatetime,paste,directionality,safari',
74 'email_compose' => 'advhr,insertdatetime,table,preview,paste,searchreplace,directionality,fullpage',
77 var $defaultConfig = array(
78 'convert_urls' => false,
81 'theme' => 'advanced',
82 'theme_advanced_toolbar_align' => "left",
83 'theme_advanced_toolbar_location' => "top",
84 'theme_advanced_buttons1' => "",
85 'theme_advanced_buttons2' => "",
86 'theme_advanced_buttons3' => "",
87 'strict_loading_mode' => true,
90 'plugins' => 'advhr,insertdatetime,table,preview,paste,searchreplace,directionality',
92 'extended_valid_elements' => 'style,hr[class|width|size|noshade],@[class|style]',
93 'content_css' => 'include/javascript/tiny_mce/themes/advanced/skins/default/content.css',
101 function SugarTinyMCE() {
103 $this->overloadButtonConfigs();
107 * Returns the Javascript necessary to initialize a TinyMCE instance for a given <textarea> or <div>
108 * @param string target Comma delimited list of DOM ID's, <textarea id='someTarget'>
111 function getInstance($targets = "") {
115 $json = getJSONobj();
118 $config = $this->defaultConfig;
119 //include tinymce lang file
120 $lang = substr($GLOBALS['current_language'], 0, 2);
121 if(file_exists('include/javascript/tiny_mce/langs/'.$lang.'.js'))
123 $config['language'] = $lang;
125 $config['directionality'] = SugarThemeRegistry::current()->directionality;
126 $config['elements'] = $targets;
127 $config['theme_advanced_buttons1'] = $this->buttonConfigs['default']['buttonConfig'];
128 $config['theme_advanced_buttons2'] = $this->buttonConfigs['default']['buttonConfig2'];
129 $config['theme_advanced_buttons3'] = $this->buttonConfigs['default']['buttonConfig3'];
131 $jsConfig = $json->encode($config);
133 $instantiateCall = '';
134 if (!empty($targets)) {
135 $exTargets = explode(",", $targets);
136 foreach($exTargets as $instance) {
137 //$instantiateCall .= "tinyMCE.execCommand('mceAddControl', false, document.getElementById('{$instance}'));\n";
140 $path = getJSPath('include/javascript/tiny_mce/tiny_mce.js');
142 <script type="text/javascript" language="Javascript" src="$path"></script>
144 <script type="text/javascript" language="Javascript">
146 if (!SUGAR.util.isTouchScreen()) {
147 tinyMCE.init({$jsConfig});
152 $exTargets = explode(",", $targets);
153 foreach($exTargets as $instance) {
155 document.getElementById('$instance').style.width = '100%';
156 document.getElementById('$instance').style.height = '100px';
168 function getConfig($type = 'default') {
172 $json = getJSONobj();
175 $config = $this->defaultConfig;
176 //include tinymce lang file
177 $lang = substr($GLOBALS['current_language'], 0, 2);
178 if(file_exists('include/javascript/tiny_mce/langs/'.$lang.'.js'))
179 $config['language'] = $lang;
180 $config['theme_advanced_buttons1'] = $this->buttonConfigs[$type]['buttonConfig'];
181 $config['theme_advanced_buttons2'] = $this->buttonConfigs[$type]['buttonConfig2'];
182 $config['theme_advanced_buttons3'] = $this->buttonConfigs[$type]['buttonConfig3'];
184 if(isset($this->pluginsConfig[$type]))
185 $config['plugins'] = $this->pluginsConfig[$type];
187 $jsConfig = $json->encode($config);
188 return "var tinyConfig = ".$jsConfig.";";
193 * This function takes in html code that has been produced (and somewhat mauled) by TinyMCE
194 * and returns a cleaned copy of it.
197 * @return $html with all the tinyMCE specific html removed
199 function cleanEncodedMCEHtml($html) {
200 $html = str_replace("mce:script", "script", $html);
201 $html = str_replace("mce_src=", "src=", $html);
202 $html = str_replace("mce_href=", "href=", $html);
207 * Reload the default button configs by allowing admins to specify
208 * which tinyMCE buttons will be displayed in a seperate config file.
211 private function overloadButtonConfigs()
213 if( file_exists( $this->customConfigFile ) )
215 require_once($this->customConfigFile);
217 if(!isset($buttonConfigs))
220 foreach ($buttonConfigs as $k => $v)
222 if( isset($this->buttonConfigs[$k]) )
223 $this->buttonConfigs[$k] = $v;