Skip to content

Commit

Permalink
MDL-68320 core: add campaign content to notifications page
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Jun 3, 2020
1 parent 2e324c1 commit ed7cd55
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
6 changes: 5 additions & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,15 @@
// 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');

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);
20 changes: 19 additions & 1 deletion admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,17 @@ public function upgrade_confirm_abort_install_page(array $abortable, moodle_url
* @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.
*/
public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
$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 = '';

Expand All @@ -312,6 +315,7 @@ public function admin_notifications_page($maturity, $insecuredataroot, $errorsdi
$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 ///
Expand Down Expand Up @@ -878,6 +882,20 @@ protected function mobile_configuration_warning($mobileconfigured) {
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.
*
Expand Down
9 changes: 9 additions & 0 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,15 @@
// $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
//=========================================================================

Expand Down
50 changes: 50 additions & 0 deletions lib/templates/campaign_content.mustache
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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"}
}}
<div class="alert alert-secondary alert-block fade in alert-dismissible">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<iframe id="campaign-content" class="w-100 border-0"></iframe>
</div>
{{#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}}

0 comments on commit ed7cd55

Please sign in to comment.