[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-simplepie-sanitize-kses.php (source)

   1  <?php
   2  /**
   3   * Feed API: WP_SimplePie_Sanitize_KSES class
   4   *
   5   * @package WordPress
   6   * @subpackage Feed
   7   * @since 4.7.0
   8   */
   9  
  10  // Don't load directly.
  11  if ( ! defined( 'ABSPATH' ) ) {
  12      die( '-1' );
  13  }
  14  
  15  /**
  16   * Core class used to implement SimplePie feed sanitization.
  17   *
  18   * Extends the SimplePie\Sanitize class to use KSES, because
  19   * we cannot universally count on DOMDocument being available.
  20   *
  21   * @since 3.5.0
  22   */
  23  #[AllowDynamicProperties]
  24  class WP_SimplePie_Sanitize_KSES extends SimplePie\Sanitize {
  25  
  26      /**
  27       * WordPress SimplePie sanitization using KSES.
  28       *
  29       * Sanitizes the incoming data, to ensure that it matches the type of data expected, using KSES.
  30       *
  31       * @since 3.5.0
  32       *
  33       * @param mixed   $data The data that needs to be sanitized.
  34       * @param int     $type The type of data that it's supposed to be.
  35       * @param string  $base Optional. The `xml:base` value to use when converting relative
  36       *                      URLs to absolute ones. Default empty.
  37       * @return mixed Sanitized data.
  38       */
  39  	public function sanitize( $data, $type, $base = '' ) {
  40          $data = trim( $data );
  41          if ( $type & SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML ) {
  42              if ( preg_match( '/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data ) ) {
  43                  $type |= SimplePie\SimplePie::CONSTRUCT_HTML;
  44              } else {
  45                  $type |= SimplePie\SimplePie::CONSTRUCT_TEXT;
  46              }
  47          }
  48          if ( $type & SimplePie\SimplePie::CONSTRUCT_BASE64 ) {
  49              $data = base64_decode( $data );
  50          }
  51          if ( $type & ( SimplePie\SimplePie::CONSTRUCT_HTML | \SimplePie\SimplePie::CONSTRUCT_XHTML ) ) {
  52              $data = wp_kses_post( $data );
  53              if ( 'UTF-8' !== $this->output_encoding ) {
  54                  $data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) );
  55              }
  56              return $data;
  57          } else {
  58              return parent::sanitize( $data, $type, $base );
  59          }
  60      }
  61  }


Generated : Sat Feb 22 08:20:01 2025 Cross-referenced by PHPXref