function widget($args, $instance) { extract($args); $page_id = trim($instance['page_id']); $n = (int) $instance['n']; $fb = fb_connector::get_fb_obj(); $post_list = $fb->api("/{$page_id}?fields=feed", "GET"); $html = "<div class='owl-carousel spri-fb-page-slide widget_dock'>"; foreach (array_slice($post_list['feed']['data'], 0, $n) as $item) { $html .= '<div>'; $html .= <<<ARTICLE <p> <a href="http://facebook.com/{$item['id']}" target="_blank"> {$item['message']} </a> </p> ARTICLE; $html .= '</div>'; } $html .= "</div>"; echo $before_widget; echo $html; echo $after_widget; }
function __construct() { // database table name setup global $wpdb; $this->post_date_table = $wpdb->prefix . "spri_fb_page_post_date"; $this->post_tag_table = $wpdb->prefix . "spri_fb_page_post_tag"; $this->target_page_table = $wpdb->prefix . "spri_fb_target_page"; // Generate FB object $this->fb = fb_connector::get_fb_obj(); // widget scripts add_action('wp_enqueue_scripts', array($this, 'register_widget_scripts')); // widget register add_action('widgets_init', array($this, 'fb_page_register_widget')); // Shortcode add_shortcode('spri-fb-page-feed', array($this, 'fb_page_feed_shortcode')); // Filter add_filter('query_vars', array($this, 'url_query_filter')); // create menu pages new spri_fb_page_option_menu(); // activation and deactivation hooks register_activation_hook(__FILE__, array($this, 'activation')); register_deactivation_hook(__FILE__, array($this, 'deactivation')); //cron job add_action('spri_fb_page_crawl_cron', array($this, 'do_cron_job')); // time interval for test add_filter('cron_schedules', array($this, 'add_custom_cron_interval')); // register style wp_register_style('spri-fb-page-auto-complete-style', plugins_url('/lib/jQuery-autoComplete/jquery.auto-complete.css', __FILE__)); wp_register_style('spri-fb-page-shortcode-style', plugins_url('/css/shortcode.css', __FILE__)); wp_register_style('spri-fb-page-widget-style', plugins_url('/css/widget.css', __FILE__)); wp_register_style('spri-fb-page-widget-slider-style', plugins_url('/lib/owl-carousel/owl.carousel.css', __FILE__)); // register script wp_register_script('spri-fb-page-shortcode-script', plugins_url('/js/shortcode.js', __FILE__), array('jquery')); wp_register_script('spri-fb-page-auto-complete-script', plugins_url('/lib/jQuery-autoComplete/jquery.auto-complete.min.js', __FILE__), array('jquery')); // register ajax add_action('wp_ajax_spri_fb_page_tag_list', array($this, 'get_tag_list')); add_action('wp_ajax_nopriv_spri_fb_page_tag_list', array($this, 'get_tag_list')); }