2014-05-28 03:40:51 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2015-08-26 06:27:08 +09:00
|
|
|
· ·
|
2014-05-28 03:40:51 +09:00
|
|
|
· Everybody I'm following and all groups I'm member of ·
|
2015-08-26 06:27:08 +09:00
|
|
|
· (to use for auto-suggestions) ·
|
|
|
|
· ·
|
|
|
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2014-05-28 03:40:51 +09:00
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· Q V I T T E R ·
|
|
|
|
· ·
|
|
|
|
· http://github.com/hannesmannerheim/qvitter ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· <o) ·
|
|
|
|
· /_//// ·
|
|
|
|
· (____/ ·
|
|
|
|
· (o< ·
|
|
|
|
· o> \\\\_\ ·
|
2015-08-26 06:27:08 +09:00
|
|
|
· \\) \____) ·
|
|
|
|
· ·
|
2014-05-28 03:40:51 +09:00
|
|
|
· ·
|
|
|
|
· Qvitter is free software: you can redistribute it and / or modify it ·
|
|
|
|
· under the terms of the GNU Affero General Public License as published by ·
|
|
|
|
· the Free Software Foundation, either version three of the License or (at ·
|
|
|
|
· your option) any later version. ·
|
|
|
|
· ·
|
|
|
|
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
|
|
|
|
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
|
|
|
|
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
|
|
|
|
· more details. ·
|
|
|
|
· ·
|
|
|
|
· You should have received a copy of the GNU Affero General Public License ·
|
|
|
|
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
|
|
|
|
· ·
|
|
|
|
· Contact h@nnesmannerhe.im if you have any questions. ·
|
2015-08-26 06:27:08 +09:00
|
|
|
· ·
|
2014-05-28 03:40:51 +09:00
|
|
|
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
|
|
|
|
|
|
|
class ApiQvitterAllFollowingAction extends ApiBareAuthAction
|
|
|
|
{
|
|
|
|
|
|
|
|
var $profiles = null;
|
|
|
|
var $users_stripped = null;
|
2015-08-26 06:27:08 +09:00
|
|
|
var $groups_stripped = null;
|
2014-05-28 03:40:51 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
|
|
|
* @return boolean success flag
|
|
|
|
*/
|
|
|
|
protected function prepare(array $args=array())
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$this->count = 5000; // max 5000, completely arbitrary...
|
|
|
|
|
|
|
|
$this->target = $this->getTargetProfile($this->arg('id'));
|
|
|
|
|
|
|
|
|
|
|
|
if (!($this->target instanceof Profile)) {
|
|
|
|
// TRANS: Client error displayed when requesting a list of followers for a non-existing user.
|
|
|
|
$this->clientError(_('No such user.'), 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->profiles = $this->getProfiles();
|
2015-08-26 06:27:08 +09:00
|
|
|
$this->groups = $this->getGroups();
|
2014-05-28 03:40:51 +09:00
|
|
|
|
2015-08-26 06:27:08 +09:00
|
|
|
|
|
|
|
// profiles: only keep id, name, nickname and avatar URL
|
2014-05-28 03:40:51 +09:00
|
|
|
foreach($this->profiles as $p) {
|
|
|
|
try {
|
2015-08-26 06:27:08 +09:00
|
|
|
$avatar = Avatar::urlByProfile($p, AVATAR_STREAM_SIZE);
|
2014-05-28 03:40:51 +09:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$avatar = false;
|
2015-08-26 06:27:08 +09:00
|
|
|
}
|
2014-05-28 03:40:51 +09:00
|
|
|
$this_user = array($p->fullname,$p->nickname,$avatar);
|
2015-06-03 00:10:58 +09:00
|
|
|
if(!$p->isLocal()) {
|
|
|
|
$this_user[3] = $p->getUrl();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this_user[3] = false;
|
|
|
|
}
|
2014-05-28 03:40:51 +09:00
|
|
|
$this->users_stripped[$p->id] = $this_user;
|
|
|
|
}
|
|
|
|
|
2015-08-26 06:27:08 +09:00
|
|
|
// groups: only keep id, name, nickname, avatar and local aliases
|
|
|
|
foreach($this->groups as $user_group) {
|
|
|
|
$p = $user_group->getProfile();
|
|
|
|
$avatar = $user_group->stream_logo;
|
|
|
|
$this_group = array($p->fullname,$p->nickname,$avatar);
|
|
|
|
if(!$user_group->isLocal()) {
|
|
|
|
$this_group[3] = $p->getUrl();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this_group[3] = false;
|
|
|
|
}
|
|
|
|
$this->groups_stripped[$p->id] = $this_group;
|
|
|
|
}
|
|
|
|
|
2014-05-28 03:40:51 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the request
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST data (unused)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function handle()
|
|
|
|
{
|
|
|
|
parent::handle();
|
2015-08-26 06:27:08 +09:00
|
|
|
|
2014-05-28 03:40:51 +09:00
|
|
|
|
|
|
|
$this->initDocument('json');
|
2015-08-26 06:27:08 +09:00
|
|
|
$this->showJsonObjects(array('users'=>$this->users_stripped,'groups'=>$this->groups_stripped));
|
2014-05-28 03:40:51 +09:00
|
|
|
$this->endDocument('json');
|
|
|
|
}
|
2015-08-26 06:27:08 +09:00
|
|
|
|
2014-05-28 03:40:51 +09:00
|
|
|
/**
|
|
|
|
* Get profiles
|
|
|
|
*
|
|
|
|
* @return array Profiles
|
|
|
|
*/
|
|
|
|
protected function getProfiles()
|
|
|
|
{
|
|
|
|
$offset = ($this->page - 1) * $this->count;
|
|
|
|
$limit = $this->count + 1;
|
|
|
|
|
|
|
|
$subs = null;
|
|
|
|
|
2015-08-26 06:27:08 +09:00
|
|
|
$subs = $this->target->getSubscribed(
|
|
|
|
$offset,
|
|
|
|
$limit
|
|
|
|
);
|
2014-05-28 03:40:51 +09:00
|
|
|
|
|
|
|
$profiles = array();
|
|
|
|
|
|
|
|
while ($subs->fetch()) {
|
|
|
|
$profiles[] = clone($subs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $profiles;
|
|
|
|
}
|
|
|
|
|
2015-08-26 06:27:08 +09:00
|
|
|
/**
|
|
|
|
* Get groups
|
|
|
|
*
|
|
|
|
* @return array groups
|
|
|
|
*/
|
|
|
|
function getGroups()
|
|
|
|
{
|
|
|
|
$groups = array();
|
|
|
|
|
|
|
|
$group = $this->target->getGroups(
|
|
|
|
($this->page - 1) * $this->count,
|
|
|
|
$this->count,
|
|
|
|
$this->since_id,
|
|
|
|
$this->max_id
|
|
|
|
);
|
|
|
|
|
|
|
|
while ($group->fetch()) {
|
|
|
|
$groups[] = clone($group);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-28 03:40:51 +09:00
|
|
|
}
|