X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=db721a542e5b3e9aaa02ab60781e010421b0aeb1;hp=f55f5135603ad783649c0e0dfd92fd15e04f7ee1;hb=509ae618cc32ba2b811cf66567d62abc597dc405;hpb=07612d2debcc78a93678db0deed050d82df432f1 diff --git a/inc/functions.php b/inc/functions.php index f55f513560..db721a542e 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -238,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? @@ -250,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 @@ -393,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__."(".__LINE__."):numRows=".SQL_NUMROWS($result_email)."
\n"; // Does the user exist? @@ -797,13 +799,13 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') { if (EXT_IS_ACTIVE('nickname')) { //* DEBUG: */ print __FUNCTION__."(".__LINE__."):NICKNAME!
\n"; // Load nickname - $result = SQL_QUERY_ESC("SELECT surname, family, gender, email, nickname FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", - array(bigintval($UID)), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `gender`, `email`, `nickname` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1", + array(bigintval($UID)), __FUNCTION__, __LINE__); } else { //* DEBUG: */ print __FUNCTION__."(".__LINE__."):NO-NICK!
\n"; /// Load normal data - $result = SQL_QUERY_ESC("SELECT surname, family, gender, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", - array(bigintval($UID)), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `gender`, `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1", + array(bigintval($UID)), __FUNCTION__, __LINE__); } // Fetch and merge data @@ -1243,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 @@ -1952,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); } @@ -2015,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 = generateUserEmailLink($email, 'admin'); } 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 = generateSponsorEmailLink($email, 'sponsor_data'); } // Shall I close the link when there is no admin? @@ -2058,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(); @@ -2432,14 +2433,14 @@ function searchDirsRecursive ($dir, &$last_changed) { //* DEBUG: */ print __FUNCTION__."(".__LINE__."):dir=" . $dir."
\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__."(".__LINE__."):ds[]=".count($ds)."
\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__."(".__LINE__."):FQFN={$FQFN}
\n"; @@ -2558,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); @@ -2734,7 +2741,7 @@ function generateAdminLink ($aid) { // Is the extension there? if (EXT_IS_ACTIVE('admins')) { // Admin found - $admin = "" . $login.""; + $admin = "" . $login.""; } else { // Extension not found $admin = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins'); @@ -2750,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)); @@ -2851,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('READ: ' . $FQFN . "
\n"); + $fp = fopen($FQFN, 'r') or OUTPUT_HTML('READ: ' . $FQFN . '
'); // Is the resource valid? if (is_resource($fp)) { // Open temporary file - $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('WRITE: ' . $tmp . "
\n"); + $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('WRITE: ' . $tmp . '
'); // Is the resource again valid? if (is_resource($fp_tmp)) { @@ -2873,7 +2880,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) { } else { $next++; } - } + } // END - if // Write to temp file fputs($fp_tmp, $line); @@ -2926,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 } @@ -2938,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 @@ -3133,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!) @@ -3199,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!"); } } @@ -3221,12 +3228,12 @@ function DETERMINE_REFID () { } elseif ((isSessionVariableSet('refid')) && (getSession('refid') != 0)) { // Set session refid als global $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')); } 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(); + } elseif ((GET_EXT_VERSION('sql_patches') != '') && (getConfig('def_refid') > 0)) { + // Set default refid as refid in URL + $GLOBALS['refid'] = getConfig('def_refid'); } else { // No default ID when sql_patches is not installed or none set $GLOBALS['refid'] = 0; @@ -3401,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 . "
\n"; + 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 . "
\n"; + //* DEBUG: */ print 'baseFile:' . $baseFile . "
\n"; + //* DEBUG: */ print 'FQFN:' . $FQFN . "
\n"; + + // 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 // //////////////////////////////////////////////////