get_error_message(); $err_msg='
'; $err_msg.='Unable to fetch the feed
Error :
'; echo $err_msg; // Prints the error message } if (!is_wp_error($feed)) : $feed->init(); $feed->set_output_encoding('UTF-8'); // set encoding $feed->handle_content_type(); // ensure encoding $feed->enable_cache(false); // no cache $limit = $feed->get_item_quantity($options['num']); // get feed items $items = $feed->get_items(0, $limit); // set array endif; } if ($limit == 0) { echo '

RSS Feed currently unavailable.

'; } else { $returnMarkup = ''; $returnMarkup .= '
'; } return $returnMarkup; } function timesince ($time) { $time = time() - $time; // to get the time since that moment $tokens = array ( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); $t = $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); return $t. " ago "; } } /** * FacebookPageFeedWidget Class */ class FacebookPageFeedWidget extends WP_Widget { private /** @type {string} */ $languagePath; /** constructor */ function FacebookPageFeedWidget() { $this->options = array( array( 'name' => 'title', 'label' => __( 'Title', 'fbf' ), 'type' => 'text' ), array( 'name' => 'pageID', 'label' => __( 'Facebook Page ID
(Replace your facebook page ID here)', 'fbf' ), 'type' => 'text' ), array( 'name' => 'num', 'label' => __( 'Show # of Posts', 'fbf' ), 'type' => 'text' ), array( 'name' => 'avatar_size', 'label' => __( 'Avatar size', 'fbf' ), 'type' => 'radio', 'values' => array('square'=>'Square','small'=>'Small','normal'=>'Normal','large'=>'Large') ), array( 'name' => 'update', 'label' => __( 'Show timestamps', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'feed_title', 'label' => __( 'Show feed title', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'show_description', 'label' => __( 'Show Description', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'show_avatar', 'label' => __( 'Show Avatar', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'link_target_blank', 'label' => __( 'Create links on new window / tab', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'replace_img_urls', 'label' => __( 'Try to replace img-URLs (beta)', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'like_button', 'label' => __( 'Show facebook like button', 'fbf' ), 'type' => 'checkbox' ), array( 'name' => 'like_button_position', 'label' => __( 'Like button position', 'fbf' ), 'type' => 'radio', 'values' => array('top'=>'Top','bottom'=>'Bottom') ), ); parent::WP_Widget(false, $name = 'FBF Facebook page Feed Widget'); } /** @see WP_Widget::widget */ function widget($args, $instance) { extract( $args ); $title = $instance['title']; echo $before_widget; if ( $title ) { echo $before_title . $instance['title'] . $after_title; } echo fbf_facebook_messages($instance); echo $after_widget; } /** @see WP_Widget::update */ function update($new_instance, $old_instance) { $instance = $old_instance; foreach ($this->options as $val) { if ($val['type']=='text') { $instance[$val['name']] = strip_tags($new_instance[$val['name']]); } else if ($val['type']=='checkbox') { $instance[$val['name']] = ($new_instance[$val['name']]=='on') ? true : false; } else if ($val['type']=='radio') { $instance[$val['name']] = $new_instance[$val['name']]; } } return $instance; } /** @see WP_Widget::form */ function form($instance) { $default['title'] = __( 'FBF Facebook page Feed Widget', 'fbf' ); $default['pageID'] = '133662330114199'; $default['num'] = '5'; $default['feed_title'] = true; $default['update'] = true; $default['show_description'] = true; $default['show_avatar'] = true; $default['avatar_size'] = 'small'; // Available sizes square, small, normal, or large $default['link_target_blank'] = true; $default['like_button'] = true; $default['like_button_position'] = 'top'; $default['replace_img_urls'] = false; $instance = wp_parse_args($instance,$default); foreach ($this->options as $val) { $label = ''; if ($val['type']=='text') { echo '

'.$label.'
'; echo '

'; } else if ($val['type']=='checkbox') { $checked = ($instance[$val['name']]) ? 'checked="checked"' : ''; echo ' '.$label.'
'; } else if ($val['type']=='radio') { echo '

'.$label.'
'; foreach($val['values'] as $key=>$name){ $label = ''; $checked = ($instance[$val['name']] == $key) ? 'checked="checked"' : ''; echo ''.$label.' '; } echo '

'; } } } } // class FacebookPageFeedWidget // register FacebookPageFeedWidget widget add_action('widgets_init', create_function('', 'return register_widget("FacebookPageFeedWidget");')); // register stylesheet 25-aug-2012 add_action('wp_head', 'fbf_add_header_css', 100); function fbf_add_header_css() { echo '' . "\n"; } // Short code FacebookPageFeed 25-aug-2012 - edited 2 feb 2013 function fbf_short_code($atts) { $atts['pageID'] = $atts['pageid']; $atts= shortcode_atts(array( 'pageID' => '133662330114199', 'num' => '5', 'update' => false, 'show_description' => false, 'show_avatar' => false, 'avatar_size' => 'small', 'link_target_blank' => false, 'feed_title' => true, 'like_button' => true, 'like_button_position' => true, 'replace_img_urls' => false, ), $atts); return fbf_facebook_messages($atts); } // sample short code // [fbf_page_feed pageID="133662330114199" num="2" show_description="true" update="true" show_avatar="true" avatar_size="square" link_target_blank="true" feed_title = "true" like_button="true" like_button_position="top"] add_shortcode('fbf_page_feed', 'fbf_short_code');