Adding the capability to replace existing scripts with customised versions.

See config-dist.php for more info.

Will add an admin interface for this later.

Shane.
This commit is contained in:
moodler 2005-07-14 15:35:23 +00:00
parent f5686a5839
commit 18259d4fd3
3 changed files with 61 additions and 0 deletions

View File

@ -219,6 +219,21 @@ $CFG->admin = 'admin';
// a phrase occurs in a given page. Otherwise all are matched.
// $CFG->filtermatchoneperpage = true;
//
// Enabling this will allow custom scripts to replace existing moodle scripts.
// For example: if $CFG->dataroot/customscripts/course/view.php exists then
// it will be used instead of $CFG->wwwroot/course/view.php
// At present this will only work for files that include config.php and are called
// as part of the url (index.php is implied).
// Some examples are:
// http://my.moodle.site/course/view.php
// http://my.moodle.site/index.php
// http://my.moodle.site/admin (index.php implied)
// Custom scripts should not include config.php
// Warning: Replacing standard moodle scripts may pose security risks and/or may not
// be compatible with upgrades. Use this option only if you are aware of the risks
// involved.
// $CFG->customscripts = true;
//
// Performance profiling
//
// If you set Debug to "Yes" in the Configuration->Variables page some

View File

@ -6463,5 +6463,41 @@ 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 full path name if a custom script exists
* @return bool false if no custom script exists
*/
function custom_script_path($urlpath='') {
global $CFG;
if (empty($urlpath) or (strpos($CFG->wwwroot, $urlpath) === false) ) {
$urlpath = qualified_me();
if (!$urlpath) return false;
}
// Strip wwwroot out
$scriptpath = str_replace($CFG->wwwroot, $CFG->dataroot.'/customscripts', $urlpath);
/// Strip the query string out
$parts = parse_url($scriptpath);
$scriptpath = $parts['path'];
/// put an index.php on the end if no explicit script name present
if (rtrim($scriptpath, '/') != $scriptpath) {
$scriptpath .= 'index.php';
}
if (file_exists($scriptpath)) {
return $scriptpath;
} else {
return false;
}
}
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
?>

View File

@ -433,6 +433,16 @@ global $THEME;
/// Adjust ALLOWED_TAGS
adjust_allowed_tags();
/// Use a custom script replacement if one exists
if (!empty($CFG->customscripts)) {
if (($customscript = custom_script_path()) !== false) {
include ($customscript);
exit;
}
}
/***
*** init_performance_info() {
***