wp/wp-admin/link-parse-opml.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 21 48c4eec2b7e6
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    25  * @global array $urls
    25  * @global array $urls
    26  * @global array $targets
    26  * @global array $targets
    27  * @global array $descriptions
    27  * @global array $descriptions
    28  * @global array $feeds
    28  * @global array $feeds
    29  *
    29  *
    30  * @param mixed $parser XML Parser resource.
    30  * @param resource $parser   XML Parser resource.
    31  * @param string $tagName XML element name.
    31  * @param string   $tag_name XML element name.
    32  * @param array $attrs XML element attributes.
    32  * @param array    $attrs    XML element attributes.
    33  */
    33  */
    34 function startElement( $parser, $tagName, $attrs ) {
    34 function startElement( $parser, $tag_name, $attrs ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    35 	global $names, $urls, $targets, $descriptions, $feeds;
    35 	global $names, $urls, $targets, $descriptions, $feeds;
    36 
    36 
    37 	if ( 'OUTLINE' === $tagName ) {
    37 	if ( 'OUTLINE' === $tag_name ) {
    38 		$name = '';
    38 		$name = '';
    39 		if ( isset( $attrs['TEXT'] ) ) {
    39 		if ( isset( $attrs['TEXT'] ) ) {
    40 			$name = $attrs['TEXT'];
    40 			$name = $attrs['TEXT'];
    41 		}
    41 		}
    42 		if ( isset( $attrs['TITLE'] ) ) {
    42 		if ( isset( $attrs['TITLE'] ) ) {
    63  * 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.
    64  *
    64  *
    65  * @since 0.71
    65  * @since 0.71
    66  * @access private
    66  * @access private
    67  *
    67  *
    68  * @param mixed $parser XML Parser resource.
    68  * @param resource $parser   XML Parser resource.
    69  * @param string $tagName XML tag name.
    69  * @param string   $tag_name XML tag name.
    70  */
    70  */
    71 function endElement( $parser, $tagName ) {
    71 function endElement( $parser, $tag_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    72 	// Nothing to do.
    72 	// Nothing to do.
    73 }
    73 }
    74 
    74 
    75 // Create an XML parser
    75 // Create an XML parser.
    76 if ( ! function_exists( 'xml_parser_create' ) ) {
    76 if ( ! function_exists( 'xml_parser_create' ) ) {
    77 	trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    77 	trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    78 	wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    78 	wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    79 }
    79 }
    80 
    80 
    81 $xml_parser = xml_parser_create();
    81 $xml_parser = xml_parser_create();
    82 
    82 
    83 // Set the functions to handle opening and closing tags
    83 // Set the functions to handle opening and closing tags.
    84 xml_set_element_handler( $xml_parser, 'startElement', 'endElement' );
    84 xml_set_element_handler( $xml_parser, 'startElement', 'endElement' );
    85 
    85 
    86 if ( ! xml_parse( $xml_parser, $opml, true ) ) {
    86 if ( ! xml_parse( $xml_parser, $opml, true ) ) {
    87 	printf(
    87 	printf(
    88 		/* translators: 1: error message, 2: line number */
    88 		/* translators: 1: Error message, 2: Line number. */
    89 		__( 'XML Error: %1$s at line %2$s' ),
    89 		__( 'XML Error: %1$s at line %2$s' ),
    90 		xml_error_string( xml_get_error_code( $xml_parser ) ),
    90 		xml_error_string( xml_get_error_code( $xml_parser ) ),
    91 		xml_get_current_line_number( $xml_parser )
    91 		xml_get_current_line_number( $xml_parser )
    92 	);
    92 	);
    93 }
    93 }
    94 
    94 
    95 // Free up memory used by the XML parser
    95 // Free up memory used by the XML parser.
    96 xml_parser_free( $xml_parser );
    96 xml_parser_free( $xml_parser );
       
    97 unset( $xml_parser );