function createDifferenceObject($fromData, $toData) { $changes = new eZXMLTextDiff(); $contentINI = eZINI::instance('content.ini'); $useSimplifiedXML = $contentINI->variable('ContentVersionDiffSettings', 'UseSimplifiedXML'); $diffSimplifiedXML = $useSimplifiedXML == 'enabled'; $oldXMLTextObject = $fromData->content(); $newXMLTextObject = $toData->content(); $oldXML = $oldXMLTextObject->attribute('xml_data'); $newXML = $newXMLTextObject->attribute('xml_data'); $simplifiedXML = new eZSimplifiedXMLEditOutput(); $domOld = new DOMDocument('1.0', 'utf-8'); $domOld->preserveWhiteSpace = false; $domOld->loadXML($oldXML); $domNew = new DOMDocument('1.0', 'utf-8'); $domNew->preserveWhiteSpace = false; $domNew->loadXML($newXML); $old = $simplifiedXML->performOutput($domOld); $new = $simplifiedXML->performOutput($domNew); if (!$diffSimplifiedXML) { $old = trim(strip_tags($old)); $new = trim(strip_tags($new)); $pattern = array('/[ ][ ]+/', '/ \\n( \\n)+/', '/^ /m', '/(\\n){3,}/'); $replace = array(' ', "\n", '', "\n\n"); $old = preg_replace($pattern, $replace, $old); $new = preg_replace($pattern, $replace, $new); } $oldArray = explode("\n", $old); $newArray = explode("\n", $new); $oldSums = array(); foreach ($oldArray as $paragraph) { $oldSums[] = crc32($paragraph); } $newSums = array(); foreach ($newArray as $paragraph) { $newSums[] = crc32($paragraph); } $textDiffer = new eZDiffTextEngine(); $pre = $textDiffer->preProcess($oldSums, $newSums); $out = $textDiffer->createOutput($pre, $oldArray, $newArray); $changes->setChanges($out); return $changes; }
function inputXML() { $contentObjectAttribute = $this->ContentObjectAttribute; $contentObjectAttributeID = $contentObjectAttribute->attribute('id'); $originalInput = 'originalInput_' . $contentObjectAttributeID; $isInputValid = 'isInputValid_' . $contentObjectAttributeID; if (isset($GLOBALS[$isInputValid]) and $GLOBALS[$isInputValid] == false) { $output = $GLOBALS[$originalInput]; } else { $dom = new DOMDocument('1.0', 'utf-8'); $success = $dom->loadXML($this->XMLData); $editOutput = new eZSimplifiedXMLEditOutput(); $dom->formatOutput = true; if (eZDebugSetting::isConditionTrue('kernel-datatype-ezxmltext', eZDebug::LEVEL_DEBUG)) { eZDebug::writeDebug($dom->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', __METHOD__ . ' xml string stored in database')); } $output = $editOutput->performOutput($dom); } return $output; }
function outputLink( $element, &$attributes, &$sectionLevel ) { $ret = null; $href = ''; $linkID = isset( $attributes['url_id'] ) ? $attributes['url_id'] : null; $objectID = isset( $attributes['object_id'] ) ? $attributes['object_id'] : null; $nodeID = isset( $attributes['node_id'] ) ? $attributes['node_id'] : null; $anchorName = isset( $attributes['anchor_name'] ) ? $attributes['anchor_name'] : null; $showPath = isset( $attributes['show_path'] ) ? $attributes['show_path'] : null; if ( $objectID ) { $href = 'ezobject://' .$objectID; } elseif ( $nodeID ) { $href = eZSimplifiedXMLEditOutput::eznodeHref( $nodeID, $showPath ); } elseif ( $linkID ) { // Fetch URL from cached array $href = $this->LinkArray[$linkID]; } else { $href = isset( $attributes['href'] ) ? $attributes['href'] : ''; } if ( $anchorName != null ) { $href .= '#' . $anchorName; } $attributes['href'] = $href; return $ret; }