123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiFriendshipsCreateAction extends ApiAuthAction
- {
- protected $needPost = true;
- var $other = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->other = $this->getTargetProfile($this->arg('id'));
- 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->other)) {
-
- $this->clientError(_('Could not follow user: profile not found.'), 403);
- }
- if ($this->scoped->isSubscribed($this->other)) {
- $errmsg = sprintf(
-
-
- _('Could not follow user: %s is already on your list.'),
- $this->other->nickname
- );
- $this->clientError($errmsg, 403);
- }
- try {
- Subscription::start($this->scoped, $this->other);
- } catch (AlreadyFulfilledException $e) {
- $this->clientError($e->getMessage(), 409);
- }
- $this->initDocument($this->format);
- $this->showProfile($this->other, $this->format);
- $this->endDocument($this->format);
- }
- }
|