3 * Parse OPML XML files and store in globals.
6 * @subpackage Administration
9 if ( ! defined('ABSPATH') )
14 // columns we wish to find are: link_url, link_name, link_target, link_description
15 // we need to map XML attribute names to our columns
16 $opml_map = array('URL' => 'link_url',
17 'HTMLURL' => 'link_url',
18 'TEXT' => 'link_name',
19 'TITLE' => 'link_name',
20 'TARGET' => 'link_target',
21 'DESCRIPTION' => 'link_description',
22 'XMLURL' => 'link_rss'
28 * XML callback function for the start of a new XML tag.
33 * @uses $updated_timestamp Not used inside function.
34 * @uses $all_links Not used inside function.
35 * @uses $map Stores names of attributes to use.
36 * @global array $names
38 * @global array $targets
39 * @global array $descriptions
40 * @global array $feeds
42 * @param mixed $parser XML Parser resource.
43 * @param string $tagName XML element name.
44 * @param array $attrs XML element attributes.
46 function startElement($parser, $tagName, $attrs) {
47 global $updated_timestamp, $all_links, $map;
48 global $names, $urls, $targets, $descriptions, $feeds;
50 if ($tagName == 'OUTLINE') {
51 foreach (array_keys($map) as $key) {
52 if (isset($attrs[$key])) {
53 $$map[$key] = $attrs[$key];
57 //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]<br />\n");
59 // save the data away.
60 $names[] = $link_name;
62 $targets[] = $link_target;
64 $descriptions[] = $link_description;
69 * XML callback function that is called at the end of a XML tag.
76 * @param mixed $parser XML Parser resource.
77 * @param string $tagName XML tag name.
79 function endElement($parser, $tagName) {
83 // Create an XML parser
84 $xml_parser = xml_parser_create();
86 // Set the functions to handle opening and closing tags
87 xml_set_element_handler($xml_parser, "startElement", "endElement");
89 if (!xml_parse($xml_parser, $opml, true)) {
90 echo(sprintf(__('XML error: %1$s at line %2$s'),
91 xml_error_string(xml_get_error_code($xml_parser)),
92 xml_get_current_line_number($xml_parser)));
95 // Free up memory used by the XML parser
96 xml_parser_free($xml_parser);