v1.0.0.8
Publisium
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/includes/config.php';
- require_once __DIR__ . '/includes/database.php';
- require_once __DIR__ . '/includes/user-auth.php';
- require_once __DIR__ . '/includes/csrf.php';
- require_once __DIR__ . '/includes/language.php';
- require_once __DIR__ . '/includes/site-front.php';
- require_once __DIR__ . '/includes/currency.php';
-
- UserAuth::boot();
- UserAuth::requireLogin();
-
- $reader = UserAuth::user();
- $settings = SiteFront::settings();
- $flashMessage = null;
-
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- if (!Csrf::verify($_POST['csrf_token'] ?? null)) {
- $flashMessage = Language::get('auth_session_expired', 'Your session expired. Please try again.');
- } else {
- $flashMessage = require __DIR__ . '/dashboard-actions/save-account.php';
- $reader = UserAuth::user();
- }
- }
-
- $subscriptionsStatement = Database::users()->prepare(
- 'SELECT * FROM subscriptions WHERE user_account_id = :id ORDER BY created_at DESC'
- );
- $subscriptionsStatement->execute(['id' => $reader['id']]);
- $subscriptions = $subscriptionsStatement->fetchAll();
-
- $consentsStatement = Database::users()->prepare(
- 'SELECT consent_type, is_granted FROM user_consents WHERE user_account_id = :id'
- );
- $consentsStatement->execute(['id' => $reader['id']]);
- $consentRows = $consentsStatement->fetchAll();
- $consents = [];
- foreach ($consentRows as $row) {
- $consents[$row['consent_type']] = (bool) $row['is_granted'];
- }
-
- $pageTitle = Language::get('account_profile', 'Profile') . ' - ' . $settings['site_name'];
- $showBanner = false;
-
- require __DIR__ . '/includes/front-header.php';
-
- ?>
- <h1 class="article-title"><?= htmlspecialchars(Language::get('account_profile', 'Profile')) ?></h1>
-
- <?php if ($flashMessage !== null): ?>
- <p style="color: var(--accent);"><?= htmlspecialchars($flashMessage) ?></p>
- <?php endif; ?>
-
- <form method="post" style="max-width:420px;margin-bottom:32px;">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="update_profile">
- <label><?= htmlspecialchars(Language::get('auth_display_name', 'Display name')) ?></label>
- <input type="text" name="display_name" value="<?= htmlspecialchars($reader['display_name'] ?? '') ?>" style="width:100%;padding:10px;border-radius:8px;border:1px solid var(--border);background:var(--panel);color:var(--text);margin:6px 0 14px;">
- <label><?= htmlspecialchars(Language::get('account_new_password', 'New password (leave empty to keep your current one)')) ?></label>
- <input type="password" name="new_password" minlength="8" style="width:100%;padding:10px;border-radius:8px;border:1px solid var(--border);background:var(--panel);color:var(--text);margin:6px 0 14px;">
- <button type="submit" class="unlock-btn" style="border:none;cursor:pointer;"><?= htmlspecialchars(Language::get('account_save', 'Save changes')) ?></button>
- </form>
-
- <h2><?= htmlspecialchars(Language::get('account_subscriptions', 'Subscriptions')) ?></h2>
- <ul>
- <?php foreach ($subscriptions as $subscription): ?>
- <?php $subscriptionEnd = !empty($subscription['current_period_end']) ? strtotime((string) $subscription['current_period_end']) : false; ?>
- <li><?= htmlspecialchars($settings['subscription_name'] !== '' ? $settings['subscription_name'] : ucfirst((string) $subscription['provider'])) ?> (<?= htmlspecialchars(Language::get('subscription_status_' . $subscription['status'], ucfirst(str_replace('_', ' ', (string) $subscription['status'])))) ?>)<?php if ($subscriptionEnd !== false): ?>, <?= htmlspecialchars(str_replace('{date}', date('Y-m-d', $subscriptionEnd), Language::get('account_subscription_until', 'until {date}'))) ?><?php endif; ?></li>
- <?php endforeach; ?>
- <?php if (empty($subscriptions)): ?>
- <li><?= htmlspecialchars(Language::get('account_no_subscriptions', 'You don’t have any subscriptions yet.')) ?></li>
- <?php endif; ?>
- </ul>
-
- <?php if ($settings['subscription_checkout_url'] !== '' && !UserAuth::hasActiveSubscription((int) $reader['id'])): ?>
- <?php
- $offerPrice = Currency::format((int) $settings['subscription_price_cents'], (string) $settings['subscription_currency']);
- $offerInterval = (string) $settings['subscription_interval'];
- ?>
- <div class="subscription-offer account-subscription-offer">
- <div class="subscription-offer-name"><?= htmlspecialchars($settings['subscription_name']) ?></div>
- <div class="subscription-offer-price"><?= htmlspecialchars($offerInterval === 'lifetime'
- ? $offerPrice . ' · ' . Language::get('subscription_one_time', 'one-time payment')
- : $offerPrice . ' / ' . ($offerInterval === 'year' ? Language::get('subscription_per_year', 'year') : Language::get('subscription_per_month', 'month'))) ?></div>
- <?php if ($settings['subscription_description'] !== ''): ?>
- <p class="subscription-offer-description"><?= htmlspecialchars($settings['subscription_description']) ?></p>
- <?php endif; ?>
- <a href="<?= htmlspecialchars(SiteFront::subscriptionCheckoutUrl((string) $reader['email'])) ?>" class="unlock-btn"><?= htmlspecialchars($offerInterval === 'lifetime' ? Language::get('article_buy_lifetime_button', 'Get lifetime access') : Language::get('article_subscribe_button', 'Subscribe')) ?></a>
- <p class="account-subscription-note"><?= htmlspecialchars(str_replace('{email}', (string) $reader['email'], Language::get('account_subscription_email_note', 'Pay with {email} so the subscription is linked to this account.'))) ?></p>
- </div>
- <?php endif; ?>
-
- <?php if ($settings['account_consents_enabled'] === '1'): ?>
- <h2><?= htmlspecialchars(Language::get('account_consents', 'Privacy consents')) ?></h2>
- <form method="post" style="max-width:420px;">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="update_consents">
- <label style="display:block;margin:0 0 10px;"><input type="checkbox" name="consent_analytics" <?= !empty($consents['analytics']) ? 'checked' : '' ?>> <?= htmlspecialchars(Language::get('account_consent_analytics', 'Allow analytics, so we can see which articles people read')) ?></label>
- <label style="display:block;margin:0 0 10px;"><input type="checkbox" name="consent_ads_personalization" <?= !empty($consents['ads_personalization']) ? 'checked' : '' ?>> <?= htmlspecialchars(Language::get('account_consent_ads', 'Allow personalized ads')) ?></label>
- <button type="submit" class="unlock-btn" style="border:none;cursor:pointer;margin-top:14px;"><?= htmlspecialchars(Language::get('account_save', 'Save changes')) ?></button>
- </form>
- <?php endif; ?>
-
- <?php require __DIR__ . '/includes/front-footer.php'; ?>
-