/** * Return the difference between two HTML documents. * @param String $a The first HTML document * @param String $b The second HTML document * @param Boolean $describe_formatting_changes If true, changes in the formatting (for example adding a certain HTML attribute * to a tag) are shown in text form. * @return String An HTML document that represents the difference between the two HTML documents by assigning the class names * diff-html-added and diff-html-removed to the changed elements. */ function html_diff($a, $b, $describe_formatting_changes = false) { $out = new ChangeText(); $htmldiffer = new HTMLDiffer(new DelegatingContentHandler($out)); $htmldiffer->htmlDiff($a, $b, $describe_formatting_changes); return $out->toString(); }
public function diffVersionsAction() { include_once 'DaisyDiff/HTMLDiff.php'; include_once 'simple_html_dom.php'; $versionFrom = Version::getById($this->_getParam("from")); $versionTo = Version::getById($this->_getParam("to")); $docFrom = $versionFrom->loadData(); $docTo = $versionTo->loadData(); // unlock the current session to access the version files session_write_close(); $request = $this->getRequest(); $fromSource = file_get_html($request->getScheme() . "://" . $request->getHttpHost() . $docFrom->getFullPath() . "?pimcore_version=" . $this->_getParam("from") . "&pimcore_admin_sid=" . $_COOKIE["pimcore_admin_sid"]); $toSource = file_get_html($request->getScheme() . "://" . $request->getHttpHost() . $docTo->getFullPath() . "?pimcore_version=" . $this->_getParam("to") . "&pimcore_admin_sid=" . $_COOKIE["pimcore_admin_sid"]); if ($docFrom instanceof Document_Page) { $from = $fromSource->find("body", 0); $to = $toSource->find("body", 0); } else { $from = $fromSource; $to = $toSource; } $diff = new HTMLDiffer(); $text = $diff->htmlDiff($from, $to); if ($docFrom instanceof Document_Page) { $fromSource->find("head", 0)->innertext = $fromSource->find("head", 0)->innertext . '<link rel="stylesheet" type="text/css" href="/pimcore/static/css/daisydiff.css" />'; $fromSource->find("body", 0)->innertext = $text; echo $fromSource; } else { echo '<link rel="stylesheet" type="text/css" href="/pimcore/static/css/daisydiff.css" />'; echo $text; } $this->removeViewRenderer(); }
function renderHtmlDiff() { global $wgOut, $wgTitle, $wgParser, $wgDebugComments; wfProfileIn(__METHOD__); $this->showDiffStyle(); $wgOut->addHTML('<h2>' . wfMsgHtml('visual-comparison') . "</h2>\n"); #add deleted rev tag if needed if (!$this->mNewRev->userCan(Revision::DELETED_TEXT)) { $wgOut->wrapWikiMsg("<div class='mw-warning plainlinks'>\n\$1</div>\n", 'rev-deleted-text-permission'); } else { if ($this->mNewRev->isDeleted(Revision::DELETED_TEXT)) { $wgOut->wrapWikiMsg("<div class='mw-warning plainlinks'>\n\$1</div>\n", 'rev-deleted-text-view'); } } if (!$this->mNewRev->isCurrent()) { $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection(false); } $this->loadText(); // Old revision if (is_object($this->mOldRev)) { $wgOut->setRevisionId($this->mOldRev->getId()); } $popts = $wgOut->parserOptions(); $oldTidy = $popts->setTidy(true); $popts->setEditSection(false); $parserOutput = $wgParser->parse($this->mOldtext, $wgTitle, $popts, true, true, $wgOut->getRevisionId()); $popts->setTidy($oldTidy); //only for new? //$wgOut->addParserOutputNoText( $parserOutput ); $oldHtml = $parserOutput->getText(); wfRunHooks('OutputPageBeforeHTML', array(&$wgOut, &$oldHtml)); // New revision if (is_object($this->mNewRev)) { $wgOut->setRevisionId($this->mNewRev->getId()); } $popts = $wgOut->parserOptions(); $oldTidy = $popts->setTidy(true); $parserOutput = $wgParser->parse($this->mNewtext, $wgTitle, $popts, true, true, $wgOut->getRevisionId()); $popts->setTidy($oldTidy); $wgOut->addParserOutputNoText($parserOutput); $newHtml = $parserOutput->getText(); wfRunHooks('OutputPageBeforeHTML', array(&$wgOut, &$newHtml)); unset($parserOutput, $popts); $differ = new HTMLDiffer(new DelegatingContentHandler($wgOut)); $differ->htmlDiff($oldHtml, $newHtml); if ($wgDebugComments) { $wgOut->addHTML("\n<!-- HtmlDiff Debug Output:\n" . HTMLDiffer::getDebugOutput() . " End Debug -->"); } wfProfileOut(__METHOD__); }
// else display template with versions to select if ($args->doCompare) { // Side By Side $sbs = getItemsToCompare($args->left_item_id, $args->right_item_id, $gui->items); prepareUserFeedback($db, $gui, $args->req_spec_id, $labels, $sbs); $gui->attrDiff = getAttrDiff($sbs['left_item'], $sbs['right_item'], $labels); $cfields = getCFToCompare($sbs, $args->tproject_id, $itemMgr); $gui->cfieldsDiff = null; if (!is_null($cfields)) { $gui->cfieldsDiff = getCFDiff($cfields, $itemMgr); } $gui->diff = array("scope" => array()); foreach ($gui->diff as $key => $val) { if ($args->useDaisyDiff) { $diff = new HTMLDiffer(); list($differences, $diffcount) = $diff->htmlDiff($sbs['left_item'][$key], $sbs['right_item'][$key]); $gui->diff[$key]["diff"] = $differences; $gui->diff[$key]["count"] = $diffcount; } else { // insert line endings so diff is better readable and makes sense (not everything in one line) // then cast to array with \n as separating character, differ needs that $gui->diff[$key]["left"] = explode("\n", str_replace("</p>", "</p>\n", $sbs['left_item'][$key])); $gui->diff[$key]["right"] = explode("\n", str_replace("</p>", "</p>\n", $sbs['right_item'][$key])); $gui->diff[$key]["diff"] = $differ->inline($gui->diff[$key]["left"], $gui->leftID, $gui->diff[$key]["right"], $gui->rightID, $args->context); $gui->diff[$key]["count"] = count($differ->changes); } $gui->diff[$key]["heading"] = lang_get($key); // are there any changes? then display! if not, nothing to show here $additional = ''; $msg_key = "no_changes"; if ($gui->diff[$key]["count"] > 0) {
<?php require_once 'Xml.php'; require_once 'Sanitizer.php'; require_once 'Diff.php'; require_once 'DifferenceEngine.php'; require_once 'Nodes.php'; require_once 'HTMLDiff.php'; function wfProfileIn($method) { } function wfProfileOut($method) { } class ContentHandler { var $output = ''; function addHtml($html) { $this->output .= $html; } } $from = getenv('from'); $to = getenv('to'); $handler = new ContentHandler(); $differ = new HTMLDiffer(new DelegatingContentHandler($handler)); $differ->htmlDiff($from, $to); echo $handler->output;
$results = ""; foreach ($right['steps'] as $step) { $steps .= str_replace("</p>", "</p>\n", $step['actions']); $results .= str_replace("</p>", "</p>\n", $step['expected_results']); } $diff_array["steps"]["right"] = $steps; $diff_array["expected_results"]["right"] = $results; } foreach ($diff_array as $key => $val) { // 20110107 - new diff engine $localized_key = lang_get($key); $gui->diff[$key]["count"] = 0; if ($args->use_daisydiff) { // using daisydiff as diffing engine $diff = new HTMLDiffer(); list($differences, $diffcount) = $diff->htmlDiff($val['left'], $val['right']); $gui->diff[$key]["diff"] = $differences; $gui->diff[$key]["count"] = $diffcount; } else { // insert line endings so diff is better readable and makes sense (not everything in one line) // then cast to array with \n as separating character, differ needs that $gui->diff[$key]["left"] = explode("\n", str_replace("</p>", "</p>\n", $val['left'])); $gui->diff[$key]["right"] = explode("\n", str_replace("</p>", "</p>\n", $val['right'])); $gui->diff[$key]["diff"] = $differ->inline($gui->diff[$key]["left"], $gui->leftID, $gui->diff[$key]["right"], $gui->rightID, $args->context); $gui->diff[$key]["count"] = count($differ->changes); } $gui->diff[$key]["heading"] = $localized_key; //are there any changes? then display! if not, nothing to show here if ($gui->diff[$key]["count"] > 0) { $gui->diff[$key]["message"] = sprintf($labels["num_changes"], $localized_key, $diff_array[$key]["count"]); } else {