123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiAccountUpdateProfileAction extends ApiAuthAction
- {
- protected $needPost = true;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->user = $this->auth_user;
- $this->name = $this->trimmed('name');
- $this->url = $this->trimmed('url');
- $this->location = $this->trimmed('location');
- $this->description = $this->trimmed('description');
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (!in_array($this->format, array('xml', 'json'))) {
-
- $this->clientError(_('API method not found.'), 404);
- }
- if (empty($this->user)) {
-
- $this->clientError(_('No such user.'), 404);
- }
- $profile = $this->user->getProfile();
- if (empty($profile)) {
-
- $this->clientError(_('User has no profile.'));
- }
- $original = clone($profile);
- $profile->fullname = $this->name;
- $profile->homepage = $this->url;
- $profile->bio = $this->description;
- $profile->location = $this->location;
- if (!empty($this->location)) {
- $loc = Location::fromName($this->location);
- if (!empty($loc)) {
- $profile->lat = $loc->lat;
- $profile->lon = $loc->lon;
- $profile->location_id = $loc->location_id;
- $profile->location_ns = $loc->location_ns;
- }
- } else {
-
- $profile->lat = '';
- $profile->lon = '';
- $profile->location_id = '';
- $profile->location_ns = '';
- }
- $result = $profile->update($original);
- if (!$result) {
- common_log_db_error($profile, 'UPDATE', __FILE__);
-
- $this->serverError(_('Could not save profile.'));
- }
- $twitter_user = $this->twitterUserArray($profile, true);
- if ($this->format == 'xml') {
- $this->initDocument('xml');
- $this->showTwitterXmlUser($twitter_user, 'user', true);
- $this->endDocument('xml');
- } elseif ($this->format == 'json') {
- $this->initDocument('json');
- $this->showJsonObjects($twitter_user);
- $this->endDocument('json');
- }
- }
- }
|