From 128937ee39d60540e30ba396a6af9021ecc25f3c Mon Sep 17 00:00:00 2001 From: Michael Milette Date: Mon, 22 Jul 2024 10:28:43 -0400 Subject: [PATCH] Revert "Added new {ifuser} tag." This reverts commit 135e1609e4c4c3e5b15f37ed62bad2dcda38ccc7. --- README.md | 8 ++++---- filter.php | 23 +---------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ed4f174..c24da8e 100644 --- a/README.md +++ b/README.md @@ -561,7 +561,7 @@ Example: To apply the patch for Moodle using git (change the "M403" for other ve git cherry-pick FETCH_HEAD ``` -This is usually enough to make the filters work in the custom menu. However, we have noticed it may not work with some Moodle themes, most notably premium themes. Those themes will need to be patched using the Technique B. +This is usually enough to make the filters work in the custom menu. However, we have noticed it may not work with some Moodle themes, most notably premium themes. Those themes will need to be patched using the technique B. **Technique B**: If technique A does not work for you, you will need to integrate a few lines of code into your Moodle theme, or ask your theme's developer/maintainer to apply this change for you. Be sure to follow the correct instructions for your version of Moodle. @@ -613,11 +613,11 @@ Add this code to the core_renderer section (probably located in /theme/yourtheme } ``` -### For themes based on **boost** (Moodle 3.2 to 3.11 and some 4.0+) +### For themes based on **boost** (Moodle 3.2 and later) -Note: Supported in Moodle 3.2 to 3.11. Most Moodle 4.0 themes do not require this patch but some that were ported for 4.0+ still do. +Note: Supported in Moodle 3.2 and later. If you are using Moodle 4.0 or later, you **must also** integrate the patch **For themes based on boost (Moodle 4.0 and later)** above. -Add the following code to core_renderer section (often found in /theme/yourtheme/classes/output/core_renderer.php) of your theme. Note: Your theme may even already have such a class (they often do). The important lines are chunk of code that starts with "// Filter custom menu items..." including the 5 lines that follow it. +Add the following code to core_renderer section (often found in /theme/yourtheme/classes/output/core_renderer.php) of your theme. Note: Your theme may even already have such a class (they often do): ```php use filter_manager; diff --git a/filter.php b/filter.php index a7b8a39..13004ad 100644 --- a/filter.php +++ b/filter.php @@ -1558,6 +1558,7 @@ public function filter($text, array $options = []) { if (!empty($grademax = floatval($gradeobj->item->grademax))) { // Avoid divide by 0 error if no grades have been defined. $grade = floatval($grademax) > 0 ? (int) ($gradeobj->grade / floatval($grademax) * 100) : 0; + } else { $grade = 0; } @@ -4742,28 +4743,6 @@ function ($matches) use ($mycohorts) { } } - // DO NOT USE THIS TAG. IT WILL BE REMOVED SOON. Use {ifprofile id is 999} instead. - // Tag: {ifuser id}...{/ifuser}. - // Description: Display content only for specified user id. - // Parameters: id number of user. - // Requires content between tags. - if (stripos($text, '{ifuser') !== false) { - $re = '/{ifuser\s+(.*)\}(.*)\{\/ifuser\}/isuU'; - $found = preg_match_all($re, $text, $matches); - if ($found > 0) { - foreach ($matches[1] as $user) { - $key = '/{ifuser\s+' . $user . '\}(.*)\{\/ifuser\}/isuU'; - if ($user == $USER->id) { - // Just remove the tags. - $replace[$key] = '$1'; - } else { - // Remove the ifuser strings. - $replace[$key] = ''; - } - } - } - } - // Tag: {iftheme themename}...{/iftheme}. // Description: Display content only if the current theme matches the one specified. // Parameters: The name of the directory in which the theme is located.