-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.php
83 lines (59 loc) · 2.03 KB
/
check.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
<?php
// This is a simple API created in response to SaveMLAK request to have ability to confirm whether or not a given link has
// been submitted to our seed database. - Konrad
//NOTE: This only finds *exact matches* - I think we should add another command,
//perhaps "c=similar" allowing outsiders to find similar urls and returns them in an array.
$u = isset($_GET['u']) ? $_GET['u'] : false; //The url to supply for the command
$c = isset($_GET['c']) ? $_GET['c'] : false; //The command
require_once('inc/common.php');
if(!$c) {
echo "ERROR: No request command found.\n";
}
if (!$u) {
echo "ERROR: No request parameter found.\n";
exit;
}
//This script only supports a 'url' command, otherwise return error
switch($c)
{
//URL CHECK COMMAND
// USAGE: jdarchive.org/check/url/[address to check]
// RETURNS: JSON of the information we have for the url or the fact it does not exist
// NOTE: URLs must be HTML encoded with urlencode() or similar, or else URLs with "?" or "&" will not be found
case 'url' :
echo getinfo($u);
break;
default:
echo "ERROR: The '$command' command is not supported.\n";
break;
}
function getinfo($url) {
if($url==""){
echo "ERROR: No url was supplied.";
return;
}
$urlquery= "SELECT * FROM `seeds` WHERE `url` LIKE '".mysql_real_escape_string($url)."%' LIMIT 400";
$numresults=mysql_query($urlquery);
$numrows=mysql_num_rows($numresults);
//Prepare the array for JSON encoding
if($numrows>0){
$response=array();
while ($row=mysql_fetch_array($numresults)){
$entry = array(
"title" => $row["title"],
"url" => $row["url"],
"id" => $row["sid"],
"frequency" => $row["frequency"],
"scope" => $row["scope"],
"submitter" => $row["name"],
"added" => $row["added"],
"archived" => $row["isArchived"]
);
//$entry=json_encode($entry);
array_push($response,$entry);
}
} else {
$response = array();
}
return json_encode($response);
}