| <?php |
|
|
| declare(strict_types=1); |
|
|
| class SearchController |
| { |
| |
| |
| |
| public function index(): void |
| { |
| $config = require __DIR__ . '/../config.php'; |
|
|
| $query = Security::sanitizeSearch($_GET['q'] ?? ''); |
| $collection = isset($_GET['collection']) && $_GET['collection'] !== '' |
| ? Security::sanitize($_GET['collection']) |
| : null; |
| $topicFilter = isset($_GET['topic']) && $_GET['topic'] !== '' |
| ? Security::sanitize($_GET['topic']) |
| : null; |
| $stampFilter = isset($_GET['stamp']) && $_GET['stamp'] !== '' |
| ? Security::sanitize($_GET['stamp']) |
| : null; |
|
|
| $perPage = $config['app']['per_page']; |
| $limit = min($perPage, $config['app']['search_limit']); |
| $page = max(1, (int) ($_GET['page'] ?? 1)); |
| $offset = ($page - 1) * $limit; |
|
|
| $results = []; |
| $total = 0; |
| $totalPages = 0; |
|
|
| if ($query !== '') { |
| $searchModel = new Search(); |
| $results = $searchModel->fullText($query, $collection, $limit, $offset, $topicFilter, $stampFilter); |
| $total = $searchModel->countResults($query, $collection, $topicFilter, $stampFilter); |
| $totalPages = (int) ceil($total / $limit); |
| } |
|
|
| |
| $docModel = new Document(); |
| $collections = $docModel->getCollections(); |
|
|
| |
| $db = Database::getInstance(); |
| $availableTopics = []; |
| $availableStamps = []; |
| try { |
| $availableTopics = [ |
| 'intelligence operations', 'national security', 'military operations', |
| 'surveillance', 'assassination', 'congressional legislation', |
| 'government oversight', 'civil rights', 'foreign policy', |
| 'law enforcement', 'financial regulation', 'public health', |
| 'human experimentation', 'scientific research', 'judicial proceedings', |
| ]; |
| $availableStamps = [ |
| 'TOP SECRET', 'SECRET', 'CONFIDENTIAL', 'CLASSIFIED', 'UNCLASSIFIED', |
| 'NOFORN', 'EYES ONLY', 'REDACTED', 'DECLASSIFIED', 'SEALED', |
| ]; |
| } catch (\PDOException $e) {} |
|
|
| require __DIR__ . '/../views/search-results.php'; |
| } |
| } |
|
|