]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/link-parse-opml.php
WordPress 4.1-scripts
[autoinstalls/wordpress.git] / wp-admin / link-parse-opml.php
1 <?php
2 /**
3  * Parse OPML XML files and store in globals.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 if ( ! defined('ABSPATH') )
10         die();
11
12 global $opml;
13
14 /**
15  * XML callback function for the start of a new XML tag.
16  *
17  * @since 0.71
18  * @access private
19  *
20  * @global array $names
21  * @global array $urls
22  * @global array $targets
23  * @global array $descriptions
24  * @global array $feeds
25  *
26  * @param mixed $parser XML Parser resource.
27  * @param string $tagName XML element name.
28  * @param array $attrs XML element attributes.
29  */
30 function startElement($parser, $tagName, $attrs) {
31         global $names, $urls, $targets, $descriptions, $feeds;
32
33         if ( 'OUTLINE' === $tagName ) {
34                 $name = '';
35                 if ( isset( $attrs['TEXT'] ) ) {
36                         $name = $attrs['TEXT'];
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'];
47                 }
48
49                 // Save the data away.
50                 $names[] = $name;
51                 $urls[] = $url;
52                 $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] :  '';
53                 $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] :  '';
54                 $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] :  '';
55         } // End if outline.
56 }
57
58 /**
59  * XML callback function that is called at the end of a XML tag.
60  *
61  * @since 0.71
62  * @access private
63  *
64  * @param mixed $parser XML Parser resource.
65  * @param string $tagName XML tag name.
66  */
67 function endElement($parser, $tagName) {
68         // Nothing to do.
69 }
70
71 // Create an XML parser
72 $xml_parser = xml_parser_create();
73
74 // Set the functions to handle opening and closing tags
75 xml_set_element_handler($xml_parser, "startElement", "endElement");
76
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)));
81 }
82
83 // Free up memory used by the XML parser
84 xml_parser_free($xml_parser);