This repository has been archived by the owner on Feb 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
82 lines (71 loc) · 2.5 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
<?php
/**
* XDCC Parser
* |- Search Module
*
* This software is free software and you are permitted to
* modify and redistribute it under the terms of the GNU General
* Public License version 3 as published by the Free Sofware
* Foundation.
*
* @link https://github.com/Kcchouette/XDCCParser/
* @author Kcchouette
* @author Alex 'xshadowfire' Yu <ayu@xshadowfire.net>
* @author DrX
* @copyright 2008-2009 Alex Yu and DrX - 2015 Kcchouette
*/
require_once 'core.php';
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header( "Content-Type: text/plain; charset=utf-8" );
function literalSearch($search) {
$t = array();
if(($index = strpos($search,'"'))!== false && ($lastindex = strpos(substr($search,$index+1),'"'))!== false) {
$t[] = addslashes(substr($search,$index+1,$lastindex));
$t = array_merge($t,simpleSearch(substr($search,0,$index)));
return array_merge($t,literalSearch(substr($search,$index+$lastindex+2)));
} else {
return simpleSearch($search);
}
}
function simpleSearch($search) {
$search = str_replace(array("_", ";", "'", ".")," ",$search);
return explode(" ",$search);
}
$x = 0;
$bots = xp_get("bots");
$t = literalSearch( str_replace( '-"', '"-', stripslashes($_GET['t']) ) ); // dirty dirty dirty hack - flip -" so I don't have to properly parse it :D
$b = array(); // our blacklist
if($_GET['nick']) foreach($bots as $key => &$bot) if($bot['nick'] != $_GET['nick']) unset($bots[$key]); // dirty hack - get rid of all bots that aren't the right one!
foreach($t as $key => $arg) {
if(!$arg) { // why are you empty?
unset($t[$key]);
} elseif($arg[0] == '-') { // let's blacklist some terms
$b[] = substr($arg,1);
unset($t[$key]);
}
}
$match = preg_match("/.*?[a-f0-9]{7}.*?/i",$_GET['t']) ? 5 : 4; // crc or non crc search, 7 or more is a go
foreach($bots as &$bot) {
$xpacks = array();
$key = count($bot['packs']['1']);
for($i=0;$i<$key;$i++) {
foreach($t as $arg) {
if(!stristr($bot['packs'][$match][$i],$arg)) {
continue 2;
}
}
foreach($b as $arg) {
if(stristr($bot['packs'][$match][$i],$arg) !== FALSE) {
continue 2;
}
}
$xpacks[$bot['packs'][1][$i]]['number'] = $bot['packs'][1][$i];
$xpacks[$bot['packs'][1][$i]]['name'] = $bot['packs'][5][$i];
$xpacks[$bot['packs'][1][$i]]['size'] = $bot['packs'][2][$i];
}
foreach($xpacks as $pack)
print("p.k[".$x++."] = {b:\"".$bot['nick']."\", n:".$pack['number'].", s:".$pack['size'].", f:\"".$pack['name']."\"};\n");
}
?>