* svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
// Output HTML code directly or 'render' it. You addionally switch the new-line character off
function outputHtml ($htmlCode, $newLine = true) {
// Init output
- if (!isset($GLOBALS['output'])) $GLOBALS['output'] = '';
+ if (!isset($GLOBALS['output'])) {
+ $GLOBALS['output'] = '';
+ } // END - if
// Transfer username
$username = getMessage('USERNAME_UNKNOWN');
$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
// 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 '<pre>'.htmlentities($GLOBALS['output']).'</pre>';
+ $eval = '$newContent = "' . compileCode(escapeQuotes($GLOBALS['output'])) . '";';
+ //* DEBUG: */ die('<pre>'.htmlentities($eval).'</pre>');
eval($eval);
// Was that eval okay?
// Something went wrong!
debug_report_bug('Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
} // END - if
+
+ // Use it again
$GLOBALS['output'] = $newContent;
// Count round
} // END - if
// Load user's data
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):UID={$userid},template={$template},content[]=".gettype($content).'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UID={$userid},template={$template},content[]=".gettype($content).'<br />');
if (($userid > 0) && (is_array($content))) {
// If nickname extension is installed, fetch nickname as well
if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):NICKNAME!<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NICKNAME!<br />");
// Load by nickname
fetchUserData($userid, 'nickname');
} else {
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):NO-NICK!<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NO-NICK!<br />");
/// Load by userid
fetchUserData($userid);
}
// Merge data if valid
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):content()=".count($content)." - PRE<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - PRE<br />");
if (isUserDataValid()) {
$content = merge_array($content, getUserDataArray());
} // END - if
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):content()=".count($content)." - AFTER<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - AFTER<br />");
} // END - if
// Translate M to male or F to female if present
// Overwrite email from data if present
if (isset($content['email'])) $email = $content['email'];
- // Store email for some functions in global data array
+ // Store email for some functions in global $DATA array
// @TODO Do only use $content, not $DATA or raw variables
$DATA['email'] = $email;
$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!
// Send mail out to an email address
function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '') {
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):TO={$toEmail},SUBJECT={$subject}<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail},SUBJECT={$subject}<br />");
// Compile subject line (for POINTS constant etc.)
- eval("\$subject = decodeEntities(\"".compileRawCode(escapeQuotes($subject))."\");");
+ eval('$subject = decodeEntities("' . compileRawCode(escapeQuotes($subject)) . '");');
// Set from header
- if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
+ if ((!isInStringIgnoreCase('@', $toEmail)) && ($toEmail > 0)) {
// Value detected, is the message extension installed?
// @TODO Extension 'msg' does not exist
if (isExtensionActive('msg')) {
// Is the webmaster!
$toEmail = getConfig('WEBMASTER');
}
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):TO={$toEmail}<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail}<br />");
// Check for PHPMailer or debug-mode
if (!checkPhpMailerUsage()) {
}
// 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';
</pre>');
} elseif (($isHtml == 'Y') && (isExtensionActive('html_mail'))) {
// Send mail as HTML away
- sendHtmlEmail($toEmail, $subject, $message, $mailHeader);
+ return sendHtmlEmail($toEmail, $subject, $message, $mailHeader);
} elseif (!empty($toEmail)) {
// Send Mail away
- sendRawEmail($toEmail, $subject, $message, $mailHeader);
+ return sendRawEmail($toEmail, $subject, $message, $mailHeader);
} elseif ($isHtml != 'Y') {
// Problem found!
- sendRawEmail(getConfig('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
+ return sendRawEmail(getConfig('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
}
}
$mail = new PHPMailer();
// Set charset to UTF-8
- $mail->CharSet('UTF-8');
+ $mail->CharSet = 'UTF-8';
// Path for PHPMailer
$mail->PluginDir = sprintf("%sinc/phpmailer/", getConfig('PATH'));
$mail->AddCustomHeader('Errors-To:' . getConfig('WEBMASTER'));
$mail->AddCustomHeader('X-Loop:' . getConfig('WEBMASTER'));
$mail->Send();
+
+ // Has an error occured?
+ if (!empty($mail->ErrorInfo)) {
+ // Log message
+ logDebugMessage(__FUNCTION__, __LINE__, 'Error while sending mail: ' . $mail->ErrorInfo);
+
+ // Raise an error
+ return false;
+ } else {
+ // All fine!
+ return true;
+ }
} else {
// Use legacy mail() command
- mail($toEmail, $subject, decodeEntities($message), $from);
+ return mail($toEmail, $subject, decodeEntities($message), $from);
}
}
// 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);
$test = substr($found, 0, strlen($match));
// Does this entry exist?
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):found={$found},match={$match},set={$set}<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "found={$found},match={$match},set={$set}<br />");
if ($test == $match) {
// Match found!
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):fuzzyFound!<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "fuzzyFound!<br />");
$fuzzyFound = true;
break;
} // END - if
// Take all string elements
if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_" . $matches[4][$key]]))) {
// Replace it in the code
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):key={$key},match={$match}<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "key={$key},match={$match}<br />");
$newMatch = str_replace('[', "['", str_replace(']', "']", $match));
$code = str_replace($match, '".' . $newMatch . '."', $code);
$matchesFound[$key . '_' . $matches[4][$key]] = 1;
$matchesFound[$match] = 1;
} elseif (!isset($matchesFound[$match])) {
// Not yet replaced!
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):match={$match}<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "match={$match}<br />");
$code = str_replace($match, '".' . $match . '."', $code);
$matchesFound[$match] = 1;
}
if ($type == 'yn') {
// This is a yes/no selection only!
- if ($id > 0) $prefix .= "[" . $id."]";
- $OUT .= " <select name=\"" . $prefix."\" class=\"" . $class . "\" size=\"1\">\n";
+ if ($id > 0) $prefix .= '[' . $id . ']';
+ $OUT .= '<select name="' . $prefix . '" class="' . $class . '" size="1">';
} 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=\"" . $class . "\" size=\"1\">\n";
+ if ($id > 0) $type2 .= '[' . $id . ']';
+ $OUT .= '<select name="' . strtolower($prefix . $type2) . '" class="' . $class . '" size="1">';
}
switch ($type) {
case 'day': // Day
for ($idx = 1; $idx < 32; $idx++) {
- $OUT .= "<option value=\"" . $idx."\"";
+ $OUT .= '<option value="' . $idx . '"';
if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
+ $OUT .= '>' . $idx . '</option>';
} // END - for
break;
case 'month': // Month
- foreach ($GLOBALS['month_descr'] as $month => $descr) {
- $OUT .= "<option value=\"" . $month."\"";
- if ($default == $month) $OUT .= ' selected="selected"';
- $OUT .= ">" . $descr."</option>\n";
+ foreach ($GLOBALS['month_descr'] as $idx => $descr) {
+ $OUT .= '<option value="' . $idx . '"';
+ if ($default == $idx) $OUT .= ' selected="selected"';
+ $OUT .= '>' . $descr . '</option>';
} // END - for
break;
$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 {
// Check if the default value is larger than minimum and bigger than actual year
if (($default > $minYear) && ($default >= $year)) {
for ($idx = $year; $idx < ($year + 11); $idx++) {
- $OUT .= "<option value=\"" . $idx."\"";
+ $OUT .= '<option value="' . $idx . '"';
if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
+ $OUT .= '>' . $idx . '</option>';
} // END - for
} elseif ($default == -1) {
// Current year minus 1
- for ($idx = $startYear; $idx <= ($year + 1); $idx++)
- {
- $OUT .= "<option value=\"" . $idx."\">" . $idx."</option>\n";
- }
+ for ($idx = $startYear; $idx <= ($year + 1); $idx++) {
+ $OUT .= '<option value="' . $idx . '">' . $idx . '</option>';
+ } // END - for
} else {
// Get current year and subtract the configured minimum age
- $OUT .= "<option value=\"".($minYear - 1)."\"><" . $minYear."</option>\n";
+ $OUT .= '<option value="' . ($minYear - 1) . '"><' . $minYear . '</option>';
// 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 {
// Construct year selection list
for ($idx = $minYear; $idx <= $year; $idx++) {
- $OUT .= "<option value=\"" . $idx."\"";
+ $OUT .= '<option value="' . $idx . '"';
if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
+ $OUT .= '>' . $idx . '</option>';
} // END - for
}
break;
case 'sec':
case 'min':
- for ($idx = '0'; $idx < 60; $idx+=5) {
+ for ($idx = 0; $idx < 60; $idx+=5) {
if (strlen($idx) == 1) $idx = '0' . $idx;
- $OUT .= "<option value=\"" . $idx."\"";
+ $OUT .= '<option value="' . $idx . '"';
if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
+ $OUT .= '>' . $idx . '</option>';
} // END - for
break;
case 'hour':
- for ($idx = '0'; $idx < 24; $idx++) {
+ for ($idx = 0; $idx < 24; $idx++) {
if (strlen($idx) == 1) $idx = '0' . $idx;
- $OUT .= "<option value=\"" . $idx."\"";
+ $OUT .= '<option value="' . $idx . '"';
if ($default == $idx) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
+ $OUT .= '>' . $idx . '</option>';
} // END - for
break;
case 'yn':
- $OUT .= "<option value=\"Y\"";
+ $OUT .= '<option value="Y"';
if ($default == 'Y') $OUT .= ' selected="selected"';
- $OUT .= ">{--YES--}</option>\n<option value=\"N\"";
+ $OUT .= '>{--YES--}</option><option value="N"';
if ($default != 'Y') $OUT .= ' selected="selected"';
- $OUT .= ">{--NO--}</option>\n";
+ $OUT .= '>{--NO--}</option>';
break;
}
- $OUT .= " </select>\n";
+ $OUT .= '</select>';
return $OUT;
}
//
function generateRandomCode ($length, $code, $userid, $DATA = '') {
// Build server string
- $server = $_SERVER['PHP_SELF'] . getConfig('ENCRYPT_SEPERATOR') . detectUserAgent() . getConfig('ENCRYPT_SEPERATOR') . getenv('SERVER_SOFTWARE') . getConfig('ENCRYPT_SEPERATOR') . detectRemoteAddr().":'.':".filemtime(getConfig('PATH').'inc/databases.php');
+ $server = $_SERVER['PHP_SELF'] . getConfig('ENCRYPT_SEPERATOR') . detectUserAgent() . getConfig('ENCRYPT_SEPERATOR') . getenv('SERVER_SOFTWARE') . getConfig('ENCRYPT_SEPERATOR') . detectRemoteAddr();
// Build key string
$keys = getConfig('SITE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY');
}
// Does only allow numbers
-function bigintval ($num, $castValue = true) {
+function bigintval ($num, $castValue = true, $abortOnMismatch = true) {
// Filter all numbers out
$ret = preg_replace('/[^0123456789]/', '', $num);
if ($castValue === true) $ret = (double)$ret;
// Has the whole value changed?
- if ('' . $ret . '' != '' . $num . '') {
+ if (('' . $ret . '' != '' . $num . '') && ($abortOnMismatch === true)) {
// Log the values
debug_report_bug('Problem with number found. ret=' . $ret . ', num='. $num);
} // END - if
debug_report_bug('img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
} elseif ($headerSent === false) {
// Return an HTML code here
- return "<img src=\"{%url=img.php?code=" . $img_code."%}\" alt=\"Image\" />\n";
+ return '<img src="{%url=img.php?code=' . $img_code . '%}" alt="Image" />';
}
// Load image
// Is it readable?
if (isFileReadable($img)) {
// Switch image type
- switch (getConfig('img_type'))
- {
+ switch (getConfig('img_type')) {
case 'jpg':
// Okay, load image and hide all errors
$image = imagecreatefromjpeg($img);
// Okay, load image and hide all errors
$image = imagecreatefrompng($img);
break;
- }
+ } // END - switch
} else {
// Exit function here
logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image type %s not found.", getConfig('img_type')));
switch (getConfig('img_type')) {
case 'jpg': imagejpeg($image); break;
case 'png': imagepng($image); break;
- }
+ } // END - switch
// Remove image from memory
imagedestroy($image);
);
} else {
// Generate table
- $OUT = "<div align=\"" . $align."\">\n";
- $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"timebox_table dashed\">\n";
- $OUT .= "<tr>\n";
+ $OUT = '<div align="' . $align . '">';
+ $OUT .= '<table border="0" cellspacing="0" cellpadding="0" class="timebox_table dashed">';
+ $OUT .= '<tr>';
- if (ereg('Y', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_YEARS--}</strong></td>\n";
- }
+ if (isInString('Y', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_YEARS--}</strong></td>';
+ } // END - if
- if (ereg('M', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MONTHS--}</strong></td>\n";
- }
+ if (isInString('M', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MONTHS--}</strong></td>';
+ } // END - if
- if (ereg('W', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_WEEKS--}</strong></td>\n";
- }
+ if (isInString('W', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_WEEKS--}</strong></td>';
+ } // END - if
- if (ereg('D', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_DAYS--}</strong></td>\n";
- }
+ if (isInString('D', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_DAYS--}</strong></td>';
+ } // END - if
- if (ereg('h', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_HOURS--}</strong></td>\n";
- }
+ if (isInString('h', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_HOURS--}</strong></td>';
+ } // END - if
- if (ereg('m', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MINUTES--}</strong></td>\n";
- }
+ if (isInString('m', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MINUTES--}</strong></td>';
+ } // END - if
- if (ereg('s', $display) || (empty($display))) {
- $OUT .= " <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_SECONDS--}</strong></td>\n";
- }
+ if (isInString('s', $display) || (empty($display))) {
+ $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_SECONDS--}</strong></td>';
+ } // END - if
- $OUT .= "</tr>\n";
- $OUT .= "<tr>\n";
+ $OUT .= '</tr>';
+ $OUT .= '<tr>';
- if (ereg('Y', $display) || (empty($display))) {
+ if (isInString('Y', $display) || (empty($display))) {
// Generate year selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_ye\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 10; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_ye" size="1">';
+ for ($idx = 0; $idx <= 10; $idx++) {
+ $OUT .= '<option class="mini_select" value="' . $idx . '"';
if ($idx == $Y) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_ye" value="0" />';
}
- if (ereg('M', $display) || (empty($display))) {
+ if (isInString('M', $display) || (empty($display))) {
// Generate month selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_mo\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 11; $idx++)
- {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_mo" size="1">';
+ for ($idx = 0; $idx <= 11; $idx++) {
+ $OUT .= ' <option class="mini_select" value="' . $idx . '"';
if ($idx == $M) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_mo" value="0" />';
}
- if (ereg('W', $display) || (empty($display))) {
+ if (isInString('W', $display) || (empty($display))) {
// Generate week selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_we\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 4; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_we" size="1">';
+ for ($idx = 0; $idx <= 4; $idx++) {
+ $OUT .= ' <option class="mini_select" value="' . $idx . '"';
if ($idx == $W) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_we" value="0" />';
}
- if (ereg('D', $display) || (empty($display))) {
+ if (isInString('D', $display) || (empty($display))) {
// Generate day selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_da\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 31; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_da" size="1">';
+ for ($idx = 0; $idx <= 31; $idx++) {
+ $OUT .= ' <option class="mini_select" value="' . $idx . '"';
if ($idx == $D) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_da" value="0" />';
}
- if (ereg('h', $display) || (empty($display))) {
+ if (isInString('h', $display) || (empty($display))) {
// Generate hour selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_ho\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 23; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_ho" size="1">';
+ for ($idx = 0; $idx <= 23; $idx++) {
+ $OUT .= ' <option class="mini_select" value="' . $idx . '"';
if ($idx == $h) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_ho" value="0" />';
}
- if (ereg('m', $display) || (empty($display))) {
+ if (isInString('m', $display) || (empty($display))) {
// Generate minute selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_mi\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 59; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_mi" size="1">';
+ for ($idx = 0; $idx <= 59; $idx++) {
+ $OUT .= ' <option class="mini_select" value="' . $idx . '"';
if ($idx == $m) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_mi" value="0" />';
}
- if (ereg('s', $display) || (empty($display))) {
+ if (isInString('s', $display) || (empty($display))) {
// Generate second selection
- $OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_se\" size=\"1\">\n";
- for ($idx = '0'; $idx <= 59; $idx++) {
- $OUT .= " <option class=\"mini_select\" value=\"" . $idx."\"";
+ $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_se" size="1">';
+ for ($idx = 0; $idx <= 59; $idx++) {
+ $OUT .= ' <option class="mini_select" value="' . $idx . '"';
if ($idx == $s) $OUT .= ' selected="selected"';
- $OUT .= ">" . $idx."</option>\n";
- }
- $OUT .= " </select></td>\n";
+ $OUT .= '>' . $idx . '</option>';
+ } // END - for
+ $OUT .= '</select></td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_se" value="0" />';
}
- $OUT .= "</tr>\n";
- $OUT .= "</table>\n";
- $OUT .= "</div>\n";
- // Return generated HTML code
+ $OUT .= '</tr>';
+ $OUT .= '</table>';
+ $OUT .= '</div>';
}
+
+ // Return generated HTML code
return $OUT;
}
$SWITCH = '0';
$TEST = date('Y', time()) / 4;
$M1 = date('m', time());
+
// If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
if ((floor($TEST) == $TEST) && ($M1 == '02') && ($postData[$prefix . '_mo'] > '02')) $SWITCH = getConfig('ONE_DAY');
+
// First add years...
$ret += $postData[$prefix . '_ye'] * (31536000 + $SWITCH);
+
// Next months...
$ret += $postData[$prefix . '_mo'] * 2628000;
+
// Next weeks
$ret += $postData[$prefix . '_we'] * 604800;
+
// Next days...
$ret += $postData[$prefix . '_da'] * 86400;
+
// Next hours...
$ret += $postData[$prefix . '_ho'] * 3600;
+
// Next minutes..
$ret += $postData[$prefix . '_mi'] * 60;
+
// And at last seconds...
$ret += $postData[$prefix . '_se'];
+
// Return calculated value
return $ret;
}
foreach($data as $k => $v) {
if ($v > 0) {
// Value is greater than 0 "eval" data to return string
- eval("\$ret .= \", \".\$v.\" {--_".strtoupper($k)."--}\";");
+ eval('$ret .= ", ".$v." {--_' . strtoupper($k) . '--}";');
break;
} // END - if
} // END - foreach
$ret = substr($ret, 2);
} else {
// Zero seconds
- $ret = "0 {--_SECONDS--}";
+ $ret = '0 {--_SECONDS--}';
}
// Return fancy time string
function addEmailNavigation ($PAGES, $offset, $show_form, $colspan, $return=false) {
$TOP = '';
if ($show_form === false) {
- $TOP = " top";
- }
+ $TOP = ' top';
+ } // END - if
$NAV = '';
for ($page = 1; $page <= $PAGES; $page++) {
// Extract host name
$host = str_replace('http://', '', $url);
- if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/'));
+ if (isInString('/', $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
} 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');
// Extract host name from script
$host = extractHostnameFromUrl($script);
- // Construct request
+ // Construct request body
$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');
+ $request .= 'Accept: text/plain;q=0.8' . getConfig('HTTP_EOL');
+ $request .= 'Accept-Charset: UTF-8,*' . getConfig('HTTP_EOL');
$request .= 'Cache-Control: no-cache' . getConfig('HTTP_EOL');
$request .= 'Content-Type: application/x-www-form-urlencoded' . getConfig('HTTP_EOL');
+ $request .= 'Content-Length: ' . strlen($body) . getConfig('HTTP_EOL');
$request .= 'Connection: close' . getConfig('HTTP_EOL');
$request .= getConfig('HTTP_EOL');
$useProxy = true;
} // END - if
+ // Load include
+ loadIncludeOnce('inc/classes/resolver.class.php');
+
+ // Get resolver instance
+ $resolver = new HostnameResolver();
+
// Open connection
- //* DEBUG: */ die("SCRIPT=" . $script.'<br />');
+ //* DEBUG: */ die('SCRIPT=' . $script.'<br />');
if ($useProxy === true) {
+ // Resolve hostname into IP address
+ $ip = $resolver->resolveHostname(compileRawCode(getConfig('proxy_host')));
+
// Connect to host through proxy connection
- $fp = fsockopen(compileRawCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
+ $fp = fsockopen($ip, bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
} else {
+ // Resolve hostname into IP address
+ $ip = $resolver->resolveHostname($host);
+
// Connect to host directly
- $fp = fsockopen($host, 80, $errno, $errdesc, 30);
+ $fp = fsockopen($ip, 80, $errno, $errdesc, 30);
}
// Is there a link?
// Do we use proxy?
if ($useProxy === true) {
- // Generate CONNECT request header
- $proxyTunnel = 'CONNECT ' . $host . ':80 HTTP/1.1' . getConfig('HTTP_EOL');
- $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL');
-
- // Use login data to proxy? (username at least!)
- if (getConfig('proxy_username') != '') {
- // Add it as well
- $encodedAuth = base64_encode(compileRawCode(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . compileRawCode(getConfig('proxy_password')));
- $proxyTunnel .= 'Proxy-Authorization: Basic ' . $encodedAuth . getConfig('HTTP_EOL');
- } // END - if
-
- // Add last new-line
- $proxyTunnel .= getConfig('HTTP_EOL');
- //* DEBUG: */ print('<strong>proxyTunnel=</strong><pre>' . $proxyTunnel.'</pre>');
-
- // Write request
- fwrite($fp, $proxyTunnel);
-
- // Got response?
- if (feof($fp)) {
- // No response received
- return $response;
- } // END - if
+ // Setup proxy tunnel
+ $response = setupProxyTunnel($host, $fp);
- // Read the first line
- $resp = trim(fgets($fp, 10240));
- $respArray = explode(' ', $resp);
- if ((strtolower($respArray[0]) !== 'http/1.0') || ($respArray[1] != '200')) {
+ // If the response is invalid, abort
+ if ((count($response) == 3) && (empty($response[0])) && (empty($response[1])) && (empty($response[2]))) {
// Invalid response!
+ logDebugMessage(__FUNCTION__, __LINE__, 'Proxy tunnel not working?');
return $response;
} // END - if
} // END - if
// Time request if debug-mode is enabled
if (isDebugModeEnabled()) {
// Add debug message...
- logDebugMessage(__FUNCTION__, __LINE__, 'Request took ' . (microtime(true) - $start) . ' seconds.');
+ logDebugMessage(__FUNCTION__, __LINE__, 'Request took ' . (microtime(true) - $start) . ' seconds and returned ' . count($response) . ' line(s).');
} // END - if
// Skip first empty lines
}
} // END - foreach
+ //* DEBUG: */ print('<strong>Request:</strong><pre>'.print_r($request, true).'</pre>');
//* DEBUG: */ print('<strong>Response:</strong><pre>'.print_r($response, true).'</pre>');
// Proxy agent found or something went wrong?
if (!isset($response[0])) {
// No response, maybe timeout
$response = array('', '', '');
+ logDebugMessage(__FUNCTION__, __LINE__, 'Invalid empty response array, maybe timed out?');
} elseif ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && ($useProxy === true)) {
// Proxy header detected, so remove two lines
array_shift($response);
} // END - if
// Was the request successfull?
- if ((!eregi('200 OK', $response[0])) || (empty($response[0]))) {
+ if ((!isInStringIgnoreCase('200 OK', $response[0])) || (empty($response[0]))) {
// Not found / access forbidden
+ logDebugMessage(__FUNCTION__, __LINE__, 'Unexpected status code ' . $response[0] . ' detected. "200 OK" was expected.');
$response = array('', '', '');
} // END - if
return $response;
}
-// Taken from www.php.net eregi() user comments
+// Sets up a proxy tunnel for given hostname and through resource
+function setupProxyTunnel ($host, $resource) {
+ // Initialize array
+ $response = array('', '', '');
+
+ // Generate CONNECT request header
+ $proxyTunnel = 'CONNECT ' . $host . ':80 HTTP/1.0' . getConfig('HTTP_EOL');
+ $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL');
+
+ // Use login data to proxy? (username at least!)
+ if (getConfig('proxy_username') != '') {
+ // Add it as well
+ $encodedAuth = base64_encode(compileRawCode(getConfig('proxy_username')) . ':' . compileRawCode(getConfig('proxy_password')));
+ $proxyTunnel .= 'Proxy-Authorization: Basic ' . $encodedAuth . getConfig('HTTP_EOL');
+ } // END - if
+
+ // Add last new-line
+ $proxyTunnel .= getConfig('HTTP_EOL');
+ //* DEBUG: */ print('<strong>proxyTunnel=</strong><pre>' . $proxyTunnel.'</pre>');
+
+ // Write request
+ fwrite($fp, $proxyTunnel);
+
+ // Got response?
+ if (feof($fp)) {
+ // No response received
+ return $response;
+ } // END - if
+
+ // Read the first line
+ $resp = trim(fgets($fp, 10240));
+ $respArray = explode(' ', $resp);
+ if ((strtolower($respArray[0]) !== 'http/1.0') || ($respArray[1] != '200')) {
+ // Invalid response!
+ return $response;
+ } // END - if
+
+ // All fine!
+ return $respArray;
+}
+
+// Taken from www.php.net isInStringIgnoreCase() user comments
function isEmailValid ($email) {
// Check first part of email address
$first = '[-a-z0-9!#$%&\'*+/=?^_<{|}~]+(\.[-a-zA-Z0-9!#$%&\'*+/=?^_<{|}~]+)*';
return preg_match($regex, $email);
}
-// Function taken from user comments on www.php.net / function eregi()
+// Function taken from user comments on www.php.net / function isInStringIgnoreCase()
function isUrlValid ($URL, $compile=true) {
// Trim URL a little
$URL = trim(urldecode($URL));
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')) {
// Generate a hash for extra-security for all passwords
function generateHash ($plainText, $salt = '', $hash = true) {
+ // Debug output
+ //* DEBUG: */ outputHtml('plainText=' . $plainText . ',salt=' . $salt . ',hash='.intval($hash).'<br />');
+
// Is the required extension 'sql_patches' there and a salt is not given?
- if (((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) || (!isExtensionActive('sql_patches')) || (!isExtensionInstalledAndNewer('other', '0.2.5'))) && (empty($salt))) {
+ // 0123 4 43 3 4 432 2 3 32 2 3 3210
+ if ((((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) && (empty($salt))) || (!isExtensionActive('sql_patches')) || (!isExtensionInstalledAndNewer('other', '0.2.5')))) {
// Extension sql_patches is missing/outdated so we hash the plain text with MD5
if ($hash === true) {
// Is plain password
// When the salt is empty build a new one, else use the first x configured characters as the salt
if (empty($salt)) {
- // Build server string (inc/databases.php is no longer updated with every commit)
+ // Build server string for more entropy
$server = $_SERVER['PHP_SELF'] . getConfig('ENCRYPT_SEPERATOR') . detectUserAgent() . getConfig('ENCRYPT_SEPERATOR') . getenv('SERVER_SOFTWARE') . getConfig('ENCRYPT_SEPERATOR') . detectRemoteAddr();
// Build key string
//* DEBUG: */ outputHtml($salt.' ('.strlen($salt).')<br />');
} else {
// Use given salt
- //* DEBUG: */ print 'salt=' . $salt . '<br />';
+ //* DEBUG: */ outputHtml('salt=' . $salt . '<br />');
$salt = substr($salt, 0, getConfig('salt_length'));
- //* DEBUG: */ print 'salt=' . $salt . '(' . strlen($salt) . '/' . getConfig('salt_length') . ')<br />';
+ //* DEBUG: */ outputHtml('salt=' . $salt . '(' . strlen($salt) . '/' . getConfig('salt_length') . ')<br />');
// Sanity check on salt
if (strlen($salt) != getConfig('salt_length')) {
} // END - if
}
+ // Generate final hash (for debug output)
+ $finalHash = $salt . sha1($salt . $plainText);
+
+ // Debug output
+ //* DEBUG: */ outputHtml('finalHash=' . $finalHash);
+
// Return hash
- return $salt.sha1($salt . $plainText);
+ return $finalHash;
}
// Scramble a string
// Scramble string here
//* DEBUG: */ outputHtml('***Original=' . $str.'***<br />');
- for ($idx = '0'; $idx < strlen($str); $idx++) {
+ for ($idx = 0; $idx < strlen($str); $idx++) {
// Get char on scrambled position
$char = substr($str, $scrambleNums[$idx], 1);
// Begin descrambling
$orig = str_repeat(' ', 40);
//* DEBUG: */ outputHtml('+++Scrambled=' . $str.'+++<br />');
- for ($idx = '0'; $idx < 40; $idx++) {
+ for ($idx = 0; $idx < 40; $idx++) {
$char = substr($str, $idx, 1);
$orig = substr_replace($orig, $char, $scrambleNums[$idx], 1);
} // END - for
$scrambleNumbers = array();
// First we need to setup randomized numbers from 0 to 31
- for ($idx = '0'; $idx < $len; $idx++) {
+ for ($idx = 0; $idx < $len; $idx++) {
// Generate number
$rand = mt_rand(0, ($len -1));
}
// Generate an PGP-like encrypted hash of given hash for e.g. cookies
-function generatePassString ($passHash) {
+function encodeHashForCookie ($passHash) {
// Return vanilla password hash
$ret = $passHash;
// Is a secret key and master salt already initialized?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, intval(isExtensionInstalled('sql_patches')) . '/' . intval(isConfigEntrySet('_PRIME')) . '/' . intval(isConfigEntrySet('secret_key')) . '/' . intval(isConfigEntrySet('master_salt')));
if ((isExtensionInstalled('sql_patches')) && (isConfigEntrySet('_PRIME')) && (isConfigEntrySet('secret_key')) && (isConfigEntrySet('master_salt'))) {
// Only calculate when the secret key is generated
- if (strlen($passHash) != getConfig('secret_key')) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '/' . strlen(getConfig('secret_key')));
+ if ((strlen($passHash) != 49) || (strlen(getConfig('secret_key')) != 40)) {
// Both keys must have same length so return unencrypted
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '!=49/' . strlen(getConfig('secret_key')) . '!=40');
return $ret;
} // END - if
$newHash = ''; $start = 9;
- //* DEBUG: */ outputHtml('passHash=' . $passHash . '(' . strlen($passHash) . ')<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'passHash=' . $passHash . '(' . strlen($passHash) . ')');
for ($idx = 0; $idx < 20; $idx++) {
- $part1 = hexdec(substr($passHash, ($idx * 2), 2));
+ $part1 = hexdec(substr($passHash, ($idx * 2) + (strlen($passHash) - strlen(getConfig('secret_key'))), 2));
$part2 = hexdec(substr(getConfig('secret_key'), $start, 2));
- //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2);
$mod = dechex($idx);
if ($part1 > $part2) {
$mod = dechex(sqrt(($part1 - $part2) * getConfig('_PRIME') / pi()));
$mod = dechex(sqrt(($part2 - $part1) * getConfig('_PRIME') / pi()));
}
$mod = substr($mod, 0, 2);
- //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'/mod=' . $mod . '('.strlen($mod).')<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')');
$mod = str_repeat(0, (2 - strlen($mod))) . $mod;
- //* DEBUG: */ outputHtml('mod(' . ($idx * 2) . ')=' . $mod . '*<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*');
$start += 2;
$newHash .= $mod;
} // END - for
- //* DEBUG: */ print($passHash . '<br />' . $newHash . ' (' . strlen($newHash) . ')<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $passHash . ',' . $newHash . ' (' . strlen($newHash) . ')');
$ret = generateHash($newHash, getConfig('master_salt'));
- //* DEBUG: */ print('ret=' . $ret . '<br />');
} // END - if
// Return result
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret . '');
return $ret;
}
// Make sure, that the script realy realy diese here and now
$GLOBALS['app_died'] = true;
- // Set content type if not set
- if (!isContentTypeSet()) {
- // text/html is the right one
- setContentType('text/html');
- } // END - if
+ // Set content type as text/html
+ setContentType('text/html');
// Load header
loadIncludeOnce('inc/header.php');
if ($runTime < 0) $runTime = '0';
// Prepare output
+ // @TODO This can be easily moved out after the merge from EL branch to this is complete
$content = array(
- 'runtime' => translateComma($runTime),
- 'timeSQLs' => translateComma(getConfig('sql_time') * 1000),
+ 'run_time' => translateComma($runTime),
+ 'sql_time' => translateComma(getConfig('sql_time') * 1000),
);
// Load the template
return $errorCode;
}
-// 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 />');
- // 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 />');
-
- // Walk through all entries
- foreach ($ds as $d) {
- // Generate proper FQFN
- $FQFN = str_replace('//', '/', getConfig('PATH') . $dir. '/'. $d);
-
- // Is it a file and readable?
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):FQFN={$FQFN}<br />");
- if (isDirectory($FQFN)) {
- // $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 />');
- searchDirsRecursive($newDir, $last_changed);
- } elseif (isFileReadable($FQFN)) {
- // $FQFN is a filename and no directory
- $time = filemtime($FQFN);
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):File: " . $d." found. (".($last_changed['time'] - $time).")<br />");
- if ($last_changed['time'] < $time) {
- // This file is newer as the file before
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>) - NEWER!<br />");
- $last_changed['path_name'] = $FQFN;
- $last_changed['time'] = $time;
- } // END - if
- }
- } // END - foreach
-}
-
-// "Getter" for revision/version data
-function getActualVersion ($type = 'Revision') {
- // By default nothing is new... ;-)
- $new = false;
-
- // Is the cache entry there?
- if (isset($GLOBALS['cache_array']['revision'][$type])) {
- // Found so increase cache hit
- incrementStatsEntry('cache_hits');
-
- // Return it
- return $GLOBALS['cache_array']['revision'][$type][0];
- } else {
- // FQFN of revision file
- $FQFN = sprintf("%s/.revision", getConfig('CACHE_PATH'));
-
- // Check if 'check_revision_data' is setted (switch for manually rewrite the .revision-File)
- if ((isGetRequestParameterSet('check_revision_data')) && (getRequestParameter('check_revision_data') == 'yes')) {
- // Forced rebuild of .revision file
- $new = true;
- } else {
- // Check for revision file
- if (!isFileReadable($FQFN)) {
- // Not found, so we need to create it
- $new = true;
- } else {
- // Revision file found
- $ins_vers = explode("\n", readFromFile($FQFN));
-
- // Get array for mapping information
- $mapper = array_flip(getSearchFor());
- //* DEBUG: */ print('<pre>mapper='.print_r($mapper, true).'</pre>ins_vers=<pre>'.print_r($ins_vers, true).'</pre>');
-
- // Is the content valid?
- if ((!is_array($ins_vers)) || (count($ins_vers) <= 0) || (!isset($ins_vers[$mapper[$type]])) || (trim($ins_vers[$mapper[$type]]) == '') || ($ins_vers[0]) == 'new') {
- // File needs update!
- $new = true;
- } else {
- // Generate fake cache entry
- foreach ($mapper as $map => $idx) {
- $GLOBALS['cache_array']['revision'][$map][0] = $ins_vers[$idx];
- } // END - foreach
-
- // Return found value
- return getActualVersion($type);
- }
- }
- }
-
- // Has it been updated?
- if ($new === true) {
- // Write it
- writeToFile($FQFN, implode("\n", getArrayFromActualVersion()));
-
- // ... and call recursive
- return getActualVersion($type);
- } // END - if
- }
-}
-
-// Repares an array we are looking for
-// The returned Array is needed twice (in getArrayFromActualVersion() and in getActualVersion() in the old .revision-fallback) so I puted it in an extra function to not polute the global namespace
-function getSearchFor () {
- // Add Revision, Date, Tag and Author
- $searchFor = array('File', 'Revision', 'Date', 'Tag', 'Author');
-
- // Return the created array
- return $searchFor;
-}
-
-// @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();
-
- // Save the last-changed filename for debugging
- $GLOBALS['cache_array']['revision']['File'] = $last_changed['path_name'];
-
- // 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 $GLOBALS['cache_array']['revision']-return array
- if (isset($t[2])) {
- $GLOBALS['cache_array']['revision'][$search] = trim($t[2]);
- } // END - if
- } // END - foreach
-
- // at least 3 keyword-Tags are needed for propper values
- if ($res && $res >= 3
- && isset($GLOBALS['cache_array']['revision']['Revision']) && $GLOBALS['cache_array']['revision']['Revision'] != ''
- && isset($GLOBALS['cache_array']['revision']['Date']) && $GLOBALS['cache_array']['revision']['Date'] != ''
- && isset($GLOBALS['cache_array']['revision']['Tag']) && $GLOBALS['cache_array']['revision']['Tag'] != '') {
- // Prepare content witch need special treadment
-
- // Prepare timestamp for date
- preg_match('@(....)-(..)-(..) (..):(..):(..)@', $GLOBALS['cache_array']['revision']['Date'], $match_d);
- $GLOBALS['cache_array']['revision']['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($GLOBALS['cache_array']['revision']['Author'])) && ($GLOBALS['cache_array']['revision']['Author'] != 'quix0r')) {
- $GLOBALS['cache_array']['revision']['Tag'] .= '-'.strtoupper($GLOBALS['cache_array']['revision']['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');
-
- // Invalid request reply?
- if (!isset($version[11])) {
- // Cannot continue here
- debug_report_bug('Invalid response from check-updates3.php, count should be 10, is ' . count($version));
- } // END - if
-
- // Prepare content
- // Only sets not setted or not proper values to the Online-Server-Fallback-Solution
- if (!isset($GLOBALS['cache_array']['revision']['File']) || $GLOBALS['cache_array']['revision']['File'] == '') $GLOBALS['cache_array']['revision']['File'] = trim($version[11]);
- if (!isset($GLOBALS['cache_array']['revision']['Revision']) || $GLOBALS['cache_array']['revision']['Revision'] == '') $GLOBALS['cache_array']['revision']['Revision'] = trim($version[10]);
- if (!isset($GLOBALS['cache_array']['revision']['Date']) || $GLOBALS['cache_array']['revision']['Date'] == '') $GLOBALS['cache_array']['revision']['Date'] = trim($version[9]);
- if (!isset($GLOBALS['cache_array']['revision']['Tag']) || $GLOBALS['cache_array']['revision']['Tag'] == '') $GLOBALS['cache_array']['revision']['Tag'] = trim($version[8]);
- if (!isset($GLOBALS['cache_array']['revision']['Author']) || $GLOBALS['cache_array']['revision']['Author'] == '') $GLOBALS['cache_array']['revision']['Author'] = 'quix0r';
- }
-
- // Return prepared array
- return $GLOBALS['cache_array']['revision'];
-}
-
// Back-ported from the new ship-simu engine. :-)
function debug_get_printable_backtrace () {
// Init variable
case getCode('MORE_RECEIVERS2') : $message = getMessage('MEMBER_NO_MORE_RECEIVERS_FOUND'); break;
case getCode('MORE_RECEIVERS3') : $message = getMessage('MEMBER_ENTER_MORE_MIN_RECEIVERS'); break;
case getCode('INVALID_URL') : $message = getMessage('MEMBER_ENTER_INVALID_URL'); break;
+ case getCode('NO_MAIL_TYPE') : $message = getMessage('MEMBER_NO_MAIL_TYPE_SELECTED'); break;
case getCode('UNKNOWN_ERROR') : $message = getMessage('LOGIN_UNKNOWN_ERROR'); break;
case getCode('UNKNOWN_STATUS') : $message = getMessage('LOGIN_UNKNOWN_STATUS'); break;
return $code;
}
-// Function taken from user comments on www.php.net / function eregi()
+// Function taken from user comments on www.php.net / function isInStringIgnoreCase()
function isUrlValidSimple ($url) {
// Prepare URL
$url = secureString(str_replace("\\", '', compileRawCode(urldecode($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);
} // 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;
}
// Handle menu-depending failed logins and return the rendered content
-function handleLoginFailtures ($accessLevel) {
+function handleLoginFailures ($accessLevel) {
// Default output is empty ;-)
$OUT = '';
// Is the session data set?
- if ((isSessionVariableSet('mxchange_' . $accessLevel.'_failures')) && (isSessionVariableSet('mxchange_' . $accessLevel.'_last_fail'))) {
+ 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: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):accessLevel={$accessLevel}<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "accessLevel={$accessLevel}<br />");
$content = array(
- 'login_failures' => getSession('mxchange_' . $accessLevel.'_failures'),
- 'last_failure' => generateDateTime(getSession('mxchange_' . $accessLevel.'_last_fail'), 2)
+ 'login_failures' => getSession('mailer_' . $accessLevel . '_failures'),
+ 'last_failure' => generateDateTime(getSession('mailer_' . $accessLevel . '_last_failure'), 2)
);
// Load template
} // END - if
// Reset session data
- setSession('mxchange_' . $accessLevel.'_failures', '');
- setSession('mxchange_' . $accessLevel.'_last_fail', '');
+ setSession('mailer_' . $accessLevel . '_failures', '');
+ setSession('mailer_' . $accessLevel . '_last_failure', '');
} // END - if
// Return rendered content
}
// Rebuild cache
-function rebuildCacheFile ($cache, $inc = '', $force = false) {
+function rebuildCache ($cache, $inc = '', $force = false) {
// Debug message
/* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force)));
// Is the include there?
if (isIncludeReadable($inc)) {
// And rebuild it from scratch
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>): inc={$inc} - LOADED!<br />");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "inc={$inc} - LOADED!<br />");
loadInclude($inc);
} else {
// Include not found!
} 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 {
$salt = substr(getSession('u_hash'), 0, -40);
// Now let's compare passwords
- $hash = generatePassString(getUserData('password'));
+ $hash = encodeHashForCookie(getUserData('password'));
// Does the hash match or should we change it?
if (($hash == getSession('u_hash')) || (postRequestParameter('pass1') == postRequestParameter('pass2'))) {
}
// Generates a 'selection box' from given array
-function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionContent) {
+function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionContent='') {
// Start the output
$OUT = '<select name="' . $name . '" size="1" class="admin_select">
<option value="X" disabled="disabled">{--PLEASE_SELECT--}</option>';
// Walk through all options
foreach ($options as $option) {
// Add the <option> entry
- $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
+ if (empty($optionContent)) {
+ // ... from template
+ $OUT .= loadTemplate('select_' . $name . '_option', true, $option);
+ } else {
+ // Direct HTML code
+ $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
+ }
} // END - foreach
// Finish selection box
if (empty($userAgent)) return true;
// Is it a spider?
- return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false));
+ return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false) || (strpos($userAgent, 'archiver') !== false));
}
// Prepares the header for HTML output
function loadHtmlHeader () {
- // Determine the page title
- $content['header_title'] = determinePageTitle();
-
- // Output page header code
- $GLOBALS['page_header'] = loadTemplate('page_header', true, $content);
+ // Run two filters:
+ // 1.) pre_page_header (mainly loads the page_header template and includes
+ // meta description)
+ runFilterChain('pre_page_header');
- // Include meta data in 'guest' module
- if (getModule() == 'index') {
- // Load meta data template
- $GLOBALS['page_header'] .= loadTemplate('metadata', true);
-
- // Add meta description to header
- if ((isInstalled()) && (isAdminRegistered()) && (SQL_IS_LINK_UP())) {
- // Add meta description not in admin and login module and when the script is installed
- generateMetaDescriptionCode();
- } // END - if
- } // END - if
+ // Here can be something be added, but normally one of the two filters
+ // around this line should do the job for you.
+ // 2.) post_page_header (mainly to load stylesheet, extra JavaScripts and
+ // to close the head-tag)
// Include more header data here
- $GLOBALS['page_header'] .= loadTemplate('header', true);
-
- // Include stylesheet
- loadIncludeOnce('inc/stylesheet.php');
-
- // Closing HEAD tag
- $GLOBALS['page_header'] .= '</head>';
+ runFilterChain('post_page_header');
}
// Adds page header and footer to output array element
// Generates meta description for current module and 'what' value
function generateMetaDescriptionCode () {
- // Only include from guest area
- if (getModule() == 'index') {
+ // Only include from guest area and if sql_patches has correct version
+ if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
// Construct dynamic description
- $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat());
+ $DESCR = '{?MAIN_TITLE?} ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat());
// Output it directly
$GLOBALS['page_header'] .= '<meta name="description" content="' . $DESCR . '" />';
return $GLOBALS['template_cache_fqfn'][$template];
}
+// Function to search for the last modified file
+function searchDirsRecursive ($dir, &$last_changed, $lookFor = 'Date') {
+ // Get dir as array
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'dir=' . $dir);
+ // 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|\.svn|debug\.log|\.cache|config\.php)$@';
+
+ $ds = getArrayFromDirectory($dir, '', false, true, array(), '.php', $excludePattern);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count(ds)='.count($ds));
+
+ // Walk through all entries
+ foreach ($ds as $d) {
+ // Generate proper FQFN
+ $FQFN = str_replace('//', '/', getConfig('PATH') . $dir . '/' . $d);
+
+ // Is it a file and readable?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'dir=' . $dir . ',d=' . $d);
+ if (isFileReadable($FQFN)) {
+ // $FQFN is a readable file so extract the requested data from it
+ $check = extractRevisionInfoFromFile($FQFN, $lookFor);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'File: ' . $d . ' found. check=' . $check);
+
+ // Is the file more recent?
+ if ((!isset($last_changed[$lookFor])) || ($last_changed[$lookFor] < $check)) {
+ // This file is newer as the file before
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'NEWER!');
+ $last_changed['path_name'] = $FQFN;
+ $last_changed[$lookFor] = $check;
+ } // END - if
+ } else {
+ // Not readable
+ /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'File: ' . $d . ' not readable or directory.');
+ }
+ } // 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 //
//////////////////////////////////////////////////