From ed7cd552f8175b25e67d9e611fa4db394b70f279 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 8 May 2020 15:21:59 +0800 Subject: [PATCH] MDL-68320 core: add campaign content to notifications page --- admin/index.php | 6 ++- admin/renderer.php | 20 +++++++++- config-dist.php | 9 +++++ lib/templates/campaign_content.mustache | 50 +++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 lib/templates/campaign_content.mustache diff --git a/admin/index.php b/admin/index.php index ee3b2e3b85e..56603183479 100644 --- a/admin/index.php +++ b/admin/index.php @@ -899,6 +899,9 @@ if (empty($CFG->disabledevlibdirscheck) && (is_dir($CFG->dirroot.'/vendor') || i // Check if the site is being foced onto ssl. $overridetossl = !empty($CFG->overridetossl); +// Check if moodle campaign content setting is enabled or not. +$showcampaigncontent = !isset($CFG->showcampaigncontent) || $CFG->showcampaigncontent; + admin_externalpage_setup('adminnotifications'); $output = $PAGE->get_renderer('core', 'admin'); @@ -906,4 +909,5 @@ $output = $PAGE->get_renderer('core', 'admin'); echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, $registered, $cachewarnings, $eventshandlers, $themedesignermode, $devlibdir, - $mobileconfigured, $overridetossl, $invalidforgottenpasswordurl, $croninfrequent); + $mobileconfigured, $overridetossl, $invalidforgottenpasswordurl, $croninfrequent, + $showcampaigncontent); diff --git a/admin/renderer.php b/admin/renderer.php index 45f46a57e3d..cda9ed65e60 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -282,6 +282,7 @@ class core_admin_renderer extends plugin_renderer_base { * @param bool $overridetossl Whether or not ssl is being forced. * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL. * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes + * @param bool $showcampaigncontent Whether the campaign content should be visible or not. * * @return string HTML to output. */ @@ -289,7 +290,9 @@ class core_admin_renderer extends plugin_renderer_base { $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0, $themedesignermode = false, $devlibdir = false, $mobileconfigured = false, - $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false) { + $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false, + $showcampaigncontent = false) { + global $CFG; $output = ''; @@ -312,6 +315,7 @@ class core_admin_renderer extends plugin_renderer_base { $output .= $this->registration_warning($registered); $output .= $this->mobile_configuration_warning($mobileconfigured); $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl); + $output .= $this->campaign_content($showcampaigncontent); ////////////////////////////////////////////////////////////////////////////////////////////////// //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// @@ -878,6 +882,20 @@ class core_admin_renderer extends plugin_renderer_base { return $output; } + /** + * Display campaign content. + * + * @param bool $showcampaigncontent Whether the campaign content should be visible or not. + * @return string the campaign content raw html. + */ + protected function campaign_content(bool $showcampaigncontent): string { + if (!$showcampaigncontent) { + return ''; + } + + return $this->render_from_template('core/campaign_content', ['lang' => current_language()]); + } + /** * Display a warning about the forgotten password URL not linking to a valid URL. * diff --git a/config-dist.php b/config-dist.php index ccc760ae7e0..995e0df8b0c 100644 --- a/config-dist.php +++ b/config-dist.php @@ -1055,6 +1055,15 @@ $CFG->admin = 'admin'; // $CFG->alternative_file_system_class = '\\local_myfilestorage\\file_system'; // //========================================================================= +// 15. CAMPAIGN CONTENT +//========================================================================= +// +// We have added a campaign content to the notifications page, in case you want to hide that from your site you just +// need to set showcampaigncontent setting to false. +// +// $CFG->showcampaigncontent = true; +// +//========================================================================= // ALL DONE! To continue installation, visit your main page with a browser //========================================================================= diff --git a/lib/templates/campaign_content.mustache b/lib/templates/campaign_content.mustache new file mode 100644 index 00000000000..dbba38284f2 --- /dev/null +++ b/lib/templates/campaign_content.mustache @@ -0,0 +1,50 @@ +{{! + 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 . +}} +{{! + @template core/campaign_content + + Moodle campaign content template. + + The purpose of this template is to render an iframe that contains campaign content. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * lang User's language. + + Example context (json): + { "lang": "en"} +}} +
+ + +
+{{#js}} +(function() { + var iframe = document.getElementById('campaign-content'); + iframe.src = 'https://campaign.moodle.org/current/lms/{{lang}}/'; + window.addEventListener('message', function (event) { + if (event.origin === 'https://campaign.moodle.org') { + iframe.style.height = event.data + 'px'; + } + }); +})(); +{{/js}}