PageRenderTime 58ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/ED_tinyMCE/index.php

https://github.com/hinablue/TextCube
PHP | 226 lines | 205 code | 9 blank | 12 comment | 45 complexity | 1d214ac0f98cb9b89f2ab62523af52a6 MD5 | raw file
Possible License(s): ISC, GPL-2.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, MIT
  1. <?php
  2. /***
  3. * TinyMCE Editor for Textcube
  4. * 2.0
  5. *
  6. * Needlworks / Jeongkyu Shin (https://github.com/inureyes)
  7. * CodeMirror plugin by zvuc (https://github.com/zvuc)
  8. */
  9. function tinyMCE_handleconfig($configVal) {
  10. $context = Model_Context::getInstance();
  11. $config = $context->getProperty('plugin.config');
  12. if (isset($config['editormode']) && $config['editormode'] != 'simple' && $config['editormode'] != 'advanced') {
  13. return false;
  14. }
  15. if (isset($config['paragraphdelim']) && $config['paragraphdelim'] != 'P' && $config['paragraphdelim'] != 'BR') {
  16. return false;
  17. }
  18. return true;
  19. }
  20. function tinyMCE_editorinit($editor) {
  21. $context = Model_Context::getInstance();
  22. $config = $context->getProperty('plugin.config');
  23. if (empty($config['editormode'])) {
  24. $config['editormode'] = 'simple';
  25. }
  26. if (empty($config['width'])) {
  27. $config['width'] = 'skin';
  28. }
  29. if (empty($config['srctheme'])) {
  30. $config['srctheme'] = 'default';
  31. }
  32. if ($config['srctheme'] == 'default') {
  33. $config['srctheme'] = 'elegant';
  34. }
  35. $config['formatter'] = null;
  36. if (empty($config['paragraphdelim'])) {
  37. $config['paragraphdelim'] = 'BR';
  38. }
  39. if ($context->getProperty('formatter.key') == 'markdown') {
  40. $config['formatter'] = 'markdown';
  41. $config['codemirror_jsfiles'] = array('mode/xml/xml.js', 'mode/markdown/markdown.js');
  42. $config['width'] = 'full';
  43. } else {
  44. $config['formatter'] = 'htmlmixed';
  45. $config['codemirror_jsfiles'] = array('mode/xml/xml.js', 'mode/javascript/javascript.js', 'mode/css/css.js', 'mode/htmlmixed/htmlmixed.js');
  46. }
  47. ob_start();
  48. ?>
  49. var editor = new tinymce.Editor('editWindow', {
  50. // General options
  51. selector : "textarea#editWindow",
  52. mode : 'exact',
  53. theme : 'modern',
  54. skin : 'textcube',
  55. <?php
  56. if (file_exists($context->getProperty("plugin.path", "") . '/tinymce/langs/' . $context->getProperty('blog.language') . '.js')) {
  57. ?>
  58. language : '<?php echo strtolower($context->getProperty('blog.language')); ?>',
  59. <?php
  60. }
  61. ?>
  62. popup_css_add: "<?php echo $context->getProperty("plugin.uri"); ?>/popup.css",
  63. menubar: false,
  64. fixed_toolbar_container: "#formatbox-container",
  65. toolbar_location : "external",
  66. toolbar_items_size: 'small',
  67. relative_urls: false,
  68. convert_urls: false,
  69. //schema: "html5",
  70. extended_valid_elements : "div[class|style|align|width|height|id|more|less],img[class|src|border|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|longdesc|style],pre[*],code[*],object,br",
  71. <?php
  72. if ($config['editormode'] == 'simple') {
  73. ?>
  74. plugins: [
  75. "TTMLsupport advlist link image lists print hr anchor autoresize",
  76. "media visualblocks",
  77. "table contextmenu directionality charmap textcolor",
  78. "codemirror"
  79. ],
  80. toolbar1: "tcsave print | bold italic underline strikethrough | styleselect formatselect fontselect fontsizeselect forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote hr tcmoreless",
  81. toolbar2: "undo redo | tcattach image media charmap | hr link unlink anchor | table | removeformat | tcsourcecodeedit code visualblocks",
  82. <?php
  83. } else {
  84. ?>
  85. plugins: [
  86. "TTMLsupport advlist link image lists charmap print hr anchor pagebreak table",
  87. "searchreplace wordcount visualblocks visualchars insertdatetime media nonbreaking",
  88. "table contextmenu directionality emoticons textcolor paste textcolor autoresize",
  89. "codemirror",
  90. ],
  91. toolbar1: "tcsave print | bold italic underline strikethrough | styleselect formatselect fontselect fontsizeselect forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote hr tcmoreless",
  92. toolbar2: "undo redo | searchreplace | tcattach image media charmap insertdatetime | subscript superscript ltr rtl cite abbr acronym del ins | hr link unlink anchor | table | cut copy paste pastetext| removeformat | tcsourcecodeedit code visualblocks",
  93. <?php
  94. }
  95. ?>
  96. // codemirror settings
  97. codemirror: {
  98. indentOnInit: false, // Whether or not to indent code on init.
  99. path: 'CodeMirror', // Path to CodeMirror distribution
  100. config: { // CodeMirror config object
  101. mode: '<?php echo $config['formatter']; ?>',
  102. lineNumbers: true,
  103. tabSize: 4,
  104. indentWithTabs: true,
  105. theme: '<?php echo $config['srctheme'] ?>'
  106. },
  107. jsFiles: [ // Additional JS files to load
  108. '<?php echo implode('\',\'', $config['codemirror_jsfiles']); ?>'
  109. ],
  110. cssFiles: [
  111. 'theme/<?php echo $config['srctheme'] ?>.css'
  112. ],
  113. showMarkdownLineBreaks: true
  114. },
  115. // content CSS
  116. content_css : "<?php echo(file_exists(__TEXTCUBE_SKIN_DIR__ . '/' . $context->getProperty('skin.skin') . '/wysiwyg.css') ? $context->getProperty('uri.service') . '/skin/blog/' . $context->getProperty('skin.skin') . '/wysiwyg.css' : $context->getProperty('uri.service') . '/resources/style/default-wysiwyg.css'); ?>",
  117. // Style formats
  118. style_formats: [
  119. {title: 'Headers', items: [
  120. {title: 'h1', block: 'h1'},
  121. {title: 'h2', block: 'h2'},
  122. {title: 'h3', block: 'h3'},
  123. {title: 'h4', block: 'h4'},
  124. {title: 'h5', block: 'h5'},
  125. {title: 'h6', block: 'h6'}
  126. ]},
  127. {title: 'Blocks', items: [
  128. {title: 'p', block: 'p'},
  129. {title: 'div', block: 'div'},
  130. {title: 'pre', block: 'pre'}
  131. ]},
  132. {title: 'Containers', items: [
  133. {title: 'section', block: 'section', wrapper: true, merge_siblings: false},
  134. {title: 'article', block: 'article', wrapper: true, merge_siblings: false},
  135. {title: 'blockquote', block: 'blockquote', wrapper: true},
  136. {title: 'hgroup', block: 'hgroup', wrapper: true},
  137. {title: 'aside', block: 'aside', wrapper: true},
  138. {title: 'figure', block: 'figure', wrapper: true}
  139. ]}
  140. ],
  141. fontsize_formats: "8pt 9pt 10pt 11pt 12pt 14pt 18pt 24pt 36pt",
  142. paste_auto_cleanup_on_paste: true,
  143. paste_convert_headers_to_strong: false,
  144. paste_remove_spans: true,
  145. <?php if ($config['formatter'] == 'markdown') { ?>
  146. apply_source_formatting: false,
  147. forced_root_block: false,
  148. <?php } else if ($config['paragraphdelim'] == 'P') { ?>
  149. forced_root_block : 'p',
  150. <?php } else { ?>
  151. forced_root_block : false,
  152. <?php
  153. }
  154. ?>
  155. width : <?php echo($config['width'] == 'full' ? '"100%"' : $context->getProperty('skin.contentWidth') + 40); ?>
  156. }, tinymce.EditorManager);
  157. editor.initialize = function() {
  158. <?php if ($config['formatter'] == 'markdown') {
  159. ?>
  160. editor.on('postRender', function (e) { editor.plugins.codemirror.showSourceEditorFrame(); });
  161. editor.on('BeforeSetContent', function(e) {
  162. if (e.initial) {
  163. e.content = e.content.replace(/\r?\n/g, '<br/>');
  164. }
  165. });
  166. <?php
  167. }
  168. ?>
  169. this.render();
  170. };
  171. editor.addObject = function(data) {
  172. this.plugins.TTMLsupport.addObject(data);
  173. };
  174. editor.command = function(command, value1, value2) {
  175. this.plugins.TTMLsupport.command(command,value1,value2);
  176. };
  177. editor.finalize = function() {
  178. this.destroy();
  179. };
  180. editor.syncTextarea = function(){
  181. if (this.doesCodeMirrorEditorEnabled == true) {
  182. this.plugins.codemirror.syncToTinyMCE();
  183. }
  184. this.save();
  185. if (entryManager.nowsaving == true && editor.tcformatter == 'markdown') {
  186. var htmlcontent = document.getElementById('editWindow').value;
  187. htmlcontent = htmlcontent.replace(new RegExp("<br/>", "gi"), "\r\n");
  188. document.getElementById('editWindow').value = htmlcontent;
  189. }
  190. };
  191. editor.syncEditorWindow = function() {
  192. this.load();
  193. };
  194. editor.on('keyup',editorChanged);
  195. editor.on('mousedown',editorChanged);
  196. editor.propertyFilePath = "<?php echo $context->getProperty('uri.service'); ?>/attach/<?php echo $context->getProperty('blog.id'); ?>/";
  197. editor.tcformatter = '<?php echo $config['formatter']; ?>';
  198. editor.fixPosition = <?php echo Setting::getBlogSettingGlobal('editorPropertyPositionFix', 0); ?>;
  199. editor.originalTextarea = document.getElementById('editWindow');
  200. editor.editorMode = 'tinymce';
  201. return editor;
  202. <?php
  203. $result = ob_get_contents();
  204. ob_end_clean();
  205. return $result;
  206. }
  207. function tinyMCE_adminheader($target, $mother) {
  208. $context = Model_Context::getInstance();
  209. if ($context->getProperty('editor.key') == 'tinyMCE') {
  210. if ($context->getProperty('suri.directive') == '/owner/entry/post' || $context->getProperty("suri.directive") == '/owner/entry/edit') {
  211. $target .= "\t<script type=\"text/javascript\" src=\"" . $context->getProperty("plugin.uri", "") . "/tinymce/tinymce.min.js\"></script>\n";
  212. $target .= "\t<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"" . $context->getProperty("plugin.uri", "") . "/override.css\" />\n";
  213. }
  214. }
  215. return $target;
  216. }
  217. ?>