MDL-21992 fix custom scripts on https pages and CLI

This commit is contained in:
Petr Skoda 2012-01-15 15:51:55 +01:00 committed by kordan
parent 716cd6b507
commit 8aaa2370bc

View File

@ -10060,40 +10060,20 @@ function object_property_exists( $obj, $property ) {
* Detect a custom script replacement in the data directory that will * Detect a custom script replacement in the data directory that will
* replace an existing moodle script * replace an existing moodle script
* *
* @param string $urlpath path to the original script
* @return string|bool full path name if a custom script exists, false if no custom script exists * @return string|bool full path name if a custom script exists, false if no custom script exists
*/ */
function custom_script_path($urlpath='') { function custom_script_path() {
global $CFG; global $CFG, $SCRIPT;
// set default $urlpath, if necessary if ($SCRIPT === null) {
if (empty($urlpath)) { // Probably some weird external script
$urlpath = qualified_me(); // e.g. http://www.this-server.com/moodle/this-script.php
}
// $urlpath is invalid if it is empty or does not start with the Moodle wwwroot
if (empty($urlpath) or (strpos($urlpath, $CFG->wwwroot) === false )) {
return false; return false;
} }
// replace wwwroot with the path to the customscripts folder and clean path $scriptpath = $CFG->customscripts . $SCRIPT;
$scriptpath = $CFG->customscripts . clean_param(substr($urlpath, strlen($CFG->wwwroot)), PARAM_PATH);
// remove the query string, if any
if (($strpos = strpos($scriptpath, '?')) !== false) {
$scriptpath = substr($scriptpath, 0, $strpos);
}
// remove trailing slashes, if any
$scriptpath = rtrim($scriptpath, '/\\');
// append index.php, if necessary
if (is_dir($scriptpath)) {
$scriptpath .= '/index.php';
}
// check the custom script exists // check the custom script exists
if (file_exists($scriptpath)) { if (file_exists($scriptpath) and is_file($scriptpath)) {
return $scriptpath; return $scriptpath;
} else { } else {
return false; return false;