/**
  * Test for issue #15230: php fatal error in fetch reverse_related_object
  *
  * This tests checks that eZContentFunctionCollection::fetchReverseRelatedObjects
  * and eZContentFunctionCollection::fetchRelatedObjectsCount won't throw a
  * fatal error if provided with a non-existing object ID
  *
  * @link http://issues.ez.no/15230
  */
 public function testIssue15230()
 {
     $nonExistingArticleID = 100000000;
     $this->assertFalse(eZContentFunctionCollection::fetchRelatedObjects($nonExistingArticleID, false, true, false, false), "eZContentFunctionCollection::fetchRelatedObjects({$nonExistingArticleID}) should have returned false");
     $this->assertFalse(eZContentFunctionCollection::fetchRelatedObjectsCount($nonExistingArticleID, false, true, false, false), "eZContentFunctionCollection::fetchRelatedObjectsCount({$nonExistingArticleID}) should have returned false");
     $this->assertFalse(eZContentFunctionCollection::fetchReverseRelatedObjects($nonExistingArticleID, false, true, false, false, false), "eZContentFunctionCollection::fetchReverseRelatedObjects({$nonExistingArticleID}) should have returned false");
     $this->assertFalse(eZContentFunctionCollection::fetchReverseRelatedObjectsCount($nonExistingArticleID, false, true, false, false, false), "eZContentFunctionCollection::fetchReverseRelatedObjectsCount({$nonExistingArticleID}) should have returned false");
 }
 static function popular_sidebar_fetch($viewCountParameters, $limit = 8, $offset = 0)
 {
     $count = array();
     $results = array();
     foreach ($viewCountParameters as $viewCountParameter) {
         $viewCountParameter = explode(';', $viewCountParameter);
         $classID = $viewCountParameter[0];
         $sectionID = $viewCountParameter[1];
         $results[] = eZContentFunctionCollection::fetchMostViewedTopList($classID, $sectionID, $offset, $limit);
     }
     foreach ($results as $result) {
         foreach ($result['result'] as $object) {
             $count[] = array($object->attribute('view_count'), $object);
         }
     }
     return self::sort_popular_desc($count);
 }
 public static function fetchReverseRelatedObjectsCount($objectID, $attributeID, $allRelations, $ignoreVisibility)
 {
     if (!is_numeric($objectID)) {
         eZDebug::writeError("\$objectID is missing or invalid", __METHOD__);
         return false;
     }
     $object = eZContentObject::fetch($objectID);
     if (!$object instanceof eZContentObject) {
         eZDebug::writeError("An error occured fetching object #{$objectID}", __METHOD__);
         return false;
     }
     $params = array();
     if (isset($ignoreVisibility)) {
         $params['IgnoreVisibility'] = $ignoreVisibility;
     }
     if (!$attributeID) {
         $attributeID = 0;
     }
     if (isset($allRelations)) {
         if ($attributeID && !$allRelations) {
             $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask(array('attribute'));
         } elseif ($allRelations === true) {
             $attributeID = false;
         } else {
             $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask($allRelations);
         }
     }
     if ($attributeID && !is_numeric($attributeID) && !is_bool($attributeID)) {
         $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier($attributeID);
         if (!$attributeID) {
             eZDebug::writeError("Can't get class attribute ID by identifier");
             return false;
         }
     }
     return array('result' => $object->reverseRelatedObjectCount(false, $attributeID, $params));
 }
Ejemplo n.º 4
0
 /**
  * Creates a new content or updates an existing one based on $file
  *
  * @param string $file the file to import
  * @param int $placeNodeID the node id where to place the new document or
  *        the node of the document to update
  * @param string $originalFileName
  * @param string $importType "import" or "replace"
  * @param eZContentUpload|null $upload (not used in this method)
  * @param string|false $locale the locale to use while creating/updating
  *        the content
  * @return array|false false if something went wrong
  */
 function import($file, $placeNodeID, $originalFileName, $importType = "import", $upload = null, $locale = false)
 {
     $ooINI = eZINI::instance('odf.ini');
     //$tmpDir = $ooINI->variable( 'ODFSettings', 'TmpDir' );
     // Use var-directory as temporary directory
     $tmpDir = getcwd() . "/" . eZSys::cacheDirectory();
     $allowedTypes = $ooINI->variable('DocumentType', 'AllowedTypes');
     $convertTypes = $ooINI->variable('DocumentType', 'ConvertTypes');
     $originalFileType = array_slice(explode('.', $originalFileName), -1, 1);
     $originalFileType = strtolower($originalFileType[0]);
     if (!in_array($originalFileType, $allowedTypes, false) and !in_array($originalFileType, $convertTypes, false)) {
         $this->setError(self::ERROR_UNSUPPORTEDTYPE, ezpI18n::tr('extension/ezodf/import/error', "Filetype: ") . $originalFileType);
         return false;
     }
     // If replacing/updating the document we need the ID.
     if ($importType == "replace") {
         $GLOBALS["OOImportObjectID"] = $placeNodeID;
     }
     // Check if we have access to node
     $place_node = eZContentObjectTreeNode::fetch($placeNodeID);
     $importClassIdentifier = $ooINI->variable('ODFImport', 'DefaultImportClass');
     // Check if class exist
     $class = eZContentClass::fetchByIdentifier($importClassIdentifier);
     if (!is_object($class)) {
         eZDebug::writeError("Content class <strong>{$importClassIdentifier}</strong> specified in odf.ini does not exist.");
         $this->setError(self::ERROR_UNKNOWNCLASS, $importClassIdentifier);
         return false;
     }
     if (!is_object($place_node)) {
         $locationOK = false;
         if ($upload !== null) {
             $parentNodes = false;
             $parentMainNode = false;
             $locationOK = $upload->detectLocations($importClassIdentifier, $class, $placeNodeID, $parentNodes, $parentMainNode);
         }
         if ($locationOK === false || $locationOK === null) {
             $this->setError(self::ERROR_UNKNOWNNODE, ezpI18n::tr('extension/ezodf/import/error', "Unable to fetch node with id ") . $placeNodeID);
             return false;
         }
         $placeNodeID = $parentMainNode;
         $place_node = eZContentObjectTreeNode::fetch($placeNodeID);
     }
     // Check if document conversion is needed
     //
     // Alex 2008/04/21 - added !== false
     if (in_array($originalFileType, $convertTypes, false) !== false) {
         $uniqueStamp = md5(time());
         $tmpFromFile = $tmpDir . "/convert_from_{$uniqueStamp}.doc";
         $tmpToFile = $tmpDir . "/ooo_converted_{$uniqueStamp}.odt";
         copy(realpath($file), $tmpFromFile);
         /// Convert document using the eZ Publish document conversion daemon
         if (!$this->daemonConvert($tmpFromFile, $tmpToFile)) {
             if ($this->getErrorNumber() == 0) {
                 $this->setError(self::ERROR_CONVERT);
             }
             return false;
         }
         // At this point we can unlink the sourcefile for conversion
         unlink($tmpFromFile);
         // Overwrite the file location
         $file = $tmpToFile;
     }
     $importResult = array();
     $unzipResult = "";
     $uniqueImportDir = $this->ImportDir;
     eZDir::mkdir($uniqueImportDir, false, true);
     $http = eZHTTPTool::instance();
     $archiveOptions = new ezcArchiveOptions(array('readOnly' => true));
     $archive = ezcArchive::open($file, null, $archiveOptions);
     $archive->extract($uniqueImportDir);
     $fileName = $uniqueImportDir . "content.xml";
     $dom = new DOMDocument('1.0', 'UTF-8');
     $success = $dom->load($fileName);
     $sectionNodeHash = array();
     // At this point we could unlink the destination file from the conversion, if conversion was used
     if (isset($tmpToFile)) {
         unlink($tmpToFile);
     }
     if (!$success) {
         $this->setError(self::ERROR_PARSEXML);
         return false;
     }
     // Fetch the automatic document styles
     $automaticStyleArray = $dom->getElementsByTagNameNS(self::NAMESPACE_OFFICE, 'automatic-styles');
     if ($automaticStyleArray->length == 1) {
         $this->AutomaticStyles = $automaticStyleArray->item(0)->childNodes;
     }
     // Fetch the body section content
     $sectionNodeArray = $dom->getElementsByTagNameNS(self::NAMESPACE_TEXT, 'section');
     $customClassFound = false;
     if ($sectionNodeArray->length > 0) {
         $registeredClassArray = $ooINI->variable('ODFImport', 'RegisteredClassArray');
         // Check the defined sections in OO document
         $sectionNameArray = array();
         foreach ($sectionNodeArray as $sectionNode) {
             $sectionNameArray[] = strtolower($sectionNode->getAttributeNS(self::NAMESPACE_TEXT, "name"));
         }
         // Check if there is a coresponding eZ Publish class for this document
         foreach ($registeredClassArray as $className) {
             $attributeArray = $ooINI->variable($className, 'Attribute');
             if (!empty($attributeArray)) {
                 // Convert space to _ in section names
                 foreach ($sectionNameArray as $key => $value) {
                     $sectionNameArray[$key] = str_replace(" ", "_", $value);
                 }
                 sort($attributeArray);
                 sort($sectionNameArray);
                 $diff = array_diff($attributeArray, $sectionNameArray);
                 if (empty($diff)) {
                     $importClassIdentifier = $className;
                     $customClassFound = true;
                     break;
                 }
             }
         }
         if ($customClassFound == true) {
             foreach ($sectionNodeArray as $sectionNode) {
                 $sectionName = str_replace(" ", "_", strtolower($sectionNode->getAttributeNS(self::NAMESPACE_TEXT, 'name')));
                 $xmlText = "";
                 $level = 1;
                 $childArray = $sectionNode->childNodes;
                 $nodeCount = 1;
                 foreach ($childArray as $childNode) {
                     if ($childNode->nodeType === XML_ELEMENT_NODE) {
                         $isLastTag = $nodeCount == $childArray->length;
                         $xmlText .= self::handleNode($childNode, $level, $isLastTag);
                     }
                     $nodeCount++;
                 }
                 $endSectionPart = "";
                 $levelDiff = 1 - $level;
                 if ($levelDiff < 0) {
                     $endSectionPart = str_repeat("</section>", abs($levelDiff));
                 }
                 $charset = eZTextCodec::internalCharset();
                 // Store the original XML for each section, since some datatypes needs to handle the XML specially
                 $sectionNodeHash[$sectionName] = $sectionNode;
                 $xmlTextArray[$sectionName] = "<?xml version='1.0' encoding='{$charset}' ?>" . "<section xmlns:image='http://ez.no/namespaces/ezpublish3/image/' " . "  xmlns:xhtml='http://ez.no/namespaces/ezpublish3/xhtml/'><section>" . $xmlText . $endSectionPart . "</section></section>";
             }
         }
     }
     if ($customClassFound == false) {
         // No defined sections. Do default import.
         $bodyNodeArray = $dom->getElementsByTagNameNS(self::NAMESPACE_OFFICE, 'text');
         // Added by Soushi
         // check the parent-style-name [ eZSectionDefinition ]
         $eZSectionDefinitionStyleName = array();
         foreach ($automaticStyleArray->item(0)->childNodes as $child) {
             if ($child->nodeType === XML_ELEMENT_NODE && $child->getAttributeNS(self::NAMESPACE_STYLE, 'parent-style-name') === 'eZSectionDefinition') {
                 $eZSectionDefinitionStyleName[] = $child->getAttributeNS(self::NAMESPACE_STYLE, 'name');
             }
         }
         $sectionNameArray = array();
         $sectionNodeArray = array();
         $paragraphSectionName = NULL;
         $firstChildFlag = false;
         $paragraphSectionNodeArray = array();
         foreach ($bodyNodeArray->item(0)->childNodes as $childNode) {
             $firstChildFlag = true;
             if ($childNode->nodeType === XML_ELEMENT_NODE && (in_array($childNode->getAttributeNS(self::NAMESPACE_TEXT, 'style-name'), $eZSectionDefinitionStyleName) || $childNode->getAttributeNS(self::NAMESPACE_TEXT, 'style-name') === 'eZSectionDefinition')) {
                 $firstChildFlag = false;
                 $childNodeChildren = $childNode->childNodes;
                 $paragraphSectionName = trim($childNodeChildren->item(0)->textContent);
                 $sectionNameArray[] = $paragraphSectionName;
             }
             if ($paragraphSectionName && $firstChildFlag) {
                 $paragraphSectionNodeArray[$paragraphSectionName][] = $childNode;
             }
         }
         $sectionNodeArray = array();
         foreach ($paragraphSectionNodeArray as $key => $childNodes) {
             $sectionNode = $dom->createElement('section');
             foreach ($childNodes as $childNode) {
                 $sectionNode->appendChild($childNode);
             }
             $sectionNodeArray[$key] = $sectionNode;
         }
         $customClassFound = false;
         if ($sectionNameArray) {
             $registeredClassArray = $ooINI->variable('ODFImport', 'RegisteredClassArray');
             // Check if there is a coresponding eZ Publish class for this document
             foreach ($registeredClassArray as $className) {
                 $attributeArray = $ooINI->variable($className, 'Attribute');
                 if (!empty($attributeArray)) {
                     // Convert space to _ in section names
                     foreach ($sectionNameArray as $key => $value) {
                         $sectionNameArray[$key] = str_replace(" ", "_", $value);
                     }
                     sort($attributeArray);
                     sort($sectionNameArray);
                     $diff = array_diff($attributeArray, $sectionNameArray);
                     if (empty($diff)) {
                         $importClassIdentifier = $className;
                         $customClassFound = true;
                         break;
                     }
                 }
             }
         }
         if ($sectionNameArray && $customClassFound == true) {
             foreach ($sectionNodeArray as $key => $sectionNode) {
                 $sectionName = str_replace(" ", "_", $key);
                 $xmlText = "";
                 $level = 1;
                 foreach ($sectionNode->childNodes as $childNode) {
                     $isLastTag = !isset($childNode->nextSibling);
                     $xmlText .= self::handleNode($childNode, $level, $isLastTag);
                 }
                 $endSectionPart = "";
                 $levelDiff = 1 - $level;
                 if ($levelDiff < 0) {
                     $endSectionPart = str_repeat("</section>", abs($levelDiff));
                 }
                 $charset = eZTextCodec::internalCharset();
                 // Store the original XML for each section, since some datatypes needs to handle the XML specially
                 $sectionNodeHash[$sectionName] = $sectionNode;
                 $xmlTextArray[$sectionName] = "<?xml version='1.0' encoding='{$charset}' ?>" . "<section xmlns:image='http://ez.no/namespaces/ezpublish3/image/' " . "  xmlns:xhtml='http://ez.no/namespaces/ezpublish3/xhtml/'><section>" . $xmlText . $endSectionPart . "</section></section>";
             }
         } else {
             if ($bodyNodeArray->length === 1) {
                 $xmlText = "";
                 $level = 1;
                 foreach ($bodyNodeArray->item(0)->childNodes as $childNode) {
                     $xmlText .= self::handleNode($childNode, $level);
                 }
                 $endSectionPart = "";
                 $levelDiff = 1 - $level;
                 if ($levelDiff < 0) {
                     $endSectionPart = str_repeat("</section>", abs($levelDiff));
                 }
                 $charset = eZTextCodec::internalCharset();
                 $xmlTextBody = "<?xml version='1.0' encoding='{$charset}' ?>" . "<section xmlns:image='http://ez.no/namespaces/ezpublish3/image/' " . "  xmlns:xhtml='http://ez.no/namespaces/ezpublish3/xhtml/'><section>" . $xmlText . $endSectionPart . "</section></section>";
             }
         }
     }
     if ($importType == "replace") {
         // Check if we are allowed to edit the node
         $functionCollection = new eZContentFunctionCollection();
         $access = $functionCollection->checkAccess('edit', $place_node, false, false, $locale);
     } else {
         // Check if we are allowed to create a node under the node
         $functionCollection = new eZContentFunctionCollection();
         $access = $functionCollection->checkAccess('create', $place_node, $importClassIdentifier, $place_node->attribute('class_identifier'), $locale);
     }
     if ($access['result']) {
         // Check if we should replace the current object or import a new
         if ($importType !== "replace") {
             $class = eZContentClass::fetchByIdentifier($importClassIdentifier);
             $place_object = $place_node->attribute('object');
             $sectionID = $place_object->attribute('section_id');
             $creatorID = $this->currentUserID;
             $parentNodeID = $placeNodeID;
             if (!is_object($class)) {
                 eZDebug::writeError("Content class <strong>{$importClassIdentifier}</strong> specified in odf.ini does not exist.");
                 $this->setError(self::ERROR_UNKNOWNCLASS, $importClassIdentifier);
                 return false;
             }
             $object = $class->instantiate($creatorID, $sectionID, false, $locale);
             $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $parentNodeID, 'is_main' => 1));
             $nodeAssignment->store();
             $version = $object->version(1);
             $version->setAttribute('modified', eZDateTime::currentTimeStamp());
             $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
             $version->store();
             $dataMap = $object->dataMap();
         } else {
             // Check if class is supported before we start changing anything
             $placeClassIdentifier = $place_node->attribute('class_identifier');
             if ($ooINI->hasVariable($placeClassIdentifier, 'DefaultImportTitleAttribute') && $ooINI->hasVariable($placeClassIdentifier, 'DefaultImportBodyAttribute')) {
                 $titleAttribute = $ooINI->variable($placeClassIdentifier, 'DefaultImportTitleAttribute');
                 $bodyAttribute = $ooINI->variable($placeClassIdentifier, 'DefaultImportBodyAttribute');
                 // Extra check to see if attributes exist in dataMap (config is not wrong)
                 $dataMap = $place_node->attribute('data_map');
                 if (!isset($dataMap[$titleAttribute]) || !isset($dataMap[$bodyAttribute])) {
                     $this->setError(self::ERROR_IMPORTING, "Error in configuration for {$placeClassIdentifier}, please check configuration file.");
                     return false;
                 }
                 unset($dataMap);
             } else {
                 $this->setError(self::ERROR_IMPORTING, "No settings for replacing node of type {$placeClassIdentifier}. Stopping.");
                 return false;
             }
             // Change class for importing
             $importClassIdentifier = $placeClassIdentifier;
             // already fetched: $node = eZContentObjectTreeNode::fetch( $placeNodeID );
             $object = $place_node->attribute('object');
             $version = $object->createNewVersionIn($locale);
             $dataMap = $version->dataMap();
         }
         $contentObjectID = $object->attribute('id');
         if ($customClassFound == true) {
             // Initialize the actual object attributes
             $attributeArray = $ooINI->variable($importClassIdentifier, 'Attribute');
             foreach ($attributeArray as $attributeIdentifier => $sectionName) {
                 switch ($dataMap[$attributeIdentifier]->DataTypeString) {
                     case "ezstring":
                     case "eztext":
                         if (!isset($xmlTextArray[$sectionName])) {
                             continue;
                         }
                         $eztextDom = new DOMDOcument('1.0', 'UTF-8');
                         $eztextDom->loadXML($xmlTextArray[$sectionName]);
                         $text = $eztextDom->documentElement->textContent;
                         $dataMap[$attributeIdentifier]->setAttribute('data_text', trim($text));
                         $dataMap[$attributeIdentifier]->store();
                         break;
                     case "ezxmltext":
                         if (!isset($xmlTextArray[$sectionName])) {
                             continue;
                         }
                         $dataMap[$attributeIdentifier]->setAttribute('data_text', $xmlTextArray[$sectionName]);
                         $dataMap[$attributeIdentifier]->store();
                         break;
                     case "ezdate":
                         // Only support date formats as a single paragraph in a section with the format:
                         // day/month/year
                         if (!isset($xmlTextArray[$sectionName])) {
                             continue;
                         }
                         $dateString = strip_tags($xmlTextArray[$sectionName]);
                         $dateArray = explode("/", $dateString);
                         if (count($dateArray) == 3) {
                             $year = $dateArray[2];
                             $month = $dateArray[1];
                             $day = $dateArray[0];
                             $date = new eZDate();
                             $contentClassAttribute = $dataMap[$attributeIdentifier];
                             $date->setMDY($month, $day, $year);
                             $dataMap[$attributeIdentifier]->setAttribute('data_int', $date->timeStamp());
                             $dataMap[$attributeIdentifier]->store();
                         }
                         break;
                     case "ezdatetime":
                         // Only support date formats as a single paragraph in a section with the format:
                         // day/month/year 14:00
                         if (!isset($xmlTextArray[$sectionName])) {
                             continue;
                         }
                         $dateString = trim(strip_tags($xmlTextArray[$sectionName]));
                         $dateTimeArray = explode(" ", $dateString);
                         $dateArray = explode("/", $dateTimeArray[0]);
                         $timeArray = explode(":", $dateTimeArray[1]);
                         if (count($dateArray) == 3 and count($timeArray) == 2) {
                             $year = $dateArray[2];
                             $month = $dateArray[1];
                             $day = $dateArray[0];
                             $hour = $timeArray[0];
                             $minute = $timeArray[1];
                             $dateTime = new eZDateTime();
                             $contentClassAttribute = $dataMap[$attributeIdentifier];
                             $dateTime->setMDYHMS($month, $day, $year, $hour, $minute, 0);
                             $dataMap[$attributeIdentifier]->setAttribute('data_int', $dateTime->timeStamp());
                             $dataMap[$attributeIdentifier]->store();
                         }
                         break;
                     case "ezimage":
                         $hasImage = false;
                         // Images are treated as an image object inside a paragrah.
                         // We fetch the first image object if there are multiple and ignore the rest
                         if (is_object($sectionNodeHash[$sectionName])) {
                             // Look for paragraphs in the section
                             foreach ($sectionNodeHash[$sectionName]->childNodes as $paragraph) {
                                 if (!$paragraph->hasChildNodes()) {
                                     continue;
                                 }
                                 // Look for frame node
                                 foreach ($paragraph->childNodes as $frame) {
                                     // finally look for the image node
                                     $children = $frame->childNodes;
                                     $imageNode = $children->item(0);
                                     if ($imageNode && $imageNode->localName == "image") {
                                         $fileName = ltrim($imageNode->getAttributeNS(self::NAMESPACE_XLINK, 'href'), '#');
                                         $filePath = $this->ImportDir . $fileName;
                                         if (file_exists($filePath)) {
                                             $imageContent = $dataMap[$attributeIdentifier]->attribute('content');
                                             $imageContent->initializeFromFile($filePath, false, basename($filePath));
                                             $imageContent->store($dataMap[$attributeIdentifier]);
                                             $dataMap[$attributeIdentifier]->store();
                                         }
                                         $hasImage = true;
                                     }
                                 }
                             }
                         }
                         if (!$hasImage) {
                             $imageHandler = $dataMap[$attributeIdentifier]->attribute('content');
                             if ($imageHandler) {
                                 $imageHandler->removeAliases($dataMap[$attributeIdentifier]);
                             }
                         }
                         break;
                     case "ezmatrix":
                         $matrixHeaderArray = array();
                         // Fetch the current defined columns in the matrix
                         $matrix = $dataMap[$attributeIdentifier]->content();
                         $columns = $matrix->attribute("columns");
                         foreach ($columns['sequential'] as $column) {
                             $matrixHeaderArray[] = $column['name'];
                         }
                         $headersValid = true;
                         $originalHeaderCount = count($matrixHeaderArray);
                         $headerCount = 0;
                         $rowCount = 0;
                         $cellArray = array();
                         // A matrix is supported as a table inside sections. If multiple tables are present we take the first.
                         if (is_object($sectionNodeHash[$sectionName])) {
                             // Look for paragraphs in the section
                             foreach ($sectionNodeHash[$sectionName]->childNodes as $table) {
                                 if ($table->localName == "table") {
                                     // Loop the rows in the table
                                     foreach ($table->childNodes as $row) {
                                         // Check the headers and compare with the defined matrix
                                         if ($row->localName == "table-header-rows") {
                                             $rowArray = $row->childNodes;
                                             if ($rowArray->length == 1) {
                                                 foreach ($rowArray->item(0)->childNodes as $headerCell) {
                                                     if ($headerCell->localName == "table-cell") {
                                                         $paragraphArray = $headerCell->childNodes;
                                                         if ($paragraphArray->length == 1) {
                                                             $headerName = $paragraphArray->item(0)->textContent;
                                                             if ($matrixHeaderArray[$headerCount] != $headerName) {
                                                                 $headersValid = false;
                                                             }
                                                             $headerCount++;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         // Check the rows
                                         if ($row->localName == "table-row") {
                                             foreach ($row->childNodes as $cell) {
                                                 if ($cell->childNodes->length >= 1) {
                                                     $firstParagraph = $cell->childNodes->item(0);
                                                     $cellArray[] = $firstParagraph->textContent;
                                                 }
                                             }
                                             $rowCount++;
                                         }
                                     }
                                 }
                             }
                         }
                         if ($headerCount == $originalHeaderCount and $headersValid == true) {
                             // Remove all existing rows
                             for ($i = 0; $i < $matrix->attribute("rowCount"); $i++) {
                                 $matrix->removeRow($i);
                             }
                             // Insert new rows
                             $matrix->addRow(false, $rowCount);
                             $matrix->Cells = $cellArray;
                             $dataMap[$attributeIdentifier]->setAttribute('data_text', $matrix->xmlString());
                             $matrix->decodeXML($dataMap[$attributeIdentifier]->attribute('data_text'));
                             $dataMap[$attributeIdentifier]->setContent($matrix);
                             $dataMap[$attributeIdentifier]->store();
                         }
                         break;
                     default:
                         eZDebug::writeError("Unsupported datatype for OpenOffice.org import: " . $dataMap[$attributeIdentifier]->DataTypeString);
                         break;
                 }
             }
         } else {
             // Check if attributes are already fetched
             if (!isset($titleAttribute) || !isset($bodyAttribute)) {
                 // Set attributes accorring to import class
                 $titleAttribute = $ooINI->variable($importClassIdentifier, 'DefaultImportTitleAttribute');
                 $bodyAttribute = $ooINI->variable($importClassIdentifier, 'DefaultImportBodyAttribute');
             }
             $objectName = basename($originalFileName);
             // Remove extension from name
             $objectName = preg_replace("/(\\....)\$/", "", $objectName);
             // Convert _ to spaces and upcase the first character
             $objectName = ucfirst(str_replace("_", " ", $objectName));
             $dataMap[$titleAttribute]->setAttribute('data_text', $objectName);
             $dataMap[$titleAttribute]->store();
             $dataMap[$bodyAttribute]->setAttribute('data_text', $xmlTextBody);
             $dataMap[$bodyAttribute]->store();
         }
         $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => $version->attribute('version')));
         $storeImagesInMedia = $ooINI->variable("ODFImport", "PlaceImagesInMedia") == "true";
         if ($storeImagesInMedia == true) {
             // Fetch object to get correct name
             $object = eZContentObject::fetch($contentObjectID);
             $contentINI = eZINI::instance('content.ini');
             $mediaRootNodeID = $contentINI->variable("NodeSettings", "MediaRootNode");
             $node = eZContentObjectTreeNode::fetch($mediaRootNodeID);
             $articleFolderName = $object->attribute('name');
             $importFolderName = $ooINI->variable('ODFImport', 'ImportedImagesMediaNodeName');
             $importNode = self::createSubNode($node, $importFolderName);
             $articleNode = self::createSubNode($importNode, $articleFolderName);
             $imageRootNode = $articleNode->attribute("node_id");
         } else {
             $imageRootNode = $object->attribute("main_node_id");
         }
         // Publish all embedded images as related objects
         foreach ($this->RelatedImageArray as $image) {
             // Publish related images
             $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $image['ID'], 'contentobject_version' => 1, 'parent_node' => $imageRootNode, 'is_main' => 1));
             $nodeAssignment->store();
             eZOperationHandler::execute('content', 'publish', array('object_id' => $image['ID'], 'version' => 1));
             $object->addContentObjectRelation($image['ID'], 1);
         }
         $mainNode = $object->attribute('main_node');
         // Create object stop.
         $importResult['Object'] = $object;
         $importResult['Published'] = $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE;
         if ($mainNode instanceof eZContentObjectTreeNode) {
             $importResult['MainNode'] = $mainNode;
             $importResult['URLAlias'] = $mainNode->attribute('url_alias');
             $importResult['NodeName'] = $mainNode->attribute('name');
         } else {
             $importResult['MainNode'] = false;
             $importResult['URLAlias'] = false;
             $importResult['NodeName'] = false;
         }
         $importResult['ClassIdentifier'] = $importClassIdentifier;
     } else {
         $this->setError(self::ERROR_ACCESSDENIED);
         return false;
     }
     // Clean up
     eZDir::recursiveDelete($uniqueImportDir);
     return $importResult;
 }
 /**
  * Unit test for eZContentFunctionCollection::fetchKeyword
  */
 public function testFetchKeyword()
 {
     $class1Identifier = __FUNCTION__ . '_1';
     // First create two content classes with a keyword attribute
     $class1 = new ezpClass($class1Identifier, $class1Identifier, '<title>');
     $class1->add('Title', 'title', 'ezstring');
     $class1->add('Keywords', 'keywords', 'ezkeyword');
     $class1->store();
     $class1ID = $class1->class->attribute('id');
     // Create an instance of each of these classes with attributes
     $object = new ezpObject($class1Identifier, 2);
     $object->title = __FUNCTION__;
     $object->keywords = "keyword1, keyword2, keyword3";
     $object->publish();
     // Fetch keywords for class 1
     $keywords = eZContentFunctionCollection::fetchKeyword('k', $class1ID, 0, 20);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(3, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
 }
 /**
  * Unit test for eZContentFunctionCollection::fetchKeyword
  */
 public function testFetchKeyword()
 {
     $class1Identifier = __FUNCTION__ . '_1';
     // First create two content classes with a keyword attribute
     $class1 = new ezpClass($class1Identifier, $class1Identifier, '<title>');
     $class1->add('Title', 'title', 'ezstring');
     $class1->add('Keywords', 'keywords', 'ezkeyword');
     $class1->store();
     $class1ID = $class1->class->attribute('id');
     // Create placeholder folders for objects
     $folder1 = new ezpObject('folder', 2);
     $folder1->title = __FUNCTION__ . ' A';
     $folder1->publish();
     $folder2 = new ezpObject('folder', 2);
     $folder2->title = __FUNCTION__ . ' B';
     $folder2->publish();
     $folder3 = new ezpObject('folder', $folder1->mainNode->node_id);
     $folder3->title = __FUNCTION__ . ' A';
     $folder3->publish();
     // Create an objects to test function
     $object0 = new ezpObject($class1Identifier, 2);
     $object0->title = __FUNCTION__ . ' A ';
     $object0->keywords = "keyword1, keyword2, keyword3";
     $object0->publish();
     $object1 = new ezpObject($class1Identifier, $folder1->mainNode->node_id);
     $object1->title = __FUNCTION__ . ' A ';
     $object1->keywords = "keyword1, keyword2, keyword3";
     $object1->publish();
     $object2 = new ezpObject($class1Identifier, $folder2->mainNode->node_id);
     $object2->title = __FUNCTION__ . ' C ';
     $object2->keywords = "keyword1, keyword2, keyword3";
     $object2->publish();
     $object3 = new ezpObject($class1Identifier, $folder3->mainNode->node_id);
     $object3->title = __FUNCTION__ . ' D ';
     $object3->keywords = "keyword1, keyword2, keyword3";
     $object3->publish();
     // Fetch keywords for class 1, on all scope
     $keywords = eZContentFunctionCollection::fetchKeyword('k', $class1ID, 0, 20);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(12, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keyword1 for class 1, not specifying parent node
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(4, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keyword1 for class 1, directly below parentNodeId (rootNode)
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), 2);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(1, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keywords for class 1, directly below parentNodeId (specific folder)
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), $folder1->mainNode->node_id);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(1, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keywords for class 1, from root folder, with depth equal to 2
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), 2, true, false, 2);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(3, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keywords for class 1, from sepecific node, with depth equal to 2
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), $folder1->mainNode->node_id, true, false, 2);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(2, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keywords for class 1, from root folder, with depth equal to 0 (unlimited)
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), 2, true, false, 0);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(4, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
     // Fetch keywords for class 1, from specific folder, with depth equal to 0 (unlimited)
     $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), $folder1->mainNode->node_id, true, false, 0);
     $this->assertInternalType('array', $keywords);
     $this->assertArrayHasKey('result', $keywords);
     $this->assertInternalType('array', $keywords['result']);
     $this->assertEquals(2, count($keywords['result']));
     foreach ($keywords['result'] as $result) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('keyword', $result);
         $this->assertArrayHasKey('link_object', $result);
         $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']);
     }
 }