Merge branch 'MDL-85726-main' of https://github.com/HuongNV13/moodle
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
define("tiny_premium/configuration",["exports","editor_tiny/utils","editor_tiny/options"],(function(_exports,_utils,_options){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.configure=void 0;_exports.configure=(instanceConfig,options)=>{const enabledPremiumPlugins=(0,_options.getInitialPluginConfiguration)(options)[(0,_options.getPluginOptionName)("tiny_premium/plugin","premiumplugins")].split(",");let plugins=instanceConfig.plugins,menu=instanceConfig.menu,toolbar=(toolbar=>(toolbar=(0,_utils.addToolbarSection)(toolbar,"premium_a","advanced",!0),(0,_utils.addToolbarSection)(toolbar,"premium_b","formatting",!0)))(instanceConfig.toolbar),contextmenu=instanceConfig.contextmenu;return-1!==enabledPremiumPlugins.indexOf("advtable")&&(plugins+=" advtable",menu=(0,_utils.addMenubarItem)(menu,"table","| advtablerownumbering","advtablesort")),-1!==enabledPremiumPlugins.indexOf("editimage")&&(plugins+=" editimage",toolbar=(0,_utils.addToolbarButton)(toolbar,"content","editimage","tiny_media_image"),instanceConfig.editimage_toolbar="rotateleft rotateright flipv fliph editimage"),-1!==enabledPremiumPlugins.indexOf("export")&&(plugins+=" export",menu=(0,_utils.addMenubarItem)(menu,"tools","| export")),-1!==enabledPremiumPlugins.indexOf("pageembed")&&(plugins+=" pageembed",toolbar=(0,_utils.addToolbarButton)(toolbar,"content","pageembed","tiny_media_video")),-1!==enabledPremiumPlugins.indexOf("typography")&&(plugins+=" typography",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_b","typography")),-1!==enabledPremiumPlugins.indexOf("casechange")&&(plugins+=" casechange",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","casechange")),-1!==enabledPremiumPlugins.indexOf("checklist")&&(plugins+=" checklist",toolbar=(0,_utils.addToolbarButton)(toolbar,"lists","checklist")),-1!==enabledPremiumPlugins.indexOf("tinymcespellchecker")&&(plugins+=" tinymcespellchecker",menu=(0,_utils.addMenubarItem)(menu,"tools","spellcheckdialog","spellcheckerlanguage"),contextmenu=(0,_utils.addContextmenuItem)(contextmenu,"spellchecker"),toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","spellcheckdialog")),-1!==enabledPremiumPlugins.indexOf("autocorrect")&&(plugins+=" autocorrect",menu=(0,_utils.addMenubarItem)(menu,"tools","| autocorrect capitalization","spellcheckdialog")),-1!==enabledPremiumPlugins.indexOf("permanentpen")&&(plugins+=" permanentpen",menu=(0,_utils.addMenubarItem)(menu,"format","| permanentpen configurepermanentpen"),toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","permanentpen"),contextmenu=(0,_utils.addContextmenuItem)(contextmenu,"configurepermanentpen")),-1!==enabledPremiumPlugins.indexOf("formatpainter")&&(plugins+=" formatpainter",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","formatpainter")),-1!==enabledPremiumPlugins.indexOf("linkchecker")&&(plugins+=" linkchecker",contextmenu=(0,_utils.addContextmenuItem)(contextmenu,"linkchecker")),-1!==enabledPremiumPlugins.indexOf("tableofcontents")&&(plugins+=" tableofcontents",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","tableofcontents")),-1!==enabledPremiumPlugins.indexOf("math")&&(plugins+=" math",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","math"),menu=(0,_utils.addMenubarItem)(menu,"insert","math","tableofcontents")),-1!==enabledPremiumPlugins.indexOf("footnotes")&&(plugins+=" footnotes",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","footnotes"),menu=(0,_utils.addMenubarItem)(menu,"insert","footnotes","tableofcontents")),-1!==enabledPremiumPlugins.indexOf("powerpaste")&&(plugins+=" powerpaste"),-1!==enabledPremiumPlugins.indexOf("a11ychecker")&&(plugins+=" a11ychecker",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","a11ycheck"),menu=(0,_utils.removeMenubarItem)(menu,"tools","a11ycheck"),menu=(0,_utils.addMenubarItem)(menu,"tools","a11ycheck","count"),menu=(0,_utils.removeMenubarItem)(menu,"tools","tiny_accessibilitychecker")),{plugins:plugins,toolbar:toolbar,menu:menu,contextmenu:contextmenu}}}));
|
||||
define("tiny_premium/configuration",["exports","editor_tiny/utils","editor_tiny/options"],(function(_exports,_utils,_options){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.configure=void 0;_exports.configure=(instanceConfig,options)=>{const pluginOptions=(0,_options.getInitialPluginConfiguration)(options),enabledPremiumPlugins=pluginOptions[(0,_options.getPluginOptionName)("tiny_premium/plugin","premiumplugins")].split(",");let serviceUrls=pluginOptions[(0,_options.getPluginOptionName)("tiny_premium/plugin","serviceurls")],plugins=instanceConfig.plugins,menu=instanceConfig.menu,toolbar=(toolbar=>(toolbar=(0,_utils.addToolbarSection)(toolbar,"premium_a","advanced",!0),(0,_utils.addToolbarSection)(toolbar,"premium_b","formatting",!0)))(instanceConfig.toolbar),contextmenu=instanceConfig.contextmenu,pluginsettings={};return pluginsettings={...pluginsettings,...serviceUrls},-1!==enabledPremiumPlugins.indexOf("advtable")&&(plugins+=" advtable",menu=(0,_utils.addMenubarItem)(menu,"table","| advtablerownumbering","advtablesort")),-1!==enabledPremiumPlugins.indexOf("editimage")&&(plugins+=" editimage",toolbar=(0,_utils.addToolbarButton)(toolbar,"content","editimage","tiny_media_image"),instanceConfig.editimage_toolbar="rotateleft rotateright flipv fliph editimage"),-1!==enabledPremiumPlugins.indexOf("export")&&(plugins+=" export",menu=(0,_utils.addMenubarItem)(menu,"tools","| export")),-1!==enabledPremiumPlugins.indexOf("pageembed")&&(plugins+=" pageembed",toolbar=(0,_utils.addToolbarButton)(toolbar,"content","pageembed","tiny_media_video")),-1!==enabledPremiumPlugins.indexOf("typography")&&(plugins+=" typography",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_b","typography")),-1!==enabledPremiumPlugins.indexOf("casechange")&&(plugins+=" casechange",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","casechange")),-1!==enabledPremiumPlugins.indexOf("checklist")&&(plugins+=" checklist",toolbar=(0,_utils.addToolbarButton)(toolbar,"lists","checklist")),-1!==enabledPremiumPlugins.indexOf("tinymcespellchecker")&&(plugins+=" tinymcespellchecker",menu=(0,_utils.addMenubarItem)(menu,"tools","spellcheckdialog","spellcheckerlanguage"),contextmenu=(0,_utils.addContextmenuItem)(contextmenu,"spellchecker"),toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","spellcheckdialog")),-1!==enabledPremiumPlugins.indexOf("autocorrect")&&(plugins+=" autocorrect",menu=(0,_utils.addMenubarItem)(menu,"tools","| autocorrect capitalization","spellcheckdialog")),-1!==enabledPremiumPlugins.indexOf("permanentpen")&&(plugins+=" permanentpen",menu=(0,_utils.addMenubarItem)(menu,"format","| permanentpen configurepermanentpen"),toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","permanentpen"),contextmenu=(0,_utils.addContextmenuItem)(contextmenu,"configurepermanentpen")),-1!==enabledPremiumPlugins.indexOf("formatpainter")&&(plugins+=" formatpainter",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","formatpainter")),-1!==enabledPremiumPlugins.indexOf("linkchecker")&&(plugins+=" linkchecker",contextmenu=(0,_utils.addContextmenuItem)(contextmenu,"linkchecker")),-1!==enabledPremiumPlugins.indexOf("tableofcontents")&&(plugins+=" tableofcontents",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","tableofcontents")),-1!==enabledPremiumPlugins.indexOf("math")&&(plugins+=" math",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","math"),menu=(0,_utils.addMenubarItem)(menu,"insert","math","tableofcontents")),-1!==enabledPremiumPlugins.indexOf("footnotes")&&(plugins+=" footnotes",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","footnotes"),menu=(0,_utils.addMenubarItem)(menu,"insert","footnotes","tableofcontents")),-1!==enabledPremiumPlugins.indexOf("powerpaste")&&(plugins+=" powerpaste"),-1!==enabledPremiumPlugins.indexOf("a11ychecker")&&(plugins+=" a11ychecker",toolbar=(0,_utils.addToolbarButton)(toolbar,"premium_a","a11ycheck"),menu=(0,_utils.removeMenubarItem)(menu,"tools","a11ycheck"),menu=(0,_utils.addMenubarItem)(menu,"tools","a11ycheck","count"),menu=(0,_utils.removeMenubarItem)(menu,"tools","tiny_accessibilitychecker")),{plugins:plugins,toolbar:toolbar,menu:menu,contextmenu:contextmenu,...pluginsettings}}}));
|
||||
|
||||
//# sourceMappingURL=configuration.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -45,12 +45,14 @@ export const configure = (instanceConfig, options) => {
|
||||
// Due to the timing the plugin options are available, we need to get at the options in this slightly unconventional way.
|
||||
const pluginOptions = getInitialPluginConfiguration(options);
|
||||
const enabledPremiumPlugins = pluginOptions[getPluginOptionName('tiny_premium/plugin', 'premiumplugins')].split(',');
|
||||
let serviceUrls = pluginOptions[getPluginOptionName('tiny_premium/plugin', 'serviceurls')];
|
||||
|
||||
let plugins = instanceConfig.plugins;
|
||||
let menu = instanceConfig.menu;
|
||||
let toolbar = configureToolbar(instanceConfig.toolbar);
|
||||
let contextmenu = instanceConfig.contextmenu;
|
||||
let pluginsettings = {};
|
||||
pluginsettings = {...pluginsettings, ...serviceUrls};
|
||||
|
||||
// Advanced Table.
|
||||
if (enabledPremiumPlugins.indexOf('advtable') !== -1) {
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tiny_premium\form;
|
||||
|
||||
use moodleform;
|
||||
|
||||
/**
|
||||
* Form for configuring Tiny Premium plugin settings.
|
||||
*
|
||||
* @package tiny_premium
|
||||
* @copyright 2025 Huong Nguyen <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tiny_premium_settings_form extends moodleform {
|
||||
|
||||
#[\Override]
|
||||
protected function definition(): void {
|
||||
$mform = $this->_form;
|
||||
$returnurl = $this->_customdata['returnurl'] ?? null;
|
||||
$plugin = $this->_customdata['plugin'] ?? '';
|
||||
$this->add_settings($mform, $plugin);
|
||||
|
||||
$mform->addElement('hidden', 'plugin', $plugin);
|
||||
$mform->setType('plugin', PARAM_ALPHA);
|
||||
if ($returnurl) {
|
||||
$mform->addElement('hidden', 'returnurl', $returnurl);
|
||||
$mform->setType('returnurl', PARAM_LOCALURL);
|
||||
}
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add settings to the form.
|
||||
* This method can be overridden to add additional settings for specific plugins.
|
||||
*
|
||||
* @param \MoodleQuickForm $mform The Moodle QuickForm instance to which settings will be added.
|
||||
* @param string $plugin The plugin name for which settings are being added.
|
||||
*/
|
||||
protected function add_settings(
|
||||
\MoodleQuickForm $mform,
|
||||
string $plugin = '',
|
||||
): void {
|
||||
$pluginname = '';
|
||||
if (!empty($plugin)) {
|
||||
$configs = \tiny_premium\manager::get_plugin_config($plugin);
|
||||
$pluginname = get_string('premiumplugin:' . $plugin, 'tiny_premium');
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'serversidesettingssheader', get_string('serverside:service', 'tiny_premium'));
|
||||
$settingshelp = \html_writer::tag('p', get_string('serverside:desc', 'tiny_premium', $pluginname));
|
||||
$mform->addElement('html', $settingshelp);
|
||||
|
||||
$radiogroup = [
|
||||
$mform->createElement('radio', 'server_side_service', '', get_string('serverside:service:tinycloud', 'tiny_premium'),
|
||||
'1'),
|
||||
$mform->createElement('radio', 'server_side_service', '', get_string('serverside:service:selfhosted', 'tiny_premium'),
|
||||
'2'),
|
||||
];
|
||||
|
||||
$mform->addGroup($radiogroup, 'server_side_service_group', get_string('serverside:service', 'tiny_premium'), '<br>',
|
||||
false);
|
||||
if (empty($configs->service_url)) {
|
||||
$mform->setDefault('server_side_service', 1);
|
||||
} else {
|
||||
$mform->setDefault('server_side_service', 2);
|
||||
}
|
||||
|
||||
$mform->addElement('text', 'service_url', get_string('serviceurl', 'tiny_premium'));
|
||||
$mform->setType('service_url', PARAM_TEXT);
|
||||
$mform->hideIf('service_url', 'server_side_service', 'eq', '1');
|
||||
if (isset($configs->service_url)) {
|
||||
$mform->setDefault('service_url', $configs->service_url);
|
||||
}
|
||||
|
||||
$mform->addElement('static', 'description', '', get_string('serviceurl:desc', 'tiny_premium', $pluginname));
|
||||
$mform->hideIf('description', 'server_side_service', 'eq', '1');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function validation($data, $files): array {
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
// Validate the service URL if self-hosted service is selected.
|
||||
if (isset($data['server_side_service']) && $data['server_side_service'] == 2) {
|
||||
if (empty($data['service_url'])) {
|
||||
$errors['service_url'] = get_string('required');
|
||||
} else {
|
||||
// Validate the URL format.
|
||||
if (!filter_var($data['service_url'], FILTER_VALIDATE_URL)) {
|
||||
$errors['service_url'] = get_string('invalidurl', 'tiny_premium');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function get_data(): ?\stdClass {
|
||||
$data = parent::get_data();
|
||||
|
||||
if ($data) {
|
||||
// If the server-side service is Tiny Cloud, unset the service URL.
|
||||
if (isset($data->server_side_service) && $data->server_side_service == 1) {
|
||||
unset($data->service_url);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
+11
@@ -101,6 +101,7 @@ class admin_setting_tiny_premium_plugins extends \admin_setting {
|
||||
$table->head = [
|
||||
get_string('name'),
|
||||
get_string('enable'),
|
||||
get_string('settings'),
|
||||
];
|
||||
$table->colclasses = [
|
||||
'leftalign',
|
||||
@@ -112,6 +113,7 @@ class admin_setting_tiny_premium_plugins extends \admin_setting {
|
||||
$plugins = manager::get_plugins();
|
||||
$enabledplugins = manager::get_enabled_plugins();
|
||||
$disabledplugins = array_diff($plugins, $enabledplugins);
|
||||
$serversideplugins = manager::get_server_side_plugins();
|
||||
$plugins = array_merge($enabledplugins, $disabledplugins);
|
||||
|
||||
foreach ($plugins as $plugin) {
|
||||
@@ -137,10 +139,19 @@ class admin_setting_tiny_premium_plugins extends \admin_setting {
|
||||
]);
|
||||
$hideshowlink = \html_writer::link($hideshowurl, $icon);
|
||||
|
||||
$settinglink = '';
|
||||
// Setting link for server-side plugins.
|
||||
if (array_key_exists($plugin, $serversideplugins)) {
|
||||
$settinglink = \html_writer::link(new \moodle_url('/lib/editor/tiny/plugins/premium/extrasettings.php', [
|
||||
'plugin' => $plugin,
|
||||
]), get_string('settings'));
|
||||
}
|
||||
|
||||
// Populate table row.
|
||||
$row = new \html_table_row([
|
||||
$pluginname,
|
||||
$hideshowlink,
|
||||
$settinglink,
|
||||
]);
|
||||
$row->attributes['class'] = $class;
|
||||
$table->data[] = $row;
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
namespace tiny_premium;
|
||||
|
||||
use moodle_url;
|
||||
use moodleform;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Tiny Premium manager.
|
||||
*
|
||||
@@ -25,6 +29,9 @@ namespace tiny_premium;
|
||||
*/
|
||||
class manager {
|
||||
|
||||
/** @var string Tiny Premium plugin prefix. */
|
||||
const PLUGIN_NAME_PREFIX = 'tiny_premium_';
|
||||
|
||||
/**
|
||||
* Get all Tiny Premium plugins currently supported.
|
||||
*
|
||||
@@ -54,6 +61,24 @@ class manager {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Tiny Premium plugins that require server-side processing.
|
||||
*
|
||||
* This method returns an associative array where the keys are the plugin names
|
||||
* and the values are the corresponding configuration keys for the server-side
|
||||
* processing URLs. These plugins require additional server-side services to
|
||||
* function properly.
|
||||
*
|
||||
* @return string[] An associative array of server-side plugins and their configuration keys.
|
||||
*/
|
||||
public static function get_server_side_plugins(): array {
|
||||
return [
|
||||
'editimage' => 'editimage_proxy_service_url',
|
||||
'linkchecker' => 'linkchecker_service_url',
|
||||
'tinymcespellchecker' => 'spellchecker_rpc_url',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled Tiny Premium plugins.
|
||||
*
|
||||
@@ -77,7 +102,8 @@ class manager {
|
||||
* @return bool Return true if enabled.
|
||||
*/
|
||||
public static function is_plugin_enabled(string $plugin): bool {
|
||||
$config = get_config('tiny_premium_' . $plugin, 'enabled');
|
||||
$plugin = self::get_formatted_plugin_name($plugin);
|
||||
$config = get_config($plugin, 'enabled');
|
||||
return ($config == 1);
|
||||
}
|
||||
|
||||
@@ -93,19 +119,97 @@ class manager {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin = 'tiny_premium_' . $plugin;
|
||||
|
||||
$formattedplugin = self::get_formatted_plugin_name($plugin);
|
||||
$unsetconfigs = [];
|
||||
foreach ($data as $key => $newvalue) {
|
||||
// Get the old value for the log.
|
||||
$oldvalue = get_config($plugin, $key) ?? null;
|
||||
add_to_config_log($key, $oldvalue, $newvalue, $plugin);
|
||||
$oldvalue = get_config($formattedplugin, $key) ?? null;
|
||||
add_to_config_log($key, $oldvalue, $newvalue, $formattedplugin);
|
||||
|
||||
// If we are disabling the plugin, remove it, otherwise, set the new value.
|
||||
if ($key === 'enabled' && $newvalue == 0) {
|
||||
unset_config($key, $plugin);
|
||||
$unsetconfigs[] = $key;
|
||||
} else {
|
||||
set_config($key, $newvalue, $plugin);
|
||||
set_config($key, $newvalue, $formattedplugin);
|
||||
}
|
||||
}
|
||||
|
||||
self::unset_plugin_config($unsetconfigs, $plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get values for a Tiny Premium plugin config.
|
||||
*
|
||||
* @param string $plugin The plugin to get.
|
||||
* @param string|null $name The name of the config to get.
|
||||
* @return mixed hash-like object or single value, return false no config found.
|
||||
*/
|
||||
public static function get_plugin_config(
|
||||
string $plugin,
|
||||
?string $name = null,
|
||||
): mixed {
|
||||
// Check this is a valid premium plugin.
|
||||
if (!in_array($plugin, self::get_plugins())) {
|
||||
return false;
|
||||
}
|
||||
$plugin = self::get_formatted_plugin_name($plugin);
|
||||
return get_config($plugin, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset a Tiny Premium plugin configs.
|
||||
*
|
||||
* @param array $names List of config names to unset.
|
||||
* @param string $plugin The plugin to use.
|
||||
*/
|
||||
public static function unset_plugin_config(
|
||||
array $names,
|
||||
string $plugin,
|
||||
): void {
|
||||
// Check this is a valid premium plugin.
|
||||
if (!in_array($plugin, self::get_plugins())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin = self::get_formatted_plugin_name($plugin);
|
||||
foreach ($names as $key) {
|
||||
unset_config($key, $plugin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings form for a Tiny Premium plugin.
|
||||
* This method will check if a custom form class exists for the plugin,
|
||||
* otherwise it will use the default settings form.
|
||||
*
|
||||
* @param string $plugin The plugin to get the settings form for.
|
||||
* @param moodle_url|null $return The URL to return to after saving the form.
|
||||
* @return moodleform Settings form for the Tiny Premium plugin.
|
||||
*/
|
||||
public static function get_settings_form(
|
||||
string $plugin,
|
||||
?moodle_url $return = null,
|
||||
): moodleform {
|
||||
$formclassname = '\tiny_premium\form\tiny_premium_' . $plugin . '_settings_form';
|
||||
if (!class_exists($formclassname)) {
|
||||
$formclassname = '\tiny_premium\form\tiny_premium_settings_form';
|
||||
}
|
||||
|
||||
return new $formclassname(null, [
|
||||
'plugin' => $plugin,
|
||||
'returnurl' => $return,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted plugin name for config.
|
||||
*
|
||||
* @param string $plugin The plugin to format.
|
||||
* @return string The formatted plugin name.
|
||||
*/
|
||||
public static function get_formatted_plugin_name(
|
||||
string $plugin,
|
||||
): string {
|
||||
return self::PLUGIN_NAME_PREFIX . $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ use editor_tiny\editor;
|
||||
use editor_tiny\plugin;
|
||||
use editor_tiny\plugin_with_configuration;
|
||||
use editor_tiny\plugin_with_configuration_for_external;
|
||||
use tiny_premium\manager;
|
||||
|
||||
/**
|
||||
* Tiny Premium plugin.
|
||||
@@ -58,15 +57,22 @@ class plugininfo extends plugin implements plugin_with_configuration, plugin_wit
|
||||
?editor $editor = null
|
||||
): array {
|
||||
$allowedplugins = [];
|
||||
$serviceurls = [];
|
||||
$serverplugins = manager::get_server_side_plugins();
|
||||
|
||||
foreach (manager::get_enabled_plugins() as $plugin) {
|
||||
if (has_capability("tiny/premium:use{$plugin}", $context)) {
|
||||
$allowedplugins[] = $plugin;
|
||||
}
|
||||
$serviceurl = get_config(manager::get_formatted_plugin_name($plugin), 'service_url');
|
||||
if ($serviceurl && isset($serverplugins[$plugin])) {
|
||||
$serviceurls[$serverplugins[$plugin]] = $serviceurl;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'premiumplugins' => implode(',', $allowedplugins),
|
||||
'serviceurls' => $serviceurls,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -75,6 +81,7 @@ class plugininfo extends plugin implements plugin_with_configuration, plugin_wit
|
||||
$settings = self::get_plugin_configuration_for_context($context, [], []);
|
||||
return [
|
||||
'premiumplugins' => $settings['premiumplugins'],
|
||||
'serviceurls' => $settings['serviceurls'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* TinyMCE Premium plugins settings page.
|
||||
*
|
||||
* @package tiny_premium
|
||||
* @copyright 2025 Huong Nguyen <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
// This is an admin page.
|
||||
admin_externalpage_setup('tiny_premium_plugin_settings');
|
||||
$return = new moodle_url('/admin/settings.php', ['section' => 'tiny_premium_settings']);
|
||||
$plugin = optional_param('plugin', '', PARAM_ALPHA);
|
||||
|
||||
// Get form class.
|
||||
$form = \tiny_premium\manager::get_settings_form(
|
||||
plugin: $plugin,
|
||||
return: $return,
|
||||
);
|
||||
if ($form->is_cancelled()) {
|
||||
redirect($return);
|
||||
} else if ($data = $form->get_data()) {
|
||||
if (isset($data->service_url) && $data->service_url !== '') {
|
||||
\tiny_premium\manager::set_plugin_config(
|
||||
data: ['service_url' => $data->service_url],
|
||||
plugin: $data->plugin,
|
||||
);
|
||||
} else {
|
||||
\tiny_premium\manager::unset_plugin_config(
|
||||
names: ['service_url'],
|
||||
plugin: $data->plugin,
|
||||
);
|
||||
}
|
||||
redirect($return, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
|
||||
}
|
||||
|
||||
// Get all Tiny Premium plugins.
|
||||
$premiumplugins = \tiny_premium\manager::get_plugins();
|
||||
if (!in_array($plugin, $premiumplugins)) {
|
||||
throw new moodle_exception('pluginnotfound', 'tiny_premium', $return, $plugin);
|
||||
}
|
||||
$pluginname = get_string('premiumplugin:' . $plugin, 'tiny_premium');
|
||||
|
||||
// Display the page.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($pluginname);
|
||||
$form->display();
|
||||
echo $OUTPUT->footer();
|
||||
@@ -29,6 +29,7 @@ $string['accessibilitycheckerinfo'] = 'The TinyMCE Premium Accessibility Checker
|
||||
$string['apikey'] = 'API key';
|
||||
$string['apikey_desc'] = 'Your API key is available on your <a href="https://www.tiny.cloud">Tiny Cloud</a> account page if you have purchased a subscription, or if you are on a free trial.';
|
||||
$string['emptyapikeywarning'] = 'Enabled TinyMCE Premium plugins will not be available until an API key is added.';
|
||||
$string['invalidurl'] = 'Entered URL is invalid';
|
||||
$string['pluginname'] = 'TinyMCE Premium';
|
||||
$string['pluginnotfound'] = 'Tiny Premium plugin {$a} not found.';
|
||||
$string['premium:use'] = 'Use TinyMCE Premium';
|
||||
@@ -68,7 +69,14 @@ $string['premiumplugin:tinymcespellchecker'] = 'Spell Checker Pro';
|
||||
$string['premiumplugin:typography'] = 'Advanced Typography';
|
||||
$string['premiumplugins'] = 'Premium plugins';
|
||||
$string['premiumplugins_desc'] = 'Access to TinyMCE Premium plugins requires an API key. Not all listed plugins may be available with your TinyMCE Premium subscription. You can check available plugins on your <a href="https://www.tiny.cloud">Tiny Cloud</a> account page.';
|
||||
$string['premiumplugins_settings'] = 'TinyMCE Premium plugins settings';
|
||||
$string['privacy:metadata'] = 'The Tiny Premium plugin for TinyMCE does not store any personal data.';
|
||||
$string['serverside:desc'] = 'The {$a} plugin uses a server-side service to process data. You can choose to use the Tiny Cloud service, or connect to your own self-hosted instance using a service URL.';
|
||||
$string['serverside:service'] = 'Server-side service';
|
||||
$string['serverside:service:selfhosted'] = 'Use self-hosted service';
|
||||
$string['serverside:service:tinycloud'] = 'Use Tiny Cloud';
|
||||
$string['serviceurl'] = 'Service URL';
|
||||
$string['serviceurl:desc'] = 'Enter the URL of your self-hosted {$a} service. <a href="https://www.tiny.cloud/docs/tinymce/latest/bundle-intro-setup/" target="_blank">View setup guide from Tiny</a>.';
|
||||
|
||||
// Deprecated since Moodle 4.5.
|
||||
$string['helplinktext'] = 'Premium plugins';
|
||||
|
||||
@@ -40,4 +40,14 @@ if ($hassiteconfig) {
|
||||
// Set individual Tiny Premium plugins.
|
||||
$settings->add(new \tiny_premium\local\admin_setting_tiny_premium_plugins());
|
||||
}
|
||||
|
||||
// Extra settings for on-premise plugins (hidden, accessed via direct link from the settings page).
|
||||
$page = new admin_externalpage(
|
||||
name: 'tiny_premium_plugin_settings',
|
||||
visiblename: get_string('premiumplugins_settings', 'tiny_premium'),
|
||||
url: new moodle_url('/lib/editor/tiny/plugins/premium/extrasettings.php'),
|
||||
req_capability: 'moodle/site:config',
|
||||
hidden: true,
|
||||
);
|
||||
$ADMIN->add('editortiny', $page);
|
||||
}
|
||||
|
||||
@@ -27,3 +27,29 @@ Feature: Check the features of the TinyMCE Premium settings
|
||||
When I click on "Enable Accessibility Checker" "link"
|
||||
Then I should see "Accessibility Checker enabled."
|
||||
And I should see "The TinyMCE Premium Accessibility Checker will override the default Accessibility Checker for users who have access to it."
|
||||
|
||||
@javascript
|
||||
Scenario Outline: I can set service URL for the TinyMCE Premium plugins
|
||||
Given the following config values are set as admin:
|
||||
| apikey | "123456" | tiny_premium |
|
||||
And "Settings" "link" should exist in the "<plugin>" "table_row"
|
||||
When I click on "Settings" "link" in the "<plugin>" "table_row"
|
||||
Then I should see "The <plugin> plugin uses a server-side service to process data. You can choose to use the Tiny Cloud service, or connect to your own self-hosted instance using a service URL."
|
||||
And I should see "Use Tiny Cloud"
|
||||
And I should see "Use self-hosted service"
|
||||
And "Service URL" "field" should not be visible
|
||||
And I click on "Use self-hosted service" "radio"
|
||||
And "Service URL" "field" should be visible
|
||||
And I should see "Enter the URL of your self-hosted <plugin> service"
|
||||
And I set the field "Service URL" to "<serviceurl>"
|
||||
And I click on "Save changes" "button"
|
||||
And I should see "Changes saved"
|
||||
And I click on "Settings" "link" in the "<plugin>" "table_row"
|
||||
And "Service URL" "field" should be visible
|
||||
And the field "Service URL" matches value "<serviceurl>"
|
||||
|
||||
Examples:
|
||||
| plugin | serviceurl |
|
||||
| Enhanced Image Editing | http://moodle.test:8080/ephox-image-proxy |
|
||||
| Link Checker | http://moodle.test:8080/ephox-hyperlinking |
|
||||
| Spell Checker Pro | http://moodle.test:8080/ephox-spelling |
|
||||
|
||||
@@ -55,9 +55,9 @@ final class plugininfo_test extends advanced_testcase {
|
||||
$context = \context_system::instance();
|
||||
$this->setUser($user);
|
||||
|
||||
$this->assertEquals(
|
||||
['premiumplugins' => implode(',', \tiny_premium\manager::get_plugins())],
|
||||
plugininfo::get_plugin_configuration_for_external($context)
|
||||
);
|
||||
$configs = plugininfo::get_plugin_configuration_for_external($context);
|
||||
$this->assertArrayHasKey('premiumplugins', $configs);
|
||||
$this->assertArrayHasKey('serviceurls', $configs);
|
||||
$this->assertEquals(implode(',', \tiny_premium\manager::get_plugins()), $configs['premiumplugins']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user