Skip to content

Commit

Permalink
Added frontpage slider functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Diphylla authored and ShUl0w committed Sep 28, 2023
1 parent e4077f0 commit 8381e1e
Show file tree
Hide file tree
Showing 11 changed files with 699 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changes
* 2023-09-22 - Make codechecker happier
* 2023-09-24 - Test: Behat scenario 'Show hint for self enrolment without an enrolment key' was broken, solves #398.
* 2023-09-22 - Improvement: Reuse Moodle core function remove_dir(), solves #369.
* 2023-09-19 - Feature: Add slider which can be displayed on site home, solves #162.

### v4.2-r2

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ In this tab, you can enable and configure multiple information banners to be sho

In this tab, you can enable and configure multiple advertisement tiles to be shown on site home.

#### Tab "Slider"

In this tab, you can enable and configure multiple slides to be shown on site home.

### Settings page "Functionality"

#### Tab "Courses"
Expand Down
46 changes: 45 additions & 1 deletion lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@
$string['infobannerdismissiblesetting'] = 'Info banner {$a->no} dismissible';
$string['infobannerdismissiblesetting_desc'] = 'With this setting, you can make info banner {$a->no} dismissible. If the user clicks on the x-button in the info banner, the banner will be hidden for this user permanently. The visibility is not reset anyhow automatically, even if you change the content of the info banner. If you want to reset the visibility of the info banner, click the \'Reset visibility\' button below.';
$string['infobannerstartsetting'] = 'Info banner {$a->no} start time';
$string['infobannerstartsetting_desc'] = 'With this setting, you can define from when on info banner {$a->no} should be displayed. The configured time is interpreted as server time, not as user time.';$string['infobannerendsetting'] = 'Info banner {$a->no} end time';
$string['infobannerstartsetting_desc'] = 'With this setting, you can define from when on info banner {$a->no} should be displayed. The configured time is interpreted as server time, not as user time.';
$string['infobannerendsetting'] = 'Info banner {$a->no} end time';
$string['infobannerendsetting_desc'] = 'With this setting, you can define until when info banner {$a->no} should be displayed. The configured time is interpreted as server time, not as user time.';
// Settings: Advertisement tiles tab.
$string['tilestab'] = 'Advertisement tiles';
Expand Down Expand Up @@ -763,6 +764,49 @@
$string['flavourstitle'] = 'Title';
$string['flavourstitle_help'] = 'The flavour\'s title is just used internally to allow you to document a particular flavour in the list of flavours.';

// Settings: Slider.
$string['slidertab'] = 'Slider';
// ... Section: Slider general.
$string['slidergeneralheading'] = 'Slider general';
$string['slideractivatedsetting'] = 'Activate Slider';
$string['slideractivatedsetting_desc'] = 'With this setting, you activate the slider to be shown on site home.';
$string['sliderpositiononfrontpage'] = 'Position the slider';
$string['sliderpositiononfrontpage_desc'] = 'The slider is shown on site home only. With this setting, you control if the slider is displayed before the site home content or after the site home content. If you want to show only the slider on site home and nothing else, all other site home content can be removed by changing the <a href="{$a->url}">site home settings</a>.';
$string['sliderfrontpagepositionsetting_before'] = 'Before the site home content';
$string['sliderfrontpagepositionsetting_after'] = 'After the site home content';
$string['sliderarrownavsetting'] = 'Enable arrow navigation';
$string['sliderarrownavsetting_desc'] = 'With this setting, you can add navigation arrows on both sides of the slider.';
$string['sliderindicatornavsetting'] = 'Enable slider indicator navigation';
$string['sliderindicatornavsetting_desc'] = 'With this setting, you can add navigation indicators on the bottom of the slider.';
$string['slideranimationsetting'] = 'Animation type';
$string['slideranimationsetting_desc'] = 'With this setting, you control the slider animation. \'Slide\' applies a sliding animation, \'fade\' applies a fading animation and \'none\' removes all animations.';
$string['sliderintervalsetting'] = 'Interval speed';
$string['sliderintervalsetting_desc'] = 'With this setting, you control how long a slide is displayed in milliseconds. The minimum value is 1000 (one second) and the maximum value is 10000 (10 seconds).';
$string['sliderridesetting'] = 'Cycle through slides';
$string['sliderridesetting_desc'] = 'With this setting, you control the cycling behaviour of the slider. \'On page load\' begins cycling through slides after the page has finished loading, \'after interaction\' will start cycling after a user has interacted with the slider. \'Never\' disables the automatic cycling of slides altogether, requiring user input to cycle through slides.';
$string['sliderkeybaordsetting'] = 'Allow keyboard interaction';
$string['sliderkeybaordsetting_desc'] = 'With this setting, you enable keyboard inputs (arrow keys) to control the slider. Please note that disabling this lowers accessibility.';
$string['sliderpausesetting'] = 'Pause slider on mouseover';
$string['sliderpausesetting_desc'] = 'With this setting, you prevent the slider from cycling through the slides when a user hovers over a slide. Please note that disabling this lowers accessibility.';
$string['sliderwrapsetting'] = 'Continuously cycle through slides';
$string['sliderwrapsetting_desc'] = 'With this setting, you make the slider cycling through all slides. If you disable this, the slider will stop cycling at the last slide.';
// ... Section: Slides.
$string['oneslidetab'] = 'Slide {$a->no}';
$string['oneslideenabled'] = 'Enable slide {$a->no}';
$string['oneslideenabled_desc'] = 'With this setting, you can enable slide {$a->no}.';
$string['oneslidepickimage'] = 'Slide {$a->no} image';
$string['oneslidepickimage_desc'] = 'Here, you can upload an image file which will be shown as background image behind the content of slide {$a->no}. Please make sure or check that the content is still readable on the background image. Please note that it is required to set an image for the slide to appear.';
$string['oneslideimagetitle'] = 'Slide {$a->no} image title';
$string['oneslideimagetitle_desc'] = 'Here, you can set a title for the image of slide {$a->no}. This is an optional setting, the slide will be shown even if you do not set an image title. Please note that not providing an image title lowers accessibility.';
$string['oneslidelink'] = 'Slide {$a->no} link URL';
$string['oneslidelink_desc'] = 'Here, you can set a (Moodle-internal or external) URL which the slide content of slide {$a->no} will link to. The link will be opened in a new browser tab. This is an optional setting, the slide will be shown even if you do not set a link URL.';
$string['oneslidelinktitle'] = 'Slide {$a->no} link title';
$string['oneslidelinktitle_desc'] = 'Here, you can set a title for the URL of slide {$a->no}. This is an optional setting, the slide will be shown even if you do not set a link title. Please note that not providing a link title lowers accessibility.';
$string['oneslidecaption'] = 'Slide {$a->no} caption';
$string['oneslidecaption_desc'] = 'Here, you enter the caption which should be displayed in slide {$a->no}. The caption is displayed at the bottom center of the slide. This is an optional setting, the slide will be shown even if you do not set a caption.';
$string['oneslidecontent'] = 'Slide {$a->no} content';
$string['oneslidecontent_desc'] = 'Here, you enter the content which should be displayed in slide {$a->no}. The content is displayed at the bottom center of the slide. If a caption is set, the content is displayed below the caption. This is an optional setting, the slide will be shown even if you do not set any content.';

// Settings: Smart menus page.
$string['smartmenus'] = 'Smart menus';
$string['error:smartmenusmenuitemnotfound'] = 'Smart menu item not found';
Expand Down
5 changes: 5 additions & 0 deletions layout/drawers.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@
require_once(__DIR__ . '/includes/advertisementtiles.php');
}

// Include the template content for the slider, but only if we are on the frontpage.
if ($PAGE->pagelayout == 'frontpage') {
require_once(__DIR__ . '/includes/slider.php');
}

// Include the template content for the smart menus.
require_once(__DIR__ . '/includes/smartmenus.php');

Expand Down
122 changes: 122 additions & 0 deletions layout/includes/slider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?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 - scrollspy include.
*
* @package theme_boost_union
* @copyright 2023 Annika Lambert <[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');

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

$generalsettings = new stdClass();
$generalsettings->show = $config->{'slideractivatedsetting'};

// Getting and setting the Slider position on the frontpage.
switch ($config->{'sliderpositiononfrontpage'}) {
case THEME_BOOST_UNION_SETTING_SLIDER_FRONTPAGEPOSITION_BEFORE:
$templatecontext['sliderpositionbefore'] = true;
$templatecontext['sliderpositionafter'] = false;
break;
case THEME_BOOST_UNION_SETTING_SLIDER_FRONTPAGEPOSITION_AFTER:
$templatecontext['sliderpositionbefore'] = false;
$templatecontext['sliderpositionafter'] = true;
}

if ($generalsettings->show) {

$generalsettings->showarrownav = $config->{'sliderarrownavsetting'};
$generalsettings->showindicatornav = $config->{'sliderindicatornavsetting'};

switch ($config->{'slideranimationsetting'}) {
case 0:
$generalsettings->animation = "slide";
break;
case 1:
$generalsettings->animation = "slide carousel-fade";
break;
case 2:
$generalsettings->animation = "";
}
if ($config->{'sliderintervalsetting'} < 1000) {
$generalsettings->interval = 1000;
} else if ($config->{'sliderintervalsetting'} > 10000) {
$generalsettings->interval = 10000;
} else {
$generalsettings->interval = $config->{'sliderintervalsetting'};
}

// Bootstrap mixed-value logic.
switch ($config->{'sliderridesetting'}) {
case 0:
$templatecontext['ride'] = "carousel";
break;
case 1:
$templatecontext['ride'] = "true";
break;
case 2:
$templatecontext['ride'] = "false";
}

$generalsettings->ride = $templatecontext['ride'];

/**
* Maps boolean values (true/false) to corresponding string values ("true"/"false")
*
* PHP translates booleans to 1/0 instead of true/false. Bootstrap needs string boolean values.
* @param var $var The integer representation of a boolean.
* @return string
*/
function boolean_to_string ($var) {
if ($var == 1) {
return "true";
} else {
return "false";
}
}
$generalsettings->keyboard = boolean_to_string($config->{'sliderkeyboardsetting'});
$generalsettings->pause = boolean_to_string($config->{'sliderpausesetting'});
$generalsettings->wrap = boolean_to_string($config->{'sliderwrapsetting'});


$templatecontext['slidergeneralsettings'] = $generalsettings;


$slides = array();
for ($i = 1; $i <= THEME_BOOST_UNION_SETTING_SLIDES_COUNT; $i++) {
$sliderimage = theme_boost_union_get_urlofsliderimage($i);
if ($sliderimage && $config->{'slide' . $i . 'enabled'} == THEME_BOOST_UNION_SETTING_SELECT_YES) {
$slidercontent = new stdClass();
$slidercontent->count = count($slides);
$slidercontent->image = $sliderimage;
$slidercontent->imagetitle = $config->{'oneslideimagetitle' . $i};
$slidercontent->link = $config->{'oneslidelink' . $i};
$slidercontent->linktitle = $config->{'oneslidelinktitle' . $i};
$slidercontent->caption = $config->{'oneslidecaption' . $i};
$slidercontent->content = $config->{'oneslidecontent' . $i};
array_push($slides, $slidercontent);
}
}
$templatecontext['slidecontent'] = $slides;
}
14 changes: 12 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
define('THEME_BOOST_UNION_SETTING_ADVERTISEMENTTILES_FRONTPAGEPOSITION_BEFORE', 1);
define('THEME_BOOST_UNION_SETTING_ADVERTISEMENTTILES_FRONTPAGEPOSITION_AFTER', 2);

define('THEME_BOOST_UNION_SETTING_SLIDES_COUNT', 6);
define('THEME_BOOST_UNION_SETTING_SLIDER_FRONTPAGEPOSITION_BEFORE', 1);
define('THEME_BOOST_UNION_SETTING_SLIDER_FRONTPAGEPOSITION_AFTER', 2);

define('THEME_BOOST_UNION_SETTING_FAVERSION_NONE', 'none');
define('THEME_BOOST_UNION_SETTING_FAVERSION_FA6FREE', 'fa6free');
define('THEME_BOOST_UNION_SETTING_FAFILES_MANDATORY', 'm');
Expand Down Expand Up @@ -341,6 +345,11 @@ function theme_boost_union_get_extra_scss($theme) {
// Setting: Mark external links.
$content .= theme_boost_union_get_scss_to_mark_external_links($theme);

// Load slider css if slider setting is enabled.
if (get_config("theme_boost_union", "slideractivatedsetting")) {
$content .= theme_boost_union_get_slider_scss();
}

return $content;
}

Expand Down Expand Up @@ -436,8 +445,9 @@ function theme_boost_union_pluginfile($course, $cm, $context, $filearea, $args,
// This code is copied and modified from theme_boost_pluginfile() in theme/boost/lib.php.
} else if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'backgroundimage' ||
$filearea === 'loginbackgroundimage' || $filearea === 'additionalresources' ||
$filearea === 'customfonts' || $filearea === 'courseheaderimagefallback' ||
preg_match("/tilebackgroundimage[2-9]|1[0-2]?/", $filearea))) {
$filearea === 'customfonts' || $filearea === 'fontawesome' || $filearea === 'courseheaderimagefallback' ||
preg_match("/tilebackgroundimage[2-9]|1[0-2]?/", $filearea) ||
preg_match("/sliderbackgroundimage[2-9]|1[0-2]?/", $filearea))) {
$theme = theme_config::load('boost_union');
// By default, theme files must be cache-able by both browsers and proxies.
if (!array_key_exists('cacheability', $options)) {
Expand Down
51 changes: 51 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,44 @@ function theme_boost_union_get_urloftilebackgroundimage($tileno) {
return null;
}

/**
*
* Get the slider image URL from the filearea 'oneslideimage'.tileno.
*
* @param int $slideno The slide number.
* @return string|null
*/
function theme_boost_union_get_urlofsliderimage($slideno) {
// Only continue if slide number is valid.
if ($slideno < 0 || $slideno > THEME_BOOST_UNION_SETTING_SLIDES_COUNT) {
return null;
}
// Get the image config for this slide.
$bgconfig = get_config('theme_boost_union', 'oneslidepickimage'.$slideno);

if (!empty($bgconfig)) {
// Get the system context.
$systemcontext = context_system::instance();

// Get filearea.
$fs = get_file_storage();

// Get all files from filearea.
$files = $fs->get_area_files($systemcontext->id, 'theme_boost_union', 'sliderbackgroundimage'.$slideno,
false, 'itemid', false);

// Just pick the first file - we are sure that there is just one file.
$file = reset($files);

// Build and return the image URL.
return moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(),
$file->get_itemid(), $file->get_filepath(), $file->get_filename());
}

// No file was found.
return null;
}

/**
* Add background images from setting 'loginbackgroundimage' to SCSS.
*
Expand Down Expand Up @@ -1342,3 +1380,16 @@ function theme_boost_union_get_scss_to_mark_external_links($theme) {
}
return $scss;
}

/**
* Get the css settings for the slider feature.
*/
function theme_boost_union_get_slider_scss() {
$layout = ".carousel-caption { text-shadow: 0px 0px 2px black; }";
$layout .= ".carousel-control-prev, .carousel-control-next { filter: drop-shadow( 0px 0px 2px rgb(0, 0, 0)); }";
$layout .= ".carousel-indicators { filter: drop-shadow( 0px 0px 1px rgb(0, 0, 0)); }";
$layout .= ".carousel-inner { border-radius: 0.5rem; }";
$layout .= ".boost-union-frontpage-slider { padding: 15px; }";

return $layout;
}
Loading

0 comments on commit 8381e1e

Please sign in to comment.