-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?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 | ||
|
||
$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 | ||
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; | ||
} | ||
|
||
//echo $url."<br />"; | ||
|
||
$urlquery= "SELECT * FROM `seeds` WHERE `url` LIKE '".$url."%'"; | ||
|
||
$numresults=mysql_query($urlquery); | ||
$numrows=mysql_num_rows($numresults); | ||
echo "NUMROWS: $numrows"; | ||
if($numrows>0){ | ||
$row=mysql_fetch_array($numresults); | ||
$response = array( | ||
"found" => 1, | ||
"title" => $row["title"], | ||
"url" => $row["url"], | ||
"id" => $row["sid"], | ||
"frequency" => $row["frequency"], | ||
"scope" => $row["scope"], | ||
"submitter" => $row["name"], | ||
"added" => $row["added"], | ||
"archived" => $row["isArchived"] | ||
); | ||
|
||
} else { | ||
$response = array( | ||
"found" => 0 | ||
); | ||
} | ||
|
||
return json_encode($response); | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?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 | ||
|
||
// .htaccess has been set to allow for /command/parameter/parameter structured URIs | ||
// simplify the resulting info: | ||
|
||
require_once('../inc/common.php'); | ||
|
||
$requestURI = explode('/', $_SERVER['REQUEST_URI']); | ||
$scriptName = explode('/',$_SERVER['SCRIPT_NAME']); | ||
|
||
for($i= 0;$i < sizeof($scriptName);$i++) | ||
{ | ||
if ($requestURI[$i] == $scriptName[$i]) | ||
{ | ||
unset($requestURI[$i]); | ||
} | ||
} | ||
|
||
$query = array_values($requestURI); | ||
|
||
//There should be one command and one parameter | ||
|
||
if(!$query[0]) { | ||
echo "ERROR: No request command found.\n"; | ||
} else { | ||
$command=$query[0]; | ||
} | ||
|
||
if (count($query)<2) { | ||
echo "ERROR: No request parameter found.\n"; | ||
exit; | ||
} | ||
|
||
|
||
|
||
//This script only supports a 'url' command, otherwise return error | ||
|
||
switch($command) | ||
{ | ||
//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 | ||
case 'url' : | ||
//collapse all parameters that follow, assume it is all one url | ||
$url=$query; | ||
//exclude the command, the rest will be the url | ||
unset($url[0]); | ||
$url=implode("/",$url); | ||
getinfo($url); | ||
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 '".$url."' LIMIT 1"; | ||
|
||
$numresults=mysql_query($query); | ||
$numrows=mysql_num_rows($numresults); | ||
|
||
if($numrows>0){ | ||
echo "FOUND"; | ||
} else { | ||
echo "NOT FOUND"; | ||
} | ||
|
||
} |