global $DATA;
// Do we have cache?
- if (!isset($GLOBALS['template_eval'][$template])) {
+ if (isTemplateCached($template)) {
+ // Evaluate the cache
+ eval(readTemplateCache($template));
+ } elseif (!isset($GLOBALS['template_eval'][$template])) {
// Add more variables which you want to use in your template files
$username = getUsername();
$ret = '';
if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
- // Generate date/time string
- $date_time = generateDateTime(time(), 1);
-
- // Is content an array
- if (is_array($content)) $content['date_time'] = $date_time;
-
- // @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",
- array(getUserId()), __FUNCTION__, __LINE__);
-
- // Is content an array?
- if (is_array($content)) {
- // Merge data
- $content = merge_array($content, SQL_FETCHARRAY($result));
-
- // Translate gender
- $content['gender'] = translateGender($content['gender']);
- } else {
- // @DEPRECATED
- // @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);
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array [%s], template=%s.", gettype($content), $template));
- }
-
- // Free result
- SQL_FREERESULT($result);
- } // END - if
-
// Base directory
$basePath = sprintf("%stemplates/%s/html/", getConfig('PATH'), getLanguage());
$mode = '';
$ret = '';
if ((strpos($GLOBALS['tpl_content'], '$') !== false) || (strpos($GLOBALS['tpl_content'], '{--') !== false) || (strpos($GLOBALS['tpl_content'], '{!') !== false) || (strpos($GLOBALS['tpl_content'], '{?') !== false)) {
// Normal HTML output?
- if ($GLOBALS['output_mode'] == 0) {
+ if (getOutputMode() == 0) {
// Add surrounding HTML comments to help finding bugs faster
$ret = "<!-- Template " . $template . " - Start -->\n" . $GLOBALS['tpl_content'] . "<!-- Template " . $template . " - End -->\n";
// Prepare eval() command
- $eval = '$ret = "' . compileCode(smartAddSlashes($GLOBALS['tpl_content'])) . '";';
+ $eval = '$ret = "' . compileCode(smartAddSlashes($ret)) . '";';
} else {
// Prepare eval() command
$eval = '$ret = "' . compileCode(smartAddSlashes($GLOBALS['tpl_content'])) . '";';
// Eval the code
eval($GLOBALS['template_eval'][$template]);
- } else {
- // No file!
- $GLOBALS['template_eval'][$template] = '404';
- }
- } elseif (((isAdmin()) || ((isInstalling()) && (!isInstalled()))) && ($GLOBALS['template_eval'][$template] == '404')) {
- // Only admins shall see this warning or when installation mode is active
- $ret = '<br /><span class=\\"guest_failed\\">{--TEMPLATE_404--}</span><br />
+ } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
+ // Only admins shall see this warning or when installation mode is active
+ $ret = '<br /><span class=\\"guest_failed\\">{--TEMPLATE_404--}</span><br />
(' . $template . ')<br />
<br />
{--TEMPLATE_CONTENT--}
<pre>' . print_r($content, true) . '</pre>
{--TEMPLATE_DATA--}
<pre>' . print_r($DATA, true) . '</pre>
-<br /><br />\";';
+<br /><br />';
+ } else {
+ // No file!
+ $GLOBALS['template_eval'][$template] = '404';
+ }
} else {
// Eval the code
eval($GLOBALS['template_eval'][$template]);
// Return the HTML code
return $ret;
} else {
- // Output direct
+ // Output directly
outputHtml($ret);
}
} elseif (isDebugModeEnabled()) {
function loadEmailTemplate ($template, $content = array(), $UID = 0) {
global $DATA;
- // Our configuration is kept non-global here
- $_CONFIG = getConfigArray();
-
// Make sure all template names are lowercase!
$template = strtolower($template);
} // END - if
// Load user's data
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):UID={$UID},template={$template},content[]=".gettype($content)."<br />");
+ //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):UID={$UID},template={$template},content[]=".gettype($content).'<br />');
if (($UID > 0) && (is_array($content))) {
// If nickname extension is installed, fetch nickname as well
- if (isExtensionActive('nickname')) {
+ if (isNicknameUsed($UID)) {
//* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NICKNAME!<br />");
- // 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__);
+ // Load by nickname
+ fetchUserData($UID, 'nickname');
} else {
//* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NO-NICK!<br />");
- /// 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__);
+ /// Load by userid
+ fetchUserData($UID);
}
- // Fetch and merge data
+ // Merge data if valid
//* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):content()=".count($content)." - PRE<br />");
- $content = merge_array($content, SQL_FETCHARRAY($result));
+ if (isUserDataValid()) {
+ $content = merge_array($content, getUserDataArray());
+ } // END - if
//* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):content()=".count($content)." - AFTER<br />");
-
- // Free result
- SQL_FREERESULT($result);
} // END - if
// Translate M to male or F to female if present
if (isFileReadable($FQFN)) {
// The local file does exists so we load it. :)
$GLOBALS['tpl_content'] = readFromFile($FQFN);
- $GLOBALS['tpl_content'] = SQL_ESCAPE($GLOBALS['tpl_content']);
// Run code
- $GLOBALS['tpl_content'] = "\$newContent = decodeEntities(\"".compileCode($GLOBALS['tpl_content'])."\");";
+ $GLOBALS['tpl_content'] = "\$newContent = decodeEntities(\"".compileCode(smartAddSlashes($GLOBALS['tpl_content']))."\");";
eval($GLOBALS['tpl_content']);
} elseif (!empty($template)) {
// Template file not found!
unset($DATA);
// Compile the code and eval it
- $eval = '$newContent = "' . compileCode(smartAddSlashes($newContent)) . '";';
+ $eval = '$newContent = "' . compileRawCode(smartAddSlashes($newContent)) . '";';
eval($eval);
// Return content
//* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):TO={$toEmail},SUBJECT={$subject}<br />");
// Compile subject line (for POINTS constant etc.)
- eval("\$subject = decodeEntities(\"".compileCode(smartAddSlashes($subject))."\");");
+ eval("\$subject = decodeEntities(\"".compileRawCode(smartAddSlashes($subject))."\");");
// Set from header
if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
ADD_MESSAGE_TO_BOX($toEmail, $subject, $message, $isHtml);
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__);
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):numRows=".SQL_NUMROWS($result_email)."<br />");
-
// Does the user exist?
- if (SQL_NUMROWS($result_email)) {
- // Load email address
- list($toEmail) = SQL_FETCHROW($result_email);
+ if (fetchUserData($toEmail)) {
+ // Get the email
+ $toEmail = getUserData('email');
} else {
// Set webmaster
$toEmail = getConfig('WEBMASTER');
}
-
- // Free result
- SQL_FREERESULT($result_email);
}
- } elseif ($toEmail == 0) {
+ } elseif ($toEmail == '0') {
// Is the webmaster!
$toEmail = getConfig('WEBMASTER');
}
}
// Compile "TO"
- eval("\$toEmail = \"".compileCode(smartAddSlashes($toEmail))."\";");
+ eval("\$toEmail = \"".compileRawCode(smartAddSlashes($toEmail))."\";");
// Compile "MSG"
- eval("\$message = \"".compileCode(smartAddSlashes($message))."\";");
+ eval("\$message = \"".compileRawCode(smartAddSlashes($message))."\";");
// Fix HTML parameter (default is no!)
if (empty($isHtml)) $isHtml = 'N';
if (isDebugModeEnabled()) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
outputHtml('<pre>
-Headers : ' . htmlentities(trim($mailHeader)) . '
+Headers : ' . str_replace('<', '<', str_replace('>', '>', htmlentities(trim($mailHeader)))) . '
To : ' . $toEmail . '
Subject : ' . $subject . '
Message : ' . $message . '
// get new instance
$mail = new PHPMailer();
+
+ // Set charset to UTF-8
+ $mail->CharSet('UTF-8');
+
+ // Path for PHPMailer
$mail->PluginDir = sprintf("%sinc/phpmailer/", getConfig('PATH'));
$mail->IsSMTP();
// Redirects to an URL and if neccessarry extends it with own base URL
function redirectToUrl ($URL) {
- // Compile out URI codes
- $URL = compileUriCode($URL);
+ // Compile out codes
+ eval('$URL = "' . compileRawCode($URL) . '";');
// Check if http(s):// is there
if ((substr($URL, 0, 7) != 'http://') && (substr($URL, 0, 8) != 'https://')) {
// Three different debug ways...
//* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $URL);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
//* DEBUG: */ die($URL);
// Default 'rel' value is external, nofollow is evil from Google and hurts the Internet
return $code;
} // END - if
+ // Start couting
+ $startCompile = explode(' ', microtime());
+
+ // Comile the code
+ $code = compileRawCode($code, $simple, $constants, $full);
+
+ // Get timing
+ $compiled = explode(' ', microtime());
+
+ // Add timing
+ $code .= '<!-- Compilation time: ' . ((($compiled[1] + $compiled[0]) - ($startCompile[1] + $startCompile[0])) * 1000). 'ms //-->';
+
+ // Return compiled code
+ return $code;
+}
+
+// Compiles the code (use compileCode() only for HTML because of the comments)
+function compileRawCode ($code, $simple = false, $constants = true, $full = true) {
+ // Is the code a string?
+ if (!is_string($code)) {
+ // Silently return it
+ return $code;
+ } // END - if
+
// Init replacement-array with full security characters
$secChars = $GLOBALS['security_chars'];
} // END - foreach
} // END - if
- // Return compiled code
+ // Return it
return $code;
}
}
//
-function addSelectionBox ($type, $default, $prefix = '', $id = 0) {
+function addSelectionBox ($type, $default, $prefix = '', $id = 0, $class = 'register_select') {
$OUT = '';
if ($type == 'yn') {
// This is a yes/no selection only!
if ($id > 0) $prefix .= "[" . $id."]";
- $OUT .= " <select name=\"" . $prefix."\" class=\"register_select\" size=\"1\">\n";
+ $OUT .= " <select name=\"" . $prefix."\" class=\"" . $class . "\" size=\"1\">\n";
} else {
// Begin with regular selection box here
if (!empty($prefix)) $prefix .= "_";
$type2 = $type;
if ($id > 0) $type2 .= "[" . $id."]";
- $OUT .= " <select name=\"".strtolower($prefix . $type2)."\" class=\"register_select\" size=\"1\">\n";
+ $OUT .= " <select name=\"".strtolower($prefix . $type2)."\" class=\"" . $class . "\" size=\"1\">\n";
}
switch ($type) {
$data .= getConfig('ENCRYPT_SEPERATOR') . determineReferalId();
$data .= getConfig('ENCRYPT_SEPERATOR') . getLanguage();
$data .= getConfig('ENCRYPT_SEPERATOR') . getCurrentTheme();
- $data .= getConfig('ENCRYPT_SEPERATOR') . getUserId();
+ $data .= getConfig('ENCRYPT_SEPERATOR') . getMemberId();
// Calculate number for generating the code
$a = $code + getConfig('_ADD') - 1;
- if (isConfigEntrySet('master_hash')) {
+ if (isConfigEntrySet('master_salt')) {
// Generate hash with master salt from modula of number with the prime number and other data
$saltedHash = generateHash(($a % getConfig('_PRIME')) . getConfig('ENCRYPT_SEPERATOR') . $server . getConfig('ENCRYPT_SEPERATOR') . $keys . getConfig('ENCRYPT_SEPERATOR') . $data . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . $a, getConfig('master_salt'));
$rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(getConfig('rand_no') - $a + sqrt(getConfig('_ADD'))) / pi();
} else {
// Generate hash with "hash of site key" from modula of number with the prime number and other data
- $saltedHash = generateHash(($a % getConfig('_PRIME')) . getConfig('ENCRYPT_SEPERATOR') . $server . getConfig('ENCRYPT_SEPERATOR') . $keys . getConfig('ENCRYPT_SEPERATOR') . $data . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . $a, substr(sha1(getConfig('SITE_KEY')), 0, 8));
+ $saltedHash = generateHash(($a % getConfig('_PRIME')) . getConfig('ENCRYPT_SEPERATOR') . $server . getConfig('ENCRYPT_SEPERATOR') . $keys . getConfig('ENCRYPT_SEPERATOR') . $data . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . $a, substr(sha1(getConfig('SITE_KEY')), 0, getConfig('salt_length')));
// Create number from hash
$rcode = hexdec(substr($saltedHash, 8, 9)) / abs(getConfig('rand_no') - $a + sqrt(getConfig('_ADD'))) / pi();
if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/'));
// Generate relative URL
- //* DEBUG: */ print("SCRIPT=" . $script."<br />");
+ //* DEBUG: */ print("SCRIPT=" . $script.'<br />');
if (substr(strtolower($script), 0, 7) == 'http://') {
// But only if http:// is in front!
$script = substr($script, (strlen($url) + 7));
$script = substr($script, (strlen($url) + 8));
}
- //* DEBUG: */ print("SCRIPT=" . $script."<br />");
+ //* DEBUG: */ print("SCRIPT=" . $script.'<br />');
if (substr($script, 0, 1) == '/') $script = substr($script, 1);
// Return host name
return array('', '', '');
} // END - if
- // Compile the script name
- $script = compileCode($script);
-
// Extract host name from script
$host = extractHostnameFromUrl($script);
} // END - if
// Open connection
- //* DEBUG: */ die("SCRIPT=" . $script."<br />");
+ //* DEBUG: */ die("SCRIPT=" . $script.'<br />');
if ($useProxy === true) {
// Connect to host through proxy connection
- $fp = @fsockopen(compileCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
+ $fp = @fsockopen(compileRawCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
} else {
// Connect to host directly
$fp = @fsockopen($host, 80, $errno, $errdesc, 30);
// Use login data to proxy? (username at least!)
if (getConfig('proxy_username') != '') {
// Add it as well
- $encodedAuth = base64_encode(compileCode(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . compileCode(getConfig('proxy_password')));
+ $encodedAuth = base64_encode(compileRawCode(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . compileRawCode(getConfig('proxy_password')));
$proxyTunnel .= "Proxy-Authorization: Basic " . $encodedAuth . getConfig('HTTP_EOL');
} // END - if
// Taken from www.php.net eregi() user comments
function isEmailValid ($email) {
- // Compile email
- $email = compileCode($email);
-
// Check first part of email address
$first = '[-a-z0-9!#$%&\'*+/=?^_<{|}~]+(\.[-a-zA-Z0-9!#$%&\'*+/=?^_<{|}~]+)*';
function isUrlValid ($URL, $compile=true) {
// Trim URL a little
$URL = trim(urldecode($URL));
- //* DEBUG: */ outputHtml($URL."<br />");
+ //* DEBUG: */ outputHtml($URL.'<br />');
// Compile some chars out...
if ($compile === true) $URL = compileUriCode($URL, false, false, false);
- //* DEBUG: */ outputHtml($URL."<br />");
+ //* DEBUG: */ outputHtml($URL.'<br />');
// Check for the extension filter
if (isExtensionActive('filter')) {
// Generate a hash for extra-security for all passwords
function generateHash ($plainText, $salt = '') {
// Is the required extension 'sql_patches' there and a salt is not given?
- if (((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) || (!isExtensionActive('sql_patches'))) && (empty($salt))) {
+ if (((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) || (!isExtensionActive('sql_patches')) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) && (empty($salt))) {
// Extension sql_patches is missing/outdated so we hash the plain text with MD5
return md5($plainText);
} // END - if
//* DEBUG: */ outputHtml($salt." (".strlen($salt).")<br />");
} else {
// Use given salt
+ //* DEBUG: */ print 'salt=' . $salt . '<br />';
$salt = substr($salt, 0, getConfig('salt_length'));
- //* DEBUG: */ outputHtml("GIVEN={$salt}<br />");
+ //* DEBUG: */ print 'salt=' . $salt . '(' . strlen($salt) . '/' . getConfig('salt_length') . ')<br />';
+
+ // Sanity check on salt
+ if (strlen($salt) != getConfig('salt_length')) {
+ // Not the same!
+ debug_report_bug(__FUNCTION__.': salt length mismatch! ('.strlen($salt).'/'.getConfig('salt_length').')');
+ } // END - if
}
// Return hash
$ret = $passHash;
// Is a secret key and master salt already initialized?
- if ((isExtensionInstalled('sql_patches')) && (isConfigEntrySet('secret_key')) && (isConfigEntrySet('master_salt'))) {
+ if ((isExtensionInstalled('sql_patches')) && (isExtensionInstalledAndNewer('other', '0.2.5')) && (isConfigEntrySet('_PRIME')) && (isConfigEntrySet('secret_key')) && (isConfigEntrySet('master_salt'))) {
// Only calculate when the secret key is generated
$newHash = ''; $start = 9;
for ($idx = 0; $idx < 10; $idx++) {
} elseif ($part2 > $part1) {
$mod = dechex(sqrt(($part2 - $part1) * getConfig('_PRIME') / pi()));
}
- $mod = substr(round($mod), 0, 4);
- $mod = str_repeat(0, 4-strlen($mod)) . $mod;
- //* DEBUG: */ outputHtml("*" . $start.'=' . $mod."*<br />");
+ $mod = substr($mod, 0, 4);
+ //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'/mod=' . $mod . '('.strlen($mod).')<br />');
+ $mod = str_repeat(0, (4 - strlen($mod))) . $mod;
+ //* DEBUG: */ outputHtml('*' . $start . '=' . $mod . '*<br />');
$start += 4;
$newHash .= $mod;
} // END - for
- //* DEBUG: */ print($passHash."<br />" . $newHash." (".strlen($newHash).')');
+ //* DEBUG: */ print($passHash.'<br />' . $newHash." (".strlen($newHash).')<br />');
$ret = generateHash($newHash, getConfig('master_salt'));
- //* DEBUG: */ print($ret."<br />");
+ //* DEBUG: */ print('ret='.$ret.'<br />');
} else {
// Hash it simple
//* DEBUG: */ outputHtml("--" . $passHash."--<br />");
}
// Generates an error code from given account status
-function generateErrorCodeFromUserStatus ($status) {
- // @TODO The status should never be empty
- if (empty($status)) {
- // Something really bad happend here
- debug_report_bug(__FUNCTION__ . ': status is empty.');
+function generateErrorCodeFromUserStatus ($status='') {
+ // If no status is provided, use the default, cached
+ if ((empty($status)) && (isMember())) {
+ // Get user status
+ $status = getUserData('status');
} // END - if
// Default error code if unknown account status
// Function to search for the last modifified file
function searchDirsRecursive ($dir, &$last_changed) {
// Get dir as array
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=" . $dir."<br />");
+ //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=" . $dir.'<br />');
// 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|debug\.log|\.cache|config\.php)$@';
$ds = getArrayFromDirectory($dir, '', true, false, array(), '.php', $excludePattern);
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds)."<br />");
+ //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds).'<br />');
// Walk through all entries
foreach ($ds as $d) {
// $FQFN is a directory so also crawl into this directory
$newDir = $d;
if (!empty($dir)) $newDir = $dir . '/'. $d;
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):DESCENT: " . $newDir."<br />");
+ //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):DESCENT: " . $newDir.'<br />');
searchDirsRecursive($newDir, $last_changed);
} elseif (isFileReadable($FQFN)) {
// $FQFN is a filename and no directory
return $message;
}
-// Generate a "link" for the given admin id (admin_id)
-function generateAdminLink ($adminId) {
- // No assigned admin is default
- $admin = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
-
- // Zero? = Not assigned
- if (bigintval($adminId) > 0) {
- // Load admin's login
- $login = getAdminLogin($adminId);
-
- // Is the login valid?
- if ($login != '***') {
- // Is the extension there?
- if (isExtensionActive('admins')) {
- // Admin found
- $admin = "<a href=\"".generateEmailLink(getAdminEmail($adminId), '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'), $adminId)."</div>";
- }
- } // END - if
-
- // Return result
- return $admin;
-}
-
// Compile characters which are allowed in URLs
function compileUriCode ($code, $simple = true) {
// Compile constants
// Function taken from user comments on www.php.net / function eregi()
function isUrlValidSimple ($url) {
// Prepare URL
- $url = secureString(str_replace("\\", '', compileCode(urldecode($url))));
+ $url = secureString(str_replace("\\", '', compileRawCode(urldecode($url))));
// Allows http and https
$http = "(http|https)+(:\/\/)";
// @TODO Are these convertions still required?
$pat = str_replace('.', "\.", $pat);
$pat = str_replace('@', "\@", $pat);
- //* DEBUG: */ outputHtml($key."= " . $pat . "<br />");
+ //* DEBUG: */ outputHtml($key."= " . $pat . '<br />');
} // END - if
// Check if expression matches
}
// Send notification to admin
function sendAdminNotification ($subject, $templateName, $content=array(), $userid = 0) {
- if (getExtensionVersion('admins') >= '0.4.1') {
+ if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
// Send new way
sendAdminsEmails($subject, $templateName, $content, $userid);
} else {
// 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");
+ fwrite($fp, date('d.m.Y|H:i:s', time()) . '|' . getModule(false) . '|' . basename($funcFile) . '|' . $line . '|' . $message . "\n");
fclose($fp);
} // END - if
}
// Converts timestamp selections into a timestamp
function convertSelectionsToTimestamp (&$postData, &$DATA, &$id, &$skip) {
// Init test variable
+ $skip = false;
$test2 = '';
// Get last three chars
if ((isset($postData[$test.'_ye'])) && (isset($postData[$test.'_mo'])) && (isset($postData[$test.'_we'])) && (isset($postData[$test.'_da'])) && (isset($postData[$test.'_ho'])) && (isset($postData[$test.'_mi'])) && (isset($postData[$test.'_se'])) && ($test != $test2)) {
// Generate timestamp
$postData[$test] = createTimestampFromSelections($test, $postData);
- $DATA[] = sprintf("%s='%s'", $test, $postData[$test]);
+ $DATA[] = sprintf("`%s`='%s'", $test, $postData[$test]);
+ $GLOBALS['skip_config'][$test] = true;
// Remove data from array
foreach (array('ye', 'mo', 'we', 'da', 'ho', 'mi', 'se') as $rem) {
- unset($postData[$test.'_' . $rem]);
+ unset($postData[$test . '_' . $rem]);
} // END - foreach
// Skip adding
- unset($id); $skip = true; $test2 = $test;
+ unset($id);
+ $skip = true;
+ $test2 = $test;
} // END - if
- } else {
- // Process this entry
- $skip = false;
- $test2 = '';
- }
+ } // END - if
}
// Reverts the german decimal comma into Computer decimal dot
// Determines referal id and sets it
function determineReferalId () {
- // Skip this in non-html-mode
- if (getOutputMode() != 0) return false;
+ // Skip this in non-html-mode and outside ref.php
+ if ((getOutputMode() != 0) && (basename($_SERVER['PHP_SELF']) != 'ref.php')) return false;
// Check if refid is set
if ((isset($GLOBALS['refid'])) && ($GLOBALS['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
+ // No default id when sql_patches is not installed or none set
$GLOBALS['refid'] = 0;
}
// Set cookie when default refid > 0
if (!isSessionVariableSet('refid') || (!empty($GLOBALS['refid'])) || ((getSession('refid') == 0) && (isConfigEntrySet('def_refid')) && (getConfig('def_refid') > 0))) {
+ // Default is not found
+ $found = false;
+
+ // Do we have nickname or userid set?
+ if (isNicknameUsed($GLOBALS['refid'])) {
+ // Nickname in URL, so load the id
+ $found = fetchUserData($GLOBALS['refid'], 'nickname');
+ } elseif ($GLOBALS['refid'] > 0) {
+ // Direct userid entered
+ $found = fetchUserData($GLOBALS['refid']);
+ }
+
+ // Is the record valid?
+ if (($found === false) || (!isUserDataValid())) {
+ // No, then reset referal id
+ $GLOBALS['refid'] = getConfig('def_refid');
+ } // END - if
+
// Set cookie
setSession('refid', $GLOBALS['refid']);
} // END - if
exit;
}
-// Setter for userid
-function setUserId ($userid) {
- $GLOBALS['userid'] = bigintval($userid);
+// Init member id
+function initMemberId () {
+ $GLOBALS['member_id'] = 0;
+}
+
+// Setter for member id
+function setMemberId ($memberid) {
+ // We should not set member id to zero
+ if ($memberid == 0) debug_report_bug('Userid should not be set zero.');
+
+ // Set it secured
+ $GLOBALS['member_id'] = bigintval($memberid);
}
-// Getter for userid or returns zero
-function getUserId () {
- // Default userid
- $userid = 0;
+// Getter for member id or returns zero
+function getMemberId () {
+ // Default member id
+ $memberid = 0;
- // Is the userid set?
- if (isUserIdSet()) {
+ // Is the member id set?
+ if (isMemberIdSet()) {
// Then use it
- $userid = $GLOBALS['userid'];
+ $memberid = $GLOBALS['member_id'];
} // END - if
// Return it
- return $userid;
+ return $memberid;
}
-// Checks ether the userid is set
-function isUserIdSet () {
- return (isset($GLOBALS['userid']));
+// Checks ether the member id is set
+function isMemberIdSet () {
+ return (isset($GLOBALS['member_id']));
}
// Handle message codes from URL
// Exclude '.', '..' and entries in $excludeArray automatically
if (in_array($baseFile, $excludeArray, true)) {
// Exclude them
- //* DEBUG: */ outputHtml('excluded=' . $baseFile . "<br />");
+ //* DEBUG: */ outputHtml('excluded=' . $baseFile . '<br />');
continue;
} // END - if
// 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: */ outputHtml('baseDir:' . $baseDir . "<br />");
- //* DEBUG: */ outputHtml('baseFile:' . $baseFile . "<br />");
- //* DEBUG: */ outputHtml('FQFN:' . $FQFN . "<br />");
+ //* DEBUG: */ outputHtml('baseDir:' . $baseDir . '<br />');
+ //* DEBUG: */ outputHtml('baseFile:' . $baseFile . '<br />');
+ //* DEBUG: */ outputHtml('FQFN:' . $FQFN . '<br />');
// Exclude this one
continue;
return str_replace(';', ', ', $old);
}
+// Determines the right page title
+function determinePageTitle () {
+ // Config and database connection valid?
+ if ((isConfigLocalLoaded()) && (isConfigurationLoaded()) && (SQL_IS_LINK_UP()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
+ // Init title
+ $TITLE = '';
+
+ // Title decoration enabled?
+ if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_left') != '')) $TITLE .= trim(getConfig('title_left'))." ";
+
+ // Do we have some extra title?
+ if (isExtraTitleSet()) {
+ // Then prepent it
+ $TITLE .= getExtraTitle() . ' by ';
+ } // END - if
+
+ // Add main title
+ $TITLE .= getConfig('MAIN_TITLE');
+
+ // Add title of module? (middle decoration will also be added!)
+ if ((getConfig('enable_mod_title') == 'Y') || ((!isWhatSet()) && (!isActionSet())) || (getModule() == 'admin')) {
+ $TITLE .= ' ' . trim(getConfig('title_middle')) . ' ' . getModuleTitle(getModule());
+ } // END - if
+
+ // Add title from what file
+ $mode = '';
+ if (getModule() == 'login') $mode = 'member';
+ elseif (getModule() == 'index') $mode = 'guest';
+ if ((!empty($mode)) && (getConfig('enable_what_title') == 'Y')) $TITLE .= " ".trim(getConfig('title_middle'))." ".getModuleDescription($mode, getWhat());
+
+ // Add title decorations? (right)
+ if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_right') != '')) $TITLE .= " ".trim(getConfig('title_right'));
+
+ // Remember title in constant for the template
+ $pageTitle = $TITLE;
+ } elseif ((isInstalled()) && (isAdminRegistered())) {
+ // Installed, admin registered but no ext-sql_patches
+ $pageTitle = '[-- ' . getConfig('MAIN_TITLE').' - '.getModuleTitle(getModule()) . ' --]';
+ } elseif ((isInstalled()) && (!isAdminRegistered())) {
+ // Installed but no admin registered
+ $pageTitle = sprintf(getMessage('SETUP_OF_MXCHANGE'), getConfig('MAIN_TITLE'));
+ } elseif ((!isInstalled()) || (!isAdminRegistered())) {
+ // Installation mode
+ $pageTitle = getMessage('INSTALLATION_OF_MXCHANGE');
+ } else {
+ // Configuration not found!
+ $pageTitle = getMessage('NO_CONFIG_FOUND_TITLE');
+
+ // Do not add the fatal message in installation mode
+ if ((!isInstalling()) && (!isConfigurationLoaded())) addFatalMessage(__FILE__, __LINE__, getMessage('NO_CONFIG_FOUND'));
+ }
+
+ // Return title
+ return $pageTitle;
+}
+
+// Checks wethere there is a cache file there. This function is cached.
+function isTemplateCached ($template) {
+ // Do we have cached this result?
+ if (!isset($GLOBALS['template_cache'][$template])) {
+ // Generate FQFN
+ $FQFN = sprintf("%s_compiled/templates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+
+ // Is it there?
+ $GLOBALS['template_cache'][$template] = isFileReadable($FQFN);
+ } // END - if
+
+ // Return it
+ return $GLOBALS['template_cache'][$template];
+}
+
+// Flushes non-flushed template cache to disk
+function flushTemplateCache ($template, $eval) {
+ // Is this cache flushed?
+ if ((!isTemplateCached($template)) && ($eval != '404')) {
+ // Generate FQFN
+ $FQFN = sprintf("%s_compiled/templates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+
+ // Replace username with a call
+ $eval = str_replace('$username', '".getUsername()."', $eval);
+
+ // And flush it
+ writeToFile($FQFN, $eval, true);
+ } // END - if
+}
+
+// Reads a template cache
+function readTemplateCache ($template) {
+ // Check it again
+ if (isTemplateCached($template)) {
+ // Generate FQFN
+ $FQFN = sprintf("%s_compiled/templates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+
+ // And read from it
+ $GLOBALS['template_eval'][$template] = readFromFile($FQFN);
+ } // END - if
+
+ // And return it
+ return $GLOBALS['template_eval'][$template];
+}
+
//////////////////////////////////////////////////
// AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
//////////////////////////////////////////////////