Skip to content

Commit

Permalink
Merge branch 'w03_MDL-21992_m22_customscripts' of https://github.com/…
Browse files Browse the repository at this point in the history
…skodak/moodle into MOODLE_22_STABLE
  • Loading branch information
Aparup Banerjee committed Jan 16, 2012
2 parents 6f96020 + 7991c4c commit 7b3dae9
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions lib/moodlelib.php
Expand Up @@ -10024,40 +10024,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;

// set default $urlpath, if necessary
if (empty($urlpath)) {
$urlpath = qualified_me(); // e.g. http://www.this-server.com/moodle/this-script.php
}
function custom_script_path() {
global $CFG, $SCRIPT;

// $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;
Expand Down

0 comments on commit 7b3dae9

Please sign in to comment.