3 * Parse OPML XML files and store in globals.
6 * @subpackage Administration
9 if ( ! defined('ABSPATH') )
15 * XML callback function for the start of a new XML tag.
20 * @global array $names
22 * @global array $targets
23 * @global array $descriptions
24 * @global array $feeds
26 * @param mixed $parser XML Parser resource.
27 * @param string $tagName XML element name.
28 * @param array $attrs XML element attributes.
30 function startElement($parser, $tagName, $attrs) {
31 global $names, $urls, $targets, $descriptions, $feeds;
33 if ( 'OUTLINE' === $tagName ) {
35 if ( isset( $attrs['TEXT'] ) ) {
36 $name = $attrs['TEXT'];
38 if ( isset( $attrs['TITLE'] ) ) {
39 $name = $attrs['TITLE'];
42 if ( isset( $attrs['URL'] ) ) {
45 if ( isset( $attrs['HTMLURL'] ) ) {
46 $url = $attrs['HTMLURL'];
49 // Save the data away.
52 $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : '';
53 $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : '';
54 $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : '';
59 * XML callback function that is called at the end of a XML tag.
64 * @param mixed $parser XML Parser resource.
65 * @param string $tagName XML tag name.
67 function endElement($parser, $tagName) {
71 // Create an XML parser
72 $xml_parser = xml_parser_create();
74 // Set the functions to handle opening and closing tags
75 xml_set_element_handler($xml_parser, "startElement", "endElement");
77 if (!xml_parse($xml_parser, $opml, true)) {
78 echo(sprintf(__('XML error: %1$s at line %2$s'),
79 xml_error_string(xml_get_error_code($xml_parser)),
80 xml_get_current_line_number($xml_parser)));
83 // Free up memory used by the XML parser
84 xml_parser_free($xml_parser);