diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 697249c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: php -php: - - 5.5 - - 5.4 diff --git a/api/.htaccess b/api/.htaccess index 946c51f..0853656 100644 --- a/api/.htaccess +++ b/api/.htaccess @@ -1,2 +1,26 @@ +Header unset Pragma +FileETag None +Header unset ETag + +ExpiresActive On +ExpiresDefault A0 + + +ExpiresDefault A0 +Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform" +Header set Pragma "no-cache" + + +Options +FollowSymLinks RewriteEngine On -RewriteRule ^(.*?)$ https://www.xboxleaders.com/api/1.0/$1 [L,QSA,NE] \ No newline at end of file + +RedirectMatch 301 ^/api/(1\.0|2\.0)/.* https://www.xboxleaders.com/api/ + +RewriteRule ^achievements\.(json|xml)$ achievements.php?format=$1 [L,QSA] +RewriteRule ^games\.(json|xml)$ games.php?format=$1 [L,QSA] +RewriteRule ^profile\.(json|xml)$ profile.php?format=$1 [L,QSA] +RewriteRule ^friends\.(json|xml)$ friends.php?format=$1 [L,QSA] +RewriteRule ^search\.(json|xml)$ search.php?format=$1 [L,QSA] + +RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT) +RewriteRule .* - [F] \ No newline at end of file diff --git a/api/1.0/.htaccess b/api/1.0/.htaccess deleted file mode 100644 index 4de88d6..0000000 --- a/api/1.0/.htaccess +++ /dev/null @@ -1,23 +0,0 @@ -Header unset Pragma -FileETag None -Header unset ETag - -ExpiresActive On -ExpiresDefault A0 - - -ExpiresDefault A0 -Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform" -Header set Pragma "no-cache" - - -Options +FollowSymLinks -RewriteEngine On - -RewriteRule ^achievements\.(json|xml)$ achievements.php?format=$1 [L,QSA] -RewriteRule ^games\.(json|xml)$ games.php?format=$1 [L,QSA] -RewriteRule ^profile\.(json|xml)$ profile.php?format=$1 [L,QSA] -RewriteRule ^friends\.(json|xml)$ friends.php?format=$1 [L,QSA] - -RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT) -RewriteRule .* - [F] \ No newline at end of file diff --git a/api/1.0/achievements.php b/api/1.0/achievements.php deleted file mode 100644 index fcbc986..0000000 --- a/api/1.0/achievements.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -include("../includes/bootloader.php"); -include("includes/kernel.php"); -$api->output_headers(); - -$gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null; -$titleid = (isset($_GET['titleid'])) ? (int)$_GET['titleid'] : null; -$region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US'; - -if($api->offline) { - echo $api->output_error(700); -} else if(!$api->logged_in) { - echo $api->output_error(500); -} else { - if(empty($gamertag)) { - echo $api->output_error(301); - } else if(empty($titleid)) { - echo $api->output_error(302); - } else if($api->check_culture($region) == false) { - echo $api->output_error(305); - } else { - $data = $api->fetch_achievements($gamertag, $titleid, $region); - if($data) { - echo $api->output_payload($data); - } else { - echo $api->output_error($api->error); - } - } -} - -?> \ No newline at end of file diff --git a/api/1.0/friends.php b/api/1.0/friends.php deleted file mode 100644 index 68b7f54..0000000 --- a/api/1.0/friends.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -include("../includes/bootloader.php"); -include("includes/kernel.php"); -$api->output_headers(); - -$gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null; -$region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US'; - -if($api->offline) { - echo $api->output_error(700); -} else if(!$api->logged_in) { - echo $api->output_error(500); -} else { - if(empty($gamertag)) { - echo $api->output_error(301); - } else if($api->check_culture($region) == false) { - echo $api->output_error(305); - } else { - $data = $api->fetch_friends($gamertag, $region); - if($data) { - echo $api->output_payload($data); - } else { - echo $api->output_error($api->error); - } - } -} - -?> \ No newline at end of file diff --git a/api/1.0/games.php b/api/1.0/games.php deleted file mode 100644 index 6e7b30c..0000000 --- a/api/1.0/games.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -include("../includes/bootloader.php"); -include("includes/kernel.php"); -$api->output_headers(); - -$gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null; -$region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US'; - -if($api->offline) { - echo $api->output_error(700); -} else if(!$api->logged_in) { - echo $api->output_error(500); -} else { - if(empty($gamertag)) { - echo $api->output_error(301); - } else if($api->check_culture($region) == false) { - echo $api->output_error(305); - } else { - $data = $api->fetch_games($gamertag, $region); - if($data) { - echo $api->output_payload($data); - } else { - echo $api->output_error($api->error); - } - } -} - -?> \ No newline at end of file diff --git a/api/1.0/includes/classes/api.class.php b/api/1.0/includes/classes/api.class.php deleted file mode 100644 index a922691..0000000 --- a/api/1.0/includes/classes/api.class.php +++ /dev/null @@ -1,332 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -class API extends Base { - /** - * Version of this API - */ - public $version = "1.0"; - - /** - * Fetch profile information - * - * @access public - * @var string gamertag - * @var string region - * @return array - */ - public function fetch_profile($gamertag, $region) { - $gamertag = trim($gamertag); - $url = "http://live.xbox.com/" . $region . "/Profile?gamertag=" . urlencode($gamertag); - $key = $this->version . ":profile." . $gamertag; - - $data = $this->__cache->fetch($key); - if(!$data) { - $data = $this->fetch_url($url); - $this->__cache->store($key, $data, 3600); - } - - if(stripos($data, "
")) { - $user = array(); - $user['Tier'] = (strpos($data, "
") !== false) ? "gold" : "silver"; - $user['IsValid'] = (strpos($data, "errorCode: '404'") !== false) ? 0 : 1; - $user['IsCheater'] = (strpos($data, "
") !== false) ? 1: 0; - $user['IsOnline'] = 0; - $user['OnlineStatus'] = trim(str_replace("\r\n", " - ", trim($this->find($data, "
", "
")))); - if (strpos($data, '
') !== false) { - $user['XBLLaunchTeam'] = (strpos($data, 'xbox360Badge') !== false) ? 1 : 0; - $user['NXELaunchTeam'] = (strpos($data, 'nxeBadge') !== false) ? 1 : 0; - $user['KinectLaunchTeam'] = (strpos($data, 'kinectBadge') !== false) ? 1 : 0; - } - $user['AvatarTile'] = str_replace("https://avatar-ssl", "http://avatar", $this->find($data, "find($data, "find($data, "

", "

"))); - $user['GamerScore'] = trim($this->find($data, "
", "
")); - $user['Reputation'] = 0; - $user['Name'] = ""; - $user['Motto'] = ""; - $user['Location'] = ""; - $user['Bio'] = ""; - - $user['IsOnline'] = (strpos($user['OnlineStatus'], "Last seen") !== false - or (strpos($user['OnlineStatus'], 'Offline') !== false) - or (trim(empty($user['OnlineStatus'])))) ? 0 : 1; - - if(strpos($data, "
") !== false) { - $user['Motto'] = $this->clean(trim(strip_tags($this->find($data, "
", "
")))); - } - if(strpos($data, "
find($data, "
"))); - } - if(strpos($data, "
") !== false) { - $user['Location'] = trim(strip_tags(str_replace("", "", trim($this->find($data, "
", "
"))))); - } - if(strpos($data, "
") !== false) { - $user['Bio'] = trim(strip_tags(str_replace("", "", trim($this->find($data, "
", "
"))))); - } - - preg_match_all('~
~si', $data, $reputation); - foreach ($reputation[1] as $k => $v) { - $starvalue = array( - 'Empty' => 0, 'Quarter' => 1, 'Half' => 2, - 'ThreeQuarter' => 3, 'Full' => 4 - ); - $user['Reputation'] = $user['Reputation'] + $starvalue[$v]; - } - - return $user; - } else if(stripos($data, "errorCode: '404'")) { - $this->error = 501; - return false; - } else { - $this->error = 500; - $this->__cache->remove($key); - $this->force_new_login(); - - return false; - } - } - - /** - * Fetch achievement information for a specific game - * - * @access public - * @var string gamertag - * @var int titleid - * @var string region - * @return array - */ - public function fetch_achievements($gamertag, $titleid, $region) { - $gamertag = trim($gamertag); - $url = "https://live.xbox.com/" . $region . "/Activity/Details?titleId=" . urlencode($titleid) . "&compareTo=" . urlencode($gamertag); - $key = $this->version . ":achievements." . $gamertag . "." . $titleid; - - $data = $this->__cache->fetch($key); - if(!$data) { - $data = $this->fetch_url($url); - $this->__cache->store($key, $data, 3600); - } - - $json = $this->find($data, "broker.publish(routes.activity.details.load, ", ");"); - $json = json_decode($json, true); - - if(!empty($json)) { - $achievements = array(); - - $achievements['Gamertag'] = $g = $json['Players'][0]['Gamertag']; - $achievements['Id'] = $json['Game']['Id']; - $achievements['Title'] = $this->clean($json['Game']['Name']); - $achievements['Url'] = "http://marketplace.xbox.com/" . $region . "/" . $achievements['Id']; - $achievements['BoxArt'] = "http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802" . dechex($achievements['Id']) . "/1033/boxartsm.jpg"; - $achievements['LargeBoxArt'] = "http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802" . dechex($achievements['Id']) . "/1033/boxartlg.jpg"; - $achievements['EarnedGamerScore'] = $json['Game']['Progress'][$g]['Score']; - $achievements['PossibleGamerScore'] = $json['Game']['PossibleScore']; - $achievements['EarnedAchievements'] = $json['Game']['Progress'][$g]['Achievements']; - $achievements['PossibleAchievements'] = $json['Game']['PossibleAchievements']; - $achievements['LastPlayed'] = substr(str_replace(array("/Date(", ")/"), "", $json['Game']['Progress'][$g]['LastPlayed']), 0, 10); - - $i = 0; - foreach($json['Achievements'] as $achievement) { - $achievements['Achievements'][$i]['Id'] = $achievement['Id']; - $achievements['Achievements'][$i]['TileUrl'] = ($achievement['IsHidden'] == "true") ? "https://live.xbox.com/Content/Images/HiddenAchievement.png" : $achievement['TileUrl']; - $achievements['Achievements'][$i]['Title'] = ""; - $achievements['Achievements'][$i]['Description'] = ""; - - if(!empty($achievement['Name'])) { - $achievements['Achievements'][$i]['Title'] = $this->clean($achievement['Name']); - } else { - $achievements['Achievements'][$i]['Title'] = "Secret Achievement"; - } - - if(!empty($achievement['Description'])) { - $achievements['Achievements'][$i]['Description'] = $this->clean($achievement['Description']); - } else { - $achievements['Achievements'][$i]['Description'] = "This is a secret achievement. Unlock it to find out more."; - } - - if(!empty($achievement['Score'])) { - $achievements['Achievements'][$i]['GamerScore'] = $achievement['Score']; - } else { - $achievements['Achievements'][$i]['GamerScore'] = "--"; - } - - $achievements['Achievements'][$i]['IsSecret'] = ($achievement['IsHidden']) ? "yes" : "no"; - - if(!empty($achievement['EarnDates'][$g]['EarnedOn'])) { - $achievements['Achievements'][$i]['Unlocked'] = "yes"; - $achievements['Achievements'][$i]['DateEarned'] = substr(str_replace(array("/Date(", ")/"), "", $achievement['EarnDates'][$g]['EarnedOn']), 0, 10); - $achievements['Achievements'][$i]['EarnedOffline'] = ($achievement['EarnDates'][$g]['IsOffline'] == "true") ? "yes" : "no"; - } else { - $achievements['Achievements'][$i]['Unlocked'] = "no"; - $achievements['Achievements'][$i]['DateEarned'] = null; - $achievements['Achievements'][$i]['EarnedOffline'] = null; - } - - $i++; - } - - return $achievements; - } else if(stripos($data, "errorCode: '404'")) { - $this->error = 502; - return false; - } else { - $this->error = 500; - $this->__cache->remove($key); - $this->force_new_login(); - - return false; - } - } - - /** - * Fetch information about played games - * - * @access public - * @var string gamertag - * @var string region - * @return array - */ - public function fetch_games($gamertag, $region) { - $gamertag = trim($gamertag); - $url = "https://live.xbox.com/" . $region . "/Activity?compareTo=" . urlencode($gamertag); - $key = $this->version . ":games." . $gamertag; - - $data = $this->__cache->fetch($key); - if(!$data) { - $data = $this->fetch_url($url); - $post_data = "__RequestVerificationToken=" . urlencode(trim($this->find($data, ""))); - $headers = array("X-Requested-With: XMLHttpRequest", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8"); - - $data = $this->fetch_url("https://live.xbox.com/" . $region . "/Activity/Summary?compareTo=" . urlencode($gamertag) . "&lc=1033", $url, 10, $post_data, $headers); - $this->__cache->store($key, $data, 3600); - } - - $json = json_decode($data, true); - - if($json['Success'] == "true" && $json['Data']['Players'][0]['Gamertag'] != "xboxleaders com") { - $json = $json['Data']; - $games = array(); - - $games['Gamertag'] = $g = $json['Players'][0]['Gamertag']; - $games['Gamerpic'] = "http://avatar.xboxlive.com/avatar/" . $games['Gamertag'] . "/avatarpic-l.png"; - $games['GameCount'] = $json['Players'][0]['GameCount']; - $games['TotalEarnedGamerScore'] = $json['Players'][0]['Gamerscore']; - $games['TotalPossibleGamerScore'] = 0; - $games['TotalEarnedAchievements'] = 0; - $games['TotalPossibleAchievements'] = 0; - $games['TotalPercentCompleted'] = $json['Players'][0]['PercentComplete']; - - $i = 0; - foreach($json['Games'] as $game) { - if($game['Progress'][$g]['LastPlayed'] !== "null" && $game['PossibleScore'] !== 0) { - $games['PlayedGames'][$i]['Id'] = $game['Id']; - $games['PlayedGames'][$i]['Title'] = $game['Name']; - $games['PlayedGames'][$i]['Url'] = "http://marketplace.xbox.com/" . $region . "/Title/" . $game['Id'] . "/"; - $games['PlayedGames'][$i]['BoxArt'] = "http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802" . dechex($game['Id']) . "/1033/boxartsm.jpg"; - $games['PlayedGames'][$i]['LargeBoxArt'] = "http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802" . dechex($game['Id']) . "/1033/boxartlg.jpg"; - $games['PlayedGames'][$i]['EarnedGamerScore'] = $game['Progress'][$g]['Score']; - $games['PlayedGames'][$i]['PossibleGamerScore'] = $game['PossibleScore']; - $games['PlayedGames'][$i]['EarnedAchievements'] = $game['Progress'][$g]['Achievements']; - $games['PlayedGames'][$i]['PossibleAchievements'] = $game['PossibleAchievements']; - $games['PlayedGames'][$i]['PercentageCompleted'] = round((($game['Progress'][$g]['Achievements'] / $game['PossibleAchievements']) * 100), 1); - $games['PlayedGames'][$i]['LastPlayed'] = (int)substr(str_replace(array("/Date(", ")/"), "", $game['Progress'][$g]['LastPlayed']), 0, 10); - - $games['TotalPossibleGamerScore'] = $games['TotalPossibleGamerScore'] + $games['PlayedGames'][$i]['PossibleGamerScore']; - $games['TotalEarnedAchievements'] = $games['TotalEarnedAchievements'] + $games['PlayedGames'][$i]['EarnedAchievements']; - $games['TotalPossibleAchievements'] = $games['TotalPossibleAchievements'] + $games['PlayedGames'][$i]['PossibleAchievements']; - - $i++; - } - } - - return $games; - } else if($json['Data']['Players'][0]['Gamertag'] == "xboxleaders com") { - $this->error = 501; - return false; - } else { - $this->error = 500; - $this->__cache->remove($key); - $this->force_new_login(); - - return false; - } - } - - /** - * Fetch data about a players' friends list - * - * @access public - * @var string gamertag - * @var string region - * @return array - */ - public function fetch_friends($gamertag, $region) { - $gamertag = trim($gamertag); - $url = "https://live.xbox.com/" . $region . "/Friends"; - $key = $this->version . ":friends." . $gamertag; - - $data = $this->__cache->fetch($key); - if(!$data) { - $data = $this->fetch_url($url); - $post_data = "__RequestVerificationToken=" . urlencode(trim($this->find($data, ""))); - $headers = array("X-Requested-With: XMLHttpRequest", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8"); - - $data = $this->fetch_url("https://live.xbox.com/" . $region . "/Friends/List?Gamertag=" . urlencode($gamertag), $url, 10, $post_data, $headers); - $this->__cache->store($data, 3600); - } - - $json = json_decode($data, true); - if(!empty($json['Data']['Friends'])) { - $friends = array(); - $friends['TotalFriends'] = 0; - $friends['TotalOnlineFriends'] = 0; - $friends['TotalOfflineFriends'] = 0; - - $i = 0; - foreach($json['Data']['Friends'] as $friend) { - $friends['Friends'][$i]['Gamertag'] = $friend['GamerTag']; - $friends['Friends'][$i]['AvatarSmall'] = $friend['GamerTileUrl']; - $friends['Friends'][$i]['AvatarLarge'] = $friend['LargeGamerTileUrl']; - $friends['Friends'][$i]['GamerScore'] = $friend['GamerScore']; - $friends['Friends'][$i]['IsOnline'] = $friend['IsOnline'] == 1 ? "true" : "false"; - $friends['Friends'][$i]['PresenceInfo']['LastOnline'] = substr(str_replace(array("/Date(", ")/"), "", $friend['LastSeen']), 0, 10); - $friends['Friends'][$i]['PresenceInfo']['OnlineStatus'] = $friend['Presence']; - $friends['Friends'][$i]['PresenceInfo']['Game']['Title'] = $friend['TitleInfo']['Name']; - $friends['Friends'][$i]['PresenceInfo']['Game']['Id'] = $friend['TitleInfo']['Id']; - $friends['Friends'][$i]['PresenceInfo']['Game']['Url'] = "http://marketplace.xbox.com/" . $region . "/Title/" . $friend['TitleInfo']['Id'] . "/"; - - $friends['TotalFriends'] = ++$friends['TotalFriends']; - if($friend['IsOnline']) { - $friends['TotalOnlineFriends'] = ++$friends['TotalOnlineFriends']; - } else { - $friends['TotalOfflineFriends'] = ++$friends['TotalOfflineFriends']; - } - ++$i; - } - - return $friends; - } else { - $this->error = 503; - $this->__cache->remove($key); - $this->force_new_login(); - - return false; - } - } -} - -?> \ No newline at end of file diff --git a/api/1.0/includes/kernel.php b/api/1.0/includes/kernel.php deleted file mode 100644 index cf5ff4e..0000000 --- a/api/1.0/includes/kernel.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -include("classes/api.class.php"); - -$api = new API($cache); - -$api->format = (isset($_GET['format']) && in_array($_GET['format'], array("xml", "json"))) ? strtolower(trim($_GET['format'])) : "xml"; -$api->version = "1.0"; -$api->debug = (isset($_GET['debug'])); -$api->cookie_file = COOKIE_FILE; -$api->debug_file = DEBUG_FILE; -$api->stack_trace_file = STACK_TRACE_FILE; -$api->access_file = ACCESS_FILE; -$api->save_to_access($_SERVER['REMOTE_ADDR'] . " " . $_SERVER['REQUEST_URI']); - -$api->init(XBOX_EMAIL, XBOX_PASSWORD); - -?> \ No newline at end of file diff --git a/api/1.0/index.php b/api/1.0/index.php deleted file mode 100644 index 38052d6..0000000 --- a/api/1.0/index.php +++ /dev/null @@ -1,18 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -include("../includes/bootloader.php"); -include("includes/kernel.php"); -$api->output_headers(); - -echo $api->output_error(304); - -?> \ No newline at end of file diff --git a/api/1.0/profile.php b/api/1.0/profile.php deleted file mode 100644 index b042726..0000000 --- a/api/1.0/profile.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @license http://opensource.org/licenses/mit-license.php The MIT License - */ - -include("../includes/bootloader.php"); -include("includes/kernel.php"); -$api->output_headers(); - -$gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null; -$region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US'; - -if($api->offline) { - echo $api->output_error(700); -} else if(!$api->logged_in) { - echo $api->output_error(500); -} else { - if(empty($gamertag)) { - echo $api->output_error(301); - } else if($api->check_culture($region) == false) { - echo $api->output_error(305); - } else { - $data = $api->fetch_profile($gamertag, $region); - if($data) { - echo $api->output_payload($data); - } else { - echo $api->output_error($api->error); - } - } -} - -?> \ No newline at end of file diff --git a/api/2.0/.htaccess b/api/2.0/.htaccess deleted file mode 100644 index 7bdd338..0000000 --- a/api/2.0/.htaccess +++ /dev/null @@ -1,24 +0,0 @@ -Header unset Pragma -FileETag None -Header unset ETag - -ExpiresActive On -ExpiresDefault A0 - - -ExpiresDefault A0 -Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform" -Header set Pragma "no-cache" - - -Options +FollowSymLinks -RewriteEngine On - -RewriteRule ^achievements\.(json|xml)$ achievements.php?format=$1 [L,QSA] -RewriteRule ^games\.(json|xml)$ games.php?format=$1 [L,QSA] -RewriteRule ^profile\.(json|xml)$ profile.php?format=$1 [L,QSA] -RewriteRule ^friends\.(json|xml)$ friends.php?format=$1 [L,QSA] -RewriteRule ^search\.(json|xml)$ search.php?format=$1 [L,QSA] - -RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT) -RewriteRule .* - [F] \ No newline at end of file diff --git a/api/2.0/achievements.php b/api/achievements.php similarity index 100% rename from api/2.0/achievements.php rename to api/achievements.php diff --git a/api/2.0/friends.php b/api/friends.php similarity index 100% rename from api/2.0/friends.php rename to api/friends.php diff --git a/api/2.0/games.php b/api/games.php similarity index 100% rename from api/2.0/games.php rename to api/games.php diff --git a/api/2.0/includes/classes/api.class.php b/api/includes/classes/api.class.php similarity index 100% rename from api/2.0/includes/classes/api.class.php rename to api/includes/classes/api.class.php diff --git a/api/includes/classes/cache.class.php b/api/includes/classes/cache.class.php index 35ac8ce..2d8322d 100644 --- a/api/includes/classes/cache.class.php +++ b/api/includes/classes/cache.class.php @@ -11,7 +11,8 @@ * @license http://opensource.org/licenses/mit-license.php The MIT License * *******************************************************************************/ -class Cache { +class Cache +{ public $driver = 'disk'; public $root = '/tmp/'; public $hits = 0; @@ -21,77 +22,116 @@ class Cache { function __construct($driver = null, $root = null) { - if ($driver) { + if ($driver) + { $this->driver = strtolower($driver); } - if ($root) { + + if ($root) + { $this->root = $root; } - if ($this->driver == 'apc') { - if(!function_exists('apc_fetch')) $this->driver = 'disk'; - } elseif ($this->driver == 'memcached') { - if (!class_exists('Memcached')) { + + if ($this->driver == 'apc') + { + if(!function_exists('apc_fetch')) + { + $this->driver = 'disk'; + } + } + elseif ($this->driver == 'memcached') + { + if (!class_exists('Memcached')) + { $this->driver = 'disk'; } - } elseif ($this->driver == 'xcache') { - if (!function_exists('xcache_get')) { + } + elseif ($this->driver == 'xcache') + { + if (!function_exists('xcache_get')) + { $this->driver = 'disk'; } } - if ($this->driver == 'memcached') { + if ($this->driver == 'memcached') + { $this->__memcached = new Memcached(); $this->__memcached->addServer('localhost', 11211); - } elseif ($this->driver == 'disk') { + } + elseif ($this->driver == 'disk') + { $file = $this->root . 'c_index'; - if (!file_exists($file)) { + if (!file_exists($file)) + { $this->save_index(); - } else { + } + else + { $this->index = unserialize(file_get_contents($file)); } $handle = opendir($this->root); - if ($handle) { - while (false !== ($file = readdir($handle))) { - if (substr($file, 0, 2) == 'c_') { + if ($handle) + { + while (false !== ($file = readdir($handle))) + { + if (substr($file, 0, 2) == 'c_') + { $key = str_replace(array('c_', '.cache'), '', $file); $created = filemtime($this->root . $file); $ttl = (int)$this->index[$key]['ttl']; $expires = $created + $ttl; - if ($expires < time() && $ttl !== 0) { + if ($expires < time() && $ttl !== 0) + { unlink($this->root . $file); unset($this->index[$key]); } } } + closedir($handle); } + $this->save_index(); } } public function fetch($key) { - if ($this->driver == 'apc') { + if ($this->driver == 'apc') + { $data = apc_fetch($key); - } elseif ($this->driver == 'xcache') { + } + elseif ($this->driver == 'xcache') + { $data = xcache_get($key); - } elseif ($this->driver == 'memcached') { + } + elseif ($this->driver == 'memcached') + { $data = $this->__memcached->get($key); - } elseif ($this->driver == 'disk') { + } + elseif ($this->driver == 'disk') + { $file = $this->get_filename($key); - if (file_exists($file)) { + + if (file_exists($file)) + { $data = file_get_contents($file); } } - if (isset($data) && $data) { + if (isset($data) && $data) + { $this->hits++; - } else { + } + else + { $this->misses++; } + $data = unserialize($data); return $data; @@ -101,16 +141,24 @@ public function store($key, $data, $ttl = 0) { $data = serialize($data); - if ($this->driver == 'apc') { + if ($this->driver == 'apc') + { return apc_store($key, $data, $ttl); - } elseif ($this->driver == 'memcached') { + } + elseif ($this->driver == 'memcached') + { return $this->__memcached->set($key, $data, $ttl); - } elseif ($this->driver == 'xcache') { + } + elseif ($this->driver == 'xcache') + { return xcache_set($key, $data, $ttl); - } elseif ($this->driver == 'disk') { + } + elseif ($this->driver == 'disk') + { $file = $this->get_filename($key); - if (file_exists($file)) { + if (file_exists($file)) + { unlink($file); } @@ -130,16 +178,24 @@ public function store($key, $data, $ttl = 0) public function remove($key) { - if ($this->driver == 'apc') { + if ($this->driver == 'apc') + { return apc_delete($key); - } elseif ($this->driver == 'memcached') { + } + elseif ($this->driver == 'memcached') + { return $this->__memcached->delete($key); - } elseif ($this->driver == 'xcache') { + } + elseif ($this->driver == 'xcache') + { return xcache_unset($key); - } elseif ($this->driver == 'disk') { + } + elseif ($this->driver == 'disk') + { $file = $this->get_filename($key); - if (file_exists($file)) { + if (file_exists($file)) + { unlink($file); } diff --git a/api/2.0/includes/kernel.php b/api/includes/kernel.php similarity index 100% rename from api/2.0/includes/kernel.php rename to api/includes/kernel.php diff --git a/api/2.0/index.php b/api/index.php similarity index 100% rename from api/2.0/index.php rename to api/index.php diff --git a/api/2.0/profile.php b/api/profile.php similarity index 100% rename from api/2.0/profile.php rename to api/profile.php diff --git a/api/2.0/search.php b/api/search.php similarity index 100% rename from api/2.0/search.php rename to api/search.php diff --git a/index.php b/index.php index f01c28f..356dad7 100644 --- a/index.php +++ b/index.php @@ -58,7 +58,7 @@