PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/4.6/mambots/editors/mostlyce.php

http://miacms.googlecode.com/
PHP | 336 lines | 240 code | 30 blank | 66 comment | 62 complexity | b89d00c0b32cbb95be9e6d59f0649f47 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-2.0
  1. <?php
  2. /**
  3. * @package MOStlyCE
  4. * @author Chad Auld (chadauld@brilaps.com)
  5. * @copyright Brilaps, LLC (http://brilaps.com)
  6. * @license GNU Lesser General Public License (LGPL - http://www.gnu.org/licenses/lgpl.html)
  7. */
  8. /** ensure this file is being included by a parent file */
  9. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  10. global $mosConfig_live_site, $jspath, $mosConfig_absolute_path, $adminside;
  11. include($mosConfig_absolute_path."mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_config.php");
  12. $_MAMBOTS->registerFunction( 'onInitEditor', 'botmostlyceEditorInit' );
  13. $_MAMBOTS->registerFunction( 'onGetEditorContents', 'botmostlyceEditorGetContents' );
  14. $_MAMBOTS->registerFunction( 'onEditorArea', 'botmostlyceEditorEditorArea' );
  15. // --- Start custom code DHS Informatisering - opensource@dhs.nl, www.dhs.nl
  16. // This code makes it possible to use mostlyce in a website that combines normal and SSL-connections
  17. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
  18. $jspath = "https:" . stristr ( $mosConfig_live_site, "//" );
  19. } else {
  20. $jspath = "http:" . stristr ( $mosConfig_live_site, "//" );
  21. }
  22. // Replaced every occurrence of '$mosConfig_live_site' with '$jspath' in this file
  23. // --- End custom code DHS Informatisering ---
  24. //Render Row Buttons
  25. function renderButton($row, $remove_font) {
  26. $row = explode( ',', $row );
  27. foreach( $row as $key => $rowitem ) {
  28. if( strpos( $rowitem, '-' ) === 0) {
  29. unset( $row[$key] );
  30. }
  31. if( $remove_font ){
  32. if( $rowitem == 'fontselect' || $rowitem == 'fontsizeselect' || $rowitem == 'forecolor' || $rowitem == 'backcolor' ) {
  33. unset( $row[$key] );
  34. }
  35. }
  36. }
  37. return $new_row = implode( ',', array_values( $row ) );
  38. }
  39. /**
  40. * TinyMCE WYSIWYG Editor - javascript initialization
  41. */
  42. function botmostlyceEditorInit() {
  43. global $mosConfig_live_site, $my, $database, $mosConfig_absolute_path, $jspath;
  44. global $adminside, $mosConfig_secret, $mosConfig_cachetime;
  45. include($mosConfig_absolute_path."mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_config.php");
  46. //Setup a session variable for Image Manager and external list generator security checks
  47. $env = md5($_SERVER['HTTP_USER_AGENT']);
  48. $mostlyceRestoreKey=md5($mosConfig_secret.$env.$_SERVER['REMOTE_ADDR']);
  49. //Determine cookie expiration time. Should match login timeout (though min of 1min).
  50. if (is_numeric($mosConfig_cachetime) && $mosConfig_cachetime>=60) {
  51. $cookieTimeout = $mosConfig_cachetime;
  52. } else {
  53. $cookieTimeout = 60;
  54. }
  55. setcookie("mostlyce[startup_key]", $mostlyceRestoreKey, time()+$cookieTimeout, '/');
  56. setcookie("mostlyce[usertype]", $my->usertype, time()+$cookieTimeout, '/');
  57. //Allows for dynamic editor sizing by apps like Remository
  58. $get_width = mosGetParam($_GET,'width',NULL);
  59. $get_height = mosGetParam($_GET,'height',NULL);
  60. if ($get_width) {
  61. $editor_width = (int) $get_width;
  62. }
  63. if ($get_height) {
  64. $editor_height = (int) $get_height;
  65. }
  66. // Get the default stylesheet
  67. $query = "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'";
  68. $database->setQuery( $query );
  69. $cur_template = $database->loadResult();
  70. // Assigned template
  71. if (isset( $Itemid ) && $Itemid != "" && $Itemid != 0) {
  72. $query = "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='$Itemid' LIMIT 1";
  73. $database->setQuery($query);
  74. $cur_template = $database->loadResult() ? $database->loadResult() : $cur_template;
  75. }
  76. //Plugin settings and Authorization
  77. $invalid_elements[] = 'object,applet';
  78. //Check access level and MOStlyCE Admin preference. Set editor items accordingly.
  79. //Script Elements (Only loads for Admin)
  80. if (($adminside>0) && ($editor_script_acl==='true')) {
  81. $elements[] = "script[$editor_script_elms]";
  82. } else {
  83. $invalid_elements[] = "script";
  84. }
  85. //IFrame Elements (Only loads for Admin)
  86. if (($adminside>0) && ($editor_iframe_acl=='true')) {
  87. $elements[] = "iframe[$editor_iframe_elms]";
  88. }
  89. //Media Plugin
  90. if ($editor_plugin_media_acl==='true') {
  91. $plugins[] = 'media';
  92. }
  93. //Font Options
  94. if ($editor_font_tools_acl==='true') {
  95. $elements[] = "font[face|size|color|style]";
  96. $remove_font = false;
  97. } else {
  98. $remove_font = true;
  99. }
  100. //Emotions Plugin
  101. if ($editor_plugin_emotions_acl==='true') {
  102. $plugins[] = 'emotions';
  103. }
  104. //Print Plugin
  105. if ($editor_plugin_print==='true') {
  106. $plugins[] = 'print';
  107. }
  108. //Search & Replace Plugin
  109. if ($editor_plugin_searchreplace==='true') {
  110. $plugins[] = 'searchreplace';
  111. }
  112. //Table Plugin
  113. if ($editor_plugin_table_acl==='true') {
  114. $plugins[] = 'table';
  115. }
  116. //DateTime Plugin
  117. if ($editor_plugin_datetime_acl==='true') {
  118. $plugins[] = 'insertdatetime';
  119. }
  120. //SpellChecker Plugin (needs Curl)
  121. if ($editor_plugin_spellchecker==='true' && function_exists("curl_init")) {
  122. $plugins[] = 'spellchecker';
  123. $theme_advanced_buttons_add = 'spellchecker';
  124. } else {
  125. $theme_advanced_buttons_add = '';
  126. }
  127. //Layer Plugin
  128. if ($editor_plugin_layer==='true') {
  129. $plugins[] = 'layer';
  130. }
  131. //Image/File Manager Plugin
  132. if ($editor_plugin_img_mgr==='true') {
  133. $file_browser_callback='fileBrowserCallBack';
  134. } else {
  135. //Img/File browser not enabled
  136. $file_browser_callback='';
  137. }
  138. //Paragraphs or breaks
  139. if ($editor_newlines == 'p') {
  140. $p_newlines = "true";
  141. $br_newlines = "false";
  142. }
  143. if ($editor_newlines == 'br') {
  144. $p_newlines = "false";
  145. $br_newlines = "true";
  146. }
  147. $css_template = $mosConfig_live_site."/templates/".$cur_template."/css/";
  148. $content_css = ($editor_css_override === '1' ) ? $css_template.$editor_custom_css : $css_template."template_css.css";
  149. //Plugins List
  150. $plugins[] = $editor_extra_plugins;
  151. $plugins[] = 'safari,pagebreak,style,advhr,advimage,advlink,iespell,inlinepopups,preview,contextmenu,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras'; //These ones are always loaded
  152. $plugins = implode( ',', $plugins );
  153. $elements[] = $editor_xtd_elms;
  154. $elements = implode( ',', $elements );
  155. $invalid_elements = implode( ',', $invalid_elements );
  156. /* Check TinyMCE compression setting & verify requestors compression capabilites and set correct file path
  157. Notes:
  158. * The TinyMCE PHP gzip compressor cannot and will not work if zlib compression is already enabled on the server.
  159. * If they requested editor compression run the checks otherwise don't waste the cycles
  160. */
  161. $supportsGzip = false;
  162. if ($editor_compression==='true') {
  163. $encodings = '';
  164. if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  165. $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
  166. }
  167. if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
  168. $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
  169. $supportsGzip = true;
  170. }
  171. }
  172. $tinyHeader = '';
  173. if ($editor_compression==='true' && $supportsGzip===true) {
  174. $tinyHeader = "<script type=\"text/javascript\" src=\"$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/tiny_mce_gzip.js\"></script>";
  175. $tinyHeader .="<!-- Standard init and GZ init need to be in seperate script tags! -->
  176. <script type=\"text/javascript\">
  177. tinyMCE_GZ.init({
  178. plugins : '$plugins',
  179. themes : '$editor_themes',
  180. languages : '$editor_lang',
  181. disk_cache : true,
  182. debug : false
  183. });
  184. </script>";
  185. } else {
  186. $tinyHeader = "<script type=\"text/javascript\" src=\"$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/tiny_mce.js\"></script>";
  187. }
  188. $external_link_list_url = htmlentities($jspath.'/index2.php?option=com_mostlyce_frontend&task=contentlist&no_html=1', ENT_QUOTES, 'UTF-8');
  189. $external_image_list_url = htmlentities($jspath.'/index2.php?option=com_mostlyce_frontend&task=imagelist&no_html=1', ENT_QUOTES, 'UTF-8');
  190. return <<<EOD
  191. <!--//TinyMCE/MOStlyCE-->
  192. $tinyHeader
  193. <script type="text/javascript" src="$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_functions.js"></script>
  194. <script type="text/javascript">
  195. /* <![CDATA[ */
  196. tinyMCE.init({
  197. //General options
  198. mode : "textareas",
  199. editor_selector : "mceEditor",
  200. theme : "$editor_themes",
  201. plugins : "$plugins",
  202. //Theme options
  203. theme_advanced_buttons1: "styleselect,formatselect,fontselect,fontsizeselect,charmap,help",
  204. theme_advanced_buttons2: "undo,redo,|,newdocument,cut,cleanup,copy,paste,pastetext,pasteword, print,search,replace|,bold,italic,underline,forecolor,backcolor,code,styleprops",
  205. theme_advanced_buttons3: "justifyleft,justifycenter,justifyright,justifyfull,directionality,|,bullist,numlist,outdent,indent,blockquote,|,hr,advhr,|,strikethrough,sub,sup,visualchars,del,ins,attribs",
  206. theme_advanced_buttons4: "link,unlink,anchor,|,tablecontrols,|,removeformat,visualaid",
  207. theme_advanced_buttons5: "image,emotions,media,|,preview,fullscreen,|,insertdate,inserttime,insertlayer,moveforward,movebackward,absolute,cite,abbr,acronym, nonbreaking,template,pagebreak",
  208. theme_advanced_buttons5_add : "$theme_advanced_buttons_add",
  209. theme_advanced_toolbar_location : "top",
  210. theme_advanced_toolbar_align : "left",
  211. theme_advanced_statusbar_location : "bottom",
  212. //Drop lists for link/image/media/template dialogs
  213. //template_external_list_url : "",
  214. external_link_list_url : "$external_link_list_url",
  215. external_image_list_url : "$external_image_list_url",
  216. //media_external_list_url : "",
  217. //More MOStlyCE custom settings
  218. file_browser_callback : "$file_browser_callback",
  219. theme_advanced_source_editor_width : "$editor_width",
  220. theme_advanced_source_editor_height : "$editor_height",
  221. miacms_base_url : "$mosConfig_live_site/",
  222. document_base_url : "$mosConfig_live_site/",
  223. plugin_insertdate_dateFormat : "$editor_plugin_dateformat",
  224. plugin_insertdate_timeFormat : "$editor_plugin_timeformat",
  225. content_css : "$content_css",
  226. entity_encoding : "raw",
  227. invalid_elements : "$invalid_elements",
  228. force_br_newlines : "$br_newlines",
  229. force_p_newlines : "$p_newlines",
  230. directionality : "$editor_direction",
  231. language : "$editor_lang",
  232. lang_list : "$editor_lang_list",
  233. pagebreak_separator : "{mospagebreak}",
  234. extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],$elements",
  235. spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
  236. });
  237. function fileBrowserCallBack(field_name, url, type, win) {
  238. var connector = "$jspath/mambots/editors/mostlyce/jscripts/tiny_mce/filemanager/browser.php?Connector=connectors/php/connector.php";
  239. var enableAutoTypeSelection = false;
  240. var cType;
  241. tinymcpuk_field = field_name;
  242. tinymcpuk = win;
  243. switch (type) {
  244. case "image":
  245. cType = "Image";
  246. break;
  247. case "flash":
  248. cType = "Flash";
  249. break;
  250. case "file":
  251. cType = "File";
  252. break;
  253. case "media":
  254. cType = "Media";
  255. break;
  256. }
  257. if (enableAutoTypeSelection && cType) {
  258. connector += "&Type=" + cType;
  259. }
  260. window.open(connector, "tinymcpuk", "modal,width=600,height=400");
  261. }
  262. /*]]>*/
  263. </script>
  264. <!-- /tinyMCE -->
  265. EOD;
  266. }
  267. /**
  268. * TinyMCE WYSIWYG Editor - copy editor contents to form field
  269. * @param string The name of the editor area
  270. * @param string The name of the form field
  271. */
  272. function botmostlyceEditorGetContents($editorArea, $hiddenField) {
  273. global $jspath;
  274. return <<<EOD
  275. tinyMCE.triggerSave();
  276. EOD;
  277. }
  278. /**
  279. * mostlyce WYSIWYG Editor - display the editor
  280. * @param string The name of the editor area
  281. * @param string The content of the field
  282. * @param string The name of the form field
  283. * @param string The width of the editor area
  284. * @param string The height of the editor area
  285. * @param int The number of columns for the editor area
  286. * @param int The number of rows for the editor area
  287. */
  288. function botmostlyceEditorEditorArea($name, $content, $hiddenField, $width, $height, $col, $row, $showbut=1) {
  289. global $jspath, $_MAMBOTS, $mosConfig_absolute_path;
  290. include($mosConfig_absolute_path."mambots/editors/mostlyce/jscripts/tiny_mce/mostlyce_config.php");
  291. $results = $_MAMBOTS->trigger('onCustomEditorButton');
  292. $buttons = array();
  293. foreach ($results as $result) {
  294. $buttons[] = '<img src="'.$jspath.'/mambots/editors-xtd/'.$result[0].'" alt="custom buttons" onclick="tinyMCE.execCommand(\'mceInsertContent\',false,\''.$result[1].'\')" />';
  295. }
  296. //Hide old {mosimage} button if requested
  297. if ($editor_mosimage_icon == 'false') {
  298. unset($buttons[array_search(0,$buttons)]);
  299. }
  300. $buttons = implode( "", $buttons );
  301. return <<<EOD
  302. <textarea id="$hiddenField" name="$hiddenField" cols="" rows="" style="width:{$width}px; height:{$height}px;" class="mceEditor">$content</textarea>
  303. <br />$buttons
  304. EOD;
  305. }
  306. ?>