BxBaseEditorTinyMCE.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolEditor');
  10. /**
  11. * TinyMCE editor representation.
  12. * @see BxDolEditor
  13. */
  14. class BxBaseEditorTinyMCE extends BxDolEditor {
  15. /**
  16. * Common initialization params
  17. */
  18. protected static $CONF_COMMON = "
  19. jQuery('{bx_var_selector}').tinymce({
  20. {bx_var_custom_init}
  21. document_base_url: '{bx_url_root}',
  22. script_url: '{bx_var_plugins_path}tiny_mce/tiny_mce_gzip.php',
  23. skin: '{bx_var_skin}',
  24. language: '{bx_var_lang}',
  25. content_css: '{bx_var_css_path}',
  26. gecko_spellcheck: true,
  27. entity_encoding: 'raw',
  28. verify_html: false
  29. });
  30. ";
  31. /**
  32. * Standard view initialization params
  33. */
  34. protected static $CONF_STANDARD = "
  35. plugins: 'autolink,autosave,lists,inlinepopups,media,paste,fullscreen',
  36. width: '100%',
  37. height: '270',
  38. theme: 'advanced',
  39. theme_advanced_buttons1: 'bold,italic,underline,removeformat,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,undo,redo,|,blockquote,formatselect',
  40. theme_advanced_buttons2: 'hr,link,unlink,image,media,|,fullscreen,cleanup,pastetext,code',
  41. theme_advanced_buttons3: '',
  42. theme_advanced_toolbar_location: 'top',
  43. theme_advanced_toolbar_align: 'left',
  44. theme_advanced_statusbar_location: 'bottom',
  45. theme_advanced_resizing: true,
  46. theme_advanced_resize_horizontal: false,
  47. theme_advanced_resizing_use_cookie: true,
  48. theme_advanced_path: false,
  49. ";
  50. /**
  51. * Minimal view initialization params
  52. */
  53. protected static $CONF_MINI = "
  54. plugins: 'autolink,autosave,lists,inlinepopups,paste,fullscreen',
  55. width: '100%',
  56. height: '150',
  57. theme: 'advanced',
  58. theme_advanced_buttons1: 'bold,italic,underline,removeformat,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,blockquote,|,link,unlink,image',
  59. theme_advanced_buttons2: '',
  60. theme_advanced_buttons3: '',
  61. theme_advanced_toolbar_location: 'top',
  62. theme_advanced_toolbar_align: 'left',
  63. theme_advanced_statusbar_location: 'none',
  64. ";
  65. /**
  66. * Full view initialization params
  67. */
  68. protected static $CONF_FULL = "
  69. plugins: 'autolink,autosave,lists,table,inlinepopups,media,searchreplace,print,paste,fullscreen',
  70. width: '100%',
  71. height: '320',
  72. theme: 'advanced',
  73. theme_advanced_buttons1: 'bold,italic,underline,removeformat,|,sub,sup,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|,outdent,indent,blockquote,formatselect,|,hr,link,unlink,image,media',
  74. theme_advanced_buttons2: 'anchor,|,tablecontrols,|,visualaid,|,search,replace,|,print,|,fullscreen,cleanup,pastetext,code',
  75. theme_advanced_buttons3: '',
  76. theme_advanced_toolbar_location: 'top',
  77. theme_advanced_toolbar_align: 'left',
  78. theme_advanced_statusbar_location: 'bottom',
  79. theme_advanced_resizing: true,
  80. theme_advanced_resize_horizontal: false,
  81. theme_advanced_resizing_use_cookie: true,
  82. ";
  83. /**
  84. * Available editor languages
  85. */
  86. protected static $CONF_LANGS = array('ar' => 1, 'be' => 1, 'bg' => 1, 'ca' => 1, 'cn' => 1, 'cs' => 1, 'cy' => 1, 'da' => 1, 'de' => 1, 'en' => 1, 'es' => 1, 'et' => 1, 'fi' => 1, 'fr' => 1, 'he' => 1, 'hu' => 1, 'it' => 1, 'ja' => 1, 'km' => 1, 'lt' => 1, 'mk' => 1, 'nb' => 1, 'nl' => 1, 'pl' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sv' => 1, 'tr' => 1, 'zh' => 1);
  87. protected $_oTemplate;
  88. protected $_bJsCssAdded = false;
  89. public function __construct ($aObject, $oTemplate) {
  90. parent::__construct ($aObject);
  91. if ($oTemplate)
  92. $this->_oTemplate = $oTemplate;
  93. else
  94. $this->_oTemplate = BxDolTemplate::getInstance();
  95. }
  96. /**
  97. * Attach editor to HTML element, in most cases - textarea.
  98. * @param $sSelector - jQuery selector to attach editor to.
  99. * @param $iViewMode - editor view mode: BX_EDITOR_STANDARD, BX_EDITOR_MINI, BX_EDITOR_FULL
  100. * @param $bDynamicMode - is AJAX mode or not, the HTML with editor area is loaded dynamically.
  101. */
  102. public function attachEditor ($sSelector, $iViewMode = BX_EDITOR_STANDARD, $bDynamicMode = false) {
  103. // set visual mode
  104. switch ($iViewMode) {
  105. case BX_EDITOR_MINI:
  106. $sToolsItems = self::$CONF_MINI;
  107. break;
  108. case BX_EDITOR_FULL:
  109. $sToolsItems = self::$CONF_FULL;
  110. break;
  111. case BX_EDITOR_STANDARD:
  112. default:
  113. $sToolsItems = self::$CONF_STANDARD;
  114. }
  115. // detect language
  116. bx_import('BxDolLanguages');
  117. $sLang = BxDolLanguages::getInstance()->detectLanguageFromArray (self::$CONF_LANGS);
  118. // initialize editor
  119. $sInitEditor = $this->_replaceMarkers(self::$CONF_COMMON, array(
  120. 'bx_var_custom_init' => $sToolsItems,
  121. 'bx_var_plugins_path' => bx_js_string(BX_DOL_URL_PLUGINS, BX_ESCAPE_STR_APOS),
  122. 'bx_var_css_path' => bx_js_string($this->_oTemplate->getCssUrl('editor.css'), BX_ESCAPE_STR_APOS),
  123. 'bx_var_skin' => bx_js_string($this->_aObject['skin'], BX_ESCAPE_STR_APOS),
  124. 'bx_var_lang' => bx_js_string($sLang, BX_ESCAPE_STR_APOS),
  125. 'bx_var_selector' => bx_js_string($sSelector, BX_ESCAPE_STR_APOS),
  126. 'bx_url_root' => bx_js_string(BX_DOL_URL_ROOT, BX_ESCAPE_STR_APOS),
  127. ));
  128. if ($bDynamicMode) {
  129. $sScript = "<script>
  130. if ('undefined' == typeof(jQuery(document).tinymce)) {
  131. $.getScript('" . bx_js_string(BX_DOL_URL_PLUGINS . 'tiny_mce/jquery.tinymce.js', BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  132. $sInitEditor
  133. });
  134. } else {
  135. $sInitEditor
  136. }
  137. </script>";
  138. } else {
  139. $sScript = "
  140. <script>
  141. $(document).ready(function () {
  142. $sInitEditor
  143. });
  144. </script>";
  145. }
  146. return $this->_addJsCss($bDynamicMode) . $sScript;
  147. }
  148. /**
  149. * Add css/js files which are needed for editor display and functionality.
  150. */
  151. protected function _addJsCss($bDynamicMode = false, $sInitEditor = '') {
  152. if ($bDynamicMode)
  153. return '';
  154. if ($this->_bJsCssAdded)
  155. return '';
  156. $this->_oTemplate->addJs(BX_DOL_URL_PLUGINS . 'tiny_mce/jquery.tinymce.js');
  157. $this->_bJsCssAdded = true;
  158. return '';
  159. }
  160. }
  161. /** @} */