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(); }
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(); }
/** * @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(); }
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); }