You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sessioncommunities.online/sites/+components/qr_modals.php

47 lines
1.1 KiB
PHP

<?php
/**
* @var CommunityRoom[] $rooms
*/
function room_qr_code_cached($room_id) {
global $QR_CODES;
return "$QR_CODES/$room_id.png";
}
/**
* 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);
}
file_exists($QR_CODES) or mkdir($QR_CODES, 0700);
?>
<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">
&times;
</span>
<img
src="data:image/png;base64,<?=base64_qr_code($room)?>"
alt="Community join link encoded as QR code"
class="qr-code"
loading="lazy"
>
</div>
</div>
<?php endforeach; ?>
</div>