/** * Return top level Metalib KB categories as XML * * @param Xerxes_Framework_Request $objRequest * @param Xerxes_Framework_Registry $objRegistry * @return int status */ public function doExecute() { $objXml = new DOMDOcument(); $objData = new Xerxes_DataMap(); $lang = $this->request->getProperty("lang"); $arrResults = $objData->getCategories($lang); $x = 1; if (count($arrResults) > 0) { $objXml->loadXML("<categories />"); foreach ($arrResults as $objCategoryData) { $objCategory = $objXml->createElement("category"); $objCategory->setAttribute("position", $x); foreach ($objCategoryData->properties() as $key => $value) { if ($value != null) { $objElement = $objXml->createElement("{$key}", Xerxes_Framework_Parser::escapeXml($value)); $objCategory->appendChild($objElement); } } // add the url for the category $arrParams = array("base" => "databases", "action" => "subject", "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("url", $url); $objCategory->appendChild($objElement); $objXml->documentElement->appendChild($objCategory); $x++; } } $this->request->addDocument($objXml); return 1; }
/** * This static method has most of the actual logic for a snippet generator page. * This mainly entails constructing and adding some URLs in an <embed> block * used for pointing to various types of snippet inclusion. Subclass defines * the starting url properties (base, action, anything else neccesary for a * snippet display), and calls this. * * @param array $url_params * @param array $direct_url_params * @return unknown */ protected function doExecuteHelper(array $url_params, array $direct_url_params = null) { // default embed css to false, because it's awful. if ($this->request->getProperty("disp_embed_css") == "") { $this->request->setProperty("disp_embed_css", "false"); } $objXml = new DOMDOcument(); $objXml->loadXML("<embed_info />"); $properties = array_keys($this->request->getAllProperties()); $display_properties = array(); foreach ($properties as $p) { if (substr($p, 0, 5) == 'disp_') { array_push($display_properties, $p); } } // direct to resource non-embedded action url if ($direct_url_params) { $direct_url = $this->request->url_for($direct_url_params, true); $objXml->documentElement->appendChild($objXml->createElement("direct_url", $direct_url)); } // embedded urls $url_params["gen_full_urls"] = "true"; // base embedded action url $raw_embedded_action_url = $this->request->url_for($url_params, true); if (strpos($raw_embedded_action_url, '?') == 0) { $raw_embedded_action_url .= "?"; } $objXml->documentElement->appendChild($objXml->createElement("raw_embedded_action_url", $raw_embedded_action_url)); // direct embed url $url_params["disp_embed"] = "true"; foreach ($display_properties as $p) { $url_params[$p] = $this->request->getProperty($p); } $embed_ssi_url = $this->request->url_for($url_params, true); $objXml->documentElement->appendChild($objXml->createElement("embed_direct_url", $embed_ssi_url)); // now the js snippet url $url_params["format"] = "embed_html_js"; $embed_js_call_url = $this->request->url_for($url_params, true); $objXml->documentElement->appendChild($objXml->createElement("embed_js_call_url", $embed_js_call_url)); $this->request->addDocument($objXml); return 1; }
public function doExecute() { // If supplied in URL, use that (for future API use). // Nevermind, this is a privacy problem until we right access // controls for that future API use. //$username = $this->request->getProperty("username"); //if ( ! $username ) { // default to logged in user $username = $this->request->getSession("username"); //} // we can only do this if we have a real user (not temp user), otherwise // just add no XML. if ($username == null || !Xerxes_Framework_Restrict::isAuthenticatedUser($this->request)) { return 0; } $objXml = new DOMDOcument(); $objData = new Xerxes_DataMap(); $arrResults = $objData->getUserCreatedCategories($username); $x = 1; if (count($arrResults) > 0) { $objXml->loadXML("<userCategories />"); foreach ($arrResults as $objCategoryData) { $objCategory = $objXml->createElement("category"); $objCategory->setAttribute("position", $x); foreach ($objCategoryData->properties() as $key => $value) { if ($value != null) { $objElement = $objXml->createElement("{$key}", Xerxes_Framework_Parser::escapeXml($value)); $objCategory->appendChild($objElement); } } // add the url for the category $arrParams = array("base" => "collections", "action" => "subject", "username" => $username, "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("url", $url); $objCategory->appendChild($objElement); $objXml->documentElement->appendChild($objCategory); $x++; } } $this->request->addDocument($objXml); return 1; }
public function doExecute() { $objXml = new DOMDOcument(); $objXml->loadXML("<databases />"); $strID = $this->request->getProperty("id"); $strQuery = $this->request->getProperty("query"); $alpha = $this->request->getProperty("alpha"); $objDataMap = new Xerxes_DataMap(); $arrResults = array(); if ($strID) { $arrResults = $objDataMap->getDatabases($strID); if (count($arrResults) == 0) { throw new Xerxes_Exception_NotFound("Can not find database with id {$strID}"); } } elseif ($alpha != "") { $this->addAlphaList(); $arrResults = $objDataMap->getDatabasesStartingWith($alpha); } elseif ($strQuery) { $arrResults = $objDataMap->getDatabases(null, $strQuery); } elseif ($this->request->getProperty("suppress_full_db_list") != "true") { $this->addAlphaList(); // only show single letters, please if ($this->registry->getConfig("DATABASE_LIST_SINGLE_LETTER_DISPAY", false, false) && $this->request->getProperty("action") == "alphabetical") { $params = array("base" => "databases", "action" => "alphabetical", "alpha" => "A"); $link = $this->request->url_for($params); $this->request->setRedirect($link); return 0; } // all database $arrResults = $objDataMap->getDatabases(); } foreach ($arrResults as $objDatabaseData) { $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry); $objDatabase = $objXml->importNode($objDatabase, true); $objXml->documentElement->appendChild($objDatabase); } $this->request->addDocument($objXml); return 1; }
/** * 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; }
/** * Returns an ezcsseStyle object for given XML string * * @param string $source * @return ezcsseStyle */ static function createFromXML($source) { $newObj = new ezcsseStyle(); if ($source) { $dom = new DOMDOcument(); $success = $dom->loadXML($source); $root = $dom->documentElement; if ($root->hasAttributes()) { foreach ($root->attributes as $attr) { $newObj->setAttribute($attr->name, $attr->value); } } foreach ($root->childNodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'rule') { $newObj->addRule(ezcsseRule::createFromXML($node)); } elseif ($node->nodeType == XML_ELEMENT_NODE) { $newObj->setAttribute($node->nodeName, $node->nodeValue); } } } return $newObj; }
function __construct($pack, $mixModule) { $fileList = $mixModule->root->createPack('so')->createModule('XStyle')->selectFiles('|\\.xsl$|'); $fileList = array_merge($fileList, $pack->selectFiles('|\\.xsl$|')); $index = array(); foreach ($fileList as $file) { $index[] = array('xsl:include' => array('@href' => "../../{$file->id}?{$file->version}")); } $index = so_dom::make()->append(array('xsl:stylesheet' => array('@version' => '1.0', '@xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform', $index))); $mixModule->createFile('index.xsl')->content = $index; $compiled = so_dom::make('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" />'); foreach ($fileList as $file) { $docEl = DOMDocument::load($file->path)->documentElement; $prefix = $file->pack->name; $ns = $docEl->lookupNamespaceURI($prefix); if ($ns) { $compiled['@xmlns:' . $prefix] = $ns; } $compiled[] = array('#comment' => " {$file->id} ", $docEl->childNodes); } $mixModule->createFile('compiled.xsl')->content = $compiled; $minified = new DOMDOcument(); $minified->formatOutput = false; $minified->preserveWhiteSpace = false; $minified->loadXML($compiled); $mixModule->createFile('min.xsl')->content = $minified->C14N(); }
} if ( !file_exists( $translationFile ) ) $script->shutdown( 1, "Translation file $translationFile does not exist" ); $cli->output( $cli->stylize( 'file', $translationFile ) . ":", false ); $cli->output( " loading", false ); $fd = fopen( $translationFile, "rb" ); $transXML = fread( $fd, filesize( $translationFile ) ); fclose( $fd ); $cli->output( " parsing", false ); $tree = new DOMDOcument(); $success = $tree->loadXML( $transXML ); $cli->output( " validating", false ); if ( !eZTSTranslator::validateDOMTree( $tree ) ) $script->shutdown( 1, "XML text for file $translationFile did not validate" ); function handleContextNode( $context, $cli, $data ) { $contextName = null; $messages = array(); $context_children = $context->childNodes; foreach ( $context_children as $context_child ) { if ( $context_child->nodeType == XML_ELEMENT_NODE ) {
public function doExecute() { $objXml = new DOMDOcument(); $objXml->loadXML("<category />"); $strSubject = $this->request->getProperty("subject"); $strUser = $this->request->getProperty("username"); $objData = new Xerxes_DataMap(); $objCategoryData = null; // only fetch if we actually have params, avoid the fetch-everything phenomena if ($strSubject && $strUser) { $objCategoryData = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUser); } // if there hasn't if (!$objCategoryData) { if ($this->request->getRedirect()) { // nevermind, we're in the creation process, already redirected, // just end now. return 1; } else { throw new Xerxes_Exception_NotFound("text_collections_error_personal_collection_not_found"); } } // make sure they have access if (!$objCategoryData->published) { Xerxes_Helper::ensureSpecifiedUser($objCategoryData->owned_by_user, $this->request, $this->registry, "text_collections_error_private_collection"); } $y = 1; if ($objCategoryData != null) { $objXml->documentElement->setAttribute("name", $objCategoryData->name); $objXml->documentElement->setAttribute("normalized", $objCategoryData->normalized); $objXml->documentElement->setAttribute("owned_by_user", $objCategoryData->owned_by_user); $objXml->documentElement->setAttribute("published", $objCategoryData->published); // we treat the 'default' collection (usually 'My Saved Records') special // giving it less flexibility for simplicity, in the XSL/javascript. if ($this->isDefaultCollection($objCategoryData)) { $objXml->documentElement->setAttribute("is_default_collection", "yes"); } // standard url for the category $arrParams = array("base" => "collections", "action" => "subject", "username" => $strUser, "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("url", $url); $objXml->documentElement->appendChild($objElement); //edit url for the user-created category $arrParams = array("base" => "collections", "action" => "edit_form", "username" => $strUser, "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("edit_url", $url); $objXml->documentElement->appendChild($objElement); // the attributes of the subcategories $db_list_index = 1; foreach ($objCategoryData->subcategories as $objSubData) { $objSubCategory = $objXml->createElement("subcategory"); $objSubCategory->setAttribute("name", $objSubData->name); $objSubCategory->setAttribute("position", $y); $objSubCategory->setAttribute("id", $objSubData->id); $y++; // the database information foreach ($objSubData->databases as $objDatabaseData) { $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry, $db_list_index); $objDatabase = $objXml->importNode($objDatabase, true); $objSubCategory->appendChild($objDatabase); } $objXml->documentElement->appendChild($objSubCategory); } } $this->request->addDocument($objXml); return 1; }
/** * Extract files * * @param string $schemaDir Schema directory * @param string $schemaFile Schema files * @param bool $delOldDir Delete old directory * * @return void */ function extractFiles($schemaDir, $schemaFile, $delOldDir = false) { $baseDir = "modules/hprimxml/xsd"; $destinationDir = "{$baseDir}/{$schemaDir}"; $archivePath = "{$baseDir}/{$schemaFile}"; if ($delOldDir && file_exists($destinationDir)) { if (CMbPath::remove($destinationDir)) { echo "<div class='info'>Suppression de {$destinationDir}</div>"; } else { echo "<div class='error'>Impossible de supprimer le dossier {$destinationDir}</div>"; return; } } if (false != ($nbFiles = CMbPath::extract($archivePath, $destinationDir))) { echo "<div class='info'>Extraction de {$nbFiles} fichiers pour {$schemaDir}</div>"; } else { echo "<div class='error'>Impossible d'extraire l'archive {$schemaFile}</div>"; return; } if (CAppUI::conf("hprimxml concatenate_xsd")) { $rootFiles = glob("{$destinationDir}/msg*.xsd"); $includeFiles = array_diff(glob("{$destinationDir}/*.xsd"), $rootFiles); foreach ($rootFiles as $rootFile) { $xsd = new CHPrimXMLSchema(); $xsd->loadXML(file_get_contents($rootFile)); $xpath = new DOMXPath($xsd); $importFiles = array(); foreach ($includeFiles as $includeFile) { $include = new DOMDOcument(); $include->loadXML(file_get_contents($includeFile)); $isImport = false; foreach ($importFiles as $key => $value) { if (strpos($includeFile, $key) !== false) { $isImport = true; break; } } foreach ($include->documentElement->childNodes as $child) { $impNode = $xsd->importNode($child, true); $existing = false; if (in_array($impNode->nodeName, array("xsd:simpleType", "xsd:complexType"))) { $name = $impNode->getAttribute('name'); $existing = $xpath->query("//{$impNode->nodeName}[@name='{$name}']")->length > 0; } if ($isImport) { $xsd->documentElement->setAttribute("xmlns:insee", "http://www.hprim.org/inseeXML"); } if (!$existing) { $xsd->documentElement->appendChild($impNode); } } } $xsd->purgeImportedNamespaces(); $xsd->purgeIncludes(); file_put_contents(substr($rootFile, 0, -4) . ".xml", $xsd->saveXML()); echo "<div class='info'>Schéma concatené</div>"; } } }