/** * Outputs the widget based on the arguments input through the widget controls. * @since 0.7 */ function widget($args, $instance) { extract($args); echo $before_widget; if ($instance['title']) { echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title; } $screen_name = trim(urlencode($instance['screen_name'])); if (empty($screen_name)) { return; } $number = $instance['number']; if ($number > 200) { $number = 200; } $link_attr = ''; if (isset($instance['target_blank'])) { $link_attr = ' target="_blank"'; } if (isset($instance['nofollow'])) { $link_attr .= ' rel="nofollow"'; } if (!($tweets = wp_cache_get('widget-twitter-' . $this->number, 'widget'))) { $params = array('screen_name' => $screen_name, 'trim_user' => true, 'include_entities' => true, 'exclude_replies' => (bool) $instance['exclude_replies'], 'count' => (bool) $instance['exclude_replies'] ? 100 : $number, 'include_rts' => (bool) $instance['include_rts']); $twitter_json_url = esc_url_raw('http://api.twitter.com/1/statuses/user_timeline.json?' . http_build_query($params), array('http', 'https')); unset($params); $response = wp_remote_get($twitter_json_url, array('User-Agent' => 'WordPress.com Twitter Widget')); $response_code = wp_remote_retrieve_response_code($response); if (200 == $response_code) { $tweets = wp_remote_retrieve_body($response); $tweets = json_decode($tweets); $expire = 900; if (!is_array($tweets) || isset($tweets['error'])) { $tweets = 'error'; $expire = 300; } } else { $tweets = 'error'; $expire = 300; wp_cache_add('widget-twitter-response-code-' . $this->number, $response_code, 'widget', $expire); } wp_cache_add('widget-twitter-' . $this->number, $tweets, 'widget', $expire); } if ('error' != $tweets) { echo '<ul class="tweets">' . "\n"; $tweets_out = 0; foreach ((array) $tweets as $tweet) { if ($tweets_out >= $number) { break; } if (empty($tweet->text)) { continue; } $text = make_clickable(esc_html($tweet->text)); /* * Create links from plain text based on Twitter patterns * @link http://github.com/mzsanford/twitter-text-rb/blob/master/lib/regex.rb Official Twitter regex */ $text = preg_replace_callback('/(^|[^0-9A-Z&\\/]+)(#|\\xef\\xbc\\x83)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\xc0-\\xd6\\xd8-\\xf6\\xf8\\xff]*)/iu', array($this, '_wpcom_widget_twitter_hashtag'), $text); $text = preg_replace_callback('/([^a-zA-Z0-9_]|^)([@\\xef\\xbc\\xa0]+)([a-zA-Z0-9_]{1,20})(\\/[a-zA-Z][a-zA-Z0-9\\x80-\\xff-]{0,79})?/u', array($this, '_wpcom_widget_twitter_username'), $text); $text = '<span class="tweet-content"> ' . $text . '</span>'; if (isset($tweet->id_str)) { $tweet_id = urlencode($tweet->id_str); } else { $tweet_id = urlencode($tweet->id); } // Tweet Meta $tweet_meta = ''; $tweet_meta .= '<a href="' . esc_url("http://twitter.com/{$screen_name}/statuses/{$tweet_id}") . '" class="timesince">' . str_replace(' ', ' ', wpcom_time_since(strtotime($tweet->created_at))) . " ago</a>"; if (!empty($tweet->source)) { $tweet_meta .= ' <span class="from">from ' . $tweet->source . '</span>'; } // if( !empty($tweet_meta) ) $tweet_meta = '<span class="tweet-meta">' . $tweet_meta . '</span>'; $text = '<li>' . $text . $tweet_meta . "</li>\n"; $text = str_replace(' rel="nofollow"', '', $text); if ($link_attr) { $text = str_replace('<a href=', '<a' . $link_attr . ' href=', $text); } echo $text; unset($tweet_id); $tweets_out++; } echo "</ul>\n"; } else { if (401 == wp_cache_get('widget-twitter-response-code-' . $this->number, 'widget')) { echo '<p>' . esc_html(sprintf(__('Error: Please make sure the Twitter account is <a href="%s">public</a>.'), 'http://support.twitter.com/forums/10711/entries/14016')) . '</p>'; } else { echo '<p>' . esc_html__('Error: Twitter did not respond. Please wait a few minutes and refresh this page.') . '</p>'; } } if (!empty($screen_name) && !empty($instance['follow_button'])) { echo '<a href="https://twitter.com/' . $screen_name . '" class="twitter-follow-button" data-show-count="false">' . sprintf(__('Follow @%s', 'dp'), $screen_name) . '</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>'; } echo $after_widget; }
function widget($args, $instance) { extract($args); $account = trim(urlencode($instance['account'])); if (empty($account)) { return; } $title = apply_filters('widget_title', $instance['title']); if (empty($title)) { $title = __('Twitter Updates', 'jetpack'); } $show = absint($instance['show']); // # of Updates to show if ($show > 200) { // Twitter paginates at 200 max tweets. update() should not have accepted greater than 20 $show = 200; } $hidereplies = (bool) $instance['hidereplies']; $include_retweets = (bool) $instance['includeretweets']; echo "{$before_widget}{$before_title}<a href='" . esc_url("http://twitter.com/{$account}") . "'>" . esc_html($title) . "</a>{$after_title}"; if (false === ($tweets = get_transient('widget-twitter-' . $this->number))) { $params = array('screen_name' => $account, 'trim_user' => true, 'include_entities' => false); /** * The exclude_replies parameter filters out replies on the server. If combined with count it only filters that number of tweets (not all tweets up to the requested count) * If we are not filtering out replies then we should specify our requested tweet count */ if ($hidereplies) { $params['exclude_replies'] = true; } else { $params['count'] = $show; } if ($include_retweets) { $params['include_rts'] = true; } $twitter_json_url = esc_url_raw('http://api.twitter.com/1/statuses/user_timeline.json?' . http_build_query($params), array('http', 'https')); unset($params); $response = wp_remote_get($twitter_json_url, array('User-Agent' => 'WordPress.com Twitter Widget')); $response_code = wp_remote_retrieve_response_code($response); if (200 == $response_code) { $tweets = wp_remote_retrieve_body($response); $tweets = json_decode($tweets, true); $expire = 900; if (!is_array($tweets) || isset($tweets['error'])) { $tweets = 'error'; $expire = 300; } } else { $tweets = 'error'; $expire = 300; set_transient('widget-twitter-response-code-' . $this->number, $response_code, $expire); } set_transient('widget-twitter-' . $this->number, $tweets, $expire); } if ('error' != $tweets) { $before_timesince = ' '; if (isset($instance['beforetimesince']) && !empty($instance['beforetimesince'])) { $before_timesince = esc_html($instance['beforetimesince']); } $before_tweet = ''; if (isset($instance['beforetweet']) && !empty($instance['beforetweet'])) { $before_tweet = stripslashes(wp_filter_post_kses($instance['beforetweet'])); } echo '<ul class="tweets">' . "\n"; $tweets_out = 0; foreach ((array) $tweets as $tweet) { if ($tweets_out >= $show) { break; } if (empty($tweet['text'])) { continue; } $text = make_clickable(esc_html($tweet['text'])); /* * Create links from plain text based on Twitter patterns * @link http://github.com/mzsanford/twitter-text-rb/blob/master/lib/regex.rb Official Twitter regex */ $text = preg_replace_callback('/(^|[^0-9A-Z&\\/]+)(#|\\xef\\xbc\\x83)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\xc0-\\xd6\\xd8-\\xf6\\xf8\\xff]*)/iu', array(&$this, '_wpcom_widget_twitter_hashtag'), $text); $text = preg_replace_callback('/([^a-zA-Z0-9_]|^)([@\\xef\\xbc\\xa0]+)([a-zA-Z0-9_]{1,20})(\\/[a-zA-Z][a-zA-Z0-9\\x80-\\xff-]{0,79})?/u', array(&$this, '_wpcom_widget_twitter_username'), $text); if (isset($tweet['id_str'])) { $tweet_id = urlencode($tweet['id_str']); } else { $tweet_id = urlencode($tweet['id']); } $created_at = str_replace('+0000', '', $tweet['created_at']) . ' UTC'; // Twitter's datetime format is strange, refactor for the sake of PHP4 echo "<li>{$before_tweet}{$text}{$before_timesince}<a href=\"" . esc_url("http://twitter.com/{$account}/statuses/{$tweet_id}") . '" class="timesince">' . str_replace(' ', ' ', wpcom_time_since(strtotime($created_at))) . " ago</a></li>\n"; unset($tweet_id); $tweets_out++; } echo "</ul>\n"; } else { if (401 == get_transient('widget-twitter-response-code-' . $this->number)) { echo '<p>' . wp_kses(sprintf(__('Error: Please make sure the Twitter account is <a href="%s">public</a>.', 'jetpack'), 'http://support.twitter.com/forums/10711/entries/14016'), array('a' => array('href' => true))) . '</p>'; } else { echo '<p>' . esc_html__('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'jetpack') . '</p>'; } } echo $after_widget; }
/** * Outputs the widget based on the arguments input through the widget controls. * @since 0.7 */ function widget($args, $instance) { extract($args); echo $before_widget; if ($instance['title']) { echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title; } $screen_name = trim(urlencode($instance['screen_name'])); if (empty($screen_name)) { return; } $number = $instance['number']; if ($number > 200) { $number = 200; } $link_attr = ''; if (isset($instance['target_blank'])) { $link_attr = ' target="_blank"'; } if (isset($instance['nofollow'])) { $link_attr .= ' rel="nofollow"'; } $use_yql = $instance['use_yql']; if (!($tweets = wp_cache_get('widget-twitter-' . $this->number, 'widget'))) { $params = array('screen_name' => $screen_name, 'trim_user' => true, 'include_entities' => true, 'exclude_replies' => (bool) $instance['exclude_replies'], 'count' => (bool) $instance['exclude_replies'] ? 100 : $number, 'include_rts' => (bool) $instance['include_rts']); $twitter_json_url = esc_url_raw('http://api.twitter.com/1/statuses/user_timeline.json?' . http_build_query($params), array('http', 'https')); unset($params); if ($use_yql) { $yqlQuery = 'select * from json where url="http://twitter.com/statuses/user_timeline/' . $screen_name . '.json?count=' . $number . '"'; $r = json_decode(file_get_contents('http://query.yahooapis.com/v1/public/yql?q=' . urlencode($yqlQuery) . '&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'))->query->results; $tweets = $r->json->json; $expire = 900; } else { $response = wp_remote_get($twitter_json_url, array('User-Agent' => 'WordPress.com Twitter Widget')); $response_code = wp_remote_retrieve_response_code($response); if (200 == $response_code) { $tweets = wp_remote_retrieve_body($response); $tweets = json_decode($tweets); $expire = 900; if (!is_array($tweets) || isset($tweets['error'])) { $tweets = 'error'; $expire = 300; } } else { $tweets = 'error'; $expire = 300; wp_cache_add('widget-twitter-response-code-' . $this->number, $response_code, 'widget', $expire); } } wp_cache_add('widget-twitter-' . $this->number, $tweets, 'widget', $expire); } if ('error' != $tweets) { echo '<ul class="tweets">' . "\n"; $tweets_out = 0; foreach ((array) $tweets as $tweet) { if ($tweets_out >= $number) { break; } if (empty($tweet->text)) { continue; } $text = make_clickable(esc_html($tweet->text)); /* * Create links from plain text based on Twitter patterns * @link http://github.com/mzsanford/twitter-text-rb/blob/master/lib/regex.rb Official Twitter regex */ $text = preg_replace_callback('/(^|[^0-9A-Z&\\/]+)(#|\\xef\\xbc\\x83)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\xc0-\\xd6\\xd8-\\xf6\\xf8\\xff]*)/iu', array($this, '_wpcom_widget_twitter_hashtag'), $text); $text = preg_replace_callback('/([^a-zA-Z0-9_]|^)([@\\xef\\xbc\\xa0]+)([a-zA-Z0-9_]{1,20})(\\/[a-zA-Z][a-zA-Z0-9\\x80-\\xff-]{0,79})?/u', array($this, '_wpcom_widget_twitter_username'), $text); if (isset($tweet->id_str)) { $tweet_id = urlencode($tweet->id_str); } else { $tweet_id = urlencode($tweet->id); } $text = '<li>' . $text . '<a href="' . esc_url("http://twitter.com/{$screen_name}/statuses/{$tweet_id}") . '" class="timesince">' . str_replace(' ', ' ', wpcom_time_since(strtotime($tweet->created_at))) . " ago</a></li>\n"; $text = str_replace(' rel="nofollow"', '', $text); if ($link_attr) { $text = str_replace('<a href=', '<a' . $link_attr . ' href=', $text); } echo $text; unset($tweet_id); $tweets_out++; } echo "</ul>\n"; } else { if (401 == wp_cache_get('widget-twitter-response-code-' . $this->number, 'widget')) { echo '<p>' . esc_html(sprintf(__('Error: Please make sure the Twitter account is <a href="%s">public</a>.'), 'http://support.twitter.com/forums/10711/entries/14016')) . '</p>'; } else { echo '<p>' . esc_html__('Error: Twitter did not respond. Please wait a few minutes and refresh this page.') . '</p>'; } } echo $after_widget; }
function widget($args, $instance) { if (is_single()) { // only display on single pages extract($args); if (rolo_type_is('contact')) { $account = urlencode(rolo_contact_tweet(get_the_ID())); } if (rolo_type_is('company')) { $account = urlencode(rolo_company_tweet(get_the_ID())); } if (empty($account)) { return; } $title = apply_filters('widget_title', $instance['title']); if (empty($title)) { $title = __('Twitter Updates'); } $show = absint($instance['show']); // # of Updates to show $hidereplies = $instance['hidereplies']; $before_timesince = esc_html($instance['beforetimesince']); if (empty($before_timesince)) { $before_timesince = ' '; } $before_tweet = esc_html($instance['beforetweet']); echo "{$before_widget}{$before_title}<a href='" . clean_url("http://twitter.com/{$account}") . "'>{$title}</a>{$after_title}"; if (!($tweets = wp_cache_get('widget-twitter-' . $this->number, 'widget'))) { $twitter_json_url = clean_url("http://twitter.com/statuses/user_timeline/{$account}.json", null, 'raw'); $response = wp_remote_get($twitter_json_url, array('User-Agent' => 'Wickett Twitter Widget')); $response_code = wp_remote_retrieve_response_code($response); if (200 == $response_code) { $tweets = wp_remote_retrieve_body($response); $tweets = json_decode($tweets); $expire = 900; if (!is_array($tweets) || isset($tweets['error'])) { $tweets = 'error'; $expire = 300; } } else { $tweets = 'error'; $expire = 300; wp_cache_add('widget-twitter-response-code-' . $this->number, $response_code, 'widget', $expire); } wp_cache_add('widget-twitter-' . $this->number, $tweets, 'widget', $expire); } if ('error' != $tweets) { echo "<ul class='tweets'>\n"; $tweets_out = 0; foreach ((array) $tweets as $tweet) { if ($tweets_out >= $show) { break; } if (empty($tweet->text) || $hidereplies && !empty($tweet->in_reply_to_user_id)) { continue; } $text = make_clickable(wp_specialchars($tweet->text)); $text = preg_replace_callback('/(^|\\s)@(\\w+)/', array($this, '_rolo_twitter_widget_username'), $text); $text = preg_replace_callback('/(^|\\s)#(\\w+)/', array($this, '_rolo_twitter_widget_hashtag'), $text); // Move the year for PHP4 compat $created_at = substr($tweet->created_at, 0, 10) . substr($tweet->created_at, 25, 5) . substr($tweet->created_at, 10, 15); echo "<li>{$before_tweet}{$text}{$before_timesince}<a href='" . clean_url("http://twitter.com/{$account}/statuses/" . urlencode($tweet->id)) . "' class='timesince'>" . str_replace(' ', ' ', wpcom_time_since(strtotime($created_at))) . " ago</a></li>\n"; $tweets_out++; } echo "</ul>\n"; } else { if (401 == wp_cache_get('widget-twitter-response-code-' . $this->number, 'widget')) { echo "<p>" . __("Error: Please make sure the Twitter account is <a href='http://help.twitter.com/forums/10711/entries/14016'>public</a>.") . "</p>"; } else { echo "<p>" . __("Error: Twitter did not respond. Please wait a few minutes and refresh this page.") . "</p>"; } } echo $after_widget; } }
function dcsmt_inc_pinterest($args, $instance) { extract($args); $widget_options = wp_parse_args($instance, $this->defaults); extract($widget_options, EXTR_SKIP); $id = $widget_options['pinterestId']; $rssId = 'http://pinterest.com/' . $id . '/feed.rss'; $icon_close = '<a href="#" class="dcsmt-close dcsmt-close-tab"></a>'; $title = $widget_options['pinterestTitle'] == '' ? '' : '<h3><a href="http://pinterest.com/' . $id . '/">' . $widget_options['pinterestTitle'] . '</a>' . $icon_close . '</h3>'; $nPinterest = $widget_options['nPinterest']; $tab = ''; if ($id != '') { require_once ABSPATH . WPINC . '/feed.php'; $tab = '<script type="text/javascript"> jQuery(document).ready(function($) { $(".tab-pinterest").jCarouselLitedcsmt({ btnNext: ".btn-pin.next", btnPrev: ".btn-pin.prev", visible: 1, scroll: 1, speed: 800, auto: 0, width: ' . ($widget_options['width'] - 20) . ', height: ' . ($widget_options['height'] - 100) . ' }); $(".dcsmt-pinterest-item a").each(function(){ if(!$(this).hasClass("hrefconvert")){ var href = $(this).attr("href"); href = href.replace("/pin/","http://pinterest.com/pin/"); $(this).attr("href",href).addClass("hrefconvert"); } }); }); </script>'; $tab .= '<div class="tab-pinterest tab-inner" style="width: ' . $widget_options['width'] . ';">' . $title; $rss = fetch_feed($rssId); // print_r($rss); $maxitems = $rss->get_item_quantity((int) $nPinterest); $rss_items = $rss->get_items(0, $maxitems); $tab .= '<div class="carousel" style="width: ' . $widget_options['width'] . ';">' . "\n"; $tab .= '<ul class="list-dcsmt-pinterest">'; $count = 1; foreach ($rss_items as $item) { $time = wpcom_time_since(strtotime($item->get_date())); $tab .= '<li class="dcsmt-pinterest-item carousel-slide" style="width: ' . $widget_options['width'] . ';"><div class="pin">'; $tab .= $item->get_description(); $tab .= '<p class="btm">Pinned ' . $time . ' ago</p>'; $tab .= '</div></li>'; $count++; } } $tab .= '</ul></div>'; $tab .= '<a href="#" class="btn-pin prev"></a><a href="#" class="btn-pin next"></a>'; $tab .= $widget_options['pinterest_follow'] == true ? '<a href="http://pinterest.com/' . $id . '/" class="dcsmt-pin-btn"><img src="http://passets-cdn.pinterest.com/images/follow-on-pinterest-button.png" width="156" height="26" alt="Follow Me on Pinterest" /></a>' : ''; $tab .= '</div>'; return $tab; }