The relatively new logo serving code uses the method 'setting_file_url' in '/lib/outputlib.php' and that has some https code that could be adapted:
public function setting_file_url($setting, $filearea) {
global $CFG;
if (empty($this->settings->$setting)) {
return null;
}
$component = 'theme_'.$this->name;
$itemid = theme_get_revision();
$filepath = $this->settings->$setting;
$syscontext = context_system::instance();
$url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php", "/$syscontext->id/$component/$filearea/$itemid".$filepath);
// Now this is tricky because the we can not hardcode http or https here, lets use the relative link.
// Note: unfortunately moodle_url does not support //urls yet.
$url = preg_replace('|^https?://|i', '//', $url->out(false));
return $url;
}
as I do in the Shoelace theme:
function theme_shoelace_set_fontwww($css) {
global $CFG;
$tag = 'setting:fontwww';
$syscontext = context_system::instance();
$itemid = theme_get_revision();
$url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php", "/$syscontext->id/theme_shoelace/font/$itemid/");
// Now this is tricky because the we can not hard code http or https here, lets use the relative link.
// Note: unfortunately moodle_url does not support //urls yet.
$url = preg_replace('|^https?://|i', '//', $url->out(false));
$css = str_replace($tag, $url, $css);
return $css;
}
and then serve:
function theme_shoelace_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM) {
if ($filearea === 'logo') {
$theme = theme_config::load('shoelace');
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
} else if ($filearea === 'font') {
global $CFG;
if (!empty($CFG->themedir)) {
$thefontpath = $CFG->themedir . '/shoelace/style/font/';
} else {
$thefontpath = $CFG->dirroot . '/theme/shoelace/style/font/';
}
// Use log as a way of seeing what is going on.
//add_to_log(24, 'theme_shoelace', '$thefontpath', $thefontpath);
//add_to_log(24, 'theme_shoelace', 'args[1]', $args[1]);
//send_file($thefontpath.$args[1], $args[1]); // Mime type detection not working?
// Note: Third parameter is normally 'default' which is the 'lifetime' of the file. Here set lower for development purposes.
send_file($thefontpath.$args[1], $args[1], 20 , 0, false, false, 'font/opentype');
} else {
send_file_not_found();
}
} else {
send_file_not_found();
}
}