7 */ |
7 */ |
8 |
8 |
9 if ( ! defined('ABSPATH') ) |
9 if ( ! defined('ABSPATH') ) |
10 die(); |
10 die(); |
11 |
11 |
12 global $opml, $map; |
12 global $opml; |
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 |
13 |
27 /** |
14 /** |
28 * XML callback function for the start of a new XML tag. |
15 * XML callback function for the start of a new XML tag. |
29 * |
16 * |
30 * @since 0.71 |
17 * @since 0.71 |
31 * @access private |
18 * @access private |
32 * |
19 * |
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 |
20 * @global array $names |
37 * @global array $urls |
21 * @global array $urls |
38 * @global array $targets |
22 * @global array $targets |
39 * @global array $descriptions |
23 * @global array $descriptions |
40 * @global array $feeds |
24 * @global array $feeds |
42 * @param mixed $parser XML Parser resource. |
26 * @param mixed $parser XML Parser resource. |
43 * @param string $tagName XML element name. |
27 * @param string $tagName XML element name. |
44 * @param array $attrs XML element attributes. |
28 * @param array $attrs XML element attributes. |
45 */ |
29 */ |
46 function startElement($parser, $tagName, $attrs) { |
30 function startElement($parser, $tagName, $attrs) { |
47 global $updated_timestamp, $all_links, $map; |
|
48 global $names, $urls, $targets, $descriptions, $feeds; |
31 global $names, $urls, $targets, $descriptions, $feeds; |
49 |
32 |
50 if ($tagName == 'OUTLINE') { |
33 if ( 'OUTLINE' === $tagName ) { |
51 foreach (array_keys($map) as $key) { |
34 $name = ''; |
52 if (isset($attrs[$key])) { |
35 if ( isset( $attrs['TEXT'] ) ) { |
53 $$map[$key] = $attrs[$key]; |
36 $name = $attrs['TEXT']; |
54 } |
37 } |
|
38 if ( isset( $attrs['TITLE'] ) ) { |
|
39 $name = $attrs['TITLE']; |
|
40 } |
|
41 $url = ''; |
|
42 if ( isset( $attrs['URL'] ) ) { |
|
43 $url = $attrs['URL']; |
|
44 } |
|
45 if ( isset( $attrs['HTMLURL'] ) ) { |
|
46 $url = $attrs['HTMLURL']; |
55 } |
47 } |
56 |
48 |
57 //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]<br />\n"); |
49 // Save the data away. |
58 |
50 $names[] = $name; |
59 // save the data away. |
51 $urls[] = $url; |
60 $names[] = $link_name; |
52 $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : ''; |
61 $urls[] = $link_url; |
53 $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : ''; |
62 $targets[] = $link_target; |
54 $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : ''; |
63 $feeds[] = $link_rss; |
55 } // End if outline. |
64 $descriptions[] = $link_description; |
|
65 } // end if outline |
|
66 } |
56 } |
67 |
57 |
68 /** |
58 /** |
69 * XML callback function that is called at the end of a XML tag. |
59 * XML callback function that is called at the end of a XML tag. |
70 * |
60 * |
71 * @since 0.71 |
61 * @since 0.71 |
72 * @access private |
62 * @access private |
73 * @package WordPress |
|
74 * @subpackage Dummy |
|
75 * |
63 * |
76 * @param mixed $parser XML Parser resource. |
64 * @param mixed $parser XML Parser resource. |
77 * @param string $tagName XML tag name. |
65 * @param string $tagName XML tag name. |
78 */ |
66 */ |
79 function endElement($parser, $tagName) { |
67 function endElement($parser, $tagName) { |
80 // nothing to do. |
68 // Nothing to do. |
81 } |
69 } |
82 |
70 |
83 // Create an XML parser |
71 // Create an XML parser |
84 $xml_parser = xml_parser_create(); |
72 $xml_parser = xml_parser_create(); |
85 |
73 |
86 // Set the functions to handle opening and closing tags |
74 // Set the functions to handle opening and closing tags |
87 xml_set_element_handler($xml_parser, "startElement", "endElement"); |
75 xml_set_element_handler($xml_parser, "startElement", "endElement"); |
88 |
76 |
89 if (!xml_parse($xml_parser, $opml, true)) { |
77 if ( ! xml_parse( $xml_parser, $opml, true ) ) { |
90 echo(sprintf(__('XML error: %1$s at line %2$s'), |
78 printf( |
91 xml_error_string(xml_get_error_code($xml_parser)), |
79 /* translators: 1: error message, 2: line number */ |
92 xml_get_current_line_number($xml_parser))); |
80 __( 'XML Error: %1$s at line %2$s' ), |
|
81 xml_error_string( xml_get_error_code( $xml_parser ) ), |
|
82 xml_get_current_line_number( $xml_parser ) |
|
83 ); |
93 } |
84 } |
94 |
85 |
95 // Free up memory used by the XML parser |
86 // Free up memory used by the XML parser |
96 xml_parser_free($xml_parser); |
87 xml_parser_free($xml_parser); |