* @license GNU General Public License version 2 or later. */ // No direct access defined('_JEXEC') or die; jimport('joomla.event.plugin'); /** * @package NewLifeInIT * @subpackage plg_editors_artofeditor * @since 1.0.1 */ class plgEditorArtofEditor extends JPlugin { /** * Get's a sanitised name for the editor. * * @param string $name The name of the form control. * * @return string * @since 1.0.0 */ protected function getEditorName($name) { return preg_replace('#\W#', '_', $name); } /** * Add the buttons to the editor. * * @param string $name The name of the control. * @param * * @return string * @since 1.0.0 */ protected function displayButtons($name, $buttons) { // Load modal popup behavior JHTML::_('behavior.modal', 'a.modal-button'); // Initialise variables. $id = $this->getEditorName($name); $args = array( 'name' => $id, 'event' => 'onGetInsertMethod' ); $return = ''; $results[] = $this->update($args); foreach ($results as $result) { if (is_string($result) && trim($result)) { $return .= $result; } } if (is_array($buttons) || (is_bool($buttons) && $buttons)) { $results = $this->_subject->getButtons($id, $buttons); $return .= "\n
\n"; foreach ($results as $button) { if ($button->get('name')) { $modal = ($button->get('modal')) ? 'class="modal-button"' : null; $href = ($button->get('link')) ? 'href="'.$button->get('link').'"' : null; $onclick = ($button->get('onclick')) ? 'onclick="'.$button->get('onclick').'"' : null; $return .= "
\n"; } } $return .= "
\n"; } return $return; } function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true) { JHTML::_('behavior.modal', 'a.modal-button'); if (is_numeric($width)) { $width .= 'px'; } if (is_numeric($height)) { $height .= 'px'; } // AJE: Fixes for JForm based editors (jform[fieldname]). $id = $this->getEditorName($name); $html = ' '; $user = JFactory::getUser(); $fr = ''; if (!strpos(JPATH_BASE,'administrator')) { $fr = '_ft'; } $html .= ""; $html .= $this->displayButtons($id, $buttons); return $html; } /** * Get the code to get the content in the editor. * * @param string $name The name of the form control. * * @return string * @since 1.0.0 */ function onGetContent($name) { $id = $this->getEditorName($name); return " CKEDITOR.instances.$id.getData(); "; } /** * Get/inject the code to insert text into the editor. * * @param string $name The name of the form control (not used). * * @return string * @since 1.0.0 */ function onGetInsertMethod($name) { static $once = false; if (!$once) { $once = true; $id = $this->getEditorName($name); $doc = JFactory::getDocument(); $js = " function jInsertEditorText(text, editor) { CKEDITOR.instances[editor].insertHtml(text); return true; }"; $doc->addScriptDeclaration($js); } return true; } /** * Initialise the editor. * * @return string * @since 1.0.0 */ function onInit() { // Initialise variables. $doc = JFactory::getDocument(); $doc->addStyleDeclaration("table.admintable {width: 100%;}"); $result = ''; return $result; } /** * Get/inject the code to copy the editor content to the form control. * * @param string $name The name of the form control. * * @return string * @since 1.0.0 */ function onSave($name) { return ''; } /** * @param string $name The name of the form control. * @param string $html * * @return string * @since 1.0.0 */ function onSetContent($name, $html) { $id = $this->getEditorName($name); return "CKEDITOR.instances.$id.setData('$html');"; } }