3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/twitterapi.php');
24 class Twitapidirect_messagesAction extends TwitterapiAction {
27 function is_readonly() {
29 static $write_methods = array( 'direct_messages',
32 $cmdtext = explode('.', $this->arg('method'));
34 if (in_array($cmdtext[0], $write_methods)) {
41 function direct_messages($args, $apidata) {
42 parent::handle($args);
44 $user = $apidata['user'];
46 $count = $this->arg('count');
47 $since = $this->arg('since');
48 $since_id = $this->arg('since_id');
49 $page = $this->arg('page');
59 $message = new Message();
60 $message->to_profile = $user->id;
61 $message->orderBy('created DESC, id DESC');
62 $message->limit((($page-1)*20), $count);
66 switch($apidata['content-type']) {
68 $this->show_xml_direct_messages($message);
71 //$this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
74 //$this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
77 $this->show_json_direct_messages($message);
80 common_user_error(_('API method not found!'), $code = 404);
86 function sent($args, $apidata) {
87 parent::handle($args);
88 common_server_error(_('API method under construction.'), $code=501);
92 # had to change this from "new" to "create" to avoid PHP reserved word
93 function create($args, $apidata) {
94 parent::handle($args);
95 common_server_error(_('API method under construction.'), $code=501);
99 function destroy($args, $apidata) {
100 parent::handle($args);
101 common_server_error(_('API method under construction.'), $code=501);
105 function show_xml_direct_messages($message) {
107 $this->init_document('xml');
108 common_element_start('direct-messages', array('type' => 'array'));
110 if (is_array($messages)) {
111 foreach ($message as $m) {
112 $twitter_dm = $this->twitter_dm_array($m);
113 $this->show_twitter_xml_dm($twitter_dm);
116 while ($message->fetch()) {
117 $twitter_dm = $this->twitter_dm_array($message);
118 $this->show_twitter_xml_dm($twitter_dm);
122 common_element_end('direct-messages');
123 $this->end_document('xml');
126 function show_json_direct_messages($message) {
128 $this->init_document('json');
132 if (is_array($message)) {
133 foreach ($message as $m) {
134 $twitter_dm = $this->twitter_dm_array($m);
135 array_push($dmsgs, $twitter_dm);
138 while ($message->fetch()) {
139 $twitter_dm = $this->twitter_dm_array($message);
140 array_push($dmsgs, $twitter_dm);
144 $this->show_twitter_json_dmsgs($dmsgs);
146 $this->end_document('json');