function testTweetButton() { $result = $this->Twitter->tweetButton(); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?count=horizontal&lang=en" class="twitter-share-button">Tweet</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'default call %s'); $result = $this->Twitter->tweetButton(null); $this->assertEqual($result, $ok, 'null label'); $result = $this->Twitter->tweetButton(''); $this->assertEqual($result, $ok, 'empty label'); $result = $this->Twitter->tweetButton(null, null); $this->assertEqual($result, $ok, 'empty option'); $result = $this->Twitter->tweetButton(null, null, null); $this->assertEqual($result, $ok, 'null query flag'); $result = $this->Twitter->tweetButton(null, null, null, null); $this->assertEqual($result, $ok, 'null inline flag'); $result = $this->Twitter->tweetButton('TestLabel'); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?count=horizontal&lang=en" class="twitter-share-button">TestLabel</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'Test label'); $options = array('class' => 'testClass', 'url' => 'testUrl', 'via' => 'testVia', 'text' => 'testText', 'related' => 'testRelated', 'lang' => 'ja', 'counturl' => 'testCounturl'); $result = $this->Twitter->tweetButton(null, $options); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?url=testUrl&via=testVia&text=testText&related=testRelated&count=horizontal&lang=ja&counturl=testCounturl" class="testClass">Tweet</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'Test Options'); $options = array('count' => 'none'); $result = $this->Twitter->tweetButton(null, $options); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?count=none&lang=en" class="twitter-share-button">Tweet</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'Test Options'); $options = array('count' => 'vertical'); $result = $this->Twitter->tweetButton(null, $options); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?count=vertical&lang=en" class="twitter-share-button">Tweet</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'Test Options'); $options = array('count' => 'top'); $result = $this->Twitter->tweetButton(null, $options); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?count=none&lang=en" class="twitter-share-button">Tweet</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'Test Options'); $result = $this->Twitter->tweetButton(null, null, true); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-lang="en">Tweet</a> OUTPUT_EOL; $this->assertEqual($result, $ok, 'Test Options'); $this->startTest(); $result = $this->Twitter->tweetButton(null, null, null, true); $ok = <<<OUTPUT_EOL <a href="http://twitter.com/share?count=horizontal&lang=en" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> OUTPUT_EOL; $this->assertEqual($result, $ok, 'default call'); }
/** * Connect * * @return null */ public function actionConnect() { // referer $referer = craft()->httpSession->get('twitter.referer'); if (!$referer) { $referer = craft()->request->getUrlReferrer(); craft()->httpSession->add('twitter.referer', $referer); TwitterHelper::log('Twitter OAuth Connect Step 1: ' . "\r\n" . print_r(['referer' => $referer], true), LogLevel::Info); } // connect if ($response = craft()->oauth->connect(array('plugin' => 'twitter', 'provider' => $this->handle))) { // var_dump($response); // die(); if ($response['success']) { // token $token = $response['token']; // save token craft()->twitter_oauth->saveToken($token); TwitterHelper::log('Twitter OAuth Connect Step 2: ' . "\r\n" . print_r(['token' => $token], true), LogLevel::Info); // session notice craft()->userSession->setNotice(Craft::t("Connected to Twitter.")); } else { // session error craft()->userSession->setError(Craft::t($response['errorMsg'])); } } else { // session error craft()->userSession->setError(Craft::t("Couldn’t connect")); } // OAuth Step 5 // redirect craft()->httpSession->remove('twitter.referer'); $this->redirect($referer); }
function front_end($args, $instance) { extract($args); $tweets = TwitterHelper::get_tweets($instance['username'], $instance['count']); if (!empty($tweets)) { if ($instance['title']) { echo $before_title . $instance['title'] . $after_title; } } ?> <?php foreach ($tweets as $tweet) { ?> <p><?php echo $tweet->tweet_text; ?> - <span class="time"><?php echo $tweet->time_distance; ?> ago</span></p> <?php } ?> <?php }
/** * Returns true if tweet is in valid format (@streetgrindzapp <menu image url> <open time>-<close time>) */ public static function isValidFormat($tweet) { try { $tweet_text = $tweet->text; $matches = TwitterHelper::parseTruckTweet($tweet_text); return $matches ? true : false; } catch (Exception $e) { Yii::log("Exception occurred parsing Tweet format:" . $e, 'error', get_called_class()); return false; } }
public function run($args) { $this->connection = new TwitterOAuth(Yii::app()->params['trucks']['twitter']['consumerKey'], Yii::app()->params['trucks']['twitter']['consumerSecret'], Yii::app()->params['trucks']['twitter']['oauthAccessToken'], Yii::app()->params['trucks']['twitter']['oauthAccessTokenSecret']); $mentions = $this->connection->get('statuses/mentions'); $num_mentions = count($mentions); for ($i = $num_mentions - 1; $i >= 0; $i--) { $mention = $mentions[$i]; $truck = Trucks::model()->findByAttributes(array('twitter_id' => $mention->user->id_str)); if (NULL === $truck) { $message = 'SKIPPED: Tweet (id=' . $mention->id_str . ') is from an unauthorized Tweeter (@' . $mention->user->screen_name . ").\n"; Yii::log($message, 'info', get_called_class()); echo $message; continue; } elseif (TwitterHelper::isGeoLocatable($mention)) { if (TwitterHelper::isValidFormat($mention)) { Yii::log("Tweet is valid. Checking for db insertion", 'info', get_called_class()); $truck_tweet = TrucksTweets::model()->findByAttributes(array('tweet_id' => $mention->id_str)); if (NULL === $truck_tweet) { $parsed_tweet = TwitterHelper::parseTruckTweet($mention->text); $truck_tweet = new TrucksTweets(); $truck_tweet->truck_id = $truck->id; $truck_tweet->tweet = $mention->text; $truck_tweet->tweet_id = $mention->id_str; $truck_tweet->menu_url = $parsed_tweet['menu_url']; $truck_tweet->start_time = TwitterHelper::convertTruckTime($mention->created_at, $parsed_tweet['start']); $truck_tweet->end_time = TwitterHelper::convertTruckTime($mention->created_at, $parsed_tweet['end']); $truck_tweet->geo_lat = $mention->coordinates->coordinates[1]; $truck_tweet->geo_long = $mention->coordinates->coordinates[0]; $truck_tweet->save(); $message = 'INSERTED: Tweet (text=' . $mention->text . ') from @' . $mention->user->screen_name . " successfully saved.\n"; Yii::log($message, 'info', get_called_class()); echo $message; } else { $message = 'SKIPPED: Tweet (id=' . $mention->id_str . ") already exists.\n"; Yii::log($message, 'info', get_called_class()); // Eating this output to save on cron tasks // echo $message; continue; } } else { $message = 'SKIPPED: Tweet (text=' . $mention->text . ") is an invalid format.\n"; Yii::log($message, 'info', get_called_class()); echo $message; continue; } } else { $message = 'SKIPPED: Tweet (text=' . $mention->text . ') from ' . $mention->user->screen_name . " is not geo-locatable.\n"; Yii::log($message, 'info', get_called_class()); echo $message; continue; } } }
public function set($id, $value, $expire = null, $dependency = null, $enableCache = null) { if (is_null($enableCache)) { $enableCache = craft()->config->get('enableCache', 'twitter'); } if ($enableCache) { $cacheKey = $this->getCacheKey($id); if (!$expire) { $expire = craft()->config->get('cacheDuration', 'twitter'); $expire = TwitterHelper::formatDuration($expire); } return craft()->cache->set($cacheKey, $value, $expire, $dependency); } }
function carbon_twitter_is_config_valid() { $tweets = TwitterHelper::get_tweets('cnn', 1, true); if (!$tweets) { return false; } return true; }
/** * linkify text * * @param string $value * @param array $options * username: linkify username. eg. @username * hashtag : linkify hashtag. eg. #hashtag * url : linkify url. eg. http://example.com/ * @return string */ public function linkify($value, $options = array()) { return $this->Twitter->linkify($value, $options); }
/** * create tweet button * * @see http://dev.twitter.com/pages/tweet_button * @param string $label * @param array $options * @param boolean $dataAttribute * @param boolean $scriptInline * @return string */ public function tweetButton($label = null, $options = array(), $dataAttribute = false, $scriptInline = false) { return $this->Twitter->tweetButton($label, $options, $dataAttribute, $scriptInline); }
public function front_end($args, $instance) { // outputs the content of the widget if (!carbon_twitter_is_configured()) { return; //twitter settings are not configured } $instance = array('title' => Carbon_ACF_Widget::get_widget_meta($widget_id, 'title'), 'username' => Carbon_ACF_Widget::get_widget_meta($widget_id, 'username'), 'count' => Carbon_ACF_Widget::get_widget_meta($widget_id, 'count')); $tweets = TwitterHelper::get_tweets($instance['username'], $instance['count']); if (empty($tweets)) { return; //no tweets, or error while retrieving } if ($instance['title']) { $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); echo $args['before_title'] . $title . $args['after_title']; } ?> <div class="widget-body"> <ul> <?php foreach ($tweets as $tweet) { ?> <li><?php echo $tweet->tweet_text; ?> - <span><?php printf(__('%1$s ago', 'crb'), $tweet->time_distance); ?> </span></li> <?php } ?> </ul> </div><!-- /.widget-body --> <?php }
function front_end($args, $instance) { extract($args); if (ot_get_option('twitter_oauth_access_token') && ot_get_option('twitter_oauth_access_token_secret') && ot_get_option('twitter_consumer_key') && ot_get_option('twitter_consumer_secret')) { $load = intval($instance['load']); $title = $instance['title']; $twitter_user = $instance['twitter_user']; $button_text = $instance['button_text']; $button_url = $instance['button_url']; $new_window = $instance['new_window']; ?> <div class="tweets-widget"><?php echo $title ? $before_title . $title . $after_title : ''; if ($button_url || $button_text) { ?> <a href="<?php echo $button_url; ?> "<?php if ($new_window) { ?> target="_blank"<?php } ?> class="widget-button"><?php echo $button_text; ?> </a><?php } ?> <div class="tweets-container"> <?php $tweets = TwitterHelper::get_tweets($twitter_user, $load); if (empty($tweets)) { return; } if (!empty($tweets)) { echo '<ul>'; foreach ($tweets as $tweet) { ?> <li> <span class="tweet_text"><?php echo wpautop(preg_replace('~' . preg_quote($instance['twitter_user'], '~') . ': ~iu', '', $tweet->tweet_text)); ?> </span> <span class="tweet_time"><a target="_blank" href="<?php echo $tweet->tweet_link; ?> "><?php echo $tweet->time_distance; ?> — <?php _e('View on Twitter', 'espresso'); ?> </a></span> </li> <?php } echo '</ul>'; } ?> </div> </div><?php } else { echo '<p style="color:#dd0000;"><strong>Important:</strong> You need to enter your Twitter Settings on the Theme Options panel before you can use this widget.</p>'; } }
<?php $section_title_tweets = get_post_meta($post->ID, '_recent_tweets_title', true); $twitter_user = get_post_meta($post->ID, '_recent_tweets_user', true); $load = get_post_meta($post->ID, '_tweet_count', true); $tweets = TwitterHelper::get_tweets($twitter_user, $load); if (!empty($tweets)) { ?> <section id="recent-tweets" class="colored-block"> <h3><?php echo $section_title_tweets; ?> </h3> <div class="tweets-carousel"><?php foreach ($tweets as $tweet) { ?> <div class="tweet"> <div class="wrapped"> <?php echo wpautop(preg_replace('~' . preg_quote($twitter_user, '~') . ': ~iu', '', $tweet->tweet_text)); ?> <small><?php _e('about', 'espresso'); ?> <?php echo relativeTime($tweet->created_at); ?> <?php _e('via', 'espresso'); ?> <a href="http://twitter.com/<?php