public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $id = $instance['id']; $limit = empty($instance['limit']) ? 2 : (int) $instance['limit']; $consumer_key = $instance['consumer_key']; $consumer_secret = $instance['consumer_secret']; $oauth_access_token = $instance['oauth_access_token']; $oauth_access_token_secret = $instance['oauth_access_token_secret']; echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } if ($id && $consumer_key && $consumer_secret && $oauth_access_token && $oauth_access_token_secret) { require_once trailingslashit(get_template_directory()) . '/library/addon/api/twitter-api-exchange.php'; $settings = array('oauth_access_token' => $oauth_access_token, 'oauth_access_token_secret' => $oauth_access_token_secret, 'consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret); $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $requestMethod = "GET"; $getfield = "?screen_name={$id}&count={$limit}"; $twitter = new TwitterAPIExchange($settings); $data = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), TRUE); ?> <div class="widget-content"> <div id="tweets" class="tweets" data-username="******" data-limit="<?php echo $limit; ?> "> <?php if (isset($data["errors"][0]["message"]) && $data["errors"][0]["message"] != '') { _e("Sorry, there was a problem when load", kopa_get_domain()); } else { ?> <ul class="tweetList"> <?php if (!empty($data)) { ?> <?php foreach ($data as $items) { ?> <?php preg_match('!https?://[\\S]+!', $items['text'], $matches); $url = ''; if (isset($matches) && !empty($matches)) { $url = $matches[0]; } $pattern = '~http://[^\\s]*~i'; $title = preg_replace($pattern, '', $items['text']); ?> <li class="tweet_content_0"> <p class="tweet_link_0"><?php echo $title; ?> <?php if (!empty($url)) { ?> <a href="<?php echo $url; ?> "><?php echo $url; ?> </a> <?php } ?> <p class="timestamp"> <?php $date = date_create($items['created_at']); if (version_compare(PHP_VERSION, '5.3') >= 0) { $created_at = $date->getTimestamp(); echo KopaUtil::human_time_diff($created_at); } else { echo date_format($date, "Y/m/d H:iP"); } ?> </p> </p> </li> <?php } ?> <?php } ?> </ul> <?php } ?> </div> </div> <?php } echo $after_widget; }
public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $limit = empty($instance['limit']) ? 4 : absint($instance['limit']); echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } $comments = get_comments(array('number' => $limit, 'status' => 'approve', 'post_status' => 'publish')); if ($comments) { ?> <div class="widget-content"> <ul class="list-unstyled"> <?php foreach ((array) $comments as $comment) { $date = get_comment_date('U', $comment->comment_ID); $post_url = get_permalink($comment->comment_post_ID); ?> <li class="clearfix"> <?php if ('true' != $instance['is_hide_gravatar'] && '' != $comment->comment_author_email) { ?> <a href="<?php echo $post_url; ?> " class="pull-left"> <?php echo get_avatar($comment->comment_author_email, 80); ?> </a> <?php } ?> <div class="item-right"> <?php if ('true' != $instance['is_hide_author']) { ?> <h4><a href="<?php echo $post_url; ?> "><?php echo get_comment_author_link($comment->comment_ID); ?> </a></h4> <?php } ?> <?php $comment_content = get_comment_text($comment->comment_ID); if ('true' != $instance['is_hide_comment'] && !empty($comment_content)) { ?> <?php $character_limit = absint($instance['comment_character_limit']); if ($character_limit > 0) { $comment_content = KopaUtil::substr($comment_content, $character_limit); } printf('<p>%s</p>', $comment_content); ?> <?php } ?> <?php if ('true' != $instance['is_hide_created_date']) { ?> <span class="kp-meta-post"><?php echo KopaUtil::human_time_diff($date); ?> </span> <?php } ?> </div> </li> <?php } ?> </ul> </div> <?php } echo $after_widget; }