/** * Load translation data (TBX file reader) * * @param string $filename TBX file to add, full path must be given for access * @param string $locale Locale has no effect for TBX because TBX defines all languages within * the source file * @param array $option OPTIONAL Options to use * @throws Zend_Translation_Exception * @return array */ protected function _loadTranslationData($filename, $locale, array $options = array()) { $this->_data = array(); if (!is_readable($filename)) { require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.'); } $encoding = $this->_findEncoding($filename); $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->_file, "_startElement", "_endElement"); xml_set_character_data_handler($this->_file, "_contentElement"); try { Zend_Xml_Security::scanFile($filename); } catch (Zend_Xml_Exception $e) { require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception($e->getMessage()); } if (!xml_parse($this->_file, file_get_contents($filename))) { $ex = sprintf('XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), $filename); xml_parser_free($this->_file); require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception($ex); } return $this->_data; }
/** * @param string $file * @return SimpleXMLElement * @throws XenForo_Exception */ public static function scanFile($file) { $xml = Zend_Xml_Security::scanFile($file); if (!$xml) { throw new XenForo_Exception("Invalid XML in {$file}"); } return $xml; }
/** * Returns a SimpleXML element from the provided file name (or XenForo_Upload object) * provided it is valid. If it is not valid, an error is thrown. * * @param string|XenForo_Upload $file * * @return SimpleXMLElement */ public function getXmlFromFile($file) { if ($file instanceof XenForo_Upload) { $file = $file->getTempFile(); } if (!file_exists($file)) { throw $this->_controller->responseException($this->_controller->responseError(new XenForo_Phrase('please_enter_valid_file_name_requested_file_not_read'))); } try { $xml = Zend_Xml_Security::scanFile($file); if ($xml) { return $xml; } } catch (Exception $e) { } throw $this->_controller->responseException($this->_controller->responseError(new XenForo_Phrase('provided_file_was_not_valid_xml_file'))); }
/** * Create auth adapter * * @param string $rolefile File containing XML with users and roles */ public function __construct($rolefile) { $this->_acl = new Zend_Acl(); $xml = Zend_Xml_Security::scanFile($rolefile); /* Roles file format: <roles> <role id=”admin”> <user name=”user1” password=”pwd”/> </role> <role id=”hr”> <user name=”user2” password=”pwd2”/> </role> </roles> */ foreach ($xml->role as $role) { $this->_acl->addRole(new Zend_Acl_Role((string) $role["id"])); foreach ($role->user as $user) { $this->_users[(string) $user["name"]] = array("password" => (string) $user["password"], "role" => (string) $role["id"]); } } }
/** * Find possible routing to other path or locale * * @param string $locale * @param string $path * @param string $attribute * @param string $value * @param array $temp * @throws Zend_Locale_Exception * @access private */ private static function _findRoute($locale, $path, $attribute, $value, &$temp) { // load locale file if not already in cache // needed for alias tag when referring to other locale if (empty(self::$_ldml[(string) $locale])) { $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml'; if (!file_exists($filename)) { //--//require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Missing locale file '{$filename}' for '{$locale}' locale."); } self::$_ldml[(string) $locale] = Zend_Xml_Security::scanFile($filename); } // search for 'alias' tag in the search path for redirection $search = ''; $tok = strtok($path, '/'); // parse the complete path if (!empty(self::$_ldml[(string) $locale])) { while ($tok !== false) { $search .= '/' . $tok; if (strpos($search, '[@') !== false) { while (strrpos($search, '[@') > strrpos($search, ']')) { $tok = strtok('/'); if (empty($tok)) { $search .= '/'; } $search = $search . '/' . $tok; } } $result = self::$_ldml[(string) $locale]->xpath($search . '/alias'); // alias found if (!empty($result)) { $source = $result[0]['source']; $newpath = $result[0]['path']; // new path - path //ldml is to ignore if ($newpath != '//ldml') { // other path - parse to make real path while (substr($newpath, 0, 3) == '../') { $newpath = substr($newpath, 3); $search = substr($search, 0, strrpos($search, '/')); } // truncate ../ to realpath otherwise problems with alias $path = $search . '/' . $newpath; while (($tok = strtok('/')) !== false) { $path = $path . '/' . $tok; } } // reroute to other locale if ($source != 'locale') { $locale = $source; } $temp = self::_getFile($locale, $path, $attribute, $value, $temp); return false; } $tok = strtok('/'); } } return true; }
/** * Packages a Windows Azure project structure. * * @command-name Create * @command-description Packages a Windows Azure project structure. * * @command-parameter-for $path Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to package. * @command-parameter-for $runDevFabric Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --RunDevFabric|-dev Required. Switch. Run and deploy to the Windows Azure development fabric. * @command-parameter-for $outputPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Optional. The output path for the resulting package. */ public function createPackageCommand($path, $runDevFabric, $outputPath) { // Create output paths if ($outputPath == '') { $outputPath = realpath($path . '/../'); } $packageOut = $outputPath . '/' . basename($path) . '.cspkg'; // Find Windows Azure SDK bin folder $windowsAzureSdkFolderCandidates = array_merge(isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles'] . '\\Windows Azure SDK\\*\\bin', GLOB_NOSORT) : array(), isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles(x86)'] . '\\Windows Azure SDK\\*\\bin', GLOB_NOSORT) : array(), isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramW6432'] . '\\Windows Azure SDK\\*\\bin', GLOB_NOSORT) : array()); if (count($windowsAzureSdkFolderCandidates) == 0) { throw new Zend_Service_Console_Exception('Could not locate Windows Azure SDK for PHP.'); } $cspack = '"' . $windowsAzureSdkFolderCandidates[0] . '\\cspack.exe' . '"'; $csrun = '"' . $windowsAzureSdkFolderCandidates[0] . '\\csrun.exe' . '"'; // Open the ServiceDefinition.csdef file and check for role paths $serviceDefinitionFile = $path . '/ServiceDefinition.csdef'; if (!file_exists($serviceDefinitionFile)) { require_once LIB_DIR . '/Zend/Service/Console/Exception.php'; throw new Zend_Service_Console_Exception('Could not locate ServiceDefinition.csdef at ' . $serviceDefinitionFile . '.'); } $serviceDefinition = Zend_Xml_Security::scanFile($serviceDefinitionFile); $xmlRoles = array(); if ($serviceDefinition->WebRole) { if (count($serviceDefinition->WebRole) > 1) { $xmlRoles = array_merge($xmlRoles, $serviceDefinition->WebRole); } else { $xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WebRole)); } } if ($serviceDefinition->WorkerRole) { if (count($serviceDefinition->WorkerRole) > 1) { $xmlRoles = array_merge($xmlRoles, $serviceDefinition->WorkerRole); } else { $xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WorkerRole)); } } // Build '/role:' command parameter $roleArgs = array(); foreach ($xmlRoles as $xmlRole) { if ($xmlRole["name"]) { $roleArgs[] = '/role:' . $xmlRole["name"] . ';' . realpath($path . '/' . $xmlRole["name"]); } } // Build command $command = $cspack; $args = array($path . '\\ServiceDefinition.csdef', implode(' ', $roleArgs), '/out:' . $packageOut); if ($runDevFabric) { $args[] = '/copyOnly'; } passthru($command . ' ' . implode(' ', $args)); // Can we copy a configuration file? $serviceConfigurationFile = $path . '/ServiceConfiguration.cscfg'; $serviceConfigurationFileOut = $outputPath . '/ServiceConfiguration.cscfg'; if (file_exists($serviceConfigurationFile) && !file_exists($serviceConfigurationFileOut)) { copy($serviceConfigurationFile, $serviceConfigurationFileOut); } // Do we have to start the development fabric? if ($runDevFabric) { passthru($csrun . ' /devstore:start /devfabric:start'); passthru($csrun . ' /removeAll'); passthru($csrun . ' /run:"' . $packageOut . ';' . $serviceConfigurationFileOut . '" /launchBrowser'); } }
public function testScanFile() { $file = tempnam(sys_get_temp_dir(), 'Zend_XML_Security'); file_put_contents($file, $this->_getXml()); $result = Zend_Xml_Security::scanFile($file); $this->assertTrue($result instanceof SimpleXMLElement); $this->assertEquals((string) $result->result, 'test'); unlink($file); }
/** * Loads the section $section from the config file (or string $xml for * access facilitated by nested object properties. * * Sections are defined in the XML as children of the root element. * * In order to extend another section, a section defines the "extends" * attribute having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "extends". * * The $options parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $options = array( * 'allowModifications' => false, * 'skipExtends' => false * ); * * @param string $xml XML file or string to process * @param mixed $section Section to process * @param array|boolean $options * @throws Zend_Config_Exception When xml is not set or cannot be loaded * @throws Zend_Config_Exception When section $sectionName cannot be found in $xml */ public function __construct($xml, $section = null, $options = false) { if (empty($xml)) { //require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['skipExtends'])) { $this->_skipExtends = (bool) $options['skipExtends']; } } set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed if (strstr($xml, '<?xml')) { $config = Zend_Xml_Security::scan($xml); } else { try { if (!($config = Zend_Xml_Security::scanFile($xml))) { //require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Error failed to load {$xml} file"); } } catch (Zend_Xml_Exception $e) { //require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($e->getMessage()); } } restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { //require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } if ($section === null) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } else { if (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config->{$sectionName})) { //require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$xml}"); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config->{$section})) { //require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$xml}"); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // Section in the XML file contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } } $this->_loadedSection = $section; }