. namespace tiny_premium; /** * Tiny Premium manager. * * @package tiny_premium * @copyright 2024 David Woloszyn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class manager { /** * Get all Tiny Premium plugins currently supported. * * The plugin identifiers are taken from Tiny Cloud (https://www.tiny.cloud/docs/tinymce/6/plugins/#premium-plugins). * * @return array The array of plugins. */ public static function get_plugins(): array { return [ 'a11ychecker', 'advtable', 'typography', 'casechange', 'checklist', 'editimage', 'export', 'footnotes', 'formatpainter', 'linkchecker', 'math', 'pageembed', 'permanentpen', 'powerpaste', 'tinymcespellchecker', 'autocorrect', 'tableofcontents', ]; } /** * Get enabled Tiny Premium plugins. * * @return array The array of enabled plugins. */ public static function get_enabled_plugins(): array { $plugins = self::get_plugins(); $enabledplugins = []; foreach ($plugins as $plugin) { if (self::is_plugin_enabled($plugin)) { $enabledplugins[] = $plugin; } } return $enabledplugins; } /** * Check if a Tiny Premium plugin is enabled in config. * * @param string $plugin The plugin to check. * @return bool Return true if enabled. */ public static function is_plugin_enabled(string $plugin): bool { $config = get_config('tiny_premium_' . $plugin, 'enabled'); return ($config == 1); } /** * Set a new value for a Tiny Premium plugin config. * * @param array $data The data to set. * @param string $plugin The plugin to use. */ public static function set_plugin_config(array $data, string $plugin): void { // Check this is a valid premium plugin. if (!in_array($plugin, self::get_plugins())) { return; } $plugin = 'tiny_premium_' . $plugin; 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); // If we are disabling the plugin, remove it, otherwise, set the new value. if ($key === 'enabled' && $newvalue == 0) { unset_config($key, $plugin); } else { set_config($key, $newvalue, $plugin); } } } }