]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/network_functions.php
Extension ext-network cleaned up
[mailer.git] / inc / libs / network_functions.php
index 8438c972198160a9a9864f91eb632e874f1dfeae..a5cec2ca0043d04386fa69cc9776dd77729bf774 100644 (file)
@@ -172,11 +172,11 @@ function isNetworkActiveById ($networkId) {
 }
 
 // "Getter" for 'network_activated' column depending on current administrator's expert setting
-function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '', $addSql = '') {
+function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '') {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$whereAnd][$table])) {
                // Default is exclude deactivated networks
-               $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'" .  $addSql;
+               $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'";
 
                // Is the export setting on and debug mode enabled?
                if ((isAdminsExpertSettingEnabled()) && (isDebugModeEnabled())) {
@@ -191,80 +191,38 @@ function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '', $addSql =
 
 // Checks whether the given network type is already used (valid)
 function isNetworkTypeHandleValid ($type, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handler`='%s' LIMIT 1",
-               array(
-                       $networkId,
-                       $type
-               ), __FUNCTION__, __LINE__);
-
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
-
-       // Free result
-       SQL_FREERESULT($result);
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$type])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId][$type] = (countSumTotalData(bigintval($networkid), 'network_types', 'network_type_id', 'network_id', TRUE, sprintf(" AND `network_type_handler`='%s'", SQL_ESCAPE($type))) == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$networkId][$type];
 }
 
 // Checks whether the given network request parameter is already used (valid)
-function isNetworkRequestElementValid ($key, $type, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_request_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_request_param_key`='%s' LIMIT 1",
-               array(
-                       $networkId,
-                       $type,
-                       $key
-               ), __FUNCTION__, __LINE__);
-
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
-
-       // Free result
-       SQL_FREERESULT($result);
-
-       // Return result
-       return $isValid;
-}
-
-// Checks whether the given vcheck request parameter is already used (valid)
-function isNetworkVcheckElementValid ($key, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_vcheck_param_id` FROM `{?_MYSQL_PREFIX?}_network_vcheck_params` WHERE `network_id`=%s AND `network_vcheck_param_key`='%s' LIMIT 1",
-               array(
-                       $networkId,
-                       $key
-               ), __FUNCTION__, __LINE__);
-
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
-
-       // Free result
-       SQL_FREERESULT($result);
+function isNetworkRequestElementValid ($key, $networkTypeId, $networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key] = (countSumTotalData(bigintval($networkId), 'network_request_params', 'network_id', 'network_request_param_id', 'network_id', TRUE, sprintf(" AND `network_type_id`=%s AND `network_request_param_key`='%s'", bigintval($networkTypeId), SQL_ESCAPE($key))) == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key];
 }
 
 // Checks whether the given network API array translation
-function isNetworkArrayTranslationValid ($key, $type, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_array_id` FROM `{?_MYSQL_PREFIX?}_network_array_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_array_index`='%s' LIMIT 1",
-               array(
-                       $networkId,
-                       $type,
-                       $key
-               ), __FUNCTION__, __LINE__);
-
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
-
-       // Free result
-       SQL_FREERESULT($result);
+function isNetworkArrayTranslationValid ($key, $networkTypeId, $networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key] = (countSumTotalData(bigintval($networkId), 'network_array_translation', 'network_array_id', 'network_id', TRUE, sprintf(" AND `network_type_id`=%s AND `network_array_index`='%s'", bigintval($networkTypeId), SQL_ESCAPE($key))) == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key];
 }
 
 // "Getter" for a network's data by provided id number
@@ -704,7 +662,7 @@ function generateAdminNetworkList ($separated = FALSE, $includeConfigured = TRUE
        `network_active`
 FROM
        `{?_MYSQL_PREFIX?}_network_data`
-' . getNetworkActivatedColumn('WHERE', '', $addSql) . '
+' . getNetworkActivatedColumn('WHERE') . '
 ORDER BY
        `network_short_name` ASC', __FUNCTION__, __LINE__);
 
@@ -719,7 +677,7 @@ ORDER BY
                                if (((($includeConfigured === FALSE) && (isNetworkApiConfigured($row['network_id']))) || (($includeUnconfigured === FALSE) && (!isNetworkApiConfigured($row['network_id'])))) && ($separated === FALSE)) {
                                        // Skip this entry
                                        continue;
-                               } // END - if
+                               } elseif ((!empty($addSql)) && (
 
                                // Add entry
                                $rows[$row['network_id']] = $row;
@@ -1010,40 +968,6 @@ function generateNetworkRequestKeyOptions () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// Generates an options list for vcheck request keys
-function generateNetworkVcheckKeyOptions () {
-       // Is it cached?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Generate and cache it
-               $GLOBALS[__FUNCTION__] = generateOptions(
-                       '/ARRAY/',
-                       array(
-                               'network_key',
-                               'site_id',
-                               'payment',
-                               'remote_address',
-                               'campaign_id',
-                               'status',
-                               'reason',
-                               'type',
-                               'network_name',
-                               'extra_value1',
-                               'extra_value2',
-                               'extra_value3',
-                               'extra_value4',
-                       ),
-                       array(),
-                       '',
-                       '', '',
-                       $GLOBALS['network_vcheck_params_disabled'],
-                       'translateNetworkVcheckParameterKey'
-               );
-       } // END - if
-
-       // Return content
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Generator (somewhat getter) for (return) array translation
 function generateNetworkTranslationOptions ($default = '') {
        // Is it cached?
@@ -1145,7 +1069,7 @@ function generateNetworkMediaOutputOptions ($mediaOutput) {
 }
 
 // Checks if the given network is configured by looking its API configuration entry up
-function isNetworkApiConfigured ($networkId) {
+function isNetworkApiConfigured ($networkId, $addSql = '') {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
                // Check for an entry in network_api_config
@@ -1450,21 +1374,6 @@ function translateNetworkRequestParameterKey ($param) {
        return '{--' . $messageId . '--}';
 }
 
-// Translates vheck request parameter
-function translateNetworkVcheckParameterKey ($param) {
-       // Generate id
-       $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
-
-       // Is the message id there?
-       if (!isMessageIdValid($messageId)) {
-               // Not valid param
-               reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
-       } // END - if
-
-       // Return message id
-       return '{--' . $messageId . '--}';
-}
-
 // Translate text-encoding
 function translateNetworkTextEncoding ($encoding) {
        // Generate id
@@ -2476,39 +2385,6 @@ function doAdminNetworkProcessAddRequestParam () {
        }
 }
 
-// Adds a vheck request parameter to given network
-function doAdminNetworkProcessAddVcheckParam () {
-       // Is the request parameter already used with given network?
-       if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
-               // Already added
-               loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
-
-               // ... so abort here
-               return FALSE;
-       } // END - if
-
-       // Add id
-       setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
-
-       // Is network_vcheck_param_default set?
-       if (!isPostRequestElementSet('network_vcheck_param_default')) {
-               // Remove empty value to get a NULL for an optional entry
-               unsetPostRequestElement('network_vcheck_param_default');
-       } // END - if
-
-       // Add the whole vcheck to database
-       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
-
-       // Output message
-       if (!SQL_HASZEROAFFECTED()) {
-               // Successfully added
-               loadTemplate('admin_network_vcheck_param_added', FALSE, postRequestArray());
-       } else {
-               // Not added
-               loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
-       }
-}
-
 // Adds a API response array entry
 function doAdminNetworkProcessAddNetworkArrayTranslation () {
        // Is the request parameter already used with given network?
@@ -2891,8 +2767,6 @@ function doAdminNetworkProcessExport () {
                'list_network_types'             => 'types',
                // Network request parameter
                'list_network_request_params'    => 'request_params',
-               // Vcheck request parameter
-               'list_network_vcheck_params'     => 'vcheck_params',
                // Network API response array index translation
                'list_network_array_translation' => 'array_translation',
        );
@@ -3104,61 +2978,6 @@ ORDER BY
        loadTemplate('admin_export_network_request_params', FALSE, $SQL);
 }
 
-// Exports (and displays) the table 'network_vcheck_params'
-function doAdminNetworkExportVcheckParams () {
-       // 'network_id' must be set
-       if (!isGetRequestElementSet('network_id')) {
-               // Only network vcheck parameters of one network will be exported per time
-               reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
-       } // END - if
-
-       // Get all network types of given network
-       $result = SQL_QUERY_ESC('SELECT
-       `network_id`,
-       `network_vcheck_param_key`,
-       `network_vcheck_param_value`,
-       `network_vcheck_param_default`
-FROM
-       `{?_MYSQL_PREFIX?}_network_vcheck_params`
-WHERE
-       `network_id`=%s
-ORDER BY
-       `network_vcheck_param_id` ASC',
-               array(
-                       bigintval(getRequestElement('network_id'))
-               ), __FUNCTION__, __LINE__);
-
-       // Start an empty SQL query
-       $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_network_vcheck_params` (`network_id`, `network_vcheck_param_key`, `network_vcheck_param_value`, `network_vcheck_param_default`) VALUES' . PHP_EOL;
-
-       // Load all entries
-       while ($content = SQL_FETCHARRAY($result)) {
-               // Add row
-               $SQL .= '(' .
-                       $content['network_id'] . ", '" .
-                       $content['network_vcheck_param_key'] . "', '" .
-                       $content['network_vcheck_param_value'] . "', ";
-               
-               // Is the column NULL?
-               if (is_null($content['network_vcheck_param_default'])) {
-                       // Column is NULL
-                       $SQL .= "NULL),\n";
-               } else {
-                       // Column is set
-                       $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
-               }
-       } // END - while
-
-       // Remove last commata and close braces
-       $SQL = substr($SQL, 0, -2);
-
-       // Free result
-       SQL_FREERESULT($result);
-
-       // Output the SQL query
-       loadTemplate('admin_export_network_vcheck_params', FALSE, $SQL);
-}
-
 // Exports (and displays) the table 'network_array_translation'
 function doAdminNetworkExportArrayTranslation () {
        // 'network_id' must be set