예제 #1
0
 function timeline($args, $apidata)
 {
     parent::handle($args);
     common_debug("in tags api action");
     $this->auth_user = $apidata['user'];
     $tag = $apidata['api_arg'];
     if (empty($tag)) {
         $this->clientError('Not Found', 404, $apidata['content-type']);
         return;
     }
     $sitename = common_config('site', 'name');
     $title = sprintf(_("Notices tagged with %s"), $tag);
     $taguribase = common_config('integration', 'taguri');
     $id = "tag:{$taguribase}:TagTimeline:" . $tag;
     $link = common_local_url('tag', array('tag' => $tag));
     $subtitle = sprintf(_('Updates tagged with %1$s on %2$s!'), $tag, $sitename);
     $page = (int) $this->arg('page', 1);
     $count = (int) $this->arg('count', 20);
     $max_id = (int) $this->arg('max_id', 0);
     $since_id = (int) $this->arg('since_id', 0);
     $since = $this->arg('since');
     # XXX: support max_id, since_id, and since arguments
     $notice = Notice_tag::getStream($tag, ($page - 1) * $count, $count + 1);
     switch ($apidata['content-type']) {
         case 'xml':
             $this->show_xml_timeline($notice);
             break;
         case 'rss':
             $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink);
             break;
         case 'atom':
             if (isset($apidata['api_arg'])) {
                 $selfuri = common_root_url() . 'api/laconica/tags/timeline/' . $apidata['api_arg'] . '.atom';
             } else {
                 $selfuri = common_root_url() . 'api/laconica/tags/timeline.atom';
             }
             $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri);
             break;
         case 'json':
             $this->show_json_timeline($notice);
             break;
         default:
             $this->clientError(_('API method not found!'), $code = 404);
     }
 }
예제 #2
0
 function rate_limit_status($args, $apidata)
 {
     parent::handle($args);
     $type = $apidata['content-type'];
     $this->init_document($type);
     if ($apidata['content-type'] == 'xml') {
         $this->elementStart('hash');
         $this->element('remaining-hits', array('type' => 'integer'), 100);
         $this->element('hourly-limit', array('type' => 'integer'), 100);
         $this->element('reset-time', array('type' => 'datetime'), null);
         $this->element('reset_time_in_seconds', array('type' => 'integer'), 0);
         $this->elementEnd('hash');
     } elseif ($apidata['content-type'] == 'json') {
         $out = array('reset_time_in_seconds' => 0, 'remaining_hits' => 100, 'hourly_limit' => 100, 'reset_time' => '');
         print json_encode($out);
     }
     $this->end_document($type);
 }
예제 #3
0
 function destroy($args, $apidata)
 {
     parent::handle($args);
     $blockee = $this->get_user($apidata['api_arg'], $apidata);
     if (!$blockee) {
         $this->clientError('Not Found', 404, $apidata['content-type']);
         return;
     }
     $user = $apidata['user'];
     if (!$user->hasBlocked($blockee) || $user->unblock($blockee)) {
         $type = $apidata['content-type'];
         $this->init_document($type);
         $this->show_profile($blockee, $type);
         $this->end_document($type);
     } else {
         $this->serverError(_('Unblock user failed.'));
     }
 }
예제 #4
0
 function timeline($args, $apidata)
 {
     parent::handle($args);
     common_debug("in groups api action");
     $this->auth_user = $apidata['user'];
     $group = $this->get_group($apidata['api_arg'], $apidata);
     if (empty($group)) {
         $this->clientError('Not Found', 404, $apidata['content-type']);
         return;
     }
     $sitename = common_config('site', 'name');
     $title = sprintf(_("%s timeline"), $group->nickname);
     $taguribase = common_config('integration', 'taguri');
     $id = "tag:{$taguribase}:GroupTimeline:" . $group->id;
     $link = common_local_url('showgroup', array('nickname' => $group->nickname));
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $group->nickname, $sitename);
     $page = (int) $this->arg('page', 1);
     $count = (int) $this->arg('count', 20);
     $max_id = (int) $this->arg('max_id', 0);
     $since_id = (int) $this->arg('since_id', 0);
     $since = $this->arg('since');
     $notice = $group->getNotices(($page - 1) * $count, $count, $since_id, $max_id, $since);
     switch ($apidata['content-type']) {
         case 'xml':
             $this->show_xml_timeline($notice);
             break;
         case 'rss':
             $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink);
             break;
         case 'atom':
             if (isset($apidata['api_arg'])) {
                 $selfuri = common_root_url() . 'api/laconica/groups/timeline/' . $apidata['api_arg'] . '.atom';
             } else {
                 $selfuri = common_root_url() . 'api/laconica/groups/timeline.atom';
             }
             $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri);
             break;
         case 'json':
             $this->show_json_timeline($notice);
             break;
         default:
             $this->clientError(_('API method not found!'), $code = 404);
     }
 }
예제 #5
0
 /**
  * Handle a request
  *
  * @param array $args Arguments from $_REQUEST
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $this->showTrends();
 }
예제 #6
0
 function show($args, $apidata)
 {
     parent::handle($args);
     if (!in_array($apidata['content-type'], array('xml', 'json'))) {
         $this->clientError(_('API method not found!'), $code = 404);
         return;
     }
     $user = null;
     $email = $this->arg('email');
     $user_id = $this->arg('user_id');
     if ($email) {
         $user = User::staticGet('email', $email);
     } elseif ($user_id) {
         $user = $this->get_user($user_id);
     } elseif (isset($apidata['api_arg'])) {
         $user = $this->get_user($apidata['api_arg']);
     } elseif (isset($apidata['user'])) {
         $user = $apidata['user'];
     }
     if (!$user) {
         // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
         $this->client_error(_('Not found.'), 404, $apidata['content-type']);
         return;
     }
     $profile = $user->getProfile();
     if (!$profile) {
         common_server_error(_('User has no profile.'));
         return;
     }
     $twitter_user = $this->twitter_user_array($profile, true);
     // Add in extended user fields offered up by this method
     $twitter_user['created_at'] = $this->date_twitter($profile->created);
     $subbed = DB_DataObject::factory('subscription');
     $subbed->subscriber = $profile->id;
     $subbed_count = (int) $subbed->count() - 1;
     $notices = DB_DataObject::factory('notice');
     $notices->profile_id = $profile->id;
     $notice_count = (int) $notices->count();
     $twitter_user['friends_count'] = is_int($subbed_count) ? $subbed_count : 0;
     $twitter_user['statuses_count'] = is_int($notice_count) ? $notice_count : 0;
     // Other fields Twitter sends...
     $twitter_user['profile_background_color'] = '';
     $twitter_user['profile_background_image_url'] = '';
     $twitter_user['profile_text_color'] = '';
     $twitter_user['profile_link_color'] = '';
     $twitter_user['profile_sidebar_fill_color'] = '';
     $twitter_user['profile_sidebar_border_color'] = '';
     $twitter_user['profile_background_tile'] = 'false';
     $faves = DB_DataObject::factory('fave');
     $faves->user_id = $user->id;
     $faves_count = (int) $faves->count();
     $twitter_user['favourites_count'] = $faves_count;
     $timezone = 'UTC';
     if ($user->timezone) {
         $timezone = $user->timezone;
     }
     $t = new DateTime();
     $t->setTimezone(new DateTimeZone($timezone));
     $twitter_user['utc_offset'] = $t->format('Z');
     $twitter_user['time_zone'] = $timezone;
     if (isset($apidata['user'])) {
         if ($apidata['user']->isSubscribed($profile)) {
             $twitter_user['following'] = 'true';
         } else {
             $twitter_user['following'] = 'false';
         }
         // Notifications on?
         $sub = Subscription::pkeyGet(array('subscriber' => $apidata['user']->id, 'subscribed' => $profile->id));
         if ($sub) {
             if ($sub->jabber || $sub->sms) {
                 $twitter_user['notifications'] = 'true';
             } else {
                 $twitter_user['notifications'] = 'false';
             }
         }
     }
     if ($apidata['content-type'] == 'xml') {
         $this->init_document('xml');
         $this->show_twitter_xml_user($twitter_user);
         $this->end_document('xml');
     } elseif ($apidata['content-type'] == 'json') {
         $this->init_document('json');
         $this->show_json_objects($twitter_user);
         $this->end_document('json');
     } else {
         // This is in case 'show' was called via /account/verify_credentials
         // without a format (xml or json).
         header('Content-Type: text/html; charset=utf-8');
         print 'Authorized';
     }
 }
예제 #7
0
 /**
  * Handle a request
  *
  * @param array $args Arguments from $_REQUEST
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $this->showAtom();
 }
예제 #8
0
 /**
  * WADL description of the API
  *
  * Gives a WADL description of the API provided by this version of the
  * software.
  *
  * @param array $args    Web arguments
  * @param array $apidata Twitter API data
  *
  * @return void
  *
  * @see ApiAction::process_command()
  */
 function wadl($args, $apidata)
 {
     parent::handle($args);
     $this->serverError(_('API method under construction.'), 501);
 }
예제 #9
0
 function downtime_schedule($args, $apidata)
 {
     parent::handle($args);
     $this->serverError(_('API method under construction.'), $code = 501);
 }
예제 #10
0
 function exists($args, $apidata)
 {
     parent::handle($args);
     if (!in_array($apidata['content-type'], array('xml', 'json'))) {
         $this->clientError(_('API method not found!'), $code = 404);
         return;
     }
     $user_a_id = $this->trimmed('user_a');
     $user_b_id = $this->trimmed('user_b');
     $user_a = $this->get_user($user_a_id);
     $user_b = $this->get_user($user_b_id);
     if (!$user_a || !$user_b) {
         $this->clientError(_('Two user ids or screen_names must be supplied.'), 400, $apidata['content-type']);
         return;
     }
     if ($user_a->isSubscribed($user_b)) {
         $result = 'true';
     } else {
         $result = 'false';
     }
     switch ($apidata['content-type']) {
         case 'xml':
             $this->init_document('xml');
             $this->element('friends', null, $result);
             $this->end_document('xml');
             break;
         case 'json':
             $this->init_document('json');
             print json_encode($result);
             $this->end_document('json');
             break;
         default:
             break;
     }
 }
예제 #11
0
 /**
  * Handle a request
  *
  * @param array $args Arguments from $_REQUEST
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $this->showResults();
 }
예제 #12
0
 function featured($args, $apidata)
 {
     parent::handle($args);
     $this->serverError(_('API method under construction.'), $code = 501);
 }