Merge pull request #71 from litemotiv/dynamic_homepage_links

Colorize user home pages based on modified age
This commit is contained in:
deepend-tildeclub 2025-02-07 12:54:40 -07:00 committed by GitHub
commit 22551d20e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 88 additions and 58 deletions

View File

@ -11,7 +11,7 @@ if (isset($_GET['notice'])) {
} }
} }
?> ?>
<h1 id="fancyboi">welcome to tilde.club</h1> <h1 id="fancyboi">welcome to Tilde.club</h1>
<p><a href="/wiki/faq.html">Questions? See the official FAQ.</a></p> <p><a href="/wiki/faq.html">Questions? See the official FAQ.</a></p>
@ -119,7 +119,7 @@ if (isset($_GET['notice'])) {
<div class="col"> <div class="col">
<p> <p>
tilde.club is not a social network it is one tiny totally Tilde.club is not a social network it is one tiny totally
standard unix computer that people respectfully use together standard unix computer that people respectfully use together
in their shared quest to build awesome web pages in their shared quest to build awesome web pages
</p> </p>
@ -129,12 +129,12 @@ if (isset($_GET['notice'])) {
RECENTLY CHANGED PAGES</a> you can see that too RECENTLY CHANGED PAGES</a> you can see that too
</p> </p>
<p> <p>
Or Check out the <a href="https://tilde.club/~tweska/gallery" target="blank">tilde.club gallery</a> created by <a href="/~tweska" target="_blank">~tweska</a> Or Check out the <a href="https://tilde.club/~tweska/gallery" target="blank">Tilde.club gallery</a> created by <a href="/~tweska" target="_blank">~tweska</a>
</p> </p>
<hr> <hr>
<h2>tilde.club gold star supporters</h2> <h2>Tilde.club gold star supporters</h2>
<p>Tilde.Club is supported by a global community of <p>Tilde.club is supported by a global community of
good people. We don't rank people by the amount good people. We don't rank people by the amount
they give, only by the fact that they gave. they give, only by the fact that they gave.
Here's who has donated! When you're on the Here's who has donated! When you're on the
@ -165,11 +165,11 @@ if (isset($_GET['notice'])) {
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h3>here are the home pages of our users</h3> <h3>Here are the home pages of our users</h3>
<p>this list does not include people who haven't changed their page yet.</p> <p>This list does not include people who haven't changed their page yet.</p>
<p>if you're not seeing yourself listed here, change your page from the default.</p> <p>If you're not seeing yourself listed here, change your page from the default.</p>
<p>users with recently updated pages within the last month are highlighted in a lighter color.</p> <p>Users with recently updated pages are highlighted in a lighter color.</p>
<p><a href="/users/">list all users</a></p> <p><a href="/users/">List all users</a></p>
<?php <?php
// these are the hashes of previous and current default pages // these are the hashes of previous and current default pages
$page_shas = [ $page_shas = [
@ -200,49 +200,62 @@ if (isset($_GET['notice'])) {
"b51a889545b5f065fd1ac2b8760cab0088a9dc22" "b51a889545b5f065fd1ac2b8760cab0088a9dc22"
]; ];
$oneMonthAgo = strtotime('-1 month');
// Retrieve from cache file if available // Retrieve from cache file if available
$cache_file = 'cache/homepages_list.html'; $cache_file = 'cache/homepages_list.html';
if (file_exists($cache_file) and time() - filemtime($cache_file) < 86400) if (file_exists($cache_file) and time() - filemtime($cache_file) < 86400)
{ {
$homepages_list = file_get_contents($cache_file); $homepagesOutput = file_get_contents($cache_file);
} }
// Cache not available or expired
// Cache not available or expired - create list
else else
{ {
$homepages_list = '<div class="user-list">'; $homepagesOutput = '<div class="user-list">';
$now = time();
foreach (glob("/home/*") as $user) { foreach (glob("/home/*") as $user)
{
// Look for index files with common extensions // Look for index files with common extensions
$indexFiles = glob("$user/public_html/index.{html,htm,php}", GLOB_BRACE); $indexFiles = glob("$user/public_html/index.{html,htm,php}", GLOB_BRACE);
$index = count($indexFiles) > 0 ? $indexFiles[0] : null; $index = count($indexFiles) > 0 ? $indexFiles[0] : null;
if (!$index || in_array(sha1_file($index), $page_shas)) continue; if (!$index || in_array(sha1_file($index), $page_shas)) continue;
// Check if the index pages were updated in the last month // determine the most recently updated file
$recentChange = false; $age = 0;
foreach ($indexFiles as $file) { foreach ($indexFiles as $file)
if (filemtime($file) > $oneMonthAgo) { {
$recentChange = true; $access = filemtime($file);
break;
} if ($access > $age)
$age = $access;
} }
$user = basename($user); $user = basename($user);
// For simplicity, we use a maximum of 50 months old
$monthsOld = floor(($now - $age) / 2592000);
if ($monthsOld > 50) $monthsOld = 50;
$homepages_list .= '<a href="/~'.$user.'/">'.(($recentChange) ? '<b>~'.$user.'</b>' : '~'.$user).'</a>'; // Set opacity in steps of 5
$opacity = 100 - 2 * $monthsOld;
$opacity = ceil($opacity / 5) * 5;
// Minimum is 15% opacity
if ($opacity < 15) $opacity = 15;
$homepagesOutput .= '<a data-op="'.$opacity.'" href="/~'.$user.'/">'.$user.'</a>';
} }
$homepages_list .= '</div>'; $homepagesOutput .= '</div>';
// Save cache file // Save cache file
$save_cache = file_put_contents($cache_file, $homepages_list); $save_cache = file_put_contents($cache_file, $homepagesOutput);
} }
echo $homepages_list; echo $homepagesOutput;
?> ?>
</div> </div>
</div> </div>

View File

@ -141,18 +141,47 @@ code > span.fl {
/* Page content */ /* Page content */
.user-list { .user-list {
display: flex; display: grid;
flex-flow: row wrap; grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
justify-content: space-evenly;
list-style-type: none;
padding: 0;
} }
.user-list a { .user-list a {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
flex: 10em; flex: 10em;
} }
.user-list a:before {
content:"~";
}
[data-op="5"] { opacity:5%; }
[data-op="10"] { opacity:10%; }
[data-op="15"] { opacity:15%; }
[data-op="20"] { opacity:20%; }
[data-op="25"] { opacity:25%; }
[data-op="30"] { opacity:30%; }
[data-op="35"] { opacity:35%; }
[data-op="40"] { opacity:40%; }
[data-op="45"] { opacity:45%; }
[data-op="50"] { opacity:50%; }
[data-op="55"] { opacity:55%; }
[data-op="60"] { opacity:60%; }
[data-op="65"] { opacity:65%; }
[data-op="70"] { opacity:70%; }
[data-op="75"] { opacity:75%; }
[data-op="80"] { opacity:80%; }
[data-op="85"] { opacity:85%; }
[data-op="90"] { opacity:90%; }
[data-op="95"] { opacity:95%; }
[data-op="100"] { opacity:100%; }
.user-list a:hover {
text-decoration:underline;
color:#f70;
}
.user-list b { .user-list b {
background-color: #fb5; background-color: #fb5;
color:#000; color:#000;

View File

@ -1,36 +1,24 @@
<?php <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$title = 'tilde.club users'; $title = 'tilde.club users';
include __DIR__.'/../header.php'; include __DIR__.'/../header.php';
?> ?>
<h1 id="fancyboi">Tilde.club user list</h1>
<h1 id="fancyboi">full user list</h1>
<div class="grid"> <div class="grid">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<p>Here is a full list of users (including those who haven't updated their page from the default)</p>
<p>here's a full list of users (including those who haven't updated their page from the default)</p> <p>Also see users who have updated their page in the <a href="http://tilde.club/tilde.24h.php">last 24 hours</a></p>
<br>
<p>see <a href="http://tilde.club/tilde.24h.php">users who have updated their page in the last 24 hours</a></p> <div class="user-list">
<?php
<br> foreach (glob("/home/*") as $user)
<ul class="user-list"> {
$user = basename($user);
<?php foreach (glob("/home/*") as $user) { echo '<a href="/~'.$user.'/">~'.$user.'</a>';
$user = basename($user); ?> }
<li><a href="/~<?=$user?>/">~<?=$user?></a></li> ?>
<?php } ?> </div>
</ul>
</div> </div>
</div> </div>
</div> </div>
<?php <?php include __DIR__.'/../footer.php';
include __DIR__.'/../footer.php';