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/index'); $instance_dao = DAOFactory::getDAO('InstanceDAO'); // 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'); $this->addToView('twitter_app_name', "ThinkUp " . $_SERVER['SERVER_NAME']); $this->addToView('thinkup_site_url', Utils::getApplicationURL(true)); $plugin = new TwitterPlugin(); if ($plugin->isConfigured()) { $this->addToView('is_configured', true); $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'twitter'); $this->addToView('owner_instances', $owner_instances); if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) { if ($this->owner->isMemberLevel()) { if (sizeof($owner_instances) > 0) { $this->do_show_add_button = false; $this->addInfoMessage("To connect another Twitter account to ThinkUp, upgrade your membership.", 'membership_cap'); } } } if (isset($_GET['oauth_token']) || $this->do_show_add_button) { $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret); /* Request tokens from twitter */ $token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true) . "account/?p=twitter"); if (isset($token_array['oauth_token']) || isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS") { //testing $token = $token_array['oauth_token']; SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']); if (isset($_GET['oauth_token'])) { self::addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors); } if ($this->do_show_add_button) { /* Build the authorization URL */ $oauthorize_link = $twitter_oauth->getAuthorizeURL($token); $this->addToView('oauthorize_link', $oauthorize_link); } } 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); } // add plugin options from $this->addOptionForm(); return $this->generateView(); }
public function testRepliesOrdering() { $this->assertEqual(TwitterPlugin::repliesOrdering('default'), 'is_reply_by_friend DESC, follower_count DESC'); $this->assertEqual(TwitterPlugin::repliesOrdering('location'), 'geo_status, reply_retweet_distance, is_reply_by_friend DESC, follower_count DESC'); $this->assertEqual(TwitterPlugin::repliesOrdering(''), 'is_reply_by_friend DESC, follower_count DESC'); }
public function testDeactivate() { //all facebook and facebook page accounts should be set to inactive on plugin deactivation $webapp = Webapp::getInstance(); $logger = Logger::getInstance(); $pd = DAOFactory::getDAO('PostDAO'); $instance = new Instance(); $instance->network_user_id = 1; $instance_builder_1 = FixtureBuilder::build('instances', array('network_username' => 'julie', 'network' => 'twitter', 'crawler_last_run' => '-1d', 'is_activated' => '1', 'is_public' => '1')); $instance_builder_2 = FixtureBuilder::build('instances', array('network_username' => 'john', 'network' => 'twitter', 'crawler_last_run' => '-1d', 'is_activated' => '1', 'is_public' => '1')); $instance_dao = DAOFactory::getDAO('InstanceDAO'); $active_instances = $instance_dao->getAllInstances("DESC", true, "twitter"); $this->assertEqual(sizeof($active_instances), 2); $tw_plugin = new TwitterPlugin(); $tw_plugin->deactivate(); $active_instances = $instance_dao->getAllInstances("DESC", true, "twitter"); $this->assertEqual(sizeof($active_instances), 0); }
public function testCrawlCompletion() { $this->debug(__METHOD__); $builders = array(); //Add instances $instance_builder_1 = FixtureBuilder::build('instances', array('id' => 1, 'network_username' => 'julie', 'network' => 'twitter', 'crawler_last_run' => '-5d', 'is_activated' => '1', 'is_public' => '1')); $instance_builder_2 = FixtureBuilder::build('instances', array('id' => 2, 'network_username' => 'john', 'network' => 'twitter', 'crawler_last_run' => '-5d', 'is_activated' => '1', 'is_public' => '1')); $builders[] = FixtureBuilder::build('instances_twitter', array('id' => 1)); $builders[] = FixtureBuilder::build('instances_twitter', array('id' => 2)); //Add owner $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1, 'is_admin' => 1)); $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 1, 'auth_error' => '')); $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 2, 'auth_error' => '')); $this->simulateLogin('*****@*****.**', true, true); $test = new TwitterInstanceMySQLDAO(); $twitter_plugin = new TwitterPlugin(); $twitter_plugin->crawl(); $instance_dao = new InstanceMySQLDAO(); $updated_instance = $instance_dao->get(1); $this->debug(Utils::varDumpToString($updated_instance)); // crawler_last_run should have been updated $this->assertNotEqual($instance_builder_1->columns['crawler_last_run'], $updated_instance->crawler_last_run); }
public function testBudgetCrawlLimits() { // set all our bedget percentages to 10% for testing $twitter_plugin = new TwitterPlugin(); $auth_budget_config = $twitter_plugin->api_budget_allocation_auth; foreach ($auth_budget_config as $function_name => $value) { $auth_budget_config[$function_name]['percent'] = 10; } $twitter_plugin->api_budget_allocation_auth = $auth_budget_config; $noauth_budget_config = $twitter_plugin->api_budget_allocation_noauth; foreach ($noauth_budget_config as $function_name => $value) { $noauth_budget_config[$function_name]['percent'] = 10; } $twitter_plugin->api_budget_allocation_noauth = $noauth_budget_config; // with auth $limits = $twitter_plugin->budgetCrawlLimits(1000, false); $this->assertIsA($limits, 'Array'); $this->assertEqual(count($limits), 14); foreach ($limits as $limit_key => $value) { $this->assertEqual($value['count'], 100); $this->assertEqual($value['remaining'], 100); } // no auth $limits = $twitter_plugin->budgetCrawlLimits(1000, true); $this->assertIsA($limits, 'Array'); $this->assertEqual(count($limits), 6); foreach ($limits as $limit_key => $value) { $this->assertEqual($value['count'], 100); $this->assertEqual($value['remaining'], 100); } }
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(); }