CKEditor.php 3.53 KB
Newer Older
1 2 3 4
<?php

namespace ACP3\Core\WYSIWYG;

5 6 7
/**
 * Implementation of the AbstractWYSIWYG class for CKEditor
 */
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
class CKEditor extends AbstractWYSIWYG {
	public function __construct($id, $name, $value = '', $toolbar = '', $advanced = false, $height = '') {
		$this->id = $id;
		$this->name = $name;
		$this->value = $value;
		$this->advanced = (bool) $advanced;
		$this->config['toolbar'] = $toolbar === 'simple' ? 'Basic' : 'Full';
		$this->config['height'] = $height . 'px';

		$this->configure();
	}	

	protected function configure() {
		$filebrowser_uri = ROOT_DIR . 'libraries/kcfinder/browse.php%s&cms=acp3';
		$upload_uri = ROOT_DIR . 'libraries/kcfinder/upload.php%s&cms=acp3';

		$this->config = array();
		$this->config['filebrowserBrowseUrl'] = sprintf($filebrowser_uri, '?type=files&amp;cms=');
		$this->config['filebrowserImageBrowseUrl'] = sprintf($filebrowser_uri, '?type=gallery');
		$this->config['filebrowserFlashBrowseUrl'] = sprintf($filebrowser_uri, '?type=files');
		$this->config['filebrowserUploadUrl'] = sprintf($upload_uri, '?type=files');
		$this->config['filebrowserImageUploadUrl'] = sprintf($upload_uri, '?type=gallery');
		$this->config['filebrowserFlashUploadUrl'] = sprintf($upload_uri, '?type=files');

		$this->config['extraPlugins'] = 'divarea,oembed,codemirror';
		$this->config['allowedContent'] = true;
		$this->config['codemirror'] = '@@{ theme: \'default\',
			lineNumbers: true,
			lineWrapping: true,
			matchBrackets: true,
			autoCloseTags: true,
			autoCloseBrackets: true,
			enableSearchTools: true,
			enableCodeFolding: true,
			enableCodeFormatting: true,
			autoFormatOnStart: true,
			autoFormatOnUncomment: true,
			highlightActiveLine: true,
			highlightMatches: true,
			showFormatButton: false,
			showCommentButton: false,
			showUncommentButton: false
		}';

		// Smilies
		if ((!isset($this->config['toolbar']) || $this->config['toolbar'] !== 'simple') && \ACP3\Core\Modules::isActive('emoticons') === true) {
			$this->config['smiley_path'] = ROOT_DIR . 'uploads/emoticons/';
			$this->config['smiley_images'] = $this->config['smiley_descriptions'] = '';
56
			$emoticons = \ACP3\Core\Registry::get('Db')->fetchAll('SELECT description, img FROM ' . DB_PRE . 'emoticons');
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
			$c_emoticons = count($emoticons);

			for ($i = 0; $i < $c_emoticons; ++$i) {
				$this->config['smiley_images'].= '\'' . $emoticons[$i]['img'] . '\',';
				$this->config['smiley_descriptions'].= '\'' . $emoticons[$i]['description'] . '\',';
			}

			$this->config['smiley_images'] = '@@[' . substr($this->config['smiley_images'], 0, -1) . ']';
			$this->config['smiley_descriptions'] = '@@[' . substr($this->config['smiley_descriptions'], 0, -1) . ']';
		}
		// Basic Toolbar erweitern
		if (isset($this->config['toolbar']) && $this->config['toolbar'] == 'Basic') {
			$this->config['toolbar_Basic'] = "@@[ ['Source','-','Undo','Redo','-','Bold','Italic','-','NumberedList','BulletedList','-','Link','Unlink','-','About'] ]";
		}
	}

	public function display() {
		require_once ACP3_ROOT_DIR . 'libraries/ckeditor/ckeditor.php';

		$ckeditor = new \CKEditor(ROOT_DIR . 'libraries/ckeditor/');
		$ckeditor->returnOutput = true;

		$wysiwyg = array(
			'id' => $this->id,
			'editor' => $ckeditor->editor($this->name, $this->id, $this->value, $this->config),
			'advanced' => $this->advanced,
		);

		if ($wysiwyg['advanced'] === true)
			$wysiwyg['advanced_replace_content'] = 'CKEDITOR.instances.' . $wysiwyg['id'] . '.insertHtml(text);';

88 89
		\ACP3\Core\Registry::get('View')->assign('wysiwyg', $wysiwyg);
		return \ACP3\Core\Registry::get('View')->fetchTemplate('system/wysiwyg.tpl');
90 91 92
	}

}