More debugging and typo in comment fixed
[mailer.git] / inc / functions.php
index 10b4d02d329c05dc548ad0e5d24520cf9cafd306..8ac91e556901e68696ead6e560043abac61bc4ca 100644 (file)
@@ -120,6 +120,9 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
 
                // Compile and run finished rendered HTML code
                while (strpos($OUTPUT, '{!') > 0) {
+                       // Replace _MYSQL_PREFIX
+                       $OUTPUT = str_replace("{!_MYSQL_PREFIX!}", getConfig('_MYSQL_PREFIX'), $OUTPUT);
+
                        // Prepare the content and eval() it...
                        $newContent = '';
                        $eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
@@ -128,7 +131,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                        // Was that eval okay?
                        if (empty($newContent)) {
                                // Something went wrong!
-                               app_die(__FUNCTION__, __LINE__, "Evaluation error:<pre>".htmlentities($eval)."</pre>");
+                               app_die(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . htmlentities($eval) . '</pre>');
                        } // END - if
                        $OUTPUT = $newContent;
                } // END - while
@@ -235,7 +238,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
        // @DEPRECATED Try to rewrite the if() condition
        if ($template == 'member_support_form') {
                // Support request of a member
-               $result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
                        array(getUserId()), __FUNCTION__, __LINE__);
 
                // Is content an array?
@@ -247,13 +250,13 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
                        $content['gender'] = translateGender($content['gender']);
                } else {
                        // @DEPRECATED
-                       // @TODO Fine all templates which are using these direct variables and rewrite them.
+                       // @TODO Find all templates which are using these direct variables and rewrite them.
                        // @TODO After this step is done, this else-block is history
                        list($gender, $surname, $family, $email) = SQL_FETCHROW($result);
 
                        // Translate gender
                        $gender = translateGender($gender);
-                       DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array (%s).", gettype($content)));
+                       DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array [%s], template=%s.", gettype($content), $template));
                }
 
                // Free result
@@ -286,13 +289,16 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
        } elseif (strpos($template, 'la_') > -1) {
                // 'Logical-area' template found
                $mode = 'la/';
+       } elseif (strpos($template, 'js_') > -1) {
+               // JavaScript template found
+               $mode = 'js/';
        } else {
                // Test for extension
                $test = substr($template, 0, strpos($template, '_'));
                if (EXT_IS_ACTIVE($test)) {
                        // Set extra path to extension's name
-                       $mode = $test.'/';
-               }
+                       $mode = $test . '/';
+               } // END - if
        }
 
        ////////////////////////
@@ -341,8 +347,11 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
                        $ret = $tmpl_file;
                }
 
-               // Add surrounding HTML comments to help finding bugs faster
-               $ret = "<!-- Template " . $template . " - Start -->\n" . $ret . "<!-- Template " . $template . " - End -->\n";
+               // Normal HTML output?
+               if ($GLOBALS['output_mode'] == 0) {
+                       // Add surrounding HTML comments to help finding bugs faster
+                       $ret = "<!-- Template " . $template . " - Start -->\n" . $ret . "<!-- Template " . $template . " - End -->\n";
+               } // END - if
        } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
                // Only admins shall see this warning or when installation mode is active
                $ret = "<br /><span class=\"guest_failed\">{--TEMPLATE_404--}</span><br />
@@ -384,14 +393,16 @@ function sendEmail ($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
        eval($eval);
 
        // Set from header
-       if ((!eregi("@", $toEmail)) && ($toEmail > 0)) {
+       if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
                // Value detected, is the message extension installed?
-               if (EXT_IS_ACTIVE("msg")) {
+               // @TODO Extension 'msg' does not exist
+               if (EXT_IS_ACTIVE('msg')) {
                        ADD_MESSAGE_TO_BOX($toEmail, $subject, $message, $HTML);
                        return;
                } else {
                        // Load email address
-                       $result_email = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", array(bigintval($toEmail)), __FUNCTION__, __LINE__);
+                       $result_email = SQL_QUERY_ESC("SELECT `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+                               array(bigintval($toEmail)), __FUNCTION__, __LINE__);
                        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):numRows=".SQL_NUMROWS($result_email)."<br />\n";
 
                        // Does the user exist?
@@ -1234,7 +1245,7 @@ function generateRandomCode ($length, $code, $uid, $DATA = '') {
        $keys = getConfig('SITE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY');
        if (isConfigEntrySet('secret_key'))  $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key');
        if (isConfigEntrySet('file_hash'))   $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash');
-       $keys .= getConfig('ENCRYPT_SEPERATOR').date("d-m-Y (l-F-T)", getConfig(('patch_ctime')));
+       $keys .= getConfig('ENCRYPT_SEPERATOR') . date("d-m-Y (l-F-T)", getConfig('patch_ctime'));
        if (isConfigEntrySet('master_salt')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
 
        // Build string from misc data
@@ -1286,9 +1297,9 @@ function bigintval ($num, $castValue = true) {
 
        // Has the whole value changed?
        // @TODO Remove this if() block if all is working fine
-       if ("" . $ret."" != '' . $num."") {
+       if ('' . $ret . '' != '' . $num . '') {
                // Log the values
-               debug_report_bug("{$ret}<>{$num}");
+               //debug_report_bug("{$ret}<>{$num}");
        } // END - if
 
        // Return result
@@ -1412,7 +1423,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= "  <td align=\"center\" class=\"admin_title bottom\"><div class=\"tiny\">{--_YEARS--}</strong></td>\n";
                }
 
-               if (ereg("M", $display) || (empty($display))) {
+               if (ereg('M', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"admin_title bottom\"><div class=\"tiny\">{--_MONTHS--}</strong></td>\n";
                }
 
@@ -1452,7 +1463,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= "<INPUT type=\"hidden\" name=\"" . $prefix."_ye\" value=\"0\" />\n";
                }
 
-               if (ereg("M", $display) || (empty($display))) {
+               if (ereg('M', $display) || (empty($display))) {
                        // Generate month selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_mo\" size=\"1\">\n";
                        for ($idx = 0; $idx <= 11; $idx++)
@@ -1943,7 +1954,6 @@ function isEmailValid ($email) {
        $regex = '@^' . $first . '\@' . $domain . '$@iU';
 
        // Return check result
-       // @NOTE altered the regex-pattern and added modificator i (match both upper and lower case letters) and U (PCRE_UNGREEDY) to work with preg_match the same way as eregi
        return preg_match($regex, $email);
 }
 
@@ -2006,20 +2016,20 @@ function generateMemberAdminActionLinks ($uid, $status = '') {
 }
 
 // Generate an email link
-function generateMemberEmailLink ($email, $table = 'admins') {
+function generateEmailLink ($email, $table = 'admins') {
        // Default email link (INSECURE! Spammer can read this by harvester programs)
        $EMAIL = 'mailto:' . $email;
 
        // Check for several extensions
        if ((EXT_IS_ACTIVE('admins')) && ($table == 'admins')) {
                // Create email link for contacting admin in guest area
-               $EMAIL = adminsCreateEmailLink($email);
+               $EMAIL = generateAdminEmailLink($email);
        } elseif ((EXT_IS_ACTIVE('user')) && (GET_EXT_VERSION('user') >= '0.3.3') && ($table == 'user_data')) {
                // Create email link for contacting a member within admin area (or later in other areas, too?)
-               $EMAIL = USER_generateMemberEmailLink($email);
+               $EMAIL = generateEmailLink($email, 'user_data');
        } elseif ((EXT_IS_ACTIVE('sponsor')) && ($table == 'sponsor_data')) {
                // Create email link to contact sponsor within admin area (or like the link above?)
-               $EMAIL = SPONSOR_generateMemberEmailLink($email);
+               $EMAIL = generateEmailLink($email, 'sponsor_data');
        }
 
        // Shall I close the link when there is no admin?
@@ -2049,7 +2059,7 @@ function generateHash ($plainText, $salt = '') {
                $server = $_SERVER['PHP_SELF'].getConfig('ENCRYPT_SEPERATOR').detectUserAgent().getConfig('ENCRYPT_SEPERATOR').getenv('SERVER_SOFTWARE').getConfig('ENCRYPT_SEPERATOR').detectRemoteAddr();
 
                // Build key string
-               $keys   = getConfig('SITE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key').getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash').getConfig('ENCRYPT_SEPERATOR').date("d-m-Y (l-F-T)", getConfig(('patch_ctime'))).getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
+               $keys   = getConfig('SITE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key').getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash').getConfig('ENCRYPT_SEPERATOR').date("d-m-Y (l-F-T)", getConfig('patch_ctime')).getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
 
                // Additional data
                $data = $plainText.getConfig('ENCRYPT_SEPERATOR').uniqid(mt_rand(), true).getConfig('ENCRYPT_SEPERATOR').time();
@@ -2423,14 +2433,14 @@ function searchDirsRecursive ($dir, &$last_changed) {
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=" . $dir."<br />\n";
        // Does it match what we are looking for? (We skip a lot files already!)
        // RegexPattern to exclude  ., .., .revision,  .svn, debug.log or .cache in the filenames
-       $excludePattern = '@(\.|\.\.|\.revision|\.svn|debug\.log|\.cache|config\.php)$@';
-       $ds = getArrayFromDirectory($dir, '', true, false, $excludePattern);
+       $excludePattern = '@(\.revision|debug\.log|\.cache|config\.php)$@';
+       $ds = getArrayFromDirectory($dir, '', true, false, array(), '.php', $excludePattern);
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds)."<br />\n";
 
        // Walk through all entries
        foreach ($ds as $d) {
                // Generate proper FQFN
-               $FQFN = str_replace("//", '/', constant('PATH') . $dir. '/'. $d);
+               $FQFN = str_replace('//', '/', constant('PATH') . $dir. '/'. $d);
 
                // Is it a file and readable?
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):FQFN={$FQFN}<br />\n";
@@ -2476,9 +2486,12 @@ function getActualVersion ($type = 'Revision') {
                } // END - if
 
                // Is the cache file outdated/invalid?
-               if ($new === true){
+               if ($new === true) {
+                       // Reload the cache file
+                       $GLOBALS['cache_instance']->loadCacheFile('revision');
+
                        // Destroy cache file
-                       $GLOBALS['cache_instance']->destroyCacheFile();
+                       $GLOBALS['cache_instance']->destroyCacheFile(false, true);
 
                        // @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
                        unset($GLOBALS['cache_array']['revision']);
@@ -2546,13 +2559,19 @@ function getSearchFor () {
 // @TODO Please describe this function
 function getArrayFromActualVersion () {
        // Init variables
-       $next_dir = ''; // Directory to start with search
+       $next_dir = '';
+
+       // Directory to start with search
        $last_changed = array(
                'path_name' => '',
                'time'      => 0
        );
-       $akt_vers = array(); // Init return array
-       $res = 0; // Init value for counting the founded keywords
+
+       // Init return array
+       $akt_vers = array();
+
+       // Init value for counting the founded keywords
+       $res = 0;
 
        // Searches all Files and there date of the last modifikation and puts the newest File in $last_changed.
        searchDirsRecursive($next_dir, $last_changed); // @TODO small change to API to $last_changed = searchDirsRecursive($next_dir, $time);
@@ -2722,7 +2741,7 @@ function generateAdminLink ($aid) {
                        // Is the extension there?
                        if (EXT_IS_ACTIVE('admins')) {
                                // Admin found
-                               $admin = "<a href=\"".adminsCreateEmailLink(getAdminEmail($aid))."\">" . $login."</a>";
+                               $admin = "<a href=\"".generateEmailLink(getAdminEmail($aid), 'admins')."\">" . $login."</a>";
                        } else {
                                // Extension not found
                                $admin = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins');
@@ -2738,7 +2757,7 @@ function generateAdminLink ($aid) {
 }
 
 // Compile characters which are allowed in URLs
-function compileUriCode ($code, $simple=true) {
+function compileUriCode ($code, $simple = true) {
        // Compile constants
        if (!$simple) $code = str_replace('{--', '".', str_replace('--}', '."', $code));
 
@@ -2839,12 +2858,12 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
                $tmp = $FQFN . '.tmp';
 
                // Open the source file
-               $fp = fopen($FQFN, 'r') or OUTPUT_HTML('<strong>READ:</strong> ' . $FQFN . "<br />\n");
+               $fp = fopen($FQFN, 'r') or OUTPUT_HTML('<strong>READ:</strong> ' . $FQFN . '<br />');
 
                // Is the resource valid?
                if (is_resource($fp)) {
                        // Open temporary file
-                       $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('<strong>WRITE:</strong> ' . $tmp . "<br />\n");
+                       $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('<strong>WRITE:</strong> ' . $tmp . '<br />');
 
                        // Is the resource again valid?
                        if (is_resource($fp_tmp)) {
@@ -2861,7 +2880,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
                                                } else {
                                                        $next++;
                                                }
-                                       }
+                                       } // END - if
 
                                        // Write to temp file
                                        fputs($fp_tmp, $line);
@@ -2914,9 +2933,9 @@ function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
                // Remove CRLF
                $message = str_replace("\r", '', str_replace("\n", '', $message));
 
-               // Log this message away
-               $fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or app_die(__FUNCTION__, __LINE__, "Cannot write logfile debug.log!");
-               fwrite($fp, date("d.m.Y|H:i:s", time())."|" . getModule()."|".basename($funcFile)."|" . $line."|".strip_tags($message)."\n");
+               // Log this message away, we better don't call app_die() here to prevent an endless loop
+               $fp = fopen(constant('PATH') . 'inc/cache/debug.log', 'a') or die(__FUNCTION__.'['.__LINE__.']: Cannot write logfile debug.log!');
+               fwrite($fp, date('d.m.Y|H:i:s', time()) . '|' . getModule() . '|' . basename($funcFile) . '|' . $line . '|' . strip_tags($message) . "\n");
                fclose($fp);
        } // END - if
 }
@@ -2926,7 +2945,7 @@ function runResetIncludes () {
        // Is the reset set or old sql_patches?
        if ((!isResetModeEnabled()) || (EXT_VERSION_IS_OLDER('sql_patches', '0.4.5'))) {
                // Then abort here
-               DEBUG_LOG(__FUNCTION__, __LINE__, "Cannot run reset! Please report this bug. Thanks");
+               DEBUG_LOG(__FUNCTION__, __LINE__, 'Cannot run reset! Please report this bug. Thanks');
        } // END - if
 
        // Get more daily reset scripts
@@ -3121,7 +3140,7 @@ function cachePurgeAdminMenu ($id=0, $action = '', $what = '', $str = '') {
                return false;
        } elseif (!isCacheInstanceValid()) {
                // No cache instance!
-               DEBUG_LOG(__FUNCTION__, __LINE__, " No cache instance found.");
+               DEBUG_LOG(__FUNCTION__, __LINE__, 'No cache instance found.');
                return false;
        } elseif ((!isConfigEntrySet('cache_admin_menu')) || (getConfig('cache_admin_menu') != 'Y')) {
                // Caching disabled (currently experiemental!)
@@ -3187,7 +3206,7 @@ function addNewBonusMail ($data, $mode = '', $output=true) {
                LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_MORE_SELECTED'));
        } else {
                // Debug log
-               DEBUG_LOG(__FUNCTION__, __LINE__, " cat={$data['cat']},receiver={$data['receiver']},data=".base64_encode(serialize($data))." More selected, than available!");
+               DEBUG_LOG(__FUNCTION__, __LINE__, "cat={$data['cat']},receiver={$data['receiver']},data=".base64_encode(serialize($data))." More selected, than available!");
        }
 }
 
@@ -3211,7 +3230,7 @@ function DETERMINE_REFID () {
                $GLOBALS['refid'] = bigintval(getSession('refid'));
        } elseif ((GET_EXT_VERSION('sql_patches') != '') && (getConfig('def_refid') > 0)) {
                // Set default refid as refid in URL
-               $GLOBALS['refid'] = getConfig(('def_refid'));
+               $GLOBALS['refid'] = getConfig('def_refid');
        } elseif ((GET_EXT_VERSION('user') >= '0.3.4') && (getConfig('select_user_zero_refid')) == 'Y') {
                // Select a random user which has confirmed enougth mails
                $GLOBALS['refid'] = determineRandomReferalId();
@@ -3389,6 +3408,113 @@ function generateExtensionInactiveNotInstalledMessage ($ext_name) {
        return $message;
 }
 
+// Reads a directory recursively by default and searches for files not matching
+// an exclusion pattern. You can now keep the exclusion pattern empty for reading
+// a whole directory.
+function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $addBaseDir = true, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = true) {
+       // Add default entries we should exclude
+       $excludeArray[] = '.';
+       $excludeArray[] = '..';
+       $excludeArray[] = '.svn';
+       $excludeArray[] = '.htaccess';
+
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "baseDir={$baseDir},prefix={$prefix} - Entered!");
+       // Init includes
+       $files = array();
+
+       // Open directory
+       $dirPointer = opendir(constant('PATH') . $baseDir) or app_die(__FUNCTION__, __LINE__, 'Cannot read directory ' . basename($baseDir) . '.');
+
+       // Read all entries
+       while ($baseFile = readdir($dirPointer)) {
+               // Exclude '.', '..' and entries in $excludeArray automatically
+               if (in_array($baseFile, $excludeArray, true))  {
+                       // Exclude them
+                       //* DEBUG: */ print 'excluded=' . $baseFile . '<br />';
+                       continue;
+               } // END - if
+
+               // Construct include filename and FQFN
+               $fileName = $baseDir . '/' . $baseFile;
+               $FQFN = constant('PATH') . $fileName;
+
+               // Remove double slashes
+               $FQFN = str_replace('//', '/', $FQFN);
+
+               // Check if the base filename matches an exclusion pattern and if the pattern is not empty
+               if ((!empty($excludePattern)) && (preg_match($excludePattern, $baseFile, $match))) {
+                       // These Lines are only for debugging!!
+                       //* DEBUG: */ print 'baseDir:' . $baseDir . '<br />';
+                       //* DEBUG: */ print 'baseFile:' . $baseFile . '<br />';
+                       //* DEBUG: */ print 'FQFN:' . $FQFN . '<br />';
+
+                       // Exclude this one
+                       continue;
+               } // END - if
+
+               // Skip also files with non-matching prefix genericly
+               if (($recursive === true) && (isDirectory($FQFN))) {
+                       // Is a redirectory so read it as well
+                       $files = merge_array($files, getArrayFromDirectory ($baseDir . $baseFile . '/', $prefix, $fileIncludeDirs, $addBaseDir, $excludeArray, $extension, $excludePattern, $recursive));
+
+                       // And skip further processing
+                       continue;
+               } elseif (substr($baseFile, 0, strlen($prefix)) != $prefix) {
+                       // Skip this file
+                       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Invalid prefix in file " . $baseFile . ", prefix=" . $prefix);
+                       continue;
+               } elseif (!isFileReadable($FQFN)) {
+                       // Not readable so skip it
+                       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "File " . $FQFN . " is not readable!");
+                       continue;
+               }
+
+               // Is the file a PHP script or other?
+               //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}");
+               if ((substr($baseFile, -4, 4) == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) {
+                       // Is this a valid include file?
+                       if ($extension == '.php') {
+                               // Remove both for extension name
+                               $extName = substr($baseFile, strlen($prefix), -4);
+
+                               // Try to find it
+                               $extId = GET_EXT_ID($extName);
+
+                               // Is the extension valid and active?
+                               if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
+                                       // Then add this file
+                                       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Extension entry ' . $baseFile . ' added.');
+                                       $files[] = $fileName;
+                               } elseif ($extId == 0) {
+                                       // Add non-extension files as well
+                                       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Regular entry ' . $baseFile . ' added.');
+                                       if ($addBaseDir === true) {
+                                               $files[] = $fileName;
+                                       } else {
+                                               $files[] = $baseFile;
+                                       }
+                               }
+                       } else {
+                               // We found .php file but should not search for them, why?
+                               debug_report_bug('We should find files with extension=' . $extension . ', but we found a PHP script.');
+                       }
+               } else {
+                       // Other, generic file found
+                       $files[] = $fileName;
+               }
+       } // END - while
+
+       // Close directory
+       closedir($dirPointer);
+
+       // Sort array
+       asort($files);
+
+       // Return array with include files
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, '- Left!');
+       return $files;
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////