Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test only index pages for recent changes #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 78 additions & 59 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php include "header.php"; ?>
<?php
include "header.php";

<?php
// Display notice message based on query parameters
if (isset($_GET['notice'])) {
$notice = htmlspecialchars($_GET['notice']);
Expand All @@ -11,7 +11,6 @@
}
}
?>

<h1 id="fancyboi">welcome to tilde.club</h1>

<p><a href="/wiki/faq.html">Questions? See the official FAQ.</a></p>
Expand Down Expand Up @@ -171,62 +170,82 @@
<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><a href="/users/">list all users</a></p>
<ul class="user-list">
<?php
// these are the hashes of previous and current default pages
$page_shas = [
"0eb53dab435e2e6e401921146bed85a80e9ad3a1",
"61eff8202777bae134ac4b11f1e16ec23dfc97d3",
"e9d41eab6edb7cd375c63ecb4a23bca928992547",
"cb2ce535ab34edebc225e88a321f972ba55763c3",
"13af6898f536265af7dbbe2935b591f5e2ee0d7d",
"b0eb2bf442e52b98714456b2f8a6662ba4c1f443",
"0b4f272852e3391e97f0ebb7b5d734a765958eeb",
"59e857ec585d6d34ed21e027164b3c3c36a95f0f",
"9da422e8759799cce29327024fc77b6aa2ace484",
"e5da596bd5f72aa583839bcefd28e988c9d4fcbe",
"adc83b19e793491b1c6ea0fd8b46cd9f32e592fc",
"3f51b25206c137593124a16d8b881079352cd1c4",
"051b45fb2da9b15c523dfafd2a1dd33cc8b54e87",
"5a1cf2f88acb15da43f5d18a13fe638d175a44cc",
"0066d512c24f4ada7ad925fd0856b6b68334a93c",
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"f032fa07b3f4d9c1264a5a9369bff19f231bff45",
"259969faeba97eb16a675bb66427efd168406c92",
"75b7ce715379312bcc0b24696b9406e10b97cedc",
"e28aa091c26528a4084b8fad2a2ddb72bee3db75",
"12608ff7f6d222d97d2e02c1a13496e1d79713bb",
"22d29b83dc93b925bee08d090b0ea0fffdeb57f2",
"4706d8acdd74efd5c6d8f9e69ec215928d9ff165",
"385212d5ea557a21b77af992ea1b3c1ea71d22c9",
"b51a889545b5f065fd1ac2b8760cab0088a9dc22"
];
$oneMonthAgo = strtotime('-1 month');

foreach (glob("/home/*") as $user) {
// Look for index files with common extensions
$indexFiles = glob("$user/public_html/index.{html,htm,php}", GLOB_BRACE);
$index = count($indexFiles) > 0 ? $indexFiles[0] : null;

if (!$index || in_array(sha1_file($index), $page_shas)) continue;

// Check for any recent changes in the public_html directory
$recentChange = false;
foreach (glob("$user/public_html/*") as $file) {
if (filemtime($file) > $oneMonthAgo) {
$recentChange = true;
break;
}
}

$user = basename($user);
$class = $recentChange ? 'recently-updated' : '';
?>
<li class="<?= $class ?>"><a href="/~<?=$user?>/">~<?=$user?></a></li>
<?php } ?>
</ul>
<?php
// these are the hashes of previous and current default pages
$page_shas = [
"0eb53dab435e2e6e401921146bed85a80e9ad3a1",
"61eff8202777bae134ac4b11f1e16ec23dfc97d3",
"e9d41eab6edb7cd375c63ecb4a23bca928992547",
"cb2ce535ab34edebc225e88a321f972ba55763c3",
"13af6898f536265af7dbbe2935b591f5e2ee0d7d",
"b0eb2bf442e52b98714456b2f8a6662ba4c1f443",
"0b4f272852e3391e97f0ebb7b5d734a765958eeb",
"59e857ec585d6d34ed21e027164b3c3c36a95f0f",
"9da422e8759799cce29327024fc77b6aa2ace484",
"e5da596bd5f72aa583839bcefd28e988c9d4fcbe",
"adc83b19e793491b1c6ea0fd8b46cd9f32e592fc",
"3f51b25206c137593124a16d8b881079352cd1c4",
"051b45fb2da9b15c523dfafd2a1dd33cc8b54e87",
"5a1cf2f88acb15da43f5d18a13fe638d175a44cc",
"0066d512c24f4ada7ad925fd0856b6b68334a93c",
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"f032fa07b3f4d9c1264a5a9369bff19f231bff45",
"259969faeba97eb16a675bb66427efd168406c92",
"75b7ce715379312bcc0b24696b9406e10b97cedc",
"e28aa091c26528a4084b8fad2a2ddb72bee3db75",
"12608ff7f6d222d97d2e02c1a13496e1d79713bb",
"22d29b83dc93b925bee08d090b0ea0fffdeb57f2",
"4706d8acdd74efd5c6d8f9e69ec215928d9ff165",
"385212d5ea557a21b77af992ea1b3c1ea71d22c9",
"b51a889545b5f065fd1ac2b8760cab0088a9dc22"
];

$oneMonthAgo = strtotime('-1 month');

// Retrieve from cache file if available
$cache_file = 'cache/homepages_list.html';

if (file_exists($cache_file) and time() - filemtime($cache_file) < 86400)
{
$homepages_list = file_get_contents($cache_file);
}
// Cache not available or expired
else
{
$homepages_list = '<ul class="user-list">';

foreach (glob("/home/*") as $user) {
// Look for index files with common extensions
$indexFiles = glob("$user/public_html/index.{html,htm,php}", GLOB_BRACE);
$index = count($indexFiles) > 0 ? $indexFiles[0] : null;

if (!$index || in_array(sha1_file($index), $page_shas)) continue;

// Check if the index pages were updated in the last month
$recentChange = false;

foreach ($indexFiles as $file) {
if (filemtime($file) > $oneMonthAgo) {
$recentChange = true;
break;
}
}

$user = basename($user);
$class = $recentChange ? 'recently-updated' : '';

$homepages_list .= '<li class="'.$class.'"><a href="/~'.$user.'/">~'.$user.'</a></li>';
}

$homepages_list .= '</ul>';

// Save cache file
$save_cache = file_put_contents($cache_file, $homepages_list);
}

echo $homepages_list;
?>
</div>
</div>
</div>

<?php include "footer.php"; ?>
<?php include "footer.php";