Skip to content

Commit

Permalink
Fixed handling of {ifprofile shortname ...} tags when logged out.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-milette committed Jul 22, 2024
1 parent fe74ded commit 67ee59d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,8 @@ Important: The specified value must be the value that is stored in the database,
* For dropdown fields, you may need to view the HTML code to see what the actual values are for a field.
* For checkboxes, the checked value is 1, unchecked is 0.

Reminder: When logged out (or in as guest), user profile fields do not exist. Therefore, "not" will always evaluate to true and "is", "contains" and "in" will evaluate to false.

### What are the supported dateTimeFormat formats?

The date and time formats, defined in Moodle (langconfig.php)[https://github.com/moodle/moodle/blob/master/lang/en/langconfig.php], control how dates and times will be displayed.
Expand Down
17 changes: 12 additions & 5 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3939,15 +3939,22 @@ function ($matches) use ($USER) {
if ($found > 0) {
foreach ($matches[1] as $key => $match) {
$fieldname = $matches[1][$key];
// Do not process tag if the specified profile field name does not exist.
if (!array_key_exists($fieldname, $profilefields)) {
continue;
}

$string = $matches[0][$key]; // String found in $text.
$operator = $matches[2][$key];
$value = $matches[3][$key];

// Do not process tag if the specified profile field name does not exist or user is not logged in.
if (!array_key_exists($fieldname, $profilefields) || !isloggedin() || isguestuser()) {
if ($operator == 'not') {
// It will always meet criteria of a "not" if the user doesn't have a profile.
$replace['/' . preg_quote($string, '/') . '/isuU'] = $matches[4][$key];
} else {
// It will never match the criteria "is", "contains" or "in" if the user doesn't have a profile.
$replace['/' . preg_quote($string, '/') . '/isuU'] = '';
}
continue;
}

if (!empty($value)) {
$value = trim($value, '"'); // Trim quotation marks.
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024072200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024072201; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014051200; // Requires Moodle version 2.7 or later.
$plugin->component = 'filter_filtercodes'; // Full name of the plugin (used for diagnostics).
$plugin->release = '2.5.2';
Expand Down

0 comments on commit 67ee59d

Please sign in to comment.