landing.php

main 174 lines · 5.1 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2/**
3 * Title: Landing Page
4 * Icon: fa-flag
5 * Group: Content
6 * Order: 8
7 * Description: Show a standalone page from landing/ instead of the front page.
8 */
9
10if (!defined('ACP_ROOT')) {
11 http_response_code(403);
12 die('Direct access denied.');
13}
14
15if ($_SERVER['REQUEST_METHOD'] === 'POST') {
16
17 $enabled = empty($_POST['enabled']) ? '' : '1';
18 $file = trim((string)($_POST['file'] ?? ''));
19
20 if ($file !== '' && !landing_is_valid_file($file)) {
21 acp_flash_error(t('acp.land.bad_file'));
22 acp_redirect('landing');
23 }
24
25 if ($enabled === '1') {
26 if (!is_dir(landing_root())) {
27 acp_flash_error(t('acp.land.no_folder', ['folder' => '<code>landing/</code>']));
28 acp_redirect('landing');
29 }
30 if ($file === '' || !is_file(landing_root() . '/' . $file)) {
31 acp_flash_error(t('acp.land.pick_page', ['folder' => '<code>landing/</code>']));
32 acp_redirect('landing');
33 }
34 }
35
36 setting_set('landing.enabled', $enabled);
37 setting_set('landing.file', $file);
38
39 acp_log('landing.toggle', $file, ['enabled' => $enabled === '1']);
40
41 acp_flash_success($enabled === '1'
42 ? t('acp.land.live', ['path' => '<code>landing/' . h($file) . '</code>'])
43 : t('acp.land.off'));
44
45 acp_redirect('landing');
46}
47
48$files = landing_available_files();
49$hasFolder = is_dir(landing_root());
50$enabled = landing_enabled();
51$current = landing_file();
52$live = landing_ready();
53?>
54
55<div class="acp-toolbar">
56 <div>
57 <?php if ($live): ?>
58 <span class="acp-pill acp-pill--green"><?= t('acp.land.live_pill') ?></span>
59 <?php elseif ($enabled): ?>
60 <span class="acp-pill acp-pill--red"><?= t('acp.land.missing_pill') ?></span>
61 <?php else: ?>
62 <span class="acp-pill acp-pill--grey"><?= t('acp.land.off_pill') ?></span>
63 <?php endif; ?>
64 </div>
65 <div class="acp-actions is-tight">
66 <a class="acp-btn acp-btn--ghost acp-btn--sm" href="<?= h(acp_site()) ?>" target="_blank" rel="noopener">
67 <i class="fa fa-external-link"></i> <?= t('acp.land.open_site') ?>
68 </a>
69 <a class="acp-btn acp-btn--ghost acp-btn--sm" href="<?= h(acp_site('index.php?site=1')) ?>" target="_blank" rel="noopener">
70 <i class="fa fa-sign-in"></i> <?= t('acp.land.skip') ?>
71 </a>
72 </div>
73</div>
74
75<div class="acp-grid acp-grid--2">
76
77 <section class="acp-card">
78 <header class="acp-card-head">
79 <h2><?= t('acp.land.title') ?></h2>
80 <p><?= t('acp.land.sub') ?></p>
81 </header>
82 <div class="acp-card-body">
83
84 <?php if (!$hasFolder): ?>
85 <div class="acp-flash acp-flash--error">
86 <i class="fa fa-exclamation-triangle"></i>
87 <span><?= t('acp.land.no_folder_flash', [
88 'folder' => '<code>landing/</code>',
89 'index' => '<code>index.html</code>',
90 'indexphp' => '<code>index.php</code>',
91 ]) ?></span>
92 </div>
93 <?php elseif (!$files): ?>
94 <div class="acp-flash acp-flash--error">
95 <i class="fa fa-exclamation-triangle"></i>
96 <span><?= t('acp.land.no_pages_flash', [
97 'folder' => '<code>landing/</code>',
98 'html' => '<code>.html</code>',
99 'php' => '<code>.php</code>',
100 ]) ?></span>
101 </div>
102 <?php endif; ?>
103
104 <form method="post">
105 <?= acp_csrf_field() ?>
106
107 <div class="acp-field">
108 <label class="acp-label" for="file"><?= t('acp.land.page_to_show') ?></label>
109 <select class="acp-select" id="file" name="file" <?= $files ? '' : 'disabled' ?>>
110 <?php if (!$files): ?>
111 <option value=""><?= t('acp.land.nothing_yet') ?></option>
112 <?php endif; ?>
113 <?php foreach ($files as $name): ?>
114 <option value="<?= h($name) ?>" <?= $name === $current ? 'selected' : '' ?>>
115 <?= h('landing/' . $name) ?>
116 </option>
117 <?php endforeach; ?>
118 </select>
119 </div>
120
121 <div class="acp-field">
122 <label style="display:flex;align-items:center;gap:8px;font-weight:400;">
123 <input type="checkbox" name="enabled" value="1" <?= $enabled ? 'checked' : '' ?>>
124 <span><?= t('acp.land.show_at_root') ?></span>
125 </label>
126 </div>
127
128 <div class="acp-actions">
129 <button class="acp-btn acp-btn--green" type="submit">
130 <i class="fa fa-check"></i> <?= t('acp.land.save') ?>
131 </button>
132 </div>
133 </form>
134 </div>
135 </section>
136
137 <section class="acp-card">
138 <header class="acp-card-head">
139 <h2><?= t('acp.land.behaves_title') ?></h2>
140 <p><?= t('acp.land.behaves_sub') ?></p>
141 </header>
142 <div class="acp-card-body">
143 <table class="acp-table">
144 <tbody>
145 <tr>
146 <td><?= t('acp.land.col_folder') ?></td>
147 <td><code><?= h(ZNOTE_LANDING_DIR) ?>/</code> <?= $hasFolder ? '' : '<em>' . t('acp.land.missing_suffix') . '</em>' ?></td>
148 </tr>
149 <tr>
150 <td><?= t('acp.land.col_pages') ?></td>
151 <td><?= $files ? h(implode(', ', $files)) : '&mdash;' ?></td>
152 </tr>
153 <tr>
154 <td><?= t('acp.land.col_way_in') ?></td>
155 <td><code>index.php?site=1</code></td>
156 </tr>
157 </tbody>
158 </table>
159
160 <p class="acp-hint">
161 <?= t('acp.land.hint1') ?>
162 </p>
163 <p class="acp-hint">
164 <?= t('acp.land.hint2', [
165 'base' => '<code>&lt;base&gt;</code>',
166 'folder' => '<code>' . h(ZNOTE_LANDING_DIR) . '/</code>',
167 'link' => '<code>&lt;a href="/index.php?site=1"&gt;Enter&lt;/a&gt;</code>',
168 ]) ?>
169 </p>
170 </div>
171 </section>
172
173</div>
174
Top