PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/editors/xstandard.php

https://gitlab.com/endomorphosis/OLAAaction
PHP | 286 lines | 165 code | 42 blank | 79 comment | 11 complexity | 2c26ca4cb1be248700a933a906e1e3f3 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: xstandard.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  6. * @license GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. // Do not allow direct access
  14. defined( '_JEXEC' ) or die( 'Restricted access' );
  15. jimport( 'joomla.plugin.plugin' );
  16. /**
  17. * XStandard Lite for Joomla! WYSIWYG Editor Plugin
  18. *
  19. * @package Editors
  20. * @since 1.5
  21. */
  22. class plgEditorXstandard extends JPlugin
  23. {
  24. /**
  25. * Constructor
  26. *
  27. * For php4 compatability we must not use the __constructor as a constructor for plugins
  28. * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  29. * This causes problems with cross-referencing necessary for the observer design pattern.
  30. *
  31. * @param object $subject The object to observe
  32. * @param array $config An array that holds the plugin configuration
  33. * @since 1.5
  34. */
  35. function plgEditorXstandard(& $subject, $config)
  36. {
  37. parent::__construct($subject, $config);
  38. }
  39. /**
  40. * Method to handle the onInitEditor event.
  41. * - Initializes the XStandard Lite WYSIWYG Editor
  42. *
  43. * @access public
  44. * @return string JavaScript Initialization string
  45. * @since 1.5
  46. */
  47. function onInit()
  48. {
  49. $html = '';
  50. ob_start();
  51. ?>
  52. <script type="text/javascript" src="<?php echo JURI::root() ?>/plugins/editors/xstandard/xstandard.js"></script>
  53. <?php
  54. $html = ob_get_contents();
  55. ob_end_clean();
  56. return $html;
  57. }
  58. /**
  59. * XStandard Lite WYSIWYG Editor - get the editor content
  60. *
  61. * @param string The name of the editor
  62. */
  63. function onGetContent( $editor ) {
  64. return "$('xstandard').value;";
  65. }
  66. /**
  67. * XStandard Lite WYSIWYG Editor - set the editor content
  68. *
  69. * @param string The name of the editor
  70. */
  71. function onSetContent( $editor, $html ) {
  72. return "$('xstandard').value =". $html .";";
  73. }
  74. /**
  75. * XStandard Lite WYSIWYG Editor - copy editor content to form field
  76. *
  77. * @param string The name of the editor
  78. */
  79. function onSave( $editor ) {
  80. $js = "var editor = $('xstandard');\n";
  81. $js .= "editor.EscapeUnicode = true;";
  82. $js .= "$('".$editor."').value = editor.value;";
  83. return $js;
  84. }
  85. /**
  86. * XStandard Lite WYSIWYG Editor - display the editor
  87. *
  88. * @param string The name of the editor area
  89. * @param string The content of the field
  90. * @param string The name of the form field
  91. * @param string The width of the editor area
  92. * @param string The height of the editor area
  93. * @param int The number of columns for the editor area
  94. * @param int The number of rows for the editor area
  95. * @param mixed Can be boolean or array.
  96. */
  97. function onDisplay( $name, $content, $width, $height, $col, $row, $buttons = true )
  98. {
  99. // Load modal popup behavior
  100. JHTML::_('behavior.modal', 'a.modal-button');
  101. // Only add "px" to width and height if they are not given as a percentage
  102. if (is_numeric( $width )) {
  103. $width .= 'px';
  104. }
  105. if (is_numeric( $height )) {
  106. $height .= 'px';
  107. }
  108. jimport('joomla.environment.browser');
  109. $instance =& JBrowser::getInstance();
  110. $language =& JFactory::getLanguage();
  111. $db =& JFactory::getDBO();
  112. $url = JURI::root();
  113. $lang = substr( $language->getTag(), 0, strpos( $language->getTag(), '-' ) );
  114. if ($language->isRTL()) {
  115. $direction = 'rtl';
  116. } else {
  117. $direction = 'ltr';
  118. }
  119. /*
  120. * Lets get the default template for the site application
  121. */
  122. $query = 'SELECT template'
  123. . ' FROM #__templates_menu'
  124. . ' WHERE client_id = 0'
  125. . ' AND menuid = 0'
  126. ;
  127. $db->setQuery( $query );
  128. $template = $db->loadResult();
  129. $file_path = JPATH_SITE .'/templates/'. $template .'/css/';
  130. if ( !file_exists( $file_path .DS. 'editor.css' ) ) {
  131. $template = 'system';
  132. }
  133. $css = JURI::root() .'/templates/'. $template . '/css/editor.css';
  134. $html = '';
  135. ob_start();
  136. ?>
  137. <div style="border: 1px solid #D5D5D5">
  138. <object type="application/x-xstandard" id="xstandard" class="<?php echo $name ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
  139. <param name="Value" value="<?php echo $content ?>" />
  140. <param name="Lang" value="<?php echo $lang ?>" />
  141. <param name="Dir" value="<?php echo $direction ?>" />
  142. <param name="EditorCSS" value="<?php echo $css ?>" />
  143. <param name="EnablePasteMarkup" value="yes" />
  144. <param name="EnableTimestamp" value="no" />
  145. <param name="EscapeUnicode" value="no" />
  146. <param name="ToolbarWysiwyg" value="line, hyperlink, attachment, directory, undo, , wysiwyg, source, screen-reader, ,expand; strong, em, underline, strikethrough, , align-left, align-center, align-right, , blockquote, undo-blockquote, ,numbering, bullets, , undo, redo, ,layout-table, data-table, draw-layout-table, draw-data-table" />
  147. <param name="ToolbarSource" value="indent, whitespace, word-wrap, dim-tags, validate,, wysiwyg, source, screen-reader, , expand" />
  148. <param name="ToolbarPreview" value="wysiwyg, source, screen-reader, ,expand" />
  149. <param name="ToolbarScreenReader" value="wysiwyg, source, screen-reader, , expand" />
  150. <param name="BackgroundColor" value="#F9F9F9" />
  151. <param name="Mode" value="<?php echo $this->params->get('mode', 'wysiwyg'); ?>" />
  152. <param name="IndentOutput" value="yes" />
  153. <param name="Options" value="<?php echo $this->params->get('wrap', '0'); ?>" />
  154. <param name="BorderColor" value="#FFF" />
  155. <param name="Base" value="<?php echo $url ?>" />
  156. <param name="ExpandWidth" value="800" />
  157. <param name="ExpandHeight" value="600" />
  158. <param name="LatestVersion" value="2.0.0.0" />
  159. <param name="CMSCode" value="065126D6-357D-46FC-AF74-A1F5B2D5036E" />
  160. <param name="CMSImageLibraryURL" value="<?php echo $url ?>plugins/editors/xstandard/imagelibrary.php" />
  161. <param name="CMSAttachmentLibraryURL" value="<?php echo $url ?>plugins/editors/xstandard/attachmentlibrary.php" />
  162. <param name="CMSDirectoryURL" value="<?php echo $url ?>plugins/editors/xstandard/directory.php" />
  163. <param name="PreviewXSLT" value="<?php echo $url ?>plugins/editors/xstandard/preview.xsl" />
  164. <param name="CSS" value="<?php echo $this->_getTemplateCss(); ?>" />
  165. <textarea name="alternate1" id="alternate1" cols="60" rows="15"><?php echo $content ?></textarea>
  166. </object>
  167. <input type="hidden" id="<?php echo $name ?>" name="<?php echo $name ?>" value="" />
  168. </div>
  169. <?php
  170. $html = ob_get_contents();
  171. ob_end_clean();
  172. $html .= $this->_displayButtons($name, $buttons);
  173. return $html;
  174. }
  175. function onGetInsertMethod($name)
  176. {
  177. $doc = & JFactory::getDocument();
  178. $js= "function jInsertEditorText( text ) {
  179. var editor = document.getElementById('xstandard');
  180. editor.InsertXML(text);
  181. }";
  182. $doc->addScriptDeclaration($js);
  183. return true;
  184. }
  185. function _getTemplateCss()
  186. {
  187. $db =& JFactory::getDBO();
  188. /*
  189. * Lets get the default template for the site application
  190. */
  191. $query = 'SELECT template'
  192. . ' FROM #__templates_menu'
  193. . ' WHERE client_id = 0'
  194. . ' AND menuid = 0'
  195. ;
  196. $db->setQuery( $query );
  197. $template = $db->loadResult();
  198. $content_css = JURI::root() .'/templates/'. $template .'/css/';
  199. $file_path = JPATH_SITE .'/templates/'. $template .'/css/';
  200. if ( file_exists( $file_path .DS. 'editor.css' ) ) {
  201. $content_css = $content_css . 'editor.css' .'", ';
  202. } else {
  203. $content_css = $content_css . 'template_css.css", ';
  204. }
  205. return $content_css;
  206. }
  207. function _displayButtons($name, $buttons)
  208. {
  209. // Load modal popup behavior
  210. JHTML::_('behavior.modal', 'a.modal-button');
  211. $args['name'] = $name;
  212. $args['event'] = 'onGetInsertMethod';
  213. $return = '';
  214. $results[] = $this->update($args);
  215. foreach ($results as $result) {
  216. if (is_string($result) && trim($result)) {
  217. $return .= $result;
  218. }
  219. }
  220. if(!empty($buttons))
  221. {
  222. $results = $this->_subject->getButtons($name, $buttons);
  223. /*
  224. * This will allow plugins to attach buttons or change the behavior on the fly using AJAX
  225. */
  226. $return .= "\n<div id=\"editor-xtd-buttons\">\n";
  227. foreach ($results as $button)
  228. {
  229. /*
  230. * Results should be an object
  231. */
  232. if ( $button->get('name') )
  233. {
  234. $modal = ($button->get('modal')) ? 'class="modal-button"' : null;
  235. $href = ($button->get('link')) ? 'href="'.$button->get('link').'"' : null;
  236. $onclick = ($button->get('onclick')) ? 'onclick="'.$button->get('onclick').'"' : null;
  237. $return .= "<div class=\"button2-left\"><div class=\"".$button->get('name')."\"><a ".$modal." title=\"".$button->get('text')."\" ".$href." ".$onclick." rel=\"".$button->get('options')."\">".$button->get('text')."</a></div></div>\n";
  238. }
  239. }
  240. $return .= "</div>\n";
  241. }
  242. return $return;
  243. }
  244. }