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); }
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("&", "&", $childNode->textContent); $tagContent = str_replace(">", ">", $tagContent); $tagContent = str_replace("<", "<", $tagContent); $tagContent = str_replace("'", "'", $tagContent); $tagContent = str_replace('"', """, $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; }