Skip to content

Commit

Permalink
Fixes #13
Browse files Browse the repository at this point in the history
More documentation changes, made timestamps consistent throughout (ints
vs strings), removed double HTML encoding.
  • Loading branch information
Jason Clemons committed Jul 8, 2013
1 parent 3f5977f commit 136a300
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
3 changes: 2 additions & 1 deletion source/2.0/includes/classes/api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ public function fetch_achievements($gamertag, $gameid, $region) {

if(!empty($achievement['EarnDates'][$g]['EarnedOn'])) {
$achievements['achievements'][$i]['unlocked'] = true;
$achievements['achievements'][$i]['unlockdate'] = substr(str_replace(array("/Date(", ")/"), "", $achievement['EarnDates'][$g]['EarnedOn']), 0, 10);
$achievements['achievements'][$i]['unlockdate'] = (int)substr(str_replace(array("/Date(", ")/"), "", $achievement['EarnDates'][$g]['EarnedOn']), 0, 10);
} else {
$achievements['achievements'][$i]['unlocked'] = false;
$achievements['achievements'][$i]['unlockdate'] = null;
}

$i++;
Expand Down
73 changes: 56 additions & 17 deletions source/includes/classes/base.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
*******************************************************************************/

class Base {
public $__cache;
public $__cache; // cache model resource

public $error;
public $stack_trace = array();
public $logged_in = false;
public $redirects = 0;
public $error; // error code
public $stack_trace = array(); // stack trace array for logging
public $logged_in = false; // flag indicating whether the current session is logged in
public $redirects = 0; // number of current redirects, prevents infinite loops

public $email, $password;
public $debug = false;
public $timeout = 8;
public $email, $password; // email/password of the scraper account
public $debug = false; // debug mode flag
public $timeout = 8; // number of seconds to timeout session

public $cookie_file = "";
public $debug_file = "";
public $stack_trace_file = "";
public $access_file = "";
public $cookie_file = ""; // cookie jar path
public $debug_file = ""; // debug file path
public $stack_trace_file = ""; // stack trace file path
public $access_file = ""; // access log file path

public $runtime = null;
public $ip = null;
public $format = "xml";
public $version = null;
public $runtime = null; // current runtime
public $ip = null; // ip address to use for session, generated in __construct()
public $format = "xml"; // default response format
public $version = null; // current api version

/**
* Error Codes
Expand Down Expand Up @@ -166,6 +166,12 @@ public function save_to_access($string) {
}
}

/**
* Check culture code against Xbox's list of supported regions
*
* @var $code int
* @return bool
*/
public function check_culture($code) {
$valid_codes = array(
'es-AR', 'en-AU', 'de-AT', 'nl-BE',
Expand All @@ -185,6 +191,11 @@ public function check_culture($code) {
return in_array($code, $valid_codes, true);
}

/**
* Perform login to Xbox LIVE
*
* @return bool
*/
protected function perform_login() {
if(empty($this->email)) {
$this->error = 601;
Expand Down Expand Up @@ -265,6 +276,11 @@ protected function perform_login() {
}
}

/**
* Check the current session to see if it's logged in
*
* @return bool
*/
protected function check_login() {
if(file_exists($this->cookie_file)) {
if(time() - filemtime($this->cookie_file) >= 3600 || filesize($this->cookie_file) == 0) {
Expand All @@ -285,6 +301,11 @@ protected function check_login() {
}
}

/**
* Force a new login session
*
* @return bool
*/
protected function force_new_login() {
$this->empty_cookie_file();
$this->logged_in = false;
Expand All @@ -297,6 +318,16 @@ protected function force_new_login() {
return false;
}

/**
* Perform the actual HTTP request
*
* @var $url string
* @var $referer string
* @var $timeout int
* @var $post_data array
* @var $headers array
* @return string
*/
protected function fetch_url($url, $referer = "", $timeout = null, $post_data = null, $headers = null) {
if($this->redirects > 4) {
$this->error = 606;
Expand Down Expand Up @@ -379,6 +410,14 @@ protected function fetch_url($url, $referer = "", $timeout = null, $post_data =
return $result;
}

/**
* Find a given string inside a string
*
* @var $haystack string
* @var $start string
* @var $finish string
* @return string
*/
protected function find($haystack, $start, $finish) {
if(!empty($haystack)) {
$s = explode($start, $haystack);
Expand All @@ -395,7 +434,7 @@ protected function find($haystack, $start, $finish) {

protected function clean($string) {
$string = html_entity_decode($string, ENT_QUOTES, "UTF-8");
$string = htmlentities(htmlentities($string, ENT_QUOTES, "UTF-8"));
$string = htmlentities($string, ENT_QUOTES, "UTF-8");

if(function_exists("mb_convert_encoding")) {
$string = mb_convert_encoding($string, "UTF-8");
Expand Down

0 comments on commit 136a300

Please sign in to comment.