Пример #1
0
 function auth_set($member_id, $oauth_url)
 {
     require_lang('twitter');
     require_code('twitter');
     $api_key = get_option('twitter_api_key', true);
     $api_secret = get_option('twitter_api_secret', true);
     $twitter = new Twitter($api_key, $api_secret);
     if (get_param_integer('oauth_in_progress', 0) == 0) {
         $response = $twitter->oAuthRequestToken($oauth_url->evaluate());
         $twitter->oAuthAuthorize($response['oauth_token']);
         exit;
     }
     $response = $twitter->oAuthAccessToken(get_param('oauth_token'), get_param('oauth_verifier'));
     if (!isset($response['oauth_token'])) {
         attach_message(do_lang_tempcode('TWITTER_OAUTH_FAIL', escape_html($response['message'])), 'warn');
         return false;
     }
     $save_to = 'twitter_oauth_token';
     if (!is_null($member_id)) {
         $save_to .= '__' . strval($member_id);
     }
     set_long_value($save_to, $response['oauth_token']);
     $save_to = 'twitter_oauth_token_secret';
     if (!is_null($member_id)) {
         $save_to .= '__' . strval($member_id);
     }
     set_long_value($save_to, $response['oauth_token_secret']);
     return true;
 }
Пример #2
0
 public function connectTwitter()
 {
     $token = Input::get('oauth_token');
     $verifier = Input::get('oauth_verifier');
     $accessToken = Twitter::oAuthAccessToken($token, $verifier);
     if (!empty($accessToken)) {
         $user_token = $accessToken['oauth_token'];
         $user_secret = $accessToken['oauth_token_secret'];
         $twitter_id = $accessToken['user_id'];
         $screen_name = $accessToken['screen_name'];
         $network_type = 'twitter';
         if (!Auth::check()) {
             $user = User::where('social_id', '=', $twitter_id)->where('type', '=', 'twitter')->first();
             if (empty($user)) {
                 $user['inputs'] = array('username' => $screen_name, 'email' => '', 'type' => $network_type, 'social_id' => $twitter_id);
                 Event::fire('user.create', array($user));
             }
         }
         if (Auth::check()) {
             $user_id = Auth::user()->id;
             $network = Network::where('user_id', '=', $user_id)->where('network', '=', $network_type)->where('network_id', '=', $twitter_id)->first();
             if (!empty($network)) {
                 $network->user_token = $user_token;
                 $network->user_secret = $user_secret;
                 $network->save();
             } else {
                 $network = new Network();
                 $network->user_id = $user_id;
                 $network->network = $network_type;
                 $network->user_token = $user_token;
                 $network->user_secret = $user_secret;
                 $network->network_id = $twitter_id;
                 $network->username = $screen_name;
                 $network->save();
             }
         }
         return Redirect::to('/networks')->with('message', array('type' => 'success', 'text' => 'You have successfully connected your Twitter account!'));
     } else {
         return Redirect::to('/networks')->with('message', array('type' => 'danger', 'text' => 'Something went wrong while trying to connect to Twitter, please try again'));
     }
 }
Пример #3
0
    function execute($par)
    {
        global $wgRequest, $wgOut, $wgUser, $wgServer, $IP;
        // this only for staff
        if (!in_array('staff', $wgUser->getGroups())) {
            $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
            return;
        }
        $target = isset($par) ? $par : $wgRequest->getVal('target');
        // set up a new account if we have been given one
        if ($wgRequest->wasPosted()) {
            $cat = Title::makeTitle(NS_CATEGORY, $wgRequest->getVal('category'));
            // set up the link between the twitter account and the category
            $username = $wgRequest->getVal('username');
            $password = $wgRequest->getVal('password');
            $dbw = wfGetDB(DB_MASTER);
            $opts = array('tfc_username' => $username, 'tfc_category' => $cat->getDBKey());
            $count = $dbw->selectField('twitterfeedcatgories', 'count(*)', $opts);
            if ($count == 0) {
                // there can only be 1 pair like this
                $dbw->insert('twitterfeedcatgories', $opts);
            }
            // do we already have auth tokens set up for this twitter account?
            $row = $dbw->selectRow('twitterfeedaccounts', array('*'), array('tws_username' => $username));
            if (!$row->tws_token) {
                // insert what we know, create the initial account
                if (!$row) {
                    $dbw->insert('twitterfeedaccounts', array('tws_username' => $username, 'tws_password' => $password));
                }
                // then send them on their way to authenticate their tokens, they'll be back, don't worry
                $callback = $wgServer . '/Special:TwitterAccounts/' . urlencode($username);
                require_once "{$IP}/extensions/wikihow/common/twitterapi.php";
                $twitter = new Twitter(WH_TWITTER_CONSUMER_KEY, WH_TWITTER_CONSUMER_SEC);
                $twitter->oAuthRequestToken($callback);
                $twitter->oAuthAuthorize();
                return;
            }
        }
        // process the call back and update the appropriate tokens
        if ($target && $wgRequest->getVal('oauth_token')) {
            require_once "{$IP}/extensions/wikihow/common/twitterapi.php";
            $twitter = new Twitter(WH_TWITTER_CONSUMER_KEY, WH_TWITTER_CONSUMER_SEC);
            $twitter->oAuthRequestToken($callback);
            $response = $twitter->oAuthAccessToken($_GET['oauth_token'], $_GET['oauth_verifier']);
            $dbw = wfGetDB(DB_MASTER);
            $dbw->update('twitterfeedaccounts', array('tws_token' => $response['oauth_token'], 'tws_verifier' => $wgRequest->getVal('oauth_verifier'), 'tws_secret' => $response['oauth_token_secret']), array('tws_username' => $target));
            $wgOut->addHTML("<b>Tokens updated for {$target}</b><br/><br/>");
        }
        // delete any relationships that were requeted
        if ($wgRequest->getVal('eaction') == 'del') {
            $username = $wgRequest->getVal('username');
            $cat = Title::makeTitle(NS_CATEGORY, $wgRequest->getVal('category'));
            $dbw = wfGetDB(DB_MASTER);
            $opts = array('tfc_username' => $username, 'tfc_category' => $cat->getDBKey());
            $dbw->delete('twitterfeedcatgories', $opts);
            $wgOut->addHTML("<b>New articles will no longer be tweeted to {$username} for the category {$cat->getText()}</b><br/><br/>");
        }
        // show all of the active accounts
        $dbr = wfGetDB(DB_MASTER);
        $res = $dbr->select(array('twitterfeedaccounts', 'twitterfeedcatgories'), array('*'), array('tfc_username=tws_username'));
        $wgOut->addHTML(<<<EOSCRIPT
function showPass(id, pass) {
\t\$('#pass_' + id).html(pass);\t
\treturn false;
}

function showCats() {
\tvar url = '/Special:Categoryhelper?type=categorypopup';
    var modalParams = {
        width: 650,
        height: 500,
        title: "Select a category",
        modal: true,
        position: 'center'
\t\tcloseText: 'Close',
    };
\t\$('#dialog-box').load(url, function() {
\t\t\t\$("#dialog-box").dialog(modalParams);
\t\t}
\t);
\treturn false;
}
\t\t
function twtDelete(cat, user) {
\tif (confirm("Are you sure you no longer want to tweet to the twitter account " + user + " for the category " + cat + "?")) {
\t\twindow.location.href='/Special:TwitterAccounts?eaction=del&username='******'margin-left: auto; margin-right: auto;' width='70%'>\n\t\t\t\t<tr><td>Username</td><td>Password</td><td>Category</td><td style='text-align:right;'>Delete</td></tr>");
        $index = 0;
        while ($row = $dbr->fetchObject($res)) {
            $cat = Title::makeTitle(NS_CATEGORY, $row->tfc_category);
            $wgOut->addHTML("<tr><td><a href='http://twitter.com/{$row->tws_username}' target='new'>{$row->tws_username}</a></td>");
            $wgOut->addHTML("<td><span id='pass_{$index}'>******* \n\t\t\t\t\t<a href='#' onclick='return showPass({$index}, \"{$row->tws_password}\");'>Show</a></span></td>");
            $wgOut->addHTML("<td><a href='{$cat->getFullURL()}' target='new'>{$cat->getText()}</td>");
            $wgOut->addHTML("<td style='text-align:right;'><a href='#' onclick='twtDelete(\"{$cat->getText()}\", \"{$row->tws_username}\");'>x</td></tr>");
            $index++;
        }
        $wgOut->addHTML("</table>");
        // set up a form to process new accounts
        $wgOut->addHTML(<<<END
\t\t\t<div style='border: 2px solid #eee; padding: 15px; margin-top: 50px;'>
\t\t\t<b>Add new account:</b><br/>
\t\t\t<form action='/Special:TwitterAccounts' method='POST'>
\t\t\t<table width='100%'>
\t\t\t\t<tr><td>Twitter Username:</td><td><input type='text' name='username'></td></tr>
\t\t\t\t<tr><td>Twitter Password:</td><td><input type='password' name='password'/></td></tr>
\t\t\t\t<tr><td>Category:</td><td><input type='text' name='category'> 
\t\t\t\t\t\t<!--<a href='#' onclick='return showCats();'>Search</a>-->
\t\t\t\t\t</td></tr>
\t\t\t</table><br/>
\t\t\t\t<i>Notes: <ul><li>The twitter account must already exist, this page does not create twitter accounts.</li>
\t\t\t\t<li> Category names are case sensitive.</li>
\t\t\t\t<li>You may have to authenticate and allow access for the wikihowfeeds application.</li>
\t\t\t\t<li>Be sure you don't accidentally use your own twitter account.</li>
\t\t\t\t</i><br/><br/>
\t\t\t\t<input type='submit' value='Add Account'/>
\t\t\t</form>\t
\t\t\t</div>
END
);
    }
Пример #4
0
 private function _check_login()
 {
     // Oauth token
     $token = $this->input->get('oauth_token');
     // Verifier token
     $verifier = $this->input->get('oauth_verifier');
     // Request access token
     if ($token && $verifier) {
         $accessToken = Twitter::oAuthAccessToken($token, $verifier);
         $this->set_db_accesstoken($accessToken);
     } else {
         $this->refreshTokens();
     }
 }
Пример #5
0
 public function getCallback()
 {
     $token = Input::get('oauth_token');
     $verifier = Input::get('oauth_verifier');
     $accessToken = Twitter::oAuthAccessToken($token, $verifier);
     if (isset($accessToken['user_id'])) {
         $user_id = $accessToken['user_id'];
         $user = User::find($user_id);
         if (empty($user)) {
             $user = new User();
             $user->id = $user_id;
         }
         Twitter::setOAuthToken($accessToken['oauth_token']);
         Twitter::setOAuthTokenSecret($accessToken['oauth_token_secret']);
         $timeline = Twitter::statusesUserTimeline($user->id);
         $user->screen_name = $accessToken['screen_name'];
         $user->profile_image_url = $timeline[0]['user']['profile_image_url'];
         $user->oauth_token = $accessToken['oauth_token'];
         $user->oauth_token_secret = $accessToken['oauth_token_secret'];
         $user->save();
         Auth::login($user);
         return Redirect::to('/');
         exit;
     } else {
         return Redirect::to('login')->with('message', 'Twitter認証できませんでした。');
         exit;
     }
 }
Пример #6
0
require_once 'twitter.php';
/* 
APPLICATION LEVEL DETAILS
Create new Twitter class instance with our 'consumer key' and 'consumer secret'
Find this on your Twitter app page. Example: http://screencast.com/t/a5s93L91V
*/
$twitter = new Twitter('2jSDrs6wyzxVyPKn4ex3LQ', 'vVXyzrcwPFDAQ8fxrgjgfkZ274QejvadOHKUp3MyNS0');
# !!
/*-------------------------------------------------------------------------------------------------
GET TOKEN / SECRET
-------------------------------------------------------------------------------------------------*/
// get a request token
$twitter->oAuthRequestToken('http://susanbuck.net/classes/inclass/exercises/twitter/authorize.php');
# !!
// authorize
if (!isset($_GET['oauth_token'])) {
    $twitter->oAuthAuthorize();
}
// get tokens
$response = $twitter->oAuthAccessToken($_GET['oauth_token'], $_GET['oauth_verifier']);
print_r($response);
?>

<title>Twitter API Authorize</title>

<br/><br/>
<a href='/classes/viewSource/?path=<?php 
echo $_SERVER['PHP_SELF'];
?>
' target='_blank'>View Source</a><br/><br/><br/>
<a href='http://classes.verkoyen.eu/modules/twitter_oauth/files/php_twitter_2_0_3.zip'>Download twitter.php (wrapper library)</a><br/><br/>