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'); }
$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 />"; $i = $id->getByUsername($tu); $oid->insert($owner->id, $i->id); echo "Created an owner_instance.<br />"; } } else { echo 'Twitter authentication failed.'; } # clean up $db->closeConnection($conn);
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(); }
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 />"; $id->insert($fb_user, $fb_username, 'facebook'); echo "Created instance"; $i = $id->getByUserId($fb_user); $oid->insert($owner->id, $i->id, $session_key); echo "Created owner instance.<br />"; } if (!$ud->isUserInDB($fb_user)) { $r = array('user_id' => $fb_user, 'user_name' => $fb_username, 'full_name' => $fb_username, 'avatar' => '', 'location' => '', 'description' => '', 'url' => '', 'is_protected' => '', 'follower_count' => 0, 'friend_count' => 0, 'post_count' => 0, 'last_updated' => '', 'last_post' => '', 'joined' => '', 'last_post_id' => '', 'network' => 'facebook'); $u = new User($r, 'Owner info');
$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']); echo "Created an owner_instance.<br />"; } } # clean up $db->closeConnection($conn); } echo '<br /> <a href="' . $THINKTANK_CFG['site_root_path'] . 'account/">Back to your account</a>.';
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); }