Skip to content

Commit b8ed368

Browse files
authored
Merge pull request #197 from trema-tech/dev
Dev
2 parents 5ebfbb2 + 279413f commit b8ed368

20 files changed

+269
-95
lines changed

.github/workflows/moodle-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
matrix:
5050
include:
5151
# Next version of Moodle (main).
52+
# Moodle 4.5.x (MOODLE_405_STABLE).
5253
# - php: '8.3'
5354
# moodle-branch: 'main'
5455
# database: 'pgsql'
@@ -57,6 +58,9 @@ jobs:
5758
# database: 'mariadb'
5859
# - php: '8.2'
5960
# moodle-branch: 'main'
61+
# database: 'mariadb'
62+
# - php: '8.1'
63+
# moodle-branch: 'main'
6064
# database: 'mariadb'
6165
# Moodle 4.4.x (MOODLE_404_STABLE).
6266
- php: '8.3'

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Keep in mind that the maintainers get final say on whether new features will be
1515

1616
Style Guides
1717
-------------------
18-
1. Write in UTF-8 in PHP 7.4, 8.0, 8.1 and 8.2
18+
1. Write in UTF-8 in PHP 7.4, 8.0, 8.1, 8.2 and 8.3.
1919
2. Follow the official[Moodle Coding Style Guide](https://moodledev.io/general/development/policies/codingstyle).
2020
3. Fully test your code with Moodle **Debug Messages** setting set to **DEVELOPER: extra Moodle debug messages for developers** and **Display debug messages** setting checked. Ensure that there are no errors or warnings at all.
2121
4. Test your code using the [Moodle Code Checker](https://moodle.org/plugins/local_codechecker) and [Moodle PHPdoc check](https://moodle.org/plugins/local_moodlecheck) plugins. Ensure that there are no errors or warnings at all.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Trema Theme for Moodle LMS
44
==========================
55

6-
![PHP](https://img.shields.io/badge/PHP-v7.4%20to%20v8.2-blue.svg)
6+
![PHP](https://img.shields.io/badge/PHP-v7.4%20to%20v8.3-blue.svg)
77
![Moodle](https://img.shields.io/badge/Moodle-v4.0%20to%20v4.4-orange.svg)
88
[![GitHub Issues](https://img.shields.io/github/issues/trema-tech/moodle-theme_trema.svg)](https://github.com/trema-tech/moodle-theme_trema/issues)
99
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-green.svg)](#contributing)

classes/output/core_renderer.php

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class core_renderer extends \theme_boost\output\core_renderer {
6161
*/
6262
public function favicon() {
6363
global $CFG;
64+
static $favicon;
65+
66+
if (!empty($favicon)) {
67+
return $favicon;
68+
}
6469

6570
// Use favicon configured in theme's settings.
6671
$favicon = $this->page->theme->setting_file_url('favicon', 'favicon');
@@ -85,8 +90,13 @@ public function favicon() {
8590
* @return bool
8691
*/
8792
public function should_display_navbar_logo() {
88-
$logo = $this->get_compact_logo_url();
89-
return !empty($logo);
93+
static $logo;
94+
95+
if (!isset($logo)) {
96+
$logo = $this->get_compact_logo_url();
97+
$logo = !empty($logo);
98+
}
99+
return $logo;
90100
}
91101

92102
/**
@@ -100,15 +110,6 @@ public function frontpage_settings_menu() {
100110
return $this->render_from_template('theme_trema/frontpage_settings_menu', $header);
101111
}
102112

103-
/**
104-
* Renders the lang menu on the login page.
105-
*
106-
* @return mixed
107-
*/
108-
public function login_lang_menu() {
109-
return $this->render_lang_menu(true);
110-
}
111-
112113
/**
113114
* Renders the lang menu
114115
*
@@ -158,52 +159,6 @@ public function render_lang_menu($showlang = false) {
158159
return '';
159160
}
160161

161-
/**
162-
* Add icons to custom menu.
163-
*
164-
* @param custom_menu $menu
165-
* @return string
166-
* @throws \coding_exception
167-
* @throws \dml_exception
168-
* @throws \moodle_exception
169-
*/
170-
protected function render_custom_menu(custom_menu $menu) {
171-
// Change Fontawesome's codes by HTML.
172-
$content = '';
173-
foreach ($menu->get_children() as $item) {
174-
$context = $item->export_for_template($this);
175-
$context->text = preg_replace('/^fa-(\w|-)+/', '<i class="fa \0 mr-1" aria-hidden="true"></i>', $context->text);
176-
$context->title = trim(preg_replace('/^fa-(\w|-)+/', '', $context->title));
177-
$content .= $this->render_from_template('core/custom_menu_item', $context);
178-
}
179-
180-
return $content;
181-
}
182-
183-
/**
184-
* We want to show the custom menus as a list of links in the footer on small screens.
185-
* Just return the menu object exported so we can render it differently.
186-
*
187-
* @return array
188-
*/
189-
public function custom_menu_flat() {
190-
global $CFG;
191-
192-
// Render standard custom_menu_flat without the language menu.
193-
$oldlangmenu = $CFG->langmenu;
194-
$CFG->langmenu = '';
195-
$context = parent::custom_menu_flat();
196-
$CFG->langmenu = $oldlangmenu;
197-
198-
// Replace FontAwesome codes with HTML.
199-
foreach ($context->children as &$item) {
200-
$item->text = preg_replace('/^fa-(\w|-)+/', '<i class="fa \0 mr-1" aria-hidden="true"></i>', $item->text);
201-
$item->title = trim(preg_replace('/^fa-(\w|-)+/', '', $item->title));
202-
}
203-
204-
return $context;
205-
}
206-
207162
/**
208163
* Renders the login form.
209164
*
@@ -236,4 +191,77 @@ public function render_login(\core_auth\output\login $form) {
236191

237192
return $this->render_from_template('core/loginform', $context);
238193
}
194+
195+
/**
196+
* Generates the standard HTML for the head section of the page.
197+
*
198+
* This method temporarily modifies the global `$CFG->additionalhtmlhead` to apply formatting
199+
* options before calling the parent method to generate the standard HTML head. It ensures that
200+
* any additional HTML specified in the site configuration is processed through Moodle filters
201+
* and included in the head section of the page. After the parent method is called, it restores
202+
* the original `$CFG->additionalhtmlhead` value.
203+
*
204+
* @return string The HTML content for the head section of the page.
205+
*/
206+
public function standard_head_html() {
207+
global $CFG;
208+
$additionalhtmlhead = $CFG->additionalhtmlhead;
209+
if (strpos($additionalhtmlhead, '}') !== false) {
210+
$CFG->additionalhtmlhead = format_text($CFG->additionalhtmlhead,
211+
FORMAT_HTML, ['noclean' => true, 'context' => $this->page->context]);
212+
}
213+
$output = parent::standard_head_html();
214+
$CFG->additionalhtmlhead = $additionalhtmlhead;
215+
return $output;
216+
}
217+
218+
/**
219+
* Adds additional HTML at the top of the body for every page.
220+
*
221+
* This method temporarily modifies the global `$CFG->additionalhtmltopofbody` to apply formatting
222+
* options before calling the parent method to generate the top of the HTML body. It ensures that
223+
* any additional HTML specified in the site configuration is processed through Moodle filters
224+
* and included in the beginning of the body of the page. After the parent method is called, it
225+
* restores the original `$CFG->additionalhtmltopofbody` value.
226+
*
227+
* Credit: GCWeb theme by TNG Consulting Inc.
228+
*
229+
* @return string Additional HTML to be placed at the top of the body.
230+
*/
231+
public function standard_top_of_body_html() {
232+
global $CFG;
233+
$additionalhtmltopofbody = $CFG->additionalhtmltopofbody;
234+
if (strpos($additionalhtmltopofbody, '}') !== false) {
235+
$CFG->additionalhtmltopofbody = format_text($CFG->additionalhtmltopofbody,
236+
FORMAT_HTML, ['noclean' => true, $this->page->context]);
237+
}
238+
$output = parent::standard_top_of_body_html();
239+
$CFG->additionalhtmltopofbody = $additionalhtmltopofbody;
240+
return $output;
241+
}
242+
243+
/**
244+
* Adds additional HTML at the end of the body for every page.
245+
*
246+
* Credit: GCWeb theme by TNG Consulting Inc.
247+
*
248+
* This method temporarily modifies the global `$CFG->additionalhtmlfooter` to apply formatting
249+
* options before calling the parent method to generate the content at the bottom of the HTML body.
250+
* It ensures that any additional HTML specified in the site configuration is processed through
251+
* Moodle filters and included in the footer section of the page. After the parent method is called,
252+
* it restores the original `$CFG->additionalhtmlfooter` value.
253+
*
254+
* @return string Additional HTML to be placed at the end of the body.
255+
*/
256+
public function standard_end_of_body_html() {
257+
global $CFG;
258+
$additionalhtmlfooter = $CFG->additionalhtmlfooter;
259+
if (strpos($additionalhtmlfooter, '}') !== false) {
260+
$CFG->additionalhtmlfooter = format_text($CFG->additionalhtmlfooter,
261+
FORMAT_HTML, ['noclean' => true, 'context' => $this->page->context]);
262+
}
263+
$output = parent::standard_end_of_body_html();
264+
$CFG->additionalhtmlfooter = $additionalhtmlfooter;
265+
return $output;
266+
}
239267
}

classes/output/primary_navigation.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Core navigation.
19+
*
20+
* @package theme_trema
21+
* @category navigation
22+
* @copyright 2022-2024 TNG Consulting Inc. - {@link https://www.tngconsulting.ca/}
23+
* @author Michael Milette
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
27+
namespace theme_trema\output;
28+
29+
use filter_manager;
30+
use renderer_base;
31+
use custom_menu;
32+
33+
/**
34+
* Custom primary navigation class for the Trema theme.
35+
*
36+
* This class extends the core primary navigation class and adds functionality
37+
* for handling custom menu items. Custom menu items reside on the same level
38+
* as the original nodes.
39+
*/
40+
class primary_navigation extends \core\navigation\output\primary {
41+
/**
42+
* Custom menu items reside on the same level as the original nodes.
43+
* Fetch and convert the nodes to a standardised array.
44+
*
45+
* @param renderer_base $output The renderer base instance.
46+
* @return array An array of custom menu items. If no custom menu items exist, an empty array is returned.
47+
*/
48+
protected function get_custom_menu(renderer_base $output): array {
49+
global $CFG;
50+
51+
// Early return if a custom menu does not exists.
52+
if (empty($CFG->custommenuitems)) {
53+
return [];
54+
}
55+
56+
$custommenuitems = $CFG->custommenuitems;
57+
58+
// If setting is enabled, filter custom menu items but don't apply auto-linking filters.
59+
if (!empty(get_config('theme_trema', 'navfilter'))) {
60+
// Include default filters to skip.
61+
$skipfilters = 'activitynames,data,glossary,sectionnames,bookchapters,urltolink,'
62+
. get_config('theme_trema', 'navfiltersexcluded');
63+
// Convert to array, trim all items, and remove duplicates and empty values.
64+
$skipfilters = array_filter(array_unique(array_map('trim', explode(',', $skipfilters))));
65+
$filteroptions = ['originalformat' => FORMAT_HTML, 'noclean' => true];
66+
$filtermanager = filter_manager::instance();
67+
$context = \context_system::instance();
68+
$CFG->custommenuitems = $filtermanager->filter_text($CFG->custommenuitems, $context, $filteroptions, $skipfilters);
69+
}
70+
$nodes = parent::get_custom_menu($output);
71+
72+
$CFG->custommenuitems = $custommenuitems;
73+
74+
return $nodes;
75+
}
76+
}

lang/de/theme_trema.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
$string['configtitle'] = 'Trema';
4545
$string['coursescards'] = 'Kurs-Karten';
4646
$string['defaultfooter_default'] = 'Startseiten-Fußbereich';
47-
$string['defaultfooter_defaultdesc'] = 'Standartinhalt für Startseiten-Fußbereich';
48-
$string['defaultfooter_desc'] = 'Standartinhalt für Fußbereich';
4947
$string['defaultfooter'] = 'Fußbereich';
48+
$string['defaultfooter_desc'] = 'Standartinhalt für Fußbereich';
5049
$string['defaultfrontpagebody'] = 'Body Startseite';
5150
$string['defaultfrontpagebody_desc'] = 'Standartinhalt für Body der Startseite';
5251
$string['diskusage'] = 'Moodledata Festplattennutzung';

lang/en/theme_trema.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@
166166
$string['imagelink_desc'] = 'Button with a link in image {$a}.';
167167
$string['light'] = 'Light';
168168
$string['link'] = 'Link';
169-
$string['link'] = 'Link';
170169
$string['linkdecoration'] = 'Link style';
171170
$string['linkdecoration_desc'] = 'Links can either be underlined or in bold.';
172171
$string['login'] = 'Login';
173172
$string['loginbackgroundimage'] = 'Login background image';
173+
$string['loginboxcontentalign'] = 'Login box alignment.';
174+
$string['loginboxcontentalign_desc'] = 'Alignment of the text and button that appear in the Login Page.';
174175
$string['loginbtnbgcolor'] = 'Log In button background color';
175176
$string['loginbtnbgcolor_desc'] = 'The background colour of the Log In button in the header.';
176177
$string['loginpagecreatefirst'] = 'Display \'Create account\' box first';
@@ -179,6 +180,10 @@
179180
$string['loginshowloginform'] = 'Show login form';
180181
$string['loginshowloginform_desc'] = 'Before disabling the login form, ensure that administrators have an alternate method to Sign in to the site.';
181182
$string['modal'] = 'Modal';
183+
$string['navfilter'] = 'Filter navigation';
184+
$string['navfilter_desc'] = 'Enable to process primary navigation through Moodle filters. Useful for dynamic custom menu items.';
185+
$string['navfiltersexcluded'] = 'Excluded navigation filters';
186+
$string['navfiltersexcluded_desc'] = 'These filters will not be applied to the primary navigation (custom menu). Must be a comma separated list of filter names. By default, the following auto-linking filters are always excluded: activitynames, data, glossary, sectionnames, bookchapters, urltolink.';
182187
$string['numberofcards'] = 'Number of cards';
183188
$string['numberofimages'] = "Number of images in frontpage banner";
184189
$string['numberofimages_desc'] = "Number of images to show in frontpage banner. If it is more than one, loads the carousel.";

layout/columns2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
}
5454
}
5555

56-
$primary = new core\navigation\output\primary($PAGE);
56+
$primary = new theme_trema\output\primary_navigation($PAGE);
5757
$renderer = $PAGE->get_renderer('core');
5858
$primarymenu = $primary->export_for_template($renderer);
5959
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();

layout/drawers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
}
8787
}
8888

89-
$primary = new core\navigation\output\primary($PAGE);
89+
$primary = new theme_trema\output\primary_navigation($PAGE);
9090
$renderer = $PAGE->get_renderer('core');
9191
$primarymenu = $primary->export_for_template($renderer);
9292
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();

layout/frontpage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
}
4949
}
5050

51-
$primary = new core\navigation\output\primary($PAGE);
51+
$primary = new theme_trema\output\primary_navigation($PAGE);
5252
$renderer = $PAGE->get_renderer('core');
5353
$primarymenu = $primary->export_for_template($renderer);
5454
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();

layout/mydashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}
5555
}
5656

57-
$primary = new core\navigation\output\primary($PAGE);
57+
$primary = new theme_trema\output\primary_navigation($PAGE);
5858
$renderer = $PAGE->get_renderer('core');
5959
$primarymenu = $primary->export_for_template($renderer);
6060
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();

lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function theme_trema_get_pre_scss($theme) {
5353
'banner-title-transform' => 'bannertitletransform',
5454
'banner-title-spacing' => 'bannertitlespacing',
5555
'banner-text-align' => 'frontpagebannercontentalign',
56+
'login-box-align' => 'loginboxcontentalign',
5657
'banner-height' => 'bannerheight',
5758
'custom-menu-alignment' => 'custommenualignment',
5859
'links-decoration' => 'linkdecoration',

0 commit comments

Comments
 (0)