= escapeHtml($article['kb_article_title']) ?>
= trim((string) $article['kb_article_summary']) !== '' ? escapeHtml($article['kb_article_summary']) . ' ยท ' : '' ?> Updated = escapeHtml(date('M j, Y', strtotime($updated))) ?>
Settings > Knowledge Base has it on (kbPublicOn()), and only * published, unarchived articles set to Anyone (kbPublicSql()). * * Laid out like the client portal, with your logo, so it looks like yours. * An article's own tables and colours are inline styles, already through * HTMLPurifier (documentHtmlPurify()), so styles are let in; scripts are not. * * Each visit counts as a read (kbCountView()), "Was this helpful?" goes under * an article (kbFeedbackHtml(), posted back here), and a search that finds * nothing goes on the Knowledge Base's Not found list. A session keeps a * visit's reads, answer and form token. */ require_once $_SERVER['DOCUMENT_ROOT'] . '/config.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/functions.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/load_global_settings.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/session_init.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/inc_set_timezone.php'; header("Content-Security-Policy: default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'"); header('X-Frame-Options: DENY'); header('X-Robots-Tag: noindex'); header('Referrer-Policy: strict-origin-when-cross-origin'); $company = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT company_name, company_logo FROM companies WHERE company_id = 1")) ?: ['company_name' => '', 'company_logo' => '']; $company_name = (string) $company['company_name']; $company_logo = (string) $company['company_logo']; $dark = ($_COOKIE['itflow_portal_theme'] ?? '') === 'dark'; $open = kbPublicOn(); $visible = kbPublicSql(); $per_page = 25; $q = trim((string) ($_GET['q'] ?? '')); $q_sql = escapeSql($q); if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = randomString(32); } // "Was this helpful?" under an article - the answer, then for a no what was missing. Back to the article. if ($open && $_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['kb_feedback']) || isset($_POST['kb_feedback_comment']))) { $kb_article_id = intval($_POST['kb_feedback'] ?? $_POST['kb_feedback_comment']); $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title FROM kb_articles WHERE kb_article_id = $kb_article_id AND $visible LIMIT 1")); if ($row && kbFeedbackReady() && hash_equals($_SESSION['csrf_token'], (string) ($_POST['csrf_token'] ?? ''))) { if (isset($_POST['kb_feedback'])) { kbFeedbackSave($kb_article_id, intval($_POST['helpful'] ?? 0) === 1, 'public'); } else { kbFeedbackComment($kb_article_id, $_POST['comment'] ?? ''); } } header('Location: ' . ($row ? kbPublicArticleUrl($row) . '#kb-feedback' : 'kb.php')); exit; } $article = null; $categories = []; $category = null; $total = 0; $articles = []; $related = []; if ($open && isset($_GET['article'])) { $kb_article_id = intval($_GET['article']); $article = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title, kb_article_summary, kb_article_content, kb_article_category_id, kb_article_created_at, kb_article_updated_at, category_name, category_icon FROM kb_articles LEFT JOIN categories ON category_id = kb_article_category_id AND kb_article_category_id > 0 WHERE kb_article_id = $kb_article_id AND $visible LIMIT 1")); if (!$article) { http_response_code(404); } else { kbCountView($kb_article_id); } if ($article && intval($article['kb_article_category_id'])) { $sql = mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title FROM kb_articles WHERE $visible AND kb_article_category_id = " . intval($article['kb_article_category_id']) . " AND kb_article_id != $kb_article_id ORDER BY COALESCE(kb_article_updated_at, kb_article_created_at) DESC LIMIT 5"); while ($row = mysqli_fetch_assoc($sql)) { $related[] = $row; } } } elseif ($open) { $sql = mysqli_query($mysqli, "SELECT kb_article_category_id, category_name, category_icon, COUNT(*) AS n FROM kb_articles LEFT JOIN categories ON category_id = kb_article_category_id AND kb_article_category_id > 0 WHERE $visible GROUP BY kb_article_category_id, category_name, category_icon, category_order ORDER BY kb_article_category_id = 0, category_order ASC, category_name ASC"); $all_count = 0; while ($row = mysqli_fetch_assoc($sql)) { $categories[intval($row['kb_article_category_id'])] = ['name' => $row['category_name'] ?? 'Other', 'icon' => categoryIcon($row['category_icon'] ?? '') ?: 'book', 'count' => intval($row['n'])]; $all_count += intval($row['n']); } $category = isset($_GET['category']) && isset($categories[intval($_GET['category'])]) ? intval($_GET['category']) : null; $where = $visible . ($category !== null ? " AND kb_article_category_id = $category" : ''); if ($q !== '') { $where .= " AND (kb_article_title LIKE '%$q_sql%' OR kb_article_summary LIKE '%$q_sql%' OR MATCH(kb_article_content_raw) AGAINST ('$q_sql'))"; } $total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM kb_articles WHERE $where"))[0]); if ($q !== '' && !$total && $category === null) { kbSearchMissSave($q, 'public'); } $pages = max(1, (int) ceil($total / $per_page)); $page = min(max(1, intval($_GET['page'] ?? 1)), $pages); $offset = ($page - 1) * $per_page; $order = $q !== '' ? "(kb_article_title LIKE '%$q_sql%') DESC, MATCH(kb_article_content_raw) AGAINST ('$q_sql') DESC" : 'COALESCE(kb_article_updated_at, kb_article_created_at) DESC'; $sql = mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title, kb_article_summary, kb_article_content, kb_article_created_at, kb_article_updated_at, category_name, category_icon FROM kb_articles LEFT JOIN categories ON category_id = kb_article_category_id AND kb_article_category_id > 0 WHERE $where ORDER BY $order, kb_article_title ASC LIMIT $per_page OFFSET $offset"); while ($row = mysqli_fetch_assoc($sql)) { $articles[] = $row; } } else { http_response_code(404); } /** The list's address with some of its settings changed. */ function kbPublicListUrl(array $changes) { global $category, $q; $params = array_merge(['category' => $category, 'q' => $q !== '' ? $q : null], $changes); $params = array_filter($params, function ($v) { return $v !== null && $v !== ''; }); return 'kb.php' . ($params ? '?' . http_build_query($params) : ''); } /** An article's address here - its id, then its title as words. */ function kbPublicArticleUrl(array $row) { $slug = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower((string) $row['kb_article_title'])), '-'); return 'kb.php?article=' . intval($row['kb_article_id']) . ($slug !== '' ? '-' . mb_substr($slug, 0, 80) : ''); } $title = $article ? $article['kb_article_title'] . ' | ' : ''; ?>
= trim((string) $article['kb_article_summary']) !== '' ? escapeHtml($article['kb_article_summary']) . ' ยท ' : '' ?> Updated = escapeHtml(date('M j, Y', strtotime($updated))) ?>