Permalink
Browse files

Cleaning up directories and minor fixes. Reducing the number of reser…

…ved variables the API requires: - : To be set with all relevant, sanitized user input to the API

-  : Holds configuration options
-  : Collection of names of variables the API should ingest
-  : Hash of API's Actions
-  : The globabl state variable (100 is the OK state)
-  : The database connection object
-  : The array to be formatted and returned to the user
-  : The table description object
  • Loading branch information...
1 parent 4f7db5a commit a06b625d951c7aec992fa2140bd2d73dff918ccc @evantahler committed Apr 5, 2011
Showing with 414 additions and 364 deletions.
  1. +6 −6 .gitignore
  2. 0 {PHP-DAVE-API → API}/.htaccess
  3. +18 −21 {PHP-DAVE-API → API}/AccessTools/APIRequest.php
  4. 0 {PHP-DAVE-API → API}/AccessTools/index.php
  5. +1 −1 {PHP-DAVE-API/Actions → API/Actions/examples}/CacheTest.php
  6. +2 −2 {PHP-DAVE-API/Actions → API/Actions/examples}/CookieTest.php
  7. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/DescribeActions.php
  8. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/DescribeTables.php
  9. +2 −2 {PHP-DAVE-API/Actions → API/Actions/examples}/Geocode.php
  10. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/LogIn.php
  11. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/ObjectTest.php
  12. +2 −9 {PHP-DAVE-API/Actions → API/Actions/examples}/SlowAction.php
  13. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/UserAdd.php
  14. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/UserDelete.php
  15. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/UserEdit.php
  16. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/UserView.php
  17. 0 {PHP-DAVE-API/Actions → API/Actions/examples}/index.php
  18. +20 −18 {PHP-DAVE-API → API}/CACHE.php
  19. +186 −0 API/CONFIG.php.example
  20. +17 −17 {PHP-DAVE-API → API}/CRON.php
  21. +2 −1 {PHP-DAVE-API → API}/CheckAPIKey.php
  22. +2 −2 {PHP-DAVE-API → API}/CommonFunctions.php
  23. +9 −10 {PHP-DAVE-API → API}/ConnectToDatabase.php
  24. +2 −2 {PHP-DAVE-API → API}/DAVE.php
  25. +8 −9 {PHP-DAVE-API → API}/DB/TableConfig.php
  26. 0 {PHP-DAVE-API → API}/DB/index.php
  27. 0 {PHP-DAVE-API → API}/GetPostVars.php
  28. 0 {PHP-DAVE-API → API}/MaxMind/COPYRIGHT.txt
  29. 0 {PHP-DAVE-API → API}/MaxMind/LICENSE.txt
  30. 0 {PHP-DAVE-API → API}/MaxMind/geoip.inc
  31. 0 {PHP-DAVE-API → API}/MaxMind/geoipcity.inc
  32. 0 {PHP-DAVE-API → API}/MaxMind/geoipregionvars.php
  33. 0 {PHP-DAVE-API → API}/MaxMind/index.php
  34. 0 {PHP-DAVE-API → API}/MaxMind/timezone.php
  35. 0 {PHP-DAVE-API → API}/MaxMind/timezone.txt
  36. 0 {PHP-DAVE-API → API}/Objects/User.php
  37. 0 {PHP-DAVE-API → API}/Objects/_BASE.php
  38. +5 −18 {PHP-DAVE-API → API}/Output.php
  39. +22 −0 API/WriteToLog.php
  40. 0 {PHP-DAVE-API → API}/config_cleaner.php
  41. 0 {PHP-DAVE-API → API}/crossdomain.xml
  42. 0 {PHP-DAVE-API → API}/helper_functions/AES.php
  43. 0 {PHP-DAVE-API → API}/helper_functions/CURL_POST.php
  44. 0 {PHP-DAVE-API → API}/helper_functions/CheckForBadWord.php
  45. 0 {PHP-DAVE-API → API}/helper_functions/GetGoFromIP.php
  46. 0 {PHP-DAVE-API → API}/helper_functions/ValidStateZip.php
  47. 0 {PHP-DAVE-API → API}/helper_functions/colors.php
  48. 0 {PHP-DAVE-API → API}/helper_functions/formatBytes.php
  49. 0 {PHP-DAVE-API → API}/helper_functions/http.php
  50. 0 {PHP-DAVE-API → API}/helper_functions/index.php
  51. 0 {PHP-DAVE-API → API}/helper_functions/microtime_float.php
  52. 0 {PHP-DAVE-API → API}/helper_functions/parseArgs.php
  53. 0 {PHP-DAVE-API → API}/helper_functions/secondsToWords.php
  54. +8 −9 {PHP-DAVE-API → API}/index.php
  55. 0 {PHP-DAVE-API → API}/static.html
  56. +0 −181 PHP-DAVE-API/CONFIG.php.example
  57. +0 −22 PHP-DAVE-API/WriteToLog.php
  58. +28 −14 {PHP-DAVE-API → SERVER}/SERVER.php
  59. +36 −5 {PHP-DAVE-API → SERVER}/script_runner.php
  60. +22 −0 SERVER/server_config.php
  61. 0 {PHP-DAVE-API/spec → SPEC}/TEST.php
  62. +1 −1 {PHP-DAVE-API/spec → SPEC}/actions/DescribeActions.php
  63. +9 −8 {PHP-DAVE-API/spec → SPEC}/spec_helper.php
  64. +3 −3 {PHP-DAVE-API/spec → SPEC}/system/general.php
  65. +3 −3 {PHP-DAVE-API/spec → SPEC}/system/output_types.php
View
@@ -1,8 +1,8 @@
favicon.gif
favicon.ico
-PHP-DAVE-API/CONFIG.php
-PHP-DAVE-API/CONFIG.php.backup
-PHP-DAVE-API/CONFIG.php.orig
-PHP-DAVE-API/DB/TABLES.php
-PHP-DAVE-API/MaxMind/GeoLiteCity.dat
-PHP-DAVE-API/LOG/*
+API/CONFIG.php
+API/DB/TABLES.php
+API/MaxMind/GeoLiteCity.dat
+API/LOG/*
+SPEC/LOG/*
+SERVER/LOG/*
File renamed without changes.
@@ -7,29 +7,26 @@
I am an example class that can be used by another PHP application (perhaps the application that renders the consumer-facing website) to connect to the DAVE API
-***********************************************/
-
-// I am an example. Uncomment me to try me out
-/*
-$PostArray = array(
- "Action" => "A_DUMMY_ACTION",
- "OutputType" => "PHP"
-);
+EXAMPLE USE:
+ $PostArray = array(
+ "Action" => "A_DUMMY_ACTION",
+ "OutputType" => "PHP"
+ );
-$API_URL = "127.0.0.1/API/"; // local host
-$APIRequest = new APIRequest($IP, $API_URL, $PostArray);
-$APIDATA = $APIRequest->DoRequest();
-if ($APIDATA != false)
-{
- echo "Your request came from ".$APIDATA['IP']." and took ".$APIDATA['ComputationTime']." seconds.";
-}
-else
-{
- echo 'Something is wrong with your URL or DAVE API configuration';
-}
-echo "\r\n\r\n";
-*/
+ $API_URL = "127.0.0.1/API/"; // local host
+ $APIRequest = new APIRequest($IP, $API_URL, $PostArray);
+ $APIDATA = $APIRequest->DoRequest();
+ if ($APIDATA != false)
+ {
+ echo "Your request came from ".$APIDATA['IP']." and took ".$APIDATA['ComputationTime']." seconds.";
+ }
+ else
+ {
+ echo 'Something is wrong with your URL or DAVE API configuration';
+ }
+ echo "\r\n\r\n";
+***********************************************/
class APIRequest
{
protected $PostArray, $response, $API_URL;
File renamed without changes.
@@ -11,7 +11,7 @@
// I'll use HASH as the variable to log by IP address;
if ($ERROR == 100)
{
- if ($CacheType == "")
+ if ($CONFIG['CacheType'] == "")
{
$ERROR = "The cache is not configured on this server";
}
@@ -9,8 +9,8 @@
***********************************************/
$NewUpperLimit = rand();
$NewLowerLimit = rand();
-_setcookie("UpperLimit", $NewUpperLimit, time() + 60);
-_setcookie("LowerLimit", $NewLowerLimit, time() + 60);
+_setcookie("UpperLimit", $NewUpperLimit);
+_setcookie("LowerLimit", $NewLowerLimit);
$OUTPUT["COOKIE_TEST"]["OldUpperLimit"] = $PARAMS['UpperLimit'];
$OUTPUT["COOKIE_TEST"]["NewUpperLimit"] = $NewUpperLimit;
@@ -33,7 +33,7 @@
date_default_timezone_set($localTimeZone);
setlocale(LC_TIME, $country_code3);
$LocalTime = strftime("%T %F");
- date_default_timezone_set($systemTimeZone);
+ date_default_timezone_set($CONFIG['systemTimeZone']);
setlocale(LC_TIME, "C");
$SystemTime = strftime("%T %F");
@@ -47,7 +47,7 @@
$OUTPUT['city'] = $city;
$OUTPUT['localTimeZone'] = $localTimeZone;
$OUTPUT['LocalTime'] = $LocalTime;
- $OUTPUT['systemTimeZone'] = $systemTimeZone;
+ $OUTPUT['systemTimeZone'] = $CONFIG['systemTimeZone'];
$OUTPUT['SystemTime'] = $SystemTime;
}
else
File renamed without changes.
@@ -5,16 +5,9 @@
https://github.com/evantahler/PHP-DAVE-API
Evan Tahler | 2011
-I am a slow action which can be used for profiling or parallelization testing. You can pass me UpperLimit in seconds to tell me how long to sleep for, or I'll use 10 sec as a default
+I am a slow action which can be used for profiling or parallelization testing. I will sleep for 10 seconds before returning.
***********************************************/
-
-if (!($PARAMS["UpperLimit"] > 0)){
- $sleep_time = 10;
-} else {
- $sleep_time = $PARAMS["UpperLimit"];
-}
-
-sleep($sleep_time);
+sleep(10);
$OUTPUT["SLEEP_TIME"] = $sleep_time;
File renamed without changes.
File renamed without changes.
@@ -12,16 +12,16 @@
***********************************************/
-if($CacheType == "MemCache")
+if($CONFIG['CacheType'] == "MemCache")
{
// start memcache if memcache is on
$memcache = new Memcache;
- $memcache->connect('localhost', 11211);
+ $memcache->connect($CONFIG['MemCacheHost'], 11211);
function SetCache($Key, $Value, $ThisCacheTime = null)
{
- global $CacheTime;
- if ($ThisCacheTime == null) { $ThisCacheTime = $CacheTime; }
+ global $CONFIG;
+ if ($ThisCacheTime == null) { $ThisCacheTime = $CONFIG['CacheTime']; }
$memcache->set($Key, $Value, false, $ThisCacheTime);
}
@@ -35,19 +35,20 @@ function GetCache($Key)
/***********************************************/
-elseif($CacheType == "DB")
+elseif($CONFIG['CacheType'] == "DB")
{
function SetCache($Key, $Value, $ThisCacheTime = null)
{
- global $CacheTime, $CacheTable, $DBObj, $Connection;
- if ($ThisCacheTime == null) { $ThisCacheTime = $CacheTime; }
+ global $CONFIG, $DBObj;
+ if ($ThisCacheTime == null) { $ThisCacheTime = $CONFIG['CacheTime']; }
$ExpireTime = time() + $ThisCacheTime;
$Status = $DBObj->GetStatus();
if ($Status === true)
{
- $SQL = 'INSERT INTO `'.$CacheTable.'` (`Key`, `Value`, `ExpireTime`) VALUES ("'.mysql_real_escape_string($Key,$Connection).'", "'.mysql_real_escape_string(serialize($Value),$Connection).'", "'.mysql_real_escape_string($ExpireTime,$Connection).'");' ;
+ $Connection = $DBObj->GetConnection();
+ $SQL = 'INSERT INTO `'.$CONFIG['CacheTable'].'` (`Key`, `Value`, `ExpireTime`) VALUES ("'.mysql_real_escape_string($Key,$Connection).'", "'.mysql_real_escape_string(serialize($Value),$Connection).'", "'.mysql_real_escape_string($ExpireTime,$Connection).'");' ;
$DBObj->Query($SQL);
$Status = $DBObj->GetStatus();
if ($Status === true){return true;}
@@ -58,12 +59,13 @@ function SetCache($Key, $Value, $ThisCacheTime = null)
function GetCache($Key)
{
- global $CacheTime, $CacheTable, $DBObj, $Connection;
+ global $CONFIG, $DBObj;
$Status = $DBObj->GetStatus();
if ($Status === true)
{
- $SQL = 'SELECT `Value` FROM `'.$CacheTable.'` WHERE (`Key` = "'.mysql_real_escape_string($Key,$Connection).'" AND `ExpireTime` >= "'.mysql_real_escape_string(time(),$Connection).'") LIMIT 1;' ;
+ $Connection = $DBObj->GetConnection();
+ $SQL = 'SELECT `Value` FROM `'.$CONFIG['CacheTable'].'` WHERE (`Key` = "'.mysql_real_escape_string($Key,$Connection).'" AND `ExpireTime` >= "'.mysql_real_escape_string(time(),$Connection).'") LIMIT 1;' ;
$DBObj->Query($SQL);
$Status = $DBObj->GetStatus();
if ($Status === true){
@@ -78,15 +80,15 @@ function GetCache($Key)
/***********************************************/
-elseif($CacheType == "FlatFile")
+elseif($CONFIG['CacheType'] == "FlatFile")
{
function SetCache($Key, $Value, $ThisCacheTime = null)
{
- global $CacheTime, $CacheFolder;
- if ($ThisCacheTime == null) { $ThisCacheTime = $CacheTime; }
+ global $CONFIG;
+ if ($ThisCacheTime == null) { $ThisCacheTime = $CONFIG['CacheTime']; }
$COUNTAINER = array((time() + $ThisCacheTime),$Value);
- $TheFile = $CacheFolder.$Key.".cache";
+ $TheFile = $CONFIG['CacheFolder'].$Key.".cache";
$fh = fopen($TheFile, 'w') or die("can't open cache file for write");
fwrite($fh, serialize($COUNTAINER));
fclose($fh);
@@ -97,9 +99,9 @@ function SetCache($Key, $Value, $ThisCacheTime = null)
function GetCache($Key)
{
- global $CacheFolder;
+ global $CONFIG;
clearstatcache();
- $TheFile = $CacheFolder.$Key.".cache";
+ $TheFile = $CONFIG['CacheFolder'].$Key.".cache";
if (!file_exists($TheFile))
{
return false;
@@ -129,8 +131,8 @@ function GetCache($Key)
{
function SetCache($Key, $Value, $ThisCacheTime = null)
{
- global $CacheTime;
- if ($ThisCacheTime == null) { $ThisCacheTime = $CacheTime; }
+ global $CONFIG;
+ if ($ThisCacheTime == null) { $ThisCacheTime = $CONFIG['CacheTime']; }
return true;
}
Oops, something went wrong.

0 comments on commit a06b625

Please sign in to comment.