/**
* Static base API URL
*/
- private static $apiUrl = "http://www.wds66.com/api/";
+ private static $apiUrl = 'http://www.wds66.com/api/';
/**
* API Wernis amount
/**
* API Wernis password (not account password!)
*/
- private $w_md5 = "";
+ private $w_md5 = '';
/**
* Nickname of the user
*/
- private $w_nick = "";
+ private $w_nick = '';
/**
* Wernis amount of the user
*/
private $statusArray = array();
+ /**
+ * Status for 'okay'
+ */
+ private $statusOkay = 'OK';
+
/**
* Protected constructor
*
// Construct the request string
$requestString = $this->config['api_url'] . $scriptName."?api_id=".$this->config['wernis_api_id']."&api_key=".$this->config['wernis_api_key'];
foreach ($requestData as $key => $value) {
- $requestString .= "&".$key."=".$value;
+ $requestString .= '&' . $key . '=' . $value;
}
// Get the raw response from the lower function
$response = $this->sendRawRequest($requestString);
// Check the response header if all is fine
- if (strpos($response[0], "200") === false) {
+ if (strpos($response[0], '200') === false) {
// Something bad happend... :(
return array(
'status' => "request_error",
$response = $response[(count($response) - 1)];
// Prepare the returning result for higher functions
- if (substr($response, 0, 1) == "&") {
+ if (substr($response, 0, 1) == '&') {
// Remove the leading & (which can be used in Flash)
$response = substr($response, 1);
}
// Bring back the response
- $data = explode("=", $response);
+ $data = explode('=', $response);
// Default return array (should not stay empty)
$return = array();
} else {
// All fine here
$return = array(
- 'status' => "OK",
+ 'status' => $this->statusOkay,
'response' => $response
);
}
// Prepare the request data
$requestData = array(
- 'sub_request' => "receive",
+ 'sub_request' => 'receive',
't_uid' => $this->w_id,
't_md5' => $this->w_md5,
'r_uid' => (int)$this->config['wernis_refid'],
// Return the result from the lower functions
$return = $this->sendRequest("book.php", $requestData);
- if ($return['status'] == "OK") {
+ if ($return['status'] == $this->statusOkay) {
// All fine!
$result = true;
} else {
// Prepare the request data
$requestData = array(
- 'sub_request' => "send",
+ 'sub_request' => 'send',
't_uid' => $this->w_id,
't_md5' => $this->w_md5,
'r_uid' => (int)$this->config['wernis_refid'],
// Return the result from the lower functions
$return = $this->sendRequest("book.php", $requestData);
- if ($return['status'] == "OK") {
+ if ($return['status'] == $this->statusOkay) {
// All fine!
$result = true;
} else {
private function sendRawRequest ($script) {
// Use the hostname from script URL as new hostname
$url = substr($script, 7);
- $extract = explode("/", $url);
+ $extract = explode('/', $url);
// Done extracting the URL :)
$url = $extract[0];
// Extract host name
- $host = str_replace("http://", "", $url);
- if (ereg("/", $host)) $host = substr($host, 0, strpos($host, "/"));
+ $host = str_replace("http://", '', $url);
+ if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/'));
// Generate relative URL
$script = substr($script, (strlen($url) + 7));
- if (substr($script, 0, 1) == "/") $script = substr($script, 1);
+ if (substr($script, 0, 1) == '/') $script = substr($script, 1);
// Open connection
$fp = @fsockopen($host, 80, $errno, $errdesc, 30);
if (!$fp) {
// Failed!
- return array("", "", "");
+ return array('', '', '');
}
// Generate request header
// Was the request successfull?
if ((!ereg("200 OK", $response[0])) && (empty($response[0]))) {
// Not found / access forbidden
- $response = array("", "", "");
+ $response = array('', '', '');
}
// Return response