X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fapiaction.php;h=4b4c94aed917648807803656c815565bc7c0a7f0;hb=852924799f6779195ca457296d94e982d41672fa;hp=8a7be31502f29e89ca02f5370a22b4d89f0351ac;hpb=8a21b13ee93cf46626ba9e99a4fda44587e6d1a1;p=quix0rs-gnu-social.git diff --git a/lib/apiaction.php b/lib/apiaction.php old mode 100644 new mode 100755 index 8a7be31502..4b4c94aed9 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -98,6 +98,8 @@ if (!defined('STATUSNET')) { exit(1); } +class ApiValidationException extends Exception { } + /** * Contains most of the Twitter-compatible API output functions. * @@ -117,7 +119,6 @@ class ApiAction extends Action const READ_ONLY = 1; const READ_WRITE = 2; - var $format = null; var $user = null; var $auth_user = null; var $page = null; @@ -126,6 +127,7 @@ class ApiAction extends Action var $since_id = null; var $source = null; var $callback = null; + var $format = null; var $access = self::READ_ONLY; // read (default) or read-write @@ -138,7 +140,7 @@ class ApiAction extends Action * * @return boolean false if user doesn't exist */ - function prepare($args) + protected function prepare(array $args=array()) { StatusNet::setApi(true); // reduce exception reports to aid in debugging parent::prepare($args); @@ -170,10 +172,10 @@ class ApiAction extends Action * * @return void */ - function handle($args) + protected function handle() { header('Access-Control-Allow-Origin: *'); - parent::handle($args); + parent::handle(); } /** @@ -200,51 +202,48 @@ class ApiAction extends Action { $twitter_user = array(); + try { + $user = $profile->getUser(); + } catch (NoSuchUserException $e) { + $user = null; + } + $twitter_user['id'] = intval($profile->id); $twitter_user['name'] = $profile->getBestName(); $twitter_user['screen_name'] = $profile->nickname; $twitter_user['location'] = ($profile->location) ? $profile->location : null; $twitter_user['description'] = ($profile->bio) ? $profile->bio : null; - $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); - $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : - Avatar::defaultImage(AVATAR_STREAM_SIZE); - - $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; - $twitter_user['protected'] = false; # not supported by StatusNet yet - $twitter_user['followers_count'] = $profile->subscriberCount(); - - $design = null; - $user = $profile->getUser(); + // TODO: avatar url template (example.com/user/avatar?size={x}x{y}) + $twitter_user['profile_image_url'] = Avatar::urlByProfile($profile, AVATAR_STREAM_SIZE); + $twitter_user['profile_image_url_https'] = $twitter_user['profile_image_url']; - // Note: some profiles don't have an associated user - - $defaultDesign = Design::siteDesign(); - - if (!empty($user)) { - $design = $user->getDesign(); + // START introduced by qvitter API, not necessary for StatusNet API + $twitter_user['profile_image_url_profile_size'] = Avatar::urlByProfile($profile, AVATAR_PROFILE_SIZE); + try { + $avatar = Avatar::getUploaded($profile); + $origurl = $avatar->displayUrl(); + } catch (Exception $e) { + $origurl = $twitter_user['profile_image_url_profile_size']; } + $twitter_user['profile_image_url_original'] = $origurl; - if (empty($design)) { - $design = $defaultDesign; + $twitter_user['groups_count'] = $profile->getGroupCount(); + foreach (array('linkcolor', 'backgroundcolor') as $key) { + $twitter_user[$key] = Profile_prefs::getConfigData($profile, 'theme', $key); } + // END introduced by qvitter API, not necessary for StatusNet API - $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor); - $twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue(); - $color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor); - $twitter_user['profile_text_color'] = ($color == null) ? '' : '#'.$color->hexValue(); - $color = Design::toWebColor(empty($design->linkcolor) ? $defaultDesign->linkcolor : $design->linkcolor); - $twitter_user['profile_link_color'] = ($color == null) ? '' : '#'.$color->hexValue(); - $color = Design::toWebColor(empty($design->sidebarcolor) ? $defaultDesign->sidebarcolor : $design->sidebarcolor); - $twitter_user['profile_sidebar_fill_color'] = ($color == null) ? '' : '#'.$color->hexValue(); - $twitter_user['profile_sidebar_border_color'] = ''; + $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; + $twitter_user['protected'] = (!empty($user) && $user->private_stream) ? true : false; + $twitter_user['followers_count'] = $profile->subscriberCount(); + + // Note: some profiles don't have an associated user $twitter_user['friends_count'] = $profile->subscriptionCount(); $twitter_user['created_at'] = $this->dateTwitter($profile->created); - $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling! - $timezone = 'UTC'; if (!empty($user) && $user->timezone) { @@ -256,27 +255,17 @@ class ApiAction extends Action $twitter_user['utc_offset'] = $t->format('Z'); $twitter_user['time_zone'] = $timezone; - - $twitter_user['profile_background_image_url'] - = empty($design->backgroundimage) - ? '' : ($design->disposition & BACKGROUND_ON) - ? Design::url($design->backgroundimage) : ''; - - $twitter_user['profile_background_tile'] - = empty($design->disposition) - ? '' : ($design->disposition & BACKGROUND_TILE) ? 'true' : 'false'; - $twitter_user['statuses_count'] = $profile->noticeCount(); // Is the requesting user following this user? $twitter_user['following'] = false; - $twitter_user['statusnet:blocking'] = false; + $twitter_user['statusnet_blocking'] = false; $twitter_user['notifications'] = false; if (isset($this->auth_user)) { $twitter_user['following'] = $this->auth_user->isSubscribed($profile); - $twitter_user['statusnet:blocking'] = $this->auth_user->hasBlocked($profile); + $twitter_user['statusnet_blocking'] = $this->auth_user->hasBlocked($profile); // Notifications on? $sub = Subscription::pkeyGet(array('subscriber' => @@ -290,8 +279,8 @@ class ApiAction extends Action if ($get_notice) { $notice = $profile->getCurrentNotice(); - if ($notice) { - # don't get user! + if ($notice instanceof Notice) { + // don't get user! $twitter_user['status'] = $this->twitterStatusArray($notice, false); } } @@ -300,6 +289,9 @@ class ApiAction extends Action $twitter_user['statusnet_profile_url'] = $profile->profileurl; + // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array + Event::handle('TwitterUserArray', array($profile, &$twitter_user, $this->scoped, array())); + return $twitter_user; } @@ -308,10 +300,10 @@ class ApiAction extends Action $base = $this->twitterSimpleStatusArray($notice, $include_user); if (!empty($notice->repeat_of)) { - $original = Notice::staticGet('id', $notice->repeat_of); - if (!empty($original)) { - $original_array = $this->twitterSimpleStatusArray($original, $include_user); - $base['retweeted_status'] = $original_array; + $original = Notice::getKV('id', $notice->repeat_of); + if ($original instanceof Notice) { + $orig_array = $this->twitterSimpleStatusArray($original, $include_user); + $base['retweeted_status'] = $orig_array; } } @@ -326,8 +318,15 @@ class ApiAction extends Action $twitter_status['text'] = $notice->content; $twitter_status['truncated'] = false; # Not possible on StatusNet $twitter_status['created_at'] = $this->dateTwitter($notice->created); - $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? - intval($notice->reply_to) : null; + try { + // We could just do $notice->reply_to but maybe the future holds a + // different story for parenting. + $parent = $notice->getParent(); + $in_reply_to = $parent->id; + } catch (Exception $e) { + $in_reply_to = null; + } + $twitter_status['in_reply_to_status_id'] = $in_reply_to; $source = null; @@ -344,13 +343,14 @@ class ApiAction extends Action } } + $twitter_status['uri'] = $notice->getUri(); $twitter_status['source'] = $source; $twitter_status['id'] = intval($notice->id); $replier_profile = null; if ($notice->reply_to) { - $reply = Notice::staticGet(intval($notice->reply_to)); + $reply = Notice::getKV(intval($notice->reply_to)); if ($reply) { $replier_profile = $reply->getProfile(); } @@ -370,10 +370,10 @@ class ApiAction extends Action $twitter_status['geo'] = null; } - if (isset($this->auth_user)) { - $twitter_status['favorited'] = $this->auth_user->hasFave($notice); + if (!is_null($this->scoped)) { + $twitter_status['repeated'] = $this->scoped->hasRepeated($notice); } else { - $twitter_status['favorited'] = false; + $twitter_status['repeated'] = false; } // Enclosures @@ -384,19 +384,21 @@ class ApiAction extends Action $twitter_status['attachments'] = array(); foreach ($attachments as $attachment) { - $enclosure_o=$attachment->getEnclosure(); - if ($enclosure_o) { + try { + $enclosure_o = $attachment->getEnclosure(); $enclosure = array(); $enclosure['url'] = $enclosure_o->url; $enclosure['mimetype'] = $enclosure_o->mimetype; $enclosure['size'] = $enclosure_o->size; $twitter_status['attachments'][] = $enclosure; + } catch (ServerException $e) { + // There was not enough metadata available } } } if ($include_user && $profile) { - # Don't get notice (recursive!) + // Don't get notice (recursive!) $twitter_user = $this->twitterUserArray($profile, false); $twitter_status['user'] = $twitter_user; } @@ -404,6 +406,11 @@ class ApiAction extends Action // StatusNet-specific $twitter_status['statusnet_html'] = $notice->rendered; + $twitter_status['statusnet_conversation_id'] = intval($notice->conversation); + + // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array + Event::handle('NoticeSimpleStatusArray', array($notice, &$twitter_status, $this->scoped, + array('include_user'=>$include_user))); return $twitter_status; } @@ -412,7 +419,7 @@ class ApiAction extends Action { $twitter_group = array(); - $twitter_group['id'] = $group->id; + $twitter_group['id'] = intval($group->id); $twitter_group['url'] = $group->permalink(); $twitter_group['nickname'] = $group->nickname; $twitter_group['fullname'] = $group->fullname; @@ -425,6 +432,7 @@ class ApiAction extends Action ); } + $twitter_group['admin_count'] = $group->getAdminCount(); $twitter_group['member_count'] = $group->getMemberCount(); $twitter_group['original_logo'] = $group->original_logo; $twitter_group['homepage_logo'] = $group->homepage_logo; @@ -457,6 +465,32 @@ class ApiAction extends Action return $entry; } + function twitterListArray($list) + { + $profile = Profile::getKV('id', $list->tagger); + + $twitter_list = array(); + $twitter_list['id'] = $list->id; + $twitter_list['name'] = $list->tag; + $twitter_list['full_name'] = '@'.$profile->nickname.'/'.$list->tag;; + $twitter_list['slug'] = $list->tag; + $twitter_list['description'] = $list->description; + $twitter_list['subscriber_count'] = $list->subscriberCount(); + $twitter_list['member_count'] = $list->taggedCount(); + $twitter_list['uri'] = $list->getUri(); + + if (isset($this->auth_user)) { + $twitter_list['following'] = $list->hasSubscriber($this->auth_user); + } else { + $twitter_list['following'] = false; + } + + $twitter_list['mode'] = ($list->private) ? 'private' : 'public'; + $twitter_list['user'] = $this->twitterUserArray($profile, false); + + return $twitter_list; + } + function twitterRssEntryArray($notice) { $entry = array(); @@ -482,13 +516,15 @@ class ApiAction extends Action $enclosures = array(); foreach ($attachments as $attachment) { - $enclosure_o=$attachment->getEnclosure(); - if ($enclosure_o) { + try { + $enclosure_o = $attachment->getEnclosure(); $enclosure = array(); $enclosure['url'] = $enclosure_o->url; $enclosure['mimetype'] = $enclosure_o->mimetype; $enclosure['size'] = $enclosure_o->size; $enclosures[] = $enclosure; + } catch (ServerException $e) { + // There was not enough metadata available } } @@ -544,13 +580,16 @@ class ApiAction extends Action { $details = array(); + $source_profile = $source->getProfile(); + $target_profile = $target->getProfile(); + $details['screen_name'] = $source->nickname; - $details['followed_by'] = $target->isSubscribed($source); - $details['following'] = $source->isSubscribed($target); + $details['followed_by'] = $target->isSubscribed($source_profile); + $details['following'] = $source->isSubscribed($target_profile); $notifications = false; - if ($source->isSubscribed($target)) { + if ($source->isSubscribed($target_profile)) { $sub = Subscription::pkeyGet(array('subscriber' => $source->id, 'subscribed' => $target->id)); @@ -560,8 +599,8 @@ class ApiAction extends Action } $details['notifications_enabled'] = $notifications; - $details['blocking'] = $source->hasBlocked($target); - $details['id'] = $source->id; + $details['blocking'] = $source->hasBlocked($target_profile); + $details['id'] = intval($source->id); return $details; } @@ -632,6 +671,20 @@ class ApiAction extends Action $this->elementEnd('group'); } + function showTwitterXmlList($twitter_list) + { + $this->elementStart('list'); + foreach($twitter_list as $element => $value) { + if($element == 'user') { + $this->showTwitterXmlUser($value, 'user'); + } + else { + $this->element($element, null, $value); + } + } + $this->elementEnd('list'); + } + function showTwitterXmlUser($twitter_user, $role='user', $namespaces=false) { $attrs = array(); @@ -697,7 +750,7 @@ class ApiAction extends Action $this->element('guid', null, $entry['guid']); $this->element('link', null, $entry['link']); - # RSS only supports 1 enclosure per item + // RSS only supports 1 enclosure per item if(array_key_exists('enclosures', $entry) and !empty($entry['enclosures'])){ $enclosure = $entry['enclosures'][0]; $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null); @@ -832,7 +885,7 @@ class ApiAction extends Action } if (!is_null($suplink)) { - # For FriendFeed's SUP protocol + // For FriendFeed's SUP protocol $this->element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', 'href' => $suplink, 'type' => 'application/json')); @@ -945,10 +998,10 @@ class ApiAction extends Action $from_profile = $message->getFrom(); $to_profile = $message->getTo(); - $dmsg['id'] = $message->id; - $dmsg['sender_id'] = $message->from_profile; + $dmsg['id'] = intval($message->id); + $dmsg['sender_id'] = intval($from_profile->id); $dmsg['text'] = trim($message->content); - $dmsg['recipient_id'] = $message->to_profile; + $dmsg['recipient_id'] = intval($to_profile->id); $dmsg['created_at'] = $this->dateTwitter($message->created); $dmsg['sender_screen_name'] = $from_profile->nickname; $dmsg['recipient_screen_name'] = $to_profile->nickname; @@ -979,10 +1032,13 @@ class ApiAction extends Action $entry['author-name'] = $from->getBestName(); $entry['author-uri'] = $from->homepage; - $avatar = $from->getAvatar(AVATAR_STREAM_SIZE); - - $entry['avatar'] = (!empty($avatar)) ? $avatar->url : Avatar::defaultImage(AVATAR_STREAM_SIZE); - $entry['avatar-type'] = (!empty($avatar)) ? $avatar->mediatype : 'image/png'; + $entry['avatar'] = $from->avatarUrl(AVATAR_STREAM_SIZE); + try { + $avatar = $from->getAvatar(AVATAR_STREAM_SIZE); + $entry['avatar-type'] = $avatar->mediatype; + } catch (Exception $e) { + $entry['avatar-type'] = 'image/png'; + } // RSS item specific @@ -1109,6 +1165,65 @@ class ApiAction extends Action $this->endDocument('xml'); } + function showXmlLists($list, $next_cursor=0, $prev_cursor=0) + { + + $this->initDocument('xml'); + $this->elementStart('lists_list'); + $this->elementStart('lists', array('type' => 'array')); + + if (is_array($list)) { + foreach ($list as $l) { + $twitter_list = $this->twitterListArray($l); + $this->showTwitterXmlList($twitter_list); + } + } else { + while ($list->fetch()) { + $twitter_list = $this->twitterListArray($list); + $this->showTwitterXmlList($twitter_list); + } + } + + $this->elementEnd('lists'); + + $this->element('next_cursor', null, $next_cursor); + $this->element('previous_cursor', null, $prev_cursor); + + $this->elementEnd('lists_list'); + $this->endDocument('xml'); + } + + function showJsonLists($list, $next_cursor=0, $prev_cursor=0) + { + $this->initDocument('json'); + + $lists = array(); + + if (is_array($list)) { + foreach ($list as $l) { + $twitter_list = $this->twitterListArray($l); + array_push($lists, $twitter_list); + } + } else { + while ($list->fetch()) { + $twitter_list = $this->twitterListArray($list); + array_push($lists, $twitter_list); + } + } + + $lists_list = array( + 'lists' => $lists, + 'next_cursor' => $next_cursor, + 'next_cursor_str' => strval($next_cursor), + 'previous_cursor' => $prev_cursor, + 'previous_cursor_str' => strval($prev_cursor) + ); + + $this->showJsonObjects($lists_list); + + $this->endDocument('json'); + } + function showTwitterXmlUsers($user) { $this->initDocument('xml'); @@ -1170,6 +1285,22 @@ class ApiAction extends Action $this->endDocument('xml'); } + function showSingleJsonList($list) + { + $this->initDocument('json'); + $twitter_list = $this->twitterListArray($list); + $this->showJsonObjects($twitter_list); + $this->endDocument('json'); + } + + function showSingleXmlList($list) + { + $this->initDocument('xml'); + $twitter_list = $this->twitterListArray($list); + $this->showTwitterXmlList($twitter_list); + $this->endDocument('xml'); + } + function dateTwitter($dt) { $dateStr = date('d F Y H:i:s', strtotime($dt)); @@ -1204,7 +1335,6 @@ class ApiAction extends Action default: // TRANS: Client error on an API request with an unsupported data format. $this->clientError(_('Not a supported data format.')); - break; } return; @@ -1231,85 +1361,10 @@ class ApiAction extends Action default: // TRANS: Client error on an API request with an unsupported data format. $this->clientError(_('Not a supported data format.')); - break; } return; } - function clientError($msg, $code = 400, $format = 'xml') - { - $action = $this->trimmed('action'); - - common_debug("User error '$code' on '$action': $msg", __FILE__); - - if (!array_key_exists($code, ClientErrorAction::$status)) { - $code = 400; - } - - $status_string = ClientErrorAction::$status[$code]; - - // Do not emit error header for JSONP - if (!isset($this->callback)) { - header('HTTP/1.1 ' . $code . ' ' . $status_string); - } - - switch($format) { - case 'xml': - $this->initDocument('xml'); - $this->elementStart('hash'); - $this->element('error', null, $msg); - $this->element('request', null, $_SERVER['REQUEST_URI']); - $this->elementEnd('hash'); - $this->endDocument('xml'); - break; - case 'json': - $this->initDocument('json'); - $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); - print(json_encode($error_array)); - $this->endDocument('json'); - break; - case 'text': - header('Content-Type: text/plain; charset=utf-8'); - print $msg; - break; - default: - // If user didn't request a useful format, throw a regular client error - throw new ClientException($msg, $code); - } - } - - function serverError($msg, $code = 500, $content_type = 'xml') - { - $action = $this->trimmed('action'); - - common_debug("Server error '$code' on '$action': $msg", __FILE__); - - if (!array_key_exists($code, ServerErrorAction::$status)) { - $code = 400; - } - - $status_string = ServerErrorAction::$status[$code]; - - // Do not emit error header for JSONP - if (!isset($this->callback)) { - header('HTTP/1.1 '.$code.' '.$status_string); - } - - if ($content_type == 'xml') { - $this->initDocument('xml'); - $this->elementStart('hash'); - $this->element('error', null, $msg); - $this->element('request', null, $_SERVER['REQUEST_URI']); - $this->elementEnd('hash'); - $this->endDocument('xml'); - } else { - $this->initDocument('json'); - $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); - print(json_encode($error_array)); - $this->endDocument('json'); - } - } - function initTwitterRss() { $this->startXML(); @@ -1360,39 +1415,43 @@ class ApiAction extends Action default: // TRANS: Client error on an API request with an unsupported data format. $this->clientError(_('Not a supported data format.')); - return; } return; } + private static function is_decimal($str) + { + return preg_match('/^[0-9]+$/', $str); + } + function getTargetUser($id) { if (empty($id)) { // Twitter supports these other ways of passing the user ID - if (is_numeric($this->arg('id'))) { - return User::staticGet($this->arg('id')); + if (self::is_decimal($this->arg('id'))) { + return User::getKV($this->arg('id')); } else if ($this->arg('id')) { $nickname = common_canonical_nickname($this->arg('id')); - return User::staticGet('nickname', $nickname); + return User::getKV('nickname', $nickname); } else if ($this->arg('user_id')) { // This is to ensure that a non-numeric user_id still // overrides screen_name even if it doesn't get used - if (is_numeric($this->arg('user_id'))) { - return User::staticGet('id', $this->arg('user_id')); + if (self::is_decimal($this->arg('user_id'))) { + return User::getKV('id', $this->arg('user_id')); } } else if ($this->arg('screen_name')) { $nickname = common_canonical_nickname($this->arg('screen_name')); - return User::staticGet('nickname', $nickname); + return User::getKV('nickname', $nickname); } else { // Fall back to trying the currently authenticated user return $this->auth_user; } - } else if (is_numeric($id)) { - return User::staticGet($id); + } else if (self::is_decimal($id)) { + return User::getKV($id); } else { $nickname = common_canonical_nickname($id); - return User::staticGet('nickname', $nickname); + return User::getKV('nickname', $nickname); } } @@ -1401,29 +1460,32 @@ class ApiAction extends Action if (empty($id)) { // Twitter supports these other ways of passing the user ID - if (is_numeric($this->arg('id'))) { - return Profile::staticGet($this->arg('id')); + if (self::is_decimal($this->arg('id'))) { + return Profile::getKV($this->arg('id')); } else if ($this->arg('id')) { // Screen names currently can only uniquely identify a local user. $nickname = common_canonical_nickname($this->arg('id')); - $user = User::staticGet('nickname', $nickname); + $user = User::getKV('nickname', $nickname); return $user ? $user->getProfile() : null; } else if ($this->arg('user_id')) { // This is to ensure that a non-numeric user_id still // overrides screen_name even if it doesn't get used - if (is_numeric($this->arg('user_id'))) { - return Profile::staticGet('id', $this->arg('user_id')); + if (self::is_decimal($this->arg('user_id'))) { + return Profile::getKV('id', $this->arg('user_id')); } } else if ($this->arg('screen_name')) { $nickname = common_canonical_nickname($this->arg('screen_name')); - $user = User::staticGet('nickname', $nickname); - return $user ? $user->getProfile() : null; + $user = User::getKV('nickname', $nickname); + return $user instanceof User ? $user->getProfile() : null; + } else { + // Fall back to trying the currently authenticated user + return $this->scoped; } - } else if (is_numeric($id)) { - return Profile::staticGet($id); + } else if (self::is_decimal($id)) { + return Profile::getKV($id); } else { $nickname = common_canonical_nickname($id); - $user = User::staticGet('nickname', $nickname); + $user = User::getKV('nickname', $nickname); return $user ? $user->getProfile() : null; } } @@ -1431,43 +1493,61 @@ class ApiAction extends Action function getTargetGroup($id) { if (empty($id)) { - if (is_numeric($this->arg('id'))) { - return User_group::staticGet($this->arg('id')); + if (self::is_decimal($this->arg('id'))) { + return User_group::getKV('id', $this->arg('id')); } else if ($this->arg('id')) { - $nickname = common_canonical_nickname($this->arg('id')); - $local = Local_group::staticGet('nickname', $nickname); - if (empty($local)) { - return null; - } else { - return User_group::staticGet('id', $local->id); - } + return User_group::getForNickname($this->arg('id')); } else if ($this->arg('group_id')) { - // This is to ensure that a non-numeric user_id still - // overrides screen_name even if it doesn't get used - if (is_numeric($this->arg('group_id'))) { - return User_group::staticGet('id', $this->arg('group_id')); + // This is to ensure that a non-numeric group_id still + // overrides group_name even if it doesn't get used + if (self::is_decimal($this->arg('group_id'))) { + return User_group::getKV('id', $this->arg('group_id')); } } else if ($this->arg('group_name')) { - $nickname = common_canonical_nickname($this->arg('group_name')); - $local = Local_group::staticGet('nickname', $nickname); - if (empty($local)) { - return null; - } else { - return User_group::staticGet('id', $local->group_id); - } + return User_group::getForNickname($this->arg('group_name')); } - } else if (is_numeric($id)) { - return User_group::staticGet($id); + } else if (self::is_decimal($id)) { + return User_group::getKV('id', $id); + } else if ($this->arg('uri')) { // FIXME: move this into empty($id) check? + return User_group::getKV('uri', urldecode($this->arg('uri'))); } else { - $nickname = common_canonical_nickname($id); - $local = Local_group::staticGet('nickname', $nickname); - if (empty($local)) { - return null; + return User_group::getForNickname($id); + } + } + + function getTargetList($user=null, $id=null) + { + $tagger = $this->getTargetUser($user); + $list = null; + + if (empty($id)) { + $id = $this->arg('id'); + } + + if($id) { + if (is_numeric($id)) { + $list = Profile_list::getKV('id', $id); + + // only if the list with the id belongs to the tagger + if(empty($list) || $list->tagger != $tagger->id) { + $list = null; + } + } + if (empty($list)) { + $tag = common_canonical_tag($id); + $list = Profile_list::getByTaggerAndTag($tagger->id, $tag); + } + + if (!empty($list) && $list->private) { + if ($this->auth_user->id == $list->tagger) { + return $list; + } } else { - return User_group::staticGet('id', $local->group_id); + return $list; } } + return null; } /**