<?php

// NOTE: If you want to make changes to this file save it as
// wysiwyg_custom.php and it will get loaded instead of this
// file and won't get overwritten when you upgrade.

// NOTE: You can find the CSS for the wysiwyg in /css/wysiwyg.css

// this is called once at the top of the page
function loadWysiwygJavascript() {
  global $SETTINGS;
  print <<<__HTML__

  <script type="text/javascript" src="tinymce3/tiny_mce_gzip.js"></script>
  <script type="text/javascript">
  tinyMCE_GZ.init({
      // Load Plugins: ***NOTE*** plugins must be added both loadWysiwygJavascript() and initWysiwyg() (twice in this page, search for "plugins:")
      plugins: 'safari,inlinepopups,contextmenu,table,fullscreen,paste,media,spellchecker',
      themes : 'advanced',
      languages : '{$SETTINGS['wysiwyg']['wysiwygLang']}',
      disk_cache : true,
      debug : false
  });
  </script>

__HTML__;
}


// this is called once for each wysiwyg editor on the page
function initWysiwyg($fieldname, $uploadBrowserCallback) {
  global $SETTINGS;
  $includeDomainsInLinks = $SETTINGS['wysiwyg']['includeDomainInLinks'] ? "remove_script_host : false," : "";
  $programUrl            = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
  $programUrl            = preg_replace("/ /", "%20", $programUrl);

  // display field
  print <<<__HTML__

  <script language="javascript" type="text/javascript"><!--
  tinyMCE.init({
      mode : "exact",
      theme : "advanced",
      language: "{$SETTINGS['wysiwyg']['wysiwygLang']}",

          // Define buttons: Button codes: http://wiki.moxiecode.com/index.php/TinyMCE:Control_reference
          theme_advanced_buttons1 : "formatselect,fontsizeselect,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,removeformat,fullscreen",
          theme_advanced_buttons2 : "forecolor,backcolor,|,link,unlink,anchor,|,hr,image,media,table,|,pastetext,pasteword,|,code,|,spellchecker",
          theme_advanced_buttons3 : "",

          // Load Plugins: ***NOTE*** plugins must be added both loadWysiwygJavascript() and initWysiwyg() (twice in this page, search for "plugins:")
          plugins: "safari,inlinepopups,contextmenu,table,fullscreen,paste,media,spellchecker",

          // Paste From Word Settings - Docs: http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste
          paste_auto_cleanup_on_paste: true,

          // Force <br> insteaad of <p> - see: http://wiki.moxiecode.com/index.php/TinyMCE:FAQ#TinyMCE_produce_BR_elements_on_enter.2Freturn_instead_of_P_elements.3F
          // Uncommon these lines to enable this for new records
          //forced_root_block : false,
          //force_br_newlines : true,
          //force_p_newlines : false,

          // Allow user to drag the editor to resize it - see "theme_advanced_resizing*" options here: http://wiki.moxiecode.com/index.php/TinyMCE:Configuration
          // Uncommon these lines to enable this.
          //theme_advanced_statusbar_location : 'bottom',
          //theme_advanced_resizing : true,

          //
          theme_advanced_toolbar_location : "top",
          theme_advanced_toolbar_align : "left",
          elements: '$fieldname',
          file_browser_callback : "$uploadBrowserCallback",
          relative_urls : false,
          document_base_url: "/",

          $includeDomainsInLinks
          entity_encoding : "raw", // don't store extended chars as entities (&ntilde) or keyword searching won't match them

          verify_html : false, // allow all tags and attributes

          // add getTime() on the end so url is always unique and won't be cached by browser
          content_css : "$programUrl/css/wysiwyg.css" +'?'+ new Date().getTime()
  });
  //--></script>

__HTML__;
}

?>
