4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2010, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
23 require_once INSTALLDIR . '/extlib/OAuth.php';
25 $shortoptions = 'o:s:u:';
26 $longoptions = array('oauth_token=', 'token_secret=', 'update=');
28 $helptext = <<<END_OF_VERIFY_HELP
29 statusupdate.php [options]
30 Update your status using OAuth
32 -o --oauth_token access token
33 -s --token_secret access token secret
34 -u --update status update
43 require_once INSTALLDIR . '/scripts/commandline.inc';
45 if (have_option('o', 'oauth_token')) {
46 $token = get_option_value('oauth_token');
49 if (have_option('s', 'token_secret')) {
50 $token_secret = get_option_value('s', 'token_secret');
53 if (have_option('u', 'update')) {
54 $update = get_option_value('u', 'update');
58 print "Please specify an access token.\n";
62 if (empty($token_secret)) {
63 print "Please specify an access token secret.\n";
68 print "You forgot to update your status!\n";
72 $ini = parse_ini_file("oauth.ini");
74 $test_consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
76 $endpoint = $ini['apiroot'] . '/statuses/update.xml';
80 $at = new OAuthToken($token, $token_secret);
82 $parsed = parse_url($endpoint);
84 parse_str($parsed['query'], $params);
86 $params['status'] = $update;
88 $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
90 $req_req = OAuthRequest::from_consumer_and_token($test_consumer, $at, 'POST', $endpoint, $params);
91 $req_req->sign_request($hmac_method, $test_consumer, $at);
93 $r = httpRequest($req_req->to_url());
95 $body = $r->getBody();
99 //print $req_req->to_url() . "\n\n";
101 function httpRequest($url)
103 $request = HTTPClient::start();
105 $request->setConfig(array(
106 'follow_redirects' => true,
107 'connect_timeout' => 120,
109 'ssl_verify_peer' => false,
110 'ssl_verify_host' => false
113 return $request->post($url);