3 * Parse OPML XML files and store in globals.
6 * @subpackage Administration
9 if ( ! defined('ABSPATH') )
13 * @global string $opml
18 * XML callback function for the start of a new XML tag.
23 * @global array $names
25 * @global array $targets
26 * @global array $descriptions
27 * @global array $feeds
29 * @param mixed $parser XML Parser resource.
30 * @param string $tagName XML element name.
31 * @param array $attrs XML element attributes.
33 function startElement($parser, $tagName, $attrs) {
34 global $names, $urls, $targets, $descriptions, $feeds;
36 if ( 'OUTLINE' === $tagName ) {
38 if ( isset( $attrs['TEXT'] ) ) {
39 $name = $attrs['TEXT'];
41 if ( isset( $attrs['TITLE'] ) ) {
42 $name = $attrs['TITLE'];
45 if ( isset( $attrs['URL'] ) ) {
48 if ( isset( $attrs['HTMLURL'] ) ) {
49 $url = $attrs['HTMLURL'];
52 // Save the data away.
55 $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : '';
56 $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : '';
57 $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : '';
62 * XML callback function that is called at the end of a XML tag.
67 * @param mixed $parser XML Parser resource.
68 * @param string $tagName XML tag name.
70 function endElement($parser, $tagName) {
74 // Create an XML parser
75 if ( ! function_exists( 'xml_parser_create' ) ) {
76 trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
77 wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
80 $xml_parser = xml_parser_create();
82 // Set the functions to handle opening and closing tags
83 xml_set_element_handler($xml_parser, "startElement", "endElement");
85 if ( ! xml_parse( $xml_parser, $opml, true ) ) {
87 /* translators: 1: error message, 2: line number */
88 __( 'XML Error: %1$s at line %2$s' ),
89 xml_error_string( xml_get_error_code( $xml_parser ) ),
90 xml_get_current_line_number( $xml_parser )
94 // Free up memory used by the XML parser
95 xml_parser_free($xml_parser);