the-art-of-joomla-archive /ckeditor/code/branches/J1.6/plugins/editors/artofeditor/artofeditor.php

Language PHP Lines 229
MD5 Hash c2f3b74d436bfb23e9f175a5cc5fbf97 Estimated Cost $2,941 (why?)
Repository https://bitbucket.org/eddieajau/the-art-of-joomla-archive View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
 * @version		$Id: ckeditor.php 1.2 28-09-2009 Danijar
 * @package		NewLifeInIT
 * @subpackage	plg_editors_artofeditor
 * @copyright	Copyright 2005 - 2011 New Life in IT Pty Ltd. All rights reserved.
 * @copyright	Based on work Copyright 2009 CMSSpace <http://www.cmsspace.com>
 * @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<div id=\"editor-xtd-buttons\">\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		.= "<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";
				}
			}

			$return .= "</div>\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 = '
		<textarea name="'.$name.'" id="'.$id.'" cols="'.$col.'" rows="'.$row.'" style="width:'.$width.'; height:'.$height.'">' .$content.   '</textarea>';

		$user = JFactory::getUser();

		$fr = '';
		if (!strpos(JPATH_BASE,'administrator')) {
			$fr = '_ft';
		}

  		$html .= "<script type='text/javascript'>
		var ".$id." = CKEDITOR.replace('".$id."',
		{
			baseHref:  '".JURI::root()."',
			skin :     '".$this->params->get('skin',	'kama')."',
			language : '".$this->params->get('language','en')."',
			uiColor:   '".$this->params->get('bgcolor',	'#6B6868')."',
			";

  		if (stripos($this->params->get('toolbar'.$fr), 'Custom') !== false) {
  			$html .= "toolbar :[".$this->params->get(
  				'toolbar_'.$this->params->get(
					'toolbar'.$fr
				),
				"[ 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ]"
  			).'],';
  		}
  		else {
  			$html .= "toolbar : '".$this->params->get('toolbar'.$fr, 'Full')."',";
  		}

		$html .= "});
		";

		$html .= ";
		</script>";
		$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 = '<script type="text/javascript" src="'.JURI::root().'plugins/editors/artofeditor/ck/ckeditor.js"></script>';

  		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');";
	}
}
Back to Top