function do_indices($node)
 {
     $this->indices = array();
     $doc = new DOMDOcument();
     $i_node = $doc->importNode($node, true);
     $xpath = new DOMXPath($doc);
     $count = 0;
     foreach ($i_node->childNodes as $cell) {
         if (!$cell instanceof DOMElement || $cell->tagName != 'Cell') {
             //could be text node with whitespace
             continue;
         }
         $count++;
         $header = $cell->textContent;
         $this->indices[$header] = $count;
     }
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 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;
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 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;
 }
Пример #6
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;
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
            }
            $data[$label]['sum'] += $len;
            $data[$label]['cnt']++;
        }
        foreach ($data as $label => $d) {
            $data[$label]['avg'] = round($d['sum'] / $d['cnt'], 0);
            if (!in_array($label, $this->labels)) {
                $this->labels[] = $label;
            }
        }
        $this->predata[] = $data;
        return $data;
    }
}
$input = new phpucJTLInput();
$dom = new DOMDOcument();
$dom->load($jtl);
$xpath = new DOMXPath($dom);
$input->processLog($xpath);
$nodes = $xpath->query('//testResults/sampleResult/@threadName');
$threadNames = array();
foreach ($nodes as $node) {
    $name = preg_replace('/ \\d+-\\d+$/S', '', $node->nodeValue);
    if (!in_array($name, $threadNames)) {
        $threadNames[] = $name;
    }
}
echo "Create JMeter result graphs... \n";
foreach ($threadNames as $threadName) {
    echo ' + ' . $threadName . '... ';
    $chart = new JTLLineChart();
Пример #9
0
 public function renderSvgPage($page, $templates, $style, $size = null)
 {
     if (!isset($page['photos'])) {
         return '';
     }
     $count_photos = count($page['photos']);
     //$template_id=$page['layout']['template_ids']['ph_count_'.$count_photos];
     $style_id = $style->id;
     //$page['layout']['style_id'];
     $placeholder_border_color_top_left = $style->placeholder_border_color_top_left;
     $placeholder_border_color_bottom_right = $style->placeholder_border_color_bottom_right;
     /*
     *
     * public $placeholder_border_color_top_left='#000000';
     
         public $placeholder_border_color_bottom_right='#FFFFFF';
     */
     $layout_index = 0;
     if (!empty($page['layout_index'])) {
         $layout_index = $page['layout_index'];
     }
     if (empty($templates[$count_photos][$layout_index])) {
         $layout_index = 0;
         $page['layout_index'] = 0;
     }
     if (!empty($templates[$count_photos])) {
         $svg = $templates[$count_photos][$layout_index]['svg'];
     } else {
         $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="700" height="250" viewBox="0 0 700 250" xml:space="preserve"><desc>Created with Fabric.js 1.4.0</desc><defs></defs>' . '<g transform="translate(0 0)"></g>' . '<rect x="-2" y="-125" rx="0" ry="0" width="4" height="250" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: black; opacity: 1;" transform="translate(350 125)"/>' . '</svg>';
     }
     /*if(!empty($page['text'])){
     
                 $svg=$templates[$template_id]['svg_text'];
             }*/
     $background_color = '#ffffff';
     //$page['layout']['background_color'];
     $background_image = false;
     //$page['layout']['background_image'];
     $photo_index = 0;
     $doc = new \DOMDOcument();
     $doc->loadxml($svg);
     //$xpath = new \DOMXpath($doc);
     //$childre=new \DOMNodeList();
     /*
     *
     * <?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
     <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="700" height="350" viewBox="0 0 700 350" xml:space="preserve"><desc>Created with Fabric.js 1.4.0</desc><defs></defs><g transform="translate(172.5 85)" data_name="1" data_value="1" passepartout="false" object_text="false" border_left="false" border_top="false" border_right="false" border_bottom="false" border_color="#FFFFFF" border_width="3"><rect x="-172.5" y="-85" rx="0" ry="0" width="345" height="170" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #ccc; opacity: 1;" transform="translate(0 0)"/><g transform="translate(0 0)"><text font-family="Arial" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #bbb; opacity: 1;" transform="translate(-11 39)"><tspan x="0" y="-26" fill="#bbb">1</tspan></text></g><g transform=""><path d="M 0 170 L 0 0 L 345 0 L 345 170 L 0 170 z" style="stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: transparent; opacity: 1; visibility: hidden;" transform="translate(-172.5 -85)" stroke-linecap="round" /></g></g><g transform="translate(83.75 265)" data_name="2" data_value="2" passepartout="false" object_text="false" border_left="false" border_top="false" border_right="false" border_bottom="false" border_color="#FFFFFF" border_width="3"><rect x="-83.75" y="-85" rx="0" ry="0" width="167.5" height="170" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #ccc; opacity: 1;" transform="translate(0 0)"/><g transform="translate(0 0)"><text font-family="Arial" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #bbb; opacity: 1;" transform="translate(-11 39)"><tspan x="0" y="-26" fill="#bbb">2</tspan></text></g><g transform=""><path d="M 0 170 L 0 0 L 167.5 0 L 167.5 170 L 0 170 z" style="stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: transparent; opacity: 1; visibility: hidden;" transform="translate(-83.5 -85)" stroke-linecap="round" /></g></g><g transform="translate(261.25 265)" data_name="3" data_value="3" passepartout="false" object_text="false" border_left="false" border_top="false" border_right="false" border_bottom="false" border_color="#FFFFFF" border_width="3"><rect x="-83.75" y="-85" rx="0" ry="0" width="167.5" height="170" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #ccc; opacity: 1;" transform="translate(0 0)"/><g transform="translate(0 0)"><text font-family="Arial" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #bbb; opacity: 1;" transform="translate(-11 39)"><tspan x="0" y="-26" fill="#bbb">3</tspan></text></g><g transform=""><path d="M 0 170 L 0 0 L 167.5 0 L 167.5 170 L 0 170 z" style="stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: transparent; opacity: 1; visibility: hidden;" transform="translate(-83.5 -85)" stroke-linecap="round" /></g></g><g transform="translate(438.75 85)" data_name="5" data_value="5" passepartout="false" object_text="false" border_left="false" border_top="false" border_right="false" border_bottom="false" border_color="#FFFFFF" border_width="3"><rect x="-83.75" y="-85" rx="0" ry="0" width="167.5" height="170" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #ccc; opacity: 1;" transform="translate(0 0)"/><g transform="translate(0 0)"><text font-family="Arial" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #bbb; opacity: 1;" transform="translate(-11 39)"><tspan x="0" y="-26" fill="#bbb">5</tspan></text></g><g transform=""><path d="M 0 170 L 0 0 L 167.5 0 L 167.5 170 L 0 170 z" style="stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: transparent; opacity: 1; visibility: hidden;" transform="translate(-83.5 -85)" stroke-linecap="round" /></g></g><g transform="translate(527.5 265)" data_name="6" data_value="6" passepartout="false" object_text="false" border_left="false" border_top="false" border_right="false" border_bottom="false" border_color="#FFFFFF" border_width="3"><rect x="-172.5" y="-85" rx="0" ry="0" width="345" height="170" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #ccc; opacity: 1;" transform="translate(0 0)"/><g transform="translate(0 0)"><text font-family="Arial" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #bbb; opacity: 1;" transform="translate(-11 39)"><tspan x="0" y="-26" fill="#bbb">6</tspan></text></g><g transform=""><path d="M 0 170 L 0 0 L 345 0 L 345 170 L 0 170 z" style="stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: transparent; opacity: 1; visibility: hidden;" transform="translate(-172.5 -85)" stroke-linecap="round" /></g></g><g transform="translate(616.25 85)" data_name="4" data_value="4" passepartout="false" object_text="false" border_left="false" border_top="false" border_right="false" border_bottom="false" border_color="#FFFFFF" border_width="3"><rect x="-83.75" y="-85" rx="0" ry="0" width="167.5" height="170" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #ccc; opacity: 1;" transform="translate(0 0)"/><g transform="translate(0 0)"><text font-family="Arial" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #bbb; opacity: 1;" transform="translate(-11 39)"><tspan x="0" y="-26" fill="#bbb">4</tspan></text></g><g transform=""><path d="M 0 170 L 0 0 L 167.5 0 L 167.5 170 L 0 170 z" style="stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: transparent; opacity: 1; visibility: hidden;" transform="translate(-83.5 -85)" stroke-linecap="round" /></g></g></svg>
     */
     $defs = null;
     $defsItem = null;
     for ($i = 0; $i < $doc->childNodes->length; $i++) {
         $childs = $doc->childNodes->item($i);
         //print_r($childs);
         if ($childs->hasChildNodes()) {
             for ($j = 0; $j < $childs->childNodes->length; $j++) {
                 $item = $childs->childNodes->item($j);
                 // echo $item->tagName.' ';
                 if ($item->tagName == 'defs') {
                     $defs = $item;
                 }
                 if ($defs) {
                     $defsItem = $item;
                     $defs = null;
                 }
                 if ($item->tagName == 'g') {
                     for ($a = 0; $a < $item->attributes->length; $a++) {
                         $attr = $item->attributes->item($a);
                         $data_name = $item->attributes->getNamedItem('data_name');
                         if ($data_name && $data_name->textContent) {
                             if ($item->childNodes) {
                                 for ($k = 0; $k < $item->childNodes->length; $k++) {
                                     $element_in_ph = $item->childNodes->item($k);
                                     if ($element_in_ph->tagName == 'rect') {
                                         $place_width = $element_in_ph->attributes->getNamedItem('width')->textContent;
                                         $place_height = $element_in_ph->attributes->getNamedItem('height')->textContent;
                                         $node = $doc->createDocumentFragment();
                                         if ($data_name->textContent != 'T') {
                                             $photo_index = intval($data_name->textContent) - 1;
                                             $photo_id = $page['photos'][$photo_index]['file_key'];
                                             if (!isset($page['photos'][$photo_index]['pos_dx'])) {
                                                 $page['photos'][$photo_index]['pos_dx'] = 0;
                                                 $page['photos'][$photo_index]['pos_dy'] = 0;
                                                 $page['photos'][$photo_index]['scale'] = 1;
                                                 // $page['photos'][$photo_index]['ext']=;
                                             }
                                             $pos_dx = $page['photos'][$photo_index]['pos_dx'];
                                             $pos_dy = $page['photos'][$photo_index]['pos_dy'];
                                             $scale = $page['photos'][$photo_index]['scale'];
                                             $ext = 'jpg';
                                             if (!empty($page['photos'][$photo_index]['ext'])) {
                                                 $ext = $page['photos'][$photo_index]['ext'];
                                             }
                                             $image_size = UserUrl::IMAGE_MIDDLE;
                                             //Нужено сделать выбор картинки на основании scale
                                             if ($size) {
                                                 $image_size = $size;
                                             }
                                             $photo_index++;
                                             $node->appendXML(ImagePlaceholderReplacer::widget(['user_id' => $this->user_id, 'photobook_id' => $this->id, 'photo_id' => $photo_id, 'place_width' => $place_width, 'place_height' => $place_height, 'real_width' => $this->data['sizes'][$photo_id]['width'], 'real_height' => $this->data['sizes'][$photo_id]['height'], 'mtime' => $this->data['sizes'][$photo_id]['mtime'], 'image_size' => $image_size, 'scale' => $scale, 'pos_dx' => $pos_dx, 'pos_dy' => $pos_dy, 'ext' => $ext, 'passpartu_left_top_border_color' => $placeholder_border_color_top_left, 'passpartu_right_bottom_border_color' => $placeholder_border_color_bottom_right]));
                                             $item->replaceChild($node, $element_in_ph);
                                         } else {
                                             $photo_id = $page['text']['file_id'];
                                             $image_size = UserUrl::IMAGE_MIDDLE;
                                             //Нужено сделать выбор картинки на основании scale
                                             if ($size) {
                                                 $image_size = $size;
                                             }
                                             $node->appendXML(TextPlaceholderReplacer::widget(['user_id' => $this->user_id, 'photobook_id' => $this->id, 'photo_id' => $photo_id, 'text_label' => $page['text']['text'], 'place_width' => $place_width, 'place_height' => $place_height, 'image_size' => $image_size]));
                                             $item->replaceChild($node, $element_in_ph);
                                         }
                                     } else {
                                         if ($element_in_ph->tagName == 'path') {
                                             $item->removeChild($element_in_ph);
                                         }
                                     }
                                     if ($element_in_ph->tagName == 'g' && $element_in_ph->hasChildNodes()) {
                                         // $element_in_ph->removeChild($element_in_ph->childNodes->item(0));
                                         try {
                                             $elem = $element_in_ph->childNodes->item(0);
                                             if ($elem->tagName == 'path') {
                                                 // print_r($elem);
                                                 //$element_in_ph->removeChild($elem);
                                             } else {
                                                 $element_in_ph->removeChild($elem);
                                             }
                                         } catch (\DOMException $e) {
                                         } catch (\ErrorException $e) {
                                         }
                                         //$element_in_ph->childNodes->item(0)->removeChild($element_in_ph->childNodes->item(0));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($defsItem) {
                 $node = $doc->createDocumentFragment();
                 $image_size = UserUrl::IMAGE_MIDDLE;
                 //Нужено сделать выбор картинки на основании scale
                 if ($size) {
                     $image_size = $size;
                 }
                 $content = '';
                 if ($background_image) {
                     $content = ImageBackgroundReplacer::widget(['style_id' => $style_id, 'file_key' => $background_image, 'image_size' => $image_size]);
                 }
                 // $node->appendXML('<rect x="0" y="0" rx="0" ry="0" width="700" height="250" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: '.$background_color.'; opacity: 1;" transform="translate(0 0)"/>'.$content);
                 $node->appendXML('<rect/>' . $content);
                 $childs->insertBefore($node, $defsItem);
             }
         }
     }
     return $doc->saveXML($doc);
 }
Пример #10
0
 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();
 }
Пример #11
0
    $translationFile = 'share/translations/' . $translationName . '/translation.ts';
}

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 )
Пример #12
0
 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;
 }
<?php

// Consider the following script:
$dom = new DOMDOcument();
$dom->load('0138.xml');
foreach ($dom->documentElement->childNodes as $child) {
    if ($child->nodeType == XML_ELEMENT_NODE && $child->nodeName == "item") {
        foreach ($child->childNodes as $item) {
            if ($item->nodeType == XML_ELEMENT_NODE && $item->nodeName == "title") {
                print "{$item->firstChild}->data\n";
            }
        }
    }
}
// Assuming the referenced XML document exists and matches the parsing logic, what should be displayed when this script is executed?
/*
1) None of the above															OK
2) The XML of each 'title' node
3) The XML of each 'item' node
4) "Title" for every title node in the document
5) The contents of every 'title' node which exists under an 'item' node
*/
Пример #14
0
/**
 * 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>";
        }
    }
}
Пример #15
0
/**
 * Creates XML structure with all modules wich can respond to "p_id" parameter in _GET (such as content and menus in catalog mode)
 *
 * @param array $options XML options:
 *                       root (string) : root node name
 *                       use (array)   : modules to scan (items or "*")
 *                       skip (array)  : filter array with modules names to use
 * @return DOMDocument
 */
function aliasCatchersAsXML($options = array('root' => 'alias-catchers', 'use' => array('*'), 'skip' => array()))
{
    $xml = new DOMDOcument('1.0', 'utf-8');
    $root_node_name = get_array_value($options, 'root', 'alias-catchers');
    $xml->appendChild($root_node = $xml->createElement($root_node_name));
    $skip_modules = get_array_value($options, 'skip', array());
    $use_modules = get_array_value($options, 'skip', array('*'));
    // content module
    if ((in_array('*', $use_modules) || in_array('content', $use_modules)) && !in_array('content', $skip_modules)) {
        if (($content_config_ok = module_get_config('content', $content_config)) && ($pages_table = get_array_value($content_config['config'], 'table', false, REGEXP_IDENTIFIER)) != false) {
            $root_node->appendChild($module_node = $xml->createElement('module'))->setAttribute('name', 'Страницы');
            $query = CMS::$DB->query("select alias, title from `{$pages_table}` order by title");
            while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                $module_node->appendChild($catcher_node = $xml->createElement('catcher'));
                $catcher_node->appendChild($xml->createElement('title'))->nodeValue = $row['title'];
                $catcher_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias'];
            }
        }
    }
    // menu module
    if ((in_array('*', $use_modules) || in_array('menu', $use_modules)) && !in_array('menu', $skip_modules)) {
        if ($menu_config_ok = module_get_config('menu', $menu_config)) {
            $root_node->appendChild($module_node = $xml->createElement('module'))->setAttribute('name', 'Каталоги');
            if (($menu_table = get_array_value($menu_config['config'], 'table_menu', false, REGEXP_IDENTIFIER)) != false) {
                $query = CMS::$DB->query("select alias, caption from `{$menu_table}` where alias > ''order by caption");
                while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                    $module_node->appendChild($catcher_node = $xml->createElement('catcher'));
                    $catcher_node->appendChild($xml->createElement('title'))->nodeValue = $row['caption'];
                    $catcher_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias'];
                }
            }
        }
    }
    return $xml;
}
Пример #16
0
 /**
  * Converts records from marc to xerxes_record and adds them to the master xml response
  * Also adds info on whether the record has already been saved this session. 
  *
  * @param DOMDOcument $objXml		master xml document
  * @param array $arrRecords			an array of marc records
  * @param bool $configMarcResults	whether to append the original marc records to the response
  * @return DOMDOcument				master xml response updated with record data
  */
 protected function addRecords($objXml, $arrRecords, $configMarcResults)
 {
     $objRecords = $objXml->createElement("records");
     $arrXerxesRecords = array();
     foreach ($arrRecords as $objRecord) {
         $objXerxesRecord = new Xerxes_MetalibRecord();
         $objXerxesRecord->loadXml($objRecord);
         array_push($arrXerxesRecords, $objXerxesRecord);
     }
     // enhance with links computed from metalib templates.
     Xerxes_MetalibRecord::completeUrlTemplates($arrXerxesRecords, $this->request, $this->registry);
     $position = $this->request->getProperty("startRecord");
     if ($position == "") {
         $position = 1;
     }
     foreach ($arrXerxesRecords as $objXerxesRecord) {
         $objRecordContainer = $objXml->createElement("record");
         $objRecords->appendChild($objRecordContainer);
         // basis for most of the links below
         $arrParams = array("base" => "metasearch", "group" => $this->request->getProperty("group"), "resultSet" => $objXerxesRecord->getResultSet(), "startRecord" => $objXerxesRecord->getRecordNumber());
         // full-text link
         $arrFullText = $arrParams;
         $arrFullText["action"] = "record";
         if ($this->request->getProperty("facet") != "") {
             // append this so the full record page knows how to get back
             $arrFullText["return"] = Xerxes_Framework_Parser::escapeXml($this->request->getServer("REQUEST_URI"));
         } else {
             // this is a regular (non-facet) result
             // we keep current resultset and position (rather than original resultset
             // and recordNumber) for the benefit of the merged set where these are different
             $arrFullText["resultSet"] = $this->request->getProperty("resultSet");
             $arrFullText["startRecord"] = $position;
         }
         $url = $this->request->url_for($arrFullText);
         $objUrlFull = $objXml->createElement("url_full", $url);
         $objRecordContainer->appendChild($objUrlFull);
         // save-delete link
         $arrSave = $arrParams;
         $arrSave["action"] = "save-delete";
         $url = $this->request->url_for($arrSave);
         $objUrlSave = $objXml->createElement("url_save_delete", $url);
         $objRecordContainer->appendChild($objUrlSave);
         // openurl redirect link
         $arrOpen = $arrParams;
         $arrOpen["action"] = "sfx";
         $url = $this->request->url_for($arrOpen);
         $objOpenUrl = $objXml->createElement("url_open", $url);
         $objRecordContainer->appendChild($objOpenUrl);
         // openurl kev context object please
         $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes");
         $kev = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL(null, $configSID));
         $objOpenUrl = $objXml->createElement("openurl_kev_co", $kev);
         $objRecordContainer->appendChild($objOpenUrl);
         // import xerxes xml
         $objXerxesXml = $objXerxesRecord->toXML();
         $objImportRecord = $objXml->importNode($objXerxesXml->documentElement, true);
         $objRecordContainer->appendChild($objImportRecord);
         // optionally import marc-xml
         if ($configMarcResults == true) {
             $objMarcRecord = $objXerxesRecord->getMarcXML();
             $objImportRecord = $objXml->importNode($objMarcRecord->getElementsByTagName("record")->item(0), true);
             $objRecordContainer->appendChild($objImportRecord);
         }
         $position++;
     }
     $objXml->documentElement->appendChild($objRecords);
     return $objXml;
 }