Projects : mp-wp : mp-wp_genesis
1 | <?php |
2 | /** |
3 | * Parse OPML XML files and store in globals. |
4 | * |
5 | * @package WordPress |
6 | * @subpackage Administration |
7 | */ |
8 | |
9 | /** Load WordPress Bootstrap */ |
10 | require_once('../wp-load.php'); |
11 | |
12 | global $opml, $map; |
13 | |
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' |
23 | ); |
24 | |
25 | $map = $opml_map; |
26 | |
27 | /** |
28 | * XML callback function for the start of a new XML tag. |
29 | * |
30 | * @since unknown |
31 | * @access private |
32 | * |
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 |
37 | * @global array $urls |
38 | * @global array $targets |
39 | * @global array $descriptions |
40 | * @global array $feeds |
41 | * |
42 | * @param mixed $parser XML Parser resource. |
43 | * @param string $tagName XML element name. |
44 | * @param array $attrs XML element attributes. |
45 | */ |
46 | function startElement($parser, $tagName, $attrs) { |
47 | global $updated_timestamp, $all_links, $map; |
48 | global $names, $urls, $targets, $descriptions, $feeds; |
49 | |
50 | if ($tagName == 'OUTLINE') { |
51 | foreach (array_keys($map) as $key) { |
52 | if (isset($attrs[$key])) { |
53 | $$map[$key] = $attrs[$key]; |
54 | } |
55 | } |
56 | |
57 | //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]<br />\n"); |
58 | |
59 | // save the data away. |
60 | $names[] = $link_name; |
61 | $urls[] = $link_url; |
62 | $targets[] = $link_target; |
63 | $feeds[] = $link_rss; |
64 | $descriptions[] = $link_description; |
65 | } // end if outline |
66 | } |
67 | |
68 | /** |
69 | * XML callback function that is called at the end of a XML tag. |
70 | * |
71 | * @since unknown |
72 | * @access private |
73 | * @package WordPress |
74 | * @subpackage Dummy |
75 | * |
76 | * @param mixed $parser XML Parser resource. |
77 | * @param string $tagName XML tag name. |
78 | */ |
79 | function endElement($parser, $tagName) { |
80 | // nothing to do. |
81 | } |
82 | |
83 | // Create an XML parser |
84 | $xml_parser = xml_parser_create(); |
85 | |
86 | // Set the functions to handle opening and closing tags |
87 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
88 | |
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))); |
93 | } |
94 | |
95 | // Free up memory used by the XML parser |
96 | xml_parser_free($xml_parser); |
97 | ?> |