search.php 657 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /* This script is used to search content and display results */
  3. require_once 'session.php';
  4. require_once 'database.php';
  5. require_once 'date.php';
  6. require_once 'twig.php';
  7. $db = new Database();
  8. $db->connect();
  9. // Must have a query ?q=
  10. if (!isset ($_GET['q']))
  11. {
  12. header ('Location: ./');
  13. exit ();
  14. }
  15. $query = trim ($_GET['q']);
  16. // Query must not be an empty string
  17. if (strlen ($query) == 0)
  18. {
  19. header ('Location: ./');
  20. exit ();
  21. }
  22. $search_results = $db->search ($query);
  23. echo $twig->render (
  24. 'search.twig',
  25. ['query' => $query,
  26. 'search_results' => $search_results]);