Skip to content

Commit

Permalink
Changes to custom script code. Credit to Gordon Bateson. Bug 4827.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikawhero committed Mar 6, 2006
1 parent 2e05b22 commit 70070c1
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions lib/moodlelib.php
Expand Up @@ -6920,26 +6920,36 @@ function object_property_exists( $obj, $property ) {
function custom_script_path($urlpath='') {
global $CFG;

if (empty($urlpath) or (strpos($CFG->wwwroot, $urlpath) === false) ) {
$urlpath = qualified_me();
if (!$urlpath) return false;
// set default $urlpath, if necessary
if (empty($urlpath)) {
$urlpath = qualified_me(); // e.g. http://www.this-server.com/moodle/this-script.php
}

/// Strip wwwroot out
$scriptpath = str_replace($CFG->wwwroot, $CFG->customscripts, $urlpath);
// clean the $urlpath
$urlpath = clean_param($urlpath, PARAM_URL);

/// Clean the path
$scriptpath = clean_param($scriptpath, PARAM_PATH);
// $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;
}

// replace wwwroot with the path to the customscripts folder
$scriptpath = $CFG->customscripts . substr($urlpath, strlen($CFG->wwwroot));

// remove the query string, if any
if (($strpos = strpos($scriptpath, '?')) !== false) {
$scriptpath = substr($scriptpath, 0, $strpos);
}

/// Strip the query string out
$parts = parse_url($scriptpath);
$scriptpath = $parts['path'];
// remove trailing slashes, if any
$scriptpath = rtrim($scriptpath, '/\\');

/// put an index.php on the end if no explicit script name present
if (rtrim($scriptpath, '/') != $scriptpath) {
$scriptpath .= 'index.php';
// append index.php, if necessary
if (is_dir($scriptpath)) {
$scriptpath .= '/index.php';
}

// check the custom script exists
if (file_exists($scriptpath)) {
return $scriptpath;
} else {
Expand Down

0 comments on commit 70070c1

Please sign in to comment.