PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ckeditor/code/branches/J1.6/plugins/editors/artofeditor/artofeditor.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 229 lines | 123 code | 34 blank | 72 comment | 12 complexity | c2f3b74d436bfb23e9f175a5cc5fbf97 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: ckeditor.php 1.2 28-09-2009 Danijar
  4. * @package NewLifeInIT
  5. * @subpackage plg_editors_artofeditor
  6. * @copyright Copyright 2005 - 2011 New Life in IT Pty Ltd. All rights reserved.
  7. * @copyright Based on work Copyright 2009 CMSSpace <http://www.cmsspace.com>
  8. * @license GNU General Public License version 2 or later.
  9. */
  10. // No direct access
  11. defined('_JEXEC') or die;
  12. jimport('joomla.event.plugin');
  13. /**
  14. * @package NewLifeInIT
  15. * @subpackage plg_editors_artofeditor
  16. * @since 1.0.1
  17. */
  18. class plgEditorArtofEditor extends JPlugin
  19. {
  20. /**
  21. * Get's a sanitised name for the editor.
  22. *
  23. * @param string $name The name of the form control.
  24. *
  25. * @return string
  26. * @since 1.0.0
  27. */
  28. protected function getEditorName($name)
  29. {
  30. return preg_replace('#\W#', '_', $name);
  31. }
  32. /**
  33. * Add the buttons to the editor.
  34. *
  35. * @param string $name The name of the control.
  36. * @param
  37. *
  38. * @return string
  39. * @since 1.0.0
  40. */
  41. protected function displayButtons($name, $buttons)
  42. {
  43. // Load modal popup behavior
  44. JHTML::_('behavior.modal', 'a.modal-button');
  45. // Initialise variables.
  46. $id = $this->getEditorName($name);
  47. $args = array(
  48. 'name' => $id,
  49. 'event' => 'onGetInsertMethod'
  50. );
  51. $return = '';
  52. $results[] = $this->update($args);
  53. foreach ($results as $result)
  54. {
  55. if (is_string($result) && trim($result)) {
  56. $return .= $result;
  57. }
  58. }
  59. if (is_array($buttons) || (is_bool($buttons) && $buttons)) {
  60. $results = $this->_subject->getButtons($id, $buttons);
  61. $return .= "\n<div id=\"editor-xtd-buttons\">\n";
  62. foreach ($results as $button)
  63. {
  64. if ($button->get('name')) {
  65. $modal = ($button->get('modal')) ? 'class="modal-button"' : null;
  66. $href = ($button->get('link')) ? 'href="'.$button->get('link').'"' : null;
  67. $onclick = ($button->get('onclick')) ? 'onclick="'.$button->get('onclick').'"' : null;
  68. $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";
  69. }
  70. }
  71. $return .= "</div>\n";
  72. }
  73. return $return;
  74. }
  75. function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true)
  76. {
  77. JHTML::_('behavior.modal', 'a.modal-button');
  78. if (is_numeric($width)) {
  79. $width .= 'px';
  80. }
  81. if (is_numeric($height)) {
  82. $height .= 'px';
  83. }
  84. // AJE: Fixes for JForm based editors (jform[fieldname]).
  85. $id = $this->getEditorName($name);
  86. $html = '
  87. <textarea name="'.$name.'" id="'.$id.'" cols="'.$col.'" rows="'.$row.'" style="width:'.$width.'; height:'.$height.'">' .$content. '</textarea>';
  88. $user = JFactory::getUser();
  89. $fr = '';
  90. if (!strpos(JPATH_BASE,'administrator')) {
  91. $fr = '_ft';
  92. }
  93. $html .= "<script type='text/javascript'>
  94. var ".$id." = CKEDITOR.replace('".$id."',
  95. {
  96. baseHref: '".JURI::root()."',
  97. skin : '".$this->params->get('skin', 'kama')."',
  98. language : '".$this->params->get('language','en')."',
  99. uiColor: '".$this->params->get('bgcolor', '#6B6868')."',
  100. ";
  101. if (stripos($this->params->get('toolbar'.$fr), 'Custom') !== false) {
  102. $html .= "toolbar :[".$this->params->get(
  103. 'toolbar_'.$this->params->get(
  104. 'toolbar'.$fr
  105. ),
  106. "[ 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ]"
  107. ).'],';
  108. }
  109. else {
  110. $html .= "toolbar : '".$this->params->get('toolbar'.$fr, 'Full')."',";
  111. }
  112. $html .= "});
  113. ";
  114. $html .= ";
  115. </script>";
  116. $html .= $this->displayButtons($id, $buttons);
  117. return $html;
  118. }
  119. /**
  120. * Get the code to get the content in the editor.
  121. *
  122. * @param string $name The name of the form control.
  123. *
  124. * @return string
  125. * @since 1.0.0
  126. */
  127. function onGetContent($name)
  128. {
  129. $id = $this->getEditorName($name);
  130. return " CKEDITOR.instances.$id.getData(); ";
  131. }
  132. /**
  133. * Get/inject the code to insert text into the editor.
  134. *
  135. * @param string $name The name of the form control (not used).
  136. *
  137. * @return string
  138. * @since 1.0.0
  139. */
  140. function onGetInsertMethod($name)
  141. {
  142. static $once = false;
  143. if (!$once) {
  144. $once = true;
  145. $id = $this->getEditorName($name);
  146. $doc = JFactory::getDocument();
  147. $js = "
  148. function jInsertEditorText(text, editor)
  149. {
  150. CKEDITOR.instances[editor].insertHtml(text);
  151. return true;
  152. }";
  153. $doc->addScriptDeclaration($js);
  154. }
  155. return true;
  156. }
  157. /**
  158. * Initialise the editor.
  159. *
  160. * @return string
  161. * @since 1.0.0
  162. */
  163. function onInit()
  164. {
  165. // Initialise variables.
  166. $doc = JFactory::getDocument();
  167. $doc->addStyleDeclaration("table.admintable {width: 100%;}");
  168. $result = '<script type="text/javascript" src="'.JURI::root().'plugins/editors/artofeditor/ck/ckeditor.js"></script>';
  169. return $result;
  170. }
  171. /**
  172. * Get/inject the code to copy the editor content to the form control.
  173. *
  174. * @param string $name The name of the form control.
  175. *
  176. * @return string
  177. * @since 1.0.0
  178. */
  179. function onSave($name)
  180. {
  181. return '';
  182. }
  183. /**
  184. * @param string $name The name of the form control.
  185. * @param string $html
  186. *
  187. * @return string
  188. * @since 1.0.0
  189. */
  190. function onSetContent($name, $html)
  191. {
  192. $id = $this->getEditorName($name);
  193. return "CKEDITOR.instances.$id.setData('$html');";
  194. }
  195. }