feeds' ), array( $this, 'dashboard' ), array( $this, 'dashboard_control' ) );
}
/**
* Fetch RSS items from the feed.
*
* @param int $num Number of items to fetch.
* @param string $feed The feed to fetch.
* @return array|bool False on error, array of RSS items on success.
*/
public function fetch_rss_items( $num, $feed ) {
include_once( ABSPATH . WPINC . '/feed.php' );
$rss = fetch_feed( $feed );
// Bail if feed doesn't work
if ( !$rss || is_wp_error( $rss ) )
return false;
$rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
// If the feed was erroneous
if ( !$rss_items ) {
$md5 = md5( $feed );
delete_transient( 'feed_' . $md5 );
delete_transient( 'feed_mod_' . $md5 );
$rss = fetch_feed( $feed );
$rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
}
return $rss_items;
}
/**
* Output CSS
*
* @return string
*/
function style() {
?>
fetch_rss_items( $item_count, 'http://pipes.yahoo.com/pipes/pipe.run?_id=52c339c010550750e3e64d478b1c96ea&_render=rss' );
$this->style();
$content = '
';
if ( !$rss_items ) {
$content .= '- ' . __( 'Error fetching feed' ) . '
';
} else {
foreach ( $rss_items as $item ) {
$title = esc_attr( strtolower( sanitize_title_with_dashes( htmlentities( $item->get_title() ) ) ) );
$class = str_replace( array( 'http://', 'https://' ), '', $item->get_permalink() );
$class = str_replace( array( '2010.', '2011.', '2012.', '2013.', '2014.', '2015.' ), '', $class );
$class = str_replace( array( '.com/', '.net/', '.org/', '.la/', 'la.' ), ' ', $class );
$class = str_replace( array( '2011/', '2012/', '2013/', '2014/' ), '', $class );
$class = str_replace( array( '01/', '02/', '03/', '04/', '05/', '06/', '07/', '08/', '09/', '10/', '11/', '12/' ), '', $class );
$class = str_replace( $title, '', $class );
$class = str_replace( '/', '', $class );
$class = str_replace( 'feedproxy.google', '', $class );
$class = str_replace( '~r', '', $class );
$class = str_replace( '~', ' ', $class );
if ( strstr( $class, ' ', true ) ) {
$class = strstr( $class, ' ', true ); // Remove everything after the space
}
// Redundant, I know. Can you make a preg_replace for this?
$url = preg_replace( '/#.*/', '', esc_url( $item->get_permalink(), null, 'display' ) );
$content .= '
';
$content .= '- ';
$content .= ' ';
$content .= '' . esc_attr( $item->get_date('F, jS Y') ) . '';
$content .= '
';
}
}
$content .= '
';
echo $content;
}
/**
* Print the dashboard control widget
*
* @return string
*/
function dashboard_control() {
if ( !$widget_options = get_option( 'the_frosty_dashboard_widget_options' ) )
$widget_options = array();
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) && 'thefrosty_dashboard' == $_POST['widget_id'] ) {
$items = stripslashes_deep( $_POST['thefrosty_dashboard_items'] );
$widget_options['items'] = $items;
update_option( 'the_frosty_dashboard_widget_options', $widget_options );
}
//print_r( $widget_options ); ?>