- Implemented:
Added view_count database migration/defaults and shared helpers in [includes/db.php](/Users/tyemeclifford/Documents/GH/mediaplayer/includes/db.php). Public player and embed.php now increment views. Homepage and catalogue can display per-video views, total views, and public stats based on admin settings. Added Admin → Settings toggles for public view/stat display. Added Admin → Upkeeping action to restore external view counts from readable provider pages, with YouTube scraping support first. Added manual per-video view-count editing in [admin/edit.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/edit.php) for older local uploads or corrections. Updated [README.md](/Users/tyemeclifford/Documents/GH/mediaplayer/README.md) with the new behavior.
This commit is contained in:
@@ -14,11 +14,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$site_sub = trim($_POST['site_sub'] ?? 'tyclifford.com / media');
|
||||
$url_mode = $_POST['url_rewrite_mode'] ?? 'pretty';
|
||||
if (!in_array($url_mode, ['pretty', 'query'], true)) $url_mode = 'pretty';
|
||||
$show_video_views = isset($_POST['public_show_video_views']) ? '1' : '0';
|
||||
$show_total_views = isset($_POST['public_show_total_views']) ? '1' : '0';
|
||||
$show_page_stats = isset($_POST['public_show_page_stats']) ? '1' : '0';
|
||||
|
||||
set_setting('catalogue_per_page', (string)$per_page);
|
||||
set_setting('site_title', $site_title);
|
||||
set_setting('site_sub', $site_sub);
|
||||
set_setting('url_rewrite_mode', $url_mode);
|
||||
set_setting('public_show_video_views', $show_video_views);
|
||||
set_setting('public_show_total_views', $show_total_views);
|
||||
set_setting('public_show_page_stats', $show_page_stats);
|
||||
$msg = 'Settings saved.';
|
||||
}
|
||||
|
||||
@@ -44,11 +50,15 @@ $per_page = setting('catalogue_per_page', '10');
|
||||
$site_title = setting('site_title', 'Ty Clifford');
|
||||
$site_sub = setting('site_sub', 'tyclifford.com / media');
|
||||
$url_rewrite_mode = url_rewrite_mode();
|
||||
$public_show_video_views = setting_bool('public_show_video_views', true);
|
||||
$public_show_total_views = setting_bool('public_show_total_views', true);
|
||||
$public_show_page_stats = setting_bool('public_show_page_stats', true);
|
||||
|
||||
// DB stats
|
||||
$db = get_db();
|
||||
$total_videos = $db->query("SELECT COUNT(*) FROM videos")->fetchColumn();
|
||||
$total_sources = $db->query("SELECT COUNT(*) FROM video_sources")->fetchColumn();
|
||||
$total_views = total_video_views(false);
|
||||
$db_size = file_exists(DB_PATH) ? round(filesize(DB_PATH)/1024, 1) : 0;
|
||||
$media_size = 0;
|
||||
if (is_dir(MEDIA_DIR)) {
|
||||
@@ -76,6 +86,11 @@ render_head('Settings — Admin', '
|
||||
.stat-tile { background:var(--surface-2); border:1px solid var(--border); border-radius:var(--r); padding:1rem; display:flex; flex-direction:column; gap:.3rem; }
|
||||
.stat-val { font-family:"Share Tech Mono",monospace; font-size:1.4rem; color:var(--text); font-weight:700; }
|
||||
.stat-label{ font-family:"Share Tech Mono",monospace; font-size:.6rem; letter-spacing:.1em; text-transform:uppercase; color:var(--text-3); }
|
||||
.option-list { display:grid; grid-template-columns:1fr; gap:.65rem; margin:0 0 1rem; }
|
||||
@media(min-width:700px) { .option-list { grid-template-columns:repeat(3,1fr); } }
|
||||
.check-option { display:flex; align-items:flex-start; gap:.55rem; background:var(--surface-2); border:1px solid var(--border); border-radius:var(--r); padding:.75rem; color:var(--text-2); font-size:.78rem; line-height:1.45; }
|
||||
.check-option input { margin-top:.15rem; accent-color:var(--purple); }
|
||||
.check-option strong { display:block; color:var(--text); font-size:.8rem; margin-bottom:.1rem; }
|
||||
');
|
||||
?>
|
||||
<main class="page" role="main">
|
||||
@@ -135,6 +150,10 @@ render_head('Settings — Admin', '
|
||||
<span class="stat-val"><?= $total_sources ?></span>
|
||||
<span class="stat-label">Sources</span>
|
||||
</div>
|
||||
<div class="stat-tile">
|
||||
<span class="stat-val"><?= h(format_count((int)$total_views)) ?></span>
|
||||
<span class="stat-label">Views</span>
|
||||
</div>
|
||||
<div class="stat-tile">
|
||||
<span class="stat-val"><?= $db_size ?> KB</span>
|
||||
<span class="stat-label">Database</span>
|
||||
@@ -177,6 +196,30 @@ render_head('Settings — Admin', '
|
||||
<span class="hint">Default routes are /v/<slug>, /all, and /search/<query>. Pretty URLs require Apache mod_rewrite and the included .htaccess.</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="form-label" style="margin-bottom:.55rem;">Public Display</p>
|
||||
<div class="option-list">
|
||||
<label class="check-option">
|
||||
<input type="checkbox" name="public_show_video_views" value="1" <?= $public_show_video_views ? 'checked' : '' ?>>
|
||||
<span>
|
||||
<strong>Video view counts</strong>
|
||||
Show each video's view count on public cards and the player.
|
||||
</span>
|
||||
</label>
|
||||
<label class="check-option">
|
||||
<input type="checkbox" name="public_show_total_views" value="1" <?= $public_show_total_views ? 'checked' : '' ?>>
|
||||
<span>
|
||||
<strong>Total view count</strong>
|
||||
Show the combined public view total.
|
||||
</span>
|
||||
</label>
|
||||
<label class="check-option">
|
||||
<input type="checkbox" name="public_show_page_stats" value="1" <?= $public_show_page_stats ? 'checked' : '' ?>>
|
||||
<span>
|
||||
<strong>Page statistics</strong>
|
||||
Show public library stats on the homepage and catalogue.
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<button class="btn btn-primary btn-sm" type="submit">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/><polyline points="17,21 17,13 7,13 7,21"/><polyline points="7,3 7,8 15,8"/></svg>
|
||||
Save Settings
|
||||
|
||||
Reference in New Issue
Block a user