]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapiaccount.php
Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into...
[quix0rs-gnu-social.git] / actions / twitapiaccount.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/twitterapi.php');
23
24 class TwitapiaccountAction extends TwitterapiAction
25 {
26     function verify_credentials($args, $apidata)
27     {
28         parent::handle($args);
29
30         switch ($apidata['content-type']) {
31         case 'xml':
32         case 'json':
33             $action_obj = new TwitapiusersAction();
34             $action_obj->prepare($args);
35             call_user_func(array($action_obj, 'show'), $args, $apidata);
36             break;
37         default:
38             header('Content-Type: text/html; charset=utf-8');
39             print 'Authorized';
40         }
41     }
42
43    function end_session($args, $apidata)
44     {
45         parent::handle($args);
46         $this->serverError(_('API method under construction.'), $code=501);
47     }
48
49     function update_location($args, $apidata)
50     {
51         parent::handle($args);
52
53         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
54             $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']);
55             return;
56         }
57
58         $location = trim($this->arg('location'));
59
60         if (!is_null($location) && mb_strlen($location) > 255) {
61
62             // XXX: But Twitter just truncates and runs with it. -- Zach
63             $this->clientError(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']);
64             return;
65         }
66
67         $user = $apidata['user'];
68         $profile = $user->getProfile();
69
70         if (!$profile) {
71             $this->serverError(_('User has no profile.'));
72             return;
73         }
74
75         $orig_profile = clone($profile);
76         $profile->location = $location;
77
78         $result = $profile->update($orig_profile);
79
80         if (!$result) {
81             common_log_db_error($profile, 'UPDATE', __FILE__);
82             $this->serverError(_('Couldn\'t save profile.'));
83             return;
84         }
85
86         common_broadcast_profile($profile);
87         $type = $apidata['content-type'];
88
89         $this->init_document($type);
90         $this->show_profile($profile, $type);
91         $this->end_document($type);
92     }
93
94
95     function update_delivery_device($args, $apidata)
96     {
97         parent::handle($args);
98         $this->serverError(_('API method under construction.'), $code=501);
99     }
100
101     // We don't have a rate limit, but some clients check this method.
102     // It always returns the same thing: 100 hit left.
103     function rate_limit_status($args, $apidata)
104     {
105         parent::handle($args);
106
107         $type = $apidata['content-type'];
108         $this->init_document($type);
109
110         if ($apidata['content-type'] == 'xml') {
111             $this->elementStart('hash');
112             $this->element('remaining-hits', array('type' => 'integer'), 100);
113             $this->element('hourly-limit', array('type' => 'integer'), 100);
114             $this->element('reset-time', array('type' => 'datetime'), null);
115             $this->element('reset_time_in_seconds', array('type' => 'integer'), 0);
116             $this->elementEnd('hash');
117         } elseif ($apidata['content-type'] == 'json') {
118
119             $out = array('reset_time_in_seconds' => 0,
120                          'remaining_hits' => 100,
121                          'hourly_limit' => 100,
122                          'reset_time' => '');
123             print json_encode($out);
124         }
125
126         $this->end_document($type);
127     }
128 }