1
0
Fork 1

Compare commits

...

5 Commits

@ -63,7 +63,7 @@ test: FLAGS = --verbose
test: clean all open server
# Build everything from scratch and test functionality on LAN.
test: FLAGS = --verbose
test-lan: FLAGS = --verbose
test-lan: clean all open lan-server
# -- Aliases --

@ -58,7 +58,6 @@ html.js .noscript, .hidden {
}
html:not(.js) .js-only {
/* Dead style */
display: none;
}

@ -1,7 +1,11 @@
<?php
include_once "$PROJECT_ROOT/languages/language_flags.php";
$WEEK_SECONDS = 604800;
$MINUTE_SECONDS = 60;
$HOUR_SECONDS = 60 * $MINUTE_SECONDS;
$DAY_SECONDS = 24 * $HOUR_SECONDS;
$WEEK_SECONDS = 7 * $DAY_SECONDS;
/**
* Representation of Session Community room.
*/
@ -174,6 +178,32 @@
return time() - $this->created;
}
/**
* Formats the period over which active users are counted as a duration string.
* @return string Active user cutoff period for this room, expressed in days.
*/
function format_user_cutoff_period(): ?string {
global $WEEK_SECONDS, $DAY_SECONDS, $HOUR_SECONDS, $MINUTE_SECONDS;
$active_users_cutoff = $this->active_users_cutoff;
if ($active_users_cutoff >= $WEEK_SECONDS) {
return floor($active_users_cutoff / $WEEK_SECONDS) . ' week(s)';
}
if ($active_users_cutoff >= $DAY_SECONDS) {
return floor($active_users_cutoff / $DAY_SECONDS) . ' day(s)';
}
if ($active_users_cutoff >= $HOUR_SECONDS) {
return floor($active_users_cutoff / $HOUR_SECONDS) . ' hour(s)';
}
if ($active_users_cutoff >= $MINUTE_SECONDS) {
return floor($active_users_cutoff / $MINUTE_SECONDS) . 'minute(s)';
}
return floor($active_users_cutoff) . 's';
}
/**
* Return the browser preview URL for this room.
*/
@ -226,28 +256,6 @@
$pubkey_4 = substr($this->server->pubkey, 0, 4);
return "$token+$pubkey_4";
}
/**
* Returns an estimate for the weekly active users of a CommunityRoom.
* @return int Active user count normalized by tracked timespan of active users.
*/
function get_weekly_active_users(): int {
global $WEEK_SECONDS;
$active_users = $this->active_users;
if ($active_users == null) {
return 0;
}
$active_users_cutoff = $this->active_users_cutoff;
if ($active_users_cutoff == null) {
return $active_users;
}
return floor($active_users * $WEEK_SECONDS / $active_users_cutoff);
}
}
/**

@ -28,7 +28,7 @@
['id' => "language", 'name' => "L", 'name_long' => "Language"],
['id' => "name", 'name' => "Name"],
['id' => "description", 'name' => "About", 'name_long' => "Description"],
['id' => "users", 'name' => "#", 'name_long' => "Weekly Active Users"],
['id' => "users", 'name' => "#", 'name_long' => "Active Users"],
['id' => "preview", 'name' => "Preview"],
['id' => "qr_code", 'name' => "QR", 'name_long' => "QR Code (for use in-app)"],
['id' => "server_icon", 'name' => "Host", 'name_long' => "Server host"],
@ -57,7 +57,8 @@
$language = html_sanitize($room->language_flag);
$name = html_sanitize($room->name);
$desc = html_sanitize($room->description);
$users = html_sanitize($room->get_weekly_active_users());
$users = html_sanitize($room->active_users);
$users_cutoff = html_sanitize($room->format_user_cutoff_period());
$preview_link = html_sanitize($room->get_preview_url());
$join_link = html_sanitize($room->get_join_url());
$pubkey = html_sanitize($pubkey);
@ -86,10 +87,15 @@
><?=$desc?></td>
<td
class="td_users"
title="'<?=$name?>' has around <?=$users?> weekly active users."
title="'<?=$name?>' has had <?=$users?> active users in the last <?=$users_cutoff?>."
><?=$users?></td>
<td class="td_preview" itemprop="url">
<a href="<?=$preview_link?>" target="_blank" rel="noopener noreferrer nofollow">
<a
href="<?=$preview_link?>"
title="Click here to preview '<?=$name?>'"
target="_blank"
rel="noopener noreferrer nofollow"
>
<span class="protocol-indicator"></span>
</a>
</td>

@ -96,9 +96,15 @@
target="_blank"
>various sources</a>.
<br>
We make an attempt to hide communities containing
objectionable or illegal content, but
you should still proceed with caution.
<span class="js-only">
We make an attempt to hide communities containing
objectionable or illegal content, but
you should still proceed with caution.
</span>
<span class="noscript">
Proceed with caution when joining unofficial communities.
As JavaScript is disabled, no communities are filtered from the list.
</span>
</p>
<p class="noscript">
This site works fine without JavaScript.