+// @TODO Please describe this function
+function getArrayFromActualVersion () {
+ // Init variables
+ $next_dir = '';
+
+ // Directory to start with search
+ $last_changed = array(
+ 'path_name' => '',
+ 'time' => 0
+ );
+
+ // 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);
+
+ // Get file
+ $last_file = readFromFile($last_changed['path_name']);
+
+ // Get all the keywords to search for
+ $searchFor = getSearchFor();
+
+ // This foreach loops the $searchFor-Tags (array('Revision', 'Date', 'Tag', 'Author') --> could easaly extended in the future)
+ foreach ($searchFor as $search) {
+ // Searches for "$search-tag:VALUE$" or "$search-tag::VALUE$"(the stylish keywordversion ;-)) in the lates modified file
+ $res += preg_match('@\$' . $search.'(:|::) (.*) \$@U', $last_file, $t);
+ // This trimms the search-result and puts it in the $akt_vers-return array
+ if (isset($t[2])) $akt_vers[$search] = trim($t[2]);
+ } // END - foreach
+
+ // Save the last-changed filename for debugging
+ $akt_vers['File'] = $last_changed['path_name'];
+
+ // at least 3 keyword-Tags are needed for propper values
+ if ($res && $res >= 3
+ && isset($akt_vers['Revision']) && $akt_vers['Revision'] != ''
+ && isset($akt_vers['Date']) && $akt_vers['Date'] != ''
+ && isset($akt_vers['Tag']) && $akt_vers['Tag'] != '') {
+ // Prepare content witch need special treadment
+
+ // Prepare timestamp for date
+ preg_match('@(....)-(..)-(..) (..):(..):(..)@', $akt_vers['Date'], $match_d);
+ $akt_vers['Date'] = mktime($match_d[4], $match_d[5], $match_d[6], $match_d[2], $match_d[3], $match_d[1]);
+
+ // Add author to the Tag if the author is set and is not quix0r (lead coder)
+ if ((isset($akt_vers['Author'])) && ($akt_vers['Author'] != "quix0r")) {
+ $akt_vers['Tag'] .= '-'.strtoupper($akt_vers['Author']);
+ } // END - if
+
+ } else {
+ // No valid Data from the last modificated file so read the Revision from the Server. Fallback-solution!! Should not be removed I think.
+ $version = sendGetRequest('check-updates3.php');
+
+ // Prepare content
+ // Only sets not setted or not proper values to the Online-Server-Fallback-Solution
+ if (!isset($akt_vers['Revision']) || $akt_vers['Revision'] == '') $akt_vers['Revision'] = trim($version[10]);
+ if (!isset($akt_vers['Date']) || $akt_vers['Date'] == '') $akt_vers['Date'] = trim($version[9]);
+ if (!isset($akt_vers['Tag']) || $akt_vers['Tag'] == '') $akt_vers['Tag'] = trim($version[8]);
+ if (!isset($akt_vers['Author']) || $akt_vers['Author'] == '') $akt_vers['Author'] = "quix0r";
+ }
+
+ // Return prepared array
+ return $akt_vers;
+}
+
+// Back-ported from the new ship-simu engine. :-)
+function debug_get_printable_backtrace () {
+ // Init variable
+ $backtrace = "<ol>\n";
+
+ // Get and prepare backtrace for output
+ $backtraceArray = debug_backtrace();
+ foreach ($backtraceArray as $key => $trace) {
+ if (!isset($trace['file'])) $trace['file'] = __FUNCTION__;
+ if (!isset($trace['line'])) $trace['line'] = __LINE__;
+ if (!isset($trace['args'])) $trace['args'] = array();
+ $backtrace .= "<li class=\"debug_list\"><span class=\"backtrace_file\">".basename($trace['file'])."</span>:" . $trace['line'].", <span class=\"backtrace_function\">" . $trace['function'].'('.count($trace['args']).")</span></li>\n";
+ } // END - foreach
+
+ // Close it
+ $backtrace .= "</ol>\n";
+
+ // Return the backtrace
+ return $backtrace;
+}
+
+// Output a debug backtrace to the user
+function debug_report_bug ($message = '') {
+ // Init message
+ $debug = '';
+ // Is the optional message set?
+ if (!empty($message)) {
+ // Use and log it
+ $debug = sprintf("Note: %s<br />\n",
+ $message
+ );
+
+ // @TODO Add a little more infos here
+ DEBUG_LOG(__FUNCTION__, __LINE__, $message);
+ } // END - if
+
+ // 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>inc/cache/debug.log</strong> in your report (you can now attach files):<pre>";
+ $debug .= debug_get_printable_backtrace();
+ $debug .= "</pre>\nRequest-URI: " . $_SERVER['REQUEST_URI']."<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 (taken from de.php.net/mt_srand)
+function generateSeed () {
+ list($usec, $sec) = explode(' ', microtime());
+ $microTime = (((float)$sec + (float)$usec)) * 100000;
+ return $microTime;
+}
+
+// Converts a message code to a human-readable message
+function convertCodeToMessage ($code) {
+ $message = '';
+ switch ($code) {
+ 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_NOT_FOUND'); break;
+ case getCode('STATS_404') : $message = getMessage('MAIL_STATS_404'); break;
+ case getCode('ALREADY_CONFIRMED'): $message = getMessage('MAIL_ALREADY_CONFIRMED'); break;
+
+ case getCode('ERROR_MAILID'):
+ if (EXT_IS_ACTIVE($ext, true)) {
+ $message = getMessage('ERROR_CONFIRMING_MAIL');
+ } else {
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'mailid');
+ }
+ break;
+
+ case getCode('EXTENSION_PROBLEM'):
+ if (REQUEST_ISSET_GET('ext')) {
+ $message = generateExtensionInactiveNotInstalledMessage(REQUEST_GET('ext'));
+ } else {
+ $message = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
+ }
+ 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'), REQUEST_GET('mod')); break;
+
+ default:
+ // Missing/invalid code
+ $message = sprintf(getMessage('UNKNOWN_MAILID_CODE'), $code);
+
+ // Log it
+ DEBUG_LOG(__FUNCTION__, __LINE__, $message);
+ break;
+ } // END - switch
+
+ // Return the message
+ return $message;
+}
+
+// Generate a "link" for the given admin id (aid)
+function generateAdminLink ($aid) {
+ // No assigned admin is default
+ $admin = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
+
+ // Zero? = Not assigned
+ if (bigintval($aid) > 0) {
+ // Load admin's login
+ $login = getAdminLogin($aid);
+
+ // Is the login valid?
+ if ($login != '***') {
+ // Is the extension there?
+ if (EXT_IS_ACTIVE('admins')) {
+ // Admin found
+ $admin = "<a href=\"".generateEmailLink(getAdminEmail($aid), 'admins')."\">" . $login."</a>";
+ } else {
+ // Extension not found
+ $admin = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins');
+ }
+ } else {
+ // Maybe deleted?
+ $admin = "<div class=\"admin_note\">".sprintf(getMessage('ADMIN_ID_404'), $aid)."</div>";
+ }
+ } // END - if
+
+ // Return result
+ return $admin;
+}
+
+// Compile characters which are allowed in URLs
+function compileUriCode ($code, $simple = true) {
+ // Compile constants
+ if (!$simple) $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 = strip_tags(str_replace("\\", '', COMPILE_CODE(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);
+ echo $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 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 />');
+
+ // Is the resource again valid?
+ if (is_resource($fp_tmp)) {
+ 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) {
+ OUTPUT_HTML('<strong>CHANGE:</strong> 404!');
+ } else {
+ OUTPUT_HTML('<strong>TMP:</strong> UNDONE!');
+ }
+ }
+ } else {
+ // File not found, not readable or writeable
+ OUTPUT_HTML('<strong>404:</strong> ' . $FQFN . '<br />');
+ }
+
+ // An error was detected!
+ return false;
+}
+// Send notification to admin
+function sendAdminNotification ($subject, $templateName, $content=array(), $uid = '0') {
+ if (GET_EXT_VERSION('admins') >= '0.4.1') {
+ // Send new way
+ SEND_ADMIN_EMAILS_PRO($subject, $templateName, $content, $uid);
+ } else {
+ // Send out out-dated way
+ $message = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
+ SEND_ADMIN_EMAILS($subject, $message);
+ }
+}
+
+// Debug message logger
+function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
+ // Is debug mode enabled?
+ if ((isDebugModeEnabled()) || ($force === true)) {
+ // Remove CRLF
+ $message = str_replace("\r", '', str_replace("\n", '', $message));
+
+ // 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