]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/blacklist_functions.php
Rewrote many parts:
[mailer.git] / inc / libs / blacklist_functions.php
index 05803c8c2793cb4aef11661d9e3bac2f14b96c44..9097b417720d9411e4070dc855403ba0d2ed20e5 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -40,6 +40,24 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
+// Checks whether given email is blacklisted
+function isEmailBlacklisted ($email) {
+       // Call inner function
+       return isGenericBlacklisted('email', $email);
+}
+
+// Checks whether given IP is blacklisted
+function isIpBlacklisted ($ip) {
+       // Call inner function
+       return isGenericBlacklisted('ip', $ip);
+}
+
+// Checks whether given URL is blacklisted
+function isUrlBlacklisted ($url) {
+       // Call inner function
+       return isGenericBlacklisted('url', $email);
+}
+
 // Checks whether given data is blacklisted
 function isGenericBlacklisted ($type, $data) {
        // Mark it as not listed by default
@@ -51,7 +69,7 @@ function isGenericBlacklisted ($type, $data) {
                return FALSE;
        } elseif (!isset($GLOBALS['blacklist_data'][$type][$data])) {
                // Check black-list for given email
-               $result = SQL_QUERY_ESC("SELECT
+               $result = sqlQueryEscaped("SELECT
        `id`,
        `data`,
        `pool_id`,
@@ -70,16 +88,16 @@ LIMIT 1",
                        ), __FUNCTION__, __LINE__);
 
                // Is there an entry?
-               if (SQL_NUMROWS($result) == 1) {
+               if (sqlNumRows($result) == 1) {
                        // Jupp, we got one listed
-                       $GLOBALS['blacklist_data'][$type][$data] = SQL_FETCHARRAY($result);
+                       $GLOBALS['blacklist_data'][$type][$data] = sqlFetchArray($result);
 
                        // Mark it as listed
                        $listed = TRUE;
                } // END - if
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
        } else {
                // Is found in cache -> black-listed
                $listed = TRUE;
@@ -92,13 +110,19 @@ LIMIT 1",
 // Inserts a given email (pattern) in blacklist if not found
 function insertEmailInBlacklist ($email, $provider = 'BLACKLIST') {
        // Call inner function
-       insertGenericInBlacklist ('email', $email, NULL, $provider);
+       return insertGenericInBlacklist ('email', $email, NULL, $provider);
 }
 
-// Inserts a given URL in blacklist if not found
+// Inserts a given IP (pattern) in blacklist if not found
+function insertIpInBlacklist ($ip, $provider = 'BLACKLIST') {
+       // Call inner function
+       return insertGenericInBlacklist ('ip', $ip, NULL, $provider);
+}
+
+// Inserts a given URL (pattern) in blacklist if not found
 function insertUrlInBlacklist ($url, $poolId, $provider = 'BLACKLIST') {
        // Call inner function
-       insertGenericInBlacklist ('url', $url, $poolId, $provider);
+       return insertGenericInBlacklist ('url', $url, $poolId, $provider);
 }
 
 // Inserts a given URL in blacklist if not found
@@ -109,7 +133,7 @@ function insertGenericInBlacklist ($type, $data, $poolId = NULL, $provider = 'BL
                reportBug(__FUNCTION__, __LINE__, 'Blacklisting of type ' . $type . ' is disabled, data=' . $data . ',poolId=' . convertZeroToNull($poolId));
        } elseif (!isUrlBlacklisted($data)) {
                // Did not find a record so we can add it... :)
-               SQL_QUERY_ESC("INSERT INTO
+               sqlQueryEscaped("INSERT INTO
        `{?_MYSQL_PREFIX?}_blacklist`
 (
        `data`,
@@ -129,18 +153,9 @@ function insertGenericInBlacklist ($type, $data, $poolId = NULL, $provider = 'BL
                        strtoupper($type)
                ), __FUNCTION__, __LINE__);
        } // END - if
-}
-
-// Checks whether given email is blacklisted
-function isEmailBlacklisted ($email) {
-       // Call inner function
-       return isGenericBlacklisted('email', $email);
-}
 
-// Checks whether given URL is blacklisted
-function isUrlBlacklisted ($url) {
-       // Call inner function
-       return isGenericBlacklisted('url', $email);
+       // Return insert id for debugging/reporting pursposes
+       return getSqlInsertId();
 }
 
 // ----------------------------------------------------------------------------
@@ -159,12 +174,36 @@ function isGenericBlacklistEnabled ($type) {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Getter for url_blacklist
+function getUrlBlacklist () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('url_blacklist');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Wrapper to check if url_blacklist is enabled
 function isUrlBlacklistEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
+               $GLOBALS[__FUNCTION__] = (getUrlBlacklist() == 'Y');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for email_blacklist
+function getEmailBlacklist () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('email_blacklist');
        } // END - if
 
        // Return cache
@@ -176,7 +215,31 @@ function isEmailBlacklistEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('email_blacklist') == 'Y');
+               $GLOBALS[__FUNCTION__] = (getEmailBlacklist() == 'Y');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for ip_blacklist
+function getIpBlacklist () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('ip_blacklist');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Wrapper to check if ip_blacklist is enabled
+function isIpBlacklistEnabled () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getIpBlacklist() == 'Y');
        } // END - if
 
        // Return cache