Skip to content

Commit

Permalink
Merge pull request #43 from moodle-an-hochschulen/issue-32
Browse files Browse the repository at this point in the history
Feature: Built-in imprint, solves #32
  • Loading branch information
lucaboesch authored Jul 8, 2022
2 parents 56566b5 + 8f064b7 commit 5b22ec8
Show file tree
Hide file tree
Showing 21 changed files with 645 additions and 8 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-07-06 - Feature: Built-in imprint, solves #32
* 2022-07-05 - Feature: Configurable favicon, solves #34
* 2022-07-05 - Feature: Allow non-admins to edit theme settings, solves #28
* 2022-07-05 - Feature: Back to top button, solves #7
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ In this tab there are the following settings:

Whatever you add to this textarea will be displayed at the end of a page, in the footer. Refer to the setting description on the settings page for further instructions.

### Tab "Static pages"

In this tab there are the following settings:

#### Imprint

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


Capabilities
------------
Expand Down
21 changes: 21 additions & 0 deletions lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@
$string['footnotesetting'] = 'Footnote';
$string['footnotesetting_desc'] = 'Whatever you add to this textarea will be displayed at the end of a page, in the footer (not the floating footer) on every page which uses the layouts "drawers", "columns2" or "login". Content in this area could be for example the copyright, the terms of use or the name of your organisation. <br/> If you want to remove the footnote again, just empty the text area.';

// Settings: Static pages tab.
$string['staticpagestab'] = 'Static pages';
$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.';
// ... 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.';
// ... Setting: Imprint page title:
$string['imprintpagetitledefault'] = 'Imprint';
$string['imprintpagetitlesetting'] = 'Imprint page title';
$string['imprintpagetitlesetting_desc'] = 'In this setting, you can define the title of the imprint page. This text will be used as link text to the imprint page as well if you configure \'Imprint link position\' accordingly.';
// ... Setting: Imprint link position:
$string['imprintlinkpositionnone'] = 'Do not automatically show a link to the imprint page';
$string['imprintlinkpositionfootnote'] = 'Add a link to the imprint page to the footnote';
$string['imprintlinkpositionfooter'] = 'Add a link to the imprint page to the footer (questionmark) icon';
$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.';

// Privacy API.
$string['privacy:metadata'] = 'The Boost Union theme does not store any personal data about any user.';

Expand Down
3 changes: 3 additions & 0 deletions layout/columns2.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
// Include the template content for the footnote.
require_once(__DIR__ . '/includes/footnote.php');

// Include the template content for the static pages.
require_once(__DIR__ . '/includes/staticpages.php');

// Render columns2.mustache from boost_union.
echo $OUTPUT->render_from_template('theme_boost_union/columns2', $templatecontext);
3 changes: 3 additions & 0 deletions layout/drawers.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,8 @@
// Include the template content for the footnote.
require_once(__DIR__ . '/includes/footnote.php');

// Include the template content for the static pages.
require_once(__DIR__ . '/includes/staticpages.php');

// Render drawers.mustache from boost_union.
echo $OUTPUT->render_from_template('theme_boost_union/drawers', $templatecontext);
3 changes: 3 additions & 0 deletions layout/includes/footnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
// Use format_text function to enable multilanguage filtering.
$footnotesetting = format_text($footnotesetting);

// Add marker to show the footnote to templatecontext.
$templatecontext['showfootnote'] = true;

// Add footnote to templatecontext.
$templatecontext['footnotesetting'] = $footnotesetting;
}
57 changes: 57 additions & 0 deletions layout/includes/staticpages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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 - Static pages layout include.
*
* @package theme_boost_union
* @copyright 2022 Moodle an Hochschulen e.V. <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

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

$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;
}

// 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->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 imprint link and page title to the templatecontext.
$templatecontext['imprintlink'] = theme_boost_union_get_imprint_link();
$templatecontext['imprintpagetitle'] = theme_boost_union_get_imprint_pagetitle();
}
3 changes: 3 additions & 0 deletions layout/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
// Include the template content for the footnote.
require_once(__DIR__ . '/includes/footnote.php');

// Include the template content for the static pages.
require_once(__DIR__ . '/includes/staticpages.php');

// Render login.mustache from boost_union.
echo $OUTPUT->render_from_template('theme_boost_union/login', $templatecontext);
5 changes: 5 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
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');


/**
* Returns the main SCSS content.
Expand Down
34 changes: 34 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,37 @@ function theme_boost_union_get_course_related_hints() {
// Return HTML code.
return $html;
}

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

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

/**
* Build the page title of the imprint page.
*
* @return string.
*/
function theme_boost_union_get_imprint_pagetitle() {
// Get the configured page title.
$imprintpagetitleconfig = get_config('theme_boost_union', 'imprintpagetitle');

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

// Otherwise.
} else {
// Return the default string.
return get_string('imprintpagetitledefault', 'theme_boost_union');
}
}
75 changes: 75 additions & 0 deletions pages/imprint.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 - Imprint page.
*
* @package theme_boost_union
* @copyright 2022 Moodle an Hochschulen e.V. <[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/imprint.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-imprint');

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

// If the imprint is disabled, we just show a short friendly warning page and are done.
if ($config->enableimprint != THEME_BOOST_UNION_SETTING_SELECT_YES) {
echo $OUTPUT->header();
$notification = new \core\output\notification(get_string('imprintdisabled', '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_imprint_pagetitle());

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

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

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

// Finish page.
echo $OUTPUT->footer();
59 changes: 59 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

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

if ($ADMIN->fulltree) {

Expand Down Expand Up @@ -273,6 +274,64 @@

// Add tab to settings page.
$settings->add($page);


// Create static pages tab.
$page = new admin_settingpage('theme_boost_union_staticpages', get_string('staticpagestab', 'theme_boost_union', null, true));

// Create imprint heading.
$name = 'theme_boost_union/imprintheading';
$title = get_string('imprintheading', 'theme_boost_union', null, true);
$setting = new admin_setting_heading($name, $title, null);
$page->add($setting);

// Setting: Enable imprint.
$name = 'theme_boost_union/enableimprint';
$title = get_string('enableimprintsetting', 'theme_boost_union', null, true);
$description = '';
$setting = new admin_setting_configselect($name, $title, $description, THEME_BOOST_UNION_SETTING_SELECT_NO, $yesnooption);
$page->add($setting);

// Setting: Imprint content.
$name = 'theme_boost_union/imprintcontent';
$title = get_string('imprintcontentsetting', 'theme_boost_union', null, true);
$description = get_string('imprintcontentsetting_desc', 'theme_boost_union', null, true);
$setting = new admin_setting_confightmleditor($name, $title, $description, '');
$page->add($setting);
$settings->hide_if('theme_boost_union/imprintcontent', 'theme_boost_union/enableimprint', 'neq', 'yes');

// Setting: Imprint page title.
$name = 'theme_boost_union/imprintpagetitle';
$title = get_string('imprintpagetitlesetting', 'theme_boost_union', null, true);
$description = get_string('imprintpagetitlesetting_desc', 'theme_boost_union', null, true);
$default = get_string('imprintpagetitledefault', 'theme_boost_union', null, true);
$setting = new admin_setting_configtext($name, $title, $description, $default);
$page->add($setting);
$settings->hide_if('theme_boost_union/imprintpagetitle', 'theme_boost_union/enableimprint', 'neq', 'yes');

// Setting: Imprint link position.
$name = 'theme_boost_union/imprintlinkposition';
$title = get_string('imprintlinkpositionsetting', 'theme_boost_union', null, true);
$imprinturl = theme_boost_union_get_imprint_link();
$description = get_string('imprintlinkpositionsetting_desc', 'theme_boost_union', array('url' => $imprinturl), true);
$imprintlinkpositionoption =
// Don't use string lazy loading (= false) because the string will be directly used and would produce a
// PHP warning otherwise.
array(THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_NONE =>
get_string('imprintlinkpositionnone', 'theme_boost_union', null, false),
THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_FOOTNOTE =>
get_string('imprintlinkpositionfootnote', 'theme_boost_union', null, false),
THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_FOOTER =>
get_string('imprintlinkpositionfooter', 'theme_boost_union', null, false),
THEME_BOOST_UNION_SETTING_IMPRINTLINKPOSITION_BOTH =>
get_string('imprintlinkpositionboth', 'theme_boost_union', null, false));
$default = 'none';
$setting = new admin_setting_configselect($name, $title, $description, $default, $imprintlinkpositionoption);
$page->add($setting);
$settings->hide_if('theme_boost_union/imprintlinkposition', 'theme_boost_union/enableimprint', 'neq', 'yes');

// Add tab to settings page.
$settings->add($page);
}

// Above, we made the theme setting not only available to admins but also
Expand Down
3 changes: 2 additions & 1 deletion templates/columns2.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Modifications compared to this template:
* Include theme_boost_union/footnote template
* Include theme_boost_union/footer template instead of theme_boost/footer
* Added the possibility to show course related hints.
}}
{{> theme_boost/head }}
Expand Down Expand Up @@ -106,7 +107,7 @@
</div>
</div>
{{{ output.standard_after_main_region_html }}}
{{> theme_boost/footer }}
{{> theme_boost_union/footer }}
{{> theme_boost_union/footnote }}
</div>

Expand Down
3 changes: 2 additions & 1 deletion templates/drawers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
Modifications compared to this template:
* Include theme_boost_union/footnote template
* Include theme_boost_union/footer template instead of theme_boost/footer
* Added the possibility to show course related hints.
}}
{{> theme_boost/head }}
Expand Down Expand Up @@ -171,7 +172,7 @@
</div>
</div>
</div>
{{> theme_boost/footer }}
{{> theme_boost_union/footer }}
{{> theme_boost_union/footnote }}
</div>
{{{ output.standard_after_main_region_html }}}
Expand Down
Loading

0 comments on commit 5b22ec8

Please sign in to comment.