]> git.mxchange.org Git - core.git/blobdiff - inc/classes/third_party/api/wernisportal/class_WernisApi.php
Made lower to upper case:
[core.git] / inc / classes / third_party / api / wernisportal / class_WernisApi.php
index 42936f106b99d01d7753e698f59ceb3554c05d59..5600032c28de1f12d4b37f64be6cacf9c96da3e3 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -70,10 +70,6 @@ class WernisApi extends BaseFrameworkSystem {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
        }
 
        /**
@@ -82,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();
 
@@ -146,7 +142,7 @@ class WernisApi extends BaseFrameworkSystem {
                global $_CONFIG;
                include "templates/zurueck.html";
                include "templates/fuss.html";
-               die();
+               exit();
        }
 
        // Fehlermeldung ausgeben und beenden
@@ -213,7 +209,7 @@ class WernisApi extends BaseFrameworkSystem {
                $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",
@@ -222,7 +218,13 @@ 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) == '&') {
@@ -300,7 +302,7 @@ class WernisApi extends BaseFrameworkSystem {
        // Widthdraw this amount
        private function executeWithdraw ($amount) {
                // First all fails...
-               $result = false;
+               $result = FALSE;
 
                // Prepare the purpose
                $purpose = "\"Bube oder Dame\"-Einsatz gesetzt.";
@@ -320,7 +322,7 @@ class WernisApi extends BaseFrameworkSystem {
 
                if ($return['status'] == $this->statusOkay) {
                        // All fine!
-                       $result = true;
+                       $result = TRUE;
                } else {
                        // Status failture text
                        $this->setStatusMessage($return['message'], $return['status']);
@@ -333,7 +335,7 @@ class WernisApi extends BaseFrameworkSystem {
        // Payout this amount
        private function executePayout ($amount) {
                // First all fails...
-               $result = false;
+               $result = FALSE;
 
                // Prepare the purpose
                $purpose = "\"Bube oder Dame\"-Gewinn erhalten.";
@@ -353,7 +355,7 @@ class WernisApi extends BaseFrameworkSystem {
 
                if ($return['status'] == $this->statusOkay) {
                        // All fine!
-                       $result = true;
+                       $result = TRUE;
                } else {
                        // Status failture text
                        $this->setStatusMessage($return['message'], $return['status']);
@@ -390,7 +392,7 @@ class WernisApi extends BaseFrameworkSystem {
                // Generate request header
                $request  = "GET /".trim($script)." HTTP/1.0\r\n";
                $request .= "Host: ".$host."\r\n";
-               $request .= sprintf("User-Agent: Bube oder Dame / 1.0 by Quix0r [Spieler: %d]\r\n\r\n", $this->w_id);
+               $request .= sprintf("User-Agent: WernisApi/1.0 by Quix0r [Spieler: %d]\r\n\r\n", $this->w_id);
 
                // Initialize array
                $response = array();
@@ -400,17 +402,17 @@ class WernisApi extends BaseFrameworkSystem {
 
                // Read response
                while(!feof($fp)) {
-                       $response[] = trim(fgets($fp, 1024));
-               }
+                       array_push($response, trim(fgets($fp, 1024)));
+               } // END - while
 
                // Close socket
                fclose($fp);
 
                // Was the request successfull?
-               if ((!ereg("200 OK", $response[0])) && (empty($response[0]))) {
+               if ((!ereg('200 OK', $response[0])) && (empty($response[0]))) {
                        // Not found / access forbidden
                        $response = array('', '', '');
-               }
+               } // END - if
 
                // Return response
                return $response;