xref: /webtrees/app/Module/CkeditorModule.php (revision 76a5e7c78a07f5736a3cd5b7437c8f18dc196a5e)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2017 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\Module;
17
18use Fisharebest\Webtrees\Controller\BaseController;
19use Fisharebest\Webtrees\I18N;
20
21/**
22 * Class CkeditorModule
23 */
24class CkeditorModule extends AbstractModule {
25	/** {@inheritdoc} */
26	public function getTitle() {
27		return /* I18N: Name of a module. CKEditor is a trademark. Do not translate it? http://ckeditor.com */ I18N::translate('CKEditor™');
28	}
29
30	/** {@inheritdoc} */
31	public function getDescription() {
32		return /* I18N: Description of the “CKEditor” module. WYSIWYG = “what you see is what you get” */ I18N::translate('Allow other modules to edit text using a “WYSIWYG” editor, instead of using HTML codes.');
33	}
34
35	/**
36	 * Convert <textarea class="html-edit"> fields to CKEditor fields
37	 *
38	 * This function needs to be called *after* we have sent the page header and
39	 * before we have sent the page footer.
40	 *
41	 * @param BaseController $controller
42	 */
43	public static function enableEditor($controller) {
44		$controller
45			->addExternalJavascript(WT_CKEDITOR_BASE_URL . 'ckeditor.js')
46			->addExternalJavascript(WT_CKEDITOR_BASE_URL . 'adapters/jquery.js')
47			// Need to specify the path before we load the libary
48			->addInlineJavascript(
49				'var CKEDITOR_BASEPATH="' . WT_CKEDITOR_BASE_URL . '";',
50				BaseController::JS_PRIORITY_HIGH
51			)
52			// Enable for all browsers
53			->addInlineJavascript('CKEDITOR.env.isCompatible = true;')
54			// Disable toolbars
55			->addInlineJavascript('CKEDITOR.config.removePlugins = "forms,newpage,preview,print,save,templates";')
56			->addInlineJavascript('CKEDITOR.config.extraAllowedContent =
57    "area[shape,coords,href,target,alt,title];map[name];img[usemap];*[class,style]";')
58			// Activate the editor
59			->addInlineJavascript('$(".html-edit").ckeditor(function(config){config.removePlugins = "forms";}, {
60				language: "' . strtolower(WT_LOCALE) . '"
61			});');
62	}
63}
64