summaryrefslogtreecommitdiff
blob: ef5a11594761e5a55161aefb82565d814342b291 (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
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
<?
	
	require_once 'inc.header1.php';
	
	if($_REQUEST['search']) {
		die;
	}
	
	require_once 'inc.header2.php';
	require_once 'inc.header3.php';
	require_once 'inc.content1.php';
	
	$q = trim($_GET['q']);
	
	// Check to see if it's a bot
	
	
// 	if($q && $_GET) {
// 	
// 		$url = $base_uri."search/$q";
// 		header("Location: $url");
// 		die;
// 	}
// 	
// 	else {
	
		// Advanced search
		if(count($uri) == 1) {
		
			$str = gettext("ADVANCED SEARCH");
			echo "<h4>$str</h4>";
			
		} else {
	
// 			$q = $uri[1];
		
			$offset = 0;
	
			$query = $db->quote("%$q%");
			$name = $db->quote($q);
	
			// Use like (case insensitive) for now, should be less of a load on db
			$sql = "SELECT * FROM search_ebuilds e WHERE cp ~~* $query OR description ~~* $query OR package_name ~~* $query OR ebuild_name ~~* $query OR atom ~~* $query ORDER BY $name = ebuild_name DESC, $name = package_name DESC, package_name, e.ev DESC, e.lvl DESC, e.p IS NULL, e.p DESC, e.rc IS NULL, e.rc DESC, e.pre IS NULL, e.pre DESC, e.beta IS NULL, e.beta DESC, e.alpha IS NULL, e.alpha DESC, e.pr IS NULL, e.pr DESC;";
			
			$arr = $db->getAll($sql);
			
			$arr_packages = array();
			
			if(!PEAR::isError($arr)) {
				if(count($arr))
					foreach($arr as $row)
						$arr_packages[$row['package']][] = $row['ebuild'];
				
				// FIXME redirect to the page instead.
				if(count($arr_packages) == 1) {
					$package_id = key($arr_packages);
					require_once 'package.php';
					require_once 'inc.content2.php';
					break;
				}
				
				$arr_easter_eggs = array(
					'torrent' => 'funny-pictures-pirate-cat-grimaces.jpg',
					'google' => 'o-hai-googlz-i-can-has-privacy.jpg',
					'fail' => 'fail_cat.jpg',
					'secret' => 'funny-pictures-cat-activates-secret-door.jpg',
					'flameeyes' => 'funny-pictures-cat-loves-coffee.jpg',
					'araujo' => 'funny-pictures-cat-will-destroy-your-work.jpg',
					'bonsaikitten' => 'cat_minions.jpg',
					'mr_bones_' => 'funny-pictures-kitten-kills-with-his-eye.jpg',
					'vader' => 'funny-pictures-darth-vader-cat.jpg',
					'drobbins' => 'dune-cat.jpg',
					'beandog' => 'ubeantoo.jpg',
				);
				
				$count = count($arr_packages);
				
				if($count < 100) {
					$str = sprintf(gettext('SEARCH RESULTS FOR %1$s &nbsp; (%2$u)'), "\"$q\"", $count);
					echo "<h4>$str</h4>";
				}
					
				if($arr_easter_eggs[strtolower($q)] && $offset == 0) {
					$url = $base_uri."images/".$arr_easter_eggs[$q];
					echo "<div align='center' style='padding: 15px;'><img src='$url' /></div>\n";
				}
				
				if($count > 1) {
				
					$str = "";
					
					// Only display the first 100
					
					if($count > 100) {
						$str = sprintf(gettext('TOP (%1$u) SEARCH RESULTS FOR %2$s &nbsp; (%3$u)'), 100, "\"$q\"", $count);
						echo "<h4>$str</h4>";
						$arr_chunk = array_chunk($arr_packages, 100, true);
						$arr_packages = current($arr_chunk);
					}
					
					foreach($arr_packages as $arr)
						echo keywordsRow($arr, 'search');
				
				}
			}
			
			elseif(PEAR::isError($arr)) {
			
				$str = sprintf(gettext('SEARCH RESULTS FOR %1$s &nbsp; (%2$u)'), $q, count($arr_packages));
				echo "<h4>$str</h4>";
			
				$str = gettext("Hmm, that query didn't work.");
				echo "<p>$str</p>";
			
			}
			
		}
		
// 	}

	require_once 'inc.content2.php';
	
	
?>