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();
 }
Beispiel #2
0
$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 />";
        $i = $id->getByUsername($tu);
        $oid->insert($owner->id, $i->id);
        echo "Created an owner_instance.<br />";
    }
} else {
Beispiel #3
0
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);
}