X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=66b0c63e190892a6e095c919f5eabb0edf6bed47;hp=eb0ba63455b268642061309e2d03b24b16963fac;hb=8d70fd41c880ca61bafb47a69a6411c741c71dff;hpb=2c0f5aabd4c866f67705f36f7878dbc223daa9d8 diff --git a/inc/functions.php b/inc/functions.php index eb0ba63455..66b0c63e19 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -134,7 +134,7 @@ function sendHttpHeaders () { $now = gmdate('D, d M Y H:i:s') . ' GMT'; // Send HTTP header - sendHeader('HTTP/1.1 200'); + sendHeader('HTTP/1.1 200 OK'); // General headers for no caching sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21 @@ -149,19 +149,21 @@ function sendHttpHeaders () { // Compiles the final output function compileFinalOutput () { // Init counter - $cnt = '0'; + $cnt = 0; // Add page header and footer addPageHeaderFooter(); // Compile all out - while (((strpos($GLOBALS['output'], '{--') > 0) || (strpos($GLOBALS['output'], '{!') > 0) || (strpos($GLOBALS['output'], '{?') > 0)) && ($cnt < 3)) { + while (((strpos($GLOBALS['output'], '{--') !== false) || (strpos($GLOBALS['output'], '{!') !== false) || (strpos($GLOBALS['output'], '{?') !== false) || (strpos($GLOBALS['output'], '{%') !== false)) && ($cnt < 3)) { // Init common variables $content = array(); $newContent = ''; // Compile it - $eval = "\$newContent = \"".compileCode(escapeQuotes($GLOBALS['output']))."\";"; + //* DEBUG: */ print '
'.htmlentities($GLOBALS['output']).'
'; + $eval = '$newContent = "' . compileCode(escapeQuotes($GLOBALS['output'])) . '";'; + //* DEBUG: */ die('
'.htmlentities($eval).'
'); eval($eval); // Was that eval okay? @@ -169,6 +171,8 @@ function compileFinalOutput () { // Something went wrong! debug_report_bug('Evaluation error:
' . linenumberCode($eval) . '
', false); } // END - if + + // Use it again $GLOBALS['output'] = $newContent; // Count round @@ -496,7 +500,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') { $GLOBALS['tpl_content'] = readFromFile($FQFN); // Run code - $GLOBALS['tpl_content'] = "\$newContent = decodeEntities(\"".compileRawCode(escapeQuotes($GLOBALS['tpl_content']))."\");"; + $GLOBALS['tpl_content'] = '$newContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'])) . '");'; eval($GLOBALS['tpl_content']); } elseif (!empty($template)) { // Template file not found! @@ -536,7 +540,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = ' //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail},SUBJECT={$subject}
"); // Compile subject line (for POINTS constant etc.) - eval("\$subject = decodeEntities(\"".compileRawCode(escapeQuotes($subject))."\");"); + eval('$subject = decodeEntities("' . compileRawCode(escapeQuotes($subject)) . '");'); // Set from header if ((!isInStringIgnoreCase('@', $toEmail)) && ($toEmail > 0)) { @@ -582,10 +586,10 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = ' } // Compile "TO" - eval("\$toEmail = \"".compileRawCode(escapeQuotes($toEmail))."\";"); + eval('$toEmail = "' . compileRawCode(escapeQuotes($toEmail)) . '";'); // Compile "MSG" - eval("\$message = \"".str_replace('$', '$', compileRawCode(escapeQuotes($message)))."\";"); + eval('$message = "' . str_replace('$', '$', compileRawCode(escapeQuotes($message))) . '";'); // Fix HTML parameter (default is no!) if (empty($isHtml)) $isHtml = 'N'; @@ -785,6 +789,9 @@ function translatePoolType ($type) { // Translates the american decimal dot into a german comma function translateComma ($dotted, $cut = true, $max = '0') { + // First, cast all to double, due to PHP changes + $dotted = (double) $dotted; + // Default is 3 you can change this in admin area "Misc -> Misc Options" if (!isConfigEntrySet('max_comma')) setConfigEntry('max_comma', 3); @@ -1194,7 +1201,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're $year = date('Y', time()); // Use configured min age or fixed? - if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) { + if (isExtensionInstalledAndNewer('order', '0.2.1')) { // Configured $startYear = $year - getConfig('min_age'); } else { @@ -1222,7 +1229,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're // Get current year and subtract the configured minimum age $OUT .= "\n"; // Calculate earliest year depending on extension version - if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) { + if (isExtensionInstalledAndNewer('order', '0.2.1')) { // Use configured minimum age $year = date('Y', time()) - getConfig('min_age'); } else { @@ -1779,11 +1786,9 @@ function sendGetRequest ($script, $data = array()) { } else { $request .= 'User-Agent: ' . getConfig('TITLE') . '/' . getConfig('VERSION') . getConfig('HTTP_EOL'); } - $request .= 'Accept: text/plain;q=0.8' . getConfig('HTTP_EOL'); + $request .= 'Accept: image/png,image/*;q=0.8,text/plain,text/html,*/*;q=0.5' . getConfig('HTTP_EOL'); $request .= 'Accept-Charset: UTF-8,*' . getConfig('HTTP_EOL'); - $request .= 'Cache-Control: no-cache' . getConfig('HTTP_EOL'); - $request .= 'Content-Type: text/plain' . getConfig('HTTP_EOL'); - $request .= 'Content-Length: 0' . getConfig('HTTP_EOL'); + $request .= 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0' . getConfig('HTTP_EOL'); $request .= 'Connection: close' . getConfig('HTTP_EOL'); $request .= getConfig('HTTP_EOL'); @@ -1810,7 +1815,7 @@ function sendPostRequest ($script, $postData) { $body = http_build_query($postData, '', '&'); // Generate POST request header - $request = 'POST /' . trim($script) . ' HTTP/1.1' . getConfig('HTTP_EOL'); + $request = 'POST /' . trim($script) . ' HTTP/1.0' . getConfig('HTTP_EOL'); $request .= 'Host: ' . $host . getConfig('HTTP_EOL'); $request .= 'Referer: ' . getConfig('URL') . '/admin.php' . getConfig('HTTP_EOL'); $request .= 'User-Agent: ' . getConfig('TITLE') . '/' . getConfig('FULL_VERSION') . getConfig('HTTP_EOL'); @@ -1987,7 +1992,7 @@ function setupProxyTunnel ($host, $resource) { $response = array('', '', ''); // Generate CONNECT request header - $proxyTunnel = 'CONNECT ' . $host . ':80 HTTP/1.1' . getConfig('HTTP_EOL'); + $proxyTunnel = 'CONNECT ' . $host . ':80 HTTP/1.0' . getConfig('HTTP_EOL'); $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL'); // Use login data to proxy? (username at least!) @@ -2106,7 +2111,7 @@ function generateEmailLink ($email, $table = 'admins') { if ((isExtensionActive('admins')) && ($table == 'admins')) { // Create email link for contacting admin in guest area $EMAIL = generateAdminEmailLink($email); - } elseif ((isExtensionActive('user')) && (getExtensionVersion('user') >= '0.3.3') && ($table == 'user_data')) { + } elseif ((isExtensionInstalledAndNewer('user', '0.3.3')) && ($table == 'user_data')) { // Create email link for contacting a member within admin area (or later in other areas, too?) $EMAIL = generateUserEmailLink($email, 'admin'); } elseif ((isExtensionActive('sponsor')) && ($table == 'sponsor_data')) { @@ -2721,11 +2726,12 @@ function isUrlValidSimple ($url) { $pattern['d1g12'] = $http . $domain1 . $getstring1; $pattern['d2g12'] = $http . $domain2 . $getstring1; $pattern['ipg12'] = $http . $ip . $getstring1; + // Test all patterns $reg = false; foreach ($pattern as $key => $pat) { // Debug regex? - if (isDebugRegExpressionEnabled()) { + if (isDebugRegularExpressionEnabled()) { // @TODO Are these convertions still required? $pat = str_replace('.', "\.", $pat); $pat = str_replace('@', "\@", $pat); @@ -2733,7 +2739,7 @@ function isUrlValidSimple ($url) { } // END - if // Check if expression matches - $reg = ($reg || preg_match(('^' . $pat.'^'), $url)); + $reg = ($reg || preg_match(('^' . $pat . '^'), $url)); // Does it match? if ($reg === true) break; @@ -2940,14 +2946,14 @@ function handleLoginFailures ($accessLevel) { $OUT = ''; // Is the session data set? - if ((isSessionVariableSet('mxchange_' . $accessLevel . '_failures')) && (isSessionVariableSet('mxchange_' . $accessLevel . '_last_failure'))) { + if ((isSessionVariableSet('mailer_' . $accessLevel . '_failures')) && (isSessionVariableSet('mailer_' . $accessLevel . '_last_failure'))) { // Ignore zero values - if (getSession('mxchange_' . $accessLevel . '_failures') > 0) { + if (getSession('mailer_' . $accessLevel . '_failures') > 0) { // Non-guest has login failures found, get both data and prepare it for template //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "accessLevel={$accessLevel}
"); $content = array( - 'login_failures' => getSession('mxchange_' . $accessLevel . '_failures'), - 'last_failure' => generateDateTime(getSession('mxchange_' . $accessLevel . '_last_failure'), 2) + 'login_failures' => getSession('mailer_' . $accessLevel . '_failures'), + 'last_failure' => generateDateTime(getSession('mailer_' . $accessLevel . '_last_failure'), 2) ); // Load template @@ -2955,8 +2961,8 @@ function handleLoginFailures ($accessLevel) { } // END - if // Reset session data - setSession('mxchange_' . $accessLevel . '_failures', ''); - setSession('mxchange_' . $accessLevel . '_last_failure', ''); + setSession('mailer_' . $accessLevel . '_failures', ''); + setSession('mailer_' . $accessLevel . '_last_failure', ''); } // END - if // Return rendered content @@ -3079,7 +3085,7 @@ function determineReferalId () { } elseif ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')) { // Select a random user which has confirmed enougth mails $GLOBALS['refid'] = determineRandomReferalId(); - } elseif ((isExtensionInstalled('sql_patches')) && (getConfig('def_refid') > 0)) { + } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (getConfig('def_refid') > 0)) { // Set default refid as refid in URL $GLOBALS['refid'] = getConfig('def_refid'); } else { @@ -3931,6 +3937,43 @@ function searchDirsRecursive ($dir, &$last_changed, $lookFor = 'Date') { } // END - foreach } +// "Fixes" null or empty string to count of dashes +function fixNullEmptyToDashes ($str, $num) { + // Use str as default + $return = $str; + + // Is it empty? + if ((is_null($str)) || (trim($str) == '')) { + // Set it + $return = str_repeat('-', $num); + } // END - if + + // Return final string + return $return; +} + +// Handles the braces [] of a field (e.g. value of 'name' attribute) +function handleFieldWithBraces ($field) { + // Are there braces [] at the end? + if (substr($field, -2, 2) == '[]') { + // Try to find one and replace it. I do it this way to allow easy + // extending of this code. + foreach (array('admin_list_builder_id_value') as $key) { + // Is the cache entry set? + if (isset($GLOBALS[$key])) { + // Insert it + $field = str_replace('[]', '[' . $GLOBALS[$key] . ']', $field); + + // And abort + break; + } // END - if + } // END - foreach + } // END - if + + // Return it + return $field; +} + ////////////////////////////////////////////////// // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS // //////////////////////////////////////////////////