Exclude directories now
[mailer.git] / inc / wrapper-functions.php
index 6c394da6cdfb3df579e3ae6e83e93d0a0907fff9..0969cf0bc5579c6d4b6197fe561d0d80bb54ba78 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 *
@@ -88,8 +88,7 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
                }
        } else {
                // Write it with fopen
-               $fp = fopen($FQFN, 'w')
-                       or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
+               $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
 
                // Aquire a lock?
                if ($aquireLock === TRUE) {
@@ -200,7 +199,7 @@ function isDirectory ($FQFN) {
                $baseName = basename($FQFN);
 
                // Check it
-               $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
+               $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && (!in_array($baseName, array('.', '..', '.svn'))));
        } // END - if
 
        // Return the result
@@ -389,10 +388,28 @@ function isHourlyResetEnabled () {
        return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
 }
 
-// Checks whether the reset mode is active
+// Checks whether the daily reset mode is active
+function isDailyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['daily_enabled'])) && ($GLOBALS['daily_enabled'] === TRUE));
+}
+
+// Checks whether the weekly reset mode is active
+function isWeeklyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['weekly_enabled'])) && ($GLOBALS['weekly_enabled'] === TRUE));
+}
+
+// Checks whether the monthly reset mode is active
+function isMonthlyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['monthly_enabled'])) && ($GLOBALS['monthly_enabled'] === TRUE));
+}
+
+// Checks whether one of the reset modes is enabled
 function isResetModeEnabled () {
        // Now simply check it
-       return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
+       return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()));
 }
 
 // Checks whether the debug mode is enabled
@@ -407,12 +424,48 @@ function isDebugModeEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// Checks whether the debug reset is enabled
-function isDebugResetEnabled () {
+// Checks whether the debug hourly is enabled
+function isDebugHourlyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug daily is enabled
+function isDebugDailyEnabled () {
        // Is cache set?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Simply check it
-               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_DAILY')) && (getConfig('DEBUG_DAILY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug weekly is enabled
+function isDebugWeeklyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug monthly is enabled
+function isDebugMonthlyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
        } // END - if
 
        // Return it
@@ -1565,7 +1618,7 @@ function isDisplayDebugSqlEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getDisplayDebugSqls() == 'Y'));
        } // END - if
 
        // Return cache
@@ -1596,12 +1649,24 @@ function isWhatTitleEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for internal_stats
+function getInternalStats () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('internal_stats');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Checks whether stats are enabled
 function ifInternalStatsEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
-               // Then determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
+               // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y'));
        } // END - if
 
        // Return cached value
@@ -1613,7 +1678,7 @@ function isAdminNotificationEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (getAdminNotify() == 'Y'));
        } // END - if
 
        // Return cache
@@ -2159,96 +2224,96 @@ function getOneDay () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for activate_xchange
-function getActivateXchange () {
+// "Getter" for img_type
+function getImgType () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
+               $GLOBALS[__FUNCTION__] = getConfig('img_type');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for img_type
-function getImgType () {
+// "Getter" for code_length
+function getCodeLength () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('img_type');
+               $GLOBALS[__FUNCTION__] = getConfig('code_length');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for code_length
-function getCodeLength () {
+// "Getter" for pass_len
+function getPassLen () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('code_length');
+               $GLOBALS[__FUNCTION__] = getConfig('pass_len');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for least_cats
-function getLeastCats () {
+// "Getter" for admin_menu
+function getAdminMenu () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('least_cats');
+               $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for pass_len
-function getPassLen () {
+// "Getter" for last_hourly
+function getLastHourly () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('pass_len');
+               $GLOBALS[__FUNCTION__] = getConfig('last_hourly');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for admin_menu
-function getAdminMenu () {
+// "Getter" for last_daily
+function getLastDaily () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
+               $GLOBALS[__FUNCTION__] = getConfig('last_daily');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for last_month
-function getLastMonth () {
+// "Getter" for last_weekly
+function getLastWeekly () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('last_month');
+               $GLOBALS[__FUNCTION__] = getConfig('last_weekly');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for max_send
-function getMaxSend () {
+// "Getter" for last_monthly
+function getLastMonthly () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('max_send');
+               $GLOBALS[__FUNCTION__] = getConfig('last_monthly');
        } // END - if
 
        // Return cache
@@ -2459,30 +2524,6 @@ function getTitleMiddle () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// Getter for 'check_double_email'
-function getCheckDoubleEmail () {
-       // Is the cache entry set?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // No, so determine it
-               $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
-       } // END - if
-
-       // Return cached entry
-       return $GLOBALS[__FUNCTION__];
-}
-
-// Checks whether 'check_double_email' is 'Y'
-function isCheckDoubleEmailEnabled () {
-       // Is the cache entry set?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // No, so determine it
-               $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
-       } // END - if
-
-       // Return cached entry
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Getter for 'display_home_in_index'
 function getDisplayHomeInIndex () {
        // Is the cache entry set?
@@ -2804,18 +2845,6 @@ function getUserUsedPoints ($userid) {
        return $GLOBALS[__FUNCTION__][$userid];
 }
 
-// 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');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Checks whether direct payment is allowed in configuration
 function isDirectPaymentEnabled () {
        // Is there cache?
@@ -3245,9 +3274,9 @@ function determineWhat ($module = NULL) {
 }
 
 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
-function prependZeros ($mStretch, $length = 2) {
+function prependZeros ($str, $length = 2) {
        // Return prepended string
-       return sprintf('%0' . (int) $length . 's', $mStretch);
+       return sprintf('%0' . (int) $length . 's', $str);
 }
 
 // Wraps convertSelectionsToEpocheTime()
@@ -3301,34 +3330,34 @@ function getUsersTotalLockedReferrals ($userid, $level = NULL) {
                // Is the not level NULL?
                if (!is_null($level)) {
                        // Then add referral level
-                       $add = ' AND r.`level`=' . bigintval($level);
+                       $add = ' AND `r`.`level`=' . bigintval($level);
                } // END - if
 
                // Check for all referrals
-               $result = SQL_QUERY_ESC("SELECT
-       COUNT(d.`userid`) AS `cnt`
+               $result = sqlQueryEscaped("SELECT
+       COUNT(`d`.`userid`) AS `cnt`
 FROM
-       `{?_MYSQL_PREFIX?}_user_data` AS d
+       `{?_MYSQL_PREFIX?}_user_data` AS `d`
 INNER JOIN
-       `{?_MYSQL_PREFIX?}_user_refs` AS r
+       `{?_MYSQL_PREFIX?}_user_refs` AS `r`
 ON
-       d.`userid`=r.`refid`
+       `d`.`userid`=`r`.`refid`
 WHERE
-       d.`status` != 'CONFIRMED' AND
-       r.`userid`=%s
+       `d`.`status` != 'CONFIRMED' AND
+       `r`.`userid`=%s
        " . $add . "
 ORDER BY
-       d.`userid` ASC
+       `d`.`userid` ASC
 LIMIT 1",
                        array(
                                $userid
                        ), __FUNCTION__, __LINE__);
 
                // Load count
-               list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
+               list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result);
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
        } // END - if
 
        // Return it
@@ -3349,7 +3378,7 @@ function convertDollarDataToGetElement ($data) {
 }
 
 // Wrapper function for SQL layer to speed-up things
-function SQL_DEBUG_ENABLED () {
+function isSqlDebugEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
@@ -3410,5 +3439,17 @@ function shift_array (&$array, $value, $key = '0') {
        array_shift($array);
 }
 
+// Wrapper for str_pad() with left padding zeros
+function padLeftZero ($str, $amount = 2) {
+       // Is str_pad() there?
+       if (function_exists('str_pad')) {
+               // Use prependZeros()
+               return prependZeros($str, $amount);
+       } else {
+               // Pad it
+               return str_pad($str, $amount, '0', STR_PAD_LEFT);
+       }
+}
+
 // [EOF]
 ?>