[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> link-parse-opml.php (source)

   1  <?php
   2  /**
   3   * Parse OPML XML files and store in globals.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  // Don't load directly.
  10  if ( ! defined( 'ABSPATH' ) ) {
  11      exit;
  12  }
  13  
  14  /**
  15   * @global string $opml
  16   */
  17  global $opml;
  18  
  19  /**
  20   * Starts a new XML tag.
  21   *
  22   * Callback function for xml_set_element_handler().
  23   *
  24   * @since 0.71
  25   * @access private
  26   *
  27   * @global array $names
  28   * @global array $urls
  29   * @global array $targets
  30   * @global array $descriptions
  31   * @global array $feeds
  32   *
  33   * @param resource $parser   XML Parser resource.
  34   * @param string   $tag_name XML element name.
  35   * @param array    $attrs    XML element attributes.
  36   */
  37  function startElement( $parser, $tag_name, $attrs ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  38      global $names, $urls, $targets, $descriptions, $feeds;
  39  
  40      if ( 'OUTLINE' === $tag_name ) {
  41          $name = '';
  42          if ( isset( $attrs['TEXT'] ) ) {
  43              $name = $attrs['TEXT'];
  44          }
  45          if ( isset( $attrs['TITLE'] ) ) {
  46              $name = $attrs['TITLE'];
  47          }
  48          $url = '';
  49          if ( isset( $attrs['URL'] ) ) {
  50              $url = $attrs['URL'];
  51          }
  52          if ( isset( $attrs['HTMLURL'] ) ) {
  53              $url = $attrs['HTMLURL'];
  54          }
  55  
  56          // Save the data away.
  57          $names[]        = $name;
  58          $urls[]         = $url;
  59          $targets[]      = $attrs['TARGET'] ?? '';
  60          $feeds[]        = $attrs['XMLURL'] ?? '';
  61          $descriptions[] = $attrs['DESCRIPTION'] ?? '';
  62      } // End if outline.
  63  }
  64  
  65  /**
  66   * Ends a new XML tag.
  67   *
  68   * Callback function for xml_set_element_handler().
  69   *
  70   * @since 0.71
  71   * @access private
  72   *
  73   * @param resource $parser   XML Parser resource.
  74   * @param string   $tag_name XML tag name.
  75   */
  76  function endElement( $parser, $tag_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  77      // Nothing to do.
  78  }
  79  
  80  // Create an XML parser.
  81  if ( ! function_exists( 'xml_parser_create' ) ) {
  82      wp_trigger_error( '', __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
  83      wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
  84  }
  85  
  86  $xml_parser = xml_parser_create();
  87  
  88  // Set the functions to handle opening and closing tags.
  89  xml_set_element_handler( $xml_parser, 'startElement', 'endElement' );
  90  
  91  if ( ! xml_parse( $xml_parser, $opml, true ) ) {
  92      printf(
  93          /* translators: 1: Error message, 2: Line number. */
  94          __( 'XML Error: %1$s at line %2$s' ),
  95          xml_error_string( xml_get_error_code( $xml_parser ) ),
  96          xml_get_current_line_number( $xml_parser )
  97      );
  98  }
  99  
 100  if ( PHP_VERSION_ID < 80000 ) { // xml_parser_free() has no effect as of PHP 8.0.
 101      // Free up memory used by the XML parser.
 102      xml_parser_free( $xml_parser );
 103  }
 104  
 105  unset( $xml_parser );


Generated : Sun Jul 26 08:20:18 2026 Cross-referenced by PHPXref