3 * StatusNet, the distributed open-source microblogging tool
5 * Update the authenticating user notification channels
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Siebrand Mazeland <s.mazeland@xs4all.nl>
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
36 * Sets which channel (device) StatusNet delivers updates to for
37 * the authenticating user. Sending none as the device parameter
38 * will disable IM and/or SMS updates.
42 * @author Zach Copley <zach@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
46 class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
49 * Take arguments for running
51 * @param array $args $_REQUEST args
53 * @return boolean success flag
55 function prepare($args)
57 parent::prepare($args);
59 $this->user = $this->auth_user;
60 $this->device = $this->trimmed('device');
68 * See which request params have been set, and update the user settings
70 * @param array $args $_REQUEST data (unused)
74 function handle($args)
76 parent::handle($args);
78 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
80 // TRANS: Client error message. POST is a HTTP command. It should not be translated.
81 _('This method requires a POST.'),
87 if (!in_array($this->format, array('xml', 'json'))) {
89 // TRANS: Client error displayed when coming across a non-supported API method.
90 _('API method not found.'),
97 // Note: Twitter no longer supports IM
99 if (!in_array(strtolower($this->device), array('sms', 'im', 'none'))) {
100 // TRANS: Client error displayed when no valid device parameter is provided for a user's delivery device setting.
101 $this->clientError(_( 'You must specify a parameter named ' .
102 '\'device\' with a value of one of: sms, im, none.' ));
106 if (empty($this->user)) {
107 // TRANS: Client error displayed when no existing user is provided for a user's delivery device setting.
108 $this->clientError(_('No such user.'), 404, $this->format);
112 $original = clone($this->user);
114 if (strtolower($this->device) == 'sms') {
115 $this->user->smsnotify = true;
116 } elseif (strtolower($this->device) == 'im') {
117 //TODO IM is pluginized now, so what should we do?
118 //Enable notifications for all IM plugins?
119 //For now, don't do anything
120 //$this->user->jabbernotify = true;
121 } elseif (strtolower($this->device == 'none')) {
122 $this->user->smsnotify = false;
123 //TODO IM is pluginized now, so what should we do?
124 //Disable notifications for all IM plugins?
125 //For now, don't do anything
126 //$this->user->jabbernotify = false;
129 $result = $this->user->update($original);
131 if ($result === false) {
132 common_log_db_error($this->user, 'UPDATE', __FILE__);
133 // TRANS: Server error displayed when a user's delivery device cannot be updated.
134 $this->serverError(_('Could not update user.'));
138 $profile = $this->user->getProfile();
140 $twitter_user = $this->twitterUserArray($profile, true);
142 // Note: this Twitter API method is retarded because it doesn't give
143 // any success/failure information. Twitter's docs claim that the
144 // notification field will change to reflect notification choice,
145 // but that's not true; notification> is used to indicate
146 // whether the auth user is following the user in question.
148 if ($this->format == 'xml') {
149 $this->initDocument('xml');
150 $this->showTwitterXmlUser($twitter_user, 'user', true);
151 $this->endDocument('xml');
152 } elseif ($this->format == 'json') {
153 $this->initDocument('json');
154 $this->showJsonObjects($twitter_user);
155 $this->endDocument('json');