themeidol_array_obj_string( $error ) ) . '">
' . __('Sorry, this feed is currently unavailable or does not exists anymore.', 'themeidol-all-widget') . '
';
}
/***************************************************************
* Convert array or object into string
***************************************************************/
function themeidol_array_obj_string ( $error ){
if ( is_array( $error ) || is_object( $error ) ) {
return print_r( $error, true );
} else {
return $error;
}
}
/***************************************************************
* Padding ratio based on image size
***************************************************************/
function themeidol_add_item_padding( $itemAttr, $sizes ){
$paddinTop = number_format( ( 15 / 150 ) * $sizes[ 'height' ], 0 );
$paddinBottom = number_format( ( 25 / 150 ) * $sizes[ 'height' ], 0 );
$stylePadding = ' style="padding: ' . $paddinTop . 'px 0 ' . $paddinBottom . 'px"';
return $itemAttr . $stylePadding;
}
/***************************************************************
* Feed item container class
***************************************************************/
function themeidol_classes_item( $itemAttr ){
$classes = array( 'rss_item' );
$classes = apply_filters( 'themeidol_add_classes_item', $classes );
$classes = ' class="' . implode( ' ', $classes ) . '"';
return $itemAttr . $classes;
}
/***************************************************************
* Main Rss Function function
***************************************************************/
function themeidol_rss( $atts, $content = '' ) {
global $feedzyStyle;
$feedzyStyle = true;
$count = 0;
//Load SimplePie if not already
if ( !class_exists( 'SimplePie' ) ){
require_once( ABSPATH . WPINC . '/class-feed.php' );
}
//Retrieve & extract shorcode parameters
extract( shortcode_atts( array(
"feeds" => '', //comma separated feeds url
"max" => '5', //number of feeds items (0 for unlimited)
"feed_title" => 'yes', //display feed title yes/no
"target" => '_blank', //_blank, _self
"title" => '', //strip title after X char
"meta" => 'yes', //yes, no
"summary" => 'yes', //strip title
"summarylength" => '', //strip summary after X char
"thumb" => 'yes', //yes, no, auto
"default" => '', //default thumb URL if no image found (only if thumb is set to yes or auto)
"size" => '', //thumbs pixel size
"keywords_title" => '' //only display item if title contains specific keywords (comma-separated list/case sensitive)
), $atts, 'themeidol_default' ) );
//Use "shortcode_atts_feedzy_default" filter to edit shortcode parameters default values or add your owns.
if ( !empty( $feeds ) ) {
$feeds = rtrim( $feeds, ',' );
$feeds = explode( ',', $feeds );
//Remove SSL from HTTP request to prevent fetching errors
foreach( $feeds as $feed ){
$feedURL[] = preg_replace("/^https:/i", "http:", $feed);
}
if ( count( $feedURL ) === 1 ) {
$feedURL = $feedURL[0];
}
}
if ( $max == '0' ) {
$max = '999';
} else if ( empty( $max ) || !ctype_digit( $max ) ) {
$max = '5';
}
if ( empty( $size ) || !ctype_digit( $size ) ){
$size = '150';
}
$sizes = array( 'width' => $size, 'height' => $size );
$sizes = apply_filters( 'themeidol_thumb_sizes', $sizes, $feedURL );
if ( !empty( $title ) && !ctype_digit( $title ) ){
$title = '';
}
if ( !empty($keywords_title)){
$keywords_title = rtrim( $keywords_title, ',' );
$keywords_title = array_map( 'trim', explode( ',', $keywords_title ) );
}
if ( !empty( $summarylength ) && !ctype_digit( $summarylength ) ){
$summarylength = '';
}
if ( !empty( $default ) ) {
$default = $default;
} else {
$default = apply_filters( 'themeidol_default_image', $default, $feedURL );
}
//Load SimplePie Instance
$feed = new SimplePie();
$feed -> set_feed_url( $feedURL );
$feed -> enable_cache( true );
$feed -> enable_order_by_date( true );
$feed -> set_cache_class( 'WP_Feed_Cache' );
$feed -> set_file_class( 'WP_SimplePie_File' );
$feed -> set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 7200, $feedURL ) );
do_action_ref_array( 'wp_feed_options', array( $feed, $feedURL ) );
$feed -> strip_comments( true );
$feed -> strip_htmltags( array( 'base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style' ) );
$feed -> init();
$feed -> handle_content_type();
// Display the error message
if ( $feed -> error() ) {
$content .= apply_filters( 'themeidol_default_error', $feed -> error(), $feedURL );
}
$content .= '';
return apply_filters( 'themeidol_global_output', $content, $feedURL );
}//end of themeidol_rss
/***************************************************************
* Retrive image from the item object
***************************************************************/
function themeidol_retrieve_image( $item ) {
$thethumbnail = "";
if ( $enclosures = $item->get_enclosures() ) {
foreach( (array) $enclosures as $enclosure ){
//item thumb
if ( $thumbnail = $enclosure->get_thumbnail() ) {
$thethumbnail = $thumbnail;
}
//media:thumbnail
if ( isset( $enclosure->thumbnails ) ) {
foreach ( (array) $enclosure->thumbnails as $thumbnail ) {
$thethumbnail = $thumbnail;
}
}
//enclosure
if ( $thumbnail = $enclosure->embed() ) {
$pattern = '/https?:\/\/.*\.(?:jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/iU';
if ( preg_match( $pattern, $thumbnail, $matches ) ) {
$thethumbnail = $matches[0];
}
}
//media:content && strpos( $enclosure->type, 'image' ) !== false
foreach ( (array) $enclosure->get_link() as $thumbnail ) {
$pattern = '/https?:\/\/.*\.(?:jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/iU';
$imgsrc = $thumbnail;
if ( preg_match( $pattern, $imgsrc, $matches ) ) {
$thethumbnail = $matches[0];
break;
}
}
//break loop if thumbnail found
if ( ! empty( $thethumbnail ) ) {
break;
}
}
}
//xmlns:itunes podcast
if ( empty( $thethumbnail ) ) {
$data = $item->get_item_tags('http://www.itunes.com/dtds/podcast-1.0.dtd', 'image');
if ( isset( $data['0']['attribs']['']['href'] ) && !empty( $data['0']['attribs']['']['href'] ) ){
$thethumbnail = $data['0']['attribs']['']['href'];
}
}
//content image
if ( empty( $thethumbnail ) ) {
$feedDescription = $item->get_content();
$thethumbnail = $this->themeidol_returnImage( $feedDescription );
}
//description image
if ( empty( $thethumbnail ) ) {
$feedDescription = $item->get_description();
$thethumbnail = $this->themeidol_returnImage( $feedDescription );
}
return $thethumbnail;
}
/***************************************************************
* Get an image from a string
***************************************************************/
function themeidol_returnImage( $string ) {
$img = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
$pattern = "/