/**
  * Test for issue #018737: Regression in eZXMLInputParser::parseAttributes with attr='0'
  *
  * @link http://issues.ez.no/18737
  * @dataProvider providerForIssue18737
  */
 public function testIssue18737( $string, $expected )
 {
     $this->assertEquals(
         $expected,
         $this->parser->parseAttributes( $string )
     );
 }
Ejemplo n.º 2
0
 /**
  * Test for argument parsing with various special characters
  *
  * @dataProvider providerForTestSpecialCharactersAttributeParsing
  */
 public function testSpecialCharactersAttributeParsing( $string, $expected )
 {
     $this->assertEquals(
         $expected,
         $this->parser->parseAttributes( $string )
     );
 }
Ejemplo n.º 3
0
 /**
  * processAttributesBySchema
  * Parses customattributes attribute and splits it into actual
  * custom: xml attributes, passes processing of normal attributes
  * to parent class.
  *
  * @param DOMElement $element
  */
 function processAttributesBySchema($element)
 {
     // custom attributes conversion
     $attr = $element->getAttribute('customattributes');
     if ($attr) {
         $attrArray = explode('attribute_separation', $attr);
         foreach ($attrArray as $attr) {
             if ($attr !== '' && strpos($attr, '|') !== false) {
                 list($attrName, $attrValue) = explode('|', $attr);
                 $element->setAttributeNS('http://ez.no/namespaces/ezpublish3/custom/', 'custom:' . $attrName, $attrValue);
             }
         }
     }
     parent::processAttributesBySchema($element);
 }
Ejemplo n.º 4
0
 function processNewElements($createdElements)
 {
     $debug = eZDebugSetting::isConditionTrue('kernel-datatype-ezxmltext', eZDebug::LEVEL_DEBUG);
     // Call handlers for newly created elements
     foreach ($createdElements as $element) {
         if ($debug) {
             eZDebug::writeDebug('processing new element ' . $element->nodeName, eZDebugSetting::changeLabel('kernel-datatype-ezxmltext'));
         }
         $tmp = null;
         if (!$this->processBySchemaPresence($element)) {
             if ($debug) {
                 eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'xml string after failed processBySchemaPresence for new element ' . $element->nodeName));
             }
             continue;
         }
         if ($debug) {
             eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'xml string after processBySchemaPresence for new element ' . $element->nodeName));
         }
         // Call "Structure handler"
         $this->callOutputHandler('structHandler', $element, $tmp);
         if (!$this->processBySchemaTree($element)) {
             if ($debug) {
                 eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'xml string after failed processBySchemaTree for new element ' . $element->nodeName));
             }
             continue;
         }
         if ($debug) {
             eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'xml string after processBySchemaTree for new element ' . $element->nodeName));
         }
         $tmp2 = null;
         // Call "Publish handler"
         $this->callOutputHandler('publishHandler', $element, $tmp2);
         if ($debug) {
             eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'xml string after callOutputHandler publishHandler for new element ' . $element->nodeName));
         }
         // Process attributes according to the schema
         if ($element->hasAttributes()) {
             if (!$this->XMLSchema->hasAttributes($element)) {
                 eZXMLInputParser::removeAllAttributes($element);
             } else {
                 $this->processAttributesBySchema($element);
             }
         }
     }
 }
Ejemplo n.º 5
0
 function batchInitializeObjectAttributeData($classAttribute)
 {
     $parser = new eZXMLInputParser();
     $doc = $parser->createRootNode();
     $xmlText = eZXMLTextType::domString($doc);
     $db = eZDB::instance();
     $xmlText = "'" . $db->escapeString($xmlText) . "'";
     return array('data_text' => $xmlText);
 }
Ejemplo n.º 6
0
 function handleInlineNode($childNode, $nextLineBreak = false, $prevLineBreak = false)
 {
     $localName = $childNode->localName;
     if ($localName == '') {
         $localName = $childNode->nodeName;
     }
     // Get the real name
     $paragraphContent = '';
     switch ($localName) {
         case "frame":
             $frameContent = "";
             foreach ($childNode->childNodes as $imageNode) {
                 switch ($imageNode->localName) {
                     case "image":
                         $href = ltrim($imageNode->getAttributeNS(self::NAMESPACE_XLINK, 'href'), '#');
                         if (0 < preg_match('@^(?:http://)([^/]+)@i', $href)) {
                             eZDebug::writeDebug("handling http url: {$href}", __METHOD__);
                             $matches = array();
                             if (0 < preg_match('/.*\\/(.*)?/i', $href, $matches)) {
                                 $fileName = $matches[1];
                                 if (false != ($imageData = file_get_contents($href))) {
                                     $href = $this->ImportDir . $fileName;
                                     $fileOut = fopen($href, "wb");
                                     if (fwrite($fileOut, $imageData)) {
                                         eZDebug::writeNotice("External image stored in {$href}", __METHOD__);
                                     } else {
                                         eZDebug::writeError("Could not save file {$href}", __METHOD__);
                                     }
                                     fclose($fileOut);
                                 } else {
                                     eZDebug::writeError("Downloading external image from {$href} has failed, broken link?", __METHOD__);
                                 }
                             } else {
                                 eZDebug::writeError("Could not match filename in {$href}", __METHOD__);
                             }
                         } else {
                             $href = $this->ImportDir . $href;
                         }
                         // Check image name
                         $imageName = $childNode->getAttributeNS(self::NAMESPACE_DRAWING, 'name');
                         if (!$imageName) {
                             // set default image name
                             $imageName = "Imported Image";
                         }
                         $imageSize = "medium";
                         $imageAlignment = "center";
                         // Check image size
                         $imageSize = "large";
                         $pageWidth = 6;
                         $width = $childNode->getAttributeNS(self::NAMESPACE_SVG_COMPATIBLE, 'width');
                         $sizePercentage = $width / $pageWidth * 100;
                         if ($sizePercentage < 80 and $sizePercentage > 30) {
                             $imageSize = 'medium';
                         }
                         if ($sizePercentage <= 30) {
                             $imageSize = 'small';
                         }
                         // Check if image should be set to original
                         $sizeArray = getimagesize($href);
                         if ($imageSize != "small" and $sizeArray[0] < 650) {
                             $imageSize = "original";
                         }
                         $styleName = $childNode->getAttributeNS(self::NAMESPACE_DRAWING, 'style-name');
                         // Check for style definitions
                         $imageAlignment = "center";
                         foreach ($this->AutomaticStyles as $style) {
                             if ($style->nodeType !== XML_ELEMENT_NODE) {
                                 continue;
                             }
                             $tmpStyleName = $style->getAttributeNS(self::NAMESPACE_STYLE, "name");
                             if ($styleName == $tmpStyleName) {
                                 if ($style->childNodes->length == 1) {
                                     $properties = $style->childNodes->item(0);
                                     $alignment = $properties->getAttributeNS(self::NAMESPACE_STYLE, "horizontal-pos");
                                 }
                                 // Check image alignment
                                 switch ($alignment) {
                                     case "left":
                                         $imageAlignment = "left";
                                         break;
                                     case "right":
                                         $imageAlignment = "right";
                                         break;
                                     default:
                                         $imageAlignment = "center";
                                         break;
                                 }
                                 break;
                             }
                         }
                         if (file_exists($href)) {
                             // Calculate RemoteID based on image md5:
                             $remoteID = "ezoo-" . md5(file_get_contents($href));
                             /*
                                                             // Check if an image with the same remote ID already exists
                                                             $db = eZDB::instance();
                                                             $imageParentNodeID = $GLOBALS["OOImportObjectID"];
                                                             $resultArray = $db->arrayQuery( 'SELECT id, node_id, ezcontentobject.remote_id
                                                                                              FROM  ezcontentobject, ezcontentobject_tree
                                                                                              WHERE ezcontentobject.remote_id = "' . $remoteID. '" AND
                                                                                                    ezcontentobject.id=ezcontentobject_tree.contentobject_id AND
                                                                                                    ezcontentobject_tree.parent_node_id=' . $imageParentNodeID );
                                                             $contentObject = false;
                                                             if ( count( $resultArray ) >= 1 )
                                                             {
                                                                 $contentObject = eZContentObject::fetch( $resultArray[0]['id'], true );
                                                                 $contentObjectID = $resultArray[0]['id'];
                                                             }
                             */
                             $contentObject = eZContentObject::fetchByRemoteID($remoteID);
                             // If image does not already exist, create it as an object
                             if (!$contentObject) {
                                 // Import image
                                 $ooINI = eZINI::instance('odf.ini');
                                 $imageClassIdentifier = $ooINI->variable("ODFImport", "DefaultImportImageClass");
                                 $class = eZContentClass::fetchByIdentifier($imageClassIdentifier);
                                 $creatorID = $this->currentUserID;
                                 $contentObject = $class->instantiate($creatorID, 1);
                                 $contentObject->setAttribute("remote_id", $remoteID);
                                 $contentObject->store();
                                 $version = $contentObject->version(1);
                                 $version->setAttribute('modified', eZDateTime::currentTimeStamp());
                                 $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
                                 $version->store();
                                 $contentObjectID = $contentObject->attribute('id');
                                 $dataMap = $contentObject->dataMap();
                                 // set image name
                                 $dataMap['name']->setAttribute('data_text', $imageName);
                                 $dataMap['name']->store();
                                 // set image caption
                                 if (isset($dataMap['caption'])) {
                                     $captionContentAttibute = $dataMap['caption'];
                                     $captionText = "{$imageName}";
                                     // create new xml for caption
                                     $xmlInputParser = new eZXMLInputParser();
                                     $dom = $xmlInputParser->createRootNode();
                                     $captionNode = $dom->createElement('paragraph', $captionText);
                                     $dom->documentElement->appendChild($captionNode);
                                     $xmlString = $dom->saveXML();
                                     $captionContentAttibute->setAttribute('data_text', $xmlString);
                                     $captionContentAttibute->store();
                                 } else {
                                     eZDebug::writeWarning("The image class does not have 'caption' attribute", 'ODF import');
                                 }
                                 // set image
                                 $imageContent = $dataMap['image']->attribute('content');
                                 //echo "Initializing Image from $href<br />";
                                 $imageContent->initializeFromFile($href, false, basename($href));
                                 $dataMap['image']->store();
                             } else {
                                 $contentObjectID = $contentObject->attribute('id');
                             }
                             $this->RelatedImageArray[] = array("ID" => $contentObjectID, "ContentObject" => $contentObject);
                             $frameContent .= "<embed object_id='{$contentObjectID}' align='{$imageAlignment}' size='{$imageSize}' />";
                         }
                         break;
                 }
             }
             // Textboxes are defined inside paragraphs.
             $paragraphContent .= "{$frameContent}";
             break;
         case "text-box":
             foreach ($childNode->childNodes as $textBoxNode) {
                 $boxContent .= self::handleNode($textBoxNode, $sectionLevel);
             }
             // Textboxes are defined inside paragraphs.
             $paragraphContent .= "</paragraph>{$boxContent}<paragraph>";
             break;
         case 'sequence':
         case 'date':
         case 'initial-creator':
             $paragraphContent .= $childNode->textContent;
             break;
         case "s":
             $paragraphContent .= " ";
             break;
         case "a":
             $href = $childNode->getAttributeNS(self::NAMESPACE_XLINK, 'href');
             $paragraphContent .= "<link href='{$href}'>" . $childNode->textContent . "</link>";
             break;
         case "#text":
             $tagContent = str_replace("&", "&amp;", $childNode->textContent);
             $tagContent = str_replace(">", "&gt;", $tagContent);
             $tagContent = str_replace("<", "&lt;", $tagContent);
             $tagContent = str_replace("'", "&apos;", $tagContent);
             $tagContent = str_replace('"', "&quot;", $tagContent);
             $paragraphContent .= $tagContent;
             break;
         case "span":
             // Fetch the style from the span
             $styleName = $childNode->getAttributeNS(self::NAMESPACE_TEXT, 'style-name');
             // Check for bold and italic styles
             $fontWeight = false;
             $fontStyle = false;
             foreach ($this->AutomaticStyles as $style) {
                 if ($style->nodeType !== XML_ELEMENT_NODE) {
                     continue;
                 }
                 $tmpStyleName = $style->getAttributeNS(self::NAMESPACE_STYLE, "name");
                 if ($styleName == $tmpStyleName) {
                     if ($style->childNodes->length >= 1) {
                         foreach ($style->childNodes as $styleChild) {
                             if ($styleChild->nodeType !== XML_ELEMENT_NODE || !$styleChild->hasAttributes()) {
                                 continue;
                             }
                             $fontWeight = $styleChild->getAttributeNS(self::NAMESPACE_FO, 'font-weight');
                             $fontStyle = $styleChild->getAttributeNS(self::NAMESPACE_FO, 'font-style');
                         }
                     }
                 }
             }
             $inlineCustomTagName = false;
             if (substr($styleName, 0, 18) == "eZCustominline_20_") {
                 $inlineCustomTagName = substr($styleName, 18);
             }
             if ($inlineCustomTagName != false) {
                 $paragraphContent .= "<custom name='{$inlineCustomTagName}'>";
             }
             if ($fontWeight == "bold") {
                 $paragraphContent .= "<strong>";
             }
             if ($fontStyle == "italic") {
                 $paragraphContent .= "<emphasize>";
             }
             $paragraphContent .= $childNode->textContent;
             if ($fontStyle == "italic") {
                 $paragraphContent .= "</emphasize>";
             }
             if ($fontWeight == "bold") {
                 $paragraphContent .= "</strong>";
             }
             if ($inlineCustomTagName != false) {
                 $paragraphContent .= "</custom>";
             }
             break;
         default:
             eZDebug::writeError("Unsupported node: '" . $localName . "'");
             break;
     }
     if ($nextLineBreak) {
         $paragraphContent = '<line>' . $paragraphContent . '</line>';
     } elseif ($prevLineBreak && $paragraphContent) {
         $paragraphContent = '<line>' . $paragraphContent . '</line>';
     }
     return $paragraphContent;
 }
Ejemplo n.º 7
0
 /**
  * Test for argument parsing with many attributes
  *
  * @dataProvider providerForTestManyAttributesParsing
  */
 public function testManyAttributesParsing($string, $expected)
 {
     $this->assertEquals($expected, $this->parser->parseAttributes($string));
 }
 function __construct($contentObjectID, $validateErrorLevel = eZXMLInputParser::ERROR_ALL, $detectErrorLevel = eZXMLInputParser::ERROR_ALL, $parseLineBreaks = false, $removeDefaultAttrs = false)
 {
     $this->contentObjectID = $contentObjectID;
     parent::__construct($validateErrorLevel, $detectErrorLevel, $parseLineBreaks, $removeDefaultAttrs);
 }