-
Notifications
You must be signed in to change notification settings - Fork 3
/
search.php
123 lines (107 loc) · 3.14 KB
/
search.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Linux - Friheden til at vælge</TITLE>
</HEAD>
<BODY>
<?php
// $Id$
// Første version af Hans Schou.
/* top.phtml sets
<!--DOCTYPE ....
.....
... [topmenu] ...
*/
$htmltitle_en="SSLUG - Liberty of searching in sgml files";
$htmltitle_da="SSLUG - Friheden til at søge i bøger";
$htmltitle_sv="SSLUG - Friheden til at söke i böcker";
$bodyarg=" background=\"/grafix/linux-back-1.gif\" ";
$maintain_name = "Hans Schou"; // Skriv dit navn her
$maintain_email = "chlor@sslug.dk"; // Skriv din email adresse her
if (file_exists($f = $DOCUMENT_ROOT."/includes/top.phtml"))
include($f);
list($width,$height) = @getimagesize("front.png");
if (isset($_GET["q"]))
$q = $_GET["q"];
if (isset($q))
$q = stripslashes($q);
if (isset($_GET["ml"]))
$ml = $_GET["ml"];
if (!$ml)
$ml = $_SERVER["HTTP_HOST"]=="cvs.linuxbog.dk" ? "sg" : "ht";
?>
<img src="front.png" alt="Friheden til at skrive bøger"
align="right" width="<? echo $width ?>" height="<? echo $height ?>">
<h1>SSLUG - Friheden til at søge i sgml/html-filer</h1>
<form action="<?php echo $PHP_SELF ?>" method="get">
Søg i
<input type=radio name=ml value="sg"<?php echo $ml=="sg"?" checked":"" ?>> SGML
<input type=radio name=ml value="ht"<?php echo $ml=="ht"?" checked":"" ?>> HTML
<br>
Søg efter:
<input type="text" name="q" value="<?php echo $q ?>" size="40">
<input type="submit" name="s" value="Submit">
<br>
<font size="-1">Der søges med <a href="unix/bog/joker-redir-pipe.html#regexp">regulære udtryk</a> - case insentive</font>
</form>
<?php
function htmllink( $sgmlfil ) {
return "<a href=\"$sgmlfil\">$sgmlfil</a>";
}
function searchinfile( $file, $q ) {
$count = 0;
$line = 0;
$fd = fopen($file, "r");
while (!feof($fd)) {
$str = fgets($fd, 1024);
$line++;
if (preg_match("|$q|i", $str)) {
if (!$count) echo "<p>\n";
$count++;
echo "<b>vi ".htmllink($file)." +$line</b>\n";
echo "<br> \n";
echo "<i>".htmlentities($str)."</i><br>\n";
flush();
}
}
fclose($fd);
if ($count) echo "</p>\n\n";
return $count;
}
function searchdir( $dir, $ext, $q ) {
$count = 0;
$d = dir($dir);
while ($fil = $d->read())
if (is_file($dir."/".$fil) && preg_match("|^[a-z0-9-_]+.+\.${ext}(.php)?$|", $fil))
$count += searchinfile("$dir/$fil", $q);
$d->close();
return $count;
}
/*
Man er doven. Vi gider kun søge i de filer der
ligger i de sub-dir der er i dette sub-dir.
*/
if ($q) {
set_time_limit(60);
flush();
$d = dir(".");
while ($dir = $d->read())
if (is_dir($dir)) {
# Prøv og find nogle SGML filer
if ($ml=="sg" && preg_match("|^[a-z0-9]+$|", $dir))
$count += searchdir($dir, "sgml", $q);
# prøv med HTML
if ($ml=="ht" && is_dir("$dir/bog"))
$count += searchdir("$dir/bog", "html", $q);
}
$d->close();
}
?>
<p>
<!-- Text slut -->
<!-- Husk din email-adresse: -->
<?php
if (file_exists($f = $DOCUMENT_ROOT."/includes/bottom.phtml"))
include($f);
?>