[Aimmath-commit] moodle/mod/math_assignment lib.php,1.38,1.39
Brought to you by:
gustav_delius,
npstrick
|
From: <gus...@us...> - 2003-10-27 16:10:12
|
Update of /cvsroot/aimmath/moodle/mod/math_assignment
In directory sc8-pr-cvs1:/tmp/cvs-serv22210/mod/math_assignment
Modified Files:
lib.php
Log Message:
removed a complicated regular expression search that managed to crash apache
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/lib.php,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** lib.php 20 Oct 2003 03:02:56 -0000 1.38
--- lib.php 27 Oct 2003 16:10:08 -0000 1.39
***************
*** 463,487 ****
/// Function which checks an AiM page to see if AiM has thrown an error from which we can recover
- /*
- // remove everything up to and including the html tag
- if (!preg_match("/<html(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE))
- return false; // no HTML data found
- $data = substr($data, $matches[0][1]);
-
- // seach for a head tag
- if (preg_match("/<head(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE)) {
- // we have a head section
- $data = substr($data, $matches[0][1] + strlen($matches[0][0]));
-
- // check for user not registered error
- if (preg_match("/<title>(.*)\bNot registered\b(.*)<\/title>/si", $data))
- return 1;
-
- // --- further checks returning different error codes to go here as required ---
-
- }
- return 0;
- */
-
if (strpos($data,"<html") === false)
return false; // no HTML data found;
--- 463,466 ----
***************
*** 627,698 ****
$grade = -1;
$max_grade = -1;
- $error = false;
-
- /*
- // remove everything up to and including the html tag
- if (!preg_match("/<html(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE))
- return ""; // no HTML data found
- $data = substr($data, $matches[0][1]);
-
- $data = preg_replace("/^[\s\S]*<html(?:\s[^<>]*?|)>/i", "", $data);
-
- // seach for a head tag
- if (preg_match("/<head(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE)) {
- // we have a head section
- $data = substr($data, $matches[0][1] + strlen($matches[0][0]));
-
- // check for error pages
- if (preg_match("/<title>(.*)\bError\b(.*)<\/title>/si", $data)) {
- $error = true;
- }
-
- // remove head but look out for scripts
- while (true) {
-
- if (!preg_match("/<\/head>|<script(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE))
- return ""; // head never ends
- $data = substr($data, $matches[0][1]);
- if (strcasecmp($matches[0][0], "</head>") == 0) {
- $data = substr($data, 7);
- break;
- }
-
- // we have found a script - extract it
- if (!preg_match("/<\/script>/i", $data, $matches, PREG_OFFSET_CAPTURE))
- return ""; // unterminated script
- $out .= substr($data, 0, $matches[0][1] + 9);
- $data = substr($data, $matches[0][1] + 9);
- }
- }
-
- // search for body tag
- if(!preg_match("/<body(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE))
- return ""; // no body found
- $data = substr($data, $matches[0][1] + strlen($matches[0][0]));
-
- // search for end of body
- if(!preg_match("/<\/body>/i", $data, $matches, PREG_OFFSET_CAPTURE))
- return ""; // unterminated body
- $data = substr($data, 0, $matches[0][1]);
-
- $out .= $data; // add body to output (NOTE that this means we can modify $data now)
-
- if (!$error) {
- // extract grades (if present)
- if (preg_match("/<table(?:\s[^<>]*?|)\sclass=(\"|'|)marktable\\1(?:\s[^<>]*?|)>/i", $data, $matches, PREG_OFFSET_CAPTURE)) {
- $data = substr($data, $matches[0][1] + strlen($matches[0][0]));
- if (preg_match("/<\/table>/i", $data, $matches, PREG_OFFSET_CAPTURE)) {
- $data = substr($data, 0, $matches[0][1]);
- // find the row which gives the totals
- if (preg_match("/<td(?:\s[^<>]*?|)>Total<\/td>(?:.(?!<td\s|<td>))*.?<td(?:\s[^<>]*?|)>((?:.(?!<\/td>))*?.?)<\/td>(?:.(?!<td\s|<td>))*.?<td(?:\s[^<>]*?|)>((?:.(?!<\/td>))*?.?)<\/td>/si", $data, $matches)) {
- if (empty($CFG->math_assignment_grade_multiplier))
- $CFG->math_assignment_grade_multiplier = 1.0;
- $max_grade = (int) (((float) decodeHTML($matches[1])) * ((float) $CFG->math_assignment_grade_multiplier));
- $grade = (int) (((float) decodeHTML($matches[2])) * ((float) $CFG->math_assignment_grade_multiplier));
- }
- }
- }
- }
- */
// extract scripts and add to $out
--- 606,609 ----
***************
*** 722,728 ****
// Remove unwanted links
$unwanted = array(">Download<",">Browse source<",">Edit home page<",">Download results<",
! ">Edit register<",">Student details<",">Hide hidden quizzes<",">Hide hidden questions<");
$out = str_replace($unwanted,"><",$out);
!
// covert the URLs
if ($old_url) {
--- 633,644 ----
// Remove unwanted links
$unwanted = array(">Download<",">Browse source<",">Edit home page<",">Download results<",
! ">Edit register<",">Student details<",">Hide hidden quizzes<",">Hide hidden questions<",
! ">New Quiz<");
$out = str_replace($unwanted,"><",$out);
!
! // Remove unwanted text
! $unwanted = array('Click here to select a new quiz.');
! $out = str_replace($unwanted,'',$out);
!
// covert the URLs
if ($old_url) {
***************
*** 745,787 ****
$out = preg_replace("/<td(?:\s[^<>]*?|)>(?:\s|<\!--(?:.(?!-->))*.?-->)*<a(?:\s[^<>]*?|)\shref=\"javascript:close\(\)\">(?:.(?!<\/a>))*?.?<\/a>(?:\s|<\!--(?:.(?!-->))*.?-->)*<\/td>/si", "", $out);
$out = preg_replace("/<a(?:\s[^<>]*?|)\shref=\"javascript:close\(\)\">(?:.(?!<\/a>))*?.?<\/a>/si", "", $out);
// make help links open in a new window
$out = preg_replace("/<a(?:\s[^<>]*?|)\shref=(\"|'|)([^\"<>]*)\/help.html\\1(\s[^<>]*?|)>Help<\/a>/i", "<a href=\"\\2/help.html\"\\3 target=\"_popup\">Help</a>", $out);
// remove new quiz links
$out = preg_replace("/<tr(?:\s[^<>]*?|)>(?:.(?!<td\s|<td>))*?.?<td(?:\s[^<>]*?|)>(?:\s|<\!--(?:.(?!-->))*.?-->)*<a(?:\s[^<>]*?|)\shref=(?(?=\")\"[^\"<>]*?\"(?=\W)|\S*?)>New Quiz<\/a>(?:\s|<\!--(?:.(?!-->))*.?-->)*<\/td>(.(?!<td\s|<td>))*?.?<td(?:\s[^<>]*?|)>(.(?!<\/td>))*?.?<\/td>(.(?!<\/tr>))*?.?<\/tr>/si", "", $out);
$out = preg_replace("/<a(?:\s[^<>]*?|)\shref=[^<>]*>New Quiz<\/a>/i", "", $out);
-
- /*
- // modify download links
- $commonpostdata = "";
- $commonpostdata = math_assignment_add_arg_to_url_data($commonpostdata, "SubjectName", $subject->name);
- $commonpostdata = math_assignment_add_arg_to_url_data($commonpostdata, "QuizName", $math_assignment->aimquiz);
- $commonpostdata = math_assignment_add_arg_to_url_data($commonpostdata, "Password", $subject->password);
- // modify download quiz links
- $postdata = math_assignment_add_arg_to_url_data($commonpostdata, "Command", "analyze/Quiz");
- $postdata = math_assignment_add_arg_to_url_data($postdata, "Action", "DownloadQuiz");
- $out = preg_replace("/javascript:DownloadQuiz\(\);/i", htmlspecialchars("$old_url?$postdata"), $out);
- // modify download register links
- $postdata = math_assignment_add_arg_to_url_data($commonpostdata, "Command", "admin/Register");
- $postdata = math_assignment_add_arg_to_url_data($postdata, "Action", "DownloadRegister");
- $out = preg_replace("/javascript:DownloadRegister\(\);/i", htmlspecialchars("$old_url?$postdata"), $out);
- // modify download source links
- $postdata = math_assignment_add_arg_to_url_data($commonpostdata, "Command", "admin/SourceFile");
- $postdata = math_assignment_add_arg_to_url_data($postdata, "Action", "DownloadSource");
- $postdata = math_assignment_add_arg_to_url_data($postdata, "SourceFile", "");
- $out = preg_replace("/javascript:DownloadSource\(('|\")([^()]*?)\\1\);/i", htmlspecialchars("$old_url?$postdata=\\2"), $out);
- if (array_key_exists("SourceFile", $_POST)) {
- $postdata = math_assignment_add_arg_to_url_data($commonpostdata, "Command", "admin/SourceFile");
- $postdata = math_assignment_add_arg_to_url_data($postdata, "Action", "DownloadSource");
- $postdata = math_assignment_add_arg_to_url_data($postdata, "SourceFile", $_POST['SourceFile']);
- $out = preg_replace("/javascript:DownloadSource\(\);/i", htmlspecialchars("$old_url?$postdata"), $out);
- }
- unset($commonpostdata);
-
- // remove styles (as we haven't loaded the AiM stylesheet)
- $out = preg_replace("/<div(?:\s[^<>]*?|)>/i", "", $out);
- $out = preg_replace("/<\/div>/i", "", $out);
- $out = preg_replace("/<span(?:\s[^<>]*?|)>/i", "", $out);
- $out = preg_replace("/<\/span>/i", "", $out);
- $out = preg_replace("/(?<=<)(\w*(?:\s[^<>]*?|))\sclass=(?(?=\")\"[^\"<>]*?\"(?=\W)|\S*?(?=>))/i", "\\1", $out);
*/
--- 661,671 ----
$out = preg_replace("/<td(?:\s[^<>]*?|)>(?:\s|<\!--(?:.(?!-->))*.?-->)*<a(?:\s[^<>]*?|)\shref=\"javascript:close\(\)\">(?:.(?!<\/a>))*?.?<\/a>(?:\s|<\!--(?:.(?!-->))*.?-->)*<\/td>/si", "", $out);
$out = preg_replace("/<a(?:\s[^<>]*?|)\shref=\"javascript:close\(\)\">(?:.(?!<\/a>))*?.?<\/a>/si", "", $out);
+
// make help links open in a new window
$out = preg_replace("/<a(?:\s[^<>]*?|)\shref=(\"|'|)([^\"<>]*)\/help.html\\1(\s[^<>]*?|)>Help<\/a>/i", "<a href=\"\\2/help.html\"\\3 target=\"_popup\">Help</a>", $out);
+ /*
// remove new quiz links
$out = preg_replace("/<tr(?:\s[^<>]*?|)>(?:.(?!<td\s|<td>))*?.?<td(?:\s[^<>]*?|)>(?:\s|<\!--(?:.(?!-->))*.?-->)*<a(?:\s[^<>]*?|)\shref=(?(?=\")\"[^\"<>]*?\"(?=\W)|\S*?)>New Quiz<\/a>(?:\s|<\!--(?:.(?!-->))*.?-->)*<\/td>(.(?!<td\s|<td>))*?.?<td(?:\s[^<>]*?|)>(.(?!<\/td>))*?.?<\/td>(.(?!<\/tr>))*?.?<\/tr>/si", "", $out);
$out = preg_replace("/<a(?:\s[^<>]*?|)\shref=[^<>]*>New Quiz<\/a>/i", "", $out);
*/
***************
*** 800,808 ****
if (function_exists('editer') && $convertlatex) {
$out = preg_replace_callback("/<latex>(.*?)<\/latex>/si", create_function('$matches', 'return tex_to_mathml($matches[1]);'), $out);
- }
-
- // remove all links from error pages
- if ($error) {
- $out = preg_replace("/<a(?:\s[^<>]*?|)>(?:.(?!<\/a>))*?.?<\/a>/si", "", $out);
}
--- 684,687 ----
|