Merge pull request #60 from litemotiv/updated_homepages

Test only index pages for recent changes
This commit is contained in:
deepend-tildeclub 2025-01-18 11:56:07 -07:00 committed by GitHub
commit dd62a18333
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 74 additions and 55 deletions

View File

@ -1,6 +1,6 @@
<?php include "header.php"; ?>
<?php <?php
include "header.php";
// Display notice message based on query parameters // Display notice message based on query parameters
if (isset($_GET['notice'])) { if (isset($_GET['notice'])) {
$notice = htmlspecialchars($_GET['notice']); $notice = htmlspecialchars($_GET['notice']);
@ -11,7 +11,6 @@ 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>
@ -171,7 +170,6 @@ if (isset($_GET['notice'])) {
<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 within the last month 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>
<ul class="user-list">
<?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 = [
@ -201,18 +199,32 @@ if (isset($_GET['notice'])) {
"385212d5ea557a21b77af992ea1b3c1ea71d22c9", "385212d5ea557a21b77af992ea1b3c1ea71d22c9",
"b51a889545b5f065fd1ac2b8760cab0088a9dc22" "b51a889545b5f065fd1ac2b8760cab0088a9dc22"
]; ];
$oneMonthAgo = strtotime('-1 month'); $oneMonthAgo = strtotime('-1 month');
foreach (glob("/home/*") as $user) { // 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 // 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 for any recent changes in the public_html directory // Check if the index pages were updated in the last month
$recentChange = false; $recentChange = false;
foreach (glob("$user/public_html/*") as $file) {
foreach ($indexFiles as $file) {
if (filemtime($file) > $oneMonthAgo) { if (filemtime($file) > $oneMonthAgo) {
$recentChange = true; $recentChange = true;
break; break;
@ -221,12 +233,19 @@ foreach (glob("/home/*") as $user) {
$user = basename($user); $user = basename($user);
$class = $recentChange ? 'recently-updated' : ''; $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;
?> ?>
<li class="<?= $class ?>"><a href="/~<?=$user?>/">~<?=$user?></a></li>
<?php } ?>
</ul>
</div> </div>
</div> </div>
</div> </div>
<?php include "footer.php";
<?php include "footer.php"; ?>