consist of enclosure HTML tag(s) with a URI and other
* attributes.
*
* @since 1.5.0
*/
function rss_enclosure() {
if ( post_password_required() ) {
return;
}
foreach ( (array) get_post_custom() as $key => $val ) {
if ( 'enclosure' === $key ) {
foreach ( (array) $val as $enc ) {
$enclosure = explode( "\n", $enc );
if ( count( $enclosure ) < 3 ) {
continue;
}
// Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'.
$t = preg_split( '/[ \t]/', trim( $enclosure[2] ) );
$type = $t[0];
/**
* Filters the RSS enclosure HTML link tag for the current post.
*
* @since 2.2.0
*
* @param string $html_link_tag The HTML link tag with a URI and other attributes.
*/
echo apply_filters( 'rss_enclosure', '' . "\n" );
}
}
}
}
/**
* Displays the atom enclosure for the current post.
*
* Uses the global $post to check whether the post requires a password and if
* the user has the password for the post. If not then it will return before
* displaying.
*
* Also uses the function get_post_custom() to get the post's 'enclosure'
* metadata field and parses the value to display the enclosure(s). The
* enclosure(s) consist of link HTML tag(s) with a URI and other attributes.
*
* @since 2.2.0
*/
function atom_enclosure() {
if ( post_password_required() ) {
return;
}
foreach ( (array) get_post_custom() as $key => $val ) {
if ( 'enclosure' === $key ) {
foreach ( (array) $val as $enc ) {
$enclosure = explode( "\n", $enc );
$url = '';
$type = '';
$length = 0;
$mimes = get_allowed_mime_types();
// Parse URL.
if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {
$url = trim( $enclosure[0] );
}
// Parse length and type.
for ( $i = 1; $i <= 2; $i++ ) {
if ( isset( $enclosure[ $i ] ) ) {
if ( is_numeric( $enclosure[ $i ] ) ) {
$length = trim( $enclosure[ $i ] );
} elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) {
$type = trim( $enclosure[ $i ] );
}
}
}
$html_link_tag = sprintf(
"\n",
esc_url( $url ),
esc_attr( $length ),
esc_attr( $type )
);
/**
* Filters the atom enclosure HTML link tag for the current post.
*
* @since 2.2.0
*
* @param string $html_link_tag The HTML link tag with a URI and other attributes.
*/
echo apply_filters( 'atom_enclosure', $html_link_tag );
}
}
}
}
/**
* Determines the type of a string of data with the data formatted.
*
* Tell whether the type is text, HTML, or XHTML, per RFC 4287 section 3.1.
*
* In the case of WordPress, text is defined as containing no markup,
* XHTML is defined as "well formed", and HTML as tag soup (i.e., the rest).
*
* Container div tags are added to XHTML values, per section 3.1.1.3.
*
* @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
*
* @since 2.5.0
*
* @param string $data Input string.
* @return array array(type, value)
*/
function prep_atom_text_construct( $data ) {
if ( ! str_contains( $data, '<' ) && ! str_contains( $data, '&' ) ) {
return array( 'text', $data );
}
if ( ! function_exists( 'xml_parser_create' ) ) {
wp_trigger_error( '', __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
return array( 'html', "" );
}
$parser = xml_parser_create();
xml_parse( $parser, '
";
return array( 'xhtml', $data );
}
}
if ( ! str_contains( $data, ']]>' ) ) {
return array( 'html', "" );
} else {
return array( 'html', htmlspecialchars( $data ) );
}
}
/**
* Displays Site Icon in atom feeds.
*
* @since 4.3.0
*
* @see get_site_icon_url()
*/
function atom_site_icon() {
$url = get_site_icon_url( 32 );
if ( $url ) {
echo '' . convert_chars( $url ) . "\n";
}
}
/**
* Displays Site Icon in RSS2.
*
* @since 4.3.0
*/
function rss2_site_icon() {
$rss_title = get_wp_title_rss();
if ( empty( $rss_title ) ) {
$rss_title = get_bloginfo_rss( 'name' );
}
$url = get_site_icon_url( 32 );
if ( $url ) {
echo '
' . convert_chars( $url ) . '' . $rss_title . '
' . get_bloginfo_rss( 'url' ) . '
3232 ' . "\n";
}
}
/**
* Returns the link for the currently displayed feed.
*
* @since 5.3.0
*
* @return string Correct link for the atom:self element.
*/
function get_self_link() {
$parsed = parse_url( home_url() );
$domain = $parsed['host'];
if ( isset( $parsed['port'] ) ) {
$domain .= ':' . $parsed['port'];
}
return set_url_scheme( 'http://' . $domain . wp_unslash( $_SERVER['REQUEST_URI'] ) );
}
/**
* Displays the link for the currently displayed feed in a XSS safe way.
*
* Generate a correct link for the atom:self element.
*
* @since 2.5.0
*/
function self_link() {
/**
* Filters the current feed URL.
*
* @since 3.6.0
*
* @see set_url_scheme()
* @see wp_unslash()
*
* @param string $feed_link The link for the feed with set URL scheme.
*/
echo esc_url( apply_filters( 'self_link', get_self_link() ) );
}
/**
* Gets the UTC time of the most recently modified post from WP_Query.
*
* If viewing a comment feed, the time of the most recently modified
* comment will be returned.
*
* @since 5.2.0
*
* @global WP_Query $wp_query WordPress Query object.
*
* @param string $format Date format string to return the time in.
* @return string|false The time in requested format, or false on failure.
*/
function get_feed_build_date( $format ) {
global $wp_query;
$datetime = false;
$max_modified_time = false;
$utc = new DateTimeZone( 'UTC' );
if ( ! empty( $wp_query ) && $wp_query->have_posts() ) {
// Extract the post modified times from the posts.
$modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' );
// If this is a comment feed, check those objects too.
if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) {
// Extract the comment modified times from the comments.
$comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );
// Add the comment times to the post times for comparison.
$modified_times = array_merge( $modified_times, $comment_times );
}
// Determine the maximum modified time.
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', max( $modified_times ), $utc );
}
if ( false === $datetime ) {
// Fall back to last time any post was modified or published.
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', get_lastpostmodified( 'GMT' ), $utc );
}
if ( false !== $datetime ) {
$max_modified_time = $datetime->format( $format );
}
/**
* Filters the date the last post or comment in the query was modified.
*
* @since 5.2.0
*
* @param string|false $max_modified_time Date the last post or comment was modified in the query, in UTC.
* False on failure.
* @param string $format The date format requested in get_feed_build_date().
*/
return apply_filters( 'get_feed_build_date', $max_modified_time, $format );
}
/**
* Returns the content type for specified feed type.
*
* @since 2.8.0
*
* @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'.
* @return string Content type for specified feed type.
*/
function feed_content_type( $type = '' ) {
if ( empty( $type ) ) {
$type = get_default_feed();
}
$types = array(
'rss' => 'application/rss+xml',
'rss2' => 'application/rss+xml',
'rss-http' => 'text/xml',
'atom' => 'application/atom+xml',
'rdf' => 'application/rdf+xml',
);
$content_type = ( ! empty( $types[ $type ] ) ) ? $types[ $type ] : 'application/octet-stream';
/**
* Filters the content type for a specific feed type.
*
* @since 2.8.0
*
* @param string $content_type Content type indicating the type of data that a feed contains.
* @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'.
*/
return apply_filters( 'feed_content_type', $content_type, $type );
}
/**
* Builds SimplePie object based on RSS or Atom feed from URL.
*
* @since 2.8.0
*
* @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
* using SimplePie's multifeed feature.
* See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
* @return SimplePie\SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
*/
function fetch_feed( $url ) {
if ( ! class_exists( 'SimplePie\SimplePie', false ) ) {
require_once ABSPATH . WPINC . '/class-simplepie.php';
}
require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php';
$feed = new SimplePie\SimplePie();
$feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
/*
* We must manually overwrite $feed->sanitize because SimplePie's constructor
* sets it before we have a chance to set the sanitization class.
*/
$feed->sanitize = new WP_SimplePie_Sanitize_KSES();
// Register the cache handler using the recommended method for SimplePie 1.3 or later.
if ( method_exists( 'SimplePie_Cache', 'register' ) ) {
SimplePie_Cache::register( 'wp_transient', 'WP_Feed_Cache_Transient' );
$feed->set_cache_location( 'wp_transient' );
} else {
// Back-compat for SimplePie 1.2.x.
require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
$feed->set_cache_class( 'WP_Feed_Cache' );
}
$feed->set_file_class( 'WP_SimplePie_File' );
$feed->set_feed_url( $url );
/** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
/**
* Fires just before processing the SimplePie feed object.
*
* @since 3.0.0
*
* @param SimplePie\SimplePie $feed SimplePie feed object (passed by reference).
* @param string|string[] $url URL of feed or array of URLs of feeds to retrieve.
*/
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
$feed->init();
$feed->set_output_encoding( get_bloginfo( 'charset' ) );
if ( $feed->error() ) {
return new WP_Error( 'simplepie-error', $feed->error() );
}
return $feed;
}
surfing – Nos Dushi Bida