PHP Classes

File: public/index.php

Recommend this page to a friend!
  Packages of Adrian M   QuickWP   public/index.php   Download  
File: public/index.php
Role: Application script
Content type: text/plain
Description: Application script
Class: QuickWP
Manage WordPress sites using the REST API
Author: By
Last change: feat(drafts): add Drafts review card, Type/Status filters, and 1-click Publish
feat(i18n): add zero-dependency UI localization (EN/RO) and language switcher
v3.0.1: Gemini auto-endpoint, AI refine existing, and Quick Edit title picker
v3.0-c: add multilingual AI Concierge (Gemini/OpenAI/Ollama), CLI ai:draft, and voice/text dashboard bar
v2.3: add User/Comment/Health services, ACF support, Menus/Comments/Media UI, CSRF session fix, PHPUnit 11 & PHPStan 2
v2.2: refactor services, add retry/pagination, shared UI layout, PHP 8.3+, PHPStan L8, and CI
Date: 12 hours ago
Size: 36,512 bytes
 

 

Contents

Class file image Download
<?php /** * QuickWP v2 - Main Entry Point * * Modern class-based front controller for WordPress Quick Tools. */ require_once __DIR__ . '/partials/bootstrap.php'; use QuickWP\Http\CsrfProtection; $healthCheck = null; if (isset($_GET['check']) && $_GET['check'] === '1') { $healthCheck = $qwp->health()->check(); } $checkUrl = 'index.php?check=1' . $siteParam; $aiResult = null; $aiError = null; $aiConfigured = $config->isAiConfigured(); $aiMode = (string) ($_POST['ai_mode'] ?? 'create'); $aiSaveMode = (string) ($_POST['ai_save_mode'] ?? 'draft_copy'); $aiTargetItem = (string) ($_POST['ai_target_item'] ?? ''); if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'ai_concierge') { if (!CsrfProtection::validate()) { $aiError = $t->get('common.csrf_error'); } else { $prompt = trim((string) ($_POST['ai_prompt'] ?? '')); $aiType = ($_POST['ai_type'] ?? 'post') === 'page' ? 'page' : 'post'; $aiLang = trim((string) ($_POST['ai_lang'] ?? 'auto')); $aiUrl = trim((string) ($_POST['ai_source_url'] ?? '')); if ($aiMode === 'refine') { $parts = explode(':', $aiTargetItem, 2); $targetType = ($parts[0] ?? 'post') === 'page' ? 'page' : 'post'; $targetId = (int) ($parts[1] ?? 0); $res = $qwp->ai()->refineExisting($targetType, $targetId, $prompt, [ 'language' => $aiLang, 'save_mode' => $aiSaveMode, ]); } else { $res = $qwp->ai()->draftFromPrompt($prompt, [ 'type' => $aiType, 'language' => $aiLang, 'source_url' => $aiUrl, 'create_draft' => true, ]); } if (!empty($res['ok'])) { $aiResult = $res; } else { $aiError = (string) ($res['error'] ?? 'AI Concierge request failed.'); } } } // Handle 1-click Publish Draft action $draftMessage = null; $draftError = null; if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'quick_publish') { if (!CsrfProtection::validate()) { $draftError = $t->get('common.csrf_error'); } else { $pubType = ($_POST['item_type'] ?? 'post') === 'page' ? 'page' : 'post'; $pubId = (int) ($_POST['item_id'] ?? 0); if ($pubId > 0) { $pubSvc = $pubType === 'page' ? $qwp->pages() : $qwp->posts(); $pubRes = $pubSvc->update($pubId, ['status' => 'publish']); if (\QuickWP\QuickWP::isSuccess($pubRes)) { $pubLink = \QuickWP\QuickWP::getLink($pubRes); $pubTitle = is_array($pubRes['json']['title'] ?? null) ? ($pubRes['json']['title']['rendered'] ?? '#' . $pubId) : (string) ($pubRes['json']['title'] ?? '#' . $pubId); $qwp->webhooks()->dispatch($pubType . '.published', [ 'id' => $pubId, 'title' => html_entity_decode(strip_tags((string) $pubTitle), ENT_QUOTES, 'UTF-8'), 'link' => $pubLink, 'site' => $siteKey, ]); $draftMessage = $t->get('drafts.published_msg') . ' #' . $pubId . ($pubLink ? ' ? <a href="' . htmlspecialchars($pubLink, ENT_QUOTES, 'UTF-8') . '" target="_blank">' . $t->e('common.view_on_site') . '</a>' : ''); } else { $draftError = \QuickWP\QuickWP::getError($pubRes); } } } } // Fetch recent drafts (posts + pages) for the Dashboard Drafts Review & Publish widget $recentDrafts = []; $draftPostsList = []; $draftPagesList = []; $draftPostsRes = $qwp->posts()->list(['per_page' => 25, 'status' => 'draft', 'context' => 'edit', 'orderby' => 'modified', 'order' => 'desc', '_fields' => 'id,title,status,modified,date']); if (\QuickWP\QuickWP::isSuccess($draftPostsRes) && is_array($draftPostsRes['json'])) { foreach ($draftPostsRes['json'] as $dp) { if ((string) ($dp['status'] ?? '') !== 'draft') { continue; } $dp['_qwp_type'] = 'post'; $recentDrafts[] = $dp; $draftPostsList[] = $dp; } } $draftPagesRes = $qwp->pages()->list(['per_page' => 25, 'status' => 'draft', 'context' => 'edit', 'orderby' => 'modified', 'order' => 'desc', '_fields' => 'id,title,status,modified,date']); if (\QuickWP\QuickWP::isSuccess($draftPagesRes) && is_array($draftPagesRes['json'])) { foreach ($draftPagesRes['json'] as $dpg) { if ((string) ($dpg['status'] ?? '') !== 'draft') { continue; } $dpg['_qwp_type'] = 'page'; $recentDrafts[] = $dpg; $draftPagesList[] = $dpg; } } usort($recentDrafts, static function (array $a, array $b): int { return strcmp((string) ($b['modified'] ?? $b['date'] ?? ''), (string) ($a['modified'] ?? $a['date'] ?? '')); }); // Build unified items list for AI Concierge "Edit / Refine Existing" (guaranteed to include drafts + published) $aiItems = []; if ($aiConfigured) { $seenAi = []; $addAiItems = static function (array $rows, string $type) use (&$aiItems, &$seenAi): void { foreach ($rows as $row) { $id = (int) ($row['id'] ?? 0); if ($id <= 0) { continue; } $key = $type . ':' . $id; if (isset($seenAi[$key])) { continue; } $seenAi[$key] = true; $rawTitle = is_array($row['title'] ?? null) ? ($row['title']['raw'] ?? $row['title']['rendered'] ?? '#' . $id) : ($row['title'] ?? '#' . $id); $cleanTitle = trim(html_entity_decode(strip_tags((string) $rawTitle), ENT_QUOTES, 'UTF-8')); $aiItems[] = [ 'val' => $key, 'id' => $id, 'type' => $type, 'status' => (string) ($row['status'] ?? 'publish'), 'title' => $cleanTitle !== '' ? $cleanTitle : '#' . $id, ]; } }; // Always include fetched drafts first so they are guaranteed available $addAiItems($draftPostsList, 'post'); $addAiItems($draftPagesList, 'page'); // Also include all other statuses (publish, pending, future, private) $postsRes = $qwp->posts()->list(['per_page' => 50, 'status' => 'any', 'context' => 'edit', '_fields' => 'id,title,status']); if (\QuickWP\QuickWP::isSuccess($postsRes) && is_array($postsRes['json'])) { $addAiItems($postsRes['json'], 'post'); } $pagesRes = $qwp->pages()->list(['per_page' => 50, 'status' => 'any', 'context' => 'edit', '_fields' => 'id,title,status']); if (\QuickWP\QuickWP::isSuccess($pagesRes) && is_array($pagesRes['json'])) { $addAiItems($pagesRes['json'], 'page'); } } ?><!DOCTYPE html> <html lang="<?= htmlspecialchars($locale, ENT_QUOTES, 'UTF-8') ?>"> <head> <meta charset="UTF-8"> <title>QuickWP - <?= $t->e('dashboard.subtitle') ?></title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> :root { --primary: #0073aa; --primary-hover: #006298; --bg: #f5f5f5; --card-bg: #fff; --text: #333; --text-muted: #666; --border: #ddd; --success: #46b450; --radius: 8px; } * { box-sizing: border-box; } body { font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; padding: 20px; background: var(--bg); color: var(--text); } .container { max-width: 600px; margin: 0 auto; background: var(--card-bg); padding: 24px 26px; border-radius: var(--radius); box-shadow: 0 2px 6px rgba(0,0,0,0.08); } h1 { font-size: 1.5rem; margin: 0 0 8px; text-align: center; } .subtitle { text-align: center; color: var(--text-muted); margin: 0 0 20px; } .version-badge { display: inline-block; background: var(--success); color: #fff; font-size: 0.7rem; padding: 2px 6px; border-radius: 10px; vertical-align: middle; margin-left: 8px; } .site-select { text-align: center; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); } .site-select form { display: inline-flex; align-items: center; gap: 8px; } .site-select select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 0.95rem; } .actions { display: flex; flex-direction: column; gap: 12px; } a.button { display: block; padding: 14px 16px; border-radius: var(--radius); text-decoration: none; color: #fff; background: var(--primary); font-weight: 600; text-align: center; transition: background 0.2s; } a.button:hover { background: var(--primary-hover); } .button-group { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } @media (max-width: 500px) { .button-group { grid-template-columns: 1fr; } } small { display: block; margin-top: 20px; color: var(--text-muted); text-align: center; font-size: 0.85rem; } .footer-links { margin-top: 16px; text-align: center; font-size: 0.85rem; } .footer-links a { color: var(--primary); text-decoration: none; } .footer-links a:hover { text-decoration: underline; } </style> </head> <body> <div class="container"> <?php if (count($availableLocales) > 1): ?> <div style="text-align: right; margin-bottom: 6px; font-size: 0.78rem;"> <?php $langParams = $_GET; unset($langParams['lang']); foreach ($availableLocales as $loc): $locUrl = '?' . http_build_query(array_merge($langParams, ['lang' => $loc])); ?> <a href="<?= htmlspecialchars($locUrl, ENT_QUOTES, 'UTF-8') ?>" style="display: inline-block; padding: 2px 7px; border-radius: 3px; text-decoration: none; font-weight: 600; <?= $loc === $locale ? 'background: var(--primary); color: #fff;' : 'background: #eef3f7; color: var(--primary);' ?>"> <?= htmlspecialchars(strtoupper($loc), ENT_QUOTES, 'UTF-8') ?> </a> <?php endforeach; ?> </div> <?php endif; ?> <h1>QuickWP <span class="version-badge">v3</span></h1> <p class="subtitle"><?= $t->e('dashboard.subtitle') ?></p> <!-- AI Concierge Command Bar (Text + Voice, Draft-First) --> <div style="margin-bottom: 18px; padding: 14px; border-radius: var(--radius); background: #f0f7fc; border: 1px solid #c3ddf0;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;"> <strong style="font-size: 0.95rem; color: var(--primary);"><?= $t->e('ai.title') ?></strong> <span style="font-size: 0.78rem; color: var(--text-muted);"> <?= $aiConfigured ? htmlspecialchars(strtoupper($config->getAiProvider()) . ' · ' . $config->getAiModel(), ENT_QUOTES, 'UTF-8') : $t->e('ai.not_configured') ?> </span> </div> <?php if ($aiError): ?> <div style="margin-bottom: 10px; padding: 8px 10px; border-radius: 4px; background: #f8d7da; color: #721c24; font-size: 0.85rem;"> <?= htmlspecialchars($aiError, ENT_QUOTES, 'UTF-8') ?> </div> <?php endif; ?> <?php if (is_array($aiResult)): ?> <?php $draftId = (int) ($aiResult['id'] ?? 0); $draftType = (string) ($aiResult['type'] ?? 'post'); $draftTitle = (string) ($aiResult['draft']['title'] ?? 'Untitled'); $draftNotes = (string) ($aiResult['draft']['notes'] ?? ''); $editUrl = 'quick-edit.php?action=load&item_type=' . urlencode($draftType) . '&item_id=' . $draftId . $siteParam; $resultActionLabel = (($aiResult['save_mode'] ?? '') === 'update') ? $t->e('ai.item_updated') : $t->e('ai.draft_created'); ?> <div style="margin-bottom: 10px; padding: 10px 12px; border-radius: 4px; background: #d4edda; color: #155724; font-size: 0.88rem;"> <?= $resultActionLabel ?> #<?= $draftId ?>: <strong><?= htmlspecialchars($draftTitle, ENT_QUOTES, 'UTF-8') ?></strong> <?php if ($draftNotes !== ''): ?> <div style="margin-top: 4px; font-size: 0.8rem; opacity: 0.9;"><?= htmlspecialchars($draftNotes, ENT_QUOTES, 'UTF-8') ?></div> <?php endif; ?> <div style="margin-top: 6px;"> <a href="<?= htmlspecialchars($editUrl, ENT_QUOTES, 'UTF-8') ?>" style="display: inline-block; padding: 5px 10px; border-radius: 4px; background: #155724; color: #fff; text-decoration: none; font-weight: 600; font-size: 0.82rem;"><?= $t->e('ai.open_editor') ?></a> </div> </div> <?php endif; ?> <?php if ($aiConfigured): ?> <form method="post" id="ai-concierge-form"> <?= CsrfProtection::field() ?> <input type="hidden" name="action" value="ai_concierge"> <?php if ($siteKey !== ''): ?> <input type="hidden" name="site" value="<?= htmlspecialchars($siteKey, ENT_QUOTES, 'UTF-8') ?>"> <?php endif; ?> <div style="display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap;"> <select name="ai_mode" id="ai_mode" onchange="toggleAiMode(this.value)" style="padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.84rem; font-weight: 600;"> <option value="create" <?= $aiMode === 'create' ? 'selected' : '' ?>><?= $t->e('ai.mode_create') ?></option> <option value="refine" <?= $aiMode === 'refine' ? 'selected' : '' ?>><?= $t->e('ai.mode_refine') ?></option> </select> <select name="ai_type_filter" id="ai_type_filter" onchange="renderAiTargetOptions()" style="padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.84rem; <?= $aiMode === 'refine' ? '' : 'display:none;' ?>"> <option value="any"><?= $t->e('edit.type') ?>: <?= $t->e('status.all') ?></option> <option value="post"><?= $t->e('nav.post') ?></option> <option value="page"><?= $t->e('nav.page') ?></option> </select> <select name="ai_status_filter" id="ai_status_filter" onchange="renderAiTargetOptions()" style="padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.84rem; <?= $aiMode === 'refine' ? '' : 'display:none;' ?>"> <option value="any"><?= $t->e('common.status') ?>: <?= $t->e('status.all') ?></option> <option value="draft"><?= $t->e('status.draft') ?></option> <option value="publish"><?= $t->e('status.published') ?></option> <option value="future"><?= $t->e('status.future') ?></option> <option value="pending"><?= $t->e('status.pending') ?></option> <option value="private"><?= $t->e('status.private') ?></option> </select> <select name="ai_target_item" id="ai_target_item" style="flex: 1; min-width: 200px; padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.84rem; <?= $aiMode === 'refine' ? '' : 'display:none;' ?>"> <option value=""><?= $t->e('ai.select_existing') ?></option> </select> </div> <div style="display: flex; gap: 6px; margin-bottom: 8px;"> <input type="text" id="ai_prompt" name="ai_prompt" required placeholder="<?= $t->e('ai.prompt_placeholder') ?>" value="<?= htmlspecialchars($_POST['ai_prompt'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="flex: 1; padding: 8px 10px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.9rem;"> <button type="button" id="ai-voice-btn" title="<?= $t->e('ai.voice_title') ?>" style="padding: 8px 11px; border: 1px solid #c3ddf0; border-radius: 4px; background: #fff; cursor: pointer; font-size: 0.95rem;">?</button> </div> <div style="display: flex; gap: 6px; flex-wrap: wrap; align-items: center;"> <input type="url" name="ai_source_url" id="ai_source_url" placeholder="<?= $t->e('ai.source_url_placeholder') ?>" value="<?= htmlspecialchars($_POST['ai_source_url'] ?? '', ENT_QUOTES, 'UTF-8') ?>" style="flex: 1; min-width: 150px; padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.82rem; <?= $aiMode === 'create' ? '' : 'display:none;' ?>"> <select name="ai_save_mode" id="ai_save_mode" style="flex: 1; min-width: 160px; padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.82rem; <?= $aiMode === 'refine' ? '' : 'display:none;' ?>"> <option value="draft_copy" <?= $aiSaveMode === 'draft_copy' ? 'selected' : '' ?>><?= $t->e('ai.save_draft_copy') ?></option> <option value="update" <?= $aiSaveMode === 'update' ? 'selected' : '' ?>><?= $t->e('ai.save_update') ?></option> </select> <select name="ai_lang" id="ai_lang" style="padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.82rem;"> <option value="auto"><?= $t->e('ai.lang_auto') ?></option> <option value="ro">RO</option> <option value="en">EN</option> <option value="de">DE</option> <option value="fr">FR</option> <option value="es">ES</option> </select> <select name="ai_type" id="ai_type" style="padding: 6px 8px; border: 1px solid #c3ddf0; border-radius: 4px; font-size: 0.82rem; <?= $aiMode === 'create' ? '' : 'display:none;' ?>"> <option value="post"><?= $t->e('nav.post') ?></option> <option value="page"><?= $t->e('nav.page') ?></option> </select> <button type="submit" id="ai-submit-btn" style="padding: 7px 14px; border: none; border-radius: 4px; background: var(--primary); color: #fff; font-weight: 600; font-size: 0.85rem; cursor: pointer;"> <?= $aiMode === 'refine' ? $t->e('ai.btn_refine') : $t->e('ai.btn_create') ?> </button> </div> </form> <script> var AI_BTN_CREATE = <?= json_encode($t->get('ai.btn_create')) ?>; var AI_BTN_REFINE = <?= json_encode($t->get('ai.btn_refine')) ?>; var AI_SELECT_PLACEHOLDER = <?= json_encode($t->get('ai.select_existing')) ?>; var AI_TYPE_LABELS = { post: <?= json_encode($t->get('nav.post')) ?>, page: <?= json_encode($t->get('nav.page')) ?> }; var AI_ITEMS = <?= json_encode($aiItems, JSON_UNESCAPED_UNICODE) ?>; var AI_INITIAL_TARGET = <?= json_encode($aiTargetItem) ?>; function renderAiTargetOptions() { var sel = document.getElementById('ai_target_item'); var typeEl = document.getElementById('ai_type_filter'); var statusEl = document.getElementById('ai_status_filter'); if (!sel) return; var typeFilter = typeEl ? typeEl.value : 'any'; var statusFilter = statusEl ? statusEl.value : 'any'; var prevVal = sel.value || AI_INITIAL_TARGET; var filtered = AI_ITEMS.filter(function (item) { var matchType = (typeFilter === 'any' || item.type === typeFilter); var matchStatus = (statusFilter === 'any' || item.status === statusFilter); return matchType && matchStatus; }); sel.innerHTML = ''; var first = document.createElement('option'); first.value = ''; first.textContent = AI_SELECT_PLACEHOLDER + ' (' + filtered.length + ')'; sel.appendChild(first); filtered.forEach(function (item) { var opt = document.createElement('option'); opt.value = item.val; opt.textContent = '#' + item.id + ' [' + (AI_TYPE_LABELS[item.type] || item.type) + ' · ' + item.status + '] ' + item.title; if (item.val === prevVal) opt.selected = true; sel.appendChild(opt); }); } function toggleAiMode(mode) { var isRefine = mode === 'refine'; var target = document.getElementById('ai_target_item'); var typeFilter = document.getElementById('ai_type_filter'); var statusFilter = document.getElementById('ai_status_filter'); var saveMode = document.getElementById('ai_save_mode'); var urlInput = document.getElementById('ai_source_url'); var typeSel = document.getElementById('ai_type'); var btn = document.getElementById('ai-submit-btn'); if (target) { target.style.display = isRefine ? '' : 'none'; target.required = isRefine; } if (typeFilter) typeFilter.style.display = isRefine ? '' : 'none'; if (statusFilter) statusFilter.style.display = isRefine ? '' : 'none'; if (saveMode) saveMode.style.display = isRefine ? '' : 'none'; if (urlInput) urlInput.style.display = isRefine ? 'none' : ''; if (typeSel) typeSel.style.display = isRefine ? 'none' : ''; if (btn) btn.textContent = isRefine ? AI_BTN_REFINE : AI_BTN_CREATE; if (isRefine) renderAiTargetOptions(); } renderAiTargetOptions(); (function () { var btn = document.getElementById('ai-voice-btn'); var input = document.getElementById('ai_prompt'); var langSel = document.getElementById('ai_lang'); var SR = window.SpeechRecognition || window.webkitSpeechRecognition; if (!btn || !input || !SR) { if (btn) btn.style.display = 'none'; return; } var rec = new SR(); rec.interimResults = false; rec.maxAlternatives = 1; var listening = false; btn.addEventListener('click', function () { if (listening) { rec.stop(); return; } var langMap = { ro: 'ro-RO', en: 'en-US', de: 'de-DE', fr: 'fr-FR', es: 'es-ES' }; rec.lang = langMap[langSel ? langSel.value : ''] || navigator.language || 'ro-RO'; listening = true; btn.textContent = '?'; rec.start(); }); rec.onresult = function (e) { var transcript = e.results[0][0].transcript; input.value = input.value ? (input.value + ' ' + transcript) : transcript; }; rec.onend = function () { listening = false; btn.textContent = '?'; }; rec.onerror = function () { listening = false; btn.textContent = '?'; }; })(); </script> <?php else: ?> <p style="margin: 0; font-size: 0.82rem; color: var(--text-muted);"> <?= $t->e('ai.setup_hint') ?> </p> <?php endif; ?> </div> <!-- Recent Drafts Review & 1-Click Publish --> <div style="margin-bottom: 18px; padding: 12px 14px; border-radius: var(--radius); background: #fffdf5; border: 1px solid #f0dfb0;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;"> <strong style="font-size: 0.92rem; color: #856404;"> <?= $t->e('drafts.heading') ?> (<span id="drafts-count"><?= count($recentDrafts) ?></span>) </strong> <a href="quick-list.php?status=draft<?= $siteParam ?>" style="font-size: 0.8rem; color: var(--primary); text-decoration: none; font-weight: 600;"> <?= $t->e('drafts.view_all') ?> </a> </div> <?php if ($draftMessage): ?> <div style="margin-bottom: 8px; padding: 8px 10px; border-radius: 4px; background: #d4edda; color: #155724; font-size: 0.84rem;"> <?= $draftMessage ?> </div> <?php endif; ?> <?php if ($draftError): ?> <div style="margin-bottom: 8px; padding: 8px 10px; border-radius: 4px; background: #f8d7da; color: #721c24; font-size: 0.84rem;"> <?= htmlspecialchars($draftError, ENT_QUOTES, 'UTF-8') ?> </div> <?php endif; ?> <?php if (empty($recentDrafts)): ?> <p style="margin: 0; font-size: 0.82rem; color: var(--text-muted);"><?= $t->e('drafts.empty') ?></p> <?php else: ?> <div style="display: flex; gap: 6px; margin-bottom: 8px;"> <select id="drafts-type-filter" onchange="filterDraftsLive()" style="padding: 6px 8px; border: 1px solid #e6d39c; border-radius: 4px; font-size: 0.84rem; background: #fff;"> <option value="any"><?= $t->e('edit.type') ?>: <?= $t->e('status.all') ?></option> <option value="post"><?= $t->e('nav.post') ?></option> <option value="page"><?= $t->e('nav.page') ?></option> </select> <input type="search" id="drafts-search" placeholder="<?= $t->e('drafts.search_placeholder') ?>" oninput="filterDraftsLive()" style="flex: 1; padding: 6px 9px; border: 1px solid #e6d39c; border-radius: 4px; font-size: 0.84rem;"> </div> <div id="drafts-list" style="max-height: 210px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;"> <?php foreach ($recentDrafts as $dr): ?> <?php $drId = (int) ($dr['id'] ?? 0); $drType = (string) ($dr['_qwp_type'] ?? 'post'); $drTitle = is_array($dr['title'] ?? null) ? ($dr['title']['raw'] ?? $dr['title']['rendered'] ?? '#' . $drId) : ($dr['title'] ?? '#' . $drId); $drTitle = html_entity_decode(strip_tags((string) $drTitle), ENT_QUOTES, 'UTF-8'); if (trim($drTitle) === '') { $drTitle = '#' . $drId; } $drEditUrl = 'quick-edit.php?action=load&item_type=' . urlencode($drType) . '&item_id=' . $drId . $siteParam; ?> <div class="draft-row" data-type="<?= htmlspecialchars($drType, ENT_QUOTES, 'UTF-8') ?>" data-title="<?= htmlspecialchars(strtolower($drTitle . ' #' . $drId), ENT_QUOTES, 'UTF-8') ?>" style="display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; background: #fff; border: 1px solid #efe3bd; border-radius: 4px; font-size: 0.84rem;"> <div style="min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"> <span style="display: inline-block; padding: 1px 5px; border-radius: 3px; font-size: 0.7rem; font-weight: 600; background: #eef3f7; color: #555; margin-right: 4px; text-transform: uppercase;"> <?= htmlspecialchars($drType === 'page' ? $t->get('nav.page') : $t->get('nav.post'), ENT_QUOTES, 'UTF-8') ?> </span> <a href="<?= htmlspecialchars($drEditUrl, ENT_QUOTES, 'UTF-8') ?>" style="color: var(--text); text-decoration: none; font-weight: 500;" title="<?= htmlspecialchars($drTitle, ENT_QUOTES, 'UTF-8') ?>"> <?= htmlspecialchars($drTitle, ENT_QUOTES, 'UTF-8') ?> </a> </div> <div style="display: flex; gap: 5px; flex-shrink: 0;"> <a href="<?= htmlspecialchars($drEditUrl, ENT_QUOTES, 'UTF-8') ?>" style="padding: 3px 8px; border-radius: 4px; background: #e5f2fa; color: var(--primary); text-decoration: none; font-size: 0.78rem; font-weight: 600;"> <?= $t->e('nav.edit') ?> </a> <form method="post" style="margin: 0;" onsubmit="return confirm(<?= htmlspecialchars(json_encode($t->get('drafts.confirm_publish')), ENT_QUOTES, 'UTF-8') ?>);"> <?= CsrfProtection::field() ?> <input type="hidden" name="action" value="quick_publish"> <input type="hidden" name="item_type" value="<?= htmlspecialchars($drType, ENT_QUOTES, 'UTF-8') ?>"> <input type="hidden" name="item_id" value="<?= $drId ?>"> <?php if ($siteKey !== ''): ?> <input type="hidden" name="site" value="<?= htmlspecialchars($siteKey, ENT_QUOTES, 'UTF-8') ?>"> <?php endif; ?> <button type="submit" style="padding: 3px 8px; border: none; border-radius: 4px; background: var(--success); color: #fff; font-size: 0.78rem; font-weight: 600; cursor: pointer;"> <?= $t->e('drafts.publish_now') ?> </button> </form> </div> </div> <?php endforeach; ?> </div> <script> function filterDraftsLive() { var searchEl = document.getElementById('drafts-search'); var typeEl = document.getElementById('drafts-type-filter'); var q = (searchEl ? searchEl.value : '').toLowerCase().trim(); var typeFilter = typeEl ? typeEl.value : 'any'; var rows = document.querySelectorAll('#drafts-list .draft-row'); var visible = 0; rows.forEach(function (row) { var matchType = (typeFilter === 'any' || row.getAttribute('data-type') === typeFilter); var matchTitle = (q === '' || (row.getAttribute('data-title') || '').indexOf(q) !== -1); var match = matchType && matchTitle; row.style.display = match ? 'flex' : 'none'; if (match) visible++; }); var cnt = document.getElementById('drafts-count'); if (cnt) cnt.textContent = String(visible); } </script> <?php endif; ?> </div> <?php if (!empty($sites)): ?> <div class="site-select"> <form method="get"> <label for="site"><?= $t->e('common.site') ?></label> <select id="site" name="site" onchange="this.form.submit()"> <?php foreach ($sites as $key => $site): ?> <option value="<?= htmlspecialchars($key, ENT_QUOTES, 'UTF-8') ?>" <?= ($key === $siteKey) ? 'selected' : '' ?>> <?= htmlspecialchars($site['label'] ?? $key, ENT_QUOTES, 'UTF-8') ?> </option> <?php endforeach; ?> </select> <noscript><button type="submit"><?= $t->e('common.switch') ?></button></noscript> </form> </div> <?php endif; ?> <div class="actions"> <div class="button-group"> <a class="button" href="quick-post.php<?= $siteSuffix ?>"><?= $t->e('dashboard.create_post') ?></a> <a class="button" href="quick-page.php<?= $siteSuffix ?>"><?= $t->e('dashboard.create_page') ?></a> </div> <a class="button" href="quick-media.php<?= $siteSuffix ?>"><?= $t->e('dashboard.media_library') ?></a> <div class="button-group"> <a class="button" href="quick-cpt.php<?= $siteSuffix ?>"><?= $t->e('dashboard.cpt') ?></a> <a class="button" href="quick-taxonomy.php<?= $siteSuffix ?>"><?= $t->e('dashboard.taxonomies') ?></a> </div> <div class="button-group"> <a class="button" href="quick-menus.php<?= $siteSuffix ?>"><?= $t->e('dashboard.menus') ?></a> <a class="button" href="quick-comments.php<?= $siteSuffix ?>"><?= $t->e('dashboard.comments') ?></a> </div> <div class="button-group"> <a class="button" href="quick-edit.php<?= $siteSuffix ?>"><?= $t->e('dashboard.quick_edit') ?></a> <a class="button" href="quick-list.php<?= $siteSuffix ?>"><?= $t->e('dashboard.browse') ?></a> </div> </div> <div style="margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); text-align: center;"> <a href="<?= htmlspecialchars($checkUrl, ENT_QUOTES, 'UTF-8') ?>" style="display: inline-block; padding: 8px 14px; border-radius: 6px; background: #e5f2fa; color: var(--primary); text-decoration: none; font-size: 0.9rem; font-weight: 600;"> <?= $t->e('dashboard.check_connection') ?> </a> <?php if ($healthCheck !== null): ?> <div style="margin-top: 12px; padding: 12px 14px; border-radius: 6px; text-align: left; font-size: 0.9rem; background: <?= $healthCheck['ok'] ? '#d4edda' : '#f8d7da' ?>; color: <?= $healthCheck['ok'] ? '#155724' : '#721c24' ?>;"> <strong><?= $healthCheck['ok'] ? $t->e('dashboard.connected') : $t->e('dashboard.connection_failed') ?></strong> (<?= (int) $healthCheck['latency_ms'] ?> ms)<br> <?php if (!empty($healthCheck['site'])): ?> <?= $t->e('common.site') ?> <strong><?= htmlspecialchars($healthCheck['site']['name'] ?: $healthCheck['site']['url'], ENT_QUOTES, 'UTF-8') ?></strong><br> <?php endif; ?> <?php if (!empty($healthCheck['user'])): ?> <?= $t->e('common.author') ?>: <strong><?= htmlspecialchars($healthCheck['user']['name'], ENT_QUOTES, 'UTF-8') ?></strong> <?php if (!empty($healthCheck['user']['roles'])): ?> (<?= htmlspecialchars(implode(', ', $healthCheck['user']['roles']), ENT_QUOTES, 'UTF-8') ?>) <?php endif; ?> <?php elseif (!empty($healthCheck['error'])): ?> Error: <?= htmlspecialchars((string) $healthCheck['error'], ENT_QUOTES, 'UTF-8') ?> <?php endif; ?> </div> <?php endif; ?> </div> <small><?= $t->e('dashboard.config_hint') ?></small> <div class="footer-links"> <a href="../README.md"><?= $t->e('dashboard.documentation') ?></a> </div> </div> </body> </html>