3 $sysdebug_ignored = forge_get_config('sysdebug_ignored');
5 // error handler function
6 function ffErrorHandler($errno, $errstr, $errfile, $errline)
8 global $ffErrors, $sysdebug_ignored;
10 if ($sysdebug_ignored && error_reporting() == 0)
11 /* prepended @ to statement => ignore */
14 if (!isset($ffErrors))
17 $msg = "[$errno] $errstr ($errfile at $errline)";
19 // Display messages only once.
20 foreach ($ffErrors as $m) {
21 if ($m['message'] == $msg)
42 case E_USER_DEPRECATED:
52 $ffErrors[] = array('type' => $type, 'message' => $msg);
53 /* Don't execute PHP internal error handler */
58 function ffOutputHandler($buffer) {
59 global $ffErrors, $gfcommon;
61 /* stop calling ffErrorHandler */
62 restore_error_handler();
64 $dtdpath = $gfcommon . 'include/';
65 // this is, sadly, necessary (especially in ff-plugin-mediawiki)
66 $pre_tag = "<pre style=\"margin:0; padding:0; border:0;\">";
68 if (!isset($ffErrors))
71 $divstring = "\n\n" . '<script type="text/javascript"><!-- <![CDATA[
72 function toggle_ffErrors() {
73 var errorsblock = document.getElementById("ffErrorsBlock");
74 if (errorsblock.style.display == "none") {
75 errorsblock.style.display = "block";
77 errorsblock.style.display = "none";
79 }' . "\n//]]> --></script>\n<div id=\"ffErrors\">\n" .
80 '<a href="javascript:toggle_ffErrors();">Click to toggle</a>' .
81 "\n<div id=\"ffErrorsBlock\">";
83 /* cut off </body></html> (hopefully only) at the end */
84 $buffer = rtrim($buffer); /* spaces, newlines, etc. */
85 if (substr($buffer, -strlen("</html>")) != "</html>") {
86 $ffErrors[] = array('type' => "error",
87 'message' => htmlentities("does not end with </html> tag"));
88 $buffer = str_ireplace("</html>", "", $buffer);
90 $buffer = substr($buffer, 0, -strlen("</html>"));
91 $buffer = rtrim($buffer); /* spaces, newlines, etc. */
92 if (substr($buffer, -strlen("</body>")) != "</body>") {
93 $ffErrors[] = array('type' => "error",
94 'message' => htmlentities("does not end with </body> tag"));
95 $buffer = str_ireplace("</body>", "", $buffer);
97 $buffer = substr($buffer, 0, -strlen("</body>"));
98 $buffer = rtrim($buffer); /* spaces, newlines, etc. */
100 /* append errors, if any */
102 foreach ($ffErrors as $msg) {
104 $buffer .= $divstring;
107 $buffer .= "\n <div class=\"" . $msg['type'] . '">' .
108 $msg['message'] . "</div>";
111 /* generate buffer for checking */
112 $cbuf = str_ireplace('http://www.w3.org/TR/xhtml1/DTD/',
113 'file://' . $dtdpath, $buffer);
115 $cbuf .= "\n</div></div>";
116 $cbuf .= "\n</body></html>\n";
118 /* now check XHTML validity… two means */
122 if (forge_get_config('sysdebug_xmlstarlet')) {
123 /* xmlstarlet (well-formed, DTD and DOCTYPE, encoding */
125 0 => array("pipe", "r"),
126 1 => array("pipe", "w"),
127 2 => array("pipe", "w"),
129 $xmlstarlet = proc_open("xmlstarlet val -d " .
130 escapeshellarg($dtdpath . 'xhtml1-transitional.dtd') .
131 " -", $dspec, $pipes);
133 if (is_resource($xmlstarlet)) {
134 fwrite($pipes[0], $cbuf);
136 $sout = stream_get_contents($pipes[1]);
137 $serr = stream_get_contents($pipes[2]);
140 $rv = proc_close($xmlstarlet);
143 'msg' => "could not run xmlstarlet"
147 'msg' => "xmlstarlet found that this document is not valid (errorlevel $rv)!",
148 'extra' => $pre_tag . htmlspecialchars(trim($serr .
149 "\n\n" . $sout)) . "</pre>",
156 $sysdebug_akelos = forge_get_config('sysdebug_akelos');
157 if ($sysdebug_akelos) {
158 /* Akelos XHTML Validator (most other stuff) */
159 require_once($gfcommon . "include/XhtmlValidator.php");
160 $XhtmlValidator = new XhtmlValidator();
161 $sbuf = explode("<html", $cbuf, 2);
162 $sbuf[1] = "<html" . $sbuf[1];
164 if ($XhtmlValidator->validate($vbuf) === false) {
165 //$vbuf = $XhtmlValidator->highlightErrors($sbuf[1]);
166 $errs = '<ul><li>' . join("</li>\n<li>",
167 $XhtmlValidator->getErrors()) . '</li></ul>';
169 'msg' => "Akelos XHTML Validator found some errors on this document!",
177 /* append XHTML source code, if validation failed */
179 if (!$sysdebug_akelos || $vbuf == $sbuf[1])
180 $vbuf = "<ol><li>" . $pre_tag . join("</pre></li>\n<li>" . $pre_tag, explode("\n", htmlentities(rtrim($cbuf)))) . "</pre></li></ol>";
182 $vbuf = $pre_tag . htmlentities(rtrim($sbuf[0])) . "</pre>" . $vbuf;
184 'msg' => "Since XHTML validation failed, here’s the checked document for you to look at:",
190 /* append error messages from the validators */
191 foreach ($valck as $msg) {
193 $buffer .= $divstring;
196 $buffer .= "\n <div class=\"" . $msg['type'] . '">' . $msg['msg'];
197 if (isset($msg['extra']))
198 $buffer .= "\n <div style=\"font-weight:normal; font-size:90%; color:#333333;\">" .
199 $msg['extra'] . "</div>\n ";
203 /* return final buffer */
205 $buffer .= "\n</div></div>";
206 return ($buffer . "\n</body></html>\n");
209 if (forge_get_config('sysdebug_phphandler')) {
210 // set to the user defined error handler
211 set_error_handler("ffErrorHandler");
214 ob_start("ffOutputHandler", 0, false);