function parse() { set_error_handler(array(&$this, 'error_handler')); array_unshift($this->ns_contexts, array()); $parser = xml_parser_create_ns(); xml_set_object($parser, $this); xml_set_element_handler($parser, "start_element", "end_element"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_set_character_data_handler($parser, "cdata"); xml_set_default_handler($parser, "_default"); xml_set_start_namespace_decl_handler($parser, "start_ns"); xml_set_end_namespace_decl_handler($parser, "end_ns"); $this->content = ''; $ret = true; $fp = fopen($this->FILE, "r"); while ($data = fread($fp, 4096)) { if ($this->debug) { $this->content .= $data; } if (!xml_parse($parser, $data, feof($fp))) { trigger_error(sprintf(__('XML error: %s at line %d') . "\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); $ret = false; break; } } fclose($fp); xml_parser_free($parser); restore_error_handler(); return $ret; }
function XhldXmlAtomParser($input) { $this->parser = xml_parser_create('UTF-8'); xml_set_object($this->parser, $this); $this->input =& $input; $this->setCaseFolding(true); $this->useUtfEncoding(); $this->_parent[0] = ''; xml_set_element_handler($this->parser, "atom_start_element", "atom_end_element"); xml_set_character_data_handler($this->parser, "atom_character_data"); xml_set_start_namespace_decl_handler($this->parser, "atom_ns_start"); xml_set_end_namespace_decl_handler($this->parser, "atom_ns_end"); }
protected final function init() { if ($this instanceof Features\IXmlNamespaceParser) { $this->parser = xml_parser_create_ns('UTF-8'); // Set up start namespace declaration handler xml_set_start_namespace_decl_handler($this->parser, 'ns_start'); // Set up end namespace declaration handler xml_set_end_namespace_decl_handler($this->parser, 'ns_end'); } elseif ($this instanceof Features\IXmlBasicParser) { $this->parser = xml_parser_create('UTF-8'); } else { throw new \BadMethodCallException('This class does not implements the XML Parser capabilities. Please implement either IXmlBasicParser or IXmlNamespaceParser.'); } xml_set_object($this->parser, $this); foreach ($this->options as $option => $value) { xml_parser_set_option($this->parser, $option, $value); } if ($this instanceof Features\IXmlProcessorParser) { // Set up processing instruction (PI) handler xml_set_processing_instruction_handler($this->parser, 'pi_handler'); } if ($this instanceof Features\IXmlEntityHandler) { // Set up external entity reference handler xml_set_external_entity_ref_handler($this->parser, 'entity_handler'); } if ($this instanceof Features\IXmlNdataHandler) { // Set up notation declaration handler xml_set_notation_decl_handler($this->parser, 'notation_handler'); // Set up unparsed entity declaration handler xml_set_unparsed_entity_decl_handler($this->parser, 'ndata_handler'); } xml_set_element_handler($this->parser, "element_start", "element_end"); xml_set_character_data_handler($this->parser, "cdata_handler"); if ($this instanceof Features\IXmlDefaultHandler) { if (!defined('ACTIVATE_XML_PARSER_DEFAULT_HANDLER_I_KNOW_WHAT_AM_I_DOING')) { trigger_error('Active default handler interferes with many XML features like internal parsable entities.', E_USER_WARNING); } // Set up default (fallback) handler. // Warning: Interferes with INTERNAL ENTITY declarations like // <!ENTITY a 'b'> xml_set_default_handler($this->parser, "default_handler"); } }
/** * Register this class with a parser * * @param string $namespace (optional) * @param string $encoding (optional) default into to autodetect based on env * @param string $separator (optional) the seperator to use for namespace * @return resource the parser */ public function register($encoding = '', $namespace = false, $separator = null) { if ($this->parser === null) { if ($namespace !== null) { $this->parser = xml_parser_create_ns($encoding, $separator); } else { $this->parser = xml_parser_create($encoding); } if (!$this->parser) { throw new RegisterParserFailure('call to xml_parser_create() failed'); } # set element handler xml_set_element_handler($this->parser, array($this, "xmlStartTag"), array($this, "xmlEndTag")); # set CDATA hander xml_set_character_data_handler($this->parser, array($this, "xmlTagContent")); # set processing instructions handler xml_set_processing_instruction_handler($this->parser, array($this, "xmlPI")); # set the unparsed entity declaration handler xml_set_unparsed_entity_decl_handler($this->parser, array($this, "xmlUnparsedEntity")); # set the notation declaration handler function xml_set_notation_decl_handler($this->parser, array($this, "xmlNotation")); # set the external entity reference handler function xml_set_external_entity_ref_handler($this->parser, array($this, "xmlEentityRef")); # Sets the default handler function xml_set_default_handler($this->parser, array($this, "xmlDefault")); # Set a handler to be called when a namespace is declared. xml_set_start_namespace_decl_handler($this->parser, array($this, "xmlNSStart")); # Set a handler to be called when leaving the scope of a namespace declaration xml_set_end_namespace_decl_handler($this->parser, array($this, "xmlNSEnd")); # turn off case folding to stop element names from being uppercased; $this->setOption(XML_OPTION_CASE_FOLDING, false); //$this->setOption(XML_OPTION_SKIP_WHITE, true); } else { throw new ParserException('Parser already registered call XML::unregister() first'); } return $this->parser; }
/** * * @access protected */ function register() { xml_set_character_data_handler($this->parser, 'character_data'); xml_set_default_handler($this->parser, 'default_data'); xml_set_element_handler($this->parser, 'tag_open', 'tag_close'); xml_set_end_namespace_decl_handler($this->parser, 'end_namespace_decl'); xml_set_external_entity_ref_handler($this->parser, 'external_entity_ref'); xml_set_notation_decl_handler($this->parser, 'notation_decl'); xml_set_processing_instruction_handler($this->parser, 'processing_instruction'); xml_set_start_namespace_decl_handler($this->parser, 'start_namespace_decl'); xml_set_unparsed_entity_decl_handler($this->parser, 'unparsed_entity'); return $this->registered = 1; }
function SimplePie_Parser($data, $encoding, $return_xml = false) { $this->encoding = $encoding; // Strip BOM: // UTF-32 Big Endian BOM if (strpos($data, sprintf('%c%c%c%c', 0x0, 0x0, 0xfe, 0xff)) === 0) { $data = substr($data, 4); } else { if (strpos($data, sprintf('%c%c%c%c', 0xff, 0xfe, 0x0, 0x0)) === 0) { $data = substr($data, 4); } else { if (strpos($data, sprintf('%c%c', 0xfe, 0xff)) === 0) { $data = substr($data, 2); } else { if (strpos($data, sprintf('%c%c', 0xff, 0xfe)) === 0) { $data = substr($data, 2); } else { if (strpos($data, sprintf('%c%c%c', 0xef, 0xbb, 0xbf)) === 0) { $data = substr($data, 3); } } } } } // Make sure the XML prolog is sane and has the correct encoding if (preg_match('/^<\\?xml(.*)?>/msiU', $data, $prolog)) { $data = substr_replace($data, '', 0, strlen($prolog[0])); } $data = "<?xml version='1.0' encoding='{$encoding}'?>\n" . $data; // Put some data into CDATA blocks // If we're RSS if ((stristr($data, '<rss') || preg_match('/<([a-z0-9]+\\:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+\\:)?channel/mi', $data) || preg_match('/<([a-z0-9]+\\:)?item/mi', $data))) { $sp_elements = array('author', 'category', 'copyright', 'description', 'docs', 'generator', 'guid', 'language', 'lastBuildDate', 'link', 'managingEditor', 'pubDate', 'title', 'url', 'webMaster'); } else { $sp_elements = array('content', 'copyright', 'name', 'subtitle', 'summary', 'tagline', 'title'); } foreach ($sp_elements as $full) { $data = preg_replace_callback("/<({$full})((\\s*((\\w+:)?\\w+)\\s*=\\s*(\"([^\"]*)\"|'([^']*)'))*)\\s*(\\/>|>(.*)<\\/{$full}>)/msiU", array(&$this, 'add_cdata'), $data); } foreach ($sp_elements as $full) { // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above) $data = preg_replace_callback("/<({$full})((\\s*((\\w+:)?\\w+)\\s*=\\s*(\"([^\"]*)\"|'([^']*)'))*)\\s*(\\/>|><!\\[CDATA\\[(.*)\\]\\]><\\/{$full}>)/msiU", array(&$this, 'cdata_in_cdata'), $data); } // Return the XML, if so desired if ($return_xml) { $this->data =& $data; return; } // Create the parser $this->xml = xml_parser_create_ns($encoding); xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1); xml_set_object($this->xml, $this); xml_set_character_data_handler($this->xml, 'data_handler'); xml_set_element_handler($this->xml, 'start_handler', 'end_handler'); xml_set_start_namespace_decl_handler($this->xml, 'start_name_space'); xml_set_end_namespace_decl_handler($this->xml, 'end_name_space'); // Parse! if (!xml_parse($this->xml, $data)) { $this->data = null; $this->error_code = xml_get_error_code($this->xml); $this->error_string = xml_error_string($this->error_code); } $this->current_line = xml_get_current_line_number($this->xml); $this->current_column = xml_get_current_column_number($this->xml); $this->current_byte = xml_get_current_byte_index($this->xml); xml_parser_free($this->xml); return; }
<?php /* Prototype : proto int xml_set_end_namespace_decl_handler(resource parser, string hdl) * Description: Set up character data handler * Source code: ext/xml/xml.c * Alias to functions: */ echo "*** Testing xml_set_end_namespace_decl_handler() : error conditions ***\n"; //Test xml_set_end_namespace_decl_handler with one more than the expected number of arguments echo "\n-- Testing xml_set_end_namespace_decl_handler() function with more than expected no. of arguments --\n"; $hdl = 'string_val'; $extra_arg = 10; var_dump(xml_set_end_namespace_decl_handler(null, $hdl, $extra_arg)); // Testing xml_set_end_namespace_decl_handler with one less than the expected number of arguments echo "\n-- Testing xml_set_end_namespace_decl_handler() function with less than expected no. of arguments --\n"; var_dump(xml_set_end_namespace_decl_handler(null)); echo "Done";
function init() { // If Bypass Image Hotlink is enabled, send image to the page and quit. if ($this->bypass_image_hotlink) { if (isset($_GET[$this->bypass_image_hotlink]) && !empty($_GET[$this->bypass_image_hotlink])) { $this->display_image($_GET[$this->bypass_image_hotlink]); exit; } } // If Bypass Image Hotlink is enabled, send image to the page and quit. if (isset($_GET['js'])) { // JavaScript for the Odeo Player $embed = ''; $embed .= 'function embed_odeo(link) {'; $embed .= 'document.writeln(\''; $embed .= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '; $embed .= ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '; $embed .= ' width="440" '; $embed .= ' height="80" '; $embed .= ' align="middle">'; $embed .= '<param name="movie" value="http://odeo.com/flash/audio_player_fullsize.swf" />'; $embed .= '<param name="allowScriptAccess" value="any" />'; $embed .= '<param name="quality" value="high">'; $embed .= '<param name="wmode" value="transparent">'; $embed .= '<param name="flashvars" value="valid_sample_rate=true&external_url=\'+link+\'" />'; $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" '; $embed .= ' pluginspage="http://www.macromedia.com/go/getflashplayer" '; $embed .= ' type="application/x-shockwave-flash" '; $embed .= ' quality="high" '; $embed .= ' width="440" '; $embed .= ' height="80" '; $embed .= ' wmode="transparent" '; $embed .= ' allowScriptAccess="any" '; $embed .= ' flashvars="valid_sample_rate=true&external_url=\'+link+\'">'; $embed .= '</embed>'; $embed .= '</object>'; $embed .= '\');'; $embed .= '}'; $embed .= "\r\n"; $embed .= 'function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {'; $embed .= 'document.writeln(\''; $embed .= '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '; $embed .= ' style="cursor:hand; cursor:pointer;" '; $embed .= ' type="\'+type+\'" '; $embed .= ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" '; $embed .= ' bgcolor="\'+bgcolor+\'" '; $embed .= ' width="\'+width+\'" '; $embed .= ' height="\'+height+\'">'; $embed .= '<param name="href" value="\'+link+\'" />'; $embed .= '<param name="src" value="\'+placeholder+\'" />'; $embed .= '<param name="autoplay" value="false" />'; $embed .= '<param name="target" value="myself" />'; $embed .= '<param name="controller" value="false" />'; $embed .= '<param name="loop" value="\'+loop+\'" />'; $embed .= '<param name="scale" value="aspect" />'; $embed .= '<param name="bgcolor" value="\'+bgcolor+\'">'; $embed .= '<embed type="\'+type+\'" '; $embed .= ' style="cursor:hand; cursor:pointer;" '; $embed .= ' href="\'+link+\'" '; $embed .= ' src="\'+placeholder+\'"'; $embed .= ' width="\'+width+\'" '; $embed .= ' height="\'+height+\'" '; $embed .= ' autoplay="false" '; $embed .= ' target="myself" '; $embed .= ' controller="false" '; $embed .= ' loop="\'+loop+\'" '; $embed .= ' scale="aspect" '; $embed .= ' bgcolor="\'+bgcolor+\'" '; $embed .= ' pluginspage="http://www.apple.com/quicktime/download/">'; $embed .= '</embed>'; $embed .= '</object>'; $embed .= '\');'; $embed .= '}'; $embed .= "\r\n"; $embed .= 'function embed_flash(bgcolor, width, height, link, loop, type) {'; $embed .= 'document.writeln(\''; $embed .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '; $embed .= ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '; $embed .= ' bgcolor="\'+bgcolor+\'" '; $embed .= ' width="\'+width+\'" '; $embed .= ' height="\'+height+\'">'; $embed .= '<param name="movie" value="\'+link+\'">'; $embed .= '<param name="quality" value="high">'; $embed .= '<param name="loop" value="\'+loop+\'">'; $embed .= '<param name="bgcolor" value="\'+bgcolor+\'">'; $embed .= '<embed src="\'+link+\'" '; $embed .= ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" '; $embed .= ' type="\'+type+\'" '; $embed .= ' quality="high" '; $embed .= ' width="\'+width+\'" '; $embed .= ' height="\'+height+\'" '; $embed .= ' bgcolor="\'+bgcolor+\'" '; $embed .= ' loop="\'+loop+\'">'; $embed .= '</embed>'; $embed .= '</object>'; $embed .= '\');'; $embed .= '}'; $embed .= "\r\n"; $embed .= 'function embed_wmedia(width, height, link) {'; $embed .= 'document.writeln(\''; $embed .= '<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"'; $embed .= ' type="application/x-oleobject"'; $embed .= ' width="\'+width+\'"'; $embed .= ' height="\'+height+\'"'; $embed .= ' standby="Loading Windows Media Player...">'; $embed .= '<param name="FileName" value="\'+link+\'">'; $embed .= '<param name="autosize" value="true">'; $embed .= '<param name="ShowControls" value="true">'; $embed .= '<param name="ShowStatusBar" value="false">'; $embed .= '<param name="ShowDisplay" value="false">'; $embed .= '<param name="autostart" value="false">'; $embed .= '<embed type="application/x-mplayer2" '; $embed .= ' src="\'+link+\'" '; $embed .= ' autosize="1" '; $embed .= ' width="\'+width+\'" '; $embed .= ' height="\'+height+\'" '; $embed .= ' showcontrols="1" '; $embed .= ' showstatusbar="0" '; $embed .= ' showdisplay="0" '; $embed .= ' autostart="0">'; $embed .= '</embed>'; $embed .= '</object>'; $embed .= '\');'; $embed .= '}'; $embed .= "\r\n"; // enable gzip compression ob_start("ob_gzhandler"); header("Content-type: text/javascript; charset: UTF-8"); header("Cache-Control: must-revalidate"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24) . " GMT"); echo $embed; exit; } // If this is a .Mac Photocast, change it to the real URL. if (stristr($this->rss_url, 'http://photocast.mac.com')) { $this->rss_url = preg_replace('%http://photocast.mac.com%i', 'http://web.mac.com', $this->rss_url); } // Clear all outdated cache from the server's cache folder $this->clear_cache($this->cache_location, $this->max_minutes); if (!empty($this->rss_url)) { // Read the XML file for processing. $cache_filename = $this->cache_location . '/' . urlencode($this->rss_url) . '.spc'; if ($this->caching && !$this->xml_dump && substr($this->rss_url, 0, 7) == 'http://' && file_exists($cache_filename)) { if ($fp = fopen($cache_filename, 'r')) { $data = ''; while (!feof($fp)) { $data .= fread($fp, 2048); } fclose($fp); $mp_rss = unserialize($data); if (empty($mp_rss)) { $this->caching = false; return $this->init(); } else { if (isset($mp_rss['feed_url'])) { $this->rss_url = $mp_rss['feed_url']; return $this->init(); } else { $this->data = $mp_rss; return true; } } } else { $this->caching = false; return $this->init(); } } else { // Get the file $mp_rss = $this->get_file($this->rss_url); // Check if file is a feed or a webpage // If it's a webpage, auto-discover the feed and re-pass it to init() $discovery = $this->rss_locator($mp_rss, $this->rss_url); if ($discovery) { if ($discovery != $this->rss_url) { $this->rss_url = $discovery; if ($this->caching && substr($this->rss_url, 0, 7) == 'http://') { if ($this->is_writeable_createable($cache_filename)) { $fp = fopen($cache_filename, 'w'); fwrite($fp, serialize(array('feed_url' => $discovery))); fclose($fp); } else { trigger_error("{$cache_filename} is not writeable", E_USER_WARNING); } } return $this->init(); } } else { $this->sp_error("A feed could not be found at {$this->rss_url}", E_USER_WARNING, __FILE__, __LINE__); return false; } // Trim out any whitespace at the beginning or the end of the file $mp_rss = trim($mp_rss); // Get encoding // Attempt to support everything from libiconv (http://www.gnu.org/software/libiconv/) // Support everything from mbstring (http://www.php.net/manual/en/ref.mbstring.php#mbstring.supported-encodings) $use_iconv = false; $use_mbstring = false; $utf8_fail = true; if (preg_match('/encoding=["|\'](.*)["|\']/Ui', $mp_rss, $encoding)) { $match = $encoding; switch (strtolower($encoding[1])) { // 7bit case '7bit': case '7-bit': $encoding = '7bit'; $use_mbstring = true; break; // 8bit // 8bit case '8bit': case '8-bit': $encoding = '8bit'; $use_mbstring = true; break; // ARMSCII-8 // ARMSCII-8 case 'armscii-8': case 'armscii': $encoding = 'ARMSCII-8'; $use_iconv = true; break; // ASCII // ASCII case 'us-ascii': case 'ascii': $encoding = 'US-ASCII'; $use_iconv = true; $use_mbstring = true; $utf8_fail = false; break; // BASE64 // BASE64 case 'base64': case 'base-64': $encoding = 'BASE64'; $use_mbstring = true; break; // Big5 - Traditional Chinese, mainly used in Taiwan // Big5 - Traditional Chinese, mainly used in Taiwan case 'big5': case '950': $encoding = 'BIG5'; $use_iconv = true; $use_mbstring = true; break; // Big5 with Hong Kong extensions, Traditional Chinese // Big5 with Hong Kong extensions, Traditional Chinese case 'big5-hkscs': $encoding = 'BIG5-HKSCS'; $use_iconv = true; $use_mbstring = true; break; // byte2be // byte2be case 'byte2be': $encoding = 'byte2be'; $use_mbstring = true; break; // byte2le // byte2le case 'byte2le': $encoding = 'byte2le'; $use_mbstring = true; break; // byte4be // byte4be case 'byte4be': $encoding = 'byte4be'; $use_mbstring = true; break; // byte4le // byte4le case 'byte4le': $encoding = 'byte4le'; $use_mbstring = true; break; // EUC-CN // EUC-CN case 'euc-cn': case 'euccn': $encoding = 'EUC-CN'; $use_iconv = true; $use_mbstring = true; break; // EUC-JISX0213 // EUC-JISX0213 case 'euc-jisx0213': case 'eucjisx0213': $encoding = 'EUC-JISX0213'; $use_iconv = true; break; // EUC-JP // EUC-JP case 'euc-jp': case 'eucjp': $encoding = 'EUC-JP'; $use_iconv = true; $use_mbstring = true; break; // EUCJP-win // EUCJP-win case 'euc-jp-win': case 'eucjp-win': case 'eucjpwin': $encoding = 'EUCJP-win'; $use_iconv = true; $use_mbstring = true; break; // EUC-KR // EUC-KR case 'euc-kr': case 'euckr': $encoding = 'EUC-KR'; $use_iconv = true; $use_mbstring = true; break; // EUC-TW // EUC-TW case 'euc-tw': case 'euctw': $encoding = 'EUC-TW'; $use_iconv = true; $use_mbstring = true; break; // GB18030 - Simplified Chinese, national standard character set // GB18030 - Simplified Chinese, national standard character set case 'gb18030-2000': case 'gb18030': $encoding = 'GB18030'; $use_iconv = true; break; // GB2312 - Simplified Chinese, national standard character set // GB2312 - Simplified Chinese, national standard character set case 'gb2312': case '936': $encoding = 'GB2312'; $use_mbstring = true; break; // GBK // GBK case 'gbk': $encoding = 'GBK'; $use_iconv = true; break; // Georgian-Academy // Georgian-Academy case 'georgian-academy': $encoding = 'Georgian-Academy'; $use_iconv = true; break; // Georgian-PS // Georgian-PS case 'georgian-ps': $encoding = 'Georgian-PS'; $use_iconv = true; break; // HTML-ENTITIES // HTML-ENTITIES case 'html-entities': case 'htmlentities': $encoding = 'HTML-ENTITIES'; $use_mbstring = true; break; // HZ // HZ case 'hz': $encoding = 'HZ'; $use_iconv = true; $use_mbstring = true; break; // ISO-2022-CN // ISO-2022-CN case 'iso-2022-cn': case 'iso2022-cn': case 'iso2022cn': $encoding = 'ISO-2022-CN'; $use_iconv = true; break; // ISO-2022-CN-EXT // ISO-2022-CN-EXT case 'iso-2022-cn-ext': case 'iso2022-cn-ext': case 'iso2022cn-ext': case 'iso2022cnext': $encoding = 'ISO-2022-CN'; $use_iconv = true; break; // ISO-2022-JP // ISO-2022-JP case 'iso-2022-jp': case 'iso2022-jp': case 'iso2022jp': $encoding = 'ISO-2022-JP'; $use_iconv = true; $use_mbstring = true; break; // ISO-2022-JP-1 // ISO-2022-JP-1 case 'iso-2022-jp-1': case 'iso2022-jp-1': case 'iso2022jp-1': case 'iso2022jp1': $encoding = 'ISO-2022-JP-1'; $use_iconv = true; break; // ISO-2022-JP-2 // ISO-2022-JP-2 case 'iso-2022-jp-2': case 'iso2022-jp-2': case 'iso2022jp-2': case 'iso2022jp2': $encoding = 'ISO-2022-JP-2'; $use_iconv = true; break; // ISO-2022-JP-3 // ISO-2022-JP-3 case 'iso-2022-jp-3': case 'iso2022-jp-3': case 'iso2022jp-3': case 'iso2022jp3': $encoding = 'ISO-2022-JP-3'; $use_iconv = true; break; // ISO-2022-KR // ISO-2022-KR case 'iso-2022-kr': case 'iso2022-kr': case 'iso2022kr': $encoding = 'ISO-2022-KR'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-1 // ISO-8859-1 case 'iso-8859-1': case 'iso8859-1': $encoding = 'ISO-8859-1'; $use_iconv = true; $use_mbstring = true; $utf8_fail = false; break; // ISO-8859-2 // ISO-8859-2 case 'iso-8859-2': case 'iso8859-2': $encoding = 'ISO-8859-2'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-3 // ISO-8859-3 case 'iso-8859-3': case 'iso8859-3': $encoding = 'ISO-8859-3'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-4 // ISO-8859-4 case 'iso-8859-4': case 'iso8859-4': $encoding = 'ISO-8859-4'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-5 // ISO-8859-5 case 'iso-8859-5': case 'iso8859-5': $encoding = 'ISO-8859-5'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-6 // ISO-8859-6 case 'iso-8859-6': case 'iso8859-6': $encoding = 'ISO-8859-6'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-7 // ISO-8859-7 case 'iso-8859-7': case 'iso8859-7': $encoding = 'ISO-8859-7'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-8 // ISO-8859-8 case 'iso-8859-8': case 'iso8859-8': $encoding = 'ISO-8859-8'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-9 // ISO-8859-9 case 'iso-8859-9': case 'iso8859-9': $encoding = 'ISO-8859-9'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-10 // ISO-8859-10 case 'iso-8859-10': case 'iso8859-10': $encoding = 'ISO-8859-10'; $use_iconv = true; $use_mbstring = true; break; // mbstring/iconv functions don't appear to support 11 & 12 // ISO-8859-13 // mbstring/iconv functions don't appear to support 11 & 12 // ISO-8859-13 case 'iso-8859-13': case 'iso8859-13': $encoding = 'ISO-8859-13'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-14 // ISO-8859-14 case 'iso-8859-14': case 'iso8859-14': $encoding = 'ISO-8859-14'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-15 // ISO-8859-15 case 'iso-8859-15': case 'iso8859-15': $encoding = 'ISO-8859-15'; $use_iconv = true; $use_mbstring = true; break; // ISO-8859-16 // ISO-8859-16 case 'iso-8859-16': case 'iso8859-16': $encoding = 'ISO-8859-16'; $use_iconv = true; break; // JIS // JIS case 'jis': $encoding = 'JIS'; $use_mbstring = true; break; // JOHAB - Korean // JOHAB - Korean case 'johab': $encoding = 'JOHAB'; $use_iconv = true; break; // Russian // Russian case 'koi8-r': case 'koi8r': $encoding = 'KOI8-R'; $use_iconv = true; $use_mbstring = true; break; // Turkish // Turkish case 'koi8-t': case 'koi8t': $encoding = 'KOI8-T'; $use_iconv = true; break; // Ukrainian // Ukrainian case 'koi8-u': case 'koi8u': $encoding = 'KOI8-U'; $use_iconv = true; break; // Russian+Ukrainian // Russian+Ukrainian case 'koi8-ru': case 'koi8ru': $encoding = 'KOI8-RU'; $use_iconv = true; break; // Macintosh (Mac OS Classic) // Macintosh (Mac OS Classic) case 'macintosh': $encoding = 'Macintosh'; $use_iconv = true; break; // MacArabic (Mac OS Classic) // MacArabic (Mac OS Classic) case 'macarabic': $encoding = 'MacArabic'; $use_iconv = true; break; // MacCentralEurope (Mac OS Classic) // MacCentralEurope (Mac OS Classic) case 'maccentraleurope': $encoding = 'MacCentralEurope'; $use_iconv = true; break; // MacCroatian (Mac OS Classic) // MacCroatian (Mac OS Classic) case 'maccroatian': $encoding = 'MacCroatian'; $use_iconv = true; break; // MacCyrillic (Mac OS Classic) // MacCyrillic (Mac OS Classic) case 'maccyrillic': $encoding = 'MacCyrillic'; $use_iconv = true; break; // MacGreek (Mac OS Classic) // MacGreek (Mac OS Classic) case 'macgreek': $encoding = 'MacGreek'; $use_iconv = true; break; // MacHebrew (Mac OS Classic) // MacHebrew (Mac OS Classic) case 'machebrew': $encoding = 'MacHebrew'; $use_iconv = true; break; // MacIceland (Mac OS Classic) // MacIceland (Mac OS Classic) case 'maciceland': $encoding = 'MacIceland'; $use_iconv = true; break; // MacRoman (Mac OS Classic) // MacRoman (Mac OS Classic) case 'macroman': $encoding = 'MacRoman'; $use_iconv = true; break; // MacRomania (Mac OS Classic) // MacRomania (Mac OS Classic) case 'macromania': $encoding = 'MacRomania'; $use_iconv = true; break; // MacThai (Mac OS Classic) // MacThai (Mac OS Classic) case 'macthai': $encoding = 'MacThai'; $use_iconv = true; break; // MacTurkish (Mac OS Classic) // MacTurkish (Mac OS Classic) case 'macturkish': $encoding = 'MacTurkish'; $use_iconv = true; break; // MacUkraine (Mac OS Classic) // MacUkraine (Mac OS Classic) case 'macukraine': $encoding = 'MacUkraine'; $use_iconv = true; break; // MuleLao-1 // MuleLao-1 case 'mulelao-1': case 'mulelao1': $encoding = 'MuleLao-1'; $use_iconv = true; break; // Shift_JIS // Shift_JIS case 'shift_jis': case 'sjis': case '932': $encoding = 'Shift_JIS'; $use_iconv = true; $use_mbstring = true; break; // Shift_JISX0213 // Shift_JISX0213 case 'shift-jisx0213': case 'shiftjisx0213': $encoding = 'Shift_JISX0213'; $use_iconv = true; break; // SJIS-win // SJIS-win case 'sjis-win': case 'sjiswin': case 'shift_jis-win': $encoding = 'SJIS-win'; $use_iconv = true; $use_mbstring = true; break; // TCVN - Vietnamese // TCVN - Vietnamese case 'tcvn': $encoding = 'TCVN'; $use_iconv = true; break; // TDS565 - Turkish // TDS565 - Turkish case 'tds565': $encoding = 'TDS565'; $use_iconv = true; break; // TIS-620 Thai // TIS-620 Thai case 'tis-620': case 'tis620': $encoding = 'TIS-620'; $use_iconv = true; $use_mbstring = true; break; // UCS-2 // UCS-2 case 'ucs-2': case 'ucs2': case 'utf-16': case 'utf16': $encoding = 'UCS-2'; $use_iconv = true; $use_mbstring = true; break; // UCS-2BE // UCS-2BE case 'ucs-2be': case 'ucs2be': case 'utf-16be': case 'utf16be': $encoding = 'UCS-2BE'; $use_iconv = true; $use_mbstring = true; break; // UCS-2LE // UCS-2LE case 'ucs-2le': case 'ucs2le': case 'utf-16le': case 'utf16le': $encoding = 'UCS-2LE'; $use_iconv = true; $use_mbstring = true; break; // UCS-2-INTERNAL // UCS-2-INTERNAL case 'ucs-2-internal': case 'ucs2internal': $encoding = 'UCS-2-INTERNAL'; $use_iconv = true; break; // UCS-4 // UCS-4 case 'ucs-4': case 'ucs4': case 'utf-32': case 'utf32': $encoding = 'UCS-4'; $use_iconv = true; $use_mbstring = true; break; // UCS-4BE // UCS-4BE case 'ucs-4be': case 'ucs4be': case 'utf-32be': case 'utf32be': $encoding = 'UCS-4BE'; $use_iconv = true; $use_mbstring = true; break; // UCS-4LE // UCS-4LE case 'ucs-4le': case 'ucs4le': case 'utf-32le': case 'utf32le': $encoding = 'UCS-4LE'; $use_iconv = true; $use_mbstring = true; break; // UCS-4-INTERNAL // UCS-4-INTERNAL case 'ucs-4-internal': case 'ucs4internal': $encoding = 'UCS-4-INTERNAL'; $use_iconv = true; break; // UCS-16 // UCS-16 case 'ucs-16': case 'ucs16': $encoding = 'UCS-16'; $use_iconv = true; $use_mbstring = true; break; // UCS-16BE // UCS-16BE case 'ucs-16be': case 'ucs16be': $encoding = 'UCS-16BE'; $use_iconv = true; $use_mbstring = true; break; // UCS-16LE // UCS-16LE case 'ucs-16le': case 'ucs16le': $encoding = 'UCS-16LE'; $use_iconv = true; $use_mbstring = true; break; // UCS-32 // UCS-32 case 'ucs-32': case 'ucs32': $encoding = 'UCS-32'; $use_iconv = true; $use_mbstring = true; break; // UCS-32BE // UCS-32BE case 'ucs-32be': case 'ucs32be': $encoding = 'UCS-32BE'; $use_iconv = true; $use_mbstring = true; break; // UCS-32LE // UCS-32LE case 'ucs-32le': case 'ucs32le': $encoding = 'UCS-32LE'; $use_iconv = true; $use_mbstring = true; break; // UTF-7 // UTF-7 case 'utf-7': case 'utf7': $encoding = 'UTF-7'; $use_iconv = true; $use_mbstring = true; break; // UTF7-IMAP // UTF7-IMAP case 'utf-7-imap': case 'utf7-imap': case 'utf7imap': $encoding = 'UTF7-IMAP'; $use_mbstring = true; break; // VISCII - Vietnamese ASCII // VISCII - Vietnamese ASCII case 'viscii': $encoding = 'VISCII'; $use_iconv = true; break; // Windows-specific Central & Eastern Europe // Windows-specific Central & Eastern Europe case 'cp1250': case 'windows-1250': case 'win-1250': case '1250': $encoding = 'Windows-1250'; $use_iconv = true; break; // Windows-specific Cyrillic // Windows-specific Cyrillic case 'cp1251': case 'windows-1251': case 'win-1251': case '1251': $encoding = 'Windows-1251'; $use_iconv = true; $use_mbstring = true; break; // Windows-specific Western Europe // Windows-specific Western Europe case 'cp1252': case 'windows-1252': case '1252': $encoding = 'Windows-1252'; $use_iconv = true; $use_mbstring = true; break; // Windows-specific Greek // Windows-specific Greek case 'cp1253': case 'windows-1253': case '1253': $encoding = 'Windows-1253'; $use_iconv = true; break; // Windows-specific Turkish // Windows-specific Turkish case 'cp1254': case 'windows-1254': case '1254': $encoding = 'Windows-1254'; $use_iconv = true; break; // Windows-specific Hebrew // Windows-specific Hebrew case 'cp1255': case 'windows-1255': case '1255': $encoding = 'Windows-1255'; $use_iconv = true; break; // Windows-specific Arabic // Windows-specific Arabic case 'cp1256': case 'windows-1256': case '1256': $encoding = 'Windows-1256'; $use_iconv = true; break; // Windows-specific Baltic // Windows-specific Baltic case 'cp1257': case 'windows-1257': case '1257': $encoding = 'Windows-1257'; $use_iconv = true; break; // Windows-specific Vietnamese // Windows-specific Vietnamese case 'cp1258': case 'windows-1258': case '1258': $encoding = 'Windows-1258'; $use_iconv = true; break; // Default to UTF-8 // Default to UTF-8 default: $encoding = 'UTF-8'; break; } } else { $mp_rss = preg_replace('/<\\?xml(.*)( standalone="no")(.*)\\?>/msiU', '<?xml\\1\\3?>', $mp_rss, 1); $mp_rss = preg_replace('/<\\?xml(.*)\\?>/msiU', '<?xml\\1 encoding="UTF-8"?>', $mp_rss, 1); preg_match('/encoding=["|\'](.*)["|\']/Ui', $mp_rss, $match); $use_iconv = true; $use_mbstring = true; $utf8_fail = false; $encoding = 'UTF-8'; } $this->encoding = $encoding; // If function is available and able, convert characters to UTF-8, and overwrite $this->encoding if (function_exists('iconv') && $use_iconv && iconv($encoding, 'UTF-8', $mp_rss)) { $mp_rss = iconv($encoding, 'UTF-8//TRANSLIT', $mp_rss); $mp_rss = str_replace($match[0], 'encoding="UTF-8"', $mp_rss); $this->encoding = 'UTF-8'; } else { if (function_exists('mb_convert_encoding') && $use_mbstring) { $mp_rss = mb_convert_encoding($mp_rss, 'UTF-8', $encoding); $mp_rss = str_replace($match[0], 'encoding="UTF-8"', $mp_rss); $this->encoding = 'UTF-8'; } else { if (($use_mbstring || $use_iconv) && $utf8_fail) { $this->encoding = 'UTF-8'; $mp_rss = str_replace($match[0], 'encoding="UTF-8"', $mp_rss); } } } $mp_rss = preg_replace('/<(.*)>[\\s]*<\\!\\[CDATA\\[/msiU', '<\\1 spencoded="false"><![CDATA[', $mp_rss); // Add an internal attribute to CDATA sections $mp_rss = str_replace(']] spencoded="false">', ']]>', $mp_rss); // Remove it when we're on the end of a CDATA block (therefore making it ill-formed) // If we're RSS if (preg_match('/<rdf:rdf/i', $mp_rss) || preg_match('/<rss/i', $mp_rss)) { $sp_elements = array('author', 'link'); // Or if we're Atom } else { $sp_elements = array('content', 'copyright', 'name', 'subtitle', 'summary', 'tagline', 'title'); } foreach ($sp_elements as $full) { // The (<\!\[CDATA\[)? never matches any CDATA block, therefore the CDATA gets added, but never replaced $mp_rss = preg_replace("/<{$full}(.*)>[\\s]*(<\\!\\[CDATA\\[)?(.*)(]]>)?[\\s]*<\\/{$full}>/msiU", "<{$full}\\1><![CDATA[\\3]]></{$full}>", $mp_rss); // The following line is a work-around for the above bug $mp_rss = preg_replace("/<{$full}(.*)><\\!\\[CDATA\\[[\\s]*<\\!\\[CDATA\\[/msiU", "<{$full}\\1><![CDATA[", $mp_rss); // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above) $mp_rss = preg_replace_callback("/<({$full})(.*)><!\\[CDATA\\[(.*)\\]\\]><\\/{$full}>/msiU", array(&$this, 'cdata_in_cdata'), $mp_rss); } // If XML Dump is enabled, send feed to the page and quit. if ($this->xml_dump) { header("Content-type: text/xml; charset=" . $this->encoding); echo $mp_rss; exit; } $this->xml = xml_parser_create_ns($this->encoding); $this->namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT'); xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1); xml_set_object($this->xml, $this); xml_set_character_data_handler($this->xml, 'dataHandler'); xml_set_element_handler($this->xml, 'startHandler', 'endHandler'); xml_set_start_namespace_decl_handler($this->xml, 'startNameSpace'); xml_set_end_namespace_decl_handler($this->xml, 'endNameSpace'); if (xml_parse($this->xml, $mp_rss)) { xml_parser_free($this->xml); $this->parse_xml_data_array(); $this->data['feedinfo']['encoding'] = $this->encoding; if ($this->order_by_date && !empty($this->data['items'])) { usort($this->data['items'], create_function('$a,$b', 'if ($a->date == $b->date) return 0; return ($a->date < $b->date) ? 1 : -1;')); } if ($this->caching && substr($this->rss_url, 0, 7) == 'http://') { if ($this->is_writeable_createable($cache_filename)) { $fp = fopen($cache_filename, 'w'); fwrite($fp, serialize($this->data)); fclose($fp); } else { trigger_error("{$cache_filename} is not writeable", E_USER_WARNING); } } return true; } else { $this->sp_error(sprintf('XML error: %s at line %d, column %d', xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml), xml_get_current_column_number($this->xml)), E_USER_WARNING, __FILE__, __LINE__); xml_parser_free($this->xml); $this->data = array(); return false; } } } else { return false; } }
/** * @internal * Init the XML parser * @param $ns * @param $encoding * @param $separator * @private */ function _initParser($ns = false, $encoding = 'UTF-8', $separator = null) { $this->_p = $ns ? xml_parser_create_ns($encoding, $separator) : xml_parser_create($encoding); xml_set_object($this->_p, $this); xml_set_default_handler($this->_p, '_default'); xml_set_element_handler($this->_p, '_tagOpen', '_tagClose'); xml_set_character_data_handler($this->_p, '_cdata'); xml_set_start_namespace_decl_handler($this->_p, '_nsStart'); xml_set_end_namespace_decl_handler($this->_p, '_nsEnd'); xml_set_external_entity_ref_handler($this->_p, '_entityRef'); xml_set_processing_instruction_handler($this->_p, '_pi'); xml_set_notation_decl_handler($this->_p, '_notation'); xml_set_unparsed_entity_decl_handler($this->_p, '_unparsedEntity'); $this->setOption(XML_OPTION_CASE_FOLDING, false); }
function Aspis_xml_set_end_namespace_decl_handler($parser, $handler) { global $Aspis_xml_objects; if (!empty($Aspis_xml_objects)) { $c = count($Aspis_xml_objects); for ($i = $c - 1; $i >= 0; $i--) { $e = $Aspis_xml_objects[$i]; if ($e[0] === $parser[0]) { $handler[0] = AspisInternalCallback(array(array(array($e[1], false), array($handler[0], false)), false)); break; } } } return array(xml_set_end_namespace_decl_handler($parser[0], $handler[0]), false); }
/* Prototype : bool xml_set_start_namespace_decl_handler ( resource $parser , callback $handler ) * Description: Set up start namespace declaration handler. * Source code: ext/xml/xml.c * Alias to functions: */ $xml = <<<HERE <aw1:book xmlns:aw1="http://www.somewhere.com/namespace1" xmlns:aw2="file:/DTD/somewhere.dtd"> <aw1:para>Any old text.</aw1:para> <aw2:td>An HTML table cell.</aw2:td> </aw1:book> HERE; $parser = xml_parser_create_ns(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); var_dump(xml_set_start_namespace_decl_handler($parser, "Namespace_Start_Handler")); var_dump(xml_set_end_namespace_decl_handler($parser, "Namespace_End_Handler")); xml_parse($parser, $xml, true); xml_parser_free($parser); echo "Done\n"; function Namespace_Start_Handler($parser, $prefix, $uri) { echo "Namespace_Start_Handler called\n"; echo "...Prefix: " . $prefix . "\n"; echo "...Uri: " . $uri . "\n"; } function Namespace_End_Handler($parser, $prefix) { echo "Namespace_End_Handler called\n"; echo "...Prefix: " . $prefix . "\n\n"; } function DefaultHandler($parser, $data)
/** * Constructs the RSS reader: downloads the URL and parses it. Check $error after constructing. * * @param URLPATH The URL to the RSS we will be reading * @param boolean Whether the 'url' is actually a filesystem path */ function rss($url, $is_filesystem_path = false) { require_lang('rss'); $this->namespace_stack = array(); $this->tag_stack = array(); $this->attribute_stack = array(); $this->gleamed_feed = array(); $this->gleamed_items = array(); $this->feed_url = $url; $this->error = NULL; if (!function_exists('xml_parser_create')) { $this->error = do_lang_tempcode('XML_NEEDED'); return; } if (!$is_filesystem_path && url_is_local($url)) { $url = get_custom_base_url() . '/' . $url; } //echo $url;exit(); if ($is_filesystem_path) { $GLOBALS['HTTP_CHARSET'] = ''; $data = @file_get_contents($url); } else { $GLOBALS['HTTP_CHARSET'] = ''; $data = http_download_file($url, NULL, false); // if (!is_null($data)) break; } if (is_null($data)) { $this->error = do_lang('RSS_XML_MISSING', $url) . ' [' . $GLOBALS['HTTP_MESSAGE'] . ']'; } else { // Try and detect feed charset $exp = '#<\\?xml\\s+version\\s*=\\s*["\'][\\d\\.]+["\']\\s*(encoding\\s*=\\s*["\']([^"\'<>]+)["\'])?\\s*(standalone\\s*=\\s*["\']([^"\'<>]+)["\'])?\\s*\\?' . '>#'; $matches = array(); if (preg_match($exp, $data, $matches) != 0 && array_key_exists(2, $matches)) { $GLOBALS['HTTP_CHARSET'] = $matches[2]; if (strtolower($GLOBALS['HTTP_CHARSET']) == 'windows-1252') { $GLOBALS['HTTP_CHARSET'] = 'ISO-8859-1'; } } // Weed out if isn't supported if (is_null($GLOBALS['HTTP_CHARSET']) || !in_array(strtoupper($GLOBALS['HTTP_CHARSET']), array('ISO-8859-1', 'US-ASCII', 'UTF-8'))) { $GLOBALS['HTTP_CHARSET'] = 'UTF-8'; } // Our internal charset $parser_charset = get_charset(); if (!in_array(strtoupper($parser_charset), array('ISO-8859-1', 'US-ASCII', 'UTF-8'))) { $parser_charset = 'UTF-8'; } // Create and setup our parser $xml_parser = function_exists('xml_parser_create_ns') ? @xml_parser_create_ns($GLOBALS['HTTP_CHARSET']) : @xml_parser_create($GLOBALS['HTTP_CHARSET']); if ($xml_parser === false) { $this->error = do_lang_tempcode('XML_PARSING_NOT_SUPPORTED'); 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, $parser_charset); xml_set_element_handler($xml_parser, 'startElement', 'endElement'); xml_set_character_data_handler($xml_parser, 'startText'); //xml_set_external_entity_ref_handler($xml_parser,'extEntity'); if (function_exists('xml_set_start_namespace_decl_handler')) { xml_set_start_namespace_decl_handler($xml_parser, 'startNamespace'); } if (function_exists('xml_set_end_namespace_decl_handler')) { xml_set_end_namespace_decl_handler($xml_parser, 'endNameSpace'); } //$data=convert_to_internal_encoding($data); xml_parser does it for us, and we can't disable it- so run with it instead of our own. Shame as it's inferior. if (strpos($data, '<!ENTITY') === false) { $extra_data = "<" . "?xml version=\"1.0\" encoding=\"" . $GLOBALS['HTTP_CHARSET'] . "\" ?" . ">\n<!DOCTYPE atom [\n<!ENTITY nbsp \" \" >\n]>\n"; $data = preg_replace($exp, $extra_data, trim($data)); if ($extra_data != '' && strpos($data, $extra_data) === false) { $data = $extra_data . $data; } if (strtoupper($GLOBALS['HTTP_CHARSET']) == 'ISO-8859-1' || strtoupper($GLOBALS['HTTP_CHARSET']) == 'UTF-8') { $table = array_flip(get_html_translation_table(HTML_ENTITIES)); if (strtoupper($GLOBALS['HTTP_CHARSET']) == 'UTF-8') { foreach ($table as $x => $y) { $table[$x] = utf8_encode($y); } } unset($table['&']); unset($table['>']); unset($table['<']); $data = strtr($data, $table); } $convert_bad_entities = true; } else { $convert_bad_entities = false; if (strpos($data, "<" . "?xml") === false) { $data = "<" . "?xml version=\"1.0\" encoding=\"" . $GLOBALS['HTTP_CHARSET'] . "\" ?" . ">" . $data; } $data = preg_replace($exp, "<" . "?xml version=\"1.0\" encoding=\"" . $GLOBALS['HTTP_CHARSET'] . "\" ?" . ">", $data); // Strip out internal encoding (we already detected and sanitised it) } $data = unixify_line_format($data, $GLOBALS['HTTP_CHARSET']); // Fixes Windows characters if ($convert_bad_entities) { if (strtoupper(get_charset()) == 'ISO-8859-1') { $table = array_flip(get_html_translation_table(HTML_ENTITIES)); unset($table['&']); unset($table['>']); unset($table['<']); $data = strtr($data, $table); } } if (xml_parse($xml_parser, $data, true) == 0) { $this->error = do_lang('RSS_XML_ERROR', xml_error_string(xml_get_error_code($xml_parser)), strval(xml_get_current_line_number($xml_parser))); } @xml_parser_free($xml_parser); $new_items = array(); foreach ($this->gleamed_items as $i) { if (!isset($i['bogus']) || !$i['bogus']) { $new_items[] = $i; } } $this->gleamed_items = $new_items; } }
* Description: Set up character data handler * Source code: ext/xml/xml.c * Alias to functions: */ echo "*** Testing xml_set_end_namespace_decl_handler() : usage variations ***\n"; error_reporting(E_ALL & ~E_NOTICE); class aClass { function __toString() { return "Some Ascii Data"; } } function validHandler(resource $parser, string $data) { } // Initialise function arguments not being substituted (if any) $hdl = 'validHandler'; //get an unset variable $unset_var = 10; unset($unset_var); $fp = fopen(__FILE__, "r"); //array of values to iterate over $values = array(0, 1, 12345, -2345, 10.5, -10.5, 101234567000.0, 1.07654321E-9, 0.5, array(), array(0), array(1), array(1, 2), array('color' => 'red', 'item' => 'pen'), NULL, null, true, false, TRUE, FALSE, "", '', "string", 'string', new aClass(), $fp, $undefined_var, $unset_var); // loop through each element of the array for parser foreach ($values as $value) { echo @"\nArg value {$value} \n"; var_dump(xml_set_end_namespace_decl_handler($value, $hdl)); } fclose($fp); echo "Done";
/** * Resets internal XML Parser instance */ protected function resetParser() { if (is_resource($this->parser)) { xml_parser_free($this->parser); $this->parser = null; } $this->documentNode = null; $this->nodeStack = array(new $this->params['nodeClass'](VIVVO_XML_DOCUMENT_NODE)); $this->parser = xml_parser_create($this->params['encoding']); xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->parser, array(&$this, 'handlerNodeStart'), array(&$this, 'handlerNodeEnd')); xml_set_character_data_handler($this->parser, array(&$this, 'handlerTextNode')); xml_set_default_handler($this->parser, array(&$this, 'handlerDefault')); xml_set_end_namespace_decl_handler($this->parser, false); xml_set_external_entity_ref_handler($this->parser, false); xml_set_notation_decl_handler($this->parser, false); xml_set_processing_instruction_handler($this->parser, false); xml_set_start_namespace_decl_handler($this->parser, false); xml_set_unparsed_entity_decl_handler($this->parser, false); VivvoXMLNode::$counter = 0; }
/** * Parses xml text using Expat * @param Object A reference to the DOM document that the xml is to be parsed into * @param string The text to be parsed * @param boolean True if CDATA Section nodes are not to be converted into Text nodes * @return boolean True if the parsing is successful */ function parse(&$myXMLDoc, $xmlText, $preserveCDATA = true) { $this->xmlDoc =& $myXMLDoc; $this->lastChild =& $this->xmlDoc; $this->preserveCDATA = $preserveCDATA; //create instance of expat parser (should be included in php distro) if (version_compare(phpversion(), '5.0', '<=')) { if ($this->xmlDoc->isNamespaceAware) { $parser = xml_parser_create_ns(''); } else { $parser = xml_parser_create(''); } } else { if ($this->xmlDoc->isNamespaceAware) { $parser = xml_parser_create_ns(); } else { $parser = xml_parser_create(); } } //set handlers for SAX events xml_set_object($parser, $this); xml_set_character_data_handler($parser, 'dataElement'); xml_set_default_handler($parser, 'defaultDataElement'); xml_set_notation_decl_handler($parser, 'notationElement'); xml_set_processing_instruction_handler($parser, 'processingInstructionElement'); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if ($this->xmlDoc->isNamespaceAware) { xml_set_start_namespace_decl_handler($parser, 'startNamespaceDeclaration'); xml_set_end_namespace_decl_handler($parser, 'endNamespaceDeclaration'); xml_set_element_handler($parser, 'startElementNS', 'endElement'); $this->namespaceURIMap[DOMIT_XML_NAMESPACE] = 'xml'; } else { xml_set_element_handler($parser, 'startElement', 'endElement'); } //parse out whitespace - (XML_OPTION_SKIP_WHITE = 1 does not //seem to work consistently across versions of PHP and Expat $xmlText = eregi_replace('>' . "[[:space:]]+" . '<', '><', $xmlText); $success = xml_parse($parser, $xmlText); $this->xmlDoc->errorCode = xml_get_error_code($parser); $this->xmlDoc->errorString = xml_error_string($this->xmlDoc->errorCode); xml_parser_free($parser); return $success; }
function NewsRss_Parser($data, $encoding, $return_xml = false) { $this->encoding = $encoding; if (strpos($data, sprintf('%c%c%c%c', 0x0, 0x0, 0xfe, 0xff)) === 0) { $data = substr($data, 4); } else { if (strpos($data, sprintf('%c%c%c%c', 0xff, 0xfe, 0x0, 0x0)) === 0) { $data = substr($data, 4); } else { if (strpos($data, sprintf('%c%c', 0xfe, 0xff)) === 0) { $data = substr($data, 2); } else { if (strpos($data, sprintf('%c%c', 0xff, 0xfe)) === 0) { $data = substr($data, 2); } else { if (strpos($data, sprintf('%c%c%c', 0xef, 0xbb, 0xbf)) === 0) { $data = substr($data, 3); } } } } } if (preg_match('/^<\\?xml(.*)?>/msiU', $data, $prolog)) { $data = substr_replace($data, '', 0, strlen($prolog[0])); } $data = "<?xml version='1.0' encoding='{$encoding}'?>\n" . $data; if ((stristr($data, '<rss') || preg_match('/<([a-z0-9]+\\:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+\\:)?channel/mi', $data) || preg_match('/<([a-z0-9]+\\:)?item/mi', $data))) { $sp_elements = array('author', 'category', 'copyright', 'description', 'docs', 'generator', 'guid', 'language', 'lastBuildDate', 'link', 'managingEditor', 'pubDate', 'title', 'url', 'webMaster'); } else { $sp_elements = array('content', 'copyright', 'name', 'subtitle', 'summary', 'tagline', 'title'); } foreach ($sp_elements as $full) { $data = preg_replace_callback("/<({$full})((\\s*((\\w+:)?\\w+)\\s*=\\s*(\"([^\"]*)\"|'([^']*)'))*)\\s*(\\/>|>(.*)<\\/{$full}>)/msiU", array(&$this, 'add_cdata'), $data); } foreach ($sp_elements as $full) { $data = preg_replace_callback("/<({$full})((\\s*((\\w+:)?\\w+)\\s*=\\s*(\"([^\"]*)\"|'([^']*)'))*)\\s*(\\/>|><!\\[CDATA\\[(.*)\\]\\]><\\/{$full}>)/msiU", array(&$this, 'cdata_in_cdata'), $data); } if ($return_xml) { $this->data =& $data; return; } $this->xml = xml_parser_create_ns($encoding); xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1); xml_set_object($this->xml, $this); xml_set_character_data_handler($this->xml, 'data_handler'); xml_set_element_handler($this->xml, 'start_handler', 'end_handler'); xml_set_start_namespace_decl_handler($this->xml, 'start_name_space'); xml_set_end_namespace_decl_handler($this->xml, 'end_name_space'); if (!xml_parse($this->xml, $data)) { $this->data = null; $this->error_code = xml_get_error_code($this->xml); $this->error_string = xml_error_string($this->error_code); } $this->current_line = xml_get_current_line_number($this->xml); $this->current_column = xml_get_current_column_number($this->xml); $this->current_byte = xml_get_current_byte_index($this->xml); xml_parser_free($this->xml); return; }
function parse() { global $app_logging; array_unshift($this->ns_contexts, array()); $parser = xml_parser_create_ns(); xml_set_object($parser, $this); xml_set_element_handler($parser, "start_element", "end_element"); xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0); xml_set_character_data_handler($parser, "cdata"); xml_set_default_handler($parser, "_default"); xml_set_start_namespace_decl_handler($parser, "start_ns"); xml_set_end_namespace_decl_handler($parser, "end_ns"); $contents = ""; $fp = fopen("php://input", "r"); while(!feof($fp)) { $line = fgets($fp, 4096); if($app_logging) $contents .= $line; if(!xml_parse($parser, $line)) { log_app("xml_parse_error", "line: $line"); $this->error = sprintf(__('XML error: %s at line %d')."\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); log_app("xml_parse_error", $this->error); return false; } } fclose($fp); xml_parser_free($parser); log_app("AtomParser->parse()",trim($contents)); return true; }
function parse() { set_error_handler(array(&$this, 'error_handler')); array_unshift($this->ns_contexts, array()); if (!function_exists('xml_parser_create_ns')) { trigger_error(__("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension.")); return false; } $parser = xml_parser_create_ns(); xml_set_object($parser, $this); xml_set_element_handler($parser, "start_element", "end_element"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_set_character_data_handler($parser, "cdata"); xml_set_default_handler($parser, "_default"); xml_set_start_namespace_decl_handler($parser, "start_ns"); xml_set_end_namespace_decl_handler($parser, "end_ns"); $this->content = ''; $ret = true; $fp = fopen($this->FILE, "r"); while ($data = fread($fp, 4096)) { if ($this->debug) { $this->content .= $data; } if (!xml_parse($parser, $data, feof($fp))) { /* translators: 1: error message, 2: line number */ trigger_error(sprintf(__('XML Error: %1$s at line %2$s') . "\n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); $ret = false; break; } } fclose($fp); xml_parser_free($parser); restore_error_handler(); return $ret; }
function parse($xml) { global $app_logging; array_unshift($this->ns_contexts, array()); $parser = xml_parser_create_ns(); xml_set_object($parser, $this); xml_set_element_handler($parser, "start_element", "end_element"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_set_character_data_handler($parser, "cdata"); xml_set_default_handler($parser, "_default"); xml_set_start_namespace_decl_handler($parser, "start_ns"); xml_set_end_namespace_decl_handler($parser, "end_ns"); $contents = ""; xml_parse($parser, $xml); xml_parser_free($parser); return true; }
/** * Convert the specified comcode (text format) into a tempcode tree. You shouldn't output the tempcode tree to the browser, as it looks really horrible. If you are in a rare case where you need to output directly (not through templates), you should call the evaluate method on the tempcode object, to convert it into a string. * * @param LONG_TEXT The comcode to convert * @param MEMBER The member the evaluation is running as. This is a security issue, and you should only run as an administrator if you have considered where the comcode came from carefully * @param ?integer The position to conduct wordwrapping at (NULL: do not conduct word-wrapping) * @param ?string A special identifier that can identify this resource in a sea of our resources of this class; usually this can be ignored, but may be used to provide a binding between Javascript in evaluated comcode, and the surrounding environment (NULL: no explicit binding) * @param object The database connection to use * @param boolean Whether to parse so as to create something that would fit inside a semihtml tag. It means we generate HTML, with Comcode written into it where the tag could never be reverse-converted (e.g. a block). * @param boolean Whether this is being pre-parsed, to pick up errors before row insertion. * @param boolean Whether to treat this whole thing as being wrapped in semihtml, but apply normal security otherwise. * @param boolean Whether we are only doing this parse to find the title structure * @param boolean Whether to only check the Comcode. It's best to use the check_comcode function which will in turn use this parameter. * @param ?MEMBER The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating) * @return tempcode The tempcode tree. */ function comcode_xml_to_tempcode($comcode, $source_member, $wrap_pos, $pass_id, $connection, $semiparse_mode, $preparse_mode, $is_all_semihtml, $structure_sweep, $check_only, $on_behalf_of_member = NULL) { if (is_null($pass_id)) { $pass_id = strval(mt_rand(0, 32000)); } // This is a unique ID that refers to this specific piece of comcode $this->wml = false; // removed feature from ocPortal now $this->comcode = $comcode; $this->source_member = $source_member; $this->wrap_pos = $wrap_pos; $this->pass_id = $pass_id; $this->connection = $connection; $this->semiparse_mode = $semiparse_mode; $this->preparse_mode = $preparse_mode; $this->is_all_semihtml = $is_all_semihtml; $this->structure_sweep = $structure_sweep; $this->check_only = $check_only; $this->on_behalf_of_member = $on_behalf_of_member; global $VALID_COMCODE_TAGS, $IMPORTED_CUSTOM_COMCODE; if (!$IMPORTED_CUSTOM_COMCODE) { _custom_comcode_import($connection); } $this->namespace_stack = array(); $this->tag_stack = array(); $this->attribute_stack = array(); $this->tempcode_stack = array(new ocp_tempcode()); $this->special_child_elements_stack = array(); // Create and setup our parser $xml_parser = function_exists('xml_parser_create_ns') ? xml_parser_create_ns() : xml_parser_create(); if ($xml_parser === false) { return do_lang_tempcode('XML_PARSING_NOT_SUPPORTED'); // 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'); if (function_exists('xml_set_start_namespace_decl_handler')) { xml_set_start_namespace_decl_handler($xml_parser, 'startNamespace'); } if (function_exists('xml_set_end_namespace_decl_handler')) { xml_set_end_namespace_decl_handler($xml_parser, 'startNamespace'); } $extra_data = "<?xml version=\"1.0\" encoding=\"" . escape_html(get_charset()) . "\" ?" . ">\n<!DOCTYPE comcode_xml [\n<!ENTITY nbsp \" \" >\n]>\n"; if (xml_parse($xml_parser, $extra_data . $comcode, true) == 0) { $error_str = xml_error_string(xml_get_error_code($xml_parser)); warn_exit(escape_html($error_str)); // Parsing error } else { $this->tempcode = $this->tempcode_stack[0]; } @xml_parser_free($xml_parser); return $this->tempcode; }