forked from Star-lion/WPPSniffStorage
-
Notifications
You must be signed in to change notification settings - Fork 7
/
filenames.php
93 lines (86 loc) · 3.78 KB
/
filenames.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
<?php
require_once('includes/header.php');
if ($result = $mysqlCon->query("SELECT DISTINCT(SniffName) AS f FROM SniffData")) {
$fileNames = array();
while ($row = $result->fetch_object())
$fileNames[] = $row->f;
echo '<script type="text/javascript">sniffFiles = ' . json_encode($fileNames) . ';</script>';
} else {
echo "No sniff found!";
require_once('includes/footer.php');
die;
}
?>
<h3 style="margin-bottom: 3px; display: block; width: 100%; border-bottom: 1px solid black;">Sniff file searcher</h3>
<p>Wanna know if a sniff has already been parsed ? Enter part or all of its name in the input box below.</p>
<div style="margin: auto; width: 850px; text-align: center;">
Sniff filename: <input type="text" name="sniffName" size="40" /><br />
Sniffs found: <span id="sniffCount" style="font-weight: bold">0</span>
<div id="extraMatch" style="color: green; font-weight: bold;"></div>
<div id="approxMatch"></div>
</div>
<script src="./includes/jquery.js"></script>
<script type="text/javascript">
$(function() {
var searchTimer;
$('input[name="sniffName"]').keyup(function() {
if ($(this).val().length == 0) {
clearTimeout(searchTimer);
$("#approxMatch").html("");
$("#extraMatch").html("");
$("#sniffCount").html(0);
return;
}
clearTimeout(searchTimer);
searchTimer = setTimeout(function() {
$("#approxMatch").html("");
$("#extraMatch").html("");
$("#filterMoar").html("");
var searchString = $('input[name="sniffName"]').val(),
hasExactName = (jQuery.inArray(searchString, sniffFiles) != -1),
approxFiles = [],
sniffCount = 0;
// Cleaning up the search string to remove metacharacters
searchString = searchString.replace("(", "\\(");
searchString = searchString.replace(")", "\\)");
searchString = searchString.replace(".", "\\.");
if (searchString.length == 0) {
$("#sniffCount").html(0);
} else {
if (hasExactName) {
$("#extraMatch").html('An exact match has been found: that sniff has been parsed.');
$("#sniffCount").html(1);
} else {
var regex = new RegExp("(" + searchString + ")", "i");
console.log(regex);
// Look for strings containing the filename
for (var i in sniffFiles) {
if (sniffCount > 50)
{
$("#sniffCount").html($("#sniffCount").html() + "+");
$("#filterMoar").html("Too many results. Improve your search string.");
break;
}
var item = sniffFiles[i];
// jQuery.each(sniffFiles, function(idx, item) {
if (regex.test(item.substring(0, item.length - 4)) && item.toLowerCase() != searchString.toLowerCase()) {
approxFiles.push(item);
++sniffCount;
}
}/*)*/ ;
if (approxFiles.length != 0) {
$("#approxMatch").html("<b>Possible matches:</b>");
jQuery.each(approxFiles, function(idx, item) {
$("#approxMatch").html($("#approxMatch").html() + '<br />' + item.replace(regex, '<span class="matchPattern">$1</span>'));
});
}
$("#sniffCount").html(sniffCount);
}
}
}, 750);
});
});
</script>
<?php
require_once('includes/footer.php');
?>