]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/link-parse-opml.php
WordPress 4.5
[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 /**
13  * @global string $opml
14  */
15 global $opml;
16
17 /**
18  * XML callback function for the start of a new XML tag.
19  *
20  * @since 0.71
21  * @access private
22  *
23  * @global array $names
24  * @global array $urls
25  * @global array $targets
26  * @global array $descriptions
27  * @global array $feeds
28  *
29  * @param mixed $parser XML Parser resource.
30  * @param string $tagName XML element name.
31  * @param array $attrs XML element attributes.
32  */
33 function startElement($parser, $tagName, $attrs) {
34         global $names, $urls, $targets, $descriptions, $feeds;
35
36         if ( 'OUTLINE' === $tagName ) {
37                 $name = '';
38                 if ( isset( $attrs['TEXT'] ) ) {
39                         $name = $attrs['TEXT'];
40                 }
41                 if ( isset( $attrs['TITLE'] ) ) {
42                         $name = $attrs['TITLE'];
43                 }
44                 $url = '';
45                 if ( isset( $attrs['URL'] ) ) {
46                         $url = $attrs['URL'];
47                 }
48                 if ( isset( $attrs['HTMLURL'] ) ) {
49                         $url = $attrs['HTMLURL'];
50                 }
51
52                 // Save the data away.
53                 $names[] = $name;
54                 $urls[] = $url;
55                 $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] :  '';
56                 $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] :  '';
57                 $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] :  '';
58         } // End if outline.
59 }
60
61 /**
62  * XML callback function that is called at the end of a XML tag.
63  *
64  * @since 0.71
65  * @access private
66  *
67  * @param mixed $parser XML Parser resource.
68  * @param string $tagName XML tag name.
69  */
70 function endElement($parser, $tagName) {
71         // Nothing to do.
72 }
73
74 // Create an XML parser
75 $xml_parser = xml_parser_create();
76
77 // Set the functions to handle opening and closing tags
78 xml_set_element_handler($xml_parser, "startElement", "endElement");
79
80 if ( ! xml_parse( $xml_parser, $opml, true ) ) {
81         printf(
82                 /* translators: 1: error message, 2: line number */
83                 __( 'XML Error: %1$s at line %2$s' ),
84                 xml_error_string( xml_get_error_code( $xml_parser ) ),
85                 xml_get_current_line_number( $xml_parser )
86         );
87 }
88
89 // Free up memory used by the XML parser
90 xml_parser_free($xml_parser);