Rewritten a lot double-quotes to single-requotes, removed deprecated exception, some...
[core.git] / inc / classes / third_party / api / wernisportal / class_WernisApi.php
index c333778bf2b99bc7ab76391e240aa8b2b859e0a2..42936f106b99d01d7753e698f59ceb3554c05d59 100644 (file)
@@ -25,7 +25,7 @@ class WernisApi extends BaseFrameworkSystem {
        /**
         * Static base API URL
         */
-       private static $apiUrl = "http://www.wds66.com/api/";
+       private static $apiUrl = 'http://www.wds66.com/api/';
 
        /**
         * API Wernis amount
@@ -40,12 +40,12 @@ class WernisApi extends BaseFrameworkSystem {
        /**
         * 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
@@ -57,6 +57,11 @@ class WernisApi extends BaseFrameworkSystem {
         */
        private $statusArray = array();
 
+       /**
+        * Status for 'okay'
+        */
+       private $statusOkay = 'OK';
+
        /**
         * Protected constructor
         *
@@ -201,14 +206,14 @@ class WernisApi extends BaseFrameworkSystem {
                // 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",
@@ -220,13 +225,13 @@ class WernisApi extends BaseFrameworkSystem {
                $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();
@@ -283,7 +288,7 @@ class WernisApi extends BaseFrameworkSystem {
                } else {
                        // All fine here
                        $return = array(
-                               'status'   => "OK",
+                               'status'   => $this->statusOkay,
                                'response' => $response
                        );
                }
@@ -302,7 +307,7 @@ class WernisApi extends BaseFrameworkSystem {
 
                // 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'],
@@ -313,7 +318,7 @@ class WernisApi extends BaseFrameworkSystem {
                // 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 {
@@ -335,7 +340,7 @@ class WernisApi extends BaseFrameworkSystem {
 
                // 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'],
@@ -346,7 +351,7 @@ class WernisApi extends BaseFrameworkSystem {
                // 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 {
@@ -362,24 +367,24 @@ class WernisApi extends BaseFrameworkSystem {
        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
@@ -404,7 +409,7 @@ class WernisApi extends BaseFrameworkSystem {
                // Was the request successfull?
                if ((!ereg("200 OK", $response[0])) && (empty($response[0]))) {
                        // Not found / access forbidden
-                       $response = array("", "", "");
+                       $response = array('', '', '');
                }
 
                // Return response