Added raw following/followers pages.

This commit is contained in:
flash 2019-02-27 15:05:27 +01:00
parent 86aa0f5cf9
commit 8cebfb6fae
3 changed files with 78 additions and 1 deletions

View file

@ -99,6 +99,38 @@ switch ($mode) {
echo file_get_contents($userBackground);
break;
case 'following':
$userId = (int)($_GET['u'] ?? 0);
if (!user_exists($userId)) {
http_response_code(404);
echo tpl_render('user.notfound');
break;
}
$followingIds = user_relation_users_from($userId, MSZ_USER_RELATION_FOLLOW);
foreach ($followingIds as $user) {
echo "{$user['user_id']}|{$user['relation_created']}<br>";
}
break;
case 'followers':
$userId = (int)($_GET['u'] ?? 0);
if (!user_exists($userId)) {
http_response_code(404);
echo tpl_render('user.notfound');
break;
}
$followerIds = user_relation_users_to($userId, MSZ_USER_RELATION_FOLLOW);
foreach ($followerIds as $user) {
echo "{$user['user_id']}|{$user['relation_created']}<br>";
}
break;
default:
$userId = user_find_for_profile($_GET['u'] ?? 0);

View file

@ -81,3 +81,40 @@ function user_relation_info(int $userId, int $subjectId): array
$getRelationInfo->bindValue('subject_id', $subjectId);
return db_fetch($getRelationInfo);
}
function user_relation_users(int $userId, int $type, bool $from): array
{
if ($userId < 1 || $type <= MSZ_USER_RELATION_NONE || !user_relation_is_valid_type($type)) {
return [];
}
static $getUsers = [];
if (empty($getUsers[$from])) {
$getUsers[$from] = db_prepare(sprintf(
'
SELECT `%1$s` AS `user_id`, `relation_created`
FROM `msz_user_relations`
WHERE `%2$s` = :user_id
AND `relation_type` = :type
',
$from ? 'subject_id' : 'user_id',
$from ? 'user_id' : 'subject_id'
));
}
$getUsers[$from]->bindValue('user_id', $userId);
$getUsers[$from]->bindValue('type', $type);
return db_fetch_all($getUsers[$from]);
}
function user_relation_users_to(int $userId, int $type): array
{
return user_relation_users($userId, $type, false);
}
function user_relation_users_from(int $userId, int $type): array
{
return user_relation_users($userId, $type, true);
}

View file

@ -165,13 +165,21 @@ function user_exists(int $userId): bool
return false;
}
static $exists = [];
if (isset($exists[$userId])) {
return $exists[$userId];
}
$check = db_prepare('
SELECT COUNT(`user_id`) > 0
FROM `msz_users`
WHERE `user_id` = :user_id
');
$check->bindValue('user_id', $userId);
return $check->execute() ? (bool)$check->fetchColumn() : false;
return $exists[$userId] = (bool)($check->execute() ? $check->fetchColumn() : false);
}
function user_id_from_username(string $username): int