public function authControl() { if (!$this->is_missing_param) { $request_token = $_GET['oauth_token']; $request_token_secret = SessionCache::get('oauth_request_token_secret'); // get oauth values $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('twitter', true); //get cached $to = new TwitterOAuth($options['oauth_consumer_key']->option_value, $options['oauth_consumer_secret']->option_value, $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'], $options['oauth_consumer_key']->option_value, $options['oauth_consumer_secret']->option_value, $options['num_twitter_errors']->option_value, $options['max_api_calls_per_crawl']->option_value, false); $authed_twitter_user = $api->verifyCredentials(); // echo "User ID: ". $authed_twitter_user['user_id']; // echo "User name: ". $authed_twitter_user['user_name']; $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($this->getLoggedInUser()); if ((int) $authed_twitter_user['user_id'] > 0) { $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO'); $instance = $instance_dao->getByUsername($authed_twitter_user['user_name'], 'twitter'); $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO'); if (isset($instance)) { $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); if ($owner_instance != null) { $owner_instance_dao->updateTokens($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret']); $this->addSuccessMessage($authed_twitter_user['user_name'] . " on Twitter is already set up in ThinkUp! To add a different Twitter account, " . "log out of Twitter.com in your browser and authorize ThinkUp again."); } else { if ($owner_instance_dao->insert($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $this->addSuccessMessage("Success! " . $authed_twitter_user['user_name'] . " on Twitter has been added to ThinkUp!"); } else { $this->addErrorMessage("Error: Could not create an owner instance."); } } } else { $instance_dao->insert($authed_twitter_user['user_id'], $authed_twitter_user['user_name']); $instance = $instance_dao->getByUsername($authed_twitter_user['user_name']); if ($owner_instance_dao->insert($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $this->addSuccessMessage("Success! " . $authed_twitter_user['user_name'] . " on Twitter has been added to ThinkUp!"); } else { $this->addErrorMessage("Error: Could not create an owner instance."); } } } } else { $msg = "Error: Twitter authorization did not complete successfully. Check if your account already " . " exists. If not, please try again."; $this->addErrorMessage($msg); } $this->view_mgr->clear_all_cache(); } return $this->generateView(); }
public function testCreateParserFromStringMalformedMarkup() { $data = <<<XML <?xml version='1.0'?> <document> <title>Forty What?</title> <from>Joe</from> <to>Jane</to> <body> I know that's the answer -- <but what's the question? </body> </document> XML; $api = new TwitterAPIAccessorOAuth('111', '222', 'test-oauth_consumer_key', 'test-oauth_consumer_secret', 5, 350); $this->assertFalse($api->createParserFromString(utf8_encode($data))); }
/** * Constructor * @param str $oauth_token * @param str $oauth_token_secret * @param str $oauth_consumer_key * @param str $oauth_consumer_secret * @param Instance $instance * @param int $archive_limit * @param int $num_twitter_errors * @param int $max_api_calls_per_crawl * @return CrawlerTwitterAPIAccessorOAuth */ public function __construct($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $instance, $archive_limit, $num_twitter_errors, $max_api_calls_per_crawl) { parent::__construct($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, $max_api_calls_per_crawl); $this->api_calls_to_leave_unmade_per_minute = $instance->api_calls_to_leave_unmade_per_minute; $this->archive_limit = $archive_limit; }
public function authControl() { $msg = ""; if (!$this->is_missing_param) { $request_token = $_GET['oauth_token']; $request_token_secret = $_SESSION['oauth_request_token_secret']; // get oauth values $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('twitter', true); //get cached $to = new TwitterOAuth($options['oauth_consumer_key']->option_value, $options['oauth_consumer_secret']->option_value, $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'], $options['oauth_consumer_key']->option_value, $options['oauth_consumer_secret']->option_value, $options['num_twitter_errors']->option_value, $options['max_api_calls_per_crawl']->option_value, false); $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($this->getLoggedInUser()); if ($twitter_id > 0) { $msg = "<h2 class=\"subhead\">Twitter authentication successful!</h2>"; $id = DAOFactory::getDAO('InstanceDAO'); $i = $id->getByUsername($tu); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); 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 />"; } } } else { $msg .= "Instance does not exist.<br />"; $id->insert($twitter_id, $tu); $msg .= "Created instance.<br />"; $i = $id->getByUsername($tu); if ($oid->insert($owner->id, $i->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $msg .= "Created an owner instance.<br />"; } else { $msg .= "Did NOT create an owner instance.<br />"; } } } } else { $msg = "PROBLEM! Twitter authorization did not complete successfully. Check if your account already " . " exists. If not, please try again."; } $this->view_mgr->clear_all_cache(); $config = Config::getInstance(); $msg .= '<br /><br /><a href="' . $config->getValue('site_root_path') . 'account/index.php?p=twitter" class="tt-button ui-state-default tt-button-icon-left ui-corner-all"><span class="ui-icon ui-icon-circle-arrow-e"></span>Back to your account</a>'; $this->addInfoMessage($msg); } return $this->generateView(); }
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(); }
/** * @return str */ public function authControl() { $config = Config::getInstance(); Utils::defineConstants(); $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitterrealtime/view/twitterrealtime.account.index.tpl'); $id = DAOFactory::getDAO('InstanceDAO'); $od = DAOFactory::getDAO('OwnerDAO'); // get plugin option values if defined... $plugin_options = $this->getPluginOptions(); // get oauth option values from twitter plugin. // @TODO -- what is the right way to do this? $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $twitter_options = $plugin_option_dao->getOptionsHash('twitter', true); $oauth_consumer_key = null; if (isset($twitter_options['oauth_consumer_key'])) { $oauth_consumer_key = $twitter_options['oauth_consumer_key']->option_value; } $oauth_consumer_secret = null; if (isset($twitter_options['oauth_consumer_secret'])) { $oauth_consumer_secret = $twitter_options['oauth_consumer_secret']->option_value; } // @TODO - get any other option values as necessary // $archive_limit = $this->getPluginOption('archive_limit'); //Add public user instance if (isset($_GET['twitter_username'])) { // if form was submitted $logger = Logger::getInstance(); $api = new TwitterAPIAccessorOAuth('NOAUTH', 'NOAUTH', $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, $max_api_calls_per_crawl); $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->addErrorMessage($e->getMessage()); } if (isset($user) && $user["is_protected"] == 'false') { // if so, add to instances table and owners table $i = $id->getByUsernameOnNetwork($_GET['twitter_username'], 'twitter'); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $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->getByUsernameOnNetwork($user["user_name"], 'twitter'); $oid->insert($this->owner->id, $i->id, '', ''); } $this->addSuccessMessage($_GET['twitter_username'] . " has been added to ThinkUp."); $this->addSuccessMessage("Added " . $_GET['twitter_username'] . " to ThinkUp."); } else { // if not, return error $this->addErrorMessage($_GET['twitter_username'] . " is a private Twitter account; ThinkUp cannot track it without authorization."); } } else { $this->addErrorMessage($_GET['twitter_username'] . " is not a valid Twitter username."); } } $auth_from_twitter = ''; if (isset($oauth_consumer_key) && isset($oauth_consumer_secret)) { $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); // create indication that auth from twitter plugin is okay $auth_from_twitter = "Using the Twitter Consumer key and secret as set in " . "the <a href=\"./?p=twitter\">Twitter plugin</a>."; } else { //set error message here $this->addErrorMessage("Unable to obtain OAuth token. Check your Twitter plugin consumer key and secret configuration."); $oauthorize_link = ''; } } else { $this->addErrorMessage("Missing required settings! Please configure the Twitter plugin."); $oauthorize_link = ''; } $owner_instances = $id->getByOwnerAndNetwork($this->owner, 'twitter'); $this->addToView('owner_instances', $owner_instances); $this->addToView('oauthorize_link', $oauthorize_link); $this->addToView('auth_from_twitter', $auth_from_twitter); // add plugin options from $this->addOptionForm(); return $this->generateView(); }
chdir(".."); require_once 'config.webapp.inc.php'; ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH); require_once "init.php"; $cfg = new Config(); $request_token = $_GET['oauth_token']; $request_token_secret = $_SESSION['oauth_request_token_secret']; /* echo "DEBUG:" echo "URL Request Token: ".$request_token."<br />"; echo "Session Request Token: ".$request_token_secret."<br />"; */ $to = new TwitterOAuth($cfg->oauth_consumer_key, $cfg->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'], $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)) {
function CrawlerTwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $instance, $archive_limit) { parent::TwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret); $this->api_calls_to_leave_unmade_per_minute = $instance->api_calls_to_leave_unmade_per_minute; $this->archive_limit = $archive_limit; }
public function __construct($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $instance, $archive_limit) { parent::__construct($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret); $this->api_calls_to_leave_unmade_per_minute = $instance->api_calls_to_leave_unmade_per_minute; $this->archive_limit = $archive_limit; }
/** * Constructor * @param str $oauth_token * @param str $oauth_token_secret * @param str $oauth_consumer_key * @param str $oauth_consumer_secret * @param Instance $instance * @param int $archive_limit * @param int $num_twitter_errors * @return CrawlerTwitterAPIAccessorOAuth */ public function __construct($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $archive_limit, $num_twitter_errors) { parent::__construct($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors); $this->archive_limit = $archive_limit; self::initializeEndpointRateLimits(); }
/** * Add user who just returned from Twitter.com OAuth authorization and populate view with error/success messages. * @param str $oauth_consumer_key * @param str $oauth_consumer_secret * @param str $num_twitter_errors * @return void */ private function addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors) { if (isset($_GET['oauth_token']) && SessionCache::isKeySet('oauth_request_token_secret')) { $request_token = $_GET['oauth_token']; $request_token_secret = SessionCache::get('oauth_request_token_secret'); $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret, $request_token, $request_token_secret); if (isset($_GET['oauth_verifier'])) { $tok = $twitter_oauth->getAccessToken($_GET['oauth_verifier']); } else { $tok = null; } if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { $api = new TwitterAPIAccessorOAuth($tok['oauth_token'], $tok['oauth_token_secret'], $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, false); $authed_twitter_user = $api->verifyCredentials(); // echo "User ID: ". $authed_twitter_user['user_id']."<br>"; // echo "User name: ". $authed_twitter_user['user_name']."<br>"; $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($this->getLoggedInUser()); if (isset($authed_twitter_user) && isset($authed_twitter_user['user_name']) && isset($authed_twitter_user['user_id'])) { $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO'); $instance = $instance_dao->getByUsername($authed_twitter_user['user_name'], 'twitter'); $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO'); if (isset($instance)) { $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); if ($owner_instance != null) { $owner_instance_dao->updateTokens($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret']); $this->addSuccessMessage($authed_twitter_user['user_name'] . " on Twitter is already set up in ThinkUp! To add a different Twitter account, " . "log out of Twitter.com in your browser and authorize ThinkUp again.", 'user_add'); } else { if ($owner_instance_dao->insert($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $this->addSuccessMessage("Success! " . $authed_twitter_user['user_name'] . " on Twitter has been added to ThinkUp!", "user_add"); } else { $this->addErrorMessage("Error: Could not create an owner instance.", "user_add"); } } } else { $instance_dao->insert($authed_twitter_user['user_id'], $authed_twitter_user['user_name']); $instance = $instance_dao->getByUsername($authed_twitter_user['user_name']); if ($owner_instance_dao->insert($owner->id, $instance->id, $tok['oauth_token'], $tok['oauth_token_secret'])) { $this->addSuccessMessage("Success! " . $authed_twitter_user['user_name'] . " on Twitter has been added to ThinkUp!", "user_add"); } else { $this->addErrorMessage("Error: Could not create an owner instance.", "user_add"); } } } } else { $msg = "Error: Twitter authorization did not complete successfully. Check if your account already " . " exists. If not, please try again."; $this->addErrorMessage($msg, "user_add"); } $this->view_mgr->clear_all_cache(); } }
public function testParseJSONErrorCodeAPI() { $api = new TwitterAPIAccessorOAuth($oauth_access_token = '111', $oauth_access_token_secret = '222', $oauth_consumer_key = 1234, $oauth_consumer_secret = 1234, $num_twitter_errors = 5, $log = true); //List of users with cursor $data = file_get_contents(THINKUP_ROOT_PATH . $this->test_data_path . 'json/error_source_user.json'); $results = $api->parseJSONErrorCodeAPI($data); $this->debug(Utils::varDumpToString($results)); $this->assertEqual($results["error"], 163); }
public function authControl() { $config = Config::getInstance(); Loader::definePathConstants(); $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitter/view/twitter.account.index.tpl'); $this->view_mgr->addHelp('twitter', 'userguide/settings/plugins/twitter'); $id = DAOFactory::getDAO('InstanceDAO'); $od = DAOFactory::getDAO('OwnerDAO'); // get plugin option values if defined... $plugin_options = $this->getPluginOptions(); $oauth_consumer_key = $this->getPluginOption('oauth_consumer_key'); $oauth_consumer_secret = $this->getPluginOption('oauth_consumer_secret'); $archive_limit = $this->getPluginOption('archive_limit'); $num_twitter_errors = $this->getPluginOption('num_twitter_errors'); $max_api_calls_per_crawl = $this->getPluginOption('max_api_calls_per_crawl'); //Add public user instance if (isset($_GET['twitter_username'])) { // if form was submitted $logger = Logger::getInstance(); $api = new TwitterAPIAccessorOAuth('NOAUTH', 'NOAUTH', $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, $max_api_calls_per_crawl); $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->addErrorMessage($e->getMessage()); } if (isset($user) && $user["is_protected"] == 'false') { // if so, add to instances table and owners table $i = $id->getByUsernameOnNetwork($_GET['twitter_username'], 'twitter'); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $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->getByUsernameOnNetwork($user["user_name"], 'twitter'); $oid->insert($this->owner->id, $i->id, '', ''); } $this->addSuccessMessage($_GET['twitter_username'] . " has been added to ThinkUp."); $this->addSuccessMessage("Added " . $_GET['twitter_username'] . " to ThinkUp."); } else { // if not, return error $this->addErrorMessage($_GET['twitter_username'] . " is a private Twitter account; ThinkUp cannot track it without authorization."); } } else { $this->addErrorMessage($_GET['twitter_username'] . " is not a valid Twitter username."); } } $this->addToView('twitter_app_name', "ThinkUp " . $_SERVER['SERVER_NAME']); $this->addToView('thinkup_site_url', Utils::getApplicationURL(true)); $plugin = new TwitterPlugin(); if ($plugin->isConfigured()) { $to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret); /* Request tokens from twitter */ $tok = $to->getRequestToken(Utils::getApplicationURL(true) . "plugins/twitter/auth.php"); if (isset($tok['oauth_token']) || isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS") { //testing $token = $tok['oauth_token']; SessionCache::put('oauth_request_token_secret', $tok['oauth_token_secret']); /* Build the authorization URL */ $oauthorize_link = $to->getAuthorizeURL($token); $owner_instances = $id->getByOwnerAndNetwork($this->owner, 'twitter'); $this->addToView('owner_instances', $owner_instances); $this->addToView('oauthorize_link', $oauthorize_link); $this->addToView('is_configured', true); } else { //set error message here $this->addErrorMessage("Unable to obtain OAuth tokens from Twitter. Please double-check the consumer key and secret " . "are correct.", "setup"); $oauthorize_link = ''; $this->addToView('is_configured', false); } } else { $this->addInfoMessage('Please complete plugin setup to start using it.', 'setup'); $this->addToView('is_configured', false); } // Secret config file value enables public Twitter name search $this->addToView('enable_twitter_search', $config->getValue('enable_twitter_search')); // add plugin options from $this->addOptionForm(); return $this->generateView(); }
function CrawlerTwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $cfg, $instance) { parent::TwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $cfg); $this->api_calls_to_leave_unmade_per_minute = $instance->api_calls_to_leave_unmade_per_minute; }
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); }