Source of file SSTwitter.php
Size: 2,691 Bytes - Last Modified: 2021-12-24T06:19:31+00:00
/var/www/docs.ssmods.com/process/src/code/SSTwitter.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 | <?php require_once (dirname(dirname(__FILE__)) . '/vendor/codebird-php/src/codebird.php'); /** * The SSTwitter class connects to Twitter API version 1.1 via OAuth * It can be used for fetching tweets from a users timeline * * @package twitter-stripe */ class SSTwitter extends Object { private $cb; private $consumerKey; private $consumerSecret; private $accessToken; private $accessSecret; private $screenName; public function __construct() { // set OAuth details from config $this->setAuth(); // connect and setup instance $this->connect(); } /** * * Setup the auth properties from the config * */ private function setAuth() { //set the auth details $this->consumerKey = Config::inst()->get('SSTwitter', 'CONSUMER_KEY'); $this->consumerSecret = Config::inst()->get('SSTwitter', 'CONSUMER_SECRET'); $this->accessToken = Config::inst()->get('SSTwitter', 'OAUTH_TOKEN'); $this->accessSecret = Config::inst()->get('SSTwitter', 'OAUTH_SECRET'); } /** * * Setup the screen name via a param or the config * The config can be overridden by providing a param * * @param string $screenName Screen Name for a user timeline */ private function setScreenName($screenName = null) { if (!$screenName) { $screenName = Config::inst()->get('SSTwitter', 'TWITTER_SCREENNAME'); } $this->screenName = $screenName; } /** * * Connect and setup a Twitter instance * */ private function connect() { \Codebird\Codebird::setConsumerKey($this->consumerKey, $this->consumerSecret); $this->cb = \Codebird\Codebird::getInstance(); $this->cb->setToken($this->accessToken, $this->accessSecret); } /** * * Fetch tweets for a instance and a screen name * * @param int $count number of tweets to fetch * @param boolean $retweet Do we need to display retweets * @param string $screenName Screen Name for a user timeline */ public function getTweets($count = 1, $retweet = false, $screenName = null) { $this->setScreenName($screenName); $params = array( 'screen_name' => $this->screenName, 'count' => $count, 'include_rts' => $retweet ); $tweets = $this->cb->statuses_userTimeline($params); return $tweets; } /** * * Send a tweet * * @param string $tweet The tweet to send */ public function sendTweet($tweet) { if (is_array($tweet)) { $params = $tweet; } else { $params['status'] = $tweet; } $reply = $this->cb->statuses_update($params); return $reply; } /** * * Search for something on Twitter * * @param string $search The query you want to search for */ public function search($search) { return $this->cb->search_tweets("q=$search", true); } } |