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 ·
|
|
|
|
· ·
|
2016-01-18 09:24:37 +09:00
|
|
|
· https://git.gnu.io/h2p/Qvitter ·
|
2014-05-28 03:40:51 +09:00
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· <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;
|
2015-11-19 00:38:19 +09:00
|
|
|
var $blocks = 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);
|
|
|
|
|
2016-02-02 02:22:41 +09:00
|
|
|
$this->format = 'json';
|
|
|
|
|
2014-05-28 03:40:51 +09:00
|
|
|
$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();
|
2015-11-19 00:38:19 +09:00
|
|
|
$this->blocks = QvitterBlocked::getBlockedIDs($this->target->id,0,10000);
|
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;
|
|
|
|
}
|
2015-08-26 08:40:29 +09:00
|
|
|
$this->groups_stripped[$user_group->id] = $this_group;
|
2015-11-23 08:24:33 +09:00
|
|
|
}
|
2015-08-26 06:27:08 +09:00
|
|
|
|
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-11-19 00:38:19 +09:00
|
|
|
$this->showJsonObjects(array('users'=>$this->users_stripped,'groups'=>$this->groups_stripped,'blocks'=>$this->blocks));
|
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
|
|
|
|
);
|
2016-01-18 09:24:37 +09:00
|
|
|
|
2015-11-23 08:24:33 +09:00
|
|
|
if(!empty($group)) {
|
|
|
|
while ($group->fetch()) {
|
|
|
|
$groups[] = clone($group);
|
|
|
|
}
|
2015-08-26 06:27:08 +09:00
|
|
|
}
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-28 03:40:51 +09:00
|
|
|
}
|