public static function feed() { $ncsu = new Tweetgater_Twitter(); $down = false; try { $timeline = $ncsu->getTimeline(); } catch (Exception $e) { $down = true; } $config = $ncsu->getConfigFile(); $fa = array(); $fa['title'] = $config->feed->title; $fa['link'] = $config->site->url . '/feed.php'; $fa['charset'] = 'UTF-8'; $fa['author'] = $config->feed->title; $entries = array(); if (!$down) { foreach ($timeline as $t) { $temp = array(); $temp['title'] = 'Tweet by @' . $t['user-screen_name']; $temp['link'] = 'http://www.twitter.com/' . $t['user-screen_name'] . '/status/' . $t['id']; $temp['description'] = $t['text'] . '<br /><br />Follow @<a href="http://www.twitter.com/' . $t['user-screen_name'] . '">' . $t['user-screen_name'] . '</a>'; $temp['lastUpdate'] = strtotime($t['created_at']); $entries[] = $temp; } } $fa['entries'] = $entries; // importing a rss feed from an array $rssFeed = Zend_Feed::importArray($fa, 'rss'); // send http headers and dump the feed $rssFeed->send(); }
<?php require_once '../inc/Tweetgater/Installer.php'; $installer = new Tweetgater_Installer(); $oauthConfig = Tweetgater_Twitter::getConfigFile(); $installUrl = Tweetgater_Twitter::getBaseUrl(); $session = new Zend_Session_Namespace('twitterAppAuthentication'); $config = array('callbackUrl' => $installUrl . '/install/twitter_callback.php', 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $oauthConfig->oauth->consumerKey, 'consumerSecret' => $oauthConfig->oauth->consumerSecret); $consumer = new Zend_Oauth_Consumer($config); $accessToken = $consumer->getAccessToken($_GET, unserialize($session->requestToken)); $installer->writeOauthToken($accessToken->getParam('oauth_token'), $accessToken->getParam('oauth_token_secret')); $session->unsetAll(); header('Location: index.php');
/** * Display search results * * @param string $terms Search terms * @param int $page integer of the page of the timeline to request * @return $ret HTML of search results */ public static function search($terms, $page = 1) { $tweetgater = new Tweetgater_Twitter(); $error = ''; try { $searchResults = $tweetgater->search($terms, $page); } catch (Exception $e) { $error = $e->getMessage(); } $ret = ''; if ($error == '') { foreach ($searchResults as $t) { $ret .= '<div class="tweet">' . ' <div class="avatar">' . ' <img src="' . $t['user-profile_image_url'] . '" alt="' . $t['user-name'] . '" width="48" height="48" />' . ' </div>' . ' <div class="text">' . ' <a class="username" href="http://twitter.com/' . $t['user-screen_name'] . '">' . $t['user-screen_name'] . '</a> ' . $t['text'] . ' </div>' . ' <div class="origination"> ' . $t['elapsed_time'] . ' from ' . $t['source'] . ($t['in_reply_to_screen_name'] != '' ? ' <a class="user" href="http://www.twitter.com/' . $t['in_reply_to_screen_name'] . '/status/' . $t['in_reply_to_status_id'] . '">in reply to ' . $t['in_reply_to_screen_name'] . '</a>' : '') . ' </div>' . ' <div style="clear:both;"></div>' . '</div>'; } $ret .= '<br /><br />' . '<a class="twitterButton" href="search.php?page=' . ($page + 1) . '">More...</a>'; return $ret; } return $error; }
public function writeOauthToken($token, $tokenSecret) { $config = Tweetgater_Twitter::getConfigFile(true); $config->oauth->token = $token; $config->oauth->tokenSecret = $tokenSecret; $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => Tweetgater_Twitter::getConfigFilePath())); $writer->write(); }
To allow this application to speak to twitter on behalf of the user account you setup, you must give it access. <br /><br /> <a href="twitter_oauth.php">Authenticate with Twitter</a> <?php die; } else { ?> Application is configured to speak to twitter. <?php } ?> <h2>Step 7: Confirm Twitter Communication</h2> <?php $ncsu = new Tweetgater_Twitter(); try { $timeline = $ncsu->getTimeline(); echo "Success connecting!"; } catch (Exception $e) { echo "Error Connecting: " . $e->getMessage(); die; } ?> <h2>Step 8: Cleanup</h2> <ul> <li>You should remove the /install directory</li> <li>You should remove write permissions from the /config directory and file</li> </ul> <br />