<script>
$(document).ready(function() {
$('.crop_container').on('click', toggleImage);
function toggleImage(event) {
$(event.target).closest('.crop_container').toggleClass('expanded');
}
});
</script>
<?php
$search_get = isset($_GET['q']) ? (string)$_GET['q'] : '';
$page_id = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$start_page = $page_id;
$end_page = 10;
$tenon_files = 0;
$miter_files = 0;
$tenon_found = [];
$miter_found = [];
if (!empty($search_get)) {
// search tenons
foreach (glob("tenons/*.txt") as $tenon_search) {
$tenon_contents = file_get_contents($tenon_search);
if (!empty($tenon_contents) && stripos($tenon_contents, $search_get) !== false) {
$tenon_found[] = $tenon_search;
}
}
if (!empty($tenon_found)) {
$tenon_found = array_unique($tenon_found);
$tenon_files = count($tenon_found);
}
// search miters
foreach (glob("miters/*.txt") as $miter_search) {
$miter_contents = file_get_contents($miter_search);
// Fixed logical bug: explicitly check !== false to catch index 0 matches
if (!empty($miter_contents) && stripos($miter_contents, $search_get) !== false) {
$miter_found[] = $miter_search;
}
}
if (!empty($miter_found)) {
$miter_files = count($miter_found);
}
}
$safe_search = htmlspecialchars($search_get, ENT_QUOTES, 'UTF-8');
if (strlen($search_get) !== 0) {
$search_total = $tenon_files + $miter_files;
?>
<div class="tenon_header">
<div class="tenon_header_td">
<span class="title"><b><?= $search_total; ?></b> results for "<?= $safe_search; ?>"</span>
</div>
</div>
<?php } else { ?>
<div class="tenon_header">
<div class="tenon_header_td">
<span class="title">No search results</span>
</div>
</div>
<?php } ?>
<div class="search_table">
<div class="search_td">
<form name="search_form" id="search_form" action="index.php" method="GET">
<input type="text" name="q" id="search_field" class="search_field" value="<?= $safe_search; ?>" placeholder="No search results"><input type="submit" class="search_submit" value="Search">
</form>
</div>
</div>
<div class="bump"></div>
<?php
if (!empty($search_get)) {
if ($tenon_files > 0) {
echo "<div class=\"tenon_table_solo\">\n";
echo "<div class=\"tenon_td\">\n";
$ts_num = 1;
foreach ($tenon_found as $tenon_search_results) {
$tenon_search_file = str_replace(["tenons/", ".txt"], "", $tenon_search_results);
$tenon_search_print = str_replace("_", " ", $tenon_search_file);
$safe_link = htmlspecialchars(urlencode($tenon_search_file), ENT_QUOTES, 'UTF-8');
$safe_print = htmlspecialchars($tenon_search_print, ENT_QUOTES, 'UTF-8');
echo "<span class=\"text\">" . $ts_num++ . ". <a href=\"index.php?t={$safe_link}\" target=\"_blank\">{$safe_print}</a></span><br>\n";
}
echo "</div></div>\n";
}
if ($miter_files > 0) {
krsort($miter_found);
$miter_print_arc = array_slice($miter_found, $start_page, $end_page, true);
foreach ($miter_print_arc as $miter_content) {
$grab = file($miter_content, FILE_IGNORE_NEW_LINES);
include 'echo.php';
}
if ($miter_files <= $end_page || ($page_id + $end_page) >= $miter_files) {
echo "<div class=\"next_page\"><span class=\"grey\">Next Page</span><a name=\"panels\"></a></div>\n";
} else {
$next_page = $start_page + $end_page;
$safe_query = htmlspecialchars(urlencode($search_get), ENT_QUOTES, 'UTF-8');
echo "<div class=\"next_page\"><a href=\"index.php?q={$safe_query}&page={$next_page}\" class=\"panel_link\">Next Page</a><a name=\"panels\"></a></div>\n";
}
}
}
?>