aboutsummaryrefslogtreecommitdiff
path: root/search.php
blob: dc09366f8c3314aee23e59874e77180cd2245e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php 
echo "+--------------------------------+\n";
echo "| Search Results                 |\n";
echo "+--------------------------------+\n\n";

$env=getenv();
$string=$env["SEARCHREQUEST"]; 
$string=htmlentities($string);

if (!empty($string) || !ctype_space($string)) {
    $string = strtolower($string);
    echo "Search terms: " . $string . "\n\n";
    $dir = new RecursiveDirectoryIterator("/srv/gopher/phlog");
    $dir->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
    $iter = new RecursiveIteratorIterator($dir);
    
    $i=0;

    echo "+".str_repeat("-", 65)."+\n\n";
    foreach ($iter as $phlogdir) {
       $path=$phlogdir->getPathname();
       	if (str_contains($path, "/gophermap") ||
       	    ($path=="/srv/gopher/phlog/rss.xml") || 
       	    ($path=="/srv/gopher/phlog/search.php")) 
       	    continue;
       	$content = strtolower(file_get_contents($path));
       	$path=str_replace("/srv/gopher", "", $path); 
       	if (strpos($content, $string) !== false) {
          	$i++;
          	$title = preg_split('#\r?\n#', $content, 2)[0];
          	$dt=substr($path, 12, 10);
          	echo "0".$dt." ".ucfirst($title)."\t".$path."\t"."spike.nagatha.fr\t70\n";
       	}
    }
    
        if ($i == 0) echo "No match";
}else{
	echo "Empty search string\n\n";
	echo "1Return to Phlo\t/phlog\tspike.nagatha.fr\t70\n";
} 

?>