You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

96 line
2.3 KiB

  1. <?php
  2. /**
  3. * Parse OPML XML files and store in globals.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. if ( ! defined('ABSPATH') )
  9. die();
  10. /**
  11. * @global string $opml
  12. */
  13. global $opml;
  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. if ( 'OUTLINE' === $tagName ) {
  33. $name = '';
  34. if ( isset( $attrs['TEXT'] ) ) {
  35. $name = $attrs['TEXT'];
  36. }
  37. if ( isset( $attrs['TITLE'] ) ) {
  38. $name = $attrs['TITLE'];
  39. }
  40. $url = '';
  41. if ( isset( $attrs['URL'] ) ) {
  42. $url = $attrs['URL'];
  43. }
  44. if ( isset( $attrs['HTMLURL'] ) ) {
  45. $url = $attrs['HTMLURL'];
  46. }
  47. // Save the data away.
  48. $names[] = $name;
  49. $urls[] = $url;
  50. $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : '';
  51. $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : '';
  52. $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : '';
  53. } // End if outline.
  54. }
  55. /**
  56. * XML callback function that is called at the end of a XML tag.
  57. *
  58. * @since 0.71
  59. * @access private
  60. *
  61. * @param mixed $parser XML Parser resource.
  62. * @param string $tagName XML tag name.
  63. */
  64. function endElement($parser, $tagName) {
  65. // Nothing to do.
  66. }
  67. // Create an XML parser
  68. if ( ! function_exists( 'xml_parser_create' ) ) {
  69. trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
  70. wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
  71. }
  72. $xml_parser = xml_parser_create();
  73. // Set the functions to handle opening and closing tags
  74. xml_set_element_handler($xml_parser, "startElement", "endElement");
  75. if ( ! xml_parse( $xml_parser, $opml, true ) ) {
  76. printf(
  77. /* translators: 1: error message, 2: line number */
  78. __( '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);