Skip to content
Snippets Groups Projects
Commit 02508ec6 authored by Kathrin Osswald's avatar Kathrin Osswald
Browse files

Added a setting to be able to add texts to your uploaded background images for the login page.

parent fd85c2b2
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ Changes
### Unreleased
* 2019-05-03 - Added a setting to be able to add texts to your uploaded background images for the login page.
* 2019-05-02 - Added setting to be able to add additional resources to the theme.
### Release v3.6-r4
......
......@@ -215,6 +215,16 @@ Please note: These images will *not* be rendered on small screens. We prevent th
* The login field takes most of the space on small screens, so the background image is hidden behind it and therefore it is not really needed there.
* Smalls screens indicate that the user is visiting the page with a mobile device. Not loading the background image in this cases will also save data traffic for the user.
##### Display text for login background images
With this optional setting you can add text, e.g. a copyright notice to your uploaded background images.
Each line consists of the file identifier (the file name) and the text that should be displayed, separated by a pipe character. Each declaration needs to be written in a new line.
For example:
``background-image-1.jpg|Copyright: CC0``
You can declare texts for a arbitrary amount of your uploaded background images. The texts will be added only to those images that match their filename with the identifier declared in this setting.
##### Login form
With this setting you can optimize the login form to fit to a greater variety background images (if checked). This means that the login form will be moved to the left of the login page, will get smaller in width and will get a background that let the background image shine through. The login form will be placed on the left because many images have their main content rather in the center and so we keep this content visible. Note: You can also activate this setting if no background images are uploaded, of course.
......
......@@ -172,6 +172,12 @@ $string['designsettings'] = 'Design Settings';
$string['loginpagedesignheadingsetting'] = 'Login page';
$string['loginbackgroundimagesetting'] = 'Login page background images';
$string['loginbackgroundimagesetting_desc'] = 'Images uploaded in this setting will be randomly displayed on the login page as background images.';
$string['loginbackgroundimagetextsetting'] = 'Display text for login background images';
$string['loginbackgroundimagetextsetting_desc'] = 'With this optional setting you can add text, e.g. a copyright notice to your uploaded background images.<br/>
Each line consists of the file identifier (the file name) and the text that should be displayed, separated by a pipe character. Each declaration needs to be written in a new line. <br/>
For example:<br/>
background-image-1.jpg|Copyright: CC0<br/>
You can declare texts for a arbitrary amount of your uploaded background images. The texts will be added only to those images that match their filename with the identifier declared in this setting.';
$string['loginform'] = 'Login form';
$string['loginform_desc'] = 'With this setting you can optimize the login form to fit to a greater variety background images (if checked). This means that the login form will be moved to the left of the login page, will get smaller in width and will get a background that let the background image shine through. The login form will be placed on the left because many images have their main content rather in the center and so we keep this content visible. Note: You can also activate this setting if no background images are uploaded, of course.';
// ...Fonts.
......
......@@ -25,12 +25,16 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/theme/boost_campus/locallib.php');
$bodyattributes = $OUTPUT->body_attributes();
$loginbackgroundimagetext = theme_boost_campus_get_loginbackgroundimage_text();
$templatecontext = [
'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
'output' => $OUTPUT,
'bodyattributes' => $bodyattributes
'bodyattributes' => $bodyattributes,
'loginbackgroundimagetext' => $loginbackgroundimagetext
];
// MODIFICATION START: Handle additional layout elements.
......
......@@ -23,38 +23,118 @@
defined('MOODLE_INTERNAL') || die();
/**
* Get a random class for body tag for the background image of the login page.
* Return the files from the loginbackgroundimage file area.
* This function always loads the files from the filearea that is not really performant.
* However, we accept this at the moment as it is only invoked on the login page.
*
* @return string
* @return array|null
* @throws coding_exception
* @throws dml_exception
*/
function theme_boost_campus_get_random_loginbackgroundimage_class() {
function theme_boost_campus_get_loginbackgroundimage_files() {
// Fetch context.
// Static variable to remember the files for subsequent calls of this function.
static $files = null;
if ($files == null) {
// 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_campus', 'loginbackgroundimage', false, 'itemid', false);
$files = $fs->get_area_files($systemcontext->id, 'theme_boost_campus', 'loginbackgroundimage',
false, 'itemid', false);
}
return $files;
}
/**
* Get the random number for displaying the background image on the login page randomly.
*
* @return int|null
* @throws coding_exception
* @throws dml_exception
*/
function theme_boost_campus_get_random_loginbackgroundimage_number() {
// Static variable.
static $number = null;
if ($number == null) {
// Get all files for loginbackgroundimages.
$files = theme_boost_campus_get_loginbackgroundimage_files();
// Get count of array elements.
$filecount = count($files);
/* We only add this class to the body background of the login page if images are uploaded at all (filearea contains images). */
// We only return a number if images are uploaded to the loginbackgroundimage file area.
if ($filecount > 0) {
// Generate random number.
$randomindex = rand(1, $filecount);
return "loginbackgroundimage" . $randomindex;
$number = rand(1, $filecount);
}
}
return $number;
}
/**
* Get a random class for body tag for the background image of the login page.
*
* @return string
*/
function theme_boost_campus_get_random_loginbackgroundimage_class() {
// Get the static random number.
$number = theme_boost_campus_get_random_loginbackgroundimage_number();
// Only create the class name with the random number if there is a number (=files uploaded to the file area).
if ($number != null) {
return "loginbackgroundimage" . $number;
} else {
return "";
}
}
/**
* Get the text that should be displayed for the randomly displayed background image on the login page.
*
* @return string
* @throws coding_exception
* @throws dml_exception
*/
function theme_boost_campus_get_loginbackgroundimage_text() {
// Get the random number.
$number = theme_boost_campus_get_random_loginbackgroundimage_number();
// Only search for the text if there's a background image.
if ($number != null) {
// Get the files from the filearea loginbackgroundimage.
$files = theme_boost_campus_get_loginbackgroundimage_files();
// Get the file for the selected random number.
$file = array_slice($files, ($number - 1), 1, false);
// Get the filename.
$filename = array_pop($file)->get_filename();
// Get the config for loginbackgroundimagetext and make array out of the lines.
$lines = explode("\n", get_config('theme_boost_campus', 'loginbackgroundimagetext'));
// Proceed the lines.
foreach ($lines as $line) {
$settings = explode("|", $line);
// Compare the filenames for a match and return the text that belongs to the randomly selected image.
if (strcmp($filename, $settings[0]) == 0) {
return $settings[1];
break;
}
}
} else {
return "";
}
}
/**
* Add background images from setting 'loginbackgroundimage' to SCSS.
......@@ -65,14 +145,8 @@ function theme_boost_campus_get_loginbackgroundimage_scss() {
$count = 0;
$scss = "";
// Fetch 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_campus', 'loginbackgroundimage', false, 'itemid', false);
$files = theme_boost_campus_get_loginbackgroundimage_files();
// Add URL of uploaded images to eviqualent class.
foreach ($files as $file) {
......@@ -87,7 +161,6 @@ function theme_boost_campus_get_loginbackgroundimage_scss() {
return $scss;
}
/**
* Create information needed for the imagearea.mustache file.
*
......@@ -163,7 +236,6 @@ function theme_boost_campus_get_imageareacontent() {
}
}
/**
* Returns a modified flat_navigation object.
*
......
......@@ -183,6 +183,12 @@ body.loginbackgroundimage {
}
}
/* Design for the text that can be added to the background images of the login page. */
#loginbackgroundimagetext span {
background-color: #fff;
border: 1px solid rgba(0, 0, 0, .125);
}
/* This will only be needed if the setting "loginform" is checked */
@if variable-exists(loginform) {
@if $loginform == 'yes' {
......@@ -200,6 +206,11 @@ body.loginbackgroundimage {
#page-login-index #page {
margin-top: 0;
}
/* Adjust the design for the loginbackgroundimagetext. */
#loginbackgroundimagetext span {
background-color: rgba(255, 255, 255, 0.8);
border-radius: 3px;
}
}
}
......
......@@ -544,6 +544,13 @@ if ($ADMIN->fulltree) {
$setting->set_updatedcallback('theme_reset_all_caches');
$page->add($setting);
$name = 'theme_boost_campus/loginbackgroundimagetext';
$title = get_string('loginbackgroundimagetextsetting', 'theme_boost_campus', null, true);
$description = get_string('loginbackgroundimagetextsetting_desc', 'theme_boost_campus', null, true);
$setting = new admin_setting_configtextarea($name, $title, $description, null, PARAM_TEXT);
$setting->set_updatedcallback('theme_reset_all_caches');
$page->add($setting);
// Setting to change the position and design of the login form.
$name = 'theme_boost_campus/loginform';
$title = get_string('loginform', 'theme_boost_campus', null, true);
......
......@@ -51,6 +51,13 @@
</section>
</div>
</div>
{{# loginbackgroundimagetext }}
<div class="row-fluid justify-content-end" id="loginbackgroundimagetext">
<span class="m-3 px-3 py-2 d-none d-md-inline">
{{loginbackgroundimagetext}}
</span>
</div>
{{/ loginbackgroundimagetext }}
</div>
<footer id="page-footer" class="py-3 bg-dark text-light">
<div class="container">
......
......@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'theme_boost_campus';
$plugin->version = 2019050200;
$plugin->version = 2019050300;
$plugin->release = 'v3.6-r4';
$plugin->requires = 2018120300;
$plugin->maturity = MATURITY_STABLE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment