<?php

class Intense_Rss extends Intense_Shortcode {

	function __construct() {
        parent::__construct();

		global $intense_visions_options;

		$this->title = __( 'RSS', 'intense' );
		$this->description = __( 'Show RSS feed posts in a list using the RSS shortcode. Each item in the list can be formatted using a template. More information about RSS feeds can be found at <a href="http://en.wikipedia.org/wiki/RSS">http://en.wikipedia.org/wiki/RSS</a>.', 'intense' );
		$this->category = __( 'Elements', 'intense' );
		$this->show_preview = true;
	}

	function shortcode( $atts, $content = null ) {
		global $intense_visions_options, $rss, $rss_item;
		extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

		$output = '';

		$rss = fetch_feed( $url );
		$id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : '';

		if ( ! is_wp_error( $rss ) ) {
			$maxitems = $rss->get_item_quantity( $max ); 
			$rss_items = $rss->get_items( 0, $maxitems );
		} else {
			return $output;
		}

		$output .= '<ul' . $id . ' class="intense rss' . ( !empty( $class ) ? ' ' . $class : '' ) . '">';

		if ( $maxitems == 0 ) {
			$output .= '<li>' . $no_items . '</li>';
		} else {
			foreach ( $rss_items as $item ) {
				$rss_item = $item;	

				$output .= '<li>';
				$output .= intense_get_template( array(
					'/rss/' . $template . '.php',
					'/rss/title.php'
				) );
				$output .= '</li>';
			}
		}

		$output .= '</ul>';

		return $output;
	}
}
