wp/wp-includes/rss.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    61 	function __construct( $source ) {
    61 	function __construct( $source ) {
    62 
    62 
    63 		# Check if PHP xml isn't compiled
    63 		# Check if PHP xml isn't compiled
    64 		#
    64 		#
    65 		if ( ! function_exists('xml_parser_create') ) {
    65 		if ( ! function_exists('xml_parser_create') ) {
    66 			return trigger_error( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." );
    66 			wp_trigger_error( '', "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." );
       
    67 			return;
    67 		}
    68 		}
    68 
    69 
    69 		$parser = xml_parser_create();
    70 		$parser = xml_parser_create();
    70 
    71 
    71 		$this->parser = $parser;
    72 		$this->parser = $parser;
   193 			$this->append_content( "<$element $attrs_str>"  );
   194 			$this->append_content( "<$element $attrs_str>"  );
   194 
   195 
   195 			array_unshift( $this->stack, $el );
   196 			array_unshift( $this->stack, $el );
   196 		}
   197 		}
   197 
   198 
   198 		// Atom support many links per containging element.
   199 		// Atom support many links per containing element.
   199 		// Magpie treats link elements of type rel='alternate'
   200 		// Magpie treats link elements of type rel='alternate'
   200 		// as being equivalent to RSS's simple link element.
   201 		// as being equivalent to RSS's simple link element.
   201 		//
   202 		//
   202 		elseif ($this->feed_type == ATOM and $el == 'link' )
   203 		elseif ($this->feed_type == ATOM and $el == 'link' )
   203 		{
   204 		{
   336 	}
   337 	}
   337 
   338 
   338 	function normalize () {
   339 	function normalize () {
   339 		// if atom populate rss fields
   340 		// if atom populate rss fields
   340 		if ( $this->is_atom() ) {
   341 		if ( $this->is_atom() ) {
   341 			$this->channel['descripton'] = $this->channel['tagline'];
   342 			$this->channel['description'] = $this->channel['tagline'];
   342 			for ( $i = 0; $i < count($this->items); $i++) {
   343 			for ( $i = 0; $i < count($this->items); $i++) {
   343 				$item = $this->items[$i];
   344 				$item = $this->items[$i];
   344 				if ( isset($item['summary']) )
   345 				if ( isset($item['summary']) )
   345 					$item['description'] = $item['summary'];
   346 					$item['description'] = $item['summary'];
   346 				if ( isset($item['atom_content']))
   347 				if ( isset($item['atom_content']))
   385 		return "$k=\"$v\"";
   386 		return "$k=\"$v\"";
   386 	}
   387 	}
   387 
   388 
   388 	function error( $errormsg, $lvl = E_USER_WARNING ) {
   389 	function error( $errormsg, $lvl = E_USER_WARNING ) {
   389 		if ( MAGPIE_DEBUG ) {
   390 		if ( MAGPIE_DEBUG ) {
   390 			trigger_error( $errormsg, $lvl);
   391 			wp_trigger_error('', $errormsg, $lvl);
   391 		} else {
   392 		} else {
   392 			error_log( $errormsg, 0);
   393 			error_log( $errormsg, 0);
   393 		}
   394 		}
   394 	}
   395 	}
   395 
   396 
   498 				}
   499 				}
   499 			}
   500 			}
   500 			else {
   501 			else {
   501 				$errormsg = "Failed to fetch $url. ";
   502 				$errormsg = "Failed to fetch $url. ";
   502 				if ( $resp->error ) {
   503 				if ( $resp->error ) {
   503 					# compensate for Snoopy's annoying habbit to tacking
   504 					# compensate for Snoopy's annoying habit to tacking
   504 					# on '\n'
   505 					# on '\n'
   505 					$http_error = substr($resp->error, 0, -2);
   506 					$http_error = substr($resp->error, 0, -2);
   506 					$errormsg .= "(HTTP Error: $http_error)";
   507 					$errormsg .= "(HTTP Error: $http_error)";
   507 				}
   508 				}
   508 				else {
   509 				else {
   539  * @since 1.5.0
   540  * @since 1.5.0
   540  * @package External
   541  * @package External
   541  * @subpackage MagpieRSS
   542  * @subpackage MagpieRSS
   542  *
   543  *
   543  * @param string $url URL to retrieve
   544  * @param string $url URL to retrieve
   544  * @param array $headers Optional. Headers to send to the URL.
   545  * @param array $headers Optional. Headers to send to the URL. Default empty string.
   545  * @return Snoopy style response
   546  * @return Snoopy style response
   546  */
   547  */
   547 function _fetch_remote_file($url, $headers = "" ) {
   548 function _fetch_remote_file($url, $headers = "" ) {
   548 	$resp = wp_safe_remote_request( $url, array( 'headers' => $headers, 'timeout' => MAGPIE_FETCH_TIME_OUT ) );
   549 	$resp = wp_safe_remote_request( $url, array( 'headers' => $headers, 'timeout' => MAGPIE_FETCH_TIME_OUT ) );
   549 	if ( is_wp_error($resp) ) {
   550 	if ( is_wp_error($resp) ) {
   629 
   630 
   630 /**
   631 /**
   631  * Set up constants with default values, unless user overrides.
   632  * Set up constants with default values, unless user overrides.
   632  *
   633  *
   633  * @since 1.5.0
   634  * @since 1.5.0
       
   635  * 
       
   636  * @global string $wp_version The WordPress version string.
       
   637  * 
   634  * @package External
   638  * @package External
   635  * @subpackage MagpieRSS
   639  * @subpackage MagpieRSS
   636  */
   640  */
   637 function init () {
   641 function init () {
   638 	if ( defined('MAGPIE_INITALIZED') ) {
   642 	if ( defined('MAGPIE_INITALIZED') ) {
   818 	Purpose:	register error
   822 	Purpose:	register error
   819 \*=======================================================================*/
   823 \*=======================================================================*/
   820 	function error ($errormsg, $lvl=E_USER_WARNING) {
   824 	function error ($errormsg, $lvl=E_USER_WARNING) {
   821 		$this->ERROR = $errormsg;
   825 		$this->ERROR = $errormsg;
   822 		if ( MAGPIE_DEBUG ) {
   826 		if ( MAGPIE_DEBUG ) {
   823 			trigger_error( $errormsg, $lvl);
   827 			wp_trigger_error( '', $errormsg, $lvl);
   824 		}
   828 		}
   825 		else {
   829 		else {
   826 			error_log( $errormsg, 0);
   830 			error_log( $errormsg, 0);
   827 		}
   831 		}
   828 	}
   832 	}
   834 }
   838 }
   835 
   839 
   836 if ( !function_exists('parse_w3cdtf') ) :
   840 if ( !function_exists('parse_w3cdtf') ) :
   837 function parse_w3cdtf ( $date_str ) {
   841 function parse_w3cdtf ( $date_str ) {
   838 
   842 
   839 	# regex to match wc3dtf
   843 	# regex to match W3C date/time formats
   840 	$pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/";
   844 	$pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/";
   841 
   845 
   842 	if ( preg_match( $pat, $date_str, $match ) ) {
   846 	if ( preg_match( $pat, $date_str, $match ) ) {
   843 		list( $year, $month, $day, $hours, $minutes, $seconds) =
   847 		list( $year, $month, $day, $hours, $minutes, $seconds) =
   844 			array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[7]);
   848 			array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[7]);