function facebook_crawl() { //TODO Crawl Facebook posts and comments and insert them into the database global $THINKTANK_CFG; global $db; global $conn; $logger = new Logger($THINKTANK_CFG['log_location']); $id = new InstanceDAO($db, $logger); $oid = new OwnerInstanceDAO($db, $logger); $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook'); foreach ($instances as $i) { $logger->setUsername($i->network_username); $tokens = $oid->getOAuthTokens($i->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($THINKTANK_CFG['facebook_api_key'], $THINKTANK_CFG['facebook_api_secret']); $cfg = new Config($i->network_username, $i->network_user_id); $id->updateLastRun($i->id); $crawler = new FacebookCrawler($i, $logger, $fb, $db); $crawler->fetchInstanceUserInfo($i->network_user_id, $session_key); $crawler->fetchUserPostsAndReplies($i->network_user_id, $session_key); $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $fb); } $logger->close(); # Close logging }
public function crawl() { global $db; global $conn; $config = Config::getInstance(); $logger = Logger::getInstance(); $id = DAOFactory::getDAO('InstanceDAO'); $oid = new OwnerInstanceDAO($db, $logger); $instances = $id->getAllActiveInstancesStalestFirstByNetwork('twitter'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $noauth = true; if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') { $noauth = false; } if ($noauth) { $api = new CrawlerTwitterAPIAccessorOAuth('NOAUTH', 'NOAUTH', $config->getValue('oauth_consumer_key'), $config->getValue('oauth_consumer_secret'), $instance, $config->getValue('archive_limit')); } else { $api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $config->getValue('oauth_consumer_key'), $config->getValue('oauth_consumer_secret'), $instance, $config->getValue('archive_limit')); } $crawler = new TwitterCrawler($instance, $api, $db); $api->init(); if ($api->available_api_calls_for_crawler > 0) { $id->updateLastRun($instance->id); // No auth req'd $crawler->fetchInstanceUserInfo(); // No auth for public Twitter users $crawler->fetchInstanceUserTweets(); if (!$noauth) { // Auth req'd, for calling user only $crawler->fetchInstanceUserMentions(); $crawler->fetchRetweetsOfInstanceUser(); $crawler->fetchInstanceUserFriends(); $crawler->fetchInstanceUserFollowers(); } $crawler->fetchStrayRepliedToTweets(); $crawler->fetchUnloadedFollowerDetails(); $crawler->fetchFriendTweetsAndFriends(); // TODO: Get direct messages // TODO: Gather favorites data if ($noauth) { // No auth req'd $crawler->fetchSearchResults($instance->network_username); } $crawler->cleanUpFollows(); // Save instance $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $api); } } $logger->close(); # Close logging }
function testUpdateTokens() { global $THINKTANK_CFG; $dao = new OwnerInstanceDAO($this->db, $this->logger); $result = $dao->insert(10, 20, 'aaa', 'bbb'); $this->assertTrue($result); $result = $dao->updateTokens(10, 20, 'ccc', 'ddd'); $this->assertTrue($result); $tokens = $dao->getOAuthTokens(20); $this->assertEqual($tokens['oauth_access_token'], 'ccc'); $this->assertEqual($tokens['oauth_access_token_secret'], 'ddd'); }
function twitter_crawl() { global $THINKTANK_CFG; global $db; global $conn; $logger = new Logger($THINKTANK_CFG['log_location']); $id = new InstanceDAO($db, $logger); $oid = new OwnerInstanceDAO($db, $logger); $lurlapi = new LongUrlAPIAccessor($THINKTANK_CFG['app_title']); $flickrapi = new FlickrAPIAccessor($THINKTANK_CFG['flickr_api_key']); $instances = $id->getAllActiveInstancesStalestFirst(); foreach ($instances as $i) { $logger->setUsername($i->network_username); $tokens = $oid->getOAuthTokens($i->id); $api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']); $crawler = new TwitterCrawler($i, $logger, $api, $db); $cfg = new Config($i->network_username, $i->network_user_id); $api->init($logger); if ($api->available_api_calls_for_crawler > 0) { $id->updateLastRun($i->id); $crawler->fetchInstanceUserInfo(); $crawler->fetchInstanceUserTweets($lurlapi, $flickrapi); $crawler->fetchInstanceUserRetweetsByMe($lurlapi, $flickrapi); $crawler->fetchInstanceUserMentions($lurlapi, $flickrapi); $crawler->fetchInstanceUserFriends(); $crawler->fetchInstanceUserFollowers(); $crawler->fetchStrayRepliedToTweets($lurlapi, $flickrapi); $crawler->fetchUnloadedFollowerDetails(); $crawler->fetchFriendTweetsAndFriends($lurlapi, $flickrapi); // TODO: Get direct messages // TODO: Gather favorites data $crawler->cleanUpFollows(); // Save instance $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $api); } } $logger->close(); # Close logging if (isset($conn)) { $db->closeConnection($conn); } // Clean up }
public function crawl() { global $db; //TODO Remove when PDO port is complete global $conn; $logger = Logger::getInstance(); $config = Config::getInstance(); $id = DAOFactory::getDAO('InstanceDAO'); $oid = new OwnerInstanceDAO($db, $logger); //crawl Facebook user profiles $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($config->getValue('facebook_api_key'), $config->getValue('facebook_api_secret')); $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $fb); $crawler->fetchInstanceUserInfo($instance->network_user_id, $session_key); $crawler->fetchUserPostsAndReplies($instance->network_user_id, $session_key); $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $fb); } //crawl Facebook pages $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook page'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($config->getValue('facebook_api_key'), $config->getValue('facebook_api_secret')); $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $fb); $crawler->fetchPagePostsAndReplies($instance->network_user_id, $instance->network_viewer_id, $session_key); $id->save($crawler->instance, 0, $logger, $fb); } $logger->close(); # Close logging }
require_once 'config.webapp.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $tu = $_POST['twitter_username']; $tp = $_POST['twitter_password']; $db = new Database($THINKTANK_CFG); $conn = $db->getConnection(); $od = new OwnerDAO($db); $owner = $od->getByEmail($_SESSION['user']); $api = new TwitterAPIAccessor($tu, $tp); $twitter_id = $api->doesAuthenticate(); if ($twitter_id > 0) { echo "Twitter authentication successful.<br />"; $id = new InstanceDAO($db); $i = $id->getByUsername($tu); $oid = new OwnerInstanceDAO($db); if (isset($i)) { echo "Instance already exists.<br />"; $id->updatePassword($tu, $tp); echo "Updated existing instance's password.<br />"; $oi = $oid->get($owner->id, $i->id); if ($oi != null) { echo "Owner already has this instance, no insert or update.<br />"; } else { $oid->insert($owner->id, $i->id); echo "Added owner instance.<br />"; } } else { echo "Instance does not exist.<br />"; $id->insert($twitter_id, $tu, $tp); echo "Created instance with password.<br />";
<?php require_once 'config.crawler.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $db = new Database($THINKTANK_CFG); $conn = $db->getConnection(); $logger = new Logger($THINKTANK_CFG['log_location']); $id = new InstanceDAO($db, $logger); $oid = new OwnerInstanceDAO($db, $logger); $lurlapi = new LongUrlAPIAccessor($THINKTANK_CFG['app_title']); $flickrapi = new FlickrAPIAccessor($THINKTANK_CFG['flickr_api_key']); $instances = $id->getAllInstancesStalestFirst(); foreach ($instances as $i) { $logger->setUsername($i->twitter_username); $tokens = $oid->getOAuthTokens($i->id); $api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']); $crawler = new Crawler($i, $logger, $api, $db); $cfg = new Config($i->twitter_username, $i->twitter_user_id); $api->init($logger); if ($api->available_api_calls_for_crawler > 0) { $id->updateLastRun($i->id); $crawler->fetchInstanceUserInfo(); $crawler->fetchInstanceUserTweets($lurlapi, $flickrapi); $crawler->fetchInstanceUserRetweetsByMe($lurlapi, $flickrapi); $crawler->fetchInstanceUserMentions($lurlapi, $flickrapi); $crawler->fetchInstanceUserFriends(); $crawler->fetchInstanceUserFollowers(); $crawler->fetchStrayRepliedToTweets($lurlapi, $flickrapi); $crawler->fetchUnloadedFollowerDetails(); $crawler->fetchFriendTweetsAndFriends($lurlapi, $flickrapi);
header("Location: /session/login.php"); } // set up chdir(".."); require_once 'config.webapp.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $db = new Database($THINKTANK_CFG); $conn = $db->getConnection(); $od = new OwnerDAO($db); $owner = $od->getByEmail($_SESSION['user']); $td = new TweetDAO($db); $id = new InstanceDAO($db); if (isset($_REQUEST['u']) && $id->isUserConfigured($_REQUEST['u'])) { $username = $_REQUEST['u']; $oid = new OwnerInstanceDAO($db); if (!$oid->doesOwnerHaveAccess($owner, $username)) { echo 'Insufficient privileges. <a href="/">Back</a>.'; $db->closeConnection($conn); die; } else { $tweets = $td->getAllTweetsByUsername($username); } } else { echo 'No access'; $db->closeConnection($conn); die; } $s = new SmartyThinkTank(); $s->assign('tweets', $tweets); $s->display('status.export.tpl', $username);
public function authControl() { global $db; //@TODO remove once PDO port is done $config = Config::getInstance(); $this->setViewTemplate($config->getValue('source_root_path') . 'webapp/plugins/twitter/view/twitter.account.index.tpl'); $id = DAOFactory::getDAO('InstanceDAO'); $od = DAOFactory::getDAO('OwnerDAO'); $oauth_consumer_key = $config->getValue('oauth_consumer_key'); $oauth_consumer_secret = $config->getValue('oauth_consumer_secret'); //Add public user instance if (isset($_GET['twitter_username'])) { // if form was submitted $logger = Logger::getInstance(); //Check user exists and is public $api = new TwitterAPIAccessorOAuth('NOAUTH', 'NOAUTH', $oauth_consumer_key, $oauth_consumer_secret, $config->getValue('archive_limit')); $api_call = str_replace("[id]", $_GET['twitter_username'], $api->cURL_source['show_user']); list($cURL_status, $data) = $api->apiRequestFromWebapp($api_call); if ($cURL_status == 200) { $thisFeed = array(); try { $xml = $api->createParserFromString(utf8_encode($data)); $user = array('user_id' => $xml->id, 'user_name' => $xml->screen_name, 'is_protected' => $xml->protected); } catch (Exception $e) { $this->addToView('errormsg', $e->getMessage()); } if (isset($user) && $user["is_protected"] == 'false') { // if so, add to instances table and owners table $i = $id->getByUsername($_GET['twitter_username']); $oid = new OwnerInstanceDAO($db); $msg = ''; if (isset($i)) { //Instance exists $oi = $oid->get($this->owner->id, $i->id); if ($oi == null) { //Owner_instance doesn't exist $oid->insert($this->owner->id, $i->id, '', ''); } } else { //Instance does not exist $id->insert($user["user_id"], $user["user_name"]); $i = $id->getByUsername($user["user_name"]); $oid->insert($this->owner->id, $i->id, '', ''); } $this->addToView('successmsg', $_GET['twitter_username'] . " has been added to ThinkTank."); $this->addToView('successmsg', "Added " . $_GET['twitter_username'] . " to ThinkTank."); } else { // if not, return error $this->addToView('errormsg', $_GET['twitter_username'] . " is a private Twitter account; ThinkTank cannot track it without authorization."); } } else { $this->addToView('errormsg', $_GET['twitter_username'] . " is not a valid Twitter username."); } } $to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret); /* Request tokens from twitter */ $tok = $to->getRequestToken(); if (isset($tok['oauth_token'])) { $token = $tok['oauth_token']; $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret']; /* Build the authorization URL */ $oauthorize_link = $to->getAuthorizeURL($token); } else { //set error message here $this->addToView('errormsg', "Unable to obtain OAuth token. Check your Twitter consumer key and secret configuration."); $oauthorize_link = ''; } $owner_instances = $id->getByOwnerAndNetwork($this->owner, 'twitter'); $this->addToView('owner_instances', $owner_instances); $this->addToView('oauthorize_link', $oauthorize_link); return $this->generateView(); }
$facebook = new Facebook($THINKTANK_CFG['facebook_api_key'], $THINKTANK_CFG['facebook_api_secret']); try { $fb_user = $facebook->api_client->users_getLoggedInUser(); echo "Facebook user is logged in and user ID set<br />"; $fb_username = $facebook->api_client->users_getInfo($fb_user, 'name'); $fb_username = $fb_username[0]['name']; } catch (Exception $e) { echo "EXCEPTION: " . $e->message; } if (isset($_GET['sessionKey']) && isset($fb_user) && $fb_user > 0) { $session_key = $_GET['sessionKey']; echo "DEBUG:"; echo "Session Key: " . $session_key . "<br />"; $od = new OwnerDAO($db); $id = new InstanceDAO($db); $oid = new OwnerInstanceDAO($db); $ud = new UserDAO($db); $owner = $od->getByEmail($_SESSION['user']); $i = $id->getByUserId($fb_user); if (isset($i)) { echo "Instance exists<br />"; $oi = $oid->get($owner->id, $i->id); if ($oi == null) { //Instance already exists, owner instance doesn't $oid->insert($owner->id, $i->id, $session_key); //Add owner instance with session key echo "Created owner instance.<br />"; } } else { //Instance does not exist echo "Instance does not exist<br />";
if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { $api = new TwitterAPIAccessorOAuth($tok['oauth_token'], $tok['oauth_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret']); $u = $api->verifyCredentials(); // echo "User ID: ". $u['user_id']; // echo "User name: ". $u['user_name']; $twitter_id = $u['user_id']; $tu = $u['user_name']; $db = new Database($THINKTANK_CFG); $conn = $db->getConnection(); $od = new OwnerDAO($db); $owner = $od->getByEmail($_SESSION['user']); if ($twitter_id > 0) { echo "Twitter authentication successful.<br />"; $id = new InstanceDAO($db); $i = $id->getByUsername($tu); $oid = new OwnerInstanceDAO($db); if (isset($i)) { echo "Instance already exists.<br />"; $oi = $oid->get($owner->id, $i->id); if ($oi != null) { echo "Owner already has this instance, no insert or update.<br />"; } else { $oid->insert($owner->id, $i->id, $tok['oauth_token'], $tok['oauth_token_secret']); echo "Added owner instance.<br />"; } } else { echo "Instance does not exist.<br />"; $id->insert($twitter_id, $tu); echo "Created instance.<br />"; $i = $id->getByUsername($tu); $oid->insert($owner->id, $i->id, $tok['oauth_token'], $tok['oauth_token_secret']);
$to = new TwitterOAuth($config->getValue('oauth_consumer_key'), $config->getValue('oauth_consumer_secret'), $request_token, $request_token_secret); $tok = $to->getAccessToken(); if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { $api = new TwitterAPIAccessorOAuth($tok['oauth_token'], $tok['oauth_token_secret'], $config->getValue('oauth_consumer_key'), $config->getValue('oauth_consumer_secret')); $u = $api->verifyCredentials(); // echo "User ID: ". $u['user_id']; // echo "User name: ". $u['user_name']; $twitter_id = $u['user_id']; $tu = $u['user_name']; $od = DAOFactory::getDAO('OwnerDAO'); $owner = $od->getByEmail($_SESSION['user']); if ($twitter_id > 0) { $msg = "<h2 class=\"subhead\">Twitter authentication successful!</h2>"; $id = DAOFactory::getDAO('InstanceDAO'); $i = $id->getByUsername($tu); $oid = new OwnerInstanceDAO($db); if (isset($i)) { $msg .= "Instance already exists.<br />"; $oi = $oid->get($owner->id, $i->id); if ($oi != null) { $msg .= "Owner already has this instance, no insert required.<br />"; if ($oid->updateTokens($owner->id, $i->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $msg .= "OAuth Tokens updated."; } else { $msg .= "OAuth Tokens NOT updated."; } } else { if ($oid->insert($owner->id, $i->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $msg .= "Added owner instance.<br />"; } else { $msg .= "PROBLEM Did not add owner instance.<br />";
/** * Handle requests for private dashboard data * @TODO Throw an Insufficient privileges Exception when owner doesn't have access to an instance */ public function authControl() { global $db; //@TODO: remove this when PDO port is done $webapp = Webapp::getInstance(); $this->setViewTemplate('index.tpl'); $continue = true; $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($this->getLoggedInUser()); $instancenstance_dao = DAOFactory::getDAO('InstanceDAO'); $config = Config::getInstance(); if (isset($_REQUEST['u']) && isset($_REQUEST['n']) && $instancenstance_dao->isUserConfigured($_REQUEST['u'])) { $username = $_REQUEST['u']; $owner_instance_dao = new OwnerInstanceDAO($db); if (!$owner_instance_dao->doesOwnerHaveAccess($owner, $username)) { $this->addToView('error', 'Insufficient privileges. <a href="/">Back</a>.'); $continue = false; } else { $instance = $instancenstance_dao->getByUsernameOnNetwork($username, $_REQUEST['n']); } } else { $instance = $instancenstance_dao->getFreshestByOwnerId($owner->id); if (!isset($instance) && $instance == null) { $this->addToView('msg', 'You have no Twitter accounts configured. <a href="' . $config->getValue('site_root_path') . 'account/?p=twitter">Set up an account→</a>'); $continue = false; } } if ($continue) { $this->addToViewCacheKey($instance->network_username); $this->addToViewCacheKey($instance->network); // instantiate data access objects $user_dao = DAOFactory::getDAO('UserDAO'); $follow_dao = DAOFactory::getDAO('FollowDAO'); // pass data to smarty $owner_stats = $user_dao->getDetails($instance->network_user_id); $this->addToView('owner_stats', $owner_stats); $this->addToView('instance', $instance); $this->addToView('instances', $instancenstance_dao->getByOwner($owner)); $total_follows_with_errors = $follow_dao->countTotalFollowsWithErrors($instance->network_user_id); $this->addToView('total_follows_with_errors', $total_follows_with_errors); $total_follows_with_full_details = $follow_dao->countTotalFollowsWithFullDetails($instance->network_user_id); $this->addToView('total_follows_with_full_details', $total_follows_with_full_details); $total_follows_protected = $follow_dao->countTotalFollowsProtected($instance->network_user_id); $this->addToView('total_follows_protected', $total_follows_protected); //TODO: Get friends with full details and also friends with errors, same as with followers $total_friends_loaded = $follow_dao->countTotalFriends($instance->network_user_id); $this->addToView('total_friends', $total_friends_loaded); $total_friends_with_errors = $follow_dao->countTotalFriendsWithErrors($instance->network_user_id); $this->addToView('total_friends_with_errors', $total_friends_with_errors); $total_friends_protected = $follow_dao->countTotalFriendsProtected($instance->network_user_id); $this->addToView('total_friends_protected', $total_friends_protected); //Percentages if (isset($owner_stats)) { $percent_followers_loaded = Utils::getPercentage($owner_stats->follower_count, $total_follows_with_full_details + $total_follows_with_errors); $percent_followers_loaded = $percent_followers_loaded > 100 ? 100 : $percent_followers_loaded; $this->addToView('percent_followers_loaded', $percent_followers_loaded); $percent_tweets_loaded = Utils::getPercentage($owner_stats->post_count, $instance->total_posts_in_system); $percent_tweets_loaded = $percent_tweets_loaded > 100 ? 100 : $percent_tweets_loaded; $this->addToView('percent_tweets_loaded', $percent_tweets_loaded); $percent_friends_loaded = Utils::getPercentage($owner_stats->friend_count, $total_friends_loaded); $percent_friends_loaded = $percent_friends_loaded > 100 ? 100 : $percent_friends_loaded; $this->addToView('percent_friends_loaded', $percent_friends_loaded); $percent_followers_suspended = round(Utils::getPercentage($total_follows_with_full_details, $total_follows_with_errors), 2); $this->addToView('percent_followers_suspended', $percent_followers_suspended); $percent_followers_protected = round(Utils::getPercentage($total_follows_with_full_details, $total_follows_protected), 2); $this->addToView('percent_followers_protected', $percent_followers_protected); } $webapp->setActivePlugin($instance->network); $this->addToView('post_tabs', $webapp->getChildTabsUnderPosts($instance)); $this->addToView('replies_tabs', $webapp->getChildTabsUnderReplies($instance)); $this->addToView('friends_tabs', $webapp->getChildTabsUnderFriends($instance)); $this->addToView('followers_tabs', $webapp->getChildTabsUnderFollowers($instance)); $this->addToView('links_tabs', $webapp->getChildTabsUnderLinks($instance)); } return $this->generateView(); }
function twitter_webapp_configuration() { global $THINKTANK_CFG; global $s; global $od; global $id; global $db; global $cfg; global $owner; //Add public user instance if (isset($_GET['twitter_username'])) { // if form was submitted $logger = new Logger($THINKTANK_CFG['log_location']); //Check user exists and is public $api = new TwitterAPIAccessorOAuth('NOAUTH', 'NOAUTH', $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $THINKTANK_CFG['archive_limit']); $api_call = str_replace("[id]", $_GET['twitter_username'], $api->cURL_source['show_user']); list($cURL_status, $data) = $api->apiRequestFromWebapp($api_call, $logger); if ($cURL_status == 200) { $thisFeed = array(); try { $xml = $api->createParserFromString(utf8_encode($data)); $user = array('user_id' => $xml->id, 'user_name' => $xml->screen_name, 'is_protected' => $xml->protected); } catch (Exception $e) { $s->assign('errormsg', $e->getMessage()); } if (isset($user) && $user["is_protected"] == 'false') { // if so, add to instances table and owners table $i = $id->getByUsername($_GET['twitter_username']); $oid = new OwnerInstanceDAO($db); $msg = ''; if (isset($i)) { //$msg .= "Instance already exists.<br />"; $oi = $oid->get($owner->id, $i->id); if ($oi != null) { //$msg .= "Owner already has this instance, no insert or update required.<br />"; } else { $oid->insert($owner->id, $i->id, '', ''); //$msg .= "Added owner instance.<br />"; } } else { //$msg .= "Instance does not exist.<br />"; $id->insert($user["user_id"], $user["user_name"]); //$msg .= "Created instance.<br />"; $i = $id->getByUsername($user["user_name"]); $oid->insert($owner->id, $i->id, '', ''); //$msg .= "Created an owner instance.<br />"; } $s->assign('successmsg', $_GET['twitter_username'] . " has been added to ThinkTank."); $s->assign('successmsg', "Added " . $_GET['twitter_username'] . " to ThinkTank."); } else { // if not, return error $s->assign('errormsg', $_GET['twitter_username'] . " is a private Twitter account; ThinkTank cannot track it without authorization."); } } else { $s->assign('errormsg', $_GET['twitter_username'] . " is not a valid Twitter username."); } } $to = new TwitterOAuth($cfg->oauth_consumer_key, $cfg->oauth_consumer_secret); /* Request tokens from twitter */ $tok = $to->getRequestToken(); $token = $tok['oauth_token']; $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret']; /* Build the authorization URL */ $oauthorize_link = $to->getAuthorizeURL($token); $owner_instances = $id->getByOwnerAndNetwork($owner, 'twitter'); $s->assign('owner_instances', $owner_instances); $s->assign('oauthorize_link', $oauthorize_link); }