]> git.mxchange.org Git - mailer.git/commitdiff
Wernis extension can now contact the API
authorRoland Häder <roland@mxchange.org>
Sun, 3 Feb 2008 22:05:51 +0000 (22:05 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 3 Feb 2008 22:05:51 +0000 (22:05 +0000)
inc/extensions/ext-wernis.php
inc/functions.php
inc/language/wernis_de.php
inc/libs/wernis_functions.php
inc/modules/admin/what-config_wernis.php
templates/de/html/admin/admin_config_wernis.tpl

index d82e998115b7753bae48923bdca50eeee522e613..33ea71e91162c8ea0681bd80ad56b41fd429588c 100644 (file)
@@ -65,6 +65,7 @@ PRIMARY KEY(id)
        $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_min_amount bigint(20) not null default '40000'";
        $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_id bigint(20) not null default '0'";
        $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_md5 varchar(32) not null default ''";
        $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_min_amount bigint(20) not null default '40000'";
        $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_id bigint(20) not null default '0'";
        $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_md5 varchar(32) not null default ''";
+       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD wernis_api_url varchar(255) not null default 'http://www.wds66.com/api/'";
        $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', '', '{!POINTS!}-Management', 'Konfiguration zur WDS66-API einstellen, Auszahlungen auflisten usw..', 15)";
        $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', 'config_wernis', 'WDS66-API-Einstellungen', 'Konfiguration zur WDS66-API einstellen.', 1)";
        $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', 'list_wernis', '{!POINTS!}-Anfragen auflisten', 'Listet alle {!POINTS!}-Auszahlungsanfragen Ihrer Mitglieder auf.', 2)";
        $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', '', '{!POINTS!}-Management', 'Konfiguration zur WDS66-API einstellen, Auszahlungen auflisten usw..', 15)";
        $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', 'config_wernis', 'WDS66-API-Einstellungen', 'Konfiguration zur WDS66-API einstellen.', 1)";
        $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES('wernis', 'list_wernis', '{!POINTS!}-Anfragen auflisten', 'Listet alle {!POINTS!}-Auszahlungsanfragen Ihrer Mitglieder auf.', 2)";
@@ -103,6 +104,7 @@ default: // Do stuff when extension is loaded
        $CONFIG['wernis_min_amount'] = $DUMMY['wernis_min_amount'];
        $CONFIG['wernis_api_id']     = $DUMMY['wernis_api_id'];
        $CONFIG['wernis_api_md5']    = $DUMMY['wernis_api_md5'];
        $CONFIG['wernis_min_amount'] = $DUMMY['wernis_min_amount'];
        $CONFIG['wernis_api_id']     = $DUMMY['wernis_api_id'];
        $CONFIG['wernis_api_md5']    = $DUMMY['wernis_api_md5'];
+       $CONFIG['wernis_api_url']    = $DUMMY['wernis_api_url'];
        unset($DUMMY);
        break;
 }
        unset($DUMMY);
        break;
 }
index d675eca81b5abe6dba65c639bbfbf7f4d6f1f816..161c73c35ddfcfc3d13ea97a30b85670b6587434 100644 (file)
@@ -1718,12 +1718,25 @@ function ADD_EMAIL_NAV($PAGES, $offset, $show_form, $colspan, $return=false) {
 
 //
 function MXCHANGE_OPEN($script) {
 
 //
 function MXCHANGE_OPEN($script) {
+       // Compile the script name
+       $script = COMPILE_CODE($script);
+
+       // Use default SERVER_URL by default... ;) So?
+       $url = SERVER_URL;
+       if (substr($script, 0, 7) == "http://") {
+               // Use the hostname from script URL as new hostname
+               $url = substr($script, 7);
+               $extract = explode("/", $url);
+               $url = $extract[0];
+               // Done extracting the URL :)
+       }
+
        // Extract host name
        // Extract host name
-       $host = str_replace("http://", "", SERVER_URL);
+       $host = str_replace("http://", "", $url);
        if (ereg("/", $host)) $host = substr($host, 0, strpos($host, "/"));
 
        // Generate relative URL
        if (ereg("/", $host)) $host = substr($host, 0, strpos($host, "/"));
 
        // Generate relative URL
-       $script = substr(SERVER_URL, (strpos(SERVER_URL, $host) + strlen($host)))."/".basename($script);
+       $script = substr($script, (strlen($url) + 7));
        if (substr($script, 0, 1) == "/") $script = substr($script, 1);
 
        // Open connection
        if (substr($script, 0, 1) == "/") $script = substr($script, 1);
 
        // Open connection
index 77fbdfc51a858fcc5f5b3b136e4efe1944a5b3e5..a57ab71099538878fba253c0eb2e7b77d2626a3d 100644 (file)
@@ -32,8 +32,7 @@
  ************************************************************************/
 
 // Some security stuff...
  ************************************************************************/
 
 // Some security stuff...
-if (basename($_SERVER['PHP_SELF']) == basename(__FILE__))
-{
+if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
@@ -45,10 +44,18 @@ define('WERNIS_ADMIN_CONFIG_TITLE', "Einstellungen zum WDS66-Hauptaccount:");
 define('WERNIS_ADMIN_MIN_AMOUNT', "Minimumguthaben von {!POINTS!} f&uuml;r Auszahlungen.");
 define('WERNIS_ADMIN_API_ID', "WDS66-API-ID (api_id=x)");
 define('WERNIS_ADMIN_API_MD5', "WDS66-API-Key (api_md5=xxxxx; 32-stellig)");
 define('WERNIS_ADMIN_MIN_AMOUNT', "Minimumguthaben von {!POINTS!} f&uuml;r Auszahlungen.");
 define('WERNIS_ADMIN_API_ID', "WDS66-API-ID (api_id=x)");
 define('WERNIS_ADMIN_API_MD5', "WDS66-API-Key (api_md5=xxxxx; 32-stellig)");
+define('WERNIS_ADMIN_API_URL', "Basis-URL der API-Skripte");
 define('WERNIS_ADMIN_CONFIG_NOTE', "<A href=\"http://www.wds66.com/ref.php?refid=10437\" target=\"_blank\">Hier</A> k&ouml;nnen Sie schon f&uuml;r <strong>5,00&euro;</strong>=<strong>25.000 Abfragen</strong> ein API-Account beantragen (dazu ist ein <strong>kostenloses</strong> {!POINTS!}-Account dennoch n&ouml;tig!)");
 define('MEMBER_WERNIS_MODE_CHOOSE', "M&ouml;chten Sie {!POINTS!} zu Ihrem WDS66-Hauptaccount ausbezahlt bekommen oder {!POINTS!} hier einzahlen?");
 define('MEMBER_WERNIS_MODE_WITHDRAW', "{!POINTS!} einzahlen");
 define('MEMBER_WERNIS_MODE_PAYOUT', "{!POINTS!} auszahlen");
 
 define('WERNIS_ADMIN_CONFIG_NOTE', "<A href=\"http://www.wds66.com/ref.php?refid=10437\" target=\"_blank\">Hier</A> k&ouml;nnen Sie schon f&uuml;r <strong>5,00&euro;</strong>=<strong>25.000 Abfragen</strong> ein API-Account beantragen (dazu ist ein <strong>kostenloses</strong> {!POINTS!}-Account dennoch n&ouml;tig!)");
 define('MEMBER_WERNIS_MODE_CHOOSE', "M&ouml;chten Sie {!POINTS!} zu Ihrem WDS66-Hauptaccount ausbezahlt bekommen oder {!POINTS!} hier einzahlen?");
 define('MEMBER_WERNIS_MODE_WITHDRAW', "{!POINTS!} einzahlen");
 define('MEMBER_WERNIS_MODE_PAYOUT', "{!POINTS!} auszahlen");
 
+// API messages
+define('WERNIS_API_REQUEST_DATA_INVALID', "Interner Fehler: Abfragedaten sind defekt!");
+define('WERNIS_API_REQUEST_DATA_MISSING', "Interner Fehler: Abfragedaten sind nicht komplett!");
+define('WERNIS_API_REQUEST_ERROR', "Abfragefehler: <u>%s</u>");
+define('WERNIS_API_REQUEST_FAILED', "Unbekannter Fehler <u>%s</u> von API erhalten! Bitte im [<A href=\"http://forum.mxchange.org\" target=\"_blank\" title=\"Direktlink zum Forum\">Forum melden</A>], den Fehlercode nennen und wie es dazu gekommen ist.");
+define('WERNIS_API_REQUEST_FAILED_AUTH', "Authorisierung an API fehlgeschlagen! Bitte API-ID und Key &uuml;berpr&uuml;fen. [<A href=\"http://www.wds66.com/modules.php?module=export\" target=\"_blank\" title=\"Direkt zum WDS66-Exportaccount\">Hier</A>] direkt zum Export-Account. Sie ben&ouml;tigen Ihren Usernamen und Passwort!");
+
 //
 ?>
 //
 ?>
index c96ac9e968aa1edde34e72b8571a3f1c88be4303..8dff531395a50d113505ea7b95e4acf584e499c0 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
 
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
 
+// Sends out a request to the API and returns it's result
+function WERNIS_SEND_REQUEST ($scriptName, $requestData =  array()) {
+       global $CONFIG;
+
+       // Is the requestData an array?
+       if (!is_array($requestData)) {
+               // Then abort here!
+               return array(
+                       'status'  => "failed_general",
+                       'message' => WERNIS_API_REQUEST_DATA_INVALID
+               );
+       }
+
+       // Is the API id and MD5 hash there?
+       if ((empty($CONFIG['wernis_api_id'])) || (empty($CONFIG['wernis_api_md5']))) {
+               // Abort here...
+               return array(
+                       'status'  => "failed_general",
+                       'message' => WERNIS_API_REQUEST_DATA_MISSING
+               );
+       }
+
+       // Construct the request string
+       $requestString = $CONFIG['wernis_api_url'] . $scriptName."?api_id=".$CONFIG['wernis_api_id']."&api_key=".$CONFIG['wernis_api_md5'];
+       foreach ($requestData as $key=>$value) {
+               $requestString .= "&".$key."=".$value;
+       }
+
+       // Get the raw response from the lower function
+       $response = MXCHANGE_OPEN($requestString);
+
+       // Check the response header if all is fine
+       if (strpos($response[0], "200") === false) {
+               // Something bad happend... :(
+               return array(
+                       'status'  => "request_eror",
+                       'message' => sprintf(WERNIS_API_REQUEST_ERROR, $response[0])
+               );
+       }
+
+       // All (maybe) fine so remove the response header from server
+       $response = $response[(count($response) - 1)];
+
+       // Prepare the returning result for higher functions
+       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);
+
+       // Default return array (should not stay empty)
+       $return = array();
+
+       // We use only the first two entries (which shall be fine)
+       if ($data[0] == "error") {
+               // The request has failed... :(
+               switch ($data[1]) {
+                       case "AUTH": // Authorization has failed
+                               $return = array(
+                                       'status'  => "auth_failed",
+                                       'message' => WERNIS_API_REQUEST_FAILED_AUTH
+                               );
+                               break;
+
+                       default: // Unknown error (maybe new?)
+                               $return = array(
+                                       'status'  => "request_failed",
+                                       'message' => sprintf(WERNIS_API_REQUEST_FAILED, $data[1])
+                               );
+                               break;
+               }
+       } else {
+               // All fine here
+               $return = array(
+                       'status'   => "OK",
+                       'response' => $response
+               );
+       }
+
+       // Return the result
+       return $return;
+}
+
+// Tests the function by calling balance.php on the API
+function WERNIS_TEST_API () {
+       // Get config first
+       global $CONFIG;
+
+       // Prepare the request to the API
+       $return = WERNIS_SEND_REQUEST("balance.php");
+
+       die("<pre>".print_r($return, true)."</pre>");
+}
+
 //
 ?>
 //
 ?>
index ea86768545a0c198b50d8ab36e779058078e88a4..7650ae1bad076f26bad92b0ef7176ed5efd9582c 100644 (file)
@@ -41,14 +41,24 @@ if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
 ADD_DESCR("admin", basename(__FILE__));
 
 if (isset($_POST['ok'])) {
 ADD_DESCR("admin", basename(__FILE__));
 
 if (isset($_POST['ok'])) {
-       // Save settings
-       ADMIN_SAVE_SETTINGS($_POST, "_config", "config='0'");
+       // First merge temporary the new API data into config
+       $CONFIG = array_merge($CONFIG, $_POST);
+
+       // Let's test the API first (hold your horses here, cowboy! Thanks. :) )
+       if (WERNIS_TEST_API()) {
+               // Save settings
+               ADMIN_SAVE_SETTINGS($_POST, "_config", "config='0'");
+       } else {
+               // Failed to test the API!
+               LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_ERROR_MESSAGE());
+       }
 }  else {
        // Prepare data for template output
        $content = array(
                'min_amount' => $CONFIG['wernis_min_amount'],
                'api_id'     => $CONFIG['wernis_api_id'],
 }  else {
        // Prepare data for template output
        $content = array(
                'min_amount' => $CONFIG['wernis_min_amount'],
                'api_id'     => $CONFIG['wernis_api_id'],
-               'api_md5'    => $CONFIG['wernis_api_md5']
+               'api_md5'    => $CONFIG['wernis_api_md5'],
+               'api_url'    => $CONFIG['wernis_api_url']
        );
 
        // Load template
        );
 
        // Load template
index d362c17f2e7f91df3f9789191906f215fca22d27..32511bce831a61b886399eae6242e5c4215269d9 100644 (file)
@@ -13,7 +13,8 @@
                <TD width="300" align="right">{--WERNIS_ADMIN_API_ID--}:</TD>
                <TD class="seperator" width="10">&nbsp;</TD>
                <TD width="270"><INPUT type="text" name="wernis_api_id"
                <TD width="300" align="right">{--WERNIS_ADMIN_API_ID--}:</TD>
                <TD class="seperator" width="10">&nbsp;</TD>
                <TD width="270"><INPUT type="text" name="wernis_api_id"
-                       class="admin_normal" value="$content[api_id]" size="2" maxlength="20"></TD>
+                       class="admin_normal" value="$content[api_id]" size="2"
+                       maxlength="20" /></TD>
        </TR>
        <TR>
                <TD colspan="3" class="seperator" height="5">&nbsp;</TD>
        </TR>
        <TR>
                <TD colspan="3" class="seperator" height="5">&nbsp;</TD>
@@ -23,7 +24,7 @@
                <TD class="seperator" width="10">&nbsp;</TD>
                <TD width="270"><INPUT type="text" name="wernis_api_md5"
                        class="admin_normal" value="$content[api_md5]" size="33"
                <TD class="seperator" width="10">&nbsp;</TD>
                <TD width="270"><INPUT type="text" name="wernis_api_md5"
                        class="admin_normal" value="$content[api_md5]" size="33"
-                       maxlength="32"></TD>
+                       maxlength="32" /></TD>
        </TR>
        <TR>
                <TD colspan="3" class="seperator bottom2" height="5">&nbsp;</TD>
        </TR>
        <TR>
                <TD colspan="3" class="seperator bottom2" height="5">&nbsp;</TD>
                <TD class="seperator" width="10">&nbsp;</TD>
                <TD width="270"><INPUT type="text" name="wernis_min_amount"
                        class="admin_normal" value="$content[min_amount]" size="5"
                <TD class="seperator" width="10">&nbsp;</TD>
                <TD width="270"><INPUT type="text" name="wernis_min_amount"
                        class="admin_normal" value="$content[min_amount]" size="5"
-                       maxlength="20"></TD>
+                       maxlength="20" /></TD>
+       </TR>
+       <TR>
+               <TD colspan="3" class="seperator" height="5">&nbsp;</TD>
+       </TR>
+       <TR>
+               <TD width="300" align="right">{--WERNIS_ADMIN_API_URL--}:</TD>
+               <TD class="seperator" width="10">&nbsp;</TD>
+               <TD width="270"><INPUT type="text" name="wernis_api_url"
+                       class="admin_normal" value="$content[api_url]" size="25"
+                       maxlength="255" /></TD>
        </TR>
        <TR>
                <TD colspan="3" class="bottom2 seperator" height="5">&nbsp;</TD>
        </TR>
        <TR>
                <TD colspan="3" class="bottom2 seperator" height="5">&nbsp;</TD>