/** * Checks if application cache is enabled for this controller/action, as set in rest.ini * * Default value will be [CacheSettings].ApplicationCache * This can be refined by setting a [<controllerClass>_<action>_CacheSettings] section (see comments in rest.ini). * * @return bool */ private function isCacheEnabled() { // Global switch if ( $this->restINI->variable( 'CacheSettings', 'ApplicationCache' ) !== 'enabled' ) { return false; } $routingInfos = $this->getRouter()->getRoutingInformation(); // Check if we have a specific setting for this controller/action $actionSectionName = $routingInfos->controllerClass . '_' . $routingInfos->action . '_CacheSettings'; if ( $this->restINI->hasVariable( $actionSectionName, 'ApplicationCache' ) ) { return $this->restINI->variable( $actionSectionName, 'ApplicationCache' ) === 'enabled'; } // Nothing at controller/action level, check at controller level $controllerSectionName = $routingInfos->controllerClass . '_CacheSettings'; if ( $this->restINI->hasVariable( $controllerSectionName, 'ApplicationCache' ) ) { return $this->restINI->variable( $controllerSectionName, 'ApplicationCache' ) === 'enabled'; } // Nothing at controller level, take the default value return $this->restINI->variable( 'CacheSettings', 'ApplicationCacheDefault' ) === 'enabled'; }
/** * Processes Open Graph metadata from object attributes * * @param eZContentObject $contentObject * @param array $returnArray * * @return array */ function processObject($contentObject, $returnArray) { if ($this->ogIni->hasVariable($contentObject->contentClassIdentifier(), 'LiteralMap')) { $literalValues = $this->ogIni->variable($contentObject->contentClassIdentifier(), 'LiteralMap'); if ($this->debug) { eZDebug::writeDebug($literalValues, 'LiteralMap'); } if ($literalValues) { foreach ($literalValues as $key => $value) { if (!empty($value)) { $returnArray[$key] = $value; } } } } if ($this->ogIni->hasVariable($contentObject->contentClassIdentifier(), 'AttributeMap')) { $attributeValues = $this->ogIni->variableArray($contentObject->contentClassIdentifier(), 'AttributeMap'); if ($this->debug) { eZDebug::writeDebug($attributeValues, 'AttributeMap'); } if ($attributeValues) { foreach ($attributeValues as $key => $value) { $contentObjectAttributeArray = $contentObject->fetchAttributesByIdentifier(array($value[0])); if (!is_array($contentObjectAttributeArray)) { continue; } $contentObjectAttributeArray = array_values($contentObjectAttributeArray); $contentObjectAttribute = $contentObjectAttributeArray[0]; if ($contentObjectAttribute instanceof eZContentObjectAttribute) { $openGraphHandler = ngOpenGraphBase::getInstance($contentObjectAttribute); if (count($value) == 1) { $data = $openGraphHandler->getData(); } else { if (count($value) == 2) { $data = $openGraphHandler->getDataMember($value[1]); } else { $data = ""; } } if (!empty($data)) { $returnArray[$key] = $data; } } } } } return $returnArray; }
function getVariable($block, $settingName, $iniFile, $path) { $ini = new eZINI($iniFile, $path, null, null, null, true, true); $result = $ini->hasVariable($block, $settingName) ? $ini->variable($block, $settingName) : false; $result = parseArrayToStr($result, '<br>'); return $result; }
if ( !$ini->save() ) { eZDebug::writeError( "Can't save ini file: $iniPath/$fileName.append" ); } unset( $baseIni ); unset( $ini ); // Remove variable from the global override if ( $siteAccess != "global_override" ) { $ini = new eZINI( $fileName . '.append', "settings/override", null, null, null, true, true ); foreach( $settings as $setting ) { if ( $ini->hasVariable( $setting[0], $setting[1] ) ) $ini->removeSetting( $setting[0], $setting[1] ); } if ( !$ini->save() ) { eZDebug::writeError( "Can't save ini file: $iniPath/$fileName.append" ); } unset($ini); } } $uri = $http->postVariable( 'RedirectURI', $http->sessionVariable( 'LastAccessedModifyingURI', '/' ) ); $module->redirectTo( $uri ); ?>
/** * Remove PathPrefix from url, if applicable (present in siteaccess and matched in url) * * @param eZINI $saIni eZINI instance of site.ini for the siteaccess to check * @param string $url * * @return bool true if no PathPrefix exists, or removed from url. false if not removed. */ protected static function removePathPrefixIfNeeded(eZINI $saIni, &$url) { if ($saIni->hasVariable('SiteAccessSettings', 'PathPrefix')) { $pathPrefix = $saIni->variable('SiteAccessSettings', 'PathPrefix'); if (!empty($pathPrefix)) { if (strpos($url, $pathPrefix . '/') === 0 || $pathPrefix === $url) { $url = substr($url, strlen($pathPrefix) + 1); } else { // PathPrefix exists, but not matched in url. return false; } } } return true; }
/** * Starts to run the import * @param array( SQLIImportItem ) $aImportItems * @throws SQLIImportBaseException * @throws ezcConfigurationNoConfigException */ public function runImport(array $aImportItems) { // First check if an import is already running if (SQLIImportToken::importIsRunning()) { throw new SQLIImportBaseException('Another import is already running. Aborting...', SQLIImportBaseException::IMPORT_ALREADY_RUNNING); } $this->token = SQLIImportToken::registerNewImport(); $this->handlePerformanceSettings(); if (empty($aImportItems)) { // If no source handler is provided, consider processing all source handlers available $aImportItems = $this->importINI->variable('ImportSettings', 'AvailableSourceHandlers'); } // Process import items one by one for ($i = 0, $iMax = count($aImportItems); $i < $iMax; ++$i) { try { if (!$aImportItems[$i] instanceof SQLIImportItem) { throw new SQLIImportRuntimeException('Invalid import item !'); } // Update status for import item $aImportItems[$i]->setAttribute('status', SQLIImportItem::STATUS_RUNNING); $aImportItems[$i]->store(); $this->currentImportItem = $aImportItems[$i]; // First check if this handler has all needed configuration $handler = $aImportItems[$i]->attribute('handler'); $handlerSection = $handler . '-HandlerSettings'; if (!$this->importINI->hasSection($handlerSection)) { // Check INI Section throw new ezcConfigurationNoConfigException('Error : Handler "' . $handler . '" does not have proper config section in sqliimport.ini !'); } if (!$this->importINI->hasVariable($handlerSection, 'ClassName')) { // Check if ClassName is properly defined throw new ezcConfigurationNoConfigException('Error : ClassName not defined for "' . $handler . '" in sqliimport.ini !'); } // Default values $handlerClassName = $this->importINI->variable($handlerSection, 'ClassName'); $handlerEnabled = true; $debug = false; $defaultParentNodeID = $this->importINI->variable('ImportSettings', 'DefaultParentNodeID'); $streamTimeout = $this->importINI->variable('ImportSettings', 'StreamTimeout'); if ($this->importINI->hasVariable($handlerSection, 'Enabled')) { $handlerEnabled = $this->importINI->variable($handlerSection, 'Enabled') === 'true'; } if ($this->importINI->hasVariable($handlerSection, 'Debug')) { $debug = $this->importINI->variable($handlerSection, 'Debug') === 'enabled'; } if ($this->importINI->hasVariable($handlerSection, 'DefaultParentNodeID')) { $localParentNodeID = $this->importINI->variable($handlerSection, 'DefaultParentNodeID'); $defaultParentNodeID = is_int($localParentNodeID) ? (int) $localParentNode : $defaultParentNodeID; } if ($this->importINI->hasVariable($handlerSection, 'StreamTimeout')) { $streamTimeout = (int) $this->importINI->variable($handlerSection, 'StreamTimeout'); } // Check $defaultParentNodeID and throw an exception if not consistent $parentNode = eZContentObjectTreeNode::fetch($defaultParentNodeID, false, false); if (!$parentNode) { throw new SQLIImportRuntimeException('Error : invalid DefaultParentNodeID ( ' . $defaultParentNodeID . ' )'); } unset($parentNode); // Check handler class validity if (!class_exists($handlerClassName)) { throw new SQLIImportRuntimeException('Error : invalid handler class "' . $handlerClassName . '". Did you regenerate autolads ?'); } // #################################### // ##### IMPORT HANDLER PROCESSING // #################################### // Instantiate the handler with appropriate options and process it. // Handler must implement ISQLIImportHandler and extend SQLIImportAbstractHandler $handlerOptions = $aImportItems[$i]->attribute('options'); $importHandler = new $handlerClassName($handlerOptions); if (!$importHandler instanceof ISQLIImportHandler || !$importHandler instanceof SQLIImportAbstractHandler) { throw new SQLIImportRuntimeException('Error : invalid handler "' . $handlerClassName . '". Must implement ISQLIImportHandler and extend SQLIImportAbstractHandler.'); } $importHandler->handlerConfArray = $this->importINI->group($handlerSection); $importHandler->initialize(); // Get process length to calculate advancement percentage to track advancement $processLength = $importHandler->getProcessLength(); $percentageAdvancementStep = 100 / $processLength; $handlerName = $importHandler->getHandlerName(); $handlerIdentifier = $importHandler->getHandlerIdentifier(); // Progress bar implementation $progressBarOptions = array('emptyChar' => ' ', 'barChar' => '='); $progressBar = new ezcConsoleProgressbar($this->output, $processLength, $progressBarOptions); $progressBar->start(); $this->cli->warning('Now processing "' . $handlerName . '" handler.'); $isInterrupted = false; while ($row = $importHandler->getNextRow()) { try { $progressBar->advance(); $startTime = time(); $importHandler->process($row); } catch (Exception $e) { SQLIImportLogger::logError('An error occurred during "' . $handlerIdentifier . '" import process : ' . $e->getMessage()); } $aImportItems[$i]->updateProgress($percentageAdvancementStep, $importHandler->getProgressionNotes()); // Now calculate process time for this iteration $endTime = time(); $diffTime = $endTime - $startTime; $oldProcessTime = $aImportItems[$i]->attribute('process_time'); $aImportItems[$i]->setAttribute('process_time', $oldProcessTime + $diffTime); $aImportItems[$i]->store(array('process_time')); // Interruption handling if ($aImportItems[$i]->isInterrupted()) { $this->cli->notice(); SQLIImportLogger::logNotice('Interruption has been requested for current import ! Cleaning and aborting process...'); $isInterrupted = true; break; } } $importHandler->cleanup(); $progressBar->finish(); $this->cli->notice(); unset($importHandler); if (!$isInterrupted) { $aImportItems[$i]->setAttribute('status', SQLIImportItem::STATUS_COMPLETED); $aImportItems[$i]->setAttribute('percentage', 100); // Force percentage to 100% $aImportItems[$i]->store(); } // #################################### // ##### END IMPORT HANDLER PROCESSING // #################################### } catch (Exception $e) { SQLIImportLogger::logError($e->getMessage()); $aImportItems[$i]->setAttribute('status', SQLIImportItem::STATUS_FAILED); $aImportItems[$i]->store(); if (isset($importHandler)) { $importHandler->cleanup(); unset($importHandler); } continue; } } }
function import($file, $placeNodeID, $originalFileName, $importType = "import", $upload = null) { // Use var-directory as temporary directory $tmpDir = getcwd() . "/" . eZSys::cacheDirectory(); $allowedTypes = $this->ooINI->variable('DocumentType', 'AllowedTypes'); $convertTypes = $this->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; } 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; } $dom = $this->getDOMDocument($file); if (isset($tmpToFile)) { unlink($tmpToFile); } if ($dom === null) { $this->setError(self::ERROR_PARSEXML); return false; } // Check if we have access to node $place_node = eZContentObjectTreeNode::fetch($placeNodeID); $contentClass = $this->getImportContentClass($dom); if (!$contentClass instanceof eZContentClass) { if (!$this->useCustomClass) { $importClassIdentifier = $this->ooINI->variable('ODFImport', 'DefaultImportClass'); eZDebug::writeError("Content class {$importClassIdentifier} specified in odf.ini does not exist."); $this->setError(self::ERROR_UNKNOWNCLASS, $importClassIdentifier); } else { eZDebug::writeError("Content class indicated in the document does not exist.."); $this->setError(self::ERROR_UNKNOWNCLASS); } return false; } $importClassIdentifier = $contentClass->attribute('identifier'); if (!$place_node instanceof eZContentObjectTreeNode) { $this->setError(self::ERROR_UNKNOWNNODE, ezpI18n::tr('extension/ezodf/import/error', "Unable to fetch node with id ") . $placeNodeID); return false; } if ($importType == "replace") { // Check if we are allowed to edit the node $functionCollection = new eZContentFunctionCollection(); $access = $functionCollection->checkAccess('edit', $place_node, false, false); } 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')); } if (!$access['result']) { $this->setError(self::ERROR_ACCESSDENIED); return false; } $importResult = array(); $sectionNodeHash = array(); // 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'); if ($this->useCustomClass && $sectionNodeArray->length > 0) { 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 (!$this->useCustomClass) { // 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; } if ($this->useCustomClass) { 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>"; } } } // Check if we should replace the current object or import a new if ($importType !== "replace") { $place_object = $place_node->attribute('object'); $sectionID = $place_object->attribute('section_id'); $creatorID = $this->currentUserID; $parentNodeID = $placeNodeID; $object = $contentClass->instantiate($creatorID, $sectionID); $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 ($this->ooINI->hasVariable($placeClassIdentifier, 'DefaultImportTitleAttribute') && $this->ooINI->hasVariable($placeClassIdentifier, 'DefaultImportBodyAttribute')) { $titleAttribute = $this->ooINI->variable($placeClassIdentifier, 'DefaultImportTitleAttribute'); $bodyAttribute = $this->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->createNewVersion(); $dataMap = $object->fetchDataMap($version->attribute('version')); } $contentObjectID = $object->attribute('id'); if ($this->useCustomClass) { // Initialize the actual object attributes $attributeArray = $this->ooINI->variable($importClassIdentifier, 'Attribute'); foreach ($attributeArray as $attributeIdentifier => $sectionName) { switch ($dataMap[$attributeIdentifier]->DataTypeString) { case "ezstring": case "eztext": $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": $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 $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 $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 = $this->ooINI->variable($importClassIdentifier, 'DefaultImportTitleAttribute'); $bodyAttribute = $this->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 = $this->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 = $this->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; // Clean up eZDir::recursiveDelete($this->ImportDir); return $importResult; }