118 lines
2.8 KiB
PHP
Executable file
118 lines
2.8 KiB
PHP
Executable file
<?php
|
|
require(__DIR__ . "/../libs/page.php");
|
|
require(__DIR__ . "/../libs/form.php");
|
|
require(__DIR__ . "/../libs/comment.php");
|
|
|
|
page_header();
|
|
|
|
function get_handler() {
|
|
global $db;
|
|
|
|
$stmt = $db->prepare("SELECT * FROM main.auth"); //weirdly, this requires a schema name
|
|
$stmt->execute([]);
|
|
$result = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
|
|
|
$pr = array();
|
|
$fcount = array();
|
|
$frs = array();
|
|
$matrixe = array();
|
|
|
|
foreach ($result as $usern) {
|
|
$fn = $usern['username'];
|
|
|
|
$pr[$fn] = 1;
|
|
|
|
$stmt = $db->prepare("SELECT * FROM main.follow WHERE target = ? AND NOT username = ?");
|
|
$stmt->execute([$fn,$fn]);
|
|
|
|
$fcount[$fn] = count($stmt->fetchAll(PDO::FETCH_DEFAULT));
|
|
|
|
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
|
|
$stmt->execute([$fn]);
|
|
|
|
$frs[$fn] = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
|
|
|
$matrixe[$fn] = array();
|
|
$matrixe[$fn][$fn] = 1;
|
|
}
|
|
|
|
foreach ($result as $usern) {
|
|
$theuser = $usern['username'];
|
|
|
|
$followers = $frs[$theuser];
|
|
foreach ($followers as $follown) {
|
|
$fn = $follown['target'];
|
|
|
|
if ($usern['username'] == $fn) continue;
|
|
$dst = $fcount[$fn];
|
|
|
|
$matrixe[$usern['username']][$fn] = 1 + 1 / ($dst + 10) / 10;
|
|
|
|
///$pr[$usern['username']] += $pr[$fn] / ($dst + 10) / 10;
|
|
}
|
|
}
|
|
|
|
|
|
for ($i = 0; $i < 6; $i++) {
|
|
$prold = $pr;
|
|
$matrixf = $matrixe;
|
|
|
|
foreach ($result as $usera) {
|
|
$pr[$usera['username']] = 0;
|
|
foreach ($result as $userb) {
|
|
$matrixe[$usera['username']][$userb['username']] = 0;
|
|
foreach ($result as $userc) {
|
|
$matrixe[$usera['username']][$userb['username']] += $matrixf[$usera['username']][$userc['username']] * $matrixf[$userc['username']][$userb['username']];
|
|
}
|
|
$pr[$usera['username']] += $prold[$userb['username']] * $matrixe[$usera['username']][$userb['username']];
|
|
}
|
|
}
|
|
|
|
$dist = 1 - ($i / 20);
|
|
|
|
$new_sum = array_sum($pr);
|
|
foreach ($result as $usern) {
|
|
$h = $pr[$usern['username']];
|
|
$pr[$usern['username']] = (($h / $new_sum/* 1.32 */) * 100) * $dist + ($h * (1 - $dist));
|
|
}
|
|
}
|
|
|
|
|
|
$new_sum = array_sum($pr);
|
|
foreach ($result as $usern) {
|
|
$pr[$usern['username']] = $pr[$usern['username']] * 100 / $new_sum;
|
|
}
|
|
|
|
function cmp($a, $b) {
|
|
if ($a == $b) {
|
|
return 0;
|
|
}
|
|
return ($a > $b) ? -1 : 1;
|
|
}
|
|
|
|
uasort($pr,'cmp');
|
|
|
|
foreach ($pr as $usern => $rr) { ?>
|
|
<div class='comment'>
|
|
<div class="avatar">
|
|
<img src="/pfp/<?php echo $usern ?>.png" class="avatar-img">
|
|
<div>
|
|
<div><b>
|
|
<a class="link" href="/user.php?id=<?php echo $usern ?>">
|
|
<?php echo $usern ?>
|
|
</a>
|
|
</b>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div><b>Power</b>: <?php echo $rr ?>%</div>
|
|
</div>
|
|
<?php }
|
|
}
|
|
|
|
get_handler();
|
|
?>
|
|
|
|
<?php
|
|
page_footer();
|
|
?>
|