WebOrbiton
v1.0.0.0

StocketBase

58 lines · 2.1 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. require_once __DIR__ . '/includes/config.php';
  6. require_once __DIR__ . '/includes/database.php';
  7. require_once __DIR__ . '/includes/site-front.php';
  8. ​
  9. $settings = SiteFront::settings();
  10. if (($settings['llms_txt_enabled'] ?? '0') !== '1') {
  11. http_response_code(404);
  12. exit;
  13. }
  14. ​
  15. $db = Database::site();
  16. $siteName = trim((string) ($settings['site_name'] ?? Config::get('APP_NAME', 'StocketBase')));
  17. $siteDescription = trim((string) ($settings['site_description'] ?? ''));
  18. $baseUrl = rtrim(Config::get('APP_URL', ''), '/') . Config::get('APP_BASE_PATH', '');
  19. ​
  20. header('Content-Type: text/plain; charset=utf-8');
  21. ​
  22. echo '# ' . ($siteName !== '' ? $siteName : 'Website') . "\n\n";
  23. if ($siteDescription !== '') {
  24. echo '> ' . preg_replace('/\s+/', ' ', $siteDescription) . "\n\n";
  25. }
  26. echo "This file provides a concise, machine-readable guide to the published catalog on this store.\n\n";
  27. ​
  28. $categories = $db->query("SELECT name, slug FROM categories ORDER BY name ASC")->fetchAll();
  29. if (!empty($categories)) {
  30. echo "## Categories\n\n";
  31. foreach ($categories as $category) {
  32. echo '- [' . $category['name'] . '](' . $baseUrl . '/category.php?slug=' . rawurlencode($category['slug']) . ")\n";
  33. }
  34. echo "\n";
  35. }
  36. ​
  37. $pages = $db->query("SELECT title, slug FROM pages WHERE status = 'published' ORDER BY title ASC")->fetchAll();
  38. if (!empty($pages)) {
  39. echo "## Pages\n\n";
  40. foreach ($pages as $page) {
  41. echo '- [' . $page['title'] . '](' . $baseUrl . '/page.php?slug=' . rawurlencode($page['slug']) . ")\n";
  42. }
  43. echo "\n";
  44. }
  45. ​
  46. $products = $db->query("SELECT title, slug, excerpt, price_cents, currency FROM products WHERE status = 'published' ORDER BY published_at DESC, id DESC")->fetchAll();
  47. if (!empty($products)) {
  48. echo "## Products\n\n";
  49. foreach ($products as $product) {
  50. $note = trim(preg_replace('/\s+/', ' ', (string) ($product['excerpt'] ?? '')));
  51. echo '- [' . $product['title'] . '](' . rtrim(Config::get('APP_URL', ''), '/') . SiteFront::productUrl($product['slug']) . ')';
  52. if ($note !== '') {
  53. echo ': ' . $note;
  54. }
  55. echo "\n";
  56. }
  57. }
  58. ​