Skip to content

Commit

Permalink
Merge pull request #197 from trema-tech/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rmady authored Jul 16, 2024
2 parents 5ebfbb2 + 279413f commit b8ed368
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 95 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
matrix:
include:
# Next version of Moodle (main).
# Moodle 4.5.x (MOODLE_405_STABLE).
# - php: '8.3'
# moodle-branch: 'main'
# database: 'pgsql'
Expand All @@ -57,6 +58,9 @@ jobs:
# database: 'mariadb'
# - php: '8.2'
# moodle-branch: 'main'
# database: 'mariadb'
# - php: '8.1'
# moodle-branch: 'main'
# database: 'mariadb'
# Moodle 4.4.x (MOODLE_404_STABLE).
- php: '8.3'
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Keep in mind that the maintainers get final say on whether new features will be

Style Guides
-------------------
1. Write in UTF-8 in PHP 7.4, 8.0, 8.1 and 8.2
1. Write in UTF-8 in PHP 7.4, 8.0, 8.1, 8.2 and 8.3.
2. Follow the official[Moodle Coding Style Guide](https://moodledev.io/general/development/policies/codingstyle).
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.
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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Trema Theme for Moodle LMS
==========================

![PHP](https://img.shields.io/badge/PHP-v7.4%20to%20v8.2-blue.svg)
![PHP](https://img.shields.io/badge/PHP-v7.4%20to%20v8.3-blue.svg)
![Moodle](https://img.shields.io/badge/Moodle-v4.0%20to%20v4.4-orange.svg)
[![GitHub Issues](https://img.shields.io/github/issues/trema-tech/moodle-theme_trema.svg)](https://github.com/trema-tech/moodle-theme_trema/issues)
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-green.svg)](#contributing)
Expand Down
142 changes: 85 additions & 57 deletions classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class core_renderer extends \theme_boost\output\core_renderer {
*/
public function favicon() {
global $CFG;
static $favicon;

if (!empty($favicon)) {
return $favicon;
}

// Use favicon configured in theme's settings.
$favicon = $this->page->theme->setting_file_url('favicon', 'favicon');
Expand All @@ -85,8 +90,13 @@ public function favicon() {
* @return bool
*/
public function should_display_navbar_logo() {
$logo = $this->get_compact_logo_url();
return !empty($logo);
static $logo;

if (!isset($logo)) {
$logo = $this->get_compact_logo_url();
$logo = !empty($logo);
}
return $logo;
}

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

/**
* Renders the lang menu on the login page.
*
* @return mixed
*/
public function login_lang_menu() {
return $this->render_lang_menu(true);
}

/**
* Renders the lang menu
*
Expand Down Expand Up @@ -158,52 +159,6 @@ public function render_lang_menu($showlang = false) {
return '';
}

/**
* Add icons to custom menu.
*
* @param custom_menu $menu
* @return string
* @throws \coding_exception
* @throws \dml_exception
* @throws \moodle_exception
*/
protected function render_custom_menu(custom_menu $menu) {
// Change Fontawesome's codes by HTML.
$content = '';
foreach ($menu->get_children() as $item) {
$context = $item->export_for_template($this);
$context->text = preg_replace('/^fa-(\w|-)+/', '<i class="fa \0 mr-1" aria-hidden="true"></i>', $context->text);
$context->title = trim(preg_replace('/^fa-(\w|-)+/', '', $context->title));
$content .= $this->render_from_template('core/custom_menu_item', $context);
}

return $content;
}

/**
* We want to show the custom menus as a list of links in the footer on small screens.
* Just return the menu object exported so we can render it differently.
*
* @return array
*/
public function custom_menu_flat() {
global $CFG;

// Render standard custom_menu_flat without the language menu.
$oldlangmenu = $CFG->langmenu;
$CFG->langmenu = '';
$context = parent::custom_menu_flat();
$CFG->langmenu = $oldlangmenu;

// Replace FontAwesome codes with HTML.
foreach ($context->children as &$item) {
$item->text = preg_replace('/^fa-(\w|-)+/', '<i class="fa \0 mr-1" aria-hidden="true"></i>', $item->text);
$item->title = trim(preg_replace('/^fa-(\w|-)+/', '', $item->title));
}

return $context;
}

/**
* Renders the login form.
*
Expand Down Expand Up @@ -236,4 +191,77 @@ public function render_login(\core_auth\output\login $form) {

return $this->render_from_template('core/loginform', $context);
}

/**
* Generates the standard HTML for the head section of the page.
*
* This method temporarily modifies the global `$CFG->additionalhtmlhead` to apply formatting
* options before calling the parent method to generate the standard HTML head. It ensures that
* any additional HTML specified in the site configuration is processed through Moodle filters
* and included in the head section of the page. After the parent method is called, it restores
* the original `$CFG->additionalhtmlhead` value.
*
* @return string The HTML content for the head section of the page.
*/
public function standard_head_html() {
global $CFG;
$additionalhtmlhead = $CFG->additionalhtmlhead;
if (strpos($additionalhtmlhead, '}') !== false) {
$CFG->additionalhtmlhead = format_text($CFG->additionalhtmlhead,
FORMAT_HTML, ['noclean' => true, 'context' => $this->page->context]);
}
$output = parent::standard_head_html();
$CFG->additionalhtmlhead = $additionalhtmlhead;
return $output;
}

/**
* Adds additional HTML at the top of the body for every page.
*
* This method temporarily modifies the global `$CFG->additionalhtmltopofbody` to apply formatting
* options before calling the parent method to generate the top of the HTML body. It ensures that
* any additional HTML specified in the site configuration is processed through Moodle filters
* and included in the beginning of the body of the page. After the parent method is called, it
* restores the original `$CFG->additionalhtmltopofbody` value.
*
* Credit: GCWeb theme by TNG Consulting Inc.
*
* @return string Additional HTML to be placed at the top of the body.
*/
public function standard_top_of_body_html() {
global $CFG;
$additionalhtmltopofbody = $CFG->additionalhtmltopofbody;
if (strpos($additionalhtmltopofbody, '}') !== false) {
$CFG->additionalhtmltopofbody = format_text($CFG->additionalhtmltopofbody,
FORMAT_HTML, ['noclean' => true, $this->page->context]);
}
$output = parent::standard_top_of_body_html();
$CFG->additionalhtmltopofbody = $additionalhtmltopofbody;
return $output;
}

/**
* Adds additional HTML at the end of the body for every page.
*
* Credit: GCWeb theme by TNG Consulting Inc.
*
* This method temporarily modifies the global `$CFG->additionalhtmlfooter` to apply formatting
* options before calling the parent method to generate the content at the bottom of the HTML body.
* It ensures that any additional HTML specified in the site configuration is processed through
* Moodle filters and included in the footer section of the page. After the parent method is called,
* it restores the original `$CFG->additionalhtmlfooter` value.
*
* @return string Additional HTML to be placed at the end of the body.
*/
public function standard_end_of_body_html() {
global $CFG;
$additionalhtmlfooter = $CFG->additionalhtmlfooter;
if (strpos($additionalhtmlfooter, '}') !== false) {
$CFG->additionalhtmlfooter = format_text($CFG->additionalhtmlfooter,
FORMAT_HTML, ['noclean' => true, 'context' => $this->page->context]);
}
$output = parent::standard_end_of_body_html();
$CFG->additionalhtmlfooter = $additionalhtmlfooter;
return $output;
}
}
76 changes: 76 additions & 0 deletions classes/output/primary_navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Core navigation.
*
* @package theme_trema
* @category navigation
* @copyright 2022-2024 TNG Consulting Inc. - {@link https://www.tngconsulting.ca/}
* @author Michael Milette
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace theme_trema\output;

use filter_manager;
use renderer_base;
use custom_menu;

/**
* Custom primary navigation class for the Trema theme.
*
* This class extends the core primary navigation class and adds functionality
* for handling custom menu items. Custom menu items reside on the same level
* as the original nodes.
*/
class primary_navigation extends \core\navigation\output\primary {
/**
* Custom menu items reside on the same level as the original nodes.
* Fetch and convert the nodes to a standardised array.
*
* @param renderer_base $output The renderer base instance.
* @return array An array of custom menu items. If no custom menu items exist, an empty array is returned.
*/
protected function get_custom_menu(renderer_base $output): array {
global $CFG;

// Early return if a custom menu does not exists.
if (empty($CFG->custommenuitems)) {
return [];
}

$custommenuitems = $CFG->custommenuitems;

// If setting is enabled, filter custom menu items but don't apply auto-linking filters.
if (!empty(get_config('theme_trema', 'navfilter'))) {
// Include default filters to skip.
$skipfilters = 'activitynames,data,glossary,sectionnames,bookchapters,urltolink,'
. get_config('theme_trema', 'navfiltersexcluded');
// Convert to array, trim all items, and remove duplicates and empty values.
$skipfilters = array_filter(array_unique(array_map('trim', explode(',', $skipfilters))));
$filteroptions = ['originalformat' => FORMAT_HTML, 'noclean' => true];
$filtermanager = filter_manager::instance();
$context = \context_system::instance();
$CFG->custommenuitems = $filtermanager->filter_text($CFG->custommenuitems, $context, $filteroptions, $skipfilters);
}
$nodes = parent::get_custom_menu($output);

$CFG->custommenuitems = $custommenuitems;

return $nodes;
}
}
3 changes: 1 addition & 2 deletions lang/de/theme_trema.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@
$string['configtitle'] = 'Trema';
$string['coursescards'] = 'Kurs-Karten';
$string['defaultfooter_default'] = 'Startseiten-Fußbereich';
$string['defaultfooter_defaultdesc'] = 'Standartinhalt für Startseiten-Fußbereich';
$string['defaultfooter_desc'] = 'Standartinhalt für Fußbereich';
$string['defaultfooter'] = 'Fußbereich';
$string['defaultfooter_desc'] = 'Standartinhalt für Fußbereich';
$string['defaultfrontpagebody'] = 'Body Startseite';
$string['defaultfrontpagebody_desc'] = 'Standartinhalt für Body der Startseite';
$string['diskusage'] = 'Moodledata Festplattennutzung';
Expand Down
7 changes: 6 additions & 1 deletion lang/en/theme_trema.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@
$string['imagelink_desc'] = 'Button with a link in image {$a}.';
$string['light'] = 'Light';
$string['link'] = 'Link';
$string['link'] = 'Link';
$string['linkdecoration'] = 'Link style';
$string['linkdecoration_desc'] = 'Links can either be underlined or in bold.';
$string['login'] = 'Login';
$string['loginbackgroundimage'] = 'Login background image';
$string['loginboxcontentalign'] = 'Login box alignment.';
$string['loginboxcontentalign_desc'] = 'Alignment of the text and button that appear in the Login Page.';
$string['loginbtnbgcolor'] = 'Log In button background color';
$string['loginbtnbgcolor_desc'] = 'The background colour of the Log In button in the header.';
$string['loginpagecreatefirst'] = 'Display \'Create account\' box first';
Expand All @@ -179,6 +180,10 @@
$string['loginshowloginform'] = 'Show login form';
$string['loginshowloginform_desc'] = 'Before disabling the login form, ensure that administrators have an alternate method to Sign in to the site.';
$string['modal'] = 'Modal';
$string['navfilter'] = 'Filter navigation';
$string['navfilter_desc'] = 'Enable to process primary navigation through Moodle filters. Useful for dynamic custom menu items.';
$string['navfiltersexcluded'] = 'Excluded navigation filters';
$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.';
$string['numberofcards'] = 'Number of cards';
$string['numberofimages'] = "Number of images in frontpage banner";
$string['numberofimages_desc'] = "Number of images to show in frontpage banner. If it is more than one, loads the carousel.";
Expand Down
2 changes: 1 addition & 1 deletion layout/columns2.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
}

$primary = new core\navigation\output\primary($PAGE);
$primary = new theme_trema\output\primary_navigation($PAGE);
$renderer = $PAGE->get_renderer('core');
$primarymenu = $primary->export_for_template($renderer);
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
Expand Down
2 changes: 1 addition & 1 deletion layout/drawers.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
}
}

$primary = new core\navigation\output\primary($PAGE);
$primary = new theme_trema\output\primary_navigation($PAGE);
$renderer = $PAGE->get_renderer('core');
$primarymenu = $primary->export_for_template($renderer);
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
Expand Down
2 changes: 1 addition & 1 deletion layout/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}
}

$primary = new core\navigation\output\primary($PAGE);
$primary = new theme_trema\output\primary_navigation($PAGE);
$renderer = $PAGE->get_renderer('core');
$primarymenu = $primary->export_for_template($renderer);
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
Expand Down
2 changes: 1 addition & 1 deletion layout/mydashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}
}

$primary = new core\navigation\output\primary($PAGE);
$primary = new theme_trema\output\primary_navigation($PAGE);
$renderer = $PAGE->get_renderer('core');
$primarymenu = $primary->export_for_template($renderer);
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
Expand Down
1 change: 1 addition & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function theme_trema_get_pre_scss($theme) {
'banner-title-transform' => 'bannertitletransform',
'banner-title-spacing' => 'bannertitlespacing',
'banner-text-align' => 'frontpagebannercontentalign',
'login-box-align' => 'loginboxcontentalign',
'banner-height' => 'bannerheight',
'custom-menu-alignment' => 'custommenualignment',
'links-decoration' => 'linkdecoration',
Expand Down
Loading

0 comments on commit b8ed368

Please sign in to comment.