From 7adac1fefbeda10f1d52c99adfd72adac0da52a1 Mon Sep 17 00:00:00 2001 From: Daniel Neis Araujo Date: Tue, 16 Aug 2022 17:57:41 -0300 Subject: [PATCH] MDL-75218 theme: Add a Favicon setting --- admin/lib.php | 2 +- admin/settings/appearance.php | 8 ++++++++ lang/en/admin.php | 2 ++ lib/outputrenderers.php | 10 +++++++++- theme/upgrade.txt | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/admin/lib.php b/admin/lib.php index 39550844fc2..d9a722d818a 100644 --- a/admin/lib.php +++ b/admin/lib.php @@ -55,7 +55,7 @@ function admin_page_type_list($pagetype, $parentcontext, $currentcontext) { function core_admin_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { global $CFG; - if (in_array($filearea, ['logo', 'logocompact'])) { + if (in_array($filearea, ['logo', 'logocompact', 'favicon'])) { $size = array_shift($args); // The path hides the size. $itemid = clean_param(array_shift($args), PARAM_INT); $filename = clean_param(array_shift($args), PARAM_FILE); diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index b0547e7aaa0..e89c09a1f90 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -82,6 +82,14 @@ reports,core_reportbuilder|/reportbuilder/index.php', $setting->set_updatedcallback('theme_reset_all_caches'); $temp->add($setting); + // Favicon file setting. + $title = get_string('favicon', 'admin'); + $description = get_string('favicon_desc', 'admin'); + $setting = new admin_setting_configstoredfile('core_admin/favicon', $title, $description, 'favicon', 0, + ['maxfiles' => 1, 'accepted_types' => ['image']]); + $setting->set_updatedcallback('theme_reset_all_caches'); + $temp->add($setting); + $ADMIN->add('appearance', $temp); // Course colours section. diff --git a/lang/en/admin.php b/lang/en/admin.php index 248b30d5894..dbfcf026c2a 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -615,6 +615,8 @@ $string['experimentalsettings'] = 'Experimental settings'; $string['extendedusernamechars'] = 'Allow extended characters in usernames'; $string['extramemorylimit'] = 'Extra PHP memory limit'; $string['fatalsessionautostart'] = '

Serious configuration error detected, please notify server administrator.

To operate properly, Moodle requires that administrator changes PHP settings.

session.auto_start must be set to off.

This setting is controlled by editing php.ini, Apache/IIS
configuration or .htaccess file on the server.

'; +$string['favicon'] = 'Favicon'; +$string['favicon_desc'] = 'Favicon file to be displayed as site icon'; $string['feedbacksettings'] = 'Feedback settings'; $string['filescleanupperiod'] = 'Clean up trash pool files'; $string['filescleanupperiod_help'] = 'How often trash pool files are deleted. These are files that are associated with a context that no longer exists, for example when a course is deleted. Please note: This setting can result in missing files in a course which is backed up, deleted and then restored if the setting \'Include files\' (backup_auto_files) in \'Automated backup settings\' is disabled.'; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index a3c536fa80c..f5c11f65870 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -4266,7 +4266,15 @@ EOD; * @return moodle_url The moodle_url for the favicon */ public function favicon() { - return $this->image_url('favicon', 'theme'); + global $CFG; + $logo = get_config('core_admin', 'favicon'); + if (empty($logo)) { + return $this->image_url('favicon', 'theme'); + } + + // Use $CFG->themerev to prevent browser caching when the file changes. + return moodle_url::make_pluginfile_url(context_system::instance()->id, 'core_admin', 'favicon', '64x64/', + theme_get_revision(), $logo); } /** diff --git a/theme/upgrade.txt b/theme/upgrade.txt index c2fa7046373..efa852ad9e1 100644 --- a/theme/upgrade.txt +++ b/theme/upgrade.txt @@ -4,6 +4,7 @@ information provided here is intended especially for theme designer. === 4.1 === * The function core_course_renderer::course_modchooser() has been finally deprecated and can not be used anymore. Please use core_course_renderer::course_activitychooser() instead. +* $OUTPUT->favicon() now returns the URL of the configurable favicon if present. === 4.0 === * A new theme config 'removedprimarynavitems' allows a theme to customise primary navigation by specifying the list of items to remove.