Exclude directories now
[mailer.git] / inc / functions.php
index 857d2c41b2f14cb955a368691463ee88f9e9651f..9060a90193d3f85512b0599ca1a7a87efe22a99b 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 *
@@ -51,7 +51,7 @@ function getFatalArray () {
 }
 
 // Add a fatal error message to the queue array
-function addFatalMessage ($F, $L, $message, $extra = '') {
+function addFatalMessage ($file, $line, $message, $extra = '') {
        if (is_array($extra)) {
                // Multiple extras for a message with masks
                $message = call_user_func_array('sprintf', $extra);
@@ -64,7 +64,7 @@ function addFatalMessage ($F, $L, $message, $extra = '') {
        array_push($GLOBALS['fatal_messages'], $message);
 
        // Log fatal messages away
-       logDebugMessage($F, $L, 'Fatal error message: ' . compileCode($message));
+       logDebugMessage($file, $line, 'Fatal error message: ' . compileCode($message));
 }
 
 // Getter for total fatal message count
@@ -1532,6 +1532,7 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) {
        // Shall I remove the cache file?
        if ((isExtensionInstalled('cache')) && (isCacheInstanceValid()) && (isHtmlOutputMode())) {
                // Rebuild cache only in HTML output-mode
+               // @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal.
                if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
                        // Destroy it
                        $GLOBALS['cache_instance']->removeCacheFile($force);
@@ -1628,6 +1629,12 @@ function doHourly () {
 
        // Run filters (one always!)
        runFilterChain('hourly');
+
+       // Do not update in hourly debug mode
+       if ((!isConfigEntrySet('DEBUG_HOURLY')) || (!isDebugHourlyEnabled())) {
+               // Update database
+               updateConfiguration('last_hourly', getHour());
+       } // END - if
 }
 
 // Enables the daily reset mode and runs it
@@ -1637,6 +1644,12 @@ function doDaily () {
 
        // Run filters
        runFilterChain('daily');
+
+       // Do not update in daily debug mode
+       if ((!isConfigEntrySet('DEBUG_DAILY')) || (!isDebugDailyEnabled())) {
+               // Update database
+               updateConfiguration('last_daily', getDay());
+       } // END - if
 }
 
 // Enables the weekly reset mode and runs it
@@ -1646,6 +1659,12 @@ function doWeekly () {
 
        // Run filters
        runFilterChain('weekly');
+
+       // Do not update in weekly debug mode
+       if ((!isConfigEntrySet('DEBUG_WEEKLY')) || (!isDebugWeeklyEnabled())) {
+               // Update database
+               updateConfiguration('last_weekly', getWeek());
+       } // END - if
 }
 
 // Enables the monthly reset mode and runs it
@@ -1655,6 +1674,12 @@ function doMonthly () {
 
        // Run filters
        runFilterChain('monthly');
+
+       // Do not update in monthly debug mode
+       if ((!isConfigEntrySet('DEBUG_MONTHLY')) || (!isDebugMonthlyEnabled())) {
+               // Update database
+               updateConfiguration('last_monthly', getMonth());
+       } // END - if
 }
 
 // Shuts down the mailer (e.g. closing database link, flushing output/filters, etc.)
@@ -1663,9 +1688,9 @@ function doShutdown () {
        runFilterChain('shutdown', NULL);
 
        // Check if link is up
-       if (SQL_IS_LINK_UP()) {
+       if (isSqlLinkUp()) {
                // Close link
-               SQL_CLOSE(__FUNCTION__, __LINE__);
+               sqlCloseLink(__FUNCTION__, __LINE__);
        } elseif (!isInstallationPhase()) {
                // No database link
                reportBug(__FUNCTION__, __LINE__, 'Database link is already down, while shutdown is running.');
@@ -1747,9 +1772,10 @@ function isExtraTitleSet () {
  * @param      $excludePattern         Regular expression to exclude more files (preg_match())
  * @param      $recursive                      whether to scan recursively
  * @param      $suffix                         Suffix for positive matches ($extension will be appended, too)
+ * @param      $withPrefixSuffix       Whether to include prefix/suffix in found entries
  * @return     $foundMatches           All found positive matches for above criteria
  */
-function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '') {
+function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '', $withPrefixSuffix = TRUE) {
        // Add default entries we should always exclude
        array_unshift($excludeArray, '.', '..', '.svn', '.htaccess');
 
@@ -1828,6 +1854,9 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad
                                if ($addBaseDir === TRUE) {
                                        // With base path
                                        array_push($foundMatches, $fileName);
+                               } elseif (($withPrefixSuffix === FALSE) && (!empty($extension))) {
+                                       // No prefix/suffix
+                                       array_push($foundMatches, substr($baseFile, strlen($prefix), -strlen($suffix . $extension)));
                                } else {
                                        // No base path
                                        array_push($foundMatches, $baseFile);
@@ -1836,9 +1865,18 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad
                                // We found .php file but should not search for them, why?
                                reportBug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script. (baseFile=' . $baseFile . ')');
                        }
-               } elseif ($fileExtension == $extension) {
+               } elseif ((($fileExtension == $extension) || (empty($extension))) && (isFileReadable($FQFN))) {
                        // Other, generic file found
-                       array_push($foundMatches, $fileName);
+                       if ($addBaseDir === TRUE) {
+                               // With base path
+                               array_push($foundMatches, $fileName);
+                       } elseif (($withPrefixSuffix === FALSE) && (!empty($extension))) {
+                               // No prefix/suffix
+                               array_push($foundMatches, substr($baseFile, strlen($prefix), -strlen($suffix . $extension)));
+                       } else {
+                               // No base path
+                               array_push($foundMatches, $baseFile);
+                       }
                }
        } // END - while
 
@@ -1864,7 +1902,7 @@ function mapModuleToTable ($moduleName) {
        // Map only these, still lame code...
        switch ($moduleName) {
                case 'index': // 'index' is the guest's menu
-                       $moduleName = 'guest'; 
+                       $moduleName = 'guest';
                        break;
 
                case 'login': // ... and 'login' the member's menu
@@ -1878,35 +1916,35 @@ function mapModuleToTable ($moduleName) {
 }
 
 // Add SQL debug data to array for later output
-function addSqlToDebug ($result, $sqlString, $timing, $F, $L) {
+function addSqlToDebug ($result, $sqlString, $timing, $file, $line) {
        // Is there cache?
        if (!isset($GLOBALS['debug_sql_available'])) {
                // Check it and cache it in $GLOBALS
                $GLOBALS['debug_sql_available'] = ((isConfigurationLoaded()) && (isDisplayDebugSqlEnabled()));
        } // END - if
-       
+
        // Don't execute anything here if we don't need or ext-other is missing
        if ($GLOBALS['debug_sql_available'] === FALSE) {
                return;
        } // END - if
 
        // Already executed?
-       if (isset($GLOBALS['debug_sqls'][$F][$L][$sqlString])) {
+       if (isset($GLOBALS['debug_sqls'][$file][$line][$sqlString])) {
                // Then abort here, we don't need to profile a query twice
                return;
        } // END - if
 
        // Remeber this as profiled (or not, but we don't care here)
-       $GLOBALS['debug_sqls'][$F][$L][$sqlString] = TRUE;
+       $GLOBALS['debug_sqls'][$file][$line][$sqlString] = TRUE;
 
        // Generate record
        $record = array(
-               'num_rows' => SQL_NUMROWS($result),
-               'affected' => SQL_AFFECTEDROWS(),
+               'num_rows' => sqlNumRows($result),
+               'affected' => sqlAffectedRows(),
                'sql_str'  => $sqlString,
                'timing'   => $timing,
-               'file'     => basename($F),
-               'line'     => $L
+               'file'     => basename($file),
+               'line'     => $line
        );
 
        // Add it
@@ -2185,7 +2223,7 @@ function generateAdminMailLinks ($mailType, $mailId) {
        // Is the mail type supported?
        if (!empty($table)) {
                // Query for the mail
-               $result = SQL_QUERY_ESC("SELECT `id`, `%s` AS `mail_status` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `id`=%s LIMIT 1",
+               $result = sqlQueryEscaped("SELECT `id`, `%s` AS `mail_status` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `id`=%s LIMIT 1",
                        array(
                                $statusColumn,
                                $table,
@@ -2193,9 +2231,9 @@ function generateAdminMailLinks ($mailType, $mailId) {
                        ), __FILE__, __LINE__);
 
                // Is there one entry there?
-               if (SQL_NUMROWS($result) == 1) {
+               if (sqlNumRows($result) == 1) {
                        // Load the entry
-                       $content = SQL_FETCHARRAY($result);
+                       $content = sqlFetchArray($result);
 
                        // Add output and type
                        $content['type']     = $mailType;
@@ -2209,7 +2247,7 @@ function generateAdminMailLinks ($mailType, $mailId) {
                } // END - if
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
        } // END - if
 
        // Return generated HTML code
@@ -2422,7 +2460,7 @@ function memberAddEntries ($tableName, $columns = array(), $filterFunctions = ar
        doGenericAddEntries($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $columnIndex);
 
        // Entry has been added?
-       if ((!SQL_HASZEROAFFECTED()) && ($GLOBALS['__XML_PARSE_RESULT'] === TRUE)) {
+       if ((!ifSqlHasZeroAffectedRows()) && ($GLOBALS['__XML_PARSE_RESULT'] === TRUE)) {
                // Display success message
                displayMessage('{--MEMBER_ENTRY_ADDED--}');
        } else {
@@ -2504,7 +2542,7 @@ function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunc
                        displayMessage('{--MEMBER_ALL_ENTRIES_REMOVED--}');
                } else {
                        // Some are still there :(
-                       displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_DELETED'), SQL_AFFECTEDROWS(), countPostSelection($idColumn[0])));
+                       displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_DELETED'), sqlAffectedRows(), countPostSelection($idColumn[0])));
                }
        } else {
                // List for deletion confirmation
@@ -2610,7 +2648,7 @@ function getArrayFromArrayIndex ($array, $key) {
 
 /**
  * Compress given data and encodes it into BASE64 to be stored in database with
- * SQL_QUERY_ESC()
+ * sqlQueryEscaped()
  *
  * @param      $data   Data to be compressed and encoded
  * @return     $data   Compressed+encoded data