xref: /webtrees/app/Module/CkeditorModule.php (revision 4cb8d1f0eb760216ff1402f3415ef3e289b4d8b3)
1<?php
2namespace Fisharebest\Webtrees;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * Class CkeditorModule
21 */
22class CkeditorModule extends Module {
23	/** {@inheritdoc} */
24	public function getTitle() {
25		return /* I18N: Name of a module.  CKEditor is a trademark.  Do not translate it?  http://ckeditor.com */ I18N::translate('CKEditor™');
26	}
27
28	/** {@inheritdoc} */
29	public function getDescription() {
30		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.');
31	}
32
33	/**
34	 * Convert <textarea class="html-edit"> fields to CKEditor fields
35	 *
36	 * This function needs to be called *after* we have sent the page header and
37	 * before we have sent the page footer.
38	 *
39	 * @param BaseController $controller
40	 *
41	 * @return void
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			// Activate the editor
53			->addInlineJavascript('jQuery(".html-edit").ckeditor(function(){}, {
54				language: "' . str_replace('_', '-', strtolower(WT_LOCALE)) . '"
55			});');
56	}
57}
58