From 7858b5212c82fa4a14ecf46085069194947f3bda Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 15 Jan 2012 15:51:55 +0100 Subject: [PATCH] MDL-21992 fix custom scripts on https pages and CLI --- lib/moodlelib.php | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 29142057ae1..e3e26f04e55 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -10053,40 +10053,20 @@ function object_property_exists( $obj, $property ) { * Detect a custom script replacement in the data directory that will * 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 */ -function custom_script_path($urlpath='') { - global $CFG; +function custom_script_path() { + global $CFG, $SCRIPT; - // set default $urlpath, if necessary - if (empty($urlpath)) { - $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 )) { + if ($SCRIPT === null) { + // Probably some weird external script return false; } - // replace wwwroot with the path to the customscripts folder and clean path - $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'; - } + $scriptpath = $CFG->customscripts . $SCRIPT; // check the custom script exists - if (file_exists($scriptpath)) { + if (file_exists($scriptpath) and is_file($scriptpath)) { return $scriptpath; } else { return false;