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')) {
35 * API analog to the profile settings page
36 * Only the parameters specified will be updated.
40 * @author Zach Copley <zach@status.net>
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42 * @link http://status.net/
44 class ApiAccountUpdateProfileAction extends ApiAuthAction
46 protected $needPost = true;
49 * Take arguments for running
51 * @param array $args $_REQUEST args
53 * @return boolean success flag
55 protected function prepare(array $args=array())
57 parent::prepare($args);
59 $this->user = $this->auth_user;
61 $this->name = $this->trimmed('name');
62 $this->url = $this->trimmed('url');
63 $this->location = $this->trimmed('location');
64 $this->description = $this->trimmed('description');
72 * See which request params have been set, and update the profile
76 protected function handle()
80 if (!in_array($this->format, array('xml', 'json'))) {
81 // TRANS: Client error displayed when coming across a non-supported API method.
82 $this->clientError(_('API method not found.'), 404);
85 if (empty($this->user)) {
86 // TRANS: Client error displayed if a user could not be found.
87 $this->clientError(_('No such user.'), 404);
90 $profile = $this->user->getProfile();
92 if (empty($profile)) {
93 // TRANS: Error message displayed when referring to a user without a profile.
94 $this->clientError(_('User has no profile.'));
97 $original = clone($profile);
99 if (!empty($this->name)) {
100 $profile->fullname = $this->name;
103 if (!empty($this->url)) {
104 $profile->homepage = $this->url;
107 if (!empty($this->description)) {
108 $profile->bio = $this->description;
111 if (!empty($this->location)) {
112 $profile->location = $this->location;
114 $loc = Location::fromName($this->location);
117 $profile->lat = $loc->lat;
118 $profile->lon = $loc->lon;
119 $profile->location_id = $loc->location_id;
120 $profile->location_ns = $loc->location_ns;
124 $result = $profile->update($original);
127 common_log_db_error($profile, 'UPDATE', __FILE__);
128 // TRANS: Server error displayed if a user profile could not be saved.
129 $this->serverError(_('Could not save profile.'));
132 $twitter_user = $this->twitterUserArray($profile, true);
134 if ($this->format == 'xml') {
135 $this->initDocument('xml');
136 $this->showTwitterXmlUser($twitter_user, 'user', true);
137 $this->endDocument('xml');
138 } elseif ($this->format == 'json') {
139 $this->initDocument('json');
140 $this->showJsonObjects($twitter_user);
141 $this->endDocument('json');