= .8) { $score = $percent; return array($mb ? mb_stripos($searchText, $w) : stripos($searchText, $w), $mb ? mb_strlen($w) : strlen($w)); } } return array(FALSE, FALSE); } function scorecmp($a, $b) { if ($a['score'] == $b['score']) { return 0; } return ($a['score'] < $b['score']) ? 1 : -1; } function textlencmp($a, $b) { if (strlen($a['text']) == strlen($b['text'])) { return 0; } return (strlen($a['text']) < strlen($b['text'])) ? 1 : -1; } function snipcmp($a, $b) { if ($a['score'] == $b['score']) { return textlencmp($a, $b); } return ($a['score'] < $b['score']) ? 1 : -1; } function ordercmp($a, $b) { if ($a['order'] == $b['order']) { return 0; } return ($a['order'] < $b['order']) ? 1 : -1; } function mfind($searchText, $searchFor, $words, $w, &$wordsfound) { if(empty($searchFor)) return FALSE; $snippet = array('text' => $searchText, 'w' => $w); if(($pos = find($searchText, $searchFor)) !== FALSE) { $wordsfound = array_merge($wordsfound, $words); $snippet['score'] = 20; $snippet['pos'] = $pos; $snippet['matchlen'] = strlen($searchFor); return $snippet; } foreach($words as $searchWord) { if(($pos = find($searchText, $searchWord)) !== FALSE) { $snippet['score'] = isset($wordscores[$searchWord]) ? 0.5 : 10; $wordsfound[] = $searchWord; $snippet['pos'] = $pos; $snippet['matchlen'] = strlen($searchWord); return $snippet; } } foreach($words as $searchWord) { $score = 1; $match = simfind($searchText, $searchWord, $score); if($match[0] !== FALSE) { $wordsfound[] = $searchWord; $snippet['score'] = $score * 5; $snippet['pos'] = $match[0]; $snippet['matchlen'] = $match[1]; return $snippet; } } return FALSE; } $page = 0; $start_page = 0; $end_page = -1; $searchResults = array(); $found = array(); if(isset($_GET['search'])) { $results_per_page = 10; $pages = 10; $page = (isset($_GET['page']) ? $_GET['page'] : 1); if($page < 1) { $page = 1; } $start_page = $page - $pages / 2; if($start_page < 1) { $start_page = 1; } $end_page = $page + $pages / 2 - 1; $searchFor = $_GET['search']; $words = array_filter(preg_split("/[\\s]+/", $searchFor), function ($w) { return strlen($w) > 2; }); $searchJSON = file_get_contents('search.json'); $searchPages = json_decode($searchJSON, TRUE); foreach($searchPages as $searchPage) { $foundwords = array(); if(($title = mfind($searchPage['title'], $searchFor, $words, 10, $foundwords)) !== FALSE) { $title['score'] *= (strlen($searchFor) / strlen($searchPage['title'])); } $snippets = array(); $order = 0; foreach($searchPage['texts'] as $text) { if(($s = mfind($text['t'], $searchFor, $words, $text['w'], $foundwords)) !== FALSE) { $s['order'] = $order++; $snippets[] = $s; } } if(count(array_diff(array_unique($words), array_unique($foundwords))) == 0) { if(count($snippets)) { $len = 300; $snippet_count = intval(($len + 99) / 100); uasort($snippets, 'snipcmp'); $original_snippets = $snippets; if(count($snippets) > $snippet_count) { $snippets = array_slice($snippets, 0, $snippet_count); } else { $snippet_count = count($snippets); } $snippet_length = intval($len / $snippet_count); $score = 0; foreach($original_snippets as $s) { $l = strlen($s['text']); if($l > $snippet_length) $l = $snippet_length; $score += $s['score'] * $s['w'] * ($l / $snippet_length); } uasort($snippets, 'ordercmp'); if($title !== FALSE) { $score += 30 * $title['score']; } $found[] = array('link' => $searchPage['link'], 'title' => htmlentities($searchPage['title']), 'score' => $score, 'snippets' => $snippets); } else if($title !== FALSE) { foreach($searchPage['texts'] as $text) { $s = array('text' => $text['t'], 'w' => $text['w']); $s['score'] = $text['w']; $snippets[] = $s; } $found[] = array('link' => $searchPage['link'], 'title' => htmlentities($searchPage['title']), 'score' => 30 * $title['score'], 'snippets' => $snippets); } } } $current_page = $page; $end_page = (count($found) + ($results_per_page - 1)) / $results_per_page; uasort($found, 'scorecmp'); $searchResults = array_slice($found, ($page - 1) * $results_per_page, $results_per_page); } ?>

Risultati di ricerca per ""

$length) { $string = wordwrap($string, $length); $string = $mb? mb_substr($string, 0, mb_strpos($string, "\n")) : substr($string, 0, strpos($string, "\n"));; } return $string; } function clip_string($string, $pos, $length, $total) { global $mb; $m = $mb ? mb_substr($string, $pos, $length) : substr($string, $pos, $length); $before = $mb ? mb_substr($string, 0, $pos) : substr($string, 0, $pos); $after = $mb ? mb_substr($string, $pos + $length, mb_strlen($string) - ($pos + $length)) : substr($string, $pos + $length, strlen($string) - ($pos + $length)); $before = rev_string($before); $half = intval(($total - $length) / 2); $hlPre = ''; $hlPost = ''; $out = htmlentities(rev_string(word_trunc($before, $half))) . $hlPre . htmlentities($m) . $hlPost . htmlentities(word_trunc($after, $half)); return $out; } if(count($searchResults) == 0) { $result = '

{title}

{text}

'; $result = str_replace('{title}', htmlentities('Nessun risultato'), $result); $result = str_replace('{text}', '', $result); echo $result; } else { echo ''; foreach($searchResults as $searchResult) { $result = '

{title}

{text}

'; $result = str_replace('{title}', '' . $searchResult['title'] . '', $result); $text = ""; foreach($searchResult['snippets'] as $s) { if(isset($s['pos'])) { $pos = $s['pos']; $m = $s['matchlen']; $snippet = clip_string($s['text'], $pos, $m, $snippet_length); } else { $snippet = $s['text']; } if(strlen($text)) $text .= "…"; $text .= " " . $snippet; } $result = str_replace('{text}', $text, $result); echo $result; } } ?>
.pbdn{display:none}.pbc{border: 0;background-color:#c0c0c0;color:#fff;border-color:#677a85}'; $control = ''; if($page > 1) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . ($page - 1); $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{btnclass}', '', $control); $control = str_replace('{lnkclass}', '', $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}
'; $buttonPage = $start_page + 1 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}
'; $buttonPage = $start_page + 2 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}
'; $buttonPage = $start_page + 3 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}
'; $buttonPage = $start_page + 4 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}
'; $buttonPage = $start_page + 5 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}'; $buttonPage = $start_page + 6 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}'; $buttonPage = $start_page + 7 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}'; $buttonPage = $start_page + 8 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}'; $buttonPage = $start_page + 9 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> {page_num}'; $buttonPage = $start_page + 10 - 1; if($buttonPage <= $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . $buttonPage; if($buttonPage == $page) { $control = str_replace('href="#"', '', $control); $control = str_replace('{lnkclass}', 'pbc', $control); } else { $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); } $control = str_replace('{btnclass}', '', $control); $control = str_replace('{page_num}', $buttonPage, $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?> >>'; if($page < $end_page) { $url = strtok($_SERVER['REQUEST_URI'],'?') . '?search=' . $searchFor . '&page=' . ($page + 1); $control = str_replace('href="#"', 'href="' . $url . '"', $control); $control = str_replace('{lnkclass}', '', $control); $control = str_replace('{btnclass}', '', $control); } else { $control = str_replace('{btnclass}', 'pbdn', $control); } echo $control; ?>
OK

Questo sito web fa uso di cookies. Si prega di consultare la nostra informativa sulla privacy per i dettagli.