/**The project module code requires modification to be compatible with Moodle versions earlier than 1.5. * to make the code operate in version 1.4.x you need to add three patchs, which add a total of four new function definitions. * to do that, paste the following patches in the designated file in the /lib folder of the moodle program folder. * It seems that it does not matter where you paste the code within the file. * I pasted these patches of code near the end of the file and saved it. After that, the project module worked. * Don Hinkelman, 2005.10.31 */ /** Patch 1 * * Place the following two function definitions in the weblib.php file within the lib folder * * Given a simple string, this function returns the string * processed by enabled filters if $CFG->filterall is enabled * * @param string $string The string to be filtered. * @param boolean $striplinks To strip any link in the result text. * @param int $courseid Current course as filters can, potentially, use it * @return string */ function format_string ($string, $striplinks = false, $courseid=NULL ) { global $CFG, $course; //We'll use a in-memory cache here to speed up repeated strings static $strcache; //Calculate md5 $md5 = md5($string.'<+>'.$striplinks); //Fetch from cache if possible if(isset($strcache[$md5])) { return $strcache[$md5]; } if (empty($courseid)) { if (!empty($course->id)) { // An ugly hack for better compatibility $courseid = $course->id; // (copied from format_text) } } if (!empty($CFG->filterall)) { $string = filter_text($string, $courseid); } if ($striplinks) { //strip links in string $string = preg_replace('/(]+?>)(.+?)(<\/a>)/is','$2',$string); } //Store to cache $strcache[$md5] = $string; return $string; } /** * Recursive implementation of stripslashes() * * This function will allow you to strip the slashes from a variable. * If the variable is an array or object, slashes will be stripped * from the items (or properties) it contains, even if they are arrays * or objects themselves. * * @param mixed the variable to remove slashes from * @return mixed */ function stripslashes_recursive($var) { if(is_object($var)) { $properties = get_object_vars($var); foreach($properties as $property => $value) { $var->$property = stripslashes_recursive($value); } } else if(is_array($var)) { foreach($var as $property => $value) { $var[$property] = stripslashes_recursive($value); } } else if(is_string($var)) { $var = stripslashes($var); } return $var; } /** Patch 2 * * Place this in lib/datalib.php of Moodle version 1.4.x * * Escape all dangerous characters in a data record * * $dataobject is an object containing needed data * Run over each field exectuting addslashes() function * to escape SQL unfriendly characters (e.g. quotes) * Handy when writing back data read from the database * * @param $dataobject Object containing the database record * @return object Same object with neccessary characters escaped */ function addslashes_object( $dataobject ) { $a = get_object_vars( $dataobject); foreach ($a as $key=>$value) { $a[$key] = addslashes( $value ); } return (object)$a; } /** Patch 3 * * place this in the lib/moodlelib.php file of Moodle version 1.4 * * originally from line 6245 in version 1.5.2, lib/moodle.php */ function remove_dir($dir, $content_only=false) { // if content_only=true then delete all but // the directory itself $handle = opendir($dir); while (false!==($item = readdir($handle))) { if($item != '.' && $item != '..') { if(is_dir($dir.'/'.$item)) { remove_dir($dir.'/'.$item); }else{ unlink($dir.'/'.$item); } } } closedir($handle); if ($content_only) { return true; } return rmdir($dir); }