Example #1
2
 function xmlParser()
 {
     $this->xml_obj = xml_parser_create();
     xml_set_object($this->xml_obj, $this);
     xml_set_character_data_handler($this->xml_obj, 'dataHandler');
     xml_set_element_handler($this->xml_obj, "startHandler", "endHandler");
 }
Example #2
1
 /**
  * Constructs FormFilter
  * @access public
  */
 function __construct()
 {
     $this->parser = xml_parser_create();
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, 'open', 'close');
     xml_set_character_data_handler($this->parser, 'data');
 }
Example #3
1
 public function parse($xml_or_arr)
 {
     if (is_array($xml_or_arr)) {
         $output = array();
         foreach ($xml_or_arr as $val) {
             $to = $this->parse($val);
             $output = array_merge($output, $to);
         }
         return $output;
     }
     //		echo '<h1>xml in parser:</h1><pre>'; print_r($xml); echo '</pre>';
     // if we don't start with a processing instruction,
     // we add an outer node just to ensure it's a valid xml document
     // (i.e. only a single root node)
     if (substr($xml_or_arr, 0, 2) != '<?') {
         $xml_or_arr = "<{$this->insertedNode}>" . $xml_or_arr . "</{$this->insertedNode}>";
     }
     $this->parser = xml_parser_create();
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, "tagOpen", "tagClosed");
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
     xml_set_character_data_handler($this->parser, "tagData");
     $this->xmldata = xml_parse($this->parser, $xml_or_arr);
     if (!$this->xmldata) {
         die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)));
     }
     xml_parser_free($this->parser);
     $this->parseCompleted();
     return $this->output;
 }
Example #4
0
 /**
  * Load translation data (TMX file reader)
  *
  * @param  string  $filename  TMX file to add, full path must be given for access
  * @param  string  $locale    Locale has no effect for TMX because TMX defines all languages within
  *                            the source file
  * @param  array   $option    OPTIONAL Options to use
  * @throws Zend_Translation_Exception
  */
 protected function _loadTranslationData($filename, $locale, array $options = array())
 {
     $options = array_merge($this->_options, $options);
     if ($options['clear']) {
         $this->_translate = array();
     }
     if (in_array('defined_language', $options) and !empty($options['defined_language'])) {
         $this->_defined = true;
     }
     if (!is_readable($filename)) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
     }
     $this->_file = xml_parser_create();
     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");
     if (!xml_parse($this->_file, file_get_contents($filename))) {
         $ex = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file));
         xml_parser_free($this->_file);
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception($ex);
     }
 }
Example #5
0
 public function xml() {
     $this->parser = xml_parser_create();    
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);    
     xml_set_object($this->parser, $this);    
     xml_set_element_handler($this->parser, 'open','close');    
     xml_set_character_data_handler($this->parser, 'data');    
 }
 function parseFile($fileLocation)
 {
     // reset it.
     $this->_docType = NULL;
     $this->_nameSpace = NULL;
     $this->_errors = NULL;
     $fp = @fopen($fileLocation, 'r');
     if ($fp) {
         $parser = xml_parser_create('ISO-8859-1');
         xml_set_object($parser, $this);
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, FALSE);
         xml_set_element_handler($parser, "_startElement", "_endElement");
         while ($data = fread($fp, 1024)) {
             if (strlen($this->_docType) > 0) {
                 break;
             }
             if (!xml_parse($parser, $data, feof($fp))) {
                 $error = xml_error_string(xml_get_error_code($parser));
                 break;
             }
         }
         xml_parser_free($parser);
         @fclose(fp);
         return TRUE;
     } else {
         $this->_errors[] = 'File ' . $fileLocation . ' could not be opened.';
         return FALSE;
     }
 }
Example #7
0
 /**
  * @return resource
  */
 protected function create()
 {
     $parser = xml_parser_create("UTF-8");
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     return $parser;
 }
Example #8
0
 function xml()
 {
     $this->parser = xml_parser_create();
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, "tag_open", "tag_close");
     xml_set_character_data_handler($this->parser, "cdata");
 }
Example #9
0
 public function parseXML($xml)
 {
     $xmlArray = null;
     $parser = xml_parser_create();
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
     xml_parse_into_struct($parser, $xml, $xmlArray, $indexdata);
     xml_parser_free($parser);
     $elements = array();
     $child = array();
     foreach ($xmlArray as $item) {
         $current = count($elements);
         if ($item['type'] == 'open' || $item['type'] == 'complete') {
             $elements[$current] = new \stdClass();
             $elements[$current]->tag = $item['tag'];
             $elements[$current]->attributes = array_key_exists('attributes', $item) ? $item['attributes'] : '';
             $elements[$current]->value = array_key_exists('value', $item) ? $item['value'] : '';
             if ($item['type'] == "open") {
                 $elements[$current]->children = array();
                 $child[count($child)] =& $elements;
                 $elements =& $elements[$current]->children;
             }
         } else {
             if ($item['type'] == 'close') {
                 $elements =& $child[count($child) - 1];
                 unset($child[count($child) - 1]);
             }
         }
     }
     if ($elements) {
         return $elements[0];
     } else {
         return null;
     }
 }
 function __construct()
 {
     $this->xml = xml_parser_create();
     xml_set_object($this->xml, $this);
     xml_set_character_data_handler($this->xml, 'dataHandler');
     xml_set_element_handler($this->xml, 'startHandler', 'endHandler');
 }
Example #11
0
 function parse($xml)
 {
     $this->result = array();
     $this->context = $xml;
     $this->currentTag = '';
     $this->currentState = array();
     $this->xmlParser = xml_parser_create();
     xml_parser_set_option($this->xmlParser, XML_OPTION_TARGET_ENCODING, "UTF-8") . xml_set_object($this->xmlParser, $this);
     xml_set_element_handler($this->xmlParser, 'startElement', 'endElement');
     xml_set_character_data_handler($this->xmlParser, 'content');
     $this->trigger('before:import');
     try {
         if (!xml_parse($this->xmlParser, $xml)) {
             $this->xmlParserError = 'Line ' . xml_get_current_line_number($this->xmlParser) . ': ' . (xml_get_error_code($this->xmlParser) ? xml_error_string(xml_get_error_code($this->xmlParser)) : 'Unknown error');
         }
     } catch (Exception $e) {
         $this->xmlParserError = $e->getMessage();
     }
     xml_parser_free($this->xmlParser);
     if ($this->xmlParserError) {
         $this->raiseError($this->xmlParserError);
     } else {
         if ($this->getCurrentState()) {
             $this->raiseError('Wrong ending state: ' . $this->getCurrentState());
         } else {
         }
     }
     $this->trigger('after:import');
     return $this->result;
 }
Example #12
0
 function __construct($charset = 'UTF-8')
 {
     $this->conf = array();
     $this->conf['error'] = '<br /><strong>Error on line %s of ' . __FILE__ . '</strong>: %s<br />';
     $this->conf['cache_path'] = dirname(__FILE__);
     $this->conf['cache_time'] = 180;
     $this->conf['debug_mode'] = true;
     $this->conf['fetch_mode'] = ONYX_FETCH_ASSOC;
     if (!function_exists('xml_parser_create')) {
         $this->raiseError(__LINE__ - 2, ONYX_ERR_NO_PARSER);
         return false;
     }
     if ($charset == 'native') {
         $charset = LANG_CHARSET;
     }
     $this->parser = @xml_parser_create($charset);
     if (!is_resource($this->parser)) {
         $this->raiseError(__LINE__ - 3, ONYX_ERR_NO_PARSER);
         return false;
     }
     xml_set_object($this->parser, $this);
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
     @xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, LANG_CHARSET);
     xml_set_element_handler($this->parser, 'tag_open', 'tag_close');
     xml_set_character_data_handler($this->parser, 'cdata');
 }
 function GetStatus($ip, $port, $pw)
 {
     error_reporting(0);
     $fp = fsockopen($ip, $port, $errno, $errstr, 1);
     if (!$fp) {
         error_reporting(E_ALL);
         $this->error = "{$errstr} ({$errno})";
         return 0;
     } else {
         error_reporting(E_ALL);
         socket_set_timeout($fp, 2);
         fputs($fp, "GET /stats?sid=1?pass="******"&mode=viewxml HTTP/1.1\r\n");
         //  original --> admin.cgi?pass
         fputs($fp, "User-Agent: Mozilla\r\n\r\n");
         while (!feof($fp)) {
             $this->SHOUTcastData .= fgets($fp, 512);
         }
         fclose($fp);
         if (stristr($this->SHOUTcastData, "HTTP/1.1 200 OK") == true) {
             $this->SHOUTcastData = trim(substr($this->SHOUTcastData, 58));
         } else {
             $this->error = "Bad login";
             return 0;
         }
         $xmlparser = xml_parser_create('UTF-8');
         //xml_parse_into_struct($xmlparser, $this->SHOUTcastData, $this->values, $this->indexes);
         if (!xml_parse_into_struct($xmlparser, $this->SHOUTcastData, $this->values, $this->indexes)) {
             $this->error = "Unparsable XML";
             return 0;
         }
         xml_parser_free($this->values);
         return 1;
     }
 }
Example #14
0
 protected function load()
 {
     global $zf_opmlItems, $zf_opmlMode;
     /* default values for parsing this opml file */
     $zf_opmlItems = array();
     $xml_parser = xml_parser_create();
     xml_set_element_handler($xml_parser, "zf_opmlStartElement", "zf_opmlEndElement");
     zf_debug('Opening file ' . $this->opmlfilename, DBG_OPML);
     @($fp = fopen($this->opmlfilename, "r"));
     $data = "";
     if ($fp) {
         $data = fread($fp, filesize($this->opmlfilename));
         fclose($fp);
         $xmlResult = xml_parse($xml_parser, $data);
         $xmlError = xml_error_string(xml_get_error_code($xml_parser));
         $xmlCrtline = xml_get_current_line_number($xml_parser);
         xml_parser_free($xml_parser);
         unset($data);
         if ($xmlResult) {
             $this->subscriptions = $zf_opmlItems;
             unset($zf_opmlItems);
         } else {
             $this->lastError = "Error parsing subscriptions file <br />error: {$xmlError} at line: {$xmlCrtline}";
             zf_debug("{$xmlError} at line: {$xmlCrtline}", DBG_OPML);
             return false;
         }
     } else {
         $this->lastError = 'Error opening the subscriptions file!';
         return false;
     }
     $this->_sanitize();
     return true;
 }
Example #15
0
 /**
  * Run the loader, to load up field-restrictions from the XML file.
  *
  * @param  string			The default breadcrumbs
  * @param  string			The breadcrumb XML data
  */
 function go($current_breadcrumbs, $data)
 {
     $this->tag_stack = array();
     $this->attribute_stack = array();
     $this->substitution_current_match_key = NULL;
     $this->substitution_current_label = NULL;
     $this->links = array();
     $this->substitutions = array();
     $breadcrumb_tpl = do_template('BREADCRUMB_ESCAPED');
     $this->breadcrumb_tpl = $breadcrumb_tpl->evaluate();
     $this->current_breadcrumbs = $current_breadcrumbs;
     // Create and setup our parser
     $xml_parser = @xml_parser_create();
     if ($xml_parser === false) {
         return;
         // PHP5 default build on windows comes with this function disabled, so we need to be able to escape on error
     }
     xml_set_object($xml_parser, $this);
     @xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, get_charset());
     @xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
     xml_set_element_handler($xml_parser, 'startElement', 'endElement');
     xml_set_character_data_handler($xml_parser, 'startText');
     // Run the parser
     if (@xml_parse($xml_parser, $data, true) == 0) {
         attach_message('breadcrumbs.xml: ' . xml_error_string(xml_get_error_code($xml_parser)), 'warn');
         return;
     }
     @xml_parser_free($xml_parser);
 }
Example #16
0
 function load($xml_file)
 {
     $this->_path = dirname($xml_file);
     if (!file_exists($xml_file)) {
         return;
     }
     $fp = @fopen($xml_file, "r");
     if ($fp) {
         $data = '';
         while (!feof($fp)) {
             $data .= fread($fp, 8192);
         }
         fclose($fp);
         if (ini_get("magic_quotes_gpc")) {
             $data = stripslashes($data);
         }
     }
     $this->_parser = xml_parser_create('UTF-8');
     xml_set_object($this->_parser, $this);
     xml_set_element_handler($this->_parser, "_saxStartElement", "_saxEndElement");
     xml_parser_set_option($this->_parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
     if (!xml_parse($this->_parser, $data, true)) {
         trigger_error(sprintf("Language pack loading failed, XML error: %s at line %d.", xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)), E_USER_ERROR);
     }
     xml_parser_free($this->_parser);
 }
Example #17
0
 public function __construct($input, $maxDepth = 20)
 {
     if (!is_string($input)) {
         throw new XmlToArrayException('No valid input.');
     }
     $this->_maxDepth = $maxDepth;
     $XMLParser = xml_parser_create();
     xml_parser_set_option($XMLParser, XML_OPTION_SKIP_WHITE, false);
     xml_parser_set_option($XMLParser, XML_OPTION_CASE_FOLDING, false);
     xml_parser_set_option($XMLParser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
     xml_set_character_data_handler($XMLParser, array($this, '_contents'));
     xml_set_default_handler($XMLParser, array($this, '_default'));
     xml_set_element_handler($XMLParser, array($this, '_start'), array($this, '_end'));
     xml_set_external_entity_ref_handler($XMLParser, array($this, '_externalEntity'));
     xml_set_notation_decl_handler($XMLParser, array($this, '_notationDecl'));
     xml_set_processing_instruction_handler($XMLParser, array($this, '_processingInstruction'));
     xml_set_unparsed_entity_decl_handler($XMLParser, array($this, '_unparsedEntityDecl'));
     if (!xml_parse($XMLParser, $input, true)) {
         $errorCode = xml_get_error_code($XMLParser);
         $message = sprintf('%s. line: %d, char: %d' . ($this->_tagStack ? ', tag: %s' : ''), xml_error_string($errorCode), xml_get_current_line_number($XMLParser), xml_get_current_column_number($XMLParser) + 1, implode('->', $this->_tagStack));
         xml_parser_free($XMLParser);
         throw new XmlToArrayException($message, $errorCode);
     }
     xml_parser_free($XMLParser);
 }
Example #18
0
 /**
  * Load translation data (XLIFF file reader)
  *
  * @param  string  $locale    Locale/Language to add data for, identical with locale identifier,
  *                            see Zend_Locale for more information
  * @param  string  $filename  XLIFF file to add, full path must be given for access
  * @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.');
     }
     if (empty($options['useId'])) {
         $this->_useId = false;
     } else {
         $this->_useId = true;
     }
     $encoding = $this->_findEncoding($filename);
     $this->_target = $locale;
     $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");
     if (!xml_parse($this->_file, file_get_contents($filename))) {
         $ex = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file));
         xml_parser_free($this->_file);
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception($ex);
     }
     return $this->_data;
 }
Example #19
0
 /**
  * 使用discuz词库
  * @param unknown_type $title
  * @param unknown_type $content
  */
 public static function discuz($title = '', $content = '')
 {
     $subjectenc = rawurlencode(strip_tags($title));
     $messageenc = rawurlencode(strip_tags(preg_replace("/\\[.+?\\]/U", '', $content)));
     $data = @implode('', file("http://keyword.discuz.com/related_kw.html?title={$subjectenc}&content={$messageenc}&ics=utf-8&ocs=utf-8"));
     if ($data) {
         $parser = xml_parser_create();
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
         xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
         xml_parse_into_struct($parser, $data, $values, $index);
         xml_parser_free($parser);
         $kws = array();
         foreach ($values as $valuearray) {
             if ($valuearray['tag'] == 'kw' || $valuearray['tag'] == 'ekw') {
                 $kws[] = trim($valuearray['value']);
             }
         }
         $return = '';
         if ($kws) {
             foreach ($kws as $kw) {
                 $kw = CHtml::encode(strip_tags($kw));
                 $return .= $dot . $kw;
                 $dot = ',';
             }
             $return = trim($return);
         }
         return $return;
     }
 }
 function analyser($file = "")
 {
     global $charset;
     if (!($fp = @fopen($this->file, "r"))) {
         die("impossible d'ouvrir le fichier {$this->file}");
     }
     $data = fread($fp, filesize($this->file));
     $rx = "/<?xml.*encoding=[\\'\"](.*?)[\\'\"].*?>/m";
     if (preg_match($rx, $data, $m)) {
         $encoding = strtoupper($m[1]);
     } else {
         $encoding = "ISO-8859-1";
     }
     $this->analyseur = xml_parser_create($encoding);
     xml_parser_set_option($this->analyseur, XML_OPTION_TARGET_ENCODING, $charset);
     xml_parser_set_option($this->analyseur, XML_OPTION_CASE_FOLDING, true);
     xml_set_object($this->analyseur, $this);
     xml_set_element_handler($this->analyseur, "debutBalise", "finBalise");
     xml_set_character_data_handler($this->analyseur, "texte");
     fclose($fp);
     if (!xml_parse($this->analyseur, $data, TRUE)) {
         die(sprintf("erreur XML %s à la ligne: %d ( {$this->file} )\n\n", xml_error_string(xml_get_error_code($this->analyseur)), xml_get_current_line_number($this->analyseur)));
     }
     xml_parser_free($this->analyseur);
 }
Example #21
0
 /**
  * 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;
 }
Example #22
0
 function openstats()
 {
     $fp = fsockopen($this->host, $this->port, $errno, $errstr, 10);
     if (!$fp) {
         $this->_error = "{$errstr} ({$errno})";
         return 0;
     } else {
         fputs($fp, "GET /admin.cgi?pass="******"&mode=viewxml HTTP/1.0\r\n");
         fputs($fp, "User-Agent: Mozilla\r\n\r\n");
         while (!feof($fp)) {
             $this->_xml .= fgets($fp, 512);
         }
         fclose($fp);
         if (stristr($this->_xml, "HTTP/1.0 200 OK") == true) {
             // <-H> Thanks to Blaster for this fix.. trim();
             $this->_xml = trim(substr($this->_xml, 42));
         } else {
             $this->_error = "Bad login";
             return 0;
         }
         $xmlparser = xml_parser_create();
         if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
             $this->_error = "Unparsable XML";
             return 0;
         }
         xml_parser_free($xmlparser);
         return 1;
     }
 }
 function MagpieRSS($source)
 {
     # if PHP xml isn't compiled in, die
     #
     if (!function_exists('xml_parser_create')) {
         trigger_error("Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php");
     }
     $parser = @xml_parser_create();
     if (!is_resource($parser)) {
         trigger_error("Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php");
     }
     $this->parser = $parser;
     # pass in parser, and a reference to this object
     # set up handlers
     #
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element');
     xml_set_character_data_handler($this->parser, 'feed_cdata');
     $status = xml_parse($this->parser, $source);
     if (!$status) {
         $errorcode = xml_get_error_code($this->parser);
         if ($errorcode != XML_ERROR_NONE) {
             $xml_error = xml_error_string($errorcode);
             $error_line = xml_get_current_line_number($this->parser);
             $error_col = xml_get_current_column_number($this->parser);
             $errormsg = "{$xml_error} at line {$error_line}, column {$error_col}";
             $this->error($errormsg);
         }
     }
     xml_parser_free($this->parser);
     $this->normalize();
 }
Example #24
0
 function reset()
 {
     if ($this->parser) {
         xml_parser_free($this->parser);
     }
     // XML file pointer
     $this->fp = 0;
     // which data has been read?
     $this->metaDataRead = 0;
     $this->allRead = 0;
     // to maintain track of where we are inside the XML file
     $this->inXml = 0;
     $this->inData = 0;
     $this->inMeta = 0;
     $this->inSkin = 0;
     $this->inTemplate = 0;
     $this->currentName = '';
     $this->currentPartName = '';
     // character data pile
     $this->cdata = '';
     // list of skinnames and templatenames (will be array of array)
     $this->skins = array();
     $this->templates = array();
     // extra info included in the XML files (e.g. installation notes)
     $this->info = '';
     // init XML parser
     $this->parser = xml_parser_create();
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, 'startElement', 'endElement');
     xml_set_character_data_handler($this->parser, 'characterData');
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
 }
Example #25
0
    /**
     * Load translation data (XMLTM file reader)
     *
     * @param  string  $locale    Locale/Language to add data for, identical with locale identifier,
     *                            see Zend_Locale for more information
     * @param  string  $filename  XMLTM file to add, full path must be given for access
     * @param  array   $option    OPTIONAL Options to use
     * @throws \Zend\Translator\Adapter\Exception\InvalidArgumentException
     * @throws \Zend\Translator\Adapter\Exception\InvalidFileTypeException
     * @return array
     */
    protected function _loadTranslationData($filename, $locale, array $options = array())
    {
        $this->_data = array();
        $this->_lang = $locale;
        if (!is_readable($filename)) {
            throw new InvalidArgumentException('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");

        if (!xml_parse($this->_file, file_get_contents($filename))) {
            $ex = sprintf('XML error: %s at line %d',
                          xml_error_string(xml_get_error_code($this->_file)),
                          xml_get_current_line_number($this->_file));
            xml_parser_free($this->_file);
            throw new InvalidFileTypeException($ex);
        }

        return $this->_data;
    }
Example #26
0
 public function __construct($dataDirectory)
 {
     //
     // Default to English for lack of anything better
     //
     $this->clientLang = 'en-us';
     //
     // See if we can find anything better
     //
     $matches = array();
     if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
         setlocale(LC_ALL, 'en-US');
         if (preg_match('/(en-US|fr-FR|de-DE|it-IT|es-ES|sv-SV|sv-SE|nl-NL)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) {
             $this->clientLang = strtolower($matches[1]);
         }
     }
     //
     // Pull in all of the strings we need
     //
     $lang2file = array("es-es" => "es-ES.xml", "en-us" => "en-US.xml", "de-de" => "de-DE.xml", "fr-fr" => "fr-FR.xml", "it-it" => "it-IT.xml", "nl-nl" => "nl-NL.xml", "sv-sv" => "sv-SE.xml", "sv-se" => "sv-SE.xml");
     $xml_parser = xml_parser_create();
     $l10nValues = array();
     $l10nIndexes = array();
     $l10nContents = file_get_contents("{$dataDirectory}/" . $lang2file[$this->getClientLang()]);
     if (!xml_parse_into_struct($xml_parser, $l10nContents, $l10nValues, $l10nIndexes)) {
         die(sprintf("l10n: XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
     } else {
         foreach ($l10nIndexes["STRING"] as $l10nStringIndex) {
             $this->l10n[$l10nValues[$l10nStringIndex]["attributes"]["ID"]] = $l10nValues[$l10nStringIndex]["value"];
         }
     }
     xml_parser_free($xml_parser);
 }
 function readConfig($filename)
 {
     // read the xml database
     //print "FILE: $filename";
     $data = implode("", file($filename));
     $parser = xml_parser_create();
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parse_into_struct($parser, $data, $values, $tags);
     xml_parser_free($parser);
     // loop through the structures
     foreach ($tags as $key => $val) {
         if ($key == "node") {
             $noderanges = $val;
             // each contiguous pair of array entries are the
             // lower and upper range for each node definition
             for ($i = 0; $i < count($noderanges); $i += 2) {
                 $offset = $noderanges[$i] + 1;
                 $len = $noderanges[$i + 1] - $offset;
                 $tdb[] = $this->parseXML(array_slice($values, $offset, $len));
             }
         } else {
             continue;
         }
     }
     return $tdb;
 }
Example #28
0
 function loadXML($file)
 {
     $this->_parser = xml_parser_create($this->getEncoding($file));
     // Auto detect for PHP4/PHP5
     xml_set_object($this->_parser, $this);
     xml_set_element_handler($this->_parser, "_saxStartElement", "_saxEndElement");
     xml_set_character_data_handler($this->_parser, "_saxCharacterData");
     xml_parser_set_option($this->_parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
     if ($fp = fopen($file, "r")) {
         $data = '';
         while (!feof($fp)) {
             $data .= fread($fp, 8192);
         }
         fclose($fp);
         // Strip slashes
         if (ini_get("magic_quotes_gpc")) {
             $data = stripslashes($data);
         }
         // XML parse
         if (!xml_parse($this->_parser, $data, true)) {
             trigger_error(sprintf("Language pack loading failed, XML error: %s at line %d.", xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)), FATAL);
         }
     } else {
         trigger_error("Could not open XML language pack: " . $file, FATAL);
     }
     xml_parser_free($this->_parser);
 }
function parseRSS($url)
{
    //PARSE RSS FEED
    $feedeed = implode('', file($url));
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $feedeed, $valueals, $index);
    xml_parser_free($parser);
    //CONSTRUCT ARRAY
    foreach ($valueals as $keyey => $valueal) {
        if ($valueal['type'] != 'cdata') {
            $item[$keyey] = $valueal;
        }
    }
    $i = 0;
    foreach ($item as $key => $value) {
        if ($value['type'] == 'open') {
            $i++;
            $itemame[$i] = $value['tag'];
        } elseif ($value['type'] == 'close') {
            $feed = $values[$i];
            $item = $itemame[$i];
            $i--;
            if (count($values[$i]) > 1) {
                $values[$i][$item][] = $feed;
            } else {
                $values[$i][$item] = $feed;
            }
        } else {
            $values[$i][$value['tag']] = $value['value'];
        }
    }
    //RETURN ARRAY VALUES
    return $values[0];
}
Example #30
-1
 /**
  * Constructor.
  *
  * @param string $xml         XML content.
  * @param string $encoding    Character set encoding, defaults to 'UTF-8'.
  * @param array $attachments  List of attachments.
  */
 function SOAP_Parser($xml, $encoding = SOAP_DEFAULT_ENCODING, $attachments = null)
 {
     parent::SOAP_Base('Parser');
     $this->_setSchemaVersion(SOAP_XML_SCHEMA_VERSION);
     $this->attachments = $attachments;
     // Check the XML tag for encoding.
     if (preg_match('/<\\?xml[^>]+encoding\\s*?=\\s*?(\'([^\']*)\'|"([^"]*)")[^>]*?[\\?]>/', $xml, $m)) {
         $encoding = strtoupper($m[2] ? $m[2] : $m[3]);
     }
     // Determine where in the message we are (envelope, header, body,
     // method). Check whether content has been read.
     if (!empty($xml)) {
         // Prepare the XML parser.
         $parser = xml_parser_create($encoding);
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
         xml_set_object($parser, $this);
         xml_set_element_handler($parser, '_startElement', '_endElement');
         xml_set_character_data_handler($parser, '_characterData');
         // Some lame SOAP implementations add nul bytes at the end of the
         // SOAP stream, and expat chokes on that.
         if ($xml[strlen($xml) - 1] == 0) {
             $xml = trim($xml);
         }
         // Parse the XML file.
         if (!xml_parse($parser, $xml, true)) {
             $err = sprintf('XML error on line %d col %d byte %d %s', xml_get_current_line_number($parser), xml_get_current_column_number($parser), xml_get_current_byte_index($parser), xml_error_string(xml_get_error_code($parser)));
             $this->_raiseSoapFault($err, htmlspecialchars($xml));
         }
         xml_parser_free($parser);
     }
 }