Skip to content

Commit

Permalink
feat: add maintenance tasks to admin page
Browse files Browse the repository at this point in the history
feat: add support to upload svg logos
  • Loading branch information
ellite authored Jul 9, 2024
1 parent c4ba1a7 commit 9f7f47b
Show file tree
Hide file tree
Showing 25 changed files with 435 additions and 178 deletions.
70 changes: 70 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,76 @@ class="one-third" value="<?= $settings['smtp_port'] ?>" />
</div>
</section>

<?php
// find unused upload logos

// Get all logos in the subscriptions table
$query = 'SELECT logo FROM subscriptions';
$stmt = $db->prepare($query);
$result = $stmt->execute();

$logosOnDB = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$logosOnDB[] = $row['logo'];
}

// Get all logos in the payment_methods table
$query = 'SELECT icon FROM payment_methods';
$stmt = $db->prepare($query);
$result = $stmt->execute();

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
if (!strstr($row['icon'], "images/uploads/icons/")) {
$logosOnDB[] = $row['icon'];
}
}

$logosOnDB = array_unique($logosOnDB);

// Get all logos in the uploads folder
$uploadDir = 'images/uploads/logos/';
$uploadFiles = scandir($uploadDir);

foreach ($uploadFiles as $file) {
if ($file != '.'&& $file != '..' && $file != 'avatars') {
$logosOnDisk[] = ['logo' => $file];
}
}

// Find unused logos
$unusedLogos = [];
foreach ($logosOnDisk as $disk) {
$found = false;
foreach ($logosOnDB as $dbLogo) {
if ($disk['logo'] == $dbLogo) {
$found = true;
break;
}
}
if (!$found) {
$unusedLogos[] = $disk;
}
}

$logosToDelete = count($unusedLogos);

?>

<section class="account-section">
<header>
<h2>
<?= translate('maintenance_tasks', $i18n) ?>
</h2>
</header>
<div class="maintenance-tasks">
<h3><?= translate('orphaned_logos', $i18n) ?></h3>
<div class="form-group-inline">
<input type="button" class="button thin mobile-grow" value="<?= translate('delete', $i18n) ?>" id="deleteUnusedLogos"
onClick="deleteUnusedLogos()" <?= $logosToDelete == 0 ? 'disabled' : '' ?> />
<span class="number-of-logos bold"><?= $logosToDelete ?></span> <?= translate('orphaned_logos', $i18n) ?>
</div>
</div>
</section>

<section class="account-section">
<header>
Expand Down
76 changes: 76 additions & 0 deletions endpoints/admin/deleteunusedlogos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

require_once '../../includes/connect_endpoint.php';

if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
die(json_encode([
"success" => false,
"message" => translate('session_expired', $i18n)
]));
}

// Check that user is an admin
if ($userId !== 1) {
die(json_encode([
"success" => false,
"message" => translate('error', $i18n)
]));
}

$query = 'SELECT logo FROM subscriptions';
$stmt = $db->prepare($query);
$result = $stmt->execute();

$logosOnDB = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$logosOnDB[] = $row['logo'];
}

$logosOnDB = array_unique($logosOnDB);

$uploadDir = '../../images/uploads/logos/';
$uploadFiles = scandir($uploadDir);

foreach ($uploadFiles as $file) {
if ($file != '.' && $file != '..' && $file != 'avatars') {
$logosOnDisk[] = ['logo' => $file];
}
}

// Get all logos in the payment_methods table
$query = 'SELECT icon FROM payment_methods';
$stmt = $db->prepare($query);
$result = $stmt->execute();

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
if (!strstr($row['icon'], "images/uploads/icons/")) {
$logosOnDB[] = $row['icon'];
}
}

$logosOnDB = array_unique($logosOnDB);

// Find and delete unused logos
$count = 0;
foreach ($logosOnDisk as $disk) {
foreach ($logosOnDB as $db) {
$found = false;
if ($disk['logo'] == $db) {
$found = true;
break;
}
}
if (!$found) {
unlink($uploadDir . $disk['logo']);
$count++;
}
}

echo json_encode([
"success" => true,
"message" => translate('success', $i18n),
'count' => $count
]);


?>
2 changes: 2 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Benutzer erstellen",
"smtp_settings" => "SMTP Einstellungen",
"smtp_usage_info" => "Wird für die Passwortwiederherstellung und andere System-E-Mails verwendet",
"maintenance_tasks" => "Wartungsaufgaben",
"orphaned_logos" => "Verwaiste Logos",
// Email Verification
"email_verified" => "E-Mail verifiziert",
"email_verification_failed" => "E-Mail konnte nicht verifiziert werden",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Δημιουργία χρήστη",
"smtp_settings" => "SMTP ρυθμίσεις",
"smtp_usage_info" => "Θα χρησιμοποιηθεί για ανάκτηση κωδικού πρόσβασης και άλλα μηνύματα ηλεκτρονικού ταχυδρομείου συστήματος.",
"maintenance_tasks" => "Εργασίες συντήρησης",
"orphaned_logos" => "Ορφανά λογότυπα",
// Email Verification
"email_verified" => "Το email επιβεβαιώθηκε",
"email_verification_failed" => "Η επαλήθευση email απέτυχε",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Create User",
"smtp_settings" => "SMTP Settings",
"smtp_usage_info" => "Will be used for password recovery and other system emails.",
"maintenance_tasks" => "Maintenance Tasks",
"orphaned_logos" => "Orphaned Logos",
// Email Verification
"email_verified" => "Email verified successfully",
"email_verification_failed" => "Email verification failed",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Crear Usuario",
"smtp_settings" => "Configuración SMTP",
"smtp_usage_info" => "Se utilizará para recuperar contraseñas y otros correos electrónicos del sistema.",
"maintenance_tasks" => "Tareas de Mantenimiento",
"orphaned_logos" => "Logotipos huérfanos",
// Email Verification
"email_verified" => "Correo electrónico verificado",
"email_verification_failed" => "Error al verificar el correo electrónico",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Créer un utilisateur",
"smtp_settings" => "Paramètres SMTP",
"smtp_usage_info" => "Sera utilisé pour la récupération du mot de passe et d'autres e-mails système.",
"maintenance_tasks" => "Tâches de maintenance",
"orphaned_logos" => "Logos orphelins",
// Email Verification
"email_verified" => "Votre adresse courriel a été vérifiée avec succès",
"email_verification_failed" => "La vérification de l'adresse courriel a échoué",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@
"create_user" => "Crea utente",
"smtp_settings" => "Impostazioni SMTP",
"smtp_usage_info" => "Verrà utilizzato per il recupero della password e altre e-mail di sistema.",
"maintenance_tasks" => "Compiti di manutenzione",
"orphaned_logos" => "Loghi orfani",

// Email Verification
"email_verified" => "L'indirizzo email è stato verificato con successo",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "ユーザーを作成",
"smtp_settings" => "SMTP設定",
"smtp_usage_info" => "パスワードの回復やその他のシステム電子メールに使用されます。",
"maintenance_tasks" => "メンテナンスタスク",
"orphaned_logos" => "孤立したロゴ",
// Email Verification
"email_verified" => "メールアドレスが確認されました",
"email_verification_failed" => "メールアドレスの確認に失敗しました",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/ko.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@
"create_user" => "유저 생성",
"smtp_settings" => "SMTP 설정",
"smtp_usage_info" => "비밀번호 복구 및 기타 시스템 이메일에 사용됩니다.",
"maintenance_tasks" => "유지보수 작업",
"orphaned_logos" => "고아 로고",
// Email Verification
"email_verified" => "이메일 인증 완료",
"email_verification_failed" => "이메일 인증 실패",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/pl.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Utwórz użytkownika",
"smtp_settings" => "Ustawienia SMTP",
"smtp_usage_info" => "Będzie używany do odzyskiwania hasła i innych e-maili systemowych.",
"maintenance_tasks" => "Zadania konserwacyjne",
"orphaned_logos" => "Osierocone logo",
// Email Verification
"email_verified" => "E-mail został zweryfikowany",
"email_verification_failed" => "Weryfikacja e-maila nie powiodła się",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Criar Utilizador",
"smtp_settings" => "Definições SMTP",
"smtp_usage_info" => "Será usado para recuperações de password e outros emails do sistema.",
"maintenance_tasks" => "Tarefas de Manutenção",
"orphaned_logos" => "Logos Órfãos",
// Email Verification
"email_verified" => "Email verificado",
"email_verification_failed" => "Verificação de email falhou",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/pt_br.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Criar usuário",
"smtp_settings" => "Configurações SMTP",
"smtp_usage_info" => "Será usado para recuperação de senha e outros e-mails do sistema.",
"maintenance_tasks" => "Tarefas de manutenção",
"orphaned_logos" => "Logos órfãos",
// Email Verification
"email_verified" => "Email verificado",
"email_verification_failed" => "Falha na verificação do email",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Создать пользователя",
"smtp_settings" => "Настройки SMTP",
"smtp_usage_info" => "Будет использоваться для восстановления пароля и других системных писем.",
"maintenance_tasks" => "Задачи обслуживания",
"orphaned_logos" => "Одинокие логотипы",
// Email Verification
"email_verified" => "Ваш адрес электронной почты подтвержден. Теперь вы можете войти.",
"email_verification_failed" => "Не удалось подтвердить ваш адрес электронной почты.",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/sl.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Ustvari uporabnika",
"smtp_settings" => "Nastavitve SMTP",
"smtp_usage_info" => "Uporabljeno bo za obnovitev gesla in druge sistemske e-pošte.",
"maintenance_tasks" => "Vzdrževalne naloge",
"orphaned_logos" => "Osamljeni logotipi",
// Email Verification
"email_verified" => "E-pošta je bila uspešno preverjena",
"email_verification_failed" => "Preverjanje e-pošte ni uspelo",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/sr.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Креирај корисника",
"smtp_settings" => "SMTP подешавања",
"smtp_usage_info" => "SMTP се користи за слање е-поште за обавештења.",
"maintenance_tasks" => "Одржавање",
"orphaned_logos" => "Породични логотипови",
// Email Verification
"email_verified" => "Е-пошта је верификована",
"email_verification_failed" => "Верификација е-поште није успела",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/sr_lat.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Kreiraj korisnika",
"smtp_settings" => "SMTP podešavanja",
"smtp_usage_info" => "Koristiće se za oporavak lozinke i druge sistemske e-poruke.",
"maintenance_tasks" => "Održavanje",
"orphaned_logos" => "Nepovezani logotipi",
// Email Verification
"email_verified" => "E-pošta je uspešno verifikovana",
"email_verification_failed" => "Verifikacija e-pošte nije uspela",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/tr.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "Kullanıcı Oluştur",
"smtp_settings" => "SMTP Ayarları",
"smtp_usage_info" => "Şifre kurtarma ve diğer sistem e-postaları için kullanılacaktır.",
"maintenance_tasks" => "Bakım Görevleri",
"orphaned_logos" => "Yetim Logolar",
// Email Verification
"email_verified" => "E-posta doğrulandı",
"email_verification_failed" => "E-posta doğrulaması başarısız oldu",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/zh_cn.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@
"create_user" => "创建用户",
"smtp_settings" => "SMTP 设置",
"smtp_usage_info" => "将用于密码恢复和其他系统电子邮件。",
"maintenance_tasks" => "维护任务",
"orphaned_logos" => "孤立的 Logo",

// Email Verification
"email_verified" => "电子邮件已验证",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/zh_tw.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
"create_user" => "建立使用者",
"smtp_settings" => "SMTP 設定",
"smtp_usage_info" => "將用於密碼恢復和其他系統電子郵件。",
"maintenance_tasks" => "維護任務",
"orphaned_logos" => "孤立的圖示",
// Email Verification
"email_verified" => "電子郵件已驗證",
"email_verification_failed" => "電子郵件驗證失敗",
Expand Down
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v2.14.2";
$version = "v2.15.0";
?>
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
<label for="logo" class="logo-preview">
<img src="" alt="<?= translate('logo_preview', $i18n) ?>" id="form-logo">
</label>
<input type="file" id="logo" name="logo" accept="image/jpeg, image/png, image/gif, image/webp"
<input type="file" id="logo" name="logo" accept="image/jpeg, image/png, image/gif, image/webp, image/svg+xml"
onchange="handleFileSelect(event)" class="hidden-input">
<input type="hidden" id="logo-url" name="logo-url">
<div id="logo-search-button" class="image-button medium disabled" title="<?= translate('search_logo', $i18n) ?>"
Expand Down
22 changes: 22 additions & 0 deletions scripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,26 @@ function addUserButton() {
showErrorMessage(error);
button.disabled = false;
});
}

function deleteUnusedLogos() {
const button = document.getElementById('deleteUnusedLogos');
button.disabled = true;

fetch('endpoints/admin/deleteunusedlogos.php')
.then(response => response.json())
.then(data => {
if (data.success) {
showSuccessMessage(data.message);
const numberOfLogos = document.querySelector('.number-of-logos');
numberOfLogos.innerText = '0';
} else {
showErrorMessage(data.message);
button.disabled = false;
}
})
.catch(error => {
showErrorMessage(error);
button.disabled = false;
});
}
Loading

0 comments on commit 9f7f47b

Please sign in to comment.