]> git.mxchange.org Git - core.git/blobdiff - inc/classes/third_party/api/wernisportal/class_WernisApi.php
'public static final' is correct
[core.git] / inc / classes / third_party / api / wernisportal / class_WernisApi.php
index cdda5d45d68ad99a3d723d59c9d2cf946193d822..3c8d700512d17554551f35e9b7e0521d06fb299e 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -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
         *
@@ -65,10 +70,6 @@ class WernisApi extends BaseFrameworkSystem {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
        }
 
        /**
@@ -77,7 +78,7 @@ class WernisApi extends BaseFrameworkSystem {
         * @param       $cfg                    Configuration array
         * @return      $apiInstance    An instance of this API class
         */
-       public final static function createWernisApi (array $cfg) {
+       public static final function createWernisApi (array $cfg) {
                // Create a new instance
                $apiInstance = new WernisApi();
 
@@ -201,14 +202,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",
@@ -217,16 +218,22 @@ class WernisApi extends BaseFrameworkSystem {
                }
 
                // All (maybe) fine so remove the response header from server
-               $response = $response[(count($response) - 1)];
+               for ($idx = (count($response) - 1); $idx > 1; $idx--) {
+                       $line = trim($response[$idx]);
+                       if (!empty($line)) {
+                               $response = $line;
+                               break;
+                       }
+               }
 
                // 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 +290,7 @@ class WernisApi extends BaseFrameworkSystem {
                } else {
                        // All fine here
                        $return = array(
-                               'status'   => "OK",
+                               'status'   => $this->statusOkay,
                                'response' => $response
                        );
                }
@@ -302,7 +309,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 +320,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 +342,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 +353,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 +369,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 +411,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