Skip to content

Commit

Permalink
Feature: Built-in contact, help and maintenance page, solves #150 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
abias authored Dec 19, 2022
1 parent f75c66d commit cf843e4
Show file tree
Hide file tree
Showing 17 changed files with 651 additions and 185 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2022-12-14 - Feature: Built-in contact, help and maintenance pages, solves #150.
* 2022-11-28 - Updated Moodle Plugin CI to latest upstream recommendations

### v4.0-r8
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ In this tab there are the following settings:

With these settings, you can add rich text content which will be shown on the imprint page.

##### Contact

With these settings, you can add rich text content which will be shown on a contact page (which is not the same as the built-in Moodle 'Contact site support' page).

##### Help

With these settings, you can add rich text content which will be shown on a help page.

##### Maintenance

With these settings, you can add rich text content which will be shown on a maintenance information page (which is not the same as the built-in Moodle maintenance page).

#### Tab "Information banners"

In this tab, you can enable and configure multiple information banners to be shown on selected pages.
Expand Down
59 changes: 58 additions & 1 deletion lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
$string['imprintheading'] = 'Imprint';
// ... ... Setting: Enable imprint.
$string['enableimprintsetting'] = 'Enable imprint';
$string['imprintdisabled'] = 'The imprint is disabled for this site. There is nothing to see here.';
$string['imprintdisabled'] = 'The imprint page is disabled for this site. There is nothing to see here.';
// ... ... Setting: Imprint content.
$string['imprintcontentsetting'] = 'Imprint content';
$string['imprintcontentsetting_desc'] = 'In this setting, you can add rich text content which will be shown on the imprint page.';
Expand All @@ -283,6 +283,63 @@
$string['imprintlinkpositionboth'] = 'Add a link to the imprint page to the footnote and to the footer (questionmark) icon';
$string['imprintlinkpositionsetting'] = 'Imprint link position';
$string['imprintlinkpositionsetting_desc'] = 'In this setting, you can configure if a link to the imprint page should be added automatically to the Moodle page. If you do not want to show a link automatically, you can add a link to {$a->url} from anywhere in Moodle manually.';
// ... Section: Contact page.
$string['contactheading'] = 'Contact';
// ... ... Setting: Enable contact page.
$string['enablecontactsetting'] = 'Enable contact page';
$string['contactdisabled'] = 'The contact page is disabled for this site. There is nothing to see here.';
// ... ... Setting: Contact page content.
$string['contactcontentsetting'] = 'Contact page content';
$string['contactcontentsetting_desc'] = 'In this setting, you can add rich text content which will be shown on a contact page (which is not the same as the built-in Moodle \'Contact site support\' page).';
// ... ... Setting: Contact page title.
$string['contactpagetitledefault'] = 'Contact';
$string['contactpagetitlesetting'] = 'Contact page title';
$string['contactpagetitlesetting_desc'] = 'In this setting, you can define the title of the contact page. This text will be used as link text to the contact page as well if you configure \'Contact page link position\' accordingly.';
// ... ... Setting: Contact page link position.
$string['contactlinkpositionnone'] = 'Do not automatically show a link to the contact page';
$string['contactlinkpositionfootnote'] = 'Add a link to the contact page to the footnote';
$string['contactlinkpositionfooter'] = 'Add a link to the contact page to the footer (questionmark) icon';
$string['contactlinkpositionboth'] = 'Add a link to the contact page to the footnote and to the footer (questionmark) icon';
$string['contactlinkpositionsetting'] = 'Contact page link position';
$string['contactlinkpositionsetting_desc'] = 'In this setting, you can configure if a link to the contact page should be added automatically to the Moodle page. If you do not want to show a link automatically, you can add a link to {$a->url} from anywhere in Moodle manually.';
// ... Section: Help page.
$string['helpheading'] = 'Help';
// ... ... Setting: Enable help page.
$string['enablehelpsetting'] = 'Enable help page';
$string['helpdisabled'] = 'The help page is disabled for this site. There is nothing to see here.';
// ... ... Setting: Help page content.
$string['helpcontentsetting'] = 'Help page content';
$string['helpcontentsetting_desc'] = 'In this setting, you can add rich text content which will be shown on a help page.';
// ... ... Setting: Help page title.
$string['helppagetitledefault'] = 'Help';
$string['helppagetitlesetting'] = 'Help page title';
$string['helppagetitlesetting_desc'] = 'In this setting, you can define the title of the help page. This text will be used as link text to the help page as well if you configure \'Help page link position\' accordingly.';
// ... ... Setting: Help page link position.
$string['helplinkpositionnone'] = 'Do not automatically show a link to the help page';
$string['helplinkpositionfootnote'] = 'Add a link to the help page to the footnote';
$string['helplinkpositionfooter'] = 'Add a link to the help page to the footer (questionmark) icon';
$string['helplinkpositionboth'] = 'Add a link to the help page to the footnote and to the footer (questionmark) icon';
$string['helplinkpositionsetting'] = 'Help page link position';
$string['helplinkpositionsetting_desc'] = 'In this setting, you can configure if a link to the help page should be added automatically to the Moodle page. If you do not want to show a link automatically, you can add a link to {$a->url} from anywhere in Moodle manually.';
// ... Section: Maintenance page.
$string['maintenanceheading'] = 'Maintenance';
// ... ... Setting: Enable maintenance page.
$string['enablemaintenancesetting'] = 'Enable maintenance information page';
$string['maintenancedisabled'] = 'The maintenance information page is disabled for this site. There is nothing to see here.';
// ... ... Setting: Maintenance page content.
$string['maintenancecontentsetting'] = 'Maintenance information page content';
$string['maintenancecontentsetting_desc'] = 'In this setting, you can add rich text content which will be shown on a maintenance information page (which is not the same as the built-in Moodle maintenance mode page).';
// ... ... Setting: Maintenance page title.
$string['maintenancepagetitledefault'] = 'Maintenance';
$string['maintenancepagetitlesetting'] = 'Maintenance information page title';
$string['maintenancepagetitlesetting_desc'] = 'In this setting, you can define the title of the maintenance information page. This text will be used as link text to the maintenance information page as well if you configure \'Maintenance information page link position\' accordingly.';
// ... ... Setting: Maintenance page link position.
$string['maintenancelinkpositionnone'] = 'Do not automatically show a link to the maintenance information page';
$string['maintenancelinkpositionfootnote'] = 'Add a link to the maintenance information page to the footnote';
$string['maintenancelinkpositionfooter'] = 'Add a link to the maintenance information page to the footer (questionmark) icon';
$string['maintenancelinkpositionboth'] = 'Add a link to the maintenance information page to the footnote and to the footer (questionmark) icon';
$string['maintenancelinkpositionsetting'] = 'Maintenance information page link position';
$string['maintenancelinkpositionsetting_desc'] = 'In this setting, you can configure if a link to the maintenance information page should be added automatically to the Moodle page. If you do not want to show a link automatically, you can add a link to {$a->url} from anywhere in Moodle manually.';
// Settings: Info banners tab.
$string['infobannertab'] = 'Info banner';
// ... Section: Info banners.
Expand Down
48 changes: 27 additions & 21 deletions layout/includes/staticpages.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,35 @@

$config = get_config('theme_boost_union');

// If the imprint is enabled.
if ($config->enableimprint == THEME_BOOST_UNION_SETTING_SELECT_YES) {
// If the admin wants to show a link in the footnote or in both locations.
if ($config->imprintlinkposition == THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_FOOTNOTE ||
$config->imprintlinkposition == THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_BOTH) {
// If the footnote is empty and not configured to be shown yet.
if (isset($templatecontext['showfootnote']) == false || $templatecontext['showfootnote'] == false) {
// Add marker to show the footnote to templatecontext.
$templatecontext['showfootnote'] = true;
// The static pages to be supported.
$staticpages = array('imprint', 'contact', 'help', 'maintenance');

// Iterate over the static pages.
foreach ($staticpages as $staticpage) {
// If the page is enabled.
if ($config->{'enable'.$staticpage} == THEME_BOOST_UNION_SETTING_SELECT_YES) {
// If the admin wants to show a link in the footnote or in both locations.
if ($config->{$staticpage.'linkposition'} == THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_FOOTNOTE ||
$config->{$staticpage.'linkposition'} == THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_BOTH) {
// If the footnote is empty and not configured to be shown yet.
if (isset($templatecontext['showfootnote']) == false || $templatecontext['showfootnote'] == false) {
// Add marker to show the footnote to templatecontext.
$templatecontext['showfootnote'] = true;
}

// Add marker to show the page link in the footnote to templatecontext.
$templatecontext[$staticpage.'linkpositionfootnote'] = true;
}

// Add marker to show the imprint link in the footnote to templatecontext.
$templatecontext['imprintlinkpositionfootnote'] = true;
}
// If the admin wants to show a link in the footer or in both locations.
if ($config->{$staticpage.'linkposition'} == THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_FOOTER ||
$config->{$staticpage.'linkposition'} == THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_BOTH) {
// Add marker to show the page link in the footer to templatecontext.
$templatecontext[$staticpage.'linkpositionfooter'] = true;
}

// If the admin wants to show a link in the footer or in both locations.
if ($config->imprintlinkposition == THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_FOOTER ||
$config->imprintlinkposition == THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_BOTH) {
// Add marker to show the imprint link in the footer to templatecontext.
$templatecontext['imprintlinkpositionfooter'] = true;
// Add the page link and page title to the templatecontext.
$templatecontext[$staticpage.'link'] = theme_boost_union_get_staticpage_link($staticpage);
$templatecontext[$staticpage.'pagetitle'] = theme_boost_union_get_staticpage_pagetitle($staticpage);
}

// Add the imprint link and page title to the templatecontext.
$templatecontext['imprintlink'] = theme_boost_union_get_imprint_link();
$templatecontext['imprintpagetitle'] = theme_boost_union_get_imprint_pagetitle();
}
8 changes: 4 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
define('THEME_BOOST_UNION_SETTING_SELECT_YES', 'yes');
define('THEME_BOOST_UNION_SETTING_SELECT_NO', 'no');

define('THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_NONE', 'none');
define('THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_FOOTNOTE', 'footnote');
define('THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_FOOTER', 'footer');
define('THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_BOTH', 'both');
define('THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_NONE', 'none');
define('THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_FOOTNOTE', 'footnote');
define('THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_FOOTER', 'footer');
define('THEME_BOOST_UNION_SETTING_STATICPAGELINKPOSITION_BOTH', 'both');

define('THEME_BOOST_UNION_SETTING_INFOBANNER_COUNT', 5);
define('THEME_BOOST_UNION_SETTING_INFOBANNERPAGES_MY', 'mydashboard');
Expand Down
20 changes: 11 additions & 9 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,38 @@ function theme_boost_union_get_course_related_hints() {
}

/**
* Build the link to the imprint page.
* Build the link to a static page.
*
* @param string $page The static page's identifier.
* @return string.
*/
function theme_boost_union_get_imprint_link() {
function theme_boost_union_get_staticpage_link($page) {
// Compose the URL object.
$url = new moodle_url('/theme/boost_union/pages/imprint.php');
$url = new moodle_url('/theme/boost_union/pages/'.$page.'.php');

// Return the string representation of the URL.
return $url->out();
}

/**
* Build the page title of the imprint page.
* Build the page title of a static page.
*
* @param string $page The static page's identifier.
* @return string.
*/
function theme_boost_union_get_imprint_pagetitle() {
function theme_boost_union_get_staticpage_pagetitle($page) {
// Get the configured page title.
$imprintpagetitleconfig = get_config('theme_boost_union', 'imprintpagetitle');
$pagetitleconfig = get_config('theme_boost_union', $page.'pagetitle');

// If there is a string configured.
if ($imprintpagetitleconfig) {
if ($pagetitleconfig) {
// Return this setting.
return $imprintpagetitleconfig;
return $pagetitleconfig;

// Otherwise.
} else {
// Return the default string.
return get_string('imprintpagetitledefault', 'theme_boost_union');
return get_string($page.'pagetitledefault', 'theme_boost_union');
}
}

Expand Down
75 changes: 75 additions & 0 deletions pages/contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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/>.

/**
* Theme Boost Union - Contact page.
*
* @package theme_boost_union
* @copyright 2022 Alexander Bias, lern.link GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// Include config.php.
// @codingStandardsIgnoreStart
// Let codechecker ignore the next line because otherwise it would complain about a missing login check
// after requiring config.php which is really not needed.
require(__DIR__ . '/../../../config.php');
// @codingStandardsIgnoreEnd

// Require the necessary libraries.
require_once($CFG->dirroot.'/theme/boost_union/lib.php');
require_once($CFG->dirroot.'/theme/boost_union/locallib.php');

// Set page URL.
$PAGE->set_url('/theme/boost_union/pages/contact.php');

// Set page layout.
$PAGE->set_pagelayout('standard');

// Set page context.
$PAGE->set_context(context_system::instance());

// Add page name as body class.
$PAGE->add_body_class('theme_boost_union-contact');

// Get theme config.
$config = get_config('theme_boost_union');

// If the contact page is disabled, we just show a short friendly warning page and are done.
if ($config->enablecontact != THEME_BOOST_UNION_SETTING_SELECT_YES) {
echo $OUTPUT->header();
$notification = new \core\output\notification(get_string('contactdisabled', 'theme_boost_union'),
\core\output\notification::NOTIFY_INFO);
$notification->set_show_closebutton(false);
echo $OUTPUT->render($notification);
echo $OUTPUT->footer();
die;
}

// Set page title.
$PAGE->set_title(theme_boost_union_get_staticpage_pagetitle('contact'));

// Start page output.
echo $OUTPUT->header();

// Show page heading.
echo $OUTPUT->heading(theme_boost_union_get_staticpage_pagetitle('contact'));

// Output contact page content.
echo format_text($config->contactcontent);

// Finish page.
echo $OUTPUT->footer();
75 changes: 75 additions & 0 deletions pages/help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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/>.

/**
* Theme Boost Union - Help page.
*
* @package theme_boost_union
* @copyright 2022 Alexander Bias, lern.link GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// Include config.php.
// @codingStandardsIgnoreStart
// Let codechecker ignore the next line because otherwise it would complain about a missing login check
// after requiring config.php which is really not needed.
require(__DIR__ . '/../../../config.php');
// @codingStandardsIgnoreEnd

// Require the necessary libraries.
require_once($CFG->dirroot.'/theme/boost_union/lib.php');
require_once($CFG->dirroot.'/theme/boost_union/locallib.php');

// Set page URL.
$PAGE->set_url('/theme/boost_union/pages/help.php');

// Set page layout.
$PAGE->set_pagelayout('standard');

// Set page context.
$PAGE->set_context(context_system::instance());

// Add page name as body class.
$PAGE->add_body_class('theme_boost_union-help');

// Get theme config.
$config = get_config('theme_boost_union');

// If the help page is disabled, we just show a short friendly warning page and are done.
if ($config->enablehelp != THEME_BOOST_UNION_SETTING_SELECT_YES) {
echo $OUTPUT->header();
$notification = new \core\output\notification(get_string('helpdisabled', 'theme_boost_union'),
\core\output\notification::NOTIFY_INFO);
$notification->set_show_closebutton(false);
echo $OUTPUT->render($notification);
echo $OUTPUT->footer();
die;
}

// Set page title.
$PAGE->set_title(theme_boost_union_get_staticpage_pagetitle('help'));

// Start page output.
echo $OUTPUT->header();

// Show page heading.
echo $OUTPUT->heading(theme_boost_union_get_staticpage_pagetitle('help'));

// Output help page content.
echo format_text($config->helpcontent);

// Finish page.
echo $OUTPUT->footer();
4 changes: 2 additions & 2 deletions pages/imprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
}

// Set page title.
$PAGE->set_title(theme_boost_union_get_imprint_pagetitle());
$PAGE->set_title(theme_boost_union_get_staticpage_pagetitle('imprint'));

// Start page output.
echo $OUTPUT->header();

// Show page heading.
echo $OUTPUT->heading(theme_boost_union_get_imprint_pagetitle());
echo $OUTPUT->heading(theme_boost_union_get_staticpage_pagetitle('imprint'));

// Output imprint content.
echo format_text($config->imprintcontent);
Expand Down
Loading

0 comments on commit cf843e4

Please sign in to comment.