Exemple #1
0
 function htmlDiff($from, $to)
 {
     // Create an XML parser
     $xml_parser = xml_parser_create('');
     $domfrom = new DomTreeBuilder();
     // Set the functions to handle opening and closing tags
     xml_set_element_handler($xml_parser, array($domfrom, "startElement"), array($domfrom, "endElement"));
     // Set the function to handle blocks of character data
     xml_set_character_data_handler($xml_parser, array($domfrom, "characters"));
     HTMLDiffer::diffDebug("Parsing " . strlen($from) . " characters worth of HTML\n");
     if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>' . Sanitizer::hackDocType() . '<body>', false) || !xml_parse($xml_parser, $from, false) || !xml_parse($xml_parser, '</body>', true)) {
         $error = xml_error_string(xml_get_error_code($xml_parser));
         $line = xml_get_current_line_number($xml_parser);
         $col = xml_get_current_column_number($xml_parser);
         HTMLDiffer::diffDebug("XML error: {$error} at line {$line} and column {$col}\n");
     }
     xml_parser_free($xml_parser);
     unset($from);
     $xml_parser = xml_parser_create('');
     $domto = new DomTreeBuilder();
     // Set the functions to handle opening and closing tags
     xml_set_element_handler($xml_parser, array($domto, "startElement"), array($domto, "endElement"));
     // Set the function to handle blocks of character data
     xml_set_character_data_handler($xml_parser, array($domto, "characters"));
     HTMLDiffer::diffDebug("Parsing " . strlen($to) . " characters worth of HTML\n");
     if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>' . Sanitizer::hackDocType() . '<body>', false) || !xml_parse($xml_parser, $to, false) || !xml_parse($xml_parser, '</body>', true)) {
         $error = xml_error_string(xml_get_error_code($xml_parser));
         $line = xml_get_current_line_number($xml_parser);
         $col = xml_get_current_column_number($xml_parser);
         HTMLDiffer::diffDebug("XML error: {$error} at line {$line} and column {$col}\n");
     }
     xml_parser_free($xml_parser);
     unset($to);
     $diffengine = new WikiDiff3();
     $differences = $this->preProcess($diffengine->diff_range($domfrom->getDiffLines(), $domto->getDiffLines()));
     unset($xml_parser, $diffengine);
     $textNodeDiffer = new TextNodeDiffer($domto, $domfrom);
     $currentIndexLeft = 0;
     $currentIndexRight = 0;
     foreach ($differences as &$d) {
         if ($d->leftstart > $currentIndexLeft) {
             $textNodeDiffer->handlePossibleChangedPart($currentIndexLeft, $d->leftstart, $currentIndexRight, $d->rightstart);
         }
         if ($d->leftlength > 0) {
             $textNodeDiffer->markAsDeleted($d->leftstart, $d->leftend, $d->rightstart);
         }
         $textNodeDiffer->markAsNew($d->rightstart, $d->rightend);
         $currentIndexLeft = $d->leftend;
         $currentIndexRight = $d->rightend;
     }
     $oldLength = $textNodeDiffer->lengthOld();
     if ($currentIndexLeft < $oldLength) {
         $textNodeDiffer->handlePossibleChangedPart($currentIndexLeft, $oldLength, $currentIndexRight, $textNodeDiffer->lengthNew());
     }
     $textNodeDiffer->expandWhiteSpace();
     $output = new HTMLOutput('htmldiff');
     return $output->parse($textNodeDiffer->bodyNode);
 }
Exemple #2
0
function _dump($mixed)
{
    //Array
    if (is_array($mixed)) {
        $arrKeys = array_keys($mixed);
        $rtn = "";
        $rtn .= HTMLOutput::getStyle("array", "#669900", "#99cc00", "#263300");
        $rtn .= HTMLOutput::getHead("array", "Array");
        for ($i = 0; $i < count($arrKeys); $i++) {
            $rtn .= HTMLOutput::getItem("array", $arrKeys[$i], _dump($mixed[$arrKeys[$i]]));
        }
        $rtn .= HTMLOutput::getBottom();
        return $rtn;
    } else {
        if (is_object($mixed) && method_exists($mixed, "dump")) {
            return $mixed->dump();
        } else {
            if (is_object($mixed)) {
                $className = get_class($mixed);
                $vars = get_class_vars($className);
                $methods = get_class_methods($mixed);
                $rtn = "";
                $rtn .= HTMLOutput::getStyle("object", "#b09300", "#f0cc02", "#3f3100");
                $rtn .= HTMLOutput::getHead("object", $className);
                // vars
                /*$rtn.= HTMLOutput::getBigRow("object","Vars(s)");
                		if($vars)
                		for($i=0;$i<count($vars);$i++)	{
                			$rtn.= HTMLOutput::getItem("object","String", $vars[$i]);
                		}*/
                // methods
                //$rtn.= HTMLOutput::getBigRow("object","Method(s)");
                for ($i = 0; $i < count($methods); $i++) {
                    $rtn .= HTMLOutput::getRow("object", $methods[$i] . "()");
                }
                $rtn .= HTMLOutput::getBottom();
                return $rtn;
            } else {
                if (is_bool($mixed)) {
                    $rtn = "";
                    $rtn .= HTMLOutput::getStyle("simple", "#ff4400", "#ff954f", "#4f1500");
                    $rtn .= HTMLOutput::smallHead("simple");
                    $rtn .= HTMLOutput::getItem("simple", "boolean", $mixed ? "yes" : "no");
                    $rtn .= HTMLOutput::getBottom();
                    return $rtn;
                } else {
                    if (is_numeric($mixed)) {
                        $rtn = "";
                        $rtn .= HTMLOutput::getStyle("simple", "#ff4400", "#ff954f", "#4f1500");
                        $rtn .= HTMLOutput::smallHead("simple");
                        $rtn .= HTMLOutput::getItem("simple", "numeric", $mixed);
                        $rtn .= HTMLOutput::getBottom();
                        return $rtn;
                    } else {
                        $rtn = "";
                        $rtn .= HTMLOutput::getStyle("simple", "#ff4400", "#ff954f", "#4f1500");
                        $rtn .= HTMLOutput::smallHead("simple");
                        $rtn .= HTMLOutput::getItem("simple", "String", $mixed);
                        $rtn .= HTMLOutput::getBottom();
                        return $rtn;
                    }
                }
            }
        }
    }
}