File: search.php

package info (click to toggle)
openclonk 8.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 169,656 kB
  • sloc: cpp: 180,484; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 148; sh: 101; javascript: 34
file content (174 lines) | stat: -rw-r--r-- 4,674 bytes parent folder | download | duplicates (7)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php

//parameters: $_GET('func')

//search?
if(isset($_GET['search'])) 
{
	if(strlen($_GET['search']) < 3) {
		$less = true;
	}
	else {
		if(isset($_GET['func'])) {
			$path = "sdk/script/fn/";
			$search = strtolower($_GET['search']);
			$result = array();
			
			
			$dir = opendir($path);
			//search
			while (($item = readdir($dir)) !== FALSE) 
			{
				$name = substr($item,0,strpos($item,'.'));
				if ("." != $item && ".." != $item
					&& (strpos(strtolower($name), $search) !== FALSE)
					&& !is_dir($path.$item))
				{
					// exact match -> redirect
					if ($search == strtolower($name))
					{
						header("Location: $path$item");
						exit;
					}
						
					array_push($result,array($path,$item));
				}
			}
			$showresults = 1;
		}
		elseif(isset($_GET['fulltext'])) {
			$result = SearchDir('sdk/');
			$showresults = 2;
		}
	}
}

function SearchDir($path) {
	if(!$dir = opendir($path))
		return;
	
	$result = array();
	$search = strtolower($_GET['search']);
	
	while (false !== ($file = readdir($dir))) {
		if ($file != "." && $file != "..") {
			if(is_dir($path.$file))
				$result = array_merge($result, SearchDir($path.$file.'/'));
			else {
				// HTML-Dokument auslesen
				$doc = new DOMDocument();
				@$doc->loadHTMLFile($path.$file);
				$divs = $doc->getElementsByTagName('div');
				foreach($divs as $div) {
					if(strpos($div->getAttribute('class'), 'text') !== false) {
						if(strpos(strtolower(strip_tags($div->nodeValue)),htmlspecialchars($search)) !== false) {
							$dirname = basename(rtrim($path, '/'));
							if(!isset($result[$dirname]))
								$result[$dirname] = array();
							
							$name = $doc->getElementsByTagName('h1')->item(0)->nodeValue;
							array_push($result[$dirname], array($path.$file,$name));
							break;
						}
					}
				}
			}
		}
	}
	closedir($dir);
	return $result;
}
?>

<?php
$lang = basename(dirname(__FILE__));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="doku.css">
<link rel="stylesheet" type="text/css" href="http://www.openclonk.org/header/header.css">
<title>OpenClonk <?php echo $lang == 'de' ? 'Referenz' : 'Reference' ?></title>
<style>
ul {
list-style-position: inside;
list-style-image: url(images/bullet_sheet.png);
}
ul a {
color: navy;  
text-decoration: none;  
}  
ul a.visited {
color: navy;  
text-decoration: none;  
}  
</style>
</head>
<body>
<?php
	readfile("http://www.openclonk.org/header/header.html");
?>
<div id="iframe"><iframe src="sdk/content.html"></iframe></div>
<div id="content">
<h1><?php print ($lang == 'de' ? 'Suche' : 'Search'); ?></h1>
<div class="text">
<form action="search.php" method="get">
<?php
echo '&nbsp;<input type="text" name="search"';
if (isset($_GET['search'])) echo ' value="' . htmlspecialchars($_GET['search']) . '"';
echo '> ';
echo '<input type="submit" name="func" value="' . ($lang == 'de' ? 'Suche' : 'Search') . '"> ';
echo '<input type="submit" name="fulltext" value="' . ($lang == 'de' ? 'Volltext' : 'Fulltext') . '">';
?>
</form>
<?php
	if($less) {
		echo $lang == 'de' ? 'Mindestens 3 Zeichen.' : '3 characters minimum.';
	}
	
	$dirtrans = array('de' => array('sdk' => 'Dokumentation', 'script' => 'Script', 'fn' => 'Funktionen', 'scenario' => 'Szenario', 'particle' => 'Partikel', 'material' => 'Material', 'folder' => 'Rundenordner', 'definition' => 'Objektdefinition'),
	                  'en' => array('sdk' => 'Documentation', 'script' => 'Script', 'fn' => 'Functions', 'scenario' => 'Scenario', 'particle' => 'Particle', 'material' => 'Material', 'folder' => 'Folder', 'definition' => 'Definition'));
	//nothing found
	if($showresults == 1) {
		if (count($result) == 0)
		{
			echo $lang == 'de' ? 'Es wurde keine Funktion gefunden.' : 'No function found.';
		}
		else {
			echo "<ul>\n";
			for($i = 0; $i < count($result); ++$i)
			{
				$item = $result[$i][1];
				if(!$name = $result[$i][2])
					$name = substr($item,0,strpos($item,'.'));
				$path = $result[$i][0];
				echo "<li><a href=\"$path$item\">$name</a></li>\n";
			}
			echo "</ul>\n";
		}
	}
	elseif($showresults == 2) {
		if (count($result) == 0)
		{
			echo $lang == 'de' ? 'Nichts gefunden.' : 'Nothing found.';
		}
		else {
			foreach($result as $dirname => $values) {
				$dirname = $dirtrans[$lang][$dirname];
				echo "<b>$dirname</b>\n";
				echo "<ul>\n";
				foreach($values as $val)
				{
					$item = $val[0];
					$name = $val[1];
					echo "<li><a href=\"$item\">$name</a></li>\n";
				}
				echo "</ul>\n";
			}
		}
	}
?>
</div>
</div>
</body></html>