コード例 #1
0
 static function handleInlineNode($child, $generator, $prevLineBreak = false)
 {
     $paragraphParameters = array();
     $imageArray = array();
     switch ($child->localName) {
         case "line":
             // @todo: (Alex) check why this is needed here and not after the next line
             if ($prevLineBreak) {
                 $paragraphParameters[] = array(eZOOGenerator::LINE, '');
             }
             // Todo: support inline tags
             $paragraphParameters[] = array(eZOOGenerator::TEXT, $child->textContent);
             foreach ($child->childNodes as $lineChild) {
                 if ($lineChild->localName == 'embed') {
                     // Only support objects of image class for now
                     $object = eZContentObject::fetch($lineChild->getAttribute("object_id"));
                     if ($object && $object->canRead()) {
                         $classIdentifier = $object->attribute("class_identifier");
                         // Todo: read class identifiers from configuration
                         if ($classIdentifier == "image") {
                             $imageSize = $lineChild->getAttribute('size');
                             if ($imageSize == "") {
                                 $imageSize = "large";
                             }
                             $imageAlignment = $lineChild->getAttribute('align');
                             if ($imageAlignment == "") {
                                 $imageAlignment = "center";
                             }
                             $dataMap = $object->dataMap();
                             $imageAttribute = $dataMap['image'];
                             $imageHandler = $imageAttribute->content();
                             $originalImage = $imageHandler->attribute('original');
                             $fileHandler = eZClusterFileHandler::instance($originalImage['url']);
                             $uniqueFile = $fileHandler->fetchUnique();
                             $displayImage = $imageHandler->attribute($imageSize);
                             $displayWidth = $displayImage['width'];
                             $displayHeight = $displayImage['height'];
                             $imageArray[] = array("FileName" => $uniqueFile, "Alignment" => $imageAlignment, "DisplayWidth" => $displayWidth, "DisplayHeight" => $displayHeight);
                         }
                     } else {
                         eZDebug::writeError("Image (object_id = " . $child->getAttribute('object_id') . " ) could not be used (does not exist or due to insufficient privileges)");
                     }
                 }
             }
             break;
             // text nodes
         // text nodes
         case "":
             $paragraphParameters[] = array(eZOOGenerator::TEXT, $child->textContent);
             break;
         case "link":
             $href = $child->getAttribute('href');
             if (!$href) {
                 $url_id = $child->getAttribute('url_id');
                 if ($url_id) {
                     $eZUrl = eZURL::fetch($url_id);
                     if (is_object($eZUrl)) {
                         $href = $eZUrl->attribute('url');
                     }
                 }
             }
             $paragraphParameters[] = array(eZOOGenerator::LINK, $href, $child->textContent);
             break;
         case "emphasize":
         case "strong":
             $style = $child->localName == 'strong' ? 'bold' : 'italic';
             $paragraphParameters[] = array(eZOOGenerator::STYLE_START, $style);
             foreach ($child->childNodes as $inlineNode) {
                 $return = self::handleInlineNode($inlineNode);
                 $paragraphParameters = array_merge($paragraphParameters, $return['paragraph_parameters']);
             }
             $paragraphParameters[] = array(eZOOGenerator::STYLE_STOP);
             break;
         case "literal":
             $literalContent = $child->textContent;
             $literalContentArray = explode("\n", $literalContent);
             foreach ($literalContentArray as $literalLine) {
                 $generator->addParagraph("Preformatted_20_Text", htmlspecialchars($literalLine));
             }
             break;
         case "custom":
             $customTagName = $child->getAttribute('name');
             // Check if the custom tag is inline
             $ini = eZINI::instance('content.ini');
             $isInlineTagList = $ini->variable('CustomTagSettings', 'IsInline');
             $isInline = array_key_exists($customTagName, $isInlineTagList) && $isInlineTagList[$customTagName];
             // Handle inline custom tags
             if ($isInline) {
                 $paragraphParameters[] = array(eZOOGenerator::STYLE_START, "eZCustominline_20_{$customTagName}");
                 $paragraphParameters[] = array(eZOOGenerator::TEXT, $child->textContent);
                 $paragraphParameters[] = array(eZOOGenerator::STYLE_STOP);
             } else {
                 $GLOBALS['CustomTagStyle'] = "eZCustom_20_{$customTagName}";
                 foreach ($child->childNodes as $customParagraph) {
                     // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                     self::handleNode($customParagraph, $generator, $prevLineBreak);
                 }
                 $GLOBALS['CustomTagStyle'] = false;
             }
             break;
         case "ol":
         case "ul":
             $listType = $child->localName == "ol" ? "ordered" : "unordered";
             $generator->startList($listType);
             foreach ($child->childNodes as $listItem) {
                 foreach ($listItem->childNodes as $childNode) {
                     if ($childNode->nodeType == XML_TEXT_NODE) {
                         $generator->addParagraph($childNode->textContent);
                     } else {
                         // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                         self::handleNode($childNode, $generator, $prevLineBreak);
                     }
                 }
                 $generator->nextListItem();
             }
             $generator->endList();
             break;
         case "table":
             $generator->startTable();
             $rows = 1;
             foreach ($child->childNodes as $row) {
                 foreach ($row->childNodes as $cell) {
                     // Set the correct col span
                     $colSpan = $cell->getAttribute("colspan");
                     if (is_numeric($colSpan)) {
                         $generator->setCurrentColSpan($colSpan);
                     }
                     // Check for table header
                     if ($cell->localName == 'th' and $rows == 1) {
                         $generator->setIsInsideTableHeading(true);
                     }
                     // If the cell is empty, create a dummy so the cell is properly exported
                     if (!$cell->hasChildNodes()) {
                         $dummy = $cell->ownerDocument->createElement("paragraph");
                         $cell->appendChild($dummy);
                         // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                         eZOOConverter::handleNode($dummy, $generator, $prevLineBreak);
                     }
                     eZDebug::writeDebug($cell->ownerDocument->saveXML($cell), 'ezxmltext table cell');
                     foreach ($cell->childNodes as $cellNode) {
                         // Alex 2008-06-03: changed $level (3rd argument) to $prevLineBreak
                         self::handleNode($cellNode, $generator, $prevLineBreak);
                     }
                     $generator->nextCell();
                 }
                 $generator->nextRow();
                 ++$rows;
             }
             $generator->endTable();
             break;
         case 'object':
         case 'embed':
             $objectID = $child->localName == 'embed' ? $child->getAttribute("object_id") : $child->getAttribute("id");
             // Only support objects of image class for now
             $object = eZContentObject::fetch($objectID);
             if ($object && $object->canRead()) {
                 $classIdentifier = $object->attribute("class_identifier");
                 // Todo: read class identifiers from configuration
                 if ($classIdentifier == "image") {
                     $imageSize = $child->getAttribute('size');
                     $imageAlignment = $child->getAttribute('align');
                     $dataMap = $object->dataMap();
                     $imageAttribute = $dataMap['image'];
                     $imageHandler = $imageAttribute->content();
                     $originalImage = $imageHandler->attribute('original');
                     $fileHandler = eZClusterFileHandler::instance($originalImage['url']);
                     $uniqueFile = $fileHandler->fetchUnique();
                     $displayImage = $imageHandler->attribute($imageSize);
                     $displayWidth = $displayImage['width'];
                     $displayHeight = $displayImage['height'];
                     $imageArray[] = array("FileName" => $uniqueFile, "Alignment" => $imageAlignment, "DisplayWidth" => $displayWidth, "DisplayHeight" => $displayHeight);
                 }
             } else {
                 eZDebug::writeError("Image (object_id = " . $child->getAttribute('object_id') . " ) could not be used (does not exist or insufficient privileges)");
             }
             break;
         default:
             eZDebug::writeError("Unsupported node at this level" . $child->localName);
     }
     return array("paragraph_parameters" => $paragraphParameters, "image_array" => $imageArray);
 }
コード例 #2
0
 /**
  * Create OO document element with conversion to Word 97 format.
  *
  * Added by Alex 2008/04/16
  *
  * @param DOMDocument Owner DOMDocument
  * @param eZContentObjectTreeNode eZContentObjectTreeNode object.
  *
  * @return DOMElement NameList DOMDocument, example:
  *
  *     <OODocument base64Encoded="1" filename="My article.doc">
  *         <![CDATA[ ad lkøjsdaølfhadsø fiuancfivn søgsbdnvsahfø ]]>
  *     </OODocument>
  */
 protected function createDocDOMElement(DOMDocument $domDocument, eZContentObjectTreeNode $node)
 {
     $ooDocumentElement = $domDocument->createElement('OODocument');
     $fileName = eZOOConverter::objectToOO($node->attribute('node_id'));
     if (is_array($fileName)) {
         throw new Exception('Could not generate OO document, ID: ' . $node->attribute('node_id') . ', Description: ' . $fileName[0]);
     }
     // Add odt document to DOMElement
     $ooDocumentElement->setAttribute('base64Encoded', '1');
     $ooDocumentElement->setAttribute('filename', $node->attribute('name') . '.doc');
     // need to generate? a file name
     $convertedFile = '/tmp/word.doc';
     //    unlink( $convertedFile );
     $this->daemonConvert(realpath($fileName), $convertedFile);
     // need to see if the conversion was successful
     $ooDocumentElement->appendChild($domDocument->createCDATASection(base64_encode(file_get_contents($convertedFile))));
     unlink($fileName);
     // need to delete the converted file (does not work?)
     // unlink( $convertedFile );
     return $ooDocumentElement;
 }
コード例 #3
0
ファイル: export.php プロジェクト: legende91/ez
        if (strlen(trim($exportTypeParam)) != 0) {
            $tpl->setVariable("error_string", ezpI18n::tr('extension/ezodf/export/error', "Destination file format not supported"));
            $success = false;
        }
    }
}
$ooINI = eZINI::instance('odf.ini');
//$tmpDir = $ooINI->variable( 'ODFSettings', 'TmpDir' );
$tmpDir = getcwd() . "/" . eZSys::cacheDirectory();
if ($doExport == true) {
    if (is_numeric($nodeID)) {
        $node = eZContentObjectTreeNode::fetch($nodeID);
        // Check if we have read access to this node
        if ($node && $node->canRead()) {
            // Do the actual eZ Publish export
            $fileName = eZOOConverter::objectToOO($nodeID);
            if (!is_array($fileName)) {
                $nodeName = $node->attribute('name');
                $originalFileName = $nodeName . ".odt";
                $contentType = "application/vnd.oasis.opendocument.text";
                $trans = eZCharTransform::instance();
                $nodeName = $trans->transformByGroup($nodeName, 'urlalias');
                $uniqueStamp = md5(time());
                $server = $ooINI->variable("ODFImport", "OOConverterAddress");
                $port = $ooINI->variable("ODFImport", "OOConverterPort");
                switch ($exportType) {
                    case "PDF":
                        if ($result = daemonConvert($server, $port, realpath($fileName), "convertToPDF", $tmpDir . "/ooo_converted_{$uniqueStamp}.pdf")) {
                            $originalFileName = $nodeName . ".pdf";
                            $contentType = "application/pdf";
                            $fileName = $tmpDir . "/ooo_converted_{$uniqueStamp}.pdf";
コード例 #4
0
include_once 'kernel/classes/datatypes/ezuser/ezuser.php';
include_once "extension/ezodf/modules/ezodf/ezooconverter.php";
include_once "lib/ezutils/classes/ezhttptool.php";
$http = eZHTTPTool::instance();
if ($http->hasPostVariable('Username')) {
}
$username = $http->postVariable('Username');
if ($http->hasPostVariable('Password')) {
}
$password = $http->postVariable('Password');
if ($http->hasPostVariable('NodeID')) {
}
$nodeID = $http->postVariable('NodeID');
// User authentication
$user = eZUser::loginUser($username, $password);
if ($user == false) {
    print 'problem:Authentication failed';
    eZExecution::cleanExit();
}
// Conversion of the stored file
$converter = new eZOOConverter();
$ooDocument = $converter->objectToOO($nodeID);
if ($ooDocument == false) {
    print 'problem:Conversion failed';
    eZExecution::cleanExit();
}
$file = file_get_contents($ooDocument);
$file = base64_encode($file);
print $file;
// Don't display eZ Publish page structure
eZExecution::cleanExit();