/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. if ( isset( $attrs['TITLE'] ) ) { 
  41. $name = $attrs['TITLE']; 
  42. $url = ''; 
  43. if ( isset( $attrs['URL'] ) ) { 
  44. $url = $attrs['URL']; 
  45. if ( isset( $attrs['HTMLURL'] ) ) { 
  46. $url = $attrs['HTMLURL']; 
  47.  
  48. // Save the data away. 
  49. $names[] = $name; 
  50. $urls[] = $url; 
  51. $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : ''; 
  52. $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : ''; 
  53. $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : ''; 
  54. } // End if outline. 
  55.  
  56. /** 
  57. * XML callback function that is called at the end of a XML tag. 
  58. * 
  59. * @since 0.71 
  60. * @access private 
  61. * 
  62. * @param mixed $parser XML Parser resource. 
  63. * @param string $tagName XML tag name. 
  64. */ 
  65. function endElement($parser, $tagName) { 
  66. // Nothing to do. 
  67.  
  68. // Create an XML parser 
  69. if ( ! function_exists( 'xml_parser_create' ) ) { 
  70. trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); 
  71. wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); 
  72.  
  73. $xml_parser = xml_parser_create(); 
  74.  
  75. // Set the functions to handle opening and closing tags 
  76. xml_set_element_handler($xml_parser, "startElement", "endElement"); 
  77.  
  78. if ( ! xml_parse( $xml_parser, $opml, true ) ) { 
  79. printf( 
  80. /** translators: 1: error message, 2: line number */ 
  81. __( 'XML Error: %1$s at line %2$s' ),  
  82. xml_error_string( xml_get_error_code( $xml_parser ) ),  
  83. xml_get_current_line_number( $xml_parser ) 
  84. ); 
  85.  
  86. // Free up memory used by the XML parser 
  87. xml_parser_free($xml_parser); 
.