00001 <?php
00002
00027 class reportDemo extends quailReporter {
00028
00032 var $classnames = array(QUAIL_TEST_SEVERE => 'quail_severe',
00033 QUAIL_TEST_MODERATE => 'quail_moderate',
00034 QUAIL_TEST_SUGGESTION => 'quail_suggestion',
00035 );
00036
00042 function getReport() {
00043 $problems = $this->guideline->getReport();
00044 if(is_array($problems)) {
00045 foreach($problems as $testname => $test) {
00046 if(!isset($this->options->display_level) || $this->options->display_level >= $test['severity'] && is_array($test)) {
00047 foreach($test as $k => $problem) {
00048 if(is_object($problem) && property_exists($problem, 'element') && is_object($problem->element)) {
00049 $existing = $problem->element->getAttribute('style');
00050 $problem->element->setAttribute('style',
00051 $existing .'; border: 2px solid red;');
00052 if(isset($this->options->image_url)) {
00053 $image = $this->dom->createElement('img');
00054 $image = $problem->element->parentNode->insertBefore($image, $problem->element);
00055 $image->setAttribute('alt', $testname);
00056 if($problem->message) {
00057 $image->setAttribute('title', $problem->message);
00058 }
00059 $image->setAttribute('src', $this->options->image_url[$test['severity']]);
00060
00061 }
00062
00063 }
00064 }
00065 }
00066 }
00067 }
00068
00069 return $this->completeURLs($this->dom->saveHTML(), implode('/', $this->path));
00070 }
00071
00072
00076 function strnpos($haystack, $needle, $occurance, $pos = 0) {
00077 for ($i = 1; $i <= $occurance; $i++) {
00078 $pos = strpos($haystack, $needle, $pos) + 1;
00079 }
00080 return $pos - 1;
00081 }
00082
00088 function parseURL($url) {
00089
00090 $pattern = "/^(?:(http[s]?):\/\/(?:(.*):(.*)@)?([^\/]+))?((?:[\/])?(?:[^\.]*?)?(?:[\/])?)?(?:([^\/^\.]+)\.([^\?]+))?(?:\?(.+))?$/i";
00091 preg_match($pattern, $url, $matches);
00092
00093 $URI_PARTS["scheme"] = $matches[1];
00094 $URI_PARTS["host"] = $matches[4];
00095 $URI_PARTS["path"] = $matches[5];
00096
00097 return $URI_PARTS;
00098 }
00099
00106 function completeURLs($HTML, $url) {
00107 $URI_PARTS = $this->parseURL($url);
00108 $path = trim($URI_PARTS["path"], "/");
00109 $host_url = trim($URI_PARTS["host"], "/");
00110
00111
00112 $host = $URI_PARTS["scheme"]."://".$host_url."/".$path."/";
00113 $host_no_path = $URI_PARTS["scheme"]."://".$host_url."/";
00114
00115
00116 $HTML = preg_replace('@<META HTTP-EQUIV(.*)URL=/@', "<META HTTP-EQUIV\$1URL=".$_SERVER['PHP_SELF']."?url=".$host_no_path, $HTML);
00117
00118
00119 $host = rtrim($host, '/')."/";
00120
00121
00122 $pattern = "#(?<=\"|'|=)\/\/#";
00123 $HTML = preg_replace($pattern, "http://", $HTML);
00124
00125
00126 $HTML = preg_replace("#\"\/#", "\"".$host, $HTML);
00127
00128
00129 $HTML = preg_replace("#\'\/#", "\'".$host, $HTML);
00130
00131
00132 $HTML = preg_replace("#(src|href|background|action)(=\"|='|=(?!'|\"))\/#i", "\$1\$2".$host_no_path, $HTML);
00133 $HTML = preg_replace("#(href|src|background|action)(=\"|=(?!'|\")|=')(?!http|ftp|https|\"|'|javascript:|mailto:)#i", "\$1\$2".$host, $HTML);
00134
00135
00136 $HTML = preg_replace('/<form.+?action=\s*(["\']?)([^>\s"\']+)\\1[^>]*>/i', "<form action=\"{$_SERVER['PHP_SELF']}\"><input type=\"hidden\" name=\"original_url\" value=\"$2\">", $HTML);
00137
00138
00139 $HTML = preg_replace("#\/(\w*?)\/\.\.\/(.*?)>#ims", "/\$2>", $HTML);
00140
00141
00142 $HTML = preg_replace("#\/\.\/(.*?)>#ims", "/\$1>", $HTML);
00143
00144
00145 if (strpos($HTML, "import url(\"http") == false && (strpos($HTML, "import \"http") == false) && strpos($HTML, "import url(\"www") == false && (strpos($HTML, "import \"www") == false)) {
00146 $pattern = "#import .(.*?).;#ims";
00147 $mainurl = substr($host, 0, $this->strnpos($host, "/", 3));
00148 $replace = "import '".$mainurl."\$1';";
00149 $HTML = preg_replace($pattern, $replace, $HTML);
00150 }
00151
00152 return $HTML;
00153 }
00154
00155 }
00156