PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/campsite/src/admin-files/articles/editor_load_tinymce.php

https://github.com/joechrysler/Campsite
PHP | 320 lines | 268 code | 22 blank | 30 comment | 63 complexity | 1b36f04bc1d9b503ac2189728b2280c1 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @param array p_dbColumns
  4. * @param object p_user The User object
  5. * @param int p_editorLanguage The current or selected language
  6. *
  7. * @return void
  8. */
  9. function editor_load_tinymce($p_dbColumns, $p_user, $p_articleNumber,
  10. $p_editorLanguage, $p_objectType = 'article')
  11. {
  12. global $Campsite;
  13. $stylesheetFile = $Campsite['WEBSITE_URL'] . '/admin/articles/article_stylesheet.css';
  14. /** STEP 1 ********************************************************
  15. * What are the names of the textareas you will be turning
  16. * into editors?
  17. ******************************************************************/
  18. $editors = array();
  19. if (is_array($p_dbColumns)) {
  20. foreach ($p_dbColumns as $dbColumn) {
  21. if ($dbColumn->getType() == ArticleTypeField::TYPE_BODY) {
  22. if ($p_articleNumber > 0) {
  23. $editors[] = $dbColumn->getName().'_'.$p_articleNumber;
  24. } else {
  25. $editors[] = $dbColumn->getName();
  26. }
  27. }
  28. }
  29. } else {
  30. if ($p_articleNumber > 0) {
  31. $editors[] = $p_dbColumns.'_'.$p_articleNumber;
  32. } else {
  33. $editors[] = $p_dbColumns;
  34. }
  35. }
  36. $textareas = implode(",", $editors);
  37. /** STEP 2 ********************************************************
  38. * Now, what are the plugins you will be using in the editors
  39. * on this page. List all the plugins you will need, even if not
  40. * all the editors will use all the plugins.
  41. ******************************************************************/
  42. $plugins = array();
  43. if ($p_user->hasPermission('EditorCopyCutPaste')) {
  44. $plugins[] = 'paste';
  45. }
  46. if ($p_user->hasPermission('EditorFindReplace')) {
  47. $plugins[] = 'searchreplace';
  48. }
  49. if ($p_user->hasPermission('EditorEnlarge')) {
  50. $plugins[] = 'fullscreen';
  51. }
  52. if ($p_user->hasPermission('EditorTable')) {
  53. $plugins[] = 'table';
  54. }
  55. if ($p_user->hasPermission('EditorLink')) {
  56. $plugins[] = 'campsiteinternallink';
  57. if ($p_objectType == 'article') {
  58. $plugins[] = 'campsiteattachment';
  59. }
  60. }
  61. if ($p_user->hasPermission('EditorImage')) {
  62. if ($p_objectType == 'article') {
  63. $plugins[] = 'campsiteimage';
  64. $plugins[] = 'media';
  65. }
  66. }
  67. $plugins[] = 'iframe';
  68. $plugins_list = implode(",", $plugins);
  69. $statusbar_location = "none";
  70. if ($p_user->hasPermission('EditorStatusBar')) {
  71. $statusbar_location = "bottom";
  72. }
  73. /** STEP 3 ********************************************************
  74. * We create a default configuration to be used by all the editors.
  75. * If you wish to configure some of the editors differently this
  76. * will be done in step 4.
  77. ******************************************************************/
  78. $toolbar1 = array();
  79. if ($p_user->hasPermission('EditorBold')) {
  80. $toolbar1[] = "bold";
  81. }
  82. if ($p_user->hasPermission('EditorItalic')) {
  83. $toolbar1[] = "italic";
  84. }
  85. if ($p_user->hasPermission('EditorUnderline')) {
  86. $toolbar1[] = "underline";
  87. }
  88. if ($p_user->hasPermission('EditorStrikethrough')) {
  89. $toolbar1[] = "strikethrough";
  90. }
  91. if ($p_user->hasPermission('EditorTextAlignment')) {
  92. $toolbar1[] = "|";
  93. $toolbar1[] = "justifyleft";
  94. $toolbar1[] = "justifycenter";
  95. $toolbar1[] = "justifyright";
  96. $toolbar1[] = "justifyfull";
  97. }
  98. if ($p_user->hasPermission('EditorIndent')) {
  99. $toolbar1[] = "|";
  100. $toolbar1[] = "outdent";
  101. $toolbar1[] = "indent";
  102. $toolbar1[] = "blockquote";
  103. }
  104. if ($p_user->hasPermission('EditorCopyCutPaste')) {
  105. $toolbar1[] = "|";
  106. $toolbar1[] = "copy";
  107. $toolbar1[] = "cut";
  108. $toolbar1[] = "paste";
  109. $toolbar1[] = "pastetext";
  110. $toolbar1[] = "pasteword";
  111. }
  112. if ($p_user->hasPermission('EditorUndoRedo')) {
  113. $toolbar1[] = "|";
  114. $toolbar1[] = "undo";
  115. $toolbar1[] = "redo";
  116. }
  117. if ($p_user->hasPermission('EditorTextDirection')) {
  118. $toolbar1[] = "|";
  119. $toolbar1[] = "ltr";
  120. $toolbar1[] = "rtl";
  121. $toolbar1[] = "charmap";
  122. }
  123. if ($p_user->hasPermission('EditorLink')) {
  124. $toolbar1[] = "|";
  125. $toolbar1[] = "campsiteinternallink";
  126. $toolbar1[] = "link";
  127. $toolbar1[] = "anchor";
  128. if ($p_objectType == 'article') {
  129. $toolbar1[] = "campsiteattachment";
  130. }
  131. }
  132. if ($p_user->hasPermission('EditorSubhead')) {
  133. $toolbar1[] = "campsite-subhead";
  134. }
  135. if ($p_user->hasPermission('EditorImage')) {
  136. if ($p_objectType == 'article') {
  137. $toolbar1[] = "campsiteimage";
  138. $toolbar1[] = "media";
  139. }
  140. }
  141. if ($p_user->hasPermission('EditorSourceView')) {
  142. $toolbar1[] = "code";
  143. }
  144. if ($p_user->hasPermission('EditorEnlarge')) {
  145. $toolbar1[] = "fullscreen";
  146. }
  147. if ($p_user->hasPermission('EditorHorizontalRule')) {
  148. $toolbar1[] = "hr";
  149. }
  150. if ($p_user->hasPermission('EditorFontColor')) {
  151. $toolbar1[] = "forecolor";
  152. $toolbar1[] = "backcolor";
  153. }
  154. if ($p_user->hasPermission('EditorSubscript')) {
  155. $toolbar1[] = "sub";
  156. }
  157. if ($p_user->hasPermission('EditorSuperscript')) {
  158. $toolbar1[] = "sup";
  159. }
  160. if ($p_user->hasPermission('EditorFindReplace')) {
  161. $toolbar1[] = "|";
  162. $toolbar1[] = "search";
  163. $toolbar1[] = "replace";
  164. }
  165. $toolbar2 = array();
  166. // Slice up the first toolbar if it is too long.
  167. if (count($toolbar1) > 34) {
  168. $toolbar2 = array_splice($toolbar1, 34);
  169. }
  170. // This is to put the bulleted and numbered list controls
  171. // on the most appropriate line of the toolbar.
  172. if ($p_user->hasPermission('EditorListBullet') && $p_user->hasPermission('EditorListNumber') && count($toolbar1) < 19) {
  173. $toolbar1[] = "|";
  174. $toolbar1[] = "bullist";
  175. $toolbar1[] = "numlist";
  176. } elseif ($p_user->hasPermission('EditorListBullet') && !$p_user->hasPermission('EditorListNumber') && count($toolbar1) < 34) {
  177. $toolbar1[] = "|";
  178. $toolbar1[] = "bullist";
  179. } elseif (!$p_user->hasPermission('EditorListBullet') && $p_user->hasPermission('EditorListNumber') && count($toolbar1) < 20) {
  180. $toolbar1[] = "|";
  181. $toolbar1[] = "numlist";
  182. } else {
  183. $hasSeparator = false;
  184. if ($p_user->hasPermission('EditorListBullet')) {
  185. $toolbar2[] = "|";
  186. $toolbar2[] = "bullist";
  187. $hasSeparator = true;
  188. }
  189. if ($p_user->hasPermission('EditorListNumber')) {
  190. if (!$hasSeparator) {
  191. $toolbar2[] = "|";
  192. }
  193. $toolbar2[] = "numlist";
  194. }
  195. }
  196. if ($p_user->hasPermission('EditorFontFace')) {
  197. $toolbar2[] = "|";
  198. $toolbar2[] = "styleselect";
  199. $toolbar2[] = "formatselect";
  200. $toolbar2[] = "fontselect";
  201. }
  202. if ($p_user->hasPermission('EditorFontSize')) {
  203. $toolbar2[] = "fontsizeselect";
  204. }
  205. if ($p_user->hasPermission('EditorTable')) {
  206. $toolbar3[] = "tablecontrols";
  207. }
  208. $toolbar3[] = 'iframe';
  209. $theme_buttons1 = (count($toolbar1) > 0) ? implode(',', $toolbar1) : '';
  210. $theme_buttons2 = (count($toolbar2) > 0) ? implode(',', $toolbar2) : '';
  211. $theme_buttons3 = (count($toolbar3) > 0) ? implode(',', $toolbar3) : '';
  212. ?>
  213. <!-- TinyMCE -->
  214. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/javascript/tinymce/tiny_mce.js"></script>
  215. <script type="text/javascript">
  216. function CampsiteSubhead(ed) {
  217. element = ed.dom.getParent(ed.selection.getNode(), 'span');
  218. if (element && ed.dom.getAttrib(element, 'class') == 'campsite_subhead') {
  219. return false;
  220. } else {
  221. html = ed.selection.getContent({format : 'text'});
  222. ed.selection.setContent('<span class="campsite_subhead">' + html + '</span>');
  223. }
  224. } // fn CampsiteSubhead
  225. // Default skin
  226. tinyMCE.init({
  227. // General options
  228. language : "<?php p($p_editorLanguage); ?>",
  229. mode : "exact",
  230. elements : "<?php p($textareas); ?>",
  231. theme : "advanced",
  232. plugins : "<?php p($plugins_list); ?>",
  233. file_browser_callback : "campsitemedia",
  234. forced_root_block : "",
  235. relative_urls : false,
  236. extended_valid_elements : "iframe[src|width|height|name|align|frameborder|scrolling|marginheight|marginwidth]",
  237. // Theme options
  238. theme_advanced_buttons1 : "<?php p($theme_buttons1); ?>",
  239. theme_advanced_buttons2 : "<?php p($theme_buttons2); ?>",
  240. theme_advanced_buttons3 : "<?php p($theme_buttons3); ?>",
  241. theme_advanced_toolbar_location : "top",
  242. theme_advanced_toolbar_align : "left",
  243. theme_advanced_resizing : false,
  244. theme_advanced_statusbar_location: "<?php p($statusbar_location); ?>",
  245. // Example content CSS (should be your site CSS)
  246. content_css : "<?php echo $stylesheetFile; ?>",
  247. // Drop lists for link/image/media/template dialogs
  248. template_external_list_url : "lists/template_list.js",
  249. external_link_list_url : "lists/link_list.js",
  250. external_image_list_url : "lists/image_list.js",
  251. media_external_list_url : "lists/media_list.js",
  252. // paste options
  253. paste_use_dialog: false,
  254. paste_auto_cleanup_on_paste: true,
  255. paste_convert_headers_to_strong: true,
  256. paste_remove_spans: true,
  257. paste_remove_styles: true,
  258. <?php if ($p_user->hasPermission('EditorSpellcheckerEnabled')): ?>
  259. gecko_spellcheck : true,
  260. <?php endif; ?>
  261. setup : function(ed) {
  262. ed.onKeyUp.add(function(ed, l) {
  263. var idx = ed.id.lastIndexOf('_');
  264. var buttonId = ed.id.substr(0, idx);
  265. buttonEnable('save_' + buttonId);
  266. });
  267. <?php if ($p_user->hasPermission('EditorSubhead')) { ?>
  268. ed.addButton('campsite-subhead', {
  269. title : 'campsitesubhead.campsitesubhead_desc',
  270. image : website_url + '/javascript/tinymce/themes/advanced/img/campsite_subhead.gif',
  271. onclick : function() {
  272. CampsiteSubhead(ed);
  273. }
  274. });
  275. <?php } ?>
  276. }
  277. });
  278. function campsitemedia(field_name, url, type, win)
  279. {
  280. topDoc = window.top.document;
  281. articleNo = topDoc.getElementById('f_article_number').value;
  282. langId = topDoc.getElementById('f_language_selected').value;
  283. tinyMCE.activeEditor.windowManager.open({
  284. url: website_url + "/javascript/tinymce/plugins/campsitemedia/popup.php?article_id="+articleNo+'&language_selected='+langId,
  285. width: 580,
  286. height: 320,
  287. inline : "yes",
  288. close_previous : "no"
  289. },{
  290. window : win,
  291. input : field_name
  292. });
  293. }
  294. </script>
  295. <!-- /TinyMCE -->
  296. <?php
  297. } // fn editor_load_tinymce
  298. ?>