예제 #1
0
 /**
  * Handle the request
  *
  * Show the user's groups
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $sitename = common_config('site', 'name');
     // TRANS: Used as title in check for group membership. %s is a user name.
     $title = sprintf(_("%s's groups"), $this->target->nickname);
     $taguribase = TagURI::base();
     $id = "tag:{$taguribase}:Groups";
     $link = common_local_url('usergroups', array('nickname' => $this->target->nickname));
     $subtitle = sprintf(_('%1$s groups %2$s is a member of.'), $sitename, $this->target->nickname);
     switch ($this->format) {
         case 'xml':
             $this->showXmlGroups($this->groups);
             break;
         case 'rss':
             $this->showRssGroups($this->groups, $title, $link, $subtitle);
             break;
         case 'atom':
             $selfuri = common_local_url('ApiGroupList', array('id' => $this->target->id, 'format' => 'atom'));
             $this->showAtomGroups($this->groups, $title, $id, $link, $subtitle, $selfuri);
             break;
         case 'json':
             $this->showJsonGroups($this->groups);
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
     }
 }
예제 #2
0
 /**
  * Handle the request
  *
  * Show the user's groups
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $sitename = common_config('site', 'name');
     // TRANS: Used as title in check for group membership. %s is a user name.
     $title = sprintf(_("%s's groups"), $this->user->nickname);
     $taguribase = TagURI::base();
     $id = "tag:{$taguribase}:Groups";
     $link = common_local_url('usergroups', array('nickname' => $this->user->nickname));
     $subtitle = sprintf(_('%1$s groups %2$s is a member of.'), $sitename, $this->user->nickname);
     switch ($this->format) {
         case 'xml':
             $this->showXmlGroups($this->groups);
             break;
         case 'rss':
             $this->showRssGroups($this->groups, $title, $link, $subtitle);
             break;
         case 'atom':
             $selfuri = common_root_url() . 'api/statusnet/groups/list/' . $this->user->id . '.atom';
             $this->showAtomGroups($this->groups, $title, $id, $link, $subtitle, $selfuri);
             break;
         case 'json':
             $this->showJsonGroups($this->groups);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
예제 #3
0
 /**
  * Handle the arguments. In our case, show a service document.
  *
  * @param Array $args unused.
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     header('Content-Type: application/atomsvc+xml');
     $this->startXML();
     $this->elementStart('service', array('xmlns' => 'http://www.w3.org/2007/app', 'xmlns:atom' => 'http://www.w3.org/2005/Atom', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/'));
     $this->elementStart('workspace');
     // TRANS: Title for Atom feed.
     $this->element('atom:title', null, _m('ATOM', 'Main'));
     $this->elementStart('collection', array('href' => common_local_url('ApiTimelineUser', array('id' => $this->user->id, 'format' => 'atom'))));
     $this->element('atom:title', null, sprintf(_("%s timeline"), $this->user->nickname));
     $this->element('accept', null, 'application/atom+xml;type=entry');
     $this->element('activity:verb', null, ActivityVerb::POST);
     $this->elementEnd('collection');
     $this->elementStart('collection', array('href' => common_local_url('AtomPubSubscriptionFeed', array('subscriber' => $this->user->id))));
     $this->element('atom:title', null, sprintf(_("%s subscriptions"), $this->user->nickname));
     $this->element('accept', null, 'application/atom+xml;type=entry');
     $this->element('activity:verb', null, ActivityVerb::FOLLOW);
     $this->elementEnd('collection');
     $this->elementStart('collection', array('href' => common_local_url('AtomPubFavoriteFeed', array('profile' => $this->user->id))));
     $this->element('atom:title', null, sprintf(_("%s favorites"), $this->user->nickname));
     $this->element('accept', null, 'application/atom+xml;type=entry');
     $this->element('activity:verb', null, ActivityVerb::FAVORITE);
     $this->elementEnd('collection');
     $this->elementStart('collection', array('href' => common_local_url('AtomPubMembershipFeed', array('profile' => $this->user->id))));
     $this->element('atom:title', null, sprintf(_("%s memberships"), $this->user->nickname));
     $this->element('accept', null, 'application/atom+xml;type=entry');
     $this->element('activity:verb', null, ActivityVerb::JOIN);
     $this->elementEnd('collection');
     $this->elementEnd('workspace');
     $this->elementEnd('service');
     $this->endXML();
 }
예제 #4
0
 /**
  * Handle the request
  *
  * Show the profiles
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $this->initDocument('json');
     print json_encode($this->showProfiles());
     $this->endDocument('json');
 }
예제 #5
0
 /**
  * Handle the request
  *
  * Save the new message
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (empty($this->user)) {
         // TRANS: Client error displayed when checking group membership for a non-existing user.
         $this->clientError(_('No such user.'), 404, $this->format);
         return;
     }
     if (empty($this->group)) {
         // TRANS: Client error displayed when checking group membership for a non-existing group.
         $this->clientError(_('Group not found.'), 404, $this->format);
         return false;
     }
     $is_member = $this->user->isMember($this->group);
     switch ($this->format) {
         case 'xml':
             $this->initDocument('xml');
             $this->element('is_member', null, $is_member);
             $this->endDocument('xml');
             break;
         case 'json':
             $this->initDocument('json');
             $this->showJsonObjects(array('is_member' => $is_member));
             $this->endDocument('json');
             break;
         default:
             $this->clientError(_('API method not found.'), 400, $this->format);
             break;
     }
 }
예제 #6
0
 /**
  * Handle the request
  *
  * Save the new message
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if (empty($this->target)) {
         // TRANS: Client error displayed when checking group membership for a non-existing user.
         $this->clientError(_('No such user.'), 404);
     }
     if (empty($this->group)) {
         // TRANS: Client error displayed when checking group membership for a non-existing group.
         $this->clientError(_('Group not found.'), 404);
     }
     $is_member = $this->target->isMember($this->group);
     switch ($this->format) {
         case 'xml':
             $this->initDocument('xml');
             $this->element('is_member', null, $is_member);
             $this->endDocument('xml');
             break;
         case 'json':
             $this->initDocument('json');
             $this->showJsonObjects(array('is_member' => $is_member));
             $this->endDocument('json');
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'));
     }
 }
예제 #7
0
 protected function handle()
 {
     parent::handle();
     if ($this->delete) {
         return $this->handleDelete();
     }
     if ($this->create) {
         return $this->handlePost();
     }
     switch ($this->format) {
         case 'xml':
             $this->initDocument('xml');
             $this->elementStart('users_list', array('xmlns:statusnet' => 'http://status.net/schema/api/1/'));
             $this->elementStart('users', array('type' => 'array'));
             if (is_array($this->users)) {
                 foreach ($this->users as $u) {
                     $twitter_user = $this->twitterUserArray($u, true);
                     $this->showTwitterXmlUser($twitter_user);
                 }
             } else {
                 while ($this->users->fetch()) {
                     $twitter_user = $this->twitterUserArray($this->users, true);
                     $this->showTwitterXmlUser($twitter_user);
                 }
             }
             $this->elementEnd('users');
             $this->element('next_cursor', null, $this->next_cursor);
             $this->element('previous_cursor', null, $this->prev_cursor);
             $this->elementEnd('users_list');
             break;
         case 'json':
             $this->initDocument('json');
             $users = array();
             if (is_array($this->users)) {
                 foreach ($this->users as $u) {
                     $twitter_user = $this->twitterUserArray($u, true);
                     array_push($users, $twitter_user);
                 }
             } else {
                 while ($this->users->fetch()) {
                     $twitter_user = $this->twitterUserArray($this->users, true);
                     array_push($users, $twitter_user);
                 }
             }
             $users_list = array('users' => $users, 'next_cursor' => $this->next_cursor, 'next_cursor_str' => strval($this->next_cursor), 'previous_cursor' => $this->prev_cursor, 'previous_cursor_str' => strval($this->prev_cursor));
             $this->showJsonObjects($users_list);
             $this->endDocument('json');
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
 /**
  * Handle the request
  *
  * Show the lists
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     switch ($this->format) {
         case 'xml':
             $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         case 'json':
             $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'));
     }
 }
예제 #9
0
 /**
  * Handle the request
  *
  * Show the lists
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     switch ($this->format) {
         case 'xml':
             $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         case 'json':
             $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         default:
             $this->clientError(_('API method not found.'), 400, $this->format);
             break;
     }
 }
예제 #10
0
 /**
  * Handle the request
  *
  * Show the lists
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (empty($this->user)) {
         // TRANS: Client error displayed trying to perform an action related to a non-existing user.
         $this->clientError(_('No such user.'), 404, $this->format);
         return;
     }
     switch ($this->format) {
         case 'xml':
             $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         case 'json':
             $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         default:
             $this->clientError(_('API method not found.'), 400, $this->format);
             break;
     }
 }
예제 #11
0
 function handle($args)
 {
     parent::handle($args);
     $arr = array('profile_tag_id' => $this->list->id, 'profile_id' => $this->user->id);
     $sub = Profile_tag_subscription::pkeyGet($arr);
     if (empty($sub)) {
         $this->clientError(_('The specified user is not a subscriber of this list.'), 400, $this->format);
     }
     $user = $this->twitterUserArray($this->user->getProfile(), true);
     switch ($this->format) {
         case 'xml':
             $this->showTwitterXmlUser($user, 'user', true);
             break;
         case 'json':
             $this->showSingleJsonUser($user);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
 /**
  * Handle the request
  *
  * Return some Twitter-ish data about API limits
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
     }
     $reset = new DateTime();
     $reset->modify('+1 hour');
     $this->initDocument($this->format);
     if ($this->format == 'xml') {
         $this->elementStart('hash');
         $this->element('remaining-hits', array('type' => 'integer'), 150);
         $this->element('hourly-limit', array('type' => 'integer'), 150);
         $this->element('reset-time', array('type' => 'datetime'), common_date_iso8601($reset->format('r')));
         $this->element('reset_time_in_seconds', array('type' => 'integer'), strtotime('+1 hour'));
         $this->elementEnd('hash');
     } elseif ($this->format == 'json') {
         $out = array('reset_time_in_seconds' => strtotime('+1 hour'), 'remaining_hits' => 150, 'hourly_limit' => 150, 'reset_time' => common_date_rfc2822($reset->format('r')));
         print json_encode($out);
     }
     $this->endDocument($this->format);
 }
예제 #13
0
 function handle($args)
 {
     parent::handle($args);
     $arr = array('profile_tag_id' => $this->list->id, 'profile_id' => $this->target->id);
     $sub = Profile_tag_subscription::pkeyGet($arr);
     if (empty($sub)) {
         // TRANS: Client error displayed when a membership check for a user is nagative.
         $this->clientError(_('The specified user is not a subscriber of this list.'));
     }
     $user = $this->twitterUserArray($this->target, true);
     switch ($this->format) {
         case 'xml':
             $this->showTwitterXmlUser($user, 'user', true);
             break;
         case 'json':
             $this->showSingleJsonUser($user);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
예제 #14
0
 /**
  * Handle the request
  *
  * @return boolean success flag
  */
 function handle($args)
 {
     parent::handle($args);
     $arr = array('tagger' => $this->list->tagger, 'tag' => $this->list->tag, 'tagged' => $this->user->id);
     $ptag = Profile_tag::pkeyGet($arr);
     if (empty($ptag)) {
         $this->clientError(_('The specified user is not a member of this list.'), 400, $this->format);
     }
     $user = $this->twitterUserArray($this->user->getProfile(), true);
     switch ($this->format) {
         case 'xml':
             $this->showTwitterXmlUser($user, 'user', true);
             break;
         case 'json':
             $this->showSingleJsonUser($user);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
     return true;
 }
예제 #15
0
 /**
  * Handle the request
  *
  * @return boolean success flag
  */
 protected function handle()
 {
     parent::handle();
     $arr = array('tagger' => $this->list->tagger, 'tag' => $this->list->tag, 'tagged' => $this->target->id);
     $ptag = Profile_tag::pkeyGet($arr);
     if (empty($ptag)) {
         // TRANS: Client error displayed when referring to a non-list member.
         $this->clientError(_('The specified user is not a member of this list.'));
     }
     $user = $this->twitterUserArray($this->target, true);
     switch ($this->format) {
         case 'xml':
             $this->showTwitterXmlUser($user, 'user', true);
             break;
         case 'json':
             $this->showSingleJsonUser($user);
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
     }
     return true;
 }
 /**
  * Handle the request
  *
  * Just show the notices
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $this->showTimeline();
 }
예제 #17
0
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!in_array($this->format, array('xml', 'json'))) {
         // TRANS: Client error displayed trying to execute an unknown API method showing friendship.
         $this->clientError(_('API method not found.'), 404);
         return;
     }
     if (empty($this->source)) {
         $this->clientError(_('Could not determine source user.'), 404);
         return;
     }
     if (empty($this->target)) {
         $this->clientError(_('Could not find target user.'), 404);
         return;
     }
     $result = $this->twitterRelationshipArray($this->source, $this->target);
     switch ($this->format) {
         case 'xml':
             $this->initDocument('xml');
             $this->showTwitterXmlRelationship($result[relationship]);
             $this->endDocument('xml');
             break;
         case 'json':
             $this->initDocument('json');
             print json_encode($result);
             $this->endDocument('json');
             break;
         default:
             break;
     }
 }
 /**
  * Handle the request
  *
  * Just show the notices
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $this->showTimeline();
 }
예제 #19
0
 /**
  * Handle the request
  *
  * Just show the notices
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if ($this->isPost()) {
         $this->handlePost();
     } else {
         $this->showTimeline();
     }
 }
예제 #20
0
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if (!in_array($this->format, array('xml', 'json'))) {
         // TRANS: Client error displayed when coming across a non-supported API method.
         $this->clientError(_('API method not found.'), 404);
     }
     if (empty($this->source)) {
         $this->clientError(_('Could not determine source user.'), 404);
     }
     if (empty($this->target)) {
         $this->clientError(_('Could not find target user.'), 404);
     }
     $result = $this->twitterRelationshipArray($this->source, $this->target);
     switch ($this->format) {
         case 'xml':
             $this->initDocument('xml');
             $this->showTwitterXmlRelationship($result[relationship]);
             $this->endDocument('xml');
             break;
         case 'json':
             $this->initDocument('json');
             print json_encode($result);
             $this->endDocument('json');
             break;
         default:
             break;
     }
 }
예제 #21
0
 /**
  * require authentication if it is a write action or user is ambiguous
  *
  */
 function requiresAuth()
 {
     return parent::requiresAuth() || $this->create || $this->delete;
 }
예제 #22
0
 /**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $this->initDocument('json');
     $this->showJsonObjects(array('users' => $this->users_stripped, 'groups' => $this->groups_stripped, 'blocks' => $this->blocks));
     $this->endDocument('json');
 }
예제 #23
0
 /**
  * Handle the request
  *
  * Show the profiles
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if (!in_array($this->format, array('xml', 'json'))) {
         // TRANS: Client error displayed when coming across a non-supported API method.
         $this->clientError(_('API method not found.'), 404);
     }
     $this->initDocument($this->format);
     if (isset($this->ids_only)) {
         $this->showIds();
     } else {
         $this->showProfiles(isset($this->lite) ? false : true);
     }
     $this->endDocument($this->format);
 }
예제 #24
0
 /**
  * Handle the request
  *
  * Show the profiles
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), $code = 404);
         return;
     }
     $this->initDocument($this->format);
     if (isset($this->ids_only)) {
         $this->showIds();
     } else {
         $this->showProfiles(isset($this->lite) ? false : true);
     }
     $this->endDocument($this->format);
 }
예제 #25
0
 /**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $this->initDocument('json');
     $this->showJsonObjects($this->users_stripped);
     $this->endDocument('json');
 }
 /**
  * Handle the request
  *
  * Just show the notices
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $this->showJsonTimeline($this->notices);
 }
예제 #27
0
 /**
  * Handle request:
  *     Show the lists the user has created if the request method is GET
  *     Create a new list by diferring to handlePost() if it is POST.
  */
 protected function handle()
 {
     parent::handle();
     if ($this->create) {
         return $this->handlePost();
     }
     switch ($this->format) {
         case 'xml':
             $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         case 'json':
             $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }