-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
91 lines (90 loc) · 5.17 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Search Mastodon tools</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#2b90d9">
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="https://dav.li/forkawesome/1.0.11/css/fork-awesome.min.css"/>
</head>
<body>
<header>
<h1><i class="fa fa-mastodon-alt" aria-hidden="true"></i></h1>
<form id="searchbar"><input type="text" placeholder="Search Mastodon tools…"/><button><i class="fa fa-chevron-right" aria-hidden="true"></i></button></form>
<!--p><i class="fa fa-search" aria-hidden="true"></i> We found 4 results!</p-->
</header>
<main>
<p id="noResults" style="display:none;">No results found. :(</p>
<?php
$database=file_get_contents("database.xml", FILE_USE_INCLUDE_PATH);
if($database!=false){
$xml=simplexml_load_string($database);
$xmlArray = array();
foreach ($xml->tool as $tool_tmp) $xmlArray[] = $tool_tmp;
shuffle($xmlArray);
foreach ($xmlArray as $tool) {?>
<a class="tool" data-id="<?php echo($tool->id); ?>" href="<?php echo($tool->link); ?>" target="_blank" rel="noopener noreferrer">
<h2><i class="fa <?php echo($tool->icon); ?>" aria-hidden="true"></i><?php echo($tool->name); ?></h2>
<p><?php echo($tool->description); ?></p>
<span class="link" title="<?php echo($tool->link); ?>"><?php echo($tool->link); ?></span>
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
<?php
}
} ?>
<a id="addYours" href="https://github.com/DavidLibeau/search-mastodon-tools" target="_blank" rel="noopener noreferrer" title="Add your tool to the database">
<i class="fa fa-plus" aria-hidden="true"></i>
</a>
</main>
<footer>
<p>This website tries to respect your privacy. It is hosted by OVH. The third party "Dav.Li" domain is hosted on the same server of this website. The software is <a href="https://github.com/DavidLibeau/search-mastodon-tools" target="_blank" rel="noopener noreferrer">free and open source</a>.<br/>Mastodon is a community driven free software not affiliated with this website. <a href="https://joinmastodon.org" target="_blank" rel="noopener noreferrer">Join Mastodon</a>.</p>
</footer>
<script src="//dav.li/jquery/2.1.4.js"></script>
<script>
function searchObject(q) {
if (q == "") {
$(".tool").show();
} else {
$(".tool").hide();
console.log(q);
parser = new DOMParser();
//var databaseXml = parser.parseFromString(database, "text/xml");
//console.log(databaseXml);
var it = database.evaluate("//tool[contains(translate(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),translate('" + q + "', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) or contains(translate(description, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),translate('" + q + "', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) or contains(translate(link, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),translate('" + q + "', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) or contains(translate(keywords//keyword, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),translate('" + q + "', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]/id/text()", database, null, XPathResult.ANY_TYPE, null);
console.log(it);
var results = [];
var node;
while (node = it.iterateNext()) {
$(".tool[data-id=\"" + node.textContent + "\"]").show();
results.push(node.textContent);
}
if (results.length == 0) {
$("#noResults").show();
} else {
$("#noResults").hide();
}
return results;
}
}
var database;
$(function() {
$.ajax({
url: "database.xml"
}).done(function(data) {
console.log(data);
database = data;
}).error(function(data) {
console.log("Error while loading database.");
console.log(data);
});
$("#searchbar").on("submit keypress", function(evt) {
if (evt.type == "submit") {
evt.preventDefault();
}
console.log(searchObject($(this).children("input").val()));
});
});
</script>
</body>
</html>