+ // Return result
+ return $admin;
+}
+
+// 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("\\", '', compileCode(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 (getExtensionVersion('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);
+ }
+}
+
+// Debug message logger
+function logDebugMessage ($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(getConfig('CACHE_PATH') . '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 . '|' . $message . "\n");
+ fclose($fp);
+ } // END - if