wp/wp-admin/link-parse-opml.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 if ( ! defined('ABSPATH') )
     9 if ( ! defined( 'ABSPATH' ) ) {
    10 	die();
    10 	die();
       
    11 }
    11 
    12 
    12 /**
    13 /**
    13  * @global string $opml
    14  * @global string $opml
    14  */
    15  */
    15 global $opml;
    16 global $opml;
    28  *
    29  *
    29  * @param mixed $parser XML Parser resource.
    30  * @param mixed $parser XML Parser resource.
    30  * @param string $tagName XML element name.
    31  * @param string $tagName XML element name.
    31  * @param array $attrs XML element attributes.
    32  * @param array $attrs XML element attributes.
    32  */
    33  */
    33 function startElement($parser, $tagName, $attrs) {
    34 function startElement( $parser, $tagName, $attrs ) {
    34 	global $names, $urls, $targets, $descriptions, $feeds;
    35 	global $names, $urls, $targets, $descriptions, $feeds;
    35 
    36 
    36 	if ( 'OUTLINE' === $tagName ) {
    37 	if ( 'OUTLINE' === $tagName ) {
    37 		$name = '';
    38 		$name = '';
    38 		if ( isset( $attrs['TEXT'] ) ) {
    39 		if ( isset( $attrs['TEXT'] ) ) {
    48 		if ( isset( $attrs['HTMLURL'] ) ) {
    49 		if ( isset( $attrs['HTMLURL'] ) ) {
    49 			$url = $attrs['HTMLURL'];
    50 			$url = $attrs['HTMLURL'];
    50 		}
    51 		}
    51 
    52 
    52 		// Save the data away.
    53 		// Save the data away.
    53 		$names[] = $name;
    54 		$names[]        = $name;
    54 		$urls[] = $url;
    55 		$urls[]         = $url;
    55 		$targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] :  '';
    56 		$targets[]      = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : '';
    56 		$feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] :  '';
    57 		$feeds[]        = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : '';
    57 		$descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] :  '';
    58 		$descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : '';
    58 	} // End if outline.
    59 	} // End if outline.
    59 }
    60 }
    60 
    61 
    61 /**
    62 /**
    62  * XML callback function that is called at the end of a XML tag.
    63  * XML callback function that is called at the end of a XML tag.
    65  * @access private
    66  * @access private
    66  *
    67  *
    67  * @param mixed $parser XML Parser resource.
    68  * @param mixed $parser XML Parser resource.
    68  * @param string $tagName XML tag name.
    69  * @param string $tagName XML tag name.
    69  */
    70  */
    70 function endElement($parser, $tagName) {
    71 function endElement( $parser, $tagName ) {
    71 	// Nothing to do.
    72 	// Nothing to do.
    72 }
    73 }
    73 
    74 
    74 // Create an XML parser
    75 // Create an XML parser
    75 if ( ! function_exists( 'xml_parser_create' ) ) {
    76 if ( ! function_exists( 'xml_parser_create' ) ) {
    78 }
    79 }
    79 
    80 
    80 $xml_parser = xml_parser_create();
    81 $xml_parser = xml_parser_create();
    81 
    82 
    82 // Set the functions to handle opening and closing tags
    83 // Set the functions to handle opening and closing tags
    83 xml_set_element_handler($xml_parser, "startElement", "endElement");
    84 xml_set_element_handler( $xml_parser, 'startElement', 'endElement' );
    84 
    85 
    85 if ( ! xml_parse( $xml_parser, $opml, true ) ) {
    86 if ( ! xml_parse( $xml_parser, $opml, true ) ) {
    86 	printf(
    87 	printf(
    87 		/* translators: 1: error message, 2: line number */
    88 		/* translators: 1: error message, 2: line number */
    88 		__( 'XML Error: %1$s at line %2$s' ),
    89 		__( 'XML Error: %1$s at line %2$s' ),
    90 		xml_get_current_line_number( $xml_parser )
    91 		xml_get_current_line_number( $xml_parser )
    91 	);
    92 	);
    92 }
    93 }
    93 
    94 
    94 // Free up memory used by the XML parser
    95 // Free up memory used by the XML parser
    95 xml_parser_free($xml_parser);
    96 xml_parser_free( $xml_parser );