+ // Add output
+ $debug .= "Please report this bug at <a title=\"Direct link to the bug-tracker\" href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a> and include the logfile from <strong>" . str_replace(getConfig('PATH'), '', getConfig('CACHE_PATH')) . "debug.log</strong> in your report (you can now attach files):<pre>";
+ $debug .= debug_get_printable_backtrace();
+ $debug .= "</pre>\nRequest-URI: " . getRequestUri()."<br />\n";
+ $debug .= "Thank you for finding bugs.";
+
+ // And abort here
+ // @TODO This cannot be rewritten to app_die(), try to find a solution for this.
+ die($debug);
+}
+
+// Generates a ***weak*** seed
+function generateSeed () {
+ return microtime(true) * 100000;
+}
+
+// Converts a message code to a human-readable message
+function getMessageFromErrorCode ($code) {
+ $message = '';
+ switch ($code) {
+ case '': break;
+ case getCode('LOGOUT_DONE') : $message = getMessage('LOGOUT_DONE'); break;
+ case getCode('LOGOUT_FAILED') : $message = "<span class=\"guest_failed\">{--LOGOUT_FAILED--}</span>"; break;
+ case getCode('DATA_INVALID') : $message = getMessage('MAIL_DATA_INVALID'); break;
+ case getCode('POSSIBLE_INVALID') : $message = getMessage('MAIL_POSSIBLE_INVALID'); break;
+ case getCode('ACCOUNT_LOCKED') : $message = getMessage('MEMBER_ACCOUNT_LOCKED_UNC'); break;
+ case getCode('USER_404') : $message = getMessage('USER_404'); break;
+ case getCode('STATS_404') : $message = getMessage('MAIL_STATS_404'); break;
+ case getCode('ALREADY_CONFIRMED'): $message = getMessage('MAIL_ALREADY_CONFIRMED'); break;
+ case getCode('WRONG_PASS') : $message = getMessage('LOGIN_WRONG_PASS'); break;
+ case getCode('WRONG_ID') : $message = getMessage('LOGIN_WRONG_ID'); break;
+ case getCode('ID_LOCKED') : $message = getMessage('LOGIN_ID_LOCKED'); break;
+ case getCode('ID_UNCONFIRMED') : $message = getMessage('LOGIN_ID_UNCONFIRMED'); break;
+ case getCode('ID_GUEST') : $message = getMessage('LOGIN_ID_GUEST'); break;
+ case getCode('NO_COOKIES') : $message = getMessage('LOGIN_NO_COOKIES'); break;
+ case getCode('COOKIES_DISABLED') : $message = getMessage('LOGIN_NO_COOKIES'); break;
+ case getCode('BEG_SAME_AS_OWN') : $message = getMessage('BEG_SAME_UID_AS_OWN'); break;
+ case getCode('LOGIN_FAILED') : $message = getMessage('LOGIN_FAILED_GENERAL'); break;
+ case getCode('MODULE_MEM_ONLY') : $message = sprintf(getMessage('MODULE_MEM_ONLY'), getRequestElement('mod')); break;
+ case getCode('OVERLENGTH') : $message = getMessage('MEMBER_TEXT_OVERLENGTH'); break;
+ case getCode('URL_FOUND') : $message = getMessage('MEMBER_TEXT_CONTAINS_URL'); break;
+ case getCode('SUBJ_URL') : $message = getMessage('MEMBER_SUBJ_CONTAINS_URL'); break;
+ case getCode('BLIST_URL') : $message = "{--MEMBER_URL_BLACK_LISTED--}<br />\n{--MEMBER_BLIST_TIME--}: ".generateDateTime(getRequestElement('blist'), 0); break;
+ case getCode('NO_RECS_LEFT') : $message = getMessage('MEMBER_SELECTED_MORE_RECS'); break;
+ case getCode('INVALID_TAGS') : $message = getMessage('MEMBER_HTML_INVALID_TAGS'); break;
+ case getCode('MORE_POINTS') : $message = getMessage('MEMBER_MORE_POINTS_NEEDED'); break;
+ case getCode('MORE_RECEIVERS1') : $message = getMessage('MEMBER_ENTER_MORE_RECEIVERS'); break;
+ case getCode('MORE_RECEIVERS2') : $message = getMessage('MEMBER_NO_MORE_RECEIVERS_FOUND'); break;
+ case getCode('MORE_RECEIVERS3') : $message = sprintf(getMessage('MEMBER_ENTER_MORE_MIN_RECEIVERS'), getConfig('order_min')); break;
+ case getCode('INVALID_URL') : $message = getMessage('MEMBER_ENTER_INVALID_URL'); break;
+
+ case getCode('ERROR_MAILID'):
+ if (isExtensionActive('mailid', true)) {
+ $message = getMessage('ERROR_CONFIRMING_MAIL');
+ } else {
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'mailid');
+ }
+ break;
+
+ case getCode('EXTENSION_PROBLEM'):
+ if (isGetRequestElementSet('ext')) {
+ $message = generateExtensionInactiveNotInstalledMessage(getRequestElement('ext'));
+ } else {
+ $message = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
+ }
+ break;
+
+ case getCode('URL_TLOCK'):
+ $result = SQL_QUERY_ESC("SELECT `timestamp` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
+
+ // Load timestamp from last order
+ list($timestamp) = SQL_FETCHROW($result);
+ $timestamp = generateDateTime($timestamp, 1);
+
+ // Free memory
+ SQL_FREERESULT($result);
+
+ // Calculate hours...
+ $STD = round(getConfig('url_tlock') / 60 / 60);
+
+ // Minutes...
+ $MIN = round((getConfig('url_tlock') - $STD * 60 * 60) / 60);
+
+ // And seconds
+ $SEC = getConfig('url_tlock') - $STD * 60 * 60 - $MIN * 60;
+
+ // Finally contruct the message
+ // @TODO Rewrite this old lost code to a template
+ $message = "{--MEMBER_URL_TIME_LOCK--}<br />{--CONFIG_URL_TLOCK--} ".$STD."
+ {--_HOURS--}, ".$MIN." {--_MINUTES--} {--_AND--} ".$SEC." {--_SECONDS--}<br />
+ {--MEMBER_LAST_TLOCK--}: ".$timestamp;
+ break;
+
+ default:
+ // Missing/invalid code
+ $message = sprintf(getMessage('UNKNOWN_MAILID_CODE'), $code);
+
+ // Log it
+ logDebugMessage(__FUNCTION__, __LINE__, $message);
+ break;
+ } // END - switch
+
+ // Return the message
+ return $message;
+}
+
+// Compile characters which are allowed in URLs
+function compileUriCode ($code, $simple = true) {
+ // Compile constants
+ if ($simple === false) $code = str_replace('{--', '".', str_replace('--}', '."', $code));
+
+ // Compile QUOT and other non-HTML codes
+ $code = str_replace('{DOT}', '.',
+ str_replace('{SLASH}', '/',
+ str_replace('{QUOT}', "'",
+ str_replace('{DOLLAR}', '$',
+ str_replace('{OPEN_ANCHOR}', '(',
+ str_replace('{CLOSE_ANCHOR}', ')',
+ str_replace('{OPEN_SQR}', '[',
+ str_replace('{CLOSE_SQR}', ']',
+ str_replace('{PER}', '%',
+ $code
+ )))))))));
+
+ // Return compiled code
+ return $code;
+}
+
+// Function taken from user comments on www.php.net / function eregi()
+function isUrlValidSimple ($url) {
+ // Prepare URL
+ $url = secureString(str_replace("\\", '', compileRawCode(urldecode($url))));
+
+ // Allows http and https
+ $http = "(http|https)+(:\/\/)";
+ // Test domain
+ $domain1 = "([[:alnum:]]([-[:alnum:]])*\.)?([[:alnum:]][-[:alnum:]\.]*[[:alnum:]])(\.[[:alpha:]]{2,5})?";
+ // Test double-domains (e.g. .de.vu)
+ $domain2 = "([-[:alnum:]])?(\.[[:alnum:]][-[:alnum:]\.]*[[:alnum:]])(\.[[:alpha:]]{2,5})(\.[[:alpha:]]{2,5})?";
+ // Test IP number
+ $ip = "([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})";
+ // ... directory
+ $dir = "((/)+([-_\.[:alnum:]])+)*";
+ // ... page
+ $page = "/([-_[:alnum:]][-\._[:alnum:]]*\.[[:alnum:]]{2,5})?";
+ // ... and the string after and including question character
+ $getstring1 = "([\?/]([[:alnum:]][-\._%[:alnum:]]*(=)?([-\@\._:%[:alnum:]])+)(&([[:alnum:]]([-_%[:alnum:]])*(=)?([-\@\[\._:%[:alnum:]])+(\])*))*)?";
+ // Pattern for URLs like http://url/dir/doc.html?var=value
+ $pattern['d1dpg1'] = $http . $domain1 . $dir . $page . $getstring1;
+ $pattern['d2dpg1'] = $http . $domain2 . $dir . $page . $getstring1;
+ $pattern['ipdpg1'] = $http . $ip . $dir . $page . $getstring1;
+ // Pattern for URLs like http://url/dir/?var=value
+ $pattern['d1dg1'] = $http . $domain1 . $dir.'/' . $getstring1;
+ $pattern['d2dg1'] = $http . $domain2 . $dir.'/' . $getstring1;
+ $pattern['ipdg1'] = $http . $ip . $dir.'/' . $getstring1;
+ // Pattern for URLs like http://url/dir/page.ext
+ $pattern['d1dp'] = $http . $domain1 . $dir . $page;
+ $pattern['d1dp'] = $http . $domain2 . $dir . $page;
+ $pattern['ipdp'] = $http . $ip . $dir . $page;
+ // Pattern for URLs like http://url/dir
+ $pattern['d1d'] = $http . $domain1 . $dir;
+ $pattern['d2d'] = $http . $domain2 . $dir;
+ $pattern['ipd'] = $http . $ip . $dir;
+ // Pattern for URLs like http://url/?var=value
+ $pattern['d1g1'] = $http . $domain1 . '/' . $getstring1;
+ $pattern['d2g1'] = $http . $domain2 . '/' . $getstring1;
+ $pattern['ipg1'] = $http . $ip . '/' . $getstring1;
+ // Pattern for URLs like http://url?var=value
+ $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()) {
+ // @TODO Are these convertions still required?
+ $pat = str_replace('.', "\.", $pat);
+ $pat = str_replace('@', "\@", $pat);
+ //* DEBUG: */ outputHtml($key."= " . $pat . '<br />');
+ } // END - if
+
+ // Check if expression matches
+ $reg = ($reg || preg_match(('^' . $pat.'^'), $url));
+
+ // Does it match?
+ if ($reg === true) break;
+ }
+
+ // Return true/false
+ return $reg;
+}
+
+// Wtites data to a config.php-style file
+// @TODO Rewrite this function to use readFromFile() and writeToFile()
+function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
+ // Initialize some variables
+ $done = false;
+ $seek++;
+ $next = -1;
+ $found = false;
+
+ // Is the file there and read-/write-able?
+ if ((isFileReadable($FQFN)) && (is_writeable($FQFN))) {
+ $search = 'CFG: ' . $comment;
+ $tmp = $FQFN . '.tmp';
+
+ // Open the source file
+ $fp = fopen($FQFN, 'r') or outputHtml('<strong>READ:</strong> ' . $FQFN . '<br />');
+
+ // Is the resource valid?
+ if (is_resource($fp)) {
+ // Open temporary file
+ $fp_tmp = fopen($tmp, 'w') or outputHtml('<strong>WRITE:</strong> ' . $tmp . '<br />');
+
+ // Is the resource again valid?
+ if (is_resource($fp_tmp)) {
+ // Mark temporary file as readable
+ $GLOBALS['file_readable'][$tmp] = true;
+
+ // Start reading
+ while (!feof($fp)) {
+ // Read from source file
+ $line = fgets ($fp, 1024);
+
+ if (strpos($line, $search) > -1) { $next = '0'; $found = true; }
+
+ if ($next > -1) {
+ if ($next === $seek) {
+ $next = -1;
+ $line = $prefix . $DATA . $suffix . "\n";
+ } else {
+ $next++;
+ }
+ } // END - if
+
+ // Write to temp file
+ fputs($fp_tmp, $line);
+ } // END - while
+
+ // Close temp file
+ fclose($fp_tmp);
+
+ // Finished writing tmp file
+ $done = true;
+ } // END - if
+
+ // Close source file
+ fclose($fp);
+
+ if (($done === true) && ($found === true)) {
+ // Copy back tmp file and delete tmp :-)
+ copyFileVerified($tmp, $FQFN, 0644);
+ return removeFile($tmp);
+ } elseif ($found === false) {
+ outputHtml('<strong>CHANGE:</strong> 404!');
+ } else {
+ outputHtml('<strong>TMP:</strong> UNDONE!');
+ }
+ }
+ } else {
+ // File not found, not readable or writeable
+ outputHtml('<strong>404:</strong> ' . $FQFN . '<br />');
+ }
+
+ // An error was detected!
+ return false;
+}
+// Send notification to admin
+function sendAdminNotification ($subject, $templateName, $content=array(), $userid = '0') {
+ if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
+ // Send new way
+ sendAdminsEmails($subject, $templateName, $content, $userid);
+ } else {
+ // Send out out-dated way
+ $message = loadEmailTemplate($templateName, $content, $userid);
+ sendAdminEmails($subject, $message);
+ }