1<?php
2
3/**
4 * Back-end <i>WYSIWYG</i> editor TinyMCE 4.x.
5 *
6 * You can place your own additional custom configuration files within
7 * <var>%USER_PLUGIN_FOLDER%/tiny_mce/config</var>
8 * There is a naming convention since there is a difference between Zenphoto (gallery) and Zenpag (news/pages) editor configurations.
9 * <var>zenphoto-<yourcustomname>.js.php</var>
10 * <var>zenpage-<yourcustomname>.js.php</var>
11 *
12 * @author Malte Müller (acrylian)
13 * @package plugins
14 * @subpackage tinymce4
15 */
16$plugin_is_filter = 5 | ADMIN_PLUGIN;
17$plugin_description = gettext("Text editor TinyMCE 4.x");
18$plugin_author = "Malte Müller (acrylian)";
19$plugin_category = gettext('Admin');
20$option_interface = 'tinymce4Options';
21
22if (!defined('EDITOR_SANITIZE_LEVEL'))
23	define('EDITOR_SANITIZE_LEVEL', 4);
24zp_register_filter('texteditor_config', 'tinymce4ConfigJS');
25
26/**
27 * Plugin option handling class
28 *
29 */
30class tinymce4Options {
31
32	function __construct() {
33		setOptionDefault('tinymce4_zenphoto', 'zenphoto-ribbon.js.php');
34		setOptionDefault('tinymce4_zenpage', 'zenpage-slim.js.php');
35		setOptionDefault('tinymce4_entitiyencoding', 'raw');
36		if (getOption('zp_plugin_tiny_mce')) {
37			setOptionDefault('zp_plugin_tinymce4', 5 | ADMIN_PLUGIN);
38			purgeOption('zp_plugin_tiny_mce');
39		}
40	}
41
42	function getOptionsSupported() {
43		$configs_zenpage = getTinyMCE4ConfigFiles('zenpage');
44		$configs_zenphoto = getTinyMCE4ConfigFiles('zenphoto');
45		$options = array(
46				gettext('Text editor configuration - Zenphoto') => array(
47						'key' => 'tinymce4_zenphoto',
48						'type' => OPTION_TYPE_SELECTOR,
49						'order' => 0,
50						'selections' => $configs_zenphoto,
51						'null_selection' => gettext('Disabled'),
52						'desc' => gettext('Applies to <em>admin</em> editable text other than for Zenpage pages and news articles.')),
53				gettext('Text editor configuration - Zenpage') => array(
54						'key' => 'tinymce4_zenpage',
55						'type' => OPTION_TYPE_SELECTOR,
56						'order' => 0,
57						'selections' => $configs_zenpage,
58						'null_selection' => gettext('Disabled'),
59						'desc' => gettext('Applies to editing on the Zenpage <em>pages</em> and <em>news</em> tabs.')),
60				gettext('Custom image size') => array(
61						'key' => 'tinymce_tinyzenpage_customimagesize',
62						'type' => OPTION_TYPE_TEXTBOX,
63						'order' => 2,
64						'desc' => gettext("Predefined size (px) for custom size images included using tinyZenpage.")),
65				gettext('Custom image size') => array(
66						'key' => 'tinymce_tinyzenpage_customimagesize',
67						'type' => OPTION_TYPE_TEXTBOX,
68						'order' => 2,
69						'desc' => gettext("Predefined size (px) for custom size images included using tinyZenpage.")),
70				gettext('Custom thumb crop - size') => array(
71						'key' => 'tinymce_tinyzenpage_customthumb_size',
72						'type' => OPTION_TYPE_TEXTBOX,
73						'order' => 2,
74						'desc' => gettext("Predefined size (px) for custom cropped thumb images included using tinyZenpage.")),
75				gettext('Custom thumb crop - width') => array(
76						'key' => 'tinymce_tinyzenpage_customthumb_cropwidth',
77						'type' => OPTION_TYPE_TEXTBOX,
78						'order' => 2,
79						'desc' => gettext("Predefined crop width (%) for custom cropped thumb  images included using tinyZenpage.")),
80				gettext('Custom thumb crop - height') => array(
81						'key' => 'tinymce_tinyzenpage_customthumb_cropheight',
82						'type' => OPTION_TYPE_TEXTBOX,
83						'order' => 2,
84						'desc' => gettext("Predefined crop height (%) for custom cropped thumb images included using tinyZenpage.")),
85				gettext('Entity encoding') => array(
86						'key' => 'tinymce4_entityencoding',
87						'type' => OPTION_TYPE_SELECTOR,
88						'order' => 3,
89						'selections' => array(
90								gettext('Raw') => 'raw',
91								gettext('Numeric') => 'numeric',
92								gettext('Named') => 'named',
93								gettext('Named and numeric') => 'named+numeric'
94								),
95						'null_selection' => 'raw',
96						'desc' => gettext('If encountering issues with special chars and other character entities change this. Note that this applies on re-saving content only. More info on the <a href="https://www.tinymce.com/docs/configure/content-filtering/#entity_encoding">tinyMCE docs</a>.')),
97				gettext('Entities') => array(
98						'key' => 'tinymce4_entities',
99						'type' => OPTION_TYPE_TEXTBOX,
100						'order' => 3,
101						'desc' => gettext('You can adjust how entities are processed. More info on the <a href="https://www.tinymce.com/docs/configure/content-filtering/#entities">tinyMCE docs</a>.')),
102		);
103		return $options;
104	}
105
106	function handleOption($option, $currentValue) {
107
108	}
109
110}
111
112function tinymce4ConfigJS($mode) {
113	global $_editorconfig;
114	if (empty($_editorconfig)) { // only if we get here first!
115		$locale = 'en';
116		$loc = str_replace('_', '-', getOption("locale"));
117		if ($loc) {
118			if (file_exists(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/tinymce4/langs/' . $loc . '.js')) {
119				$locale = $loc;
120			} else {
121				$loc = substr($loc, 0, 2);
122				if (file_exists(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/tinymce4/langs/' . $loc . '.js')) {
123					$locale = $loc;
124				}
125			}
126		}
127
128		$_editorconfig = getOption('tinymce4_' . $mode);
129		if (!empty($_editorconfig)) {
130			$_editorconfig = getPlugin('/tinymce4/config/' . $_editorconfig, true);
131			if (!empty($_editorconfig)) {
132				require_once($_editorconfig);
133			}
134		}
135	}
136	return $mode;
137}
138
139function getTinyMCE4ConfigFiles($mode) {
140	// get only those that work!
141	$files = getPluginFiles($mode . '-*.js.php', 'tinymce4/config/');
142	$array = array();
143	foreach ($files as $file) {
144		$filename = strrchr($file, '/');
145		$filename = substr($filename, 1);
146		$option = preg_replace('/^' . $mode . '-/', '', $filename);
147		$option = ucfirst(preg_replace('/.js.php$/', '', $option));
148		$array[$option] = $filename;
149	}
150	return $array;
151}
152
153?>