[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/editors/ -> mostlyce.php (source)

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