123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiAccountUpdateProfileImageAction extends ApiAuthAction
- {
- protected $needPost = true;
-
- protected function handle()
- {
- parent::handle();
-
-
- if (empty($_FILES)
- && empty($_POST)
- && ($_SERVER['CONTENT_LENGTH'] > 0)
- ) {
-
-
- $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
- 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
- intval($_SERVER['CONTENT_LENGTH']));
- $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
- }
- if (empty($this->user)) {
-
- $this->clientError(_('No such user.'), 404);
- }
- try {
- $imagefile = ImageFile::fromUpload('image');
- } catch (Exception $e) {
- $this->clientError($e->getMessage());
- }
- $type = $imagefile->preferredType();
- $filename = Avatar::filename(
- $user->id,
- image_type_to_extension($type),
- null,
- 'tmp'.common_timestamp()
- );
- $filepath = Avatar::path($filename);
- $imagefile->copyTo($filepath);
- $profile = $this->user->getProfile();
- $profile->setOriginal($filename);
- $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');
- }
- }
- }
|