'files']); $collections = array_map(fn(FilesCollection $c) => new CollectionItem($c), FilesCollection::cases()); $books = books_get(); $misc = books_get(category: BookCategory::MISC); render('files/index', collections: $collections, books: $books, misc: $misc); } function GET_folder() { list($folder_id) = input('i:folder_id'); $folder = books_get_folder($folder_id); if (!$folder) not_found(); $files = books_get($folder_id); set_title(lang('files').' - '.$folder->title); render('files/folder', folder: $folder, files: $files); } function GET_collection() { list($collection, $folder_id, $query, $offset) = input('collection, i:folder_id, q, i:offset'); $collection = FilesCollection::from($collection); $files = []; $parents = null; $query = trim($query); if (!$query) $query = null; add_skin_strings_re('/^files_(.*?)_collection$/'); add_skin_strings([ 'files_search_results_count' ]); $vars = []; $text_excerpts = null; switch ($collection) { case FilesCollection::WilliamFriedman: if ($query !== null) { $files = wff_search($query, $offset, self::SEARCH_RESULTS_PER_PAGE); $vars += [ 'search_count' => $files['count'], 'search_query' => $query ]; /** @var WFFCollectionItem[] $files */ $files = $files['items']; $query_words = array_map('mb_strtolower', preg_split('/\s+/', $query)); $found = []; $result_ids = []; foreach ($files as $file) { if ($file->isFolder()) continue; $result_ids[] = $file->id; foreach ([ mb_strtolower($file->getTitle()), strtolower($file->documentId) ] as $haystack) { foreach ($query_words as $qw) { if (mb_strpos($haystack, $qw) !== false) { $found[$file->id] = true; continue 2; } } } } $found = array_map('intval', array_keys($found)); $not_found = array_diff($result_ids, $found); if (!empty($not_found)) $text_excerpts = wff_get_text_excerpts($not_found, $query_words); if (is_xhr_request()) { ajax_ok([ ...$vars, 'new_offset' => $offset + count($files), 'html' => skin('files')->collection_files($files, $query, $text_excerpts) ]); } } else { if ($folder_id) { $parents = wff_get_folder($folder_id, true); if (!$parents) not_found(); if (count($parents) > 1) $parents = array_reverse($parents); } $files = wff_get($folder_id); } $title = lang('files_wff_collection'); if ($folder_id) $title .= ' - '.htmlescape($parents[count($parents)-1]->getTitle()); if ($query) $title .= ' - '.htmlescape($query); set_title($title); break; case FilesCollection::MercureDeFrance: if ($query !== null) { $files = mdf_search($query, $offset, self::SEARCH_RESULTS_PER_PAGE); $vars += [ 'search_count' => $files['count'], 'search_query' => $query ]; /** @var MDFCollectionItem[] $files */ $files = $files['items']; $query_words = array_map('mb_strtolower', preg_split('/\s+/', $query)); $found = []; $result_ids = []; foreach ($files as $file) { $result_ids[] = $file->id; foreach ([ $file->date, (string)$file->issue ] as $haystack) { foreach ($query_words as $qw) { if (mb_strpos($haystack, $qw) !== false) { $found[$file->id] = true; continue 2; } } } } $found = array_map('intval', array_keys($found)); $not_found = array_diff($result_ids, $found); if (!empty($not_found)) $text_excerpts = mdf_get_text_excerpts($not_found, $query_words); if (is_xhr_request()) { ajax_ok([ ...$vars, 'new_offset' => $offset + count($files), 'html' => skin('files')->collection_files($files, $query, $text_excerpts) ]); } } else { $files = mdf_get(); } $title = lang('files_mdf_collection'); if ($query) $title .= ' - '.htmlescape($query); set_title($title); break; } render('files/collection', ...$vars, collection: $collection, files: $files, parents: $parents, search_results_per_page: self::SEARCH_RESULTS_PER_PAGE, search_min_query_length: self::SEARCH_MIN_QUERY_LENGTH, text_excerpts: $text_excerpts); } }