Skip to content

Commit

Permalink
New {menuthemes} tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-milette committed Nov 5, 2023
1 parent 8888462 commit fff6aa5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ All notable changes to this project will be documented in this file.

## [2.4.2] 2023-11-05 (dev)
### Added
- Fixed {preferredlanguage} tag if system default language is a child language pack.
- New {menuthemes} tag.
### Updated
- Fixed {preferredlanguage} tag if system default language is a child language pack.
- Refactored for performance improvement performance. Enable more tags for embedding.
- Instructions for enabling filters in custom menu.
- {courseshortname} tag can now be used inside other tags.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ Also, see Courses section below.
* {courserequestmenu0} : Request a course / Course request in a top level custom menu.
* {courserequestmenu} : Request a course / Course request in submenu.
* {menuadmin} : Useful dynamic menu for Moodle teachers, managers and administrators.
* {menudev} : Useful dynamic menu for Moodle developers.
* {menudev} : Useful dynamic menu for Moodle developers. Only visible when debugging is set to DEVELOPER mode.
* {menuthemes} : Theme switcher. Only for administrators. Not available after POST. Allow Theme Changes on URL must be enabled. Will be visible even when Administrator is using the **Log In As** feature to log in as a different user.

### URL

Expand Down Expand Up @@ -1086,6 +1087,7 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo
* 80% progresspie chart [{chart progresspie 80 --size:100px --border:15px --color:darkblue --bgcolor:lightblue --title:Are you over 70%?}]: {chart progresspie 80 --size:100px --border:15px --color:darkblue --bgcolor:lightblue --title:Are you over 70%?}
* Moodle Admin custom menu items [{menuadmin}]: <br><pre>{menuadmin}</pre>
* Moodle Dev custom menu items [{menudev}]: <br><pre>{menudev}</pre>
* Moodle Admin theme switcher [{menuthemes}]: <br><pre>{menuthemes}</pre>
* Course's category ID (0 if not in a course or category list of course) [{categoryid}]: {categoryid}
* Course's category name (blank if not in a course) [{categoryname}]: {categoryname}
* Course's category number (blank if not in a course) [{categorynumber}]: {categorynumber}
Expand Down
24 changes: 24 additions & 0 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,30 @@ private function generatortags(&$text) {
$replace['/\{menudev\}/i'] = $menu;
}

// Tag: {menuthemes}.
// Description: Theme switcher for custom menu. Only for administrators. Not available after POST. Allow Theme Changes on URL must be enabled.
// Parameters: None.
if (stripos($text, '{menuthemes}') !== false) {
$menu = '';
if (is_siteadmin() && empty($_POST)) { // If a site administrator.
if (get_config('core', 'allowthemechangeonurl')) {
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http")
. "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$url .= (strpos($url, '?') ? '&' : '?');
$themeslist = core_component::get_plugin_list('theme');
$menu = '';
foreach ($themeslist as $theme => $themedir) {
$themename = ucfirst(get_string('pluginname', 'theme_' . $theme));
$menu .= '-' . $themename . '|' . $url . 'theme=' . $theme . PHP_EOL;
}
if (!empty($menu)) {
$menu = 'Themes' . PHP_EOL . $menu;
}
}
}
$replace['/\{menuthemes\}/i'] = $menu;
}

// Check if any {course*} or %7Bcourse*%7D tags. Note: There is another course tags section further down.
$coursetagsexist = (stripos($text, '{course') !== false || stripos($text, '%7Bcourse') !== false);
if ($coursetagsexist) {
Expand Down

0 comments on commit fff6aa5

Please sign in to comment.