3 * StatusNet, the distributed open-source microblogging tool
5 * Update the authenticating user's profile
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 Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/lib/apiauth.php';
37 * API analog to the profile settings page
38 * Only the parameters specified will be updated.
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/
47 class ApiAccountUpdateProfileAction extends ApiAuthAction
51 * Take arguments for running
53 * @param array $args $_REQUEST args
55 * @return boolean success flag
59 function prepare($args)
61 parent::prepare($args);
63 $this->user = $this->auth_user;
65 $this->name = $this->trimmed('name');
66 $this->url = $this->trimmed('url');
67 $this->location = $this->trimmed('location');
68 $this->description = $this->trimmed('description');
76 * See which request params have been set, and update the profile
78 * @param array $args $_REQUEST data (unused)
83 function handle($args)
85 parent::handle($args);
87 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
89 // TRANS: Client error. POST is a HTTP command. It should not be translated.
90 _('This method requires a POST.'),
96 if (!in_array($this->format, array('xml', 'json'))) {
98 _('API method not found.'),
105 if (empty($this->user)) {
106 $this->clientError(_('No such user.'), 404, $this->format);
110 $profile = $this->user->getProfile();
112 if (empty($profile)) {
113 $this->clientError(_('User has no profile.'));
117 $original = clone($profile);
119 if (!empty($this->name)) {
120 $profile->fullname = $this->name;
123 if (!empty($this->url)) {
124 $profile->homepage = $this->url;
127 if (!empty($this->description)) {
128 $profile->bio = $this->description;
131 if (!empty($this->location)) {
132 $profile->location = $this->location;
134 $loc = Location::fromName($location);
137 $profile->lat = $loc->lat;
138 $profile->lon = $loc->lon;
139 $profile->location_id = $loc->location_id;
140 $profile->location_ns = $loc->location_ns;
144 $result = $profile->update($original);
147 common_log_db_error($profile, 'UPDATE', __FILE__);
148 $this->serverError(_('Could not save profile.'));
152 common_broadcast_profile($profile);
154 $twitter_user = $this->twitterUserArray($profile, true);
156 if ($this->format == 'xml') {
157 $this->initDocument('xml');
158 $this->showTwitterXmlUser($twitter_user);
159 $this->endDocument('xml');
160 } elseif ($this->format == 'json') {
161 $this->initDocument('json');
162 $this->showJsonObjects($twitter_user);
163 $this->endDocument('json');