Ejemplo n.º 1
0
 function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     $twitter_username = $instance['twitter_username'];
     $show_num = $instance['show_num'];
     $consumer_key = $instance['consumer_key'];
     $consumer_secret = $instance['consumer_secret'];
     $access_token = $instance['access_token'];
     $access_token_secret = $instance['access_token_secret'];
     $cache_time = $instance['cache_time'];
     // Opening of widget
     echo $args['before_widget'];
     // Open of title tag
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     $gdlr_twitter = get_option('gdlr_twitter', array());
     if (!is_array($gdlr_twitter) && !empty($gdlr_twitter)) {
         $gdlr_twitter = unserialize($gdlr_twitter);
     }
     if (!is_array($gdlr_twitter)) {
         $gdlr_twitter = array();
     }
     if (empty($gdlr_twitter[$twitter_username][$show_num]['data']) || empty($gdlr_twitter[$twitter_username][$show_num]['cache_time']) || time() - intval($gdlr_twitter[$twitter_username][$show_num]['cache_time']) >= $cache_time * 3600) {
         $tweets_data = gdlr_get_tweets($consumer_key, $consumer_secret, $access_token, $access_token_secret, $twitter_username, $show_num);
         if (!empty($tweets_data)) {
             $gdlr_twitter[$twitter_username][$show_num]['data'] = $tweets_data;
             $gdlr_twitter[$twitter_username][$show_num]['cache_time'] = time();
             update_option('gdlr_twitter', $gdlr_twitter);
         }
     } else {
         $tweets_data = $gdlr_twitter[$twitter_username][$show_num]['data'];
     }
     echo '<ul class="gdlr-twitter-widget">';
     foreach ($tweets_data as $tweet_data) {
         echo '<li>' . $tweet_data . '</li>';
     }
     echo '</ul>';
     // Closing of widget
     echo $args['after_widget'];
 }
Ejemplo n.º 2
0
 function gdlr_get_twitter_item($settings)
 {
     $item_id = empty($settings['page-item-id']) ? '' : ' id="' . $settings['page-item-id'] . '" ';
     global $gdlr_spaces;
     $margin = !empty($settings['margin-bottom']) && $settings['margin-bottom'] != $gdlr_spaces['bottom-item'] ? 'margin-bottom: ' . $settings['margin-bottom'] . ';' : '';
     $margin_style = !empty($margin) ? ' style="' . $margin . '" ' : '';
     $ret = gdlr_get_item_title($settings);
     $ret .= '<div class="gdlr-item gdlr-twitter-item" ' . $item_id . $margin_style . '>';
     $gdlr_twitter = get_option('gdlr_twitter', array());
     if (!is_array($gdlr_twitter) && !empty($gdlr_twitter)) {
         $gdlr_twitter = unserialize($gdlr_twitter);
     }
     if (!is_array($gdlr_twitter)) {
         $gdlr_twitter = array();
     }
     $show_num = $settings['show-num'];
     $twitter_username = $settings['twitter-name'];
     if (empty($gdlr_twitter[$twitter_username][$show_num]['data']) || empty($gdlr_twitter[$twitter_username][$show_num]['cache_time']) || time() - intval($gdlr_twitter[$twitter_username][$show_num]['cache_time']) >= $settings['cache-time'] * 3600) {
         $tweets_data = gdlr_get_tweets($settings['consumer-key'], $settings['consumer-secret'], $settings['access-token'], $settings['access-token-secret'], $settings['twitter-name'], $settings['show-num']);
         if (!empty($tweets_data)) {
             $gdlr_twitter[$twitter_username][$show_num]['data'] = $tweets_data;
             $gdlr_twitter[$twitter_username][$show_num]['cache_time'] = time();
             update_option('gdlr_twitter', $gdlr_twitter);
         }
     } else {
         $tweets_data = $gdlr_twitter[$twitter_username][$show_num]['data'];
     }
     $ret .= '<ul class="gdlr-twitter-widget">';
     foreach ($tweets_data as $tweet_data) {
         $ret .= '<li>' . $tweet_data . '</li>';
     }
     $ret .= '</ul>';
     $ret .= '</div>';
     return $ret;
 }
Ejemplo n.º 3
0
 function gdlr_get_twitter_item($settings)
 {
     $gdlr_twitter = get_option('gdlr_twitter', array());
     if (!is_array($gdlr_twitter) && !empty($gdlr_twitter)) {
         $gdlr_twitter = unserialize($gdlr_twitter);
     }
     if (!is_array($gdlr_twitter)) {
         $gdlr_twitter = array();
     }
     $show_num = $settings['show-num'];
     $twitter_username = $settings['twitter-name'];
     if (empty($gdlr_twitter[$twitter_username][$show_num]['data']) || empty($gdlr_twitter[$twitter_username][$show_num]['cache_time']) || time() - intval($gdlr_twitter[$twitter_username][$show_num]['cache_time']) >= $settings['cache-time'] * 3600) {
         $tweets_data = gdlr_get_tweets($settings['consumer-key'], $settings['consumer-secret'], $settings['access-token'], $settings['access-token-secret'], $settings['twitter-name'], $settings['show-num']);
         if (!empty($tweets_data)) {
             $gdlr_twitter[$twitter_username][$show_num]['data'] = $tweets_data;
             $gdlr_twitter[$twitter_username][$show_num]['cache_time'] = time();
             update_option('gdlr_twitter', $gdlr_twitter);
         }
     } else {
         $tweets_data = $gdlr_twitter[$twitter_username][$show_num]['data'];
     }
     $settings['title'] = '<i class="fa fa-twitter icon-twitter"></i>';
     $settings['title-type'] = 'center gdlr-twitter-title';
     $settings['carousel'] = true;
     $ret = gdlr_get_item_title($settings);
     $ret .= '<div class="gdlr-item gdlr-twitter-item" >';
     $ret .= '<div class="flexslider" data-type="carousel" data-columns="1" data-nav-container="gdlr-twitter-item" >';
     $ret .= '<ul class="slides">';
     foreach ($tweets_data as $tweet_data) {
         $ret .= '<li>' . utf8_decode($tweet_data) . '</li>';
     }
     $ret .= '</ul>';
     $ret .= '</div>';
     // flexslider
     $ret .= '</div>';
     // gdlr-twitter-item
     return $ret;
 }