v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/includes/config.php';
- require_once __DIR__ . '/includes/database.php';
- require_once __DIR__ . '/includes/site-front.php';
-
- $settings = SiteFront::settings();
- if (($settings['llms_txt_enabled'] ?? '0') !== '1') {
- http_response_code(404);
- exit;
- }
-
- $db = Database::site();
- $siteName = trim((string) ($settings['site_name'] ?? Config::get('APP_NAME', 'StocketBase')));
- $siteDescription = trim((string) ($settings['site_description'] ?? ''));
- $baseUrl = rtrim(Config::get('APP_URL', ''), '/') . Config::get('APP_BASE_PATH', '');
-
- header('Content-Type: text/plain; charset=utf-8');
-
- echo '# ' . ($siteName !== '' ? $siteName : 'Website') . "\n\n";
- if ($siteDescription !== '') {
- echo '> ' . preg_replace('/\s+/', ' ', $siteDescription) . "\n\n";
- }
- echo "This file provides a concise, machine-readable guide to the published catalog on this store.\n\n";
-
- $categories = $db->query("SELECT name, slug FROM categories ORDER BY name ASC")->fetchAll();
- if (!empty($categories)) {
- echo "## Categories\n\n";
- foreach ($categories as $category) {
- echo '- [' . $category['name'] . '](' . $baseUrl . '/category.php?slug=' . rawurlencode($category['slug']) . ")\n";
- }
- echo "\n";
- }
-
- $pages = $db->query("SELECT title, slug FROM pages WHERE status = 'published' AND is_home = 0 ORDER BY title ASC")->fetchAll();
- if (!empty($pages)) {
- echo "## Pages\n\n";
- foreach ($pages as $page) {
- echo '- [' . $page['title'] . '](' . $baseUrl . '/page.php?slug=' . rawurlencode($page['slug']) . ")\n";
- }
- echo "\n";
- }
-
- $products = $db->query("SELECT title, slug, excerpt, price_cents, currency FROM products WHERE status = 'published' ORDER BY published_at DESC, id DESC")->fetchAll();
- if (!empty($products)) {
- echo "## Products\n\n";
- foreach ($products as $product) {
- $note = trim(preg_replace('/\s+/', ' ', (string) ($product['excerpt'] ?? '')));
- echo '- [' . $product['title'] . '](' . rtrim(Config::get('APP_URL', ''), '/') . SiteFront::productUrl($product['slug']) . ')';
- if ($note !== '') {
- echo ': ' . $note;
- }
- echo "\n";
- }
- }
-