'. __( 'Widgets', '365projectorg-widget' ) .''; return $actions; } add_action( 'widgets_init', 'tsfproject_register_widget' ); function tsfproject_register_widget() { register_widget( 'tsfproject_widget' ); } class tsfproject_widget extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'tsfproject-widget', 'description' => __( 'Display images from 365project.org feeds', '365projectorg-widget' ) ); $control_ops = array( 'width' => 300 ); parent::WP_Widget( 'tsfproject_widget', __( '365Project.org Widget', '365projectorg-widget' ), $widget_ops, $control_ops ); } function widget( $args, $instance ) { extract( $args, EXTR_SKIP ); echo $before_widget; echo $instance['hide_title'] ? '' : $before_title . esc_html( $instance['title'] ) . $after_title; $url = esc_url( $instance['feed'] ); $timeout = intval( $instance['timeout'] ); $limit = intval( $instance['limit'] ); $transient_id = md5( $widget_id . $url . $limit ); if ( false === ( $html = get_transient( $transient_id ) ) ) { $body = wp_remote_retrieve_body( wp_remote_get( $url ) ); $body = simplexml_load_string( $body ); $html = ''; $i = 0; foreach( $body->channel->item as $item ) { $description = $item->description; preg_match_all( '/()/', $description, $matches ); $html .= $matches[0][0]; ++$i; if ( $i == $limit ) break; } set_transient( $transient_id, $html, $timeout ); //$html .= ''; } echo $html; echo $after_widget; } //end widget() function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['hide_title'] = (bool) $new_instance['hide_title'] ? 1 : 0; $instance['feed'] = strip_tags( $new_instance['feed'] ); $instance['timeout'] = strip_tags( $new_instance['timeout'] ); $instance['limit'] = strip_tags( $new_instance['limit'] ); return $instance; } //end update() function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '365project.org', 'hide_title' => 0, 'feed' => 'http://365project.org/browse/latest/feed', 'timeout' => (60*10), 'limit' => 3 ) ); extract( $instance ); ?>

/>

http://365project.org/browse/latest/feed' ); ?>