Merge pull request 'Implement Community modals' from dynamic-modals into main
Reviewed-on: https://codeberg.org/gravel/sessioncommunities.online/pulls/1dev
commit
51d5685af2
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Return local path to room invite code.
|
||||
* @param string $room_id Id of room to locate QR code for.
|
||||
*/
|
||||
function room_qr_code_path(string $room_id): string {
|
||||
global $QR_CODES;
|
||||
return "$QR_CODES/$room_id.png";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return remote path to room invite code.
|
||||
* @param string $room_id Id of room to locate QR code for.
|
||||
*/
|
||||
function room_qr_code_path_relative(string $room_id): string {
|
||||
global $QR_CODES_RELATIVE;
|
||||
return "$QR_CODES_RELATIVE/$room_id.png";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch QR invite of the given room and return its local path.
|
||||
* @param \CommunityRoom $room
|
||||
* @return string
|
||||
*/
|
||||
function room_qr_code($room): string {
|
||||
$room_id = $room->get_room_identifier();
|
||||
$png_cached = room_qr_code_path($room_id);
|
||||
if (file_exists($png_cached)) {
|
||||
return room_qr_code_path_relative($room_id);
|
||||
}
|
||||
log_debug("Fetching QR code for $room_id.");
|
||||
$png = file_get_contents($room->get_invite_url());
|
||||
file_put_contents($png_cached, $png);
|
||||
return room_qr_code_path_relative($room_id);
|
||||
}
|
||||
|
||||
file_exists($QR_CODES) or mkdir($QR_CODES, 0700);
|
||||
?>
|
@ -1,46 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @var CommunityRoom[] $rooms
|
||||
*/
|
||||
|
||||
function room_qr_code_cached($room_id) {
|
||||
global $QR_CODES;
|
||||
return "$QR_CODES/$room_id.png";
|
||||
}
|
||||
require_once "$PROJECT_ROOT/php/utils/room-invites.php";
|
||||
?>
|
||||
|
||||
/**
|
||||
* Fetch QR codes from SOGS server and encode them as base64
|
||||
* @param CommunityRoom $room
|
||||
*/
|
||||
function base64_qr_code($room, $size = "512x512") {
|
||||
$room_id = $room->get_room_identifier();
|
||||
$png_cached = room_qr_code_cached($room_id);
|
||||
if (file_exists($png_cached)) {
|
||||
return base64_encode(file_get_contents($png_cached));
|
||||
}
|
||||
log_debug("Fetching QR code for $room_id.");
|
||||
$png = file_get_contents($room->get_invite_url());
|
||||
file_put_contents($png_cached, $png);
|
||||
return base64_encode($png);
|
||||
}
|
||||
<dialog id="details-modal">
|
||||
<div id="details-modal-contents">
|
||||
<div id="details-modal-close">
|
||||
×
|
||||
</div>
|
||||
<div id="details-modal-start">
|
||||
<h1 id="details-modal-title">
|
||||
<a
|
||||
id="details-modal-community-name"
|
||||
data-hydrate-with="name;preview_link:href"
|
||||
title="Open preview in new tab"
|
||||
></a>
|
||||
</h1>
|
||||
<p id="details-modal-description">
|
||||
<span>Description:</span>
|
||||
<span id="details-modal-description-inner" data-hydrate-with="description"></span>
|
||||
</p>
|
||||
<gap></gap>
|
||||
<div id="details-modal-room-info">
|
||||
<p>
|
||||
Language: <span data-hydrate-with="language_flag"></span>
|
||||
</p>
|
||||
<p>
|
||||
Users: <span data-hydrate-with="users"></span>
|
||||
</p>
|
||||
<p>
|
||||
Server:
|
||||
<a
|
||||
title="Open server in new tab"
|
||||
data-hydrate-with="hostname;hostname:href"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
></a>
|
||||
</p>
|
||||
|
||||
file_exists($QR_CODES) or mkdir($QR_CODES, 0700);
|
||||
?>
|
||||
<p>
|
||||
<button
|
||||
id="details-modal-copy-button"
|
||||
data-hydrate-with="join_link:data-href"
|
||||
title="Click here to copy this Community's join link"
|
||||
>
|
||||
Copy join link
|
||||
</button>
|
||||
|
||||
<div id="modal-container">
|
||||
<?php foreach ($rooms as $room): ?>
|
||||
<div id="modal_<?=$room->get_room_identifier()?>" class="qr-code-modal">
|
||||
<div class="qr-code-modal-content">
|
||||
<span class="qr-code-modal-close">
|
||||
×
|
||||
</span>
|
||||
<button
|
||||
id="details-modal-copy-staff-id"
|
||||
data-hydrate-with="staff:data-staff"
|
||||
title="Copy the mention for a random staff member"
|
||||
>
|
||||
Copy mod ID
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<gap></gap>
|
||||
<div id="details-modal-end">
|
||||
<img
|
||||
src="data:image/png;base64,<?=base64_qr_code($room)?>"
|
||||
alt="Community join link encoded as QR code"
|
||||
class="qr-code"
|
||||
loading="lazy"
|
||||
src=""
|
||||
id="details-modal-qr-code"
|
||||
title="Community join link encoded as QR code"
|
||||
>
|
||||
<div id="details-modal-qr-code-label">
|
||||
Scan QR code in Session to join
|
||||
<br>
|
||||
'<span data-hydrate-with="name"></span>'
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
|
Loading…
Reference in New Issue