From 944ac6f050a886d6d38d6184fc9b0d3441e1dc17 Mon Sep 17 00:00:00 2001 From: Vincent Schneider <22986332+cli-ish@users.noreply.github.com> Date: Sat, 17 Aug 2024 09:37:32 +0200 Subject: [PATCH] Update plugin structure based on https://github.com/ponlawat-w/moodle-local_accessibility/pull/13 --- .../textcolour.php | 21 +++++++--- styles.php | 38 ------------------- version.php | 4 +- 3 files changed, 17 insertions(+), 46 deletions(-) rename accessibility_textcolour.php => classes/textcolour.php (70%) delete mode 100644 styles.php diff --git a/accessibility_textcolour.php b/classes/textcolour.php similarity index 70% rename from accessibility_textcolour.php rename to classes/textcolour.php index 2e1269b..1e75f85 100644 --- a/accessibility_textcolour.php +++ b/classes/textcolour.php @@ -22,16 +22,15 @@ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace local_accessibility\widgets; +namespace accessibility_textcolour; -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__ . '/../../classes/colourwidget.php'); +use local_accessibility\widgets\apply_style; +use local_accessibility\widgets\colourwidget; /** * Text colour accessibility widget definition */ -class textcolour extends colourwidget { +class textcolour extends colourwidget implements apply_style { /** * Constructor @@ -52,7 +51,6 @@ public function init() { $userconfig = $this->getuserconfig(); if ($userconfig) { $this->addbodyclass('accessibility-textcolour'); - $PAGE->requires->css('/local/accessibility/widgets/textcolour/styles.php'); } $PAGE->requires->js_call_amd('local_accessibility/colourwidget', 'init', [ @@ -62,4 +60,15 @@ public function init() { 'accessibility-textcolour', ]); } + + public function apply_style(): string { + $userconfig = $this->getuserconfig(); + if (!$userconfig) { + return ""; + } + // Strip all special characters except # because its needed for hex colors. + // A check for #XX.. could have been used but this would not allow named css colors such as red, or green. + $color = preg_replace("/[^A-Za-z0-9#]/", '', $userconfig); + return "body.accessibility-textcolour, body.accessibility-textcolour * { color: {$color}; }"; + } } diff --git a/styles.php b/styles.php deleted file mode 100644 index acfb92d..0000000 --- a/styles.php +++ /dev/null @@ -1,38 +0,0 @@ -. - -/** - * This will return CSS style text to be added to Moodle page that will overwrite default theme by user configuration - * - * @package accessibility_textcolour - * @copyright 2023 Ponlawat Weerapanpisit - * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -require_once(__DIR__ . '/../../../../config.php'); // @codingStandardsIgnoreLine ignore login check as guest is also allowed. -header('Content-Type: text/css'); - -require_once(__DIR__ . '/../../lib.php'); -require_once(__DIR__ . '/accessibility_textcolour.php'); - -$widget = new local_accessibility\widgets\textcolour(); - -$userconfig = $widget->getuserconfig(); -if (!$userconfig) { - exit; -} - -echo "body.accessibility-textcolour, body.accessibility-textcolour * { color: {$userconfig}; }"; diff --git a/version.php b/version.php index eace6e3..bc5db56 100644 --- a/version.php +++ b/version.php @@ -26,9 +26,9 @@ $plugin->component = 'accessibility_textcolour'; $plugin->release = '1.0.1'; -$plugin->version = 2023103000; +$plugin->version = 2024051300; $plugin->requires = 2022041900; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = [ - 'local_accessibility' => 2023071300, + 'local_accessibility' => 2024050800, ];