--- a/includes/functions.php Sun Mar 28 21:49:26 2010 -0400
+++ b/includes/functions.php Sun Mar 28 23:10:46 2010 -0400
@@ -20,15 +20,15 @@
function getConfig($n, $default = false)
{
- global $enano_config;
- if ( isset( $enano_config[ $n ] ) )
- {
- return $enano_config[$n];
- }
- else
- {
- return $default;
- }
+ global $enano_config;
+ if ( isset( $enano_config[ $n ] ) )
+ {
+ return $enano_config[$n];
+ }
+ else
+ {
+ return $default;
+ }
}
/**
@@ -40,37 +40,37 @@
function setConfig($n, $v)
{
- global $enano_config, $db;
-
- if ( isset($enano_config[$n]) )
- {
- if ( $enano_config[$n] === $v )
- {
- // configuration already matches this value
- return true;
- }
- }
-
- $enano_config[$n] = $v;
- if ( $v === false )
- unset($enano_config[$n]);
-
- $v = $db->escape($v);
-
- $e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';');
- if ( !$e )
- {
- $db->_die('Error during generic setConfig() call row deletion.');
- }
-
- if ( $v !== false )
- {
- $e = $db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')');
- if ( !$e )
- {
- $db->_die('Error during generic setConfig() call row insertion.');
- }
- }
+ global $enano_config, $db;
+
+ if ( isset($enano_config[$n]) )
+ {
+ if ( $enano_config[$n] === $v )
+ {
+ // configuration already matches this value
+ return true;
+ }
+ }
+
+ $enano_config[$n] = $v;
+ if ( $v === false )
+ unset($enano_config[$n]);
+
+ $v = $db->escape($v);
+
+ $e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';');
+ if ( !$e )
+ {
+ $db->_die('Error during generic setConfig() call row deletion.');
+ }
+
+ if ( $v !== false )
+ {
+ $e = $db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')');
+ if ( !$e )
+ {
+ $db->_die('Error during generic setConfig() call row insertion.');
+ }
+ }
}
/**
@@ -83,42 +83,42 @@
if ( !function_exists('makeUrl') )
{
- function makeUrl($t, $query = false, $escape = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- $flags = '';
- $sep = urlSeparator;
- $t = sanitize_page_id($t);
- if ( isset($_GET['printable'] ) )
- {
- $flags .= $sep . 'printable=yes';
- $sep = '&';
- }
- if ( isset($_GET['theme'] ) )
- {
- $flags .= $sep . 'theme='.$session->theme;
- $sep = '&';
- }
- if ( isset($_GET['style'] ) )
- {
- $flags .= $sep . 'style='.$session->style;
- $sep = '&';
- }
- if ( isset($_GET['lang']) && preg_match('/^[a-z0-9_]+$/', @$_GET['lang']) )
- {
- $flags .= $sep . 'lang=' . urlencode($_GET['lang']);
- $sep = '&';
- }
-
- $url = is_object($session) ? $session->append_sid(contentPath.$t.$flags) : contentPath . $t . $flags;
- if($query)
- {
- $sep = strstr($url, '?') ? '&' : '?';
- $url = $url . $sep . $query;
- }
-
- return ($escape) ? htmlspecialchars($url) : $url;
- }
+ function makeUrl($t, $query = false, $escape = false)
+ {
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ $flags = '';
+ $sep = urlSeparator;
+ $t = sanitize_page_id($t);
+ if ( isset($_GET['printable'] ) )
+ {
+ $flags .= $sep . 'printable=yes';
+ $sep = '&';
+ }
+ if ( isset($_GET['theme'] ) )
+ {
+ $flags .= $sep . 'theme='.$session->theme;
+ $sep = '&';
+ }
+ if ( isset($_GET['style'] ) )
+ {
+ $flags .= $sep . 'style='.$session->style;
+ $sep = '&';
+ }
+ if ( isset($_GET['lang']) && preg_match('/^[a-z0-9_]+$/', @$_GET['lang']) )
+ {
+ $flags .= $sep . 'lang=' . urlencode($_GET['lang']);
+ $sep = '&';
+ }
+
+ $url = is_object($session) ? $session->append_sid(contentPath.$t.$flags) : contentPath . $t . $flags;
+ if($query)
+ {
+ $sep = strstr($url, '?') ? '&' : '?';
+ $url = $url . $sep . $query;
+ }
+
+ return ($escape) ? htmlspecialchars($url) : $url;
+ }
}
/**
@@ -132,72 +132,72 @@
if ( !function_exists('makeUrlNS') )
{
- function makeUrlNS($n, $t, $query = false, $escape = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- $flags = '';
-
- if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
- {
- $sep = urlSeparator;
- }
- else
- {
- $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?';
- }
- if ( isset( $_GET['printable'] ) ) {
- $flags .= $sep . 'printable';
- $sep = '&';
- }
- if ( isset( $_GET['theme'] ) )
- {
- $flags .= $sep . 'theme='.$session->theme;
- $sep = '&';
- }
- if ( isset( $_GET['style'] ) )
- {
- $flags .= $sep . 'style='.$session->style;
- $sep = '&';
- }
- if ( isset($_GET['lang']) && preg_match('/^[a-z0-9_]+$/', @$_GET['lang']) )
- {
- $flags .= $sep . 'lang=' . urlencode($_GET['lang']);
- $sep = '&';
- }
-
- $ns_prefix = "$n:";
-
- if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
- {
- $ns_prefix = ( isset($paths->nslist[$n]) ) ? $paths->nslist[$n] : $n . substr($paths->nslist['Special'], -1);
- $url = contentPath . $ns_prefix . $t . $flags;
- }
- else
- {
- // If the path manager hasn't been initted yet, take an educated guess at what the URI should be
- $url = contentPath . $n . ':' . $t . $flags;
- }
-
- if($query)
- {
- if(strstr($url, '?'))
- {
- $sep = '&';
- }
- else
- {
- $sep = '?';
- }
- $url = $url . $sep . $query . $flags;
- }
-
- if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
- {
- $url = $session->append_sid($url);
- }
-
- return ($escape) ? htmlspecialchars($url) : $url;
- }
+ function makeUrlNS($n, $t, $query = false, $escape = false)
+ {
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ $flags = '';
+
+ if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ {
+ $sep = urlSeparator;
+ }
+ else
+ {
+ $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?';
+ }
+ if ( isset( $_GET['printable'] ) ) {
+ $flags .= $sep . 'printable';
+ $sep = '&';
+ }
+ if ( isset( $_GET['theme'] ) )
+ {
+ $flags .= $sep . 'theme='.$session->theme;
+ $sep = '&';
+ }
+ if ( isset( $_GET['style'] ) )
+ {
+ $flags .= $sep . 'style='.$session->style;
+ $sep = '&';
+ }
+ if ( isset($_GET['lang']) && preg_match('/^[a-z0-9_]+$/', @$_GET['lang']) )
+ {
+ $flags .= $sep . 'lang=' . urlencode($_GET['lang']);
+ $sep = '&';
+ }
+
+ $ns_prefix = "$n:";
+
+ if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ {
+ $ns_prefix = ( isset($paths->nslist[$n]) ) ? $paths->nslist[$n] : $n . substr($paths->nslist['Special'], -1);
+ $url = contentPath . $ns_prefix . $t . $flags;
+ }
+ else
+ {
+ // If the path manager hasn't been initted yet, take an educated guess at what the URI should be
+ $url = contentPath . $n . ':' . $t . $flags;
+ }
+
+ if($query)
+ {
+ if(strstr($url, '?'))
+ {
+ $sep = '&';
+ }
+ else
+ {
+ $sep = '?';
+ }
+ $url = $url . $sep . $query . $flags;
+ }
+
+ if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ {
+ $url = $session->append_sid($url);
+ }
+
+ return ($escape) ? htmlspecialchars($url) : $url;
+ }
}
/**
@@ -211,7 +211,7 @@
function makeUrlComplete($n, $t, $query = false, $escape = false)
{
- return get_server_url() . makeUrlNS($n, $t, $query, $escape);
+ return get_server_url() . makeUrlNS($n, $t, $query, $escape);
}
/**
@@ -221,15 +221,15 @@
function get_server_url()
{
- $server_name = false;
- if ( isset($_SERVER['HTTP_HOST']) )
- $server_name = $_SERVER['HTTP_HOST'];
- else if ( isset($_SERVER['SERVER_NAME']) )
- $server_name = $_SERVER['SERVER_NAME'];
- else
- $server_name = 'localhost';
-
- return 'http' . ( $GLOBALS['is_https'] ) . '://' . $server_name;
+ $server_name = false;
+ if ( isset($_SERVER['HTTP_HOST']) )
+ $server_name = $_SERVER['HTTP_HOST'];
+ else if ( isset($_SERVER['SERVER_NAME']) )
+ $server_name = $_SERVER['SERVER_NAME'];
+ else
+ $server_name = 'localhost';
+
+ return 'http' . ( $GLOBALS['is_https'] ) . '://' . $server_name;
}
/**
@@ -239,18 +239,18 @@
function get_main_page($force_logged_in = false)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- $logged_in = false;
- if ( is_object($session) && !$force_logged_in )
- {
- $logged_in = $session->user_logged_in;
- }
- else if ( $force_logged_in )
- {
- $logged_in = true;
- }
- return $logged_in && getConfig('main_page_alt_enable', '0') == '1' ? getConfig('main_page_alt', getConfig('main_page', 'Main_Page')) : getConfig('main_page', 'Main_Page');
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $logged_in = false;
+ if ( is_object($session) && !$force_logged_in )
+ {
+ $logged_in = $session->user_logged_in;
+ }
+ else if ( $force_logged_in )
+ {
+ $logged_in = true;
+ }
+ return $logged_in && getConfig('main_page_alt_enable', '0') == '1' ? getConfig('main_page_alt', getConfig('main_page', 'Main_Page')) : getConfig('main_page', 'Main_Page');
}
/**
@@ -262,44 +262,44 @@
function get_title($sanitize = true, $chop_special = false)
{
- $title = '';
- if ( isset($_GET['title']) )
- {
- $title = $_GET['title'];
- }
- else if ( isset($_SERVER['PATH_INFO']) )
- {
- // fix for apache + CGI (occurred on a GoDaddy server, thanks mm3)
- if ( @substr(@$_SERVER['GATEWAY_INTERFACE'], 0, 3) === 'CGI' && $_SERVER['PATH_INFO'] == scriptPath . '/index.php' )
- {
- // do nothing; ignore PATH_INFO
- }
- else
- {
- $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 );
- }
- }
- else
- {
- // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request
- // If you really want to try it, the URI format is yoursite.com/?/Page_title
- if ( !empty($_SERVER['QUERY_STRING']) && substr($_SERVER['QUERY_STRING'], 0, 1) == '/' )
- {
- $pos = ( ($_ = strpos($_SERVER['QUERY_STRING'], '&')) !== false ) ? $_ - 1: 0x7FFFFFFF;
- $title = substr($_SERVER['QUERY_STRING'], 1, $pos);
- }
- }
-
- if ( $chop_special )
- {
- list(, $ns) = RenderMan::strToPageID($title);
- if ( $ns == 'Special' || $ns == 'Admin' )
- {
- list($title) = explode('/', $title);
- }
- }
-
- return ( $sanitize ) ? sanitize_page_id($title) : $title;
+ $title = '';
+ if ( isset($_GET['title']) )
+ {
+ $title = $_GET['title'];
+ }
+ else if ( isset($_SERVER['PATH_INFO']) )
+ {
+ // fix for apache + CGI (occurred on a GoDaddy server, thanks mm3)
+ if ( @substr(@$_SERVER['GATEWAY_INTERFACE'], 0, 3) === 'CGI' && $_SERVER['PATH_INFO'] == scriptPath . '/index.php' )
+ {
+ // do nothing; ignore PATH_INFO
+ }
+ else
+ {
+ $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 );
+ }
+ }
+ else
+ {
+ // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request
+ // If you really want to try it, the URI format is yoursite.com/?/Page_title
+ if ( !empty($_SERVER['QUERY_STRING']) && substr($_SERVER['QUERY_STRING'], 0, 1) == '/' )
+ {
+ $pos = ( ($_ = strpos($_SERVER['QUERY_STRING'], '&')) !== false ) ? $_ - 1: 0x7FFFFFFF;
+ $title = substr($_SERVER['QUERY_STRING'], 1, $pos);
+ }
+ }
+
+ if ( $chop_special )
+ {
+ list(, $ns) = RenderMan::strToPageID($title);
+ if ( $ns == 'Special' || $ns == 'Admin' )
+ {
+ list($title) = explode('/', $title);
+ }
+ }
+
+ return ( $sanitize ) ? sanitize_page_id($title) : $title;
}
/**
@@ -309,7 +309,7 @@
function have_blank_urlname_page()
{
- return getConfig('main_page', 'Main_Page') == '' || getConfig('main_page', getConfig('main_page', 'Main_Page')) == '';
+ return getConfig('main_page', 'Main_Page') == '' || getConfig('main_page', getConfig('main_page', 'Main_Page')) == '';
}
/**
@@ -321,78 +321,78 @@
function enano_date($string, $timestamp = false)
{
- if ( !is_int($timestamp) && !is_double($timestamp) && strval(intval($timestamp)) !== $timestamp )
- $timestamp = time();
-
- if ( is_int($string) )
- {
- global $session, $lang;
- $date_fmt = is_object($session) ? $session->date_format : DATE_4;
- $time_fmt = is_object($session) ? $session->time_format : TIME_24_NS;
-
- // within a week? use a relative date
- if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) && !($string & ED_DATE_FULL) )
- {
- $relative_date = get_relative_date($timestamp);
- if ( $string === ED_DATE )
- // why do more work if we're done?
- return $relative_date;
- }
-
- $flags = $string;
- $string = array();
- if ( $flags & ED_DATE && !isset($relative_date) )
- $string[] = $date_fmt;
- if ( $flags & ED_TIME )
- $string[] = $time_fmt;
-
- $string = implode(' ', $string);
- }
-
- // perform timestamp offset
- global $timezone;
- // it's gonna be in minutes, so multiply by 60 to offset the unix timestamp
- $timestamp = $timestamp + ( $timezone * 60 );
-
- // are we in DST?
- global $dst_params;
- $dst_offset = 0;
- if ( check_timestamp_dst($timestamp, $dst_params[0], $dst_params[1], $dst_params[2], $dst_params[3]) )
- {
- // offset for DST
- $timestamp += ( $dst_params[4] * 60 );
- $dst_offset = $dst_params[4];
- }
-
- // Does this date string include a timezone? If so, gmdate() will report UTC, which is wrong
- // FIXME This is kind of a halfass replacement...
- foreach ( array('e', 'T', 'O', 'P') as $char )
- {
- if ( ($pos = strpos($string, $char)) !== false )
- {
- if ( $string{ $pos - 1 } != '\\' )
- {
- // add in our own timezone string
- // FIXME: l10n? (do we need to? does anyone really not know what "GMT" means? even uglier escaping?)
- $tzi = '\\G\\M\\T';
- $tzo = $timezone + $dst_offset;
- $sign = $tzo > 0 ? '+' : '-';
- $tzi .= $sign . (intval(abs($tzo / 60)));
- if ( $tzo % 60 )
- $tzi .= sprintf(":%02d", abs($tzo) % 60);
-
- $string = substr($string, 0, $pos) . $tzi . substr($string, $pos + 1);
- }
- }
- }
-
- // Let PHP do the work for us =)
- $result = gmdate($string, $timestamp);
- if ( isset($relative_date) )
- {
- $result = "$relative_date, $result";
- }
- return $result;
+ if ( !is_int($timestamp) && !is_double($timestamp) && strval(intval($timestamp)) !== $timestamp )
+ $timestamp = time();
+
+ if ( is_int($string) )
+ {
+ global $session, $lang;
+ $date_fmt = is_object($session) ? $session->date_format : DATE_4;
+ $time_fmt = is_object($session) ? $session->time_format : TIME_24_NS;
+
+ // within a week? use a relative date
+ if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) && !($string & ED_DATE_FULL) )
+ {
+ $relative_date = get_relative_date($timestamp);
+ if ( $string === ED_DATE )
+ // why do more work if we're done?
+ return $relative_date;
+ }
+
+ $flags = $string;
+ $string = array();
+ if ( $flags & ED_DATE && !isset($relative_date) )
+ $string[] = $date_fmt;
+ if ( $flags & ED_TIME )
+ $string[] = $time_fmt;
+
+ $string = implode(' ', $string);
+ }
+
+ // perform timestamp offset
+ global $timezone;
+ // it's gonna be in minutes, so multiply by 60 to offset the unix timestamp
+ $timestamp = $timestamp + ( $timezone * 60 );
+
+ // are we in DST?
+ global $dst_params;
+ $dst_offset = 0;
+ if ( check_timestamp_dst($timestamp, $dst_params[0], $dst_params[1], $dst_params[2], $dst_params[3]) )
+ {
+ // offset for DST
+ $timestamp += ( $dst_params[4] * 60 );
+ $dst_offset = $dst_params[4];
+ }
+
+ // Does this date string include a timezone? If so, gmdate() will report UTC, which is wrong
+ // FIXME This is kind of a halfass replacement...
+ foreach ( array('e', 'T', 'O', 'P') as $char )
+ {
+ if ( ($pos = strpos($string, $char)) !== false )
+ {
+ if ( $string{ $pos - 1 } != '\\' )
+ {
+ // add in our own timezone string
+ // FIXME: l10n? (do we need to? does anyone really not know what "GMT" means? even uglier escaping?)
+ $tzi = '\\G\\M\\T';
+ $tzo = $timezone + $dst_offset;
+ $sign = $tzo > 0 ? '+' : '-';
+ $tzi .= $sign . (intval(abs($tzo / 60)));
+ if ( $tzo % 60 )
+ $tzi .= sprintf(":%02d", abs($tzo) % 60);
+
+ $string = substr($string, 0, $pos) . $tzi . substr($string, $pos + 1);
+ }
+ }
+ }
+
+ // Let PHP do the work for us =)
+ $result = gmdate($string, $timestamp);
+ if ( isset($relative_date) )
+ {
+ $result = "$relative_date, $result";
+ }
+ return $result;
}
/**
@@ -403,47 +403,47 @@
function get_relative_date($time)
{
- global $lang, $session;
- // Our formatting string to pass to enano_date()
- // This should not include minute/second info, only today's date in whatever format suits your fancy
- $formatstring = $session->date_format;
- // Today's date
- $today = enano_date($formatstring);
- // Yesterday's date
- $yesterday = enano_date($formatstring, (time() - (24*60*60)));
- // Date on the input
- $then = enano_date($formatstring, $time);
- // "X days ago" logic
- for ( $i = 2; $i <= 6; $i++ )
- {
- // hours_in_day * minutes_in_hour * seconds_in_minute * num_days
- $offset = 24 * 60 * 60 * $i;
- $days_ago = enano_date($formatstring, (time() - $offset));
- // so does the input timestamp match the date from $i days ago?
- if ( $then == $days_ago )
- {
- // yes, return $i
- return $lang->get('userfuncs_ml_date_daysago', array('days_ago' => $i));
- }
- }
- // either yesterday, today, or before 6 days ago
- switch($then)
- {
- case $today:
- return $lang->get('userfuncs_ml_date_today');
- case $yesterday:
- return $lang->get('userfuncs_ml_date_yesterday');
- default:
- return $then;
- }
- // .--.
- // |o_o |
- // |!_/ |
- // // \ \
- // (| | )
- // /'\_ _/`\
- // \___)=(___/
- return 'Linux rocks!';
+ global $lang, $session;
+ // Our formatting string to pass to enano_date()
+ // This should not include minute/second info, only today's date in whatever format suits your fancy
+ $formatstring = $session->date_format;
+ // Today's date
+ $today = enano_date($formatstring);
+ // Yesterday's date
+ $yesterday = enano_date($formatstring, (time() - (24*60*60)));
+ // Date on the input
+ $then = enano_date($formatstring, $time);
+ // "X days ago" logic
+ for ( $i = 2; $i <= 6; $i++ )
+ {
+ // hours_in_day * minutes_in_hour * seconds_in_minute * num_days
+ $offset = 24 * 60 * 60 * $i;
+ $days_ago = enano_date($formatstring, (time() - $offset));
+ // so does the input timestamp match the date from $i days ago?
+ if ( $then == $days_ago )
+ {
+ // yes, return $i
+ return $lang->get('userfuncs_ml_date_daysago', array('days_ago' => $i));
+ }
+ }
+ // either yesterday, today, or before 6 days ago
+ switch($then)
+ {
+ case $today:
+ return $lang->get('userfuncs_ml_date_today');
+ case $yesterday:
+ return $lang->get('userfuncs_ml_date_yesterday');
+ default:
+ return $then;
+ }
+ // .--.
+ // |o_o |
+ // |!_/ |
+ // // \ \
+ // (| | )
+ // /'\_ _/`\
+ // \___)=(___/
+ return 'Linux rocks!';
}
/**
@@ -458,31 +458,31 @@
function check_timestamp_dst($time, $start_month, $start_sunday, $end_month, $end_sunday)
{
- static $sundays = array(FIRST_SUNDAY, SECOND_SUNDAY, THIRD_SUNDAY, LAST_SUNDAY);
-
- // perform timestamp offset
- global $timezone;
- // it's gonna be in minutes, so multiply by 60 to offset the unix timestamp
- $time = $time + ( $timezone * 60 );
- $year = intval(gmdate('Y', $time));
-
- // one-pass validation
- if ( !in_array($start_sunday, $sundays) || !in_array($end_sunday, $sundays) ||
- $start_month < 1 || $start_month > 12 || $end_month < 1 || $end_month > 12 )
- return false;
-
- // get timestamp of the selected sunday (start)
- $dst_start = get_sunday_timestamp($start_month, $start_sunday, $year);
- $dst_end = get_sunday_timestamp($end_month, $end_sunday, $year);
-
- if ( $dst_start > $dst_end )
- {
- // start time is past the end time, this means we're in the southern hemisphere
- // as a result, if we're within the range, DST is NOT in progress.
- return !( $time >= $dst_start && $time <= $dst_end );
- }
-
- return $time >= $dst_start && $time <= $dst_end;
+ static $sundays = array(FIRST_SUNDAY, SECOND_SUNDAY, THIRD_SUNDAY, LAST_SUNDAY);
+
+ // perform timestamp offset
+ global $timezone;
+ // it's gonna be in minutes, so multiply by 60 to offset the unix timestamp
+ $time = $time + ( $timezone * 60 );
+ $year = intval(gmdate('Y', $time));
+
+ // one-pass validation
+ if ( !in_array($start_sunday, $sundays) || !in_array($end_sunday, $sundays) ||
+ $start_month < 1 || $start_month > 12 || $end_month < 1 || $end_month > 12 )
+ return false;
+
+ // get timestamp of the selected sunday (start)
+ $dst_start = get_sunday_timestamp($start_month, $start_sunday, $year);
+ $dst_end = get_sunday_timestamp($end_month, $end_sunday, $year);
+
+ if ( $dst_start > $dst_end )
+ {
+ // start time is past the end time, this means we're in the southern hemisphere
+ // as a result, if we're within the range, DST is NOT in progress.
+ return !( $time >= $dst_start && $time <= $dst_end );
+ }
+
+ return $time >= $dst_start && $time <= $dst_end;
}
/**
@@ -495,48 +495,48 @@
function get_sunday_timestamp($month, $sunday, $year)
{
- $days_in_month = array(
- 1 => 31,
- 2 => $year % 4 == 0 && ( $year % 100 != 0 || ( $year % 100 == 0 && $year % 400 == 0 ) ) ? 29 : 28,
- 3 => 31,
- 4 => 30,
- 5 => 31,
- 6 => 30,
- 7 => 31,
- 8 => 31,
- 9 => 30,
- 10 => 31,
- 11 => 30,
- 12 => 31
- );
-
- $result = mktime(0, 0, 0, $month, 1, $year);
-
- // hack. allows a specific day of the month to be set instead of a sunday. not a good place to do this.
- if ( is_string($sunday) && substr($sunday, -1) === 'd' )
- {
- $result += 86400 * ( intval($sunday) - 1);
- return $result;
- }
-
- $tick = 0;
- $days_remaining = $days_in_month[$month];
- while ( true )
- {
- if ( date('D', $result) == 'Sun' )
- {
- $tick++;
- if ( ( $tick == 1 && $sunday == FIRST_SUNDAY ) ||
- ( $tick == 2 && $sunday == SECOND_SUNDAY ) ||
- ( $tick == 3 && $sunday == THIRD_SUNDAY ) ||
- ( $sunday == LAST_SUNDAY && $days_remaining < 7 ) )
- break;
- }
- $days_remaining--;
- $result += 86400;
- }
-
- return $result;
+ $days_in_month = array(
+ 1 => 31,
+ 2 => $year % 4 == 0 && ( $year % 100 != 0 || ( $year % 100 == 0 && $year % 400 == 0 ) ) ? 29 : 28,
+ 3 => 31,
+ 4 => 30,
+ 5 => 31,
+ 6 => 30,
+ 7 => 31,
+ 8 => 31,
+ 9 => 30,
+ 10 => 31,
+ 11 => 30,
+ 12 => 31
+ );
+
+ $result = mktime(0, 0, 0, $month, 1, $year);
+
+ // hack. allows a specific day of the month to be set instead of a sunday. not a good place to do this.
+ if ( is_string($sunday) && substr($sunday, -1) === 'd' )
+ {
+ $result += 86400 * ( intval($sunday) - 1);
+ return $result;
+ }
+
+ $tick = 0;
+ $days_remaining = $days_in_month[$month];
+ while ( true )
+ {
+ if ( date('D', $result) == 'Sun' )
+ {
+ $tick++;
+ if ( ( $tick == 1 && $sunday == FIRST_SUNDAY ) ||
+ ( $tick == 2 && $sunday == SECOND_SUNDAY ) ||
+ ( $tick == 3 && $sunday == THIRD_SUNDAY ) ||
+ ( $sunday == LAST_SUNDAY && $days_remaining < 7 ) )
+ break;
+ }
+ $days_remaining--;
+ $result += 86400;
+ }
+
+ return $result;
}
/**
@@ -548,10 +548,10 @@
function get_page_title($page_id, $show_ns = true)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- $idata = RenderMan::strToPageID($page_id);
- return get_page_title_ns($idata[0], $idata[1]);
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $idata = RenderMan::strToPageID($page_id);
+ return get_page_title_ns($idata[0], $idata[1]);
}
/**
@@ -563,10 +563,10 @@
function get_page_title_ns($page_id, $namespace)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- $ns = namespace_factory($page_id, $namespace);
- return $ns->title;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $ns = namespace_factory($page_id, $namespace);
+ return $ns->title;
}
/**
@@ -579,59 +579,59 @@
function redirect($url, $title = 'etc_redirect_title', $message = 'etc_redirect_body', $timeout = 3)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- // POST check added in 1.1.x because Firefox 3.0 asks us if we want to "resend the form
- // data to the new location", which can be confusing for some users.
- $is_firefox_3 = ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'Firefox/3.') ) ? true : false;
- if ( $timeout == 0 && ( empty($_POST) || !$is_firefox_3 ) )
- {
- header('Location: ' . $url);
- header('Content-length: 0');
- header('HTTP/1.1 307 Temporary Redirect');
-
- // with 3xx codes HTTP clients expect a response of 0 bytes, so just die here
- exit();
- }
-
- if ( !is_object($template) )
- {
- $template = new template_nodb();
- $template->load_theme('oxygen', 'bleu', false);
- $template->assign_vars(array(
- 'SITE_NAME' => 'Enano',
- 'SITE_DESC' => 'This site is experiencing a critical error and cannot load.',
- 'COPYRIGHT' => 'Powered by Enano CMS - © 2006-2008 Dan Fuhry. This program is Free Software; see the <a href="' . scriptPath . '/install.php?mode=license">GPL file</a> included with this package for details.',
- 'PAGE_NAME' => htmlspecialchars($title)
- ));
- }
-
- $template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />');
- $template->add_header('<script type="text/javascript">
- function __r() {
- // FUNCTION AUTOMATICALLY GENERATED
- window.location="' . str_replace('"', '\\"', $url) . '";
- }
- setTimeout(\'__r();\', ' . $timeout . '000);
- </script>
- ');
-
- if ( get_class($template) == 'template_nodb' )
- $template->init_vars();
-
- $template->assign_vars(array('PAGE_NAME' => $title));
- $template->header(true);
- echo '<p>' . $message . '</p>';
- $subst = array(
- 'timeout' => $timeout,
- 'redirect_url' => str_replace('"', '\\"', $url)
- );
- echo '<p>' . $lang->get('etc_redirect_timeout', $subst) . '</p>';
- $template->footer(true);
-
- $db->close();
- exit(0);
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang;
+
+ // POST check added in 1.1.x because Firefox 3.0 asks us if we want to "resend the form
+ // data to the new location", which can be confusing for some users.
+ $is_firefox_3 = ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'Firefox/3.') ) ? true : false;
+ if ( $timeout == 0 && ( empty($_POST) || !$is_firefox_3 ) )
+ {
+ header('Location: ' . $url);
+ header('Content-length: 0');
+ header('HTTP/1.1 307 Temporary Redirect');
+
+ // with 3xx codes HTTP clients expect a response of 0 bytes, so just die here
+ exit();
+ }
+
+ if ( !is_object($template) )
+ {
+ $template = new template_nodb();
+ $template->load_theme('oxygen', 'bleu', false);
+ $template->assign_vars(array(
+ 'SITE_NAME' => 'Enano',
+ 'SITE_DESC' => 'This site is experiencing a critical error and cannot load.',
+ 'COPYRIGHT' => 'Powered by Enano CMS - © 2006-2008 Dan Fuhry. This program is Free Software; see the <a href="' . scriptPath . '/install.php?mode=license">GPL file</a> included with this package for details.',
+ 'PAGE_NAME' => htmlspecialchars($title)
+ ));
+ }
+
+ $template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />');
+ $template->add_header('<script type="text/javascript">
+ function __r() {
+ // FUNCTION AUTOMATICALLY GENERATED
+ window.location="' . str_replace('"', '\\"', $url) . '";
+ }
+ setTimeout(\'__r();\', ' . $timeout . '000);
+ </script>
+ ');
+
+ if ( get_class($template) == 'template_nodb' )
+ $template->init_vars();
+
+ $template->assign_vars(array('PAGE_NAME' => $title));
+ $template->header(true);
+ echo '<p>' . $message . '</p>';
+ $subst = array(
+ 'timeout' => $timeout,
+ 'redirect_url' => str_replace('"', '\\"', $url)
+ );
+ echo '<p>' . $lang->get('etc_redirect_timeout', $subst) . '</p>';
+ $template->footer(true);
+
+ $db->close();
+ exit(0);
}
@@ -641,85 +641,85 @@
function csrf_request_confirm()
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang, $output;
-
- // If the token was overridden with the correct one, the user confirmed the action using this form. Continue exec.
- if ( isset($_POST['cstok']) || isset($_GET['cstok']) )
- {
- // using the if() check makes sure that the token isn't in a cookie, since $_REQUEST includes $_COOKIE.
- $token_check =& $_REQUEST['cstok'];
- if ( $token_check === $session->csrf_token )
- {
- // overridden token matches, continue exec
- return true;
- }
- }
-
- @ob_end_clean();
-
- $output->set_title($lang->get('user_csrf_confirm_title'));
- $output->header();
-
- // initial info
- echo '<p>' . $lang->get('user_csrf_confirm_body') . '</p>';
-
- // start form
- $form_method = ( empty($_POST) ) ? 'get' : 'post';
- echo '<form action="' . htmlspecialchars($_SERVER['REQUEST_URI']) . '" method="' . $form_method . '" enctype="multipart/form-data">';
-
- echo '<fieldset enano:expand="closed">';
- echo '<legend>' . $lang->get('user_csrf_confirm_btn_viewrequest') . '</legend><div>';
-
- if ( empty($_POST) )
- {
- // GET request
- echo csrf_confirm_get_recursive();
- }
- else
- {
- // POST request
- echo csrf_confirm_post_recursive();
- }
- echo '</div></fieldset>';
- // insert the right CSRF token
- echo '<input type="hidden" name="cstok" value="' . $session->csrf_token . '" />';
- echo '<p><input type="submit" value="' . $lang->get('user_csrf_confirm_btn_continue') . '" /></p>';
- echo '</form><script type="text/javascript">addOnloadHook(function(){load_component(\'expander\');});</script>';
-
- $output->footer();
-
- exit;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang, $output;
+
+ // If the token was overridden with the correct one, the user confirmed the action using this form. Continue exec.
+ if ( isset($_POST['cstok']) || isset($_GET['cstok']) )
+ {
+ // using the if() check makes sure that the token isn't in a cookie, since $_REQUEST includes $_COOKIE.
+ $token_check =& $_REQUEST['cstok'];
+ if ( $token_check === $session->csrf_token )
+ {
+ // overridden token matches, continue exec
+ return true;
+ }
+ }
+
+ @ob_end_clean();
+
+ $output->set_title($lang->get('user_csrf_confirm_title'));
+ $output->header();
+
+ // initial info
+ echo '<p>' . $lang->get('user_csrf_confirm_body') . '</p>';
+
+ // start form
+ $form_method = ( empty($_POST) ) ? 'get' : 'post';
+ echo '<form action="' . htmlspecialchars($_SERVER['REQUEST_URI']) . '" method="' . $form_method . '" enctype="multipart/form-data">';
+
+ echo '<fieldset enano:expand="closed">';
+ echo '<legend>' . $lang->get('user_csrf_confirm_btn_viewrequest') . '</legend><div>';
+
+ if ( empty($_POST) )
+ {
+ // GET request
+ echo csrf_confirm_get_recursive();
+ }
+ else
+ {
+ // POST request
+ echo csrf_confirm_post_recursive();
+ }
+ echo '</div></fieldset>';
+ // insert the right CSRF token
+ echo '<input type="hidden" name="cstok" value="' . $session->csrf_token . '" />';
+ echo '<p><input type="submit" value="' . $lang->get('user_csrf_confirm_btn_continue') . '" /></p>';
+ echo '</form><script type="text/javascript">addOnloadHook(function(){load_component(\'expander\');});</script>';
+
+ $output->footer();
+
+ exit;
}
function csrf_confirm_get_recursive($_inner = false, $pfx = false, $data = false)
{
- // make posted arrays work right
- if ( !$data )
- ( $_inner == 'post' ) ? $data =& $_POST : $data =& $_GET;
- foreach ( $data as $key => $value )
- {
- $pfx_this = ( empty($pfx) ) ? $key : "{$pfx}[{$key}]";
- if ( is_array($value) )
- {
- csrf_confirm_get_recursive(true, $pfx_this, $value);
- }
- else if ( empty($value) )
- {
- echo htmlspecialchars($pfx_this . " = <nil>") . "<br />\n";
- echo '<input type="hidden" name="' . htmlspecialchars($pfx_this) . '" value="" />';
- }
- else
- {
- echo htmlspecialchars($pfx_this . " = " . $value) . "<br />\n";
- echo '<input type="hidden" name="' . htmlspecialchars($pfx_this) . '" value="' . htmlspecialchars($value) . '" />';
- }
- }
+ // make posted arrays work right
+ if ( !$data )
+ ( $_inner == 'post' ) ? $data =& $_POST : $data =& $_GET;
+ foreach ( $data as $key => $value )
+ {
+ $pfx_this = ( empty($pfx) ) ? $key : "{$pfx}[{$key}]";
+ if ( is_array($value) )
+ {
+ csrf_confirm_get_recursive(true, $pfx_this, $value);
+ }
+ else if ( empty($value) )
+ {
+ echo htmlspecialchars($pfx_this . " = <nil>") . "<br />\n";
+ echo '<input type="hidden" name="' . htmlspecialchars($pfx_this) . '" value="" />';
+ }
+ else
+ {
+ echo htmlspecialchars($pfx_this . " = " . $value) . "<br />\n";
+ echo '<input type="hidden" name="' . htmlspecialchars($pfx_this) . '" value="' . htmlspecialchars($value) . '" />';
+ }
+ }
}
function csrf_confirm_post_recursive()
{
- csrf_confirm_get_recursive('post');
+ csrf_confirm_get_recursive('post');
}
// Removed wikiFormat() from here, replaced with RenderMan::render
@@ -732,22 +732,22 @@
function isPage($p)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- static $ispage_cache = array();
- if ( isset($ispage_cache[$p]) )
- return $ispage_cache[$p];
-
- list($page_id, $namespace) = RenderMan::strToPageID($p);
- $cdata = $paths->get_cdata($page_id, $namespace);
- if ( !isset($cdata['page_exists']) )
- {
- $class = ( class_exists($_ = "Namespace_$namespace") ) ? $_ : "Namespace_Default";
- $page = new $class($page_id, $namespace);
- return $page->exists();
- }
-
- $ispage_cache[$p] = $cdata['page_exists'];
- return $cdata['page_exists'];
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ static $ispage_cache = array();
+ if ( isset($ispage_cache[$p]) )
+ return $ispage_cache[$p];
+
+ list($page_id, $namespace) = RenderMan::strToPageID($p);
+ $cdata = $paths->get_cdata($page_id, $namespace);
+ if ( !isset($cdata['page_exists']) )
+ {
+ $class = ( class_exists($_ = "Namespace_$namespace") ) ? $_ : "Namespace_Default";
+ $page = new $class($page_id, $namespace);
+ return $page->exists();
+ }
+
+ $ispage_cache[$p] = $cdata['page_exists'];
+ return $cdata['page_exists'];
}
/**
@@ -759,33 +759,33 @@
function namespace_factory($page_id, $namespace, $revision_id = 0)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- static $objcache = array();
- $pathskey = $paths->get_pathskey($page_id, $namespace) . ":$revision_id";
- if ( isset($objcache[$pathskey]) )
- return $objcache[$pathskey];
-
- if ( !class_exists("Namespace_$namespace") )
- {
- if ( file_exists(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php") )
- {
- require(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php");
- }
- }
- if ( class_exists("Namespace_$namespace") )
- {
- $class = "Namespace_$namespace";
- $ns = new $class($page_id, $namespace, $revision_id);
- $objcache[$pathskey] = $ns;
- return $ns;
- }
- else
- {
- $ns = new Namespace_Default($page_id, $namespace, $revision_id);
- $objcache[$pathskey] = $ns;
- return $ns;
- }
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ static $objcache = array();
+ $pathskey = $paths->get_pathskey($page_id, $namespace) . ":$revision_id";
+ if ( isset($objcache[$pathskey]) )
+ return $objcache[$pathskey];
+
+ if ( !class_exists("Namespace_$namespace") )
+ {
+ if ( file_exists(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php") )
+ {
+ require(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php");
+ }
+ }
+ if ( class_exists("Namespace_$namespace") )
+ {
+ $class = "Namespace_$namespace";
+ $ns = new $class($page_id, $namespace, $revision_id);
+ $objcache[$pathskey] = $ns;
+ return $ns;
+ }
+ else
+ {
+ $ns = new Namespace_Default($page_id, $namespace, $revision_id);
+ $objcache[$pathskey] = $ns;
+ return $ns;
+ }
}
/**
@@ -793,52 +793,52 @@
*/
function arrayItemUp($arr, $keyname) {
- $keylist = array_keys($arr);
- $keyflop = array_flip($keylist);
- $idx = $keyflop[$keyname];
- $idxm = $idx - 1;
- $temp = $arr[$keylist[$idxm]];
- if($arr[$keylist[0]] == $arr[$keyname]) return $arr;
- $arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
- $arr[$keylist[$idx]] = $temp;
- return $arr;
+ $keylist = array_keys($arr);
+ $keyflop = array_flip($keylist);
+ $idx = $keyflop[$keyname];
+ $idxm = $idx - 1;
+ $temp = $arr[$keylist[$idxm]];
+ if($arr[$keylist[0]] == $arr[$keyname]) return $arr;
+ $arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
+ $arr[$keylist[$idx]] = $temp;
+ return $arr;
}
function arrayItemDown($arr, $keyname) {
- $keylist = array_keys($arr);
- $keyflop = array_flip($keylist);
- $idx = $keyflop[$keyname];
- $idxm = $idx + 1;
- $temp = $arr[$keylist[$idxm]];
- $sz = sizeof($arr); $sz--;
- if($arr[$keylist[$sz]] == $arr[$keyname]) return $arr;
- $arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
- $arr[$keylist[$idx]] = $temp;
- return $arr;
+ $keylist = array_keys($arr);
+ $keyflop = array_flip($keylist);
+ $idx = $keyflop[$keyname];
+ $idxm = $idx + 1;
+ $temp = $arr[$keylist[$idxm]];
+ $sz = sizeof($arr); $sz--;
+ if($arr[$keylist[$sz]] == $arr[$keyname]) return $arr;
+ $arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
+ $arr[$keylist[$idx]] = $temp;
+ return $arr;
}
function arrayItemTop($arr, $keyname) {
- $keylist = array_keys($arr);
- $keyflop = array_flip($keylist);
- $idx = $keyflop[$keyname];
- while( $orig != $arr[$keylist[0]] ) {
- // echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger
- if($idx < 0) return $arr;
- if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) {
- return $arr;
- }
- $arr = arrayItemUp($arr, $keylist[$idx]);
- $idx--;
- }
- return $arr;
+ $keylist = array_keys($arr);
+ $keyflop = array_flip($keylist);
+ $idx = $keyflop[$keyname];
+ while( $orig != $arr[$keylist[0]] ) {
+ // echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger
+ if($idx < 0) return $arr;
+ if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) {
+ return $arr;
+ }
+ $arr = arrayItemUp($arr, $keylist[$idx]);
+ $idx--;
+ }
+ return $arr;
}
function arrayItemBottom($arr, $keyname) {
- $b = $arr[$keyname];
- unset($arr[$keyname]);
- $arr[$keyname] = $b;
- unset($b);
- return $arr;
+ $b = $arr[$keyname];
+ unset($arr[$keyname]);
+ $arr[$keyname] = $b;
+ unset($b);
+ return $arr;
}
/**
@@ -850,12 +850,12 @@
function enano_safe_array_merge($arr1, $arr2)
{
- $arr3 = $arr1;
- foreach($arr2 as $k => $v)
- {
- $arr3[$k] = $v;
- }
- return $arr3;
+ $arr3 = $arr1;
+ foreach($arr2 as $k => $v)
+ {
+ $arr3[$k] = $v;
+ }
+ return $arr3;
}
/**
@@ -866,21 +866,21 @@
function integerize_array($arr)
{
- if ( !is_array($arr) )
- return $arr;
-
- foreach ( $arr as &$val )
- {
- if ( is_string($val) && ctype_digit($val) && strlen($val) < 10 )
- {
- $val = intval($val);
- }
- else if ( is_array($val) )
- {
- $val = integerize_array($val);
- }
- }
- return $arr;
+ if ( !is_array($arr) )
+ return $arr;
+
+ foreach ( $arr as &$val )
+ {
+ if ( is_string($val) && ctype_digit($val) && strlen($val) < 10 )
+ {
+ $val = intval($val);
+ }
+ else if ( is_array($val) )
+ {
+ $val = integerize_array($val);
+ }
+ }
+ return $arr;
}
// Convert IP address to hex string
@@ -888,21 +888,21 @@
// Output: 0x7f000001 (string)
// Updated 12/8/06 to work with PHP4 and not use eval() (blech)
function ip2hex($ip) {
- if ( preg_match('/^([0-9a-f:]+)$/', $ip) )
- {
- // this is an ipv6 address
- return str_replace(':', '', $ip);
- }
- $nums = explode('.', $ip);
- if(sizeof($nums) != 4) return false;
- $str = '0x';
- foreach($nums as $n)
- {
- $byte = (string)dechex($n);
- if ( strlen($byte) < 2 )
- $byte = '0' . $byte;
- }
- return $str;
+ if ( preg_match('/^([0-9a-f:]+)$/', $ip) )
+ {
+ // this is an ipv6 address
+ return str_replace(':', '', $ip);
+ }
+ $nums = explode('.', $ip);
+ if(sizeof($nums) != 4) return false;
+ $str = '0x';
+ foreach($nums as $n)
+ {
+ $byte = (string)dechex($n);
+ if ( strlen($byte) < 2 )
+ $byte = '0' . $byte;
+ }
+ return $str;
}
// Convert DWord to IP address
@@ -910,17 +910,17 @@
// Output: 127.0.0.1
// Updated 12/8/06 to work with PHP4 and not use eval() (blech)
function hex2ip($in) {
- if(substr($in, 0, 2) == '0x') $ip = substr($in, 2, 8);
- else $ip = substr($in, 0, 8);
- $octets = enano_str_split($ip, 2);
- $str = '';
- $newoct = Array();
- foreach($octets as $o)
- {
- $o = (int)hexdec($o);
- $newoct[] = $o;
- }
- return implode('.', $newoct);
+ if(substr($in, 0, 2) == '0x') $ip = substr($in, 2, 8);
+ else $ip = substr($in, 0, 8);
+ $octets = enano_str_split($ip, 2);
+ $str = '';
+ $newoct = Array();
+ foreach($octets as $o)
+ {
+ $o = (int)hexdec($o);
+ $newoct[] = $o;
+ }
+ return implode('.', $newoct);
}
// Function strip_php moved to RenderMan class
@@ -936,38 +936,38 @@
function die_semicritical($t, $p, $no_wrapper = false)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- $db->close();
-
- if ( @ob_get_status() )
- ob_end_clean();
-
- // If the config hasn't been fetched yet, call grinding_halt.
- if ( !defined('ENANO_CONFIG_FETCHED') )
- {
- grinding_halt($t, $p);
- }
-
- // also do grinding_halt() if we're in CLI mode
- if ( defined('ENANO_CLI') )
- {
- grinding_halt($t, $p);
- }
-
- if ( $no_wrapper )
- {
- echo '<h2>' . htmlspecialchars($t) . '</h2>';
- echo "<p>$p</p>";
- exit;
- }
-
- $output = new Output_Safe();
- $output->set_title($t);
- $output->header();
- echo $p;
- $output->footer();
-
- exit;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ $db->close();
+
+ if ( @ob_get_status() )
+ ob_end_clean();
+
+ // If the config hasn't been fetched yet, call grinding_halt.
+ if ( !defined('ENANO_CONFIG_FETCHED') )
+ {
+ grinding_halt($t, $p);
+ }
+
+ // also do grinding_halt() if we're in CLI mode
+ if ( defined('ENANO_CLI') )
+ {
+ grinding_halt($t, $p);
+ }
+
+ if ( $no_wrapper )
+ {
+ echo '<h2>' . htmlspecialchars($t) . '</h2>';
+ echo "<p>$p</p>";
+ exit;
+ }
+
+ $output = new Output_Safe();
+ $output->set_title($t);
+ $output->header();
+ echo $p;
+ $output->footer();
+
+ exit;
}
/**
@@ -978,20 +978,20 @@
function die_friendly($t, $p)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- if ( @ob_get_status() )
- ob_end_clean();
-
- global $output;
-
- $output->set_title($t);
- $template->header();
- echo $p;
- $template->footer();
- $db->close();
-
- exit;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( @ob_get_status() )
+ ob_end_clean();
+
+ global $output;
+
+ $output->set_title($t);
+ $template->header();
+ echo $p;
+ $template->footer();
+ $db->close();
+
+ exit;
}
/**
@@ -1002,47 +1002,47 @@
function grinding_halt($t, $p)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- if ( !defined('scriptPath') )
- require( ENANO_ROOT . '/config.php' );
-
- if ( is_object($db) )
- $db->close();
-
- if ( @ob_get_status() )
- ob_end_clean();
-
- if ( defined('ENANO_CLI') )
- {
- // set console color
- echo "\x1B[31;1m";
- // error title
- echo "Critical error in Enano runtime: ";
- // unbold
- echo "$t\n";
- // bold
- echo "\x1B[37;1m";
- echo "Error: ";
- // unbold
- echo "\x1B[0m";
- echo "$p\n";
- exit(1);
- }
- $theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen';
- $style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu';
-
- $tpl = new template_nodb();
- $tpl->load_theme($theme, $style);
- $tpl->tpl_strings['SITE_NAME'] = 'Critical error';
- $tpl->tpl_strings['SITE_DESC'] = 'This website is experiencing a serious error and cannot load.';
- $tpl->tpl_strings['COPYRIGHT'] = 'Unable to retrieve copyright information';
- $tpl->tpl_strings['PAGE_NAME'] = $t;
- $tpl->header();
- echo $p;
- $tpl->footer();
-
- exit;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( !defined('scriptPath') )
+ require( ENANO_ROOT . '/config.php' );
+
+ if ( is_object($db) )
+ $db->close();
+
+ if ( @ob_get_status() )
+ ob_end_clean();
+
+ if ( defined('ENANO_CLI') )
+ {
+ // set console color
+ echo "\x1B[31;1m";
+ // error title
+ echo "Critical error in Enano runtime: ";
+ // unbold
+ echo "$t\n";
+ // bold
+ echo "\x1B[37;1m";
+ echo "Error: ";
+ // unbold
+ echo "\x1B[0m";
+ echo "$p\n";
+ exit(1);
+ }
+ $theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen';
+ $style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu';
+
+ $tpl = new template_nodb();
+ $tpl->load_theme($theme, $style);
+ $tpl->tpl_strings['SITE_NAME'] = 'Critical error';
+ $tpl->tpl_strings['SITE_DESC'] = 'This website is experiencing a serious error and cannot load.';
+ $tpl->tpl_strings['COPYRIGHT'] = 'Unable to retrieve copyright information';
+ $tpl->tpl_strings['PAGE_NAME'] = $t;
+ $tpl->header();
+ echo $p;
+ $tpl->footer();
+
+ exit;
}
/**
@@ -1051,7 +1051,7 @@
function show_category_info()
{
- throw new Exception('show_category_info() is deprecated. Use Namespace_*::display_categories().');
+ throw new Exception('show_category_info() is deprecated. Use Namespace_*::display_categories().');
}
/**
@@ -1060,7 +1060,7 @@
function show_file_info($page = false)
{
- throw new Exception('show_file_info() is deprecated. Use Namespace_File::show_info().');
+ throw new Exception('show_file_info() is deprecated. Use Namespace_File::show_info().');
}
/**
@@ -1069,7 +1069,7 @@
function display_page_headers()
{
- // Deprecated.
+ // Deprecated.
}
/**
@@ -1078,18 +1078,18 @@
function display_page_footers()
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- if ( isset($_GET['nofooters']) )
- {
- return;
- }
-
- $code = $plugins->setHook('send_page_footers');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( isset($_GET['nofooters']) )
+ {
+ return;
+ }
+
+ $code = $plugins->setHook('send_page_footers');
+ foreach ( $code as $cmd )
+ {
+ eval($cmd);
+ }
}
/**
@@ -1100,34 +1100,34 @@
function display_redirect_notice($page_id, $namespace)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang, $output;
-
- $url = makeUrlNS($namespace, $page_id, false, true);
- $ns = namespace_factory($page_id, $namespace);
- $page_data = $ns->get_cdata();
-
- $title = $page_data['name'];
-
- $cls = $ns->exists() ? '' : 'class="wikilink-nonexistent" ';
-
- $a = '<a ' . $cls . 'href="' . $url . '">' . $title . '</a>';
- $redir_html = '<br /><div class="mdg-infobox">
- <table border="0" width="100%" cellspacing="0" cellpadding="0">
- <tr>
- <td valign="top">
- <img alt="Cute wet-floor icon" src="' . cdnPath . '/images/redirector.png" />
- </td>
- <td valign="top" style="padding-left: 10px;">
- ' . $lang->get('page_msg_this_is_a_redirector', array( 'redirect_target' => $a )) . '
- </td>
- </tr>
- </table>
- </div>
- <br />
- <hr style="margin-left: 1em; width: 200px;" />';
-
- $output->add_after_header($redir_html);
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang, $output;
+
+ $url = makeUrlNS($namespace, $page_id, false, true);
+ $ns = namespace_factory($page_id, $namespace);
+ $page_data = $ns->get_cdata();
+
+ $title = $page_data['name'];
+
+ $cls = $ns->exists() ? '' : 'class="wikilink-nonexistent" ';
+
+ $a = '<a ' . $cls . 'href="' . $url . '">' . $title . '</a>';
+ $redir_html = '<br /><div class="mdg-infobox">
+ <table border="0" width="100%" cellspacing="0" cellpadding="0">
+ <tr>
+ <td valign="top">
+ <img alt="Cute wet-floor icon" src="' . cdnPath . '/images/redirector.png" />
+ </td>
+ <td valign="top" style="padding-left: 10px;">
+ ' . $lang->get('page_msg_this_is_a_redirector', array( 'redirect_target' => $a )) . '
+ </td>
+ </tr>
+ </table>
+ </div>
+ <br />
+ <hr style="margin-left: 1em; width: 200px;" />';
+
+ $output->add_after_header($redir_html);
}
/**
@@ -1138,19 +1138,19 @@
function smtp_get_response($socket, $response, $line = __LINE__)
{
- $server_response = '';
- while (substr($server_response, 3, 1) != ' ')
- {
- if (!($server_response = fgets($socket, 256)))
- {
- die_friendly('SMTP Error', "<p>Couldn't get mail server response codes</p>");
- }
- }
-
- if (!(substr($server_response, 0, 3) == $response))
- {
- die_friendly('SMTP Error', "<p>Ran into problems sending mail. Response: $server_response</p>");
- }
+ $server_response = '';
+ while (substr($server_response, 3, 1) != ' ')
+ {
+ if (!($server_response = fgets($socket, 256)))
+ {
+ die_friendly('SMTP Error', "<p>Couldn't get mail server response codes</p>");
+ }
+ }
+
+ if (!(substr($server_response, 0, 3) == $response))
+ {
+ die_friendly('SMTP Error', "<p>Ran into problems sending mail. Response: $server_response</p>");
+ }
}
/**
@@ -1163,7 +1163,7 @@
function smtp_send_email($to, $subject, $message, $from)
{
- return smtp_send_email_core($to, $subject, $message, "From: <$from>\n");
+ return smtp_send_email_core($to, $subject, $message, "From: <$from>\n");
}
/**
@@ -1178,184 +1178,184 @@
function smtp_send_email_core($mail_to, $subject, $message, $headers = '')
{
- // Fix any bare linefeeds in the message to make it RFC821 Compliant.
- $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
-
- if ($headers != '')
- {
- if (is_array($headers))
- {
- if (sizeof($headers) > 1)
- {
- $headers = join("\n", $headers);
- }
- else
- {
- $headers = $headers[0];
- }
- }
- $headers = chop($headers);
-
- // Make sure there are no bare linefeeds in the headers
- $headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
-
- // Ok this is rather confusing all things considered,
- // but we have to grab bcc and cc headers and treat them differently
- // Something we really didn't take into consideration originally
- $header_array = explode("\r\n", $headers);
- @reset($header_array);
-
- $headers = '';
- $cc = '';
- $bcc = '';
- while(list(, $header) = each($header_array))
- {
- if (preg_match('#^cc:#si', $header))
- {
- $cc = preg_replace('#^cc:(.*)#si', '\1', $header);
- }
- else if (preg_match('#^bcc:#si', $header))
- {
- $bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
- $header = '';
- }
- $headers .= ($header != '') ? $header . "\r\n" : '';
- }
-
- $headers = chop($headers);
- $cc = explode(', ', $cc);
- $bcc = explode(', ', $bcc);
- }
-
- if (trim($subject) == '')
- {
- die_friendly(GENERAL_ERROR, "No email Subject specified");
- }
-
- if (trim($message) == '')
- {
- die_friendly(GENERAL_ERROR, "Email message was blank");
- }
-
- // setup SMTP
- $host = getConfig('smtp_server');
- if ( empty($host) )
- return 'No smtp_host in config';
- if ( strstr($host, ':' ) )
- {
- $n = explode(':', $host);
- $smtp_host = $n[0];
- $port = intval($n[1]);
- }
- else
- {
- $smtp_host = $host;
- $port = 25;
- }
-
- $smtp_user = getConfig('smtp_user');
- $smtp_pass = getConfig('smtp_password');
-
- // Ok we have error checked as much as we can to this point let's get on
- // it already.
- if( !$socket = @fsockopen($smtp_host, $port, $errno, $errstr, 20) )
- {
- die_friendly(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr");
- }
-
- // Wait for reply
- smtp_get_response($socket, "220", __LINE__);
-
- // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
- // This improved as provided by SirSir to accomodate
- if( !empty($smtp_user) && !empty($smtp_pass) )
- {
- enano_fputs($socket, "EHLO " . $smtp_host . "\r\n");
- smtp_get_response($socket, "250", __LINE__);
-
- enano_fputs($socket, "AUTH LOGIN\r\n");
- smtp_get_response($socket, "334", __LINE__);
-
- enano_fputs($socket, base64_encode($smtp_user) . "\r\n");
- smtp_get_response($socket, "334", __LINE__);
-
- enano_fputs($socket, base64_encode($smtp_pass) . "\r\n");
- smtp_get_response($socket, "235", __LINE__);
- }
- else
- {
- enano_fputs($socket, "HELO " . $smtp_host . "\r\n");
- smtp_get_response($socket, "250", __LINE__);
- }
-
- // From this point onward most server response codes should be 250
- // Specify who the mail is from....
- enano_fputs($socket, "MAIL FROM: <" . getConfig('contact_email') . ">\r\n");
- smtp_get_response($socket, "250", __LINE__);
-
- // Specify each user to send to and build to header.
- $to_header = '';
-
- // Add an additional bit of error checking to the To field.
- $mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
- if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
- {
- enano_fputs($socket, "RCPT TO: <$mail_to>\r\n");
- smtp_get_response($socket, "250", __LINE__);
- }
-
- // Ok now do the CC and BCC fields...
- @reset($bcc);
- while(list(, $bcc_address) = each($bcc))
- {
- // Add an additional bit of error checking to bcc header...
- $bcc_address = trim($bcc_address);
- if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
- {
- enano_fputs($socket, "RCPT TO: <$bcc_address>\r\n");
- smtp_get_response($socket, "250", __LINE__);
- }
- }
-
- @reset($cc);
- while(list(, $cc_address) = each($cc))
- {
- // Add an additional bit of error checking to cc header
- $cc_address = trim($cc_address);
- if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
- {
- enano_fputs($socket, "RCPT TO: <$cc_address>\r\n");
- smtp_get_response($socket, "250", __LINE__);
- }
- }
-
- // Ok now we tell the server we are ready to start sending data
- enano_fputs($socket, "DATA\r\n");
-
- // This is the last response code we look for until the end of the message.
- smtp_get_response($socket, "354", __LINE__);
-
- // Send the Subject Line...
- enano_fputs($socket, "Subject: $subject\r\n");
-
- // Now the To Header.
- enano_fputs($socket, "To: $mail_to\r\n");
-
- // Now any custom headers....
- enano_fputs($socket, "$headers\r\n\r\n");
-
- // Ok now we are ready for the message...
- enano_fputs($socket, "$message\r\n");
-
- // Ok the all the ingredients are mixed in let's cook this puppy...
- enano_fputs($socket, ".\r\n");
- smtp_get_response($socket, "250", __LINE__);
-
- // Now tell the server we are done and close the socket...
- enano_fputs($socket, "QUIT\r\n");
- fclose($socket);
-
- return TRUE;
+ // Fix any bare linefeeds in the message to make it RFC821 Compliant.
+ $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
+
+ if ($headers != '')
+ {
+ if (is_array($headers))
+ {
+ if (sizeof($headers) > 1)
+ {
+ $headers = join("\n", $headers);
+ }
+ else
+ {
+ $headers = $headers[0];
+ }
+ }
+ $headers = chop($headers);
+
+ // Make sure there are no bare linefeeds in the headers
+ $headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
+
+ // Ok this is rather confusing all things considered,
+ // but we have to grab bcc and cc headers and treat them differently
+ // Something we really didn't take into consideration originally
+ $header_array = explode("\r\n", $headers);
+ @reset($header_array);
+
+ $headers = '';
+ $cc = '';
+ $bcc = '';
+ while(list(, $header) = each($header_array))
+ {
+ if (preg_match('#^cc:#si', $header))
+ {
+ $cc = preg_replace('#^cc:(.*)#si', '\1', $header);
+ }
+ else if (preg_match('#^bcc:#si', $header))
+ {
+ $bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
+ $header = '';
+ }
+ $headers .= ($header != '') ? $header . "\r\n" : '';
+ }
+
+ $headers = chop($headers);
+ $cc = explode(', ', $cc);
+ $bcc = explode(', ', $bcc);
+ }
+
+ if (trim($subject) == '')
+ {
+ die_friendly(GENERAL_ERROR, "No email Subject specified");
+ }
+
+ if (trim($message) == '')
+ {
+ die_friendly(GENERAL_ERROR, "Email message was blank");
+ }
+
+ // setup SMTP
+ $host = getConfig('smtp_server');
+ if ( empty($host) )
+ return 'No smtp_host in config';
+ if ( strstr($host, ':' ) )
+ {
+ $n = explode(':', $host);
+ $smtp_host = $n[0];
+ $port = intval($n[1]);
+ }
+ else
+ {
+ $smtp_host = $host;
+ $port = 25;
+ }
+
+ $smtp_user = getConfig('smtp_user');
+ $smtp_pass = getConfig('smtp_password');
+
+ // Ok we have error checked as much as we can to this point let's get on
+ // it already.
+ if( !$socket = @fsockopen($smtp_host, $port, $errno, $errstr, 20) )
+ {
+ die_friendly(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr");
+ }
+
+ // Wait for reply
+ smtp_get_response($socket, "220", __LINE__);
+
+ // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
+ // This improved as provided by SirSir to accomodate
+ if( !empty($smtp_user) && !empty($smtp_pass) )
+ {
+ enano_fputs($socket, "EHLO " . $smtp_host . "\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+
+ enano_fputs($socket, "AUTH LOGIN\r\n");
+ smtp_get_response($socket, "334", __LINE__);
+
+ enano_fputs($socket, base64_encode($smtp_user) . "\r\n");
+ smtp_get_response($socket, "334", __LINE__);
+
+ enano_fputs($socket, base64_encode($smtp_pass) . "\r\n");
+ smtp_get_response($socket, "235", __LINE__);
+ }
+ else
+ {
+ enano_fputs($socket, "HELO " . $smtp_host . "\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+ }
+
+ // From this point onward most server response codes should be 250
+ // Specify who the mail is from....
+ enano_fputs($socket, "MAIL FROM: <" . getConfig('contact_email') . ">\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+
+ // Specify each user to send to and build to header.
+ $to_header = '';
+
+ // Add an additional bit of error checking to the To field.
+ $mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
+ if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
+ {
+ enano_fputs($socket, "RCPT TO: <$mail_to>\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+ }
+
+ // Ok now do the CC and BCC fields...
+ @reset($bcc);
+ while(list(, $bcc_address) = each($bcc))
+ {
+ // Add an additional bit of error checking to bcc header...
+ $bcc_address = trim($bcc_address);
+ if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
+ {
+ enano_fputs($socket, "RCPT TO: <$bcc_address>\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+ }
+ }
+
+ @reset($cc);
+ while(list(, $cc_address) = each($cc))
+ {
+ // Add an additional bit of error checking to cc header
+ $cc_address = trim($cc_address);
+ if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
+ {
+ enano_fputs($socket, "RCPT TO: <$cc_address>\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+ }
+ }
+
+ // Ok now we tell the server we are ready to start sending data
+ enano_fputs($socket, "DATA\r\n");
+
+ // This is the last response code we look for until the end of the message.
+ smtp_get_response($socket, "354", __LINE__);
+
+ // Send the Subject Line...
+ enano_fputs($socket, "Subject: $subject\r\n");
+
+ // Now the To Header.
+ enano_fputs($socket, "To: $mail_to\r\n");
+
+ // Now any custom headers....
+ enano_fputs($socket, "$headers\r\n\r\n");
+
+ // Ok now we are ready for the message...
+ enano_fputs($socket, "$message\r\n");
+
+ // Ok the all the ingredients are mixed in let's cook this puppy...
+ enano_fputs($socket, ".\r\n");
+ smtp_get_response($socket, "250", __LINE__);
+
+ // Now tell the server we are done and close the socket...
+ enano_fputs($socket, "QUIT\r\n");
+ fclose($socket);
+
+ return TRUE;
}
/**
@@ -1367,24 +1367,24 @@
function enano_version($long = false, $no_nightly = false)
{
- if ( !defined('ENANO_CONFIG_FETCHED') )
- {
- return function_exists('installer_enano_version') ? installer_enano_version() : $GLOBALS['enano_version'];
- }
- $r = getConfig('enano_version');
- $rc = ( $long ) ? ' release candidate ' : 'RC';
- $b = ( $long ) ? ' beta ' : 'b';
- $a = ( $long ) ? ' alpha ' : 'a';
- if($v = getConfig('enano_rc_version')) $r .= $rc.$v;
- if($v = getConfig('enano_beta_version')) $r .= $b.$v;
- if($v = getConfig('enano_alpha_version')) $r .= $a.$v;
- if ( defined('ENANO_NIGHTLY') && !$no_nightly )
- {
- $nightlytag = ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
- $nightlylong = ' nightly; build date: ' . ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
- $r = ( $long ) ? $r . $nightlylong : $r . '-nightly-' . $nightlytag;
- }
- return $r;
+ if ( !defined('ENANO_CONFIG_FETCHED') )
+ {
+ return function_exists('installer_enano_version') ? installer_enano_version() : $GLOBALS['enano_version'];
+ }
+ $r = getConfig('enano_version');
+ $rc = ( $long ) ? ' release candidate ' : 'RC';
+ $b = ( $long ) ? ' beta ' : 'b';
+ $a = ( $long ) ? ' alpha ' : 'a';
+ if($v = getConfig('enano_rc_version')) $r .= $rc.$v;
+ if($v = getConfig('enano_beta_version')) $r .= $b.$v;
+ if($v = getConfig('enano_alpha_version')) $r .= $a.$v;
+ if ( defined('ENANO_NIGHTLY') && !$no_nightly )
+ {
+ $nightlytag = ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
+ $nightlylong = ' nightly; build date: ' . ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
+ $r = ( $long ) ? $r . $nightlylong : $r . '-nightly-' . $nightlytag;
+ }
+ return $r;
}
/**
@@ -1394,31 +1394,31 @@
function enano_codename()
{
- $names = array(
- '1.0RC1' => 'Leprechaun',
- '1.0RC2' => 'Clurichaun',
- '1.0RC3' => 'Druid',
- '1.0' => 'Banshee',
- '1.0.1' => 'Loch Ness',
- '1.0.1.1'=> 'Loch Ness internal bugfix build',
- '1.0.2b1'=> 'Coblynau unstable',
- '1.0.2' => 'Coblynau',
- '1.0.3' => 'Dyrad',
- '1.1.1' => 'Caoineag alpha 1',
- '1.1.2' => 'Caoineag alpha 2',
- '1.1.3' => 'Caoineag alpha 3',
- '1.1.4' => 'Caoineag alpha 4',
- '1.1.5' => 'Caoineag alpha 5',
- '1.1.6' => 'Caoineag beta 1',
- '1.1.7' => 'Caoineag beta 2',
- '1.1.8' => 'Caoineag beta 3',
- );
- $version = enano_version();
- if ( isset($names[$version]) )
- {
- return $names[$version];
- }
- return 'Anonymous build';
+ $names = array(
+ '1.0RC1' => 'Leprechaun',
+ '1.0RC2' => 'Clurichaun',
+ '1.0RC3' => 'Druid',
+ '1.0' => 'Banshee',
+ '1.0.1' => 'Loch Ness',
+ '1.0.1.1'=> 'Loch Ness internal bugfix build',
+ '1.0.2b1'=> 'Coblynau unstable',
+ '1.0.2' => 'Coblynau',
+ '1.0.3' => 'Dyrad',
+ '1.1.1' => 'Caoineag alpha 1',
+ '1.1.2' => 'Caoineag alpha 2',
+ '1.1.3' => 'Caoineag alpha 3',
+ '1.1.4' => 'Caoineag alpha 4',
+ '1.1.5' => 'Caoineag alpha 5',
+ '1.1.6' => 'Caoineag beta 1',
+ '1.1.7' => 'Caoineag beta 2',
+ '1.1.8' => 'Caoineag beta 3',
+ );
+ $version = enano_version();
+ if ( isset($names[$version]) )
+ {
+ return $names[$version];
+ }
+ return 'Anonymous build';
}
/**
@@ -1427,8 +1427,8 @@
*/
function _die($t) {
- $_ob = 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\'' . rawurlencode('' . $t . '') . '\')';
- die($_ob);
+ $_ob = 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\'' . rawurlencode('' . $t . '') . '\')';
+ die($_ob);
}
/**
@@ -1437,9 +1437,9 @@
*/
function jsdie($text) {
- global $db, $session, $paths, $template, $plugins; // Common objects
- $text = rawurlencode($text . "\n\nSQL Backtrace:\n" . $db->sql_backtrace());
- echo 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.$text.'\');';
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ $text = rawurlencode($text . "\n\nSQL Backtrace:\n" . $db->sql_backtrace());
+ echo 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.$text.'\');';
}
/**
@@ -1450,7 +1450,7 @@
function capitalize_first_letter($text)
{
- return strtoupper(substr($text, 0, 1)) . substr($text, 1);
+ return strtoupper(substr($text, 0, 1)) . substr($text, 1);
}
/**
@@ -1462,7 +1462,7 @@
function is_bit($bitfield, $value)
{
- return ( $bitfield & $value ) ? true : false;
+ return ( $bitfield & $value ) ? true : false;
}
/**
@@ -1473,16 +1473,16 @@
function trim_spaces($text)
{
- $d = true;
- while($d)
- {
- $c = substr($text, 0, 1);
- $a = substr($text, strlen($text)-1, strlen($text));
- if($c == "\n" || $c == "\r" || $c == "\t" || $c == ' ') $text = substr($text, 1, strlen($text));
- elseif($a == "\n" || $a == "\r" || $a == "\t" || $a == ' ') $text = substr($text, 0, strlen($text)-1);
- else $d = false;
- }
- return $text;
+ $d = true;
+ while($d)
+ {
+ $c = substr($text, 0, 1);
+ $a = substr($text, strlen($text)-1, strlen($text));
+ if($c == "\n" || $c == "\r" || $c == "\t" || $c == ' ') $text = substr($text, 1, strlen($text));
+ elseif($a == "\n" || $a == "\r" || $a == "\t" || $a == ' ') $text = substr($text, 0, strlen($text)-1);
+ else $d = false;
+ }
+ return $text;
}
/**
@@ -1494,21 +1494,21 @@
function enano_str_split($text, $inc = 1)
{
- if($inc < 1)
- {
- return false;
- }
- if($inc >= strlen($text))
- {
- return Array($text);
- }
- $len = ceil(strlen($text) / $inc);
- $ret = Array();
- for ( $i = 0; $i < strlen($text); $i = $i + $inc )
- {
- $ret[] = substr($text, $i, $inc);
- }
- return $ret;
+ if($inc < 1)
+ {
+ return false;
+ }
+ if($inc >= strlen($text))
+ {
+ return Array($text);
+ }
+ $len = ceil(strlen($text) / $inc);
+ $ret = Array();
+ for ( $i = 0; $i < strlen($text); $i = $i + $inc )
+ {
+ $ret[] = substr($text, $i, $inc);
+ }
+ return $ret;
}
/**
@@ -1518,13 +1518,13 @@
*/
function hex2bin($text)
{
- $arr = enano_str_split($text, 2);
- $ret = '';
- for ($i=0; $i<sizeof($arr); $i++)
- {
- $ret .= chr(hexdec($arr[$i]));
- }
- return $ret;
+ $arr = enano_str_split($text, 2);
+ $ret = '';
+ for ($i=0; $i<sizeof($arr); $i++)
+ {
+ $ret .= chr(hexdec($arr[$i]));
+ }
+ return $ret;
}
/**
@@ -1535,24 +1535,24 @@
function enano_debug_print_backtrace($return = false)
{
- ob_start();
- if ( !$return )
- echo '<pre>';
- if ( function_exists('debug_print_backtrace') )
- {
- debug_print_backtrace();
- }
- else
- {
- echo '<b>Warning:</b> No debug_print_backtrace() support!';
- }
- if ( !$return )
- echo '</pre>';
- $c = ob_get_contents();
- ob_end_clean();
- if($return) return $c;
- else echo $c;
- return null;
+ ob_start();
+ if ( !$return )
+ echo '<pre>';
+ if ( function_exists('debug_print_backtrace') )
+ {
+ debug_print_backtrace();
+ }
+ else
+ {
+ echo '<b>Warning:</b> No debug_print_backtrace() support!';
+ }
+ if ( !$return )
+ echo '</pre>';
+ $c = ob_get_contents();
+ ob_end_clean();
+ if($return) return $c;
+ else echo $c;
+ return null;
}
/**
@@ -1565,15 +1565,15 @@
function hexencode($text, $prefix = '%', $suffix = '')
{
- $arr = enano_str_split($text);
- $r = '';
- foreach($arr as $a)
- {
- $nibble = (string)dechex(ord($a));
- if(strlen($nibble) == 1) $nibble = '0' . $nibble;
- $r .= $prefix . $nibble . $suffix;
- }
- return $r;
+ $arr = enano_str_split($text);
+ $r = '';
+ foreach($arr as $a)
+ {
+ $nibble = (string)dechex(ord($a));
+ if(strlen($nibble) == 1) $nibble = '0' . $nibble;
+ $r .= $prefix . $nibble . $suffix;
+ }
+ return $r;
}
/**
@@ -1583,14 +1583,14 @@
function enano_get_magic_quotes_gpc()
{
- if(function_exists('get_magic_quotes_gpc'))
- {
- return ( get_magic_quotes_gpc() == 1 );
- }
- else
- {
- return ( strtolower(@ini_get('magic_quotes_gpc')) == '1' );
- }
+ if(function_exists('get_magic_quotes_gpc'))
+ {
+ return ( get_magic_quotes_gpc() == 1 );
+ }
+ else
+ {
+ return ( strtolower(@ini_get('magic_quotes_gpc')) == '1' );
+ }
}
/**
@@ -1601,15 +1601,15 @@
function stripslashes_recurse($arr)
{
- foreach($arr as $k => $xxxx)
- {
- $val =& $arr[$k];
- if(is_string($val))
- $val = stripslashes($val);
- elseif(is_array($val))
- $val = stripslashes_recurse($val);
- }
- return $arr;
+ foreach($arr as $k => $xxxx)
+ {
+ $val =& $arr[$k];
+ if(is_string($val))
+ $val = stripslashes($val);
+ elseif(is_array($val))
+ $val = stripslashes_recurse($val);
+ }
+ return $arr;
}
/**
@@ -1620,15 +1620,15 @@
function strip_nul_chars($arr)
{
- foreach($arr as $k => $xxxx_unused)
- {
- $val =& $arr[$k];
- if(is_string($val))
- $val = str_replace("\000", '', $val);
- elseif(is_array($val))
- $val = strip_nul_chars($val);
- }
- return $arr;
+ foreach($arr as $k => $xxxx_unused)
+ {
+ $val =& $arr[$k];
+ if(is_string($val))
+ $val = str_replace("\000", '', $val);
+ elseif(is_array($val))
+ $val = strip_nul_chars($val);
+ }
+ return $arr;
}
/**
@@ -1639,21 +1639,21 @@
*/
function strip_magic_quotes_gpc()
{
- if(enano_get_magic_quotes_gpc())
- {
- $_POST = stripslashes_recurse($_POST);
- $_GET = stripslashes_recurse($_GET);
- $_COOKIE = stripslashes_recurse($_COOKIE);
- $_REQUEST = stripslashes_recurse($_REQUEST);
- }
- $_POST = strip_nul_chars($_POST);
- $_GET = strip_nul_chars($_GET);
- $_COOKIE = strip_nul_chars($_COOKIE);
- $_REQUEST = strip_nul_chars($_REQUEST);
- $_POST = decode_unicode_array($_POST);
- $_GET = decode_unicode_array($_GET);
- $_COOKIE = decode_unicode_array($_COOKIE);
- $_REQUEST = decode_unicode_array($_REQUEST);
+ if(enano_get_magic_quotes_gpc())
+ {
+ $_POST = stripslashes_recurse($_POST);
+ $_GET = stripslashes_recurse($_GET);
+ $_COOKIE = stripslashes_recurse($_COOKIE);
+ $_REQUEST = stripslashes_recurse($_REQUEST);
+ }
+ $_POST = strip_nul_chars($_POST);
+ $_GET = strip_nul_chars($_GET);
+ $_COOKIE = strip_nul_chars($_COOKIE);
+ $_REQUEST = strip_nul_chars($_REQUEST);
+ $_POST = decode_unicode_array($_POST);
+ $_GET = decode_unicode_array($_GET);
+ $_COOKIE = decode_unicode_array($_COOKIE);
+ $_REQUEST = decode_unicode_array($_REQUEST);
}
/**
@@ -1664,42 +1664,42 @@
function compress_bitfield($bits)
{
- if ( !preg_match('/^[01]+$/', $bits) )
- return false;
-
- $current = intval($bits{0});
- $clen = 0;
- $out = '';
- for ( $i = 0; $i < strlen($bits); $i++ )
- {
- $cbit = intval($bits{$i});
- if ( $cbit !== $current || $clen == 127 || $i == strlen($bits) - 1 )
- {
- if ( $i == strlen($bits) - 1 && $cbit === $current )
- {
- $clen++;
- }
- // write chunk
- $byte = $clen;
- if ( $current === 1 )
- $byte |= 0x80;
- $out .= chr($byte);
-
- if ( $i == strlen($bits) - 1 && $cbit !== $current )
- {
- $out .= ( $cbit === 1 ) ? chr(0x81) : chr(0x1);
- }
-
- // reset
- $current = intval($cbit);
- $clen = 0;
- }
- $clen++;
- }
- $crc = dechex(crc32($out));
- while ( strlen($crc) < 8 )
- $crc = "0$crc";
- return "cbf2:{$crc}" . hexencode($out, '', '');
+ if ( !preg_match('/^[01]+$/', $bits) )
+ return false;
+
+ $current = intval($bits{0});
+ $clen = 0;
+ $out = '';
+ for ( $i = 0; $i < strlen($bits); $i++ )
+ {
+ $cbit = intval($bits{$i});
+ if ( $cbit !== $current || $clen == 127 || $i == strlen($bits) - 1 )
+ {
+ if ( $i == strlen($bits) - 1 && $cbit === $current )
+ {
+ $clen++;
+ }
+ // write chunk
+ $byte = $clen;
+ if ( $current === 1 )
+ $byte |= 0x80;
+ $out .= chr($byte);
+
+ if ( $i == strlen($bits) - 1 && $cbit !== $current )
+ {
+ $out .= ( $cbit === 1 ) ? chr(0x81) : chr(0x1);
+ }
+
+ // reset
+ $current = intval($cbit);
+ $clen = 0;
+ }
+ $clen++;
+ }
+ $crc = dechex(crc32($out));
+ while ( strlen($crc) < 8 )
+ $crc = "0$crc";
+ return "cbf2:{$crc}" . hexencode($out, '', '');
}
// test case
@@ -1714,36 +1714,36 @@
function uncompress_bitfield($bits)
{
- if ( substr($bits, 0, 4) == 'cbf:' )
- {
- return uncompress_bitfield_old($bits);
- }
- if ( substr($bits, 0, 5) != 'cbf2:' )
- {
- echo __FUNCTION__.'(): ERROR: Invalid stream';
- return false;
- }
- $bits = substr($bits, 5);
- $crc = substr($bits, 0, 8);
- $bits = substr($bits, 8);
- $bits = hexdecode($bits);
- if ( dechex(crc32($bits)) !== $crc )
- {
- echo __FUNCTION__."(): ERROR: CRC failed";
- return false;
- }
- $out = '';
- for ( $i = 0; $i < strlen($bits); $i++ )
- {
- $byte = ord($bits{$i});
- $char = $byte & 0x80 ? '1' : '0';
- $byte &= ~0x80;
- for ( $j = 0; $j < $byte; $j++ )
- {
- $out .= $char;
- }
- }
- return $out;
+ if ( substr($bits, 0, 4) == 'cbf:' )
+ {
+ return uncompress_bitfield_old($bits);
+ }
+ if ( substr($bits, 0, 5) != 'cbf2:' )
+ {
+ echo __FUNCTION__.'(): ERROR: Invalid stream';
+ return false;
+ }
+ $bits = substr($bits, 5);
+ $crc = substr($bits, 0, 8);
+ $bits = substr($bits, 8);
+ $bits = hexdecode($bits);
+ if ( dechex(crc32($bits)) !== $crc )
+ {
+ echo __FUNCTION__."(): ERROR: CRC failed";
+ return false;
+ }
+ $out = '';
+ for ( $i = 0; $i < strlen($bits); $i++ )
+ {
+ $byte = ord($bits{$i});
+ $char = $byte & 0x80 ? '1' : '0';
+ $byte &= ~0x80;
+ for ( $j = 0; $j < $byte; $j++ )
+ {
+ $out .= $char;
+ }
+ }
+ return $out;
}
/**
@@ -1755,34 +1755,34 @@
function uncompress_bitfield_old($bits)
{
- if(substr($bits, 0, 4) != 'cbf:')
- {
- echo __FUNCTION__.'(): ERROR: Invalid stream';
- return false;
- }
- $len = intval(substr($bits, strpos($bits, 'len=')+4, strpos($bits, ';')-strpos($bits, 'len=')-4));
- $crc = substr($bits, strpos($bits, 'crc=')+4, 8);
- $data = substr($bits, strpos($bits, 'data=')+5, strpos($bits, '|end')-strpos($bits, 'data=')-5);
- $data = explode(',', $data);
- foreach($data as $a => $b)
- {
- $d =& $data[$a];
- $char = substr($d, 0, 1);
- $dlen = intval(substr($d, 2, strlen($d)-1));
- $s = '';
- for($i=0;$i<$dlen;$i++,$s.=$char);
- $d = $s;
- unset($s, $dlen, $char);
- }
- $decompressed = implode('', $data);
- $decompressed = substr($decompressed, 0, -1);
- $dcrc = (string)dechex(crc32($decompressed));
- if($dcrc != $crc)
- {
- echo __FUNCTION__.'(): ERROR: CRC check failed<br />debug info:<br />original crc: '.$crc.'<br />decomp\'ed crc: '.$dcrc.'<br />';
- return false;
- }
- return $decompressed;
+ if(substr($bits, 0, 4) != 'cbf:')
+ {
+ echo __FUNCTION__.'(): ERROR: Invalid stream';
+ return false;
+ }
+ $len = intval(substr($bits, strpos($bits, 'len=')+4, strpos($bits, ';')-strpos($bits, 'len=')-4));
+ $crc = substr($bits, strpos($bits, 'crc=')+4, 8);
+ $data = substr($bits, strpos($bits, 'data=')+5, strpos($bits, '|end')-strpos($bits, 'data=')-5);
+ $data = explode(',', $data);
+ foreach($data as $a => $b)
+ {
+ $d =& $data[$a];
+ $char = substr($d, 0, 1);
+ $dlen = intval(substr($d, 2, strlen($d)-1));
+ $s = '';
+ for($i=0;$i<$dlen;$i++,$s.=$char);
+ $d = $s;
+ unset($s, $dlen, $char);
+ }
+ $decompressed = implode('', $data);
+ $decompressed = substr($decompressed, 0, -1);
+ $dcrc = (string)dechex(crc32($decompressed));
+ if($dcrc != $crc)
+ {
+ echo __FUNCTION__.'(): ERROR: CRC check failed<br />debug info:<br />original crc: '.$crc.'<br />decomp\'ed crc: '.$dcrc.'<br />';
+ return false;
+ }
+ return $decompressed;
}
/**
@@ -1796,125 +1796,125 @@
function export_table($table, $structure = true, $data = true, $compact = false)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- $struct_keys = '';
- $divider = (!$compact) ? "\n" : "\n";
- $spacer1 = (!$compact) ? "\n" : " ";
- $spacer2 = (!$compact) ? " " : " ";
- $rowspacer = (!$compact) ? "\n " : " ";
- $index_list = Array();
- $cols = $db->sql_query('SHOW COLUMNS IN '.$table.';');
- if(!$cols)
- {
- echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
- return false;
- }
- $col = Array();
- $sqlcol = Array();
- $collist = Array();
- $pri_keys = Array();
- // Using fetchrow_num() here to compensate for MySQL l10n
- while( $row = $db->fetchrow_num() )
- {
- $field =& $row[0];
- $type =& $row[1];
- $null =& $row[2];
- $key =& $row[3];
- $def =& $row[4];
- $extra =& $row[5];
- $col[] = Array(
- 'name'=>$field,
- 'type'=>$type,
- 'null'=>$null,
- 'key'=>$key,
- 'default'=>$def,
- 'extra'=>$extra,
- );
- $collist[] = $field;
- }
-
- if ( $structure )
- {
- $db->sql_query('SET SQL_QUOTE_SHOW_CREATE = 0;');
- $struct = $db->sql_query('SHOW CREATE TABLE '.$table.';');
- if ( !$struct )
- $db->_die();
- $row = $db->fetchrow_num();
- $db->free_result();
- $struct = $row[1];
- $struct = preg_replace("/\n\) ENGINE=(.+)$/", "\n);", $struct);
- unset($row);
- if ( $compact )
- {
- $struct_arr = explode("\n", $struct);
- foreach ( $struct_arr as $i => $leg )
- {
- if ( $i == 0 )
- continue;
- $test = trim($leg);
- if ( empty($test) )
- {
- unset($struct_arr[$i]);
- continue;
- }
- $struct_arr[$i] = preg_replace('/^([\s]*)/', ' ', $leg);
- }
- $struct = implode("", $struct_arr);
- }
- }
-
- // Structuring complete
- if($data)
- {
- $datq = $db->sql_query('SELECT * FROM '.$table.';');
- if(!$datq)
- {
- echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
- return false;
- }
- if($db->numrows() < 1)
- {
- if($structure) return $struct;
- else return '';
- }
- $rowdata = Array();
- $dataqs = Array();
- $insert_strings = Array();
- $z = false;
- while($row = $db->fetchrow_num())
- {
- $z = false;
- foreach($row as $i => $cell)
- {
- $str = mysql_encode_column($cell, $col[$i]['type']);
- $rowdata[] = $str;
- }
- $dataqs2 = implode(",$rowspacer", $dataqs) . ",$rowspacer" . '( ' . implode(', ', $rowdata) . ' )';
- $ins = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . $dataqs2 . ";";
- if ( strlen( $ins ) > MYSQL_MAX_PACKET_SIZE )
- {
- // We've exceeded the maximum allowed packet size for MySQL - separate this into a different query
- $insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
- $dataqs = Array('( ' . implode(', ', $rowdata) . ' )');
- $z = true;
- }
- else
- {
- $dataqs[] = '( ' . implode(', ', $rowdata) . ' )';
- }
- $rowdata = Array();
- }
- if ( !$z )
- {
- $insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
- $dataqs = Array();
- }
- $datstring = implode($divider, $insert_strings);
- }
- if($structure && !$data) return $struct;
- elseif(!$structure && $data) return $datstring;
- elseif($structure && $data) return $struct . $divider . $datstring;
- elseif(!$structure && !$data) return '';
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ $struct_keys = '';
+ $divider = (!$compact) ? "\n" : "\n";
+ $spacer1 = (!$compact) ? "\n" : " ";
+ $spacer2 = (!$compact) ? " " : " ";
+ $rowspacer = (!$compact) ? "\n " : " ";
+ $index_list = Array();
+ $cols = $db->sql_query('SHOW COLUMNS IN '.$table.';');
+ if(!$cols)
+ {
+ echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
+ return false;
+ }
+ $col = Array();
+ $sqlcol = Array();
+ $collist = Array();
+ $pri_keys = Array();
+ // Using fetchrow_num() here to compensate for MySQL l10n
+ while( $row = $db->fetchrow_num() )
+ {
+ $field =& $row[0];
+ $type =& $row[1];
+ $null =& $row[2];
+ $key =& $row[3];
+ $def =& $row[4];
+ $extra =& $row[5];
+ $col[] = Array(
+ 'name'=>$field,
+ 'type'=>$type,
+ 'null'=>$null,
+ 'key'=>$key,
+ 'default'=>$def,
+ 'extra'=>$extra,
+ );
+ $collist[] = $field;
+ }
+
+ if ( $structure )
+ {
+ $db->sql_query('SET SQL_QUOTE_SHOW_CREATE = 0;');
+ $struct = $db->sql_query('SHOW CREATE TABLE '.$table.';');
+ if ( !$struct )
+ $db->_die();
+ $row = $db->fetchrow_num();
+ $db->free_result();
+ $struct = $row[1];
+ $struct = preg_replace("/\n\) ENGINE=(.+)$/", "\n);", $struct);
+ unset($row);
+ if ( $compact )
+ {
+ $struct_arr = explode("\n", $struct);
+ foreach ( $struct_arr as $i => $leg )
+ {
+ if ( $i == 0 )
+ continue;
+ $test = trim($leg);
+ if ( empty($test) )
+ {
+ unset($struct_arr[$i]);
+ continue;
+ }
+ $struct_arr[$i] = preg_replace('/^([\s]*)/', ' ', $leg);
+ }
+ $struct = implode("", $struct_arr);
+ }
+ }
+
+ // Structuring complete
+ if($data)
+ {
+ $datq = $db->sql_query('SELECT * FROM '.$table.';');
+ if(!$datq)
+ {
+ echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
+ return false;
+ }
+ if($db->numrows() < 1)
+ {
+ if($structure) return $struct;
+ else return '';
+ }
+ $rowdata = Array();
+ $dataqs = Array();
+ $insert_strings = Array();
+ $z = false;
+ while($row = $db->fetchrow_num())
+ {
+ $z = false;
+ foreach($row as $i => $cell)
+ {
+ $str = mysql_encode_column($cell, $col[$i]['type']);
+ $rowdata[] = $str;
+ }
+ $dataqs2 = implode(",$rowspacer", $dataqs) . ",$rowspacer" . '( ' . implode(', ', $rowdata) . ' )';
+ $ins = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . $dataqs2 . ";";
+ if ( strlen( $ins ) > MYSQL_MAX_PACKET_SIZE )
+ {
+ // We've exceeded the maximum allowed packet size for MySQL - separate this into a different query
+ $insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
+ $dataqs = Array('( ' . implode(', ', $rowdata) . ' )');
+ $z = true;
+ }
+ else
+ {
+ $dataqs[] = '( ' . implode(', ', $rowdata) . ' )';
+ }
+ $rowdata = Array();
+ }
+ if ( !$z )
+ {
+ $insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
+ $dataqs = Array();
+ }
+ $datstring = implode($divider, $insert_strings);
+ }
+ if($structure && !$data) return $struct;
+ elseif(!$structure && $data) return $datstring;
+ elseif($structure && $data) return $struct . $divider . $datstring;
+ elseif(!$structure && !$data) return '';
}
/**
@@ -1924,25 +1924,25 @@
function mysql_encode_column($input, $type)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- // Decide whether to quote the string or not
- if(substr($type, 0, 7) == 'varchar' || $type == 'datetime' || $type == 'text' || $type == 'tinytext' || $type == 'smalltext' || $type == 'longtext' || substr($type, 0, 4) == 'char')
- {
- $str = "'" . $db->escape($input) . "'";
- }
- elseif(in_array($type, Array('blob', 'longblob', 'mediumblob', 'smallblob')) || substr($type, 0, 6) == 'binary' || substr($type, 0, 9) == 'varbinary')
- {
- $str = '0x' . hexencode($input, '', '');
- }
- elseif(is_null($input))
- {
- $str = 'NULL';
- }
- else
- {
- $str = (string)$input;
- }
- return $str;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ // Decide whether to quote the string or not
+ if(substr($type, 0, 7) == 'varchar' || $type == 'datetime' || $type == 'text' || $type == 'tinytext' || $type == 'smalltext' || $type == 'longtext' || substr($type, 0, 4) == 'char')
+ {
+ $str = "'" . $db->escape($input) . "'";
+ }
+ elseif(in_array($type, Array('blob', 'longblob', 'mediumblob', 'smallblob')) || substr($type, 0, 6) == 'binary' || substr($type, 0, 9) == 'varbinary')
+ {
+ $str = '0x' . hexencode($input, '', '');
+ }
+ elseif(is_null($input))
+ {
+ $str = 'NULL';
+ }
+ else
+ {
+ $str = (string)$input;
+ }
+ return $str;
}
/**
@@ -1952,19 +1952,19 @@
function fetch_allowed_extensions()
{
- global $mime_types;
- $bits = getConfig('allowed_mime_types');
- if(!$bits) return Array(false);
- $bits = uncompress_bitfield($bits);
- if(!$bits) return Array(false);
- $bits = enano_str_split($bits, 1);
- $ret = Array();
- $mt = array_keys($mime_types);
- foreach($bits as $i => $b)
- {
- $ret[$mt[$i]] = ( $b == '1' ) ? true : false;
- }
- return $ret;
+ global $mime_types;
+ $bits = getConfig('allowed_mime_types');
+ if(!$bits) return Array(false);
+ $bits = uncompress_bitfield($bits);
+ if(!$bits) return Array(false);
+ $bits = enano_str_split($bits, 1);
+ $ret = Array();
+ $mt = array_keys($mime_types);
+ foreach($bits as $i => $b)
+ {
+ $ret[$mt[$i]] = ( $b == '1' ) ? true : false;
+ }
+ return $ret;
}
/**
@@ -1975,12 +1975,12 @@
function randkey($len = 32)
{
- $key = '';
- for($i=0;$i<$len;$i++)
- {
- $key .= chr(mt_rand(0, 255));
- }
- return $key;
+ $key = '';
+ for($i=0;$i<$len;$i++)
+ {
+ $key .= chr(mt_rand(0, 255));
+ }
+ return $key;
}
/**
@@ -1991,14 +1991,14 @@
function hexdecode($hex)
{
- $hex = enano_str_split($hex, 2);
- $bin_key = '';
- foreach($hex as $nibble)
- {
- $byte = chr(hexdec($nibble));
- $bin_key .= $byte;
- }
- return $bin_key;
+ $hex = enano_str_split($hex, 2);
+ $bin_key = '';
+ foreach($hex as $nibble)
+ {
+ $byte = chr(hexdec($nibble));
+ $bin_key .= $byte;
+ }
+ return $bin_key;
}
/**
@@ -2009,166 +2009,166 @@
function sanitize_html($html, $filter_php = true)
{
- // Random seed for substitution
- $rand_seed = md5( sha1(microtime()) . mt_rand() );
-
- // We need MediaWiki
- require_once(ENANO_ROOT . '/includes/wikiengine/TagSanitizer.php');
-
- // Strip out comments that are already escaped
- preg_match_all('/<!--(.*?)-->/', $html, $comment_match);
- $i = 0;
- foreach ( $comment_match[0] as $comment )
- {
- $html = str_replace_once($comment, "{HTMLCOMMENT:$i:$rand_seed}", $html);
- $i++;
- }
-
- // Strip out code sections that will be postprocessed by Text_Wiki
- preg_match_all(';^<code(\s[^>]*)?>((?:(?R)|.)*?)</code>(\s|$);msi', $html, $code_match);
- $i = 0;
- foreach ( $code_match[0] as $code )
- {
- $html = str_replace_once($code, "{TW_CODE:$i:$rand_seed}", $html);
- $i++;
- }
-
- $html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>(.*?)</\\1>#is', '<\\1\\2\\3javascript:\\59>\\60</\\1>', $html);
- $html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>#is', '<\\1\\2\\3javascript:\\59>', $html);
-
- if($filter_php)
- $html = str_replace(
- Array('<?php', '<?', '<%', '?>', '%>'),
- Array('<?php', '<?', '<%', '?>', '%>'),
- $html);
-
- $tag_whitelist = array_keys ( setupAttributeWhitelist() );
- if ( !$filter_php )
- $tag_whitelist[] = '?php';
- // allow HTML comments
- $tag_whitelist[] = '!--';
- $len = strlen($html);
- $in_quote = false;
- $quote_char = '';
- $tag_start = 0;
- $tag_name = '';
- $in_tag = false;
- $trk_name = false;
- for ( $i = 0; $i < $len; $i++ )
- {
- $chr = $html{$i};
- $prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
- $next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
- if ( $in_quote && $in_tag )
- {
- if ( $quote_char == $chr && $prev != '\\' )
- $in_quote = false;
- }
- elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
- {
- $in_quote = true;
- $quote_char = $chr;
- }
- if ( $chr == '<' && !$in_tag && $next != '/' )
- {
- // start of a tag
- $tag_start = $i;
- $in_tag = true;
- $trk_name = true;
- }
- elseif ( !$in_quote && $in_tag && $chr == '>' )
- {
- $full_tag = substr($html, $tag_start, ( $i - $tag_start ) + 1 );
- $l = strlen($tag_name) + 2;
- $attribs_only = trim( substr($full_tag, $l, ( strlen($full_tag) - $l - 1 ) ) );
-
- // Debugging message
- // echo htmlspecialchars($full_tag) . '<br />';
-
- if ( !in_array($tag_name, $tag_whitelist) && substr($tag_name, 0, 3) != '!--' )
- {
- // Illegal tag
- //echo $tag_name . ' ';
-
- $s = ( empty($attribs_only) ) ? '' : ' ';
-
- $sanitized = '<' . $tag_name . $s . $attribs_only . '>';
-
- $html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
- $html = str_replace('</' . $tag_name . '>', '</' . $tag_name . '>', $html);
- $new_i = $tag_start + strlen($sanitized);
-
- $len = strlen($html);
- $i = $new_i;
-
- $in_tag = false;
- $tag_name = '';
- continue;
- }
- else
- {
- // If not filtering PHP, don't bother to strip
- if ( $tag_name == '?php' && !$filter_php )
- continue;
- // If this is a comment, likewise skip this "tag"
- if ( $tag_name == '!--' )
- continue;
- $f = fixTagAttributes( $attribs_only, $tag_name );
- $s = ( empty($f) ) ? '' : ' ';
-
- $sanitized = '<' . $tag_name . $f . '>';
- $new_i = $tag_start + strlen($sanitized);
-
- $html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
- $len = strlen($html);
- $i = $new_i;
-
- $in_tag = false;
- $tag_name = '';
- continue;
- }
- }
- elseif ( $in_tag && $trk_name )
- {
- $is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
- if ( $is_alphabetical )
- $tag_name .= $chr;
- else
- {
- $trk_name = false;
- }
- }
-
- }
-
- // Vulnerability from ha.ckers.org/xss.html:
- // <script src="http://foo.com/xss.js"
- // <
- // The rule is so specific because everything else will have been filtered by now
- $html = preg_replace('/<(script|iframe)(.+?)src=([^>]*)</i', '<\\1\\2src=\\3<', $html);
-
- // Vulnerability reported by fuzion from nukeit.org:
- // XSS in closing HTML tag style attribute
- // Fix: escape all closing tags with non-whitelisted characters
- $html = preg_replace('!</((?:[^>]*)([^a-z0-9_:>-]+)(?:[^>]*))>!i', '</\\1>', $html);
-
- // Restore stripped comments
- $i = 0;
- foreach ( $comment_match[0] as $comment )
- {
- $html = str_replace_once("{HTMLCOMMENT:$i:$rand_seed}", $comment, $html);
- $i++;
- }
-
- // Restore stripped code
- $i = 0;
- foreach ( $code_match[0] as $code )
- {
- $html = str_replace_once("{TW_CODE:$i:$rand_seed}", $code, $html);
- $i++;
- }
-
- return $html;
+ // Random seed for substitution
+ $rand_seed = md5( sha1(microtime()) . mt_rand() );
+
+ // We need MediaWiki
+ require_once(ENANO_ROOT . '/includes/wikiengine/TagSanitizer.php');
+
+ // Strip out comments that are already escaped
+ preg_match_all('/<!--(.*?)-->/', $html, $comment_match);
+ $i = 0;
+ foreach ( $comment_match[0] as $comment )
+ {
+ $html = str_replace_once($comment, "{HTMLCOMMENT:$i:$rand_seed}", $html);
+ $i++;
+ }
+
+ // Strip out code sections that will be postprocessed by Text_Wiki
+ preg_match_all(';^<code(\s[^>]*)?>((?:(?R)|.)*?)</code>(\s|$);msi', $html, $code_match);
+ $i = 0;
+ foreach ( $code_match[0] as $code )
+ {
+ $html = str_replace_once($code, "{TW_CODE:$i:$rand_seed}", $html);
+ $i++;
+ }
+
+ $html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>(.*?)</\\1>#is', '<\\1\\2\\3javascript:\\59>\\60</\\1>', $html);
+ $html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>#is', '<\\1\\2\\3javascript:\\59>', $html);
+
+ if($filter_php)
+ $html = str_replace(
+ Array('<?php', '<?', '<%', '?>', '%>'),
+ Array('<?php', '<?', '<%', '?>', '%>'),
+ $html);
+
+ $tag_whitelist = array_keys ( setupAttributeWhitelist() );
+ if ( !$filter_php )
+ $tag_whitelist[] = '?php';
+ // allow HTML comments
+ $tag_whitelist[] = '!--';
+ $len = strlen($html);
+ $in_quote = false;
+ $quote_char = '';
+ $tag_start = 0;
+ $tag_name = '';
+ $in_tag = false;
+ $trk_name = false;
+ for ( $i = 0; $i < $len; $i++ )
+ {
+ $chr = $html{$i};
+ $prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
+ $next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
+ if ( $in_quote && $in_tag )
+ {
+ if ( $quote_char == $chr && $prev != '\\' )
+ $in_quote = false;
+ }
+ elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
+ {
+ $in_quote = true;
+ $quote_char = $chr;
+ }
+ if ( $chr == '<' && !$in_tag && $next != '/' )
+ {
+ // start of a tag
+ $tag_start = $i;
+ $in_tag = true;
+ $trk_name = true;
+ }
+ elseif ( !$in_quote && $in_tag && $chr == '>' )
+ {
+ $full_tag = substr($html, $tag_start, ( $i - $tag_start ) + 1 );
+ $l = strlen($tag_name) + 2;
+ $attribs_only = trim( substr($full_tag, $l, ( strlen($full_tag) - $l - 1 ) ) );
+
+ // Debugging message
+ // echo htmlspecialchars($full_tag) . '<br />';
+
+ if ( !in_array($tag_name, $tag_whitelist) && substr($tag_name, 0, 3) != '!--' )
+ {
+ // Illegal tag
+ //echo $tag_name . ' ';
+
+ $s = ( empty($attribs_only) ) ? '' : ' ';
+
+ $sanitized = '<' . $tag_name . $s . $attribs_only . '>';
+
+ $html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
+ $html = str_replace('</' . $tag_name . '>', '</' . $tag_name . '>', $html);
+ $new_i = $tag_start + strlen($sanitized);
+
+ $len = strlen($html);
+ $i = $new_i;
+
+ $in_tag = false;
+ $tag_name = '';
+ continue;
+ }
+ else
+ {
+ // If not filtering PHP, don't bother to strip
+ if ( $tag_name == '?php' && !$filter_php )
+ continue;
+ // If this is a comment, likewise skip this "tag"
+ if ( $tag_name == '!--' )
+ continue;
+ $f = fixTagAttributes( $attribs_only, $tag_name );
+ $s = ( empty($f) ) ? '' : ' ';
+
+ $sanitized = '<' . $tag_name . $f . '>';
+ $new_i = $tag_start + strlen($sanitized);
+
+ $html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
+ $len = strlen($html);
+ $i = $new_i;
+
+ $in_tag = false;
+ $tag_name = '';
+ continue;
+ }
+ }
+ elseif ( $in_tag && $trk_name )
+ {
+ $is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
+ if ( $is_alphabetical )
+ $tag_name .= $chr;
+ else
+ {
+ $trk_name = false;
+ }
+ }
+
+ }
+
+ // Vulnerability from ha.ckers.org/xss.html:
+ // <script src="http://foo.com/xss.js"
+ // <
+ // The rule is so specific because everything else will have been filtered by now
+ $html = preg_replace('/<(script|iframe)(.+?)src=([^>]*)</i', '<\\1\\2src=\\3<', $html);
+
+ // Vulnerability reported by fuzion from nukeit.org:
+ // XSS in closing HTML tag style attribute
+ // Fix: escape all closing tags with non-whitelisted characters
+ $html = preg_replace('!</((?:[^>]*)([^a-z0-9_:>-]+)(?:[^>]*))>!i', '</\\1>', $html);
+
+ // Restore stripped comments
+ $i = 0;
+ foreach ( $comment_match[0] as $comment )
+ {
+ $html = str_replace_once("{HTMLCOMMENT:$i:$rand_seed}", $comment, $html);
+ $i++;
+ }
+
+ // Restore stripped code
+ $i = 0;
+ foreach ( $code_match[0] as $code )
+ {
+ $html = str_replace_once("{TW_CODE:$i:$rand_seed}", $code, $html);
+ $i++;
+ }
+
+ return $html;
}
/**
@@ -2180,162 +2180,162 @@
function wikiformat_process_block($html)
{
- $tok1 = "<litewiki>";
- $tok2 = "</litewiki>";
-
- $block_tags = array('div', 'p', 'table', 'blockquote', 'pre');
-
- $len = strlen($html);
- $in_quote = false;
- $quote_char = '';
- $tag_start = 0;
- $tag_name = '';
- $in_tag = false;
- $trk_name = false;
-
- $diag = 0;
-
- $block_tagname = '';
- $in_blocksec = 0;
- $block_start = 0;
-
- for ( $i = 0; $i < $len; $i++ )
- {
- $chr = $html{$i};
- $prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
- $next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
-
- // Are we inside of a quoted section?
- if ( $in_quote && $in_tag )
- {
- if ( $quote_char == $chr && $prev != '\\' )
- $in_quote = false;
- }
- elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
- {
- $in_quote = true;
- $quote_char = $chr;
- }
-
- if ( $chr == '<' && !$in_tag && $next == '/' )
- {
- // Iterate through until we've got a tag name
- $tag_name = '';
- $i++;
- while(true)
- {
- $i++;
- // echo $i . ' ';
- $chr = $html{$i};
- $prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
- $next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
- $tag_name .= $chr;
- if ( $next == '>' )
- break;
- }
- // echo '<br />';
- if ( in_array($tag_name, $block_tags) )
- {
- if ( $block_tagname == $tag_name )
- {
- $in_blocksec -= 1;
- if ( $in_blocksec == 0 )
- {
- $block_tagname = '';
- $i += 2;
- // echo 'Finished wiki litewiki wraparound calc at pos: ' . $i;
- $full_litewiki = substr($html, $block_start, ( $i - $block_start ));
- $new_text = "{$tok1}{$full_litewiki}{$tok2}";
- $html = substr($html, 0, $block_start) . $new_text . substr($html, $i);
-
- $i += ( strlen($tok1) + strlen($tok2) ) - 1;
- $len = strlen($html);
-
- //die('<pre>' . htmlspecialchars($html) . '</pre>');
- }
- }
- }
-
- $in_tag = false;
- $in_quote = false;
- $tag_name = '';
-
- continue;
- }
- else if ( $chr == '<' && !$in_tag && $next != '/' )
- {
- // start of a tag
- $tag_start = $i;
- $in_tag = true;
- $trk_name = true;
- }
- else if ( !$in_quote && $in_tag && $chr == '>' )
- {
- if ( !in_array($tag_name, $block_tags) )
- {
- // Inline tag - reset and go to the next one
- // echo '<inline ' . $tag_name . '> ';
-
- $in_tag = false;
- $tag_name = '';
- continue;
- }
- else
- {
- // echo '<block: ' . $tag_name . ' @ ' . $i . '><br/>';
- if ( $in_blocksec == 0 )
- {
- //die('Found a starting tag for a block element: ' . $tag_name . ' at pos ' . $tag_start);
- $block_tagname = $tag_name;
- $block_start = $tag_start;
- $in_blocksec++;
- }
- else if ( $block_tagname == $tag_name )
- {
- $in_blocksec++;
- }
-
- $in_tag = false;
- $tag_name = '';
- continue;
- }
- }
- elseif ( $in_tag && $trk_name )
- {
- $is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
- if ( $is_alphabetical )
- $tag_name .= $chr;
- else
- {
- $trk_name = false;
- }
- }
-
- // Tokenization complete
-
- }
-
- $regex = '/' . str_replace('/', '\\/', preg_quote($tok2)) . '([\s]*)' . preg_quote($tok1) . '/is';
- // die(htmlspecialchars($regex));
- $html = preg_replace($regex, '\\1', $html);
-
- return $html;
+ $tok1 = "<litewiki>";
+ $tok2 = "</litewiki>";
+
+ $block_tags = array('div', 'p', 'table', 'blockquote', 'pre');
+
+ $len = strlen($html);
+ $in_quote = false;
+ $quote_char = '';
+ $tag_start = 0;
+ $tag_name = '';
+ $in_tag = false;
+ $trk_name = false;
+
+ $diag = 0;
+
+ $block_tagname = '';
+ $in_blocksec = 0;
+ $block_start = 0;
+
+ for ( $i = 0; $i < $len; $i++ )
+ {
+ $chr = $html{$i};
+ $prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
+ $next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
+
+ // Are we inside of a quoted section?
+ if ( $in_quote && $in_tag )
+ {
+ if ( $quote_char == $chr && $prev != '\\' )
+ $in_quote = false;
+ }
+ elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
+ {
+ $in_quote = true;
+ $quote_char = $chr;
+ }
+
+ if ( $chr == '<' && !$in_tag && $next == '/' )
+ {
+ // Iterate through until we've got a tag name
+ $tag_name = '';
+ $i++;
+ while(true)
+ {
+ $i++;
+ // echo $i . ' ';
+ $chr = $html{$i};
+ $prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
+ $next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
+ $tag_name .= $chr;
+ if ( $next == '>' )
+ break;
+ }
+ // echo '<br />';
+ if ( in_array($tag_name, $block_tags) )
+ {
+ if ( $block_tagname == $tag_name )
+ {
+ $in_blocksec -= 1;
+ if ( $in_blocksec == 0 )
+ {
+ $block_tagname = '';
+ $i += 2;
+ // echo 'Finished wiki litewiki wraparound calc at pos: ' . $i;
+ $full_litewiki = substr($html, $block_start, ( $i - $block_start ));
+ $new_text = "{$tok1}{$full_litewiki}{$tok2}";
+ $html = substr($html, 0, $block_start) . $new_text . substr($html, $i);
+
+ $i += ( strlen($tok1) + strlen($tok2) ) - 1;
+ $len = strlen($html);
+
+ //die('<pre>' . htmlspecialchars($html) . '</pre>');
+ }
+ }
+ }
+
+ $in_tag = false;
+ $in_quote = false;
+ $tag_name = '';
+
+ continue;
+ }
+ else if ( $chr == '<' && !$in_tag && $next != '/' )
+ {
+ // start of a tag
+ $tag_start = $i;
+ $in_tag = true;
+ $trk_name = true;
+ }
+ else if ( !$in_quote && $in_tag && $chr == '>' )
+ {
+ if ( !in_array($tag_name, $block_tags) )
+ {
+ // Inline tag - reset and go to the next one
+ // echo '<inline ' . $tag_name . '> ';
+
+ $in_tag = false;
+ $tag_name = '';
+ continue;
+ }
+ else
+ {
+ // echo '<block: ' . $tag_name . ' @ ' . $i . '><br/>';
+ if ( $in_blocksec == 0 )
+ {
+ //die('Found a starting tag for a block element: ' . $tag_name . ' at pos ' . $tag_start);
+ $block_tagname = $tag_name;
+ $block_start = $tag_start;
+ $in_blocksec++;
+ }
+ else if ( $block_tagname == $tag_name )
+ {
+ $in_blocksec++;
+ }
+
+ $in_tag = false;
+ $tag_name = '';
+ continue;
+ }
+ }
+ elseif ( $in_tag && $trk_name )
+ {
+ $is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
+ if ( $is_alphabetical )
+ $tag_name .= $chr;
+ else
+ {
+ $trk_name = false;
+ }
+ }
+
+ // Tokenization complete
+
+ }
+
+ $regex = '/' . str_replace('/', '\\/', preg_quote($tok2)) . '([\s]*)' . preg_quote($tok1) . '/is';
+ // die(htmlspecialchars($regex));
+ $html = preg_replace($regex, '\\1', $html);
+
+ return $html;
}
function htmlalternatives($string)
{
- $ret = '';
- for ( $i = 0; $i < strlen($string); $i++ )
- {
- $chr = $string{$i};
- $ch1 = ord($chr);
- $ch2 = dechex($ch1);
- $byte = '(&\\#([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch2 . ';|&\\#x([0]*){0,7}' . $ch2 . ';|%([0]*){0,7}' . $ch2 . '|' . preg_quote($chr) . ')';
- $ret .= $byte;
- $ret .= '([\s]){0,2}';
- }
- return $ret;
+ $ret = '';
+ for ( $i = 0; $i < strlen($string); $i++ )
+ {
+ $chr = $string{$i};
+ $ch1 = ord($chr);
+ $ch2 = dechex($ch1);
+ $byte = '(&\\#([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch2 . ';|&\\#x([0]*){0,7}' . $ch2 . ';|%([0]*){0,7}' . $ch2 . '|' . preg_quote($chr) . ')';
+ $ret .= $byte;
+ $ret .= '([\s]){0,2}';
+ }
+ return $ret;
}
/**
@@ -2350,13 +2350,13 @@
function gen_sprite($path, $width, $height, $xpos, $ypos)
{
- $html = '<img src="' . scriptPath . '/images/spacer.gif" width="' . $width . '" height="' . $height . '" ';
- $xpos = ( $xpos == 0 ) ? '0' : '-' . strval($xpos);
- $ypos = ( $ypos == 0 ) ? '0' : '-' . strval($ypos);
- $html .= 'style="background-image: url(' . $path . '); background-repeat: no-repeat; background-position: ' . $ypos . 'px ' . $xpos . 'px;"';
- $html .= ' />';
-
- return $html;
+ $html = '<img src="' . scriptPath . '/images/spacer.gif" width="' . $width . '" height="' . $height . '" ';
+ $xpos = ( $xpos == 0 ) ? '0' : '-' . strval($xpos);
+ $ypos = ( $ypos == 0 ) ? '0' : '-' . strval($ypos);
+ $html .= 'style="background-image: url(' . $path . '); background-repeat: no-repeat; background-position: ' . $ypos . 'px ' . $xpos . 'px;"';
+ $html .= ' />';
+
+ return $html;
}
/**
@@ -2369,10 +2369,10 @@
$plugins->attachHook('spam_check', 'return my_spam_check($string);');
function my_spam_check($string)
{
- if ( stristr($string, 'viagra') )
- return false;
-
- return true;
+ if ( stristr($string, 'viagra') )
+ return false;
+
+ return true;
}
</code>
* @param string String to check for spam
@@ -2385,18 +2385,18 @@
function spamalyze($string, $name = false, $email = false, $url = false, $ip = false)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- if ( !$ip )
- $ip =& $_SERVER['REMOTE_ADDR'];
-
- $code = $plugins->setHook('spam_check');
- foreach ( $code as $cmd )
- {
- $result = eval($cmd);
- if ( !$result )
- return false;
- }
- return true;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ if ( !$ip )
+ $ip =& $_SERVER['REMOTE_ADDR'];
+
+ $code = $plugins->setHook('spam_check');
+ foreach ( $code as $cmd )
+ {
+ $result = eval($cmd);
+ if ( !$result )
+ return false;
+ }
+ return true;
}
/**
@@ -2411,113 +2411,113 @@
function generate_paginator($current_page, $num_pages, $result_url, $start_mult = 1, $start_add = 1)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- $out = '';
- $i = 0;
-
- // Build paginator
- $pg_css = ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ?
- // IE-specific hack
- 'display: block; width: 1px;':
- // Other browsers
- 'display: table; margin: 10px 0 0 auto;';
-
- $begin = '<div class="tblholder" style="'. $pg_css . '">
- <table border="0" cellspacing="1" cellpadding="4">
- <tr><th>' . $lang->get('paginate_lbl_page') . '</th>';
- $block = '<td class="row1" style="text-align: center;">{LINK}</td>';
- $end = '</tr></table></div>';
- $blk = $template->makeParserText($block);
- $inner = '';
- $cls = 'row2';
- if ( $num_pages < 5 )
- {
- for ( $i = 0; $i < $num_pages; $i++ )
- {
- $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
- $offset = strval(($i * $start_mult) + $start_add);
- $url = htmlspecialchars(sprintf($result_url, $offset));
- $j = $i + 1;
- $link = ( $i == $current_page ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
- $blk->assign_vars(array(
- 'CLASS'=>$cls,
- 'LINK'=>$link
- ));
- $inner .= $blk->run();
- }
- }
- else
- {
- if ( $current_page + 5 > $num_pages )
- {
- $list = Array();
- $tp = $current_page;
- if ( $current_page + 0 == $num_pages ) $tp = $tp - 3;
- if ( $current_page + 1 == $num_pages ) $tp = $tp - 2;
- if ( $current_page + 2 == $num_pages ) $tp = $tp - 1;
- for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
- {
- $list[] = $i;
- }
- }
- else
- {
- $list = Array();
- $current = $current_page;
- $lower = ( $current < 3 ) ? 1 : $current - 1;
- for ( $i = 0; $i < 3; $i++ )
- {
- $list[] = $lower + $i;
- }
- }
- $url = sprintf($result_url, $start_add);
- $link = ( 0 == $current_page ) ? "<b>" . $lang->get('paginate_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« " . $lang->get('paginate_btn_first') . "</a>";
- $blk->assign_vars(array(
- 'CLASS'=>$cls,
- 'LINK'=>$link
- ));
- $inner .= $blk->run();
-
- foreach ( $list as $i )
- {
- if ( $i == $num_pages )
- break;
- $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
- $offset = strval(($i * $start_mult) + $start_add);
- $url = sprintf($result_url, $offset);
- $j = $i + 1;
- $link = ( $i == $current_page ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
- $blk->assign_vars(array(
- 'CLASS'=>$cls,
- 'LINK'=>$link
- ));
- $inner .= $blk->run();
- }
-
- // "Last" button
- $total = (($num_pages - 1) * $start_mult) + $start_add;
-
- if ( $current_page < $num_pages )
- {
- $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
- $offset = strval($total);
- $url = sprintf($result_url, $offset);
- $link = ( $num_pages - 1 == $current_page ) ? "<b>" . $lang->get('paginate_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_last') . " »</a>";
- $blk->assign_vars(array(
- 'CLASS'=>$cls,
- 'LINK'=>$link
- ));
- $inner .= $blk->run();
- }
-
- }
-
- $inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$current_page.', '.$num_pages.', '.$start_mult.', '.$start_add.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
-
- $paginator = "\n$begin$inner$end\n";
- return $paginator;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang;
+
+ $out = '';
+ $i = 0;
+
+ // Build paginator
+ $pg_css = ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ?
+ // IE-specific hack
+ 'display: block; width: 1px;':
+ // Other browsers
+ 'display: table; margin: 10px 0 0 auto;';
+
+ $begin = '<div class="tblholder" style="'. $pg_css . '">
+ <table border="0" cellspacing="1" cellpadding="4">
+ <tr><th>' . $lang->get('paginate_lbl_page') . '</th>';
+ $block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+ $end = '</tr></table></div>';
+ $blk = $template->makeParserText($block);
+ $inner = '';
+ $cls = 'row2';
+ if ( $num_pages < 5 )
+ {
+ for ( $i = 0; $i < $num_pages; $i++ )
+ {
+ $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ $offset = strval(($i * $start_mult) + $start_add);
+ $url = htmlspecialchars(sprintf($result_url, $offset));
+ $j = $i + 1;
+ $link = ( $i == $current_page ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ $blk->assign_vars(array(
+ 'CLASS'=>$cls,
+ 'LINK'=>$link
+ ));
+ $inner .= $blk->run();
+ }
+ }
+ else
+ {
+ if ( $current_page + 5 > $num_pages )
+ {
+ $list = Array();
+ $tp = $current_page;
+ if ( $current_page + 0 == $num_pages ) $tp = $tp - 3;
+ if ( $current_page + 1 == $num_pages ) $tp = $tp - 2;
+ if ( $current_page + 2 == $num_pages ) $tp = $tp - 1;
+ for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
+ {
+ $list[] = $i;
+ }
+ }
+ else
+ {
+ $list = Array();
+ $current = $current_page;
+ $lower = ( $current < 3 ) ? 1 : $current - 1;
+ for ( $i = 0; $i < 3; $i++ )
+ {
+ $list[] = $lower + $i;
+ }
+ }
+ $url = sprintf($result_url, $start_add);
+ $link = ( 0 == $current_page ) ? "<b>" . $lang->get('paginate_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« " . $lang->get('paginate_btn_first') . "</a>";
+ $blk->assign_vars(array(
+ 'CLASS'=>$cls,
+ 'LINK'=>$link
+ ));
+ $inner .= $blk->run();
+
+ foreach ( $list as $i )
+ {
+ if ( $i == $num_pages )
+ break;
+ $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ $offset = strval(($i * $start_mult) + $start_add);
+ $url = sprintf($result_url, $offset);
+ $j = $i + 1;
+ $link = ( $i == $current_page ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ $blk->assign_vars(array(
+ 'CLASS'=>$cls,
+ 'LINK'=>$link
+ ));
+ $inner .= $blk->run();
+ }
+
+ // "Last" button
+ $total = (($num_pages - 1) * $start_mult) + $start_add;
+
+ if ( $current_page < $num_pages )
+ {
+ $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ $offset = strval($total);
+ $url = sprintf($result_url, $offset);
+ $link = ( $num_pages - 1 == $current_page ) ? "<b>" . $lang->get('paginate_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_last') . " »</a>";
+ $blk->assign_vars(array(
+ 'CLASS'=>$cls,
+ 'LINK'=>$link
+ ));
+ $inner .= $blk->run();
+ }
+
+ }
+
+ $inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$current_page.', '.$num_pages.', '.$start_mult.', '.$start_add.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
+
+ $paginator = "\n$begin$inner$end\n";
+ return $paginator;
}
/**
@@ -2536,61 +2536,61 @@
function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- $parser = $template->makeParserText($tpl_text);
-
- $num_pages = ceil ( $num_results / $perpage );
- $out = '';
- $this_page = ceil ( $start / $perpage );
- $i = 0;
-
- if ( $num_results > 0 )
- {
- $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0);
- $out .= $paginator;
- }
-
- $cls = 'row2';
-
- if ( $row = $db->fetchrow($q) )
- {
- $i = 0;
- $out .= $header;
- do {
- $i++;
- if ( $i <= $start )
- {
- continue;
- }
- if ( ( $i - $start ) > $perpage )
- {
- break;
- }
- $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
- foreach ( $row as $j => $val )
- {
- if ( isset($callers[$j]) )
- {
- $tmp = ( is_callable($callers[$j]) ) ? call_user_func($callers[$j], $val, $row) : $val;
-
- if ( is_string($tmp) )
- {
- $row[$j] = $tmp;
- }
- }
- }
- $parser->assign_vars($row);
- $parser->assign_vars(array('_css_class' => $cls));
- $out .= $parser->run();
- } while ( $row = @$db->fetchrow($q) );
- $out .= $footer;
- }
-
- if ( $num_results > 0 )
- $out .= $paginator;
-
- return $out;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $parser = $template->makeParserText($tpl_text);
+
+ $num_pages = ceil ( $num_results / $perpage );
+ $out = '';
+ $this_page = ceil ( $start / $perpage );
+ $i = 0;
+
+ if ( $num_results > 0 )
+ {
+ $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0);
+ $out .= $paginator;
+ }
+
+ $cls = 'row2';
+
+ if ( $row = $db->fetchrow($q) )
+ {
+ $i = 0;
+ $out .= $header;
+ do {
+ $i++;
+ if ( $i <= $start )
+ {
+ continue;
+ }
+ if ( ( $i - $start ) > $perpage )
+ {
+ break;
+ }
+ $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ foreach ( $row as $j => $val )
+ {
+ if ( isset($callers[$j]) )
+ {
+ $tmp = ( is_callable($callers[$j]) ) ? call_user_func($callers[$j], $val, $row) : $val;
+
+ if ( is_string($tmp) )
+ {
+ $row[$j] = $tmp;
+ }
+ }
+ }
+ $parser->assign_vars($row);
+ $parser->assign_vars(array('_css_class' => $cls));
+ $out .= $parser->run();
+ } while ( $row = @$db->fetchrow($q) );
+ $out .= $footer;
+ }
+
+ if ( $num_results > 0 )
+ $out .= $paginator;
+
+ return $out;
}
/**
@@ -2607,46 +2607,46 @@
function paginate_array($q, $num_results, $result_url, $start = 0, $perpage = 10, $header = '', $footer = '')
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- $num_pages = ceil ( $num_results / $perpage );
- $out = '';
- $i = 0;
- $this_page = ceil ( $start / $perpage );
-
- $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0);
-
- if ( $num_results > 1 )
- {
- $out .= $paginator;
- }
-
- $cls = 'row2';
-
- if ( sizeof($q) > 0 )
- {
- $i = 0;
- $out .= $header;
- foreach ( $q as $val ) {
- $i++;
- if ( $i <= $start )
- {
- continue;
- }
- if ( ( $i - $start ) > $perpage )
- {
- break;
- }
- $out .= $val;
- }
- $out .= $footer;
- }
-
- if ( $num_results > 1 )
- $out .= $paginator;
-
- return $out;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang;
+
+ $num_pages = ceil ( $num_results / $perpage );
+ $out = '';
+ $i = 0;
+ $this_page = ceil ( $start / $perpage );
+
+ $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0);
+
+ if ( $num_results > 1 )
+ {
+ $out .= $paginator;
+ }
+
+ $cls = 'row2';
+
+ if ( sizeof($q) > 0 )
+ {
+ $i = 0;
+ $out .= $header;
+ foreach ( $q as $val ) {
+ $i++;
+ if ( $i <= $start )
+ {
+ continue;
+ }
+ if ( ( $i - $start ) > $perpage )
+ {
+ break;
+ }
+ $out .= $val;
+ }
+ $out .= $footer;
+ }
+
+ if ( $num_results > 1 )
+ $out .= $paginator;
+
+ return $out;
}
/**
@@ -2655,11 +2655,11 @@
function enano_fputs($socket, $data)
{
- // echo '<pre>' . htmlspecialchars($data) . '</pre>';
- // flush();
- // ob_flush();
- // ob_end_flush();
- return fputs($socket, $data);
+ // echo '<pre>' . htmlspecialchars($data) . '</pre>';
+ // flush();
+ // ob_flush();
+ // ob_end_flush();
+ return fputs($socket, $data);
}
/**
@@ -2670,62 +2670,62 @@
function sanitize_page_id($page_id)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- if ( isset($paths->nslist['User']) )
- {
- if ( preg_match('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', $page_id) )
- {
- $ip = preg_replace('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', '', $page_id);
- if ( is_valid_ip($ip) )
- {
- return $page_id;
- }
- }
- }
-
- if ( empty($page_id) )
- return '';
-
- // Remove character escapes
- $page_id = dirtify_page_id($page_id);
-
- $pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]=_-]/', 'X', $page_id);
- $pid_dirty = enano_str_split($pid_clean, 1);
-
- foreach ( $pid_dirty as $id => $char )
- {
- if ( $char == 'X' )
- continue;
- $cid = ord($char);
- $cid = dechex($cid);
- $cid = strval($cid);
- if ( strlen($cid) < 2 )
- {
- $cid = strtoupper("0$cid");
- }
- $pid_dirty[$id] = ".$cid";
- }
-
- $pid_chars = enano_str_split($page_id, 1);
- $page_id_cleaned = '';
-
- foreach ( $pid_chars as $id => $char )
- {
- if ( $pid_dirty[$id] == 'X' )
- $page_id_cleaned .= $char;
- else
- $page_id_cleaned .= $pid_dirty[$id];
- }
-
- // global $mime_types;
-
- // $exts = array_keys($mime_types);
- // $exts = '(' . implode('|', $exts) . ')';
-
- // $page_id_cleaned = preg_replace('/\.2e' . $exts . '$/', '.\\1', $page_id_cleaned);
-
- return $page_id_cleaned;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( isset($paths->nslist['User']) )
+ {
+ if ( preg_match('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', $page_id) )
+ {
+ $ip = preg_replace('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', '', $page_id);
+ if ( is_valid_ip($ip) )
+ {
+ return $page_id;
+ }
+ }
+ }
+
+ if ( empty($page_id) )
+ return '';
+
+ // Remove character escapes
+ $page_id = dirtify_page_id($page_id);
+
+ $pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]=_-]/', 'X', $page_id);
+ $pid_dirty = enano_str_split($pid_clean, 1);
+
+ foreach ( $pid_dirty as $id => $char )
+ {
+ if ( $char == 'X' )
+ continue;
+ $cid = ord($char);
+ $cid = dechex($cid);
+ $cid = strval($cid);
+ if ( strlen($cid) < 2 )
+ {
+ $cid = strtoupper("0$cid");
+ }
+ $pid_dirty[$id] = ".$cid";
+ }
+
+ $pid_chars = enano_str_split($page_id, 1);
+ $page_id_cleaned = '';
+
+ foreach ( $pid_chars as $id => $char )
+ {
+ if ( $pid_dirty[$id] == 'X' )
+ $page_id_cleaned .= $char;
+ else
+ $page_id_cleaned .= $pid_dirty[$id];
+ }
+
+ // global $mime_types;
+
+ // $exts = array_keys($mime_types);
+ // $exts = '(' . implode('|', $exts) . ')';
+
+ // $page_id_cleaned = preg_replace('/\.2e' . $exts . '$/', '.\\1', $page_id_cleaned);
+
+ return $page_id_cleaned;
}
/**
@@ -2736,31 +2736,31 @@
function dirtify_page_id($page_id)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- // First, replace spaces with underscores
- $page_id = str_replace(' ', '_', $page_id);
-
- // Exception for userpages for IP addresses
- $pid_ip_check = ( is_object($paths) ) ? preg_replace('+^' . preg_quote($paths->nslist['User']) . '+', '', $page_id) : $page_id;
- if ( is_valid_ip($pid_ip_check) )
- {
- return $page_id;
- }
-
- preg_match_all('/\.[a-f0-9][a-f0-9]/', $page_id, $matches);
-
- foreach ( $matches[0] as $id => $char )
- {
- $char = substr($char, 1);
- $char = strtolower($char);
- $char = intval(hexdec($char));
- $char = chr($char);
- if ( preg_match('/^[\w\.\/:;\(\)@\[\]=_-]$/', $char) )
- continue;
- $page_id = str_replace($matches[0][$id], $char, $page_id);
- }
-
- return $page_id;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ // First, replace spaces with underscores
+ $page_id = str_replace(' ', '_', $page_id);
+
+ // Exception for userpages for IP addresses
+ $pid_ip_check = ( is_object($paths) ) ? preg_replace('+^' . preg_quote($paths->nslist['User']) . '+', '', $page_id) : $page_id;
+ if ( is_valid_ip($pid_ip_check) )
+ {
+ return $page_id;
+ }
+
+ preg_match_all('/\.[a-f0-9][a-f0-9]/', $page_id, $matches);
+
+ foreach ( $matches[0] as $id => $char )
+ {
+ $char = substr($char, 1);
+ $char = strtolower($char);
+ $char = intval(hexdec($char));
+ $char = chr($char);
+ if ( preg_match('/^[\w\.\/:;\(\)@\[\]=_-]$/', $char) )
+ continue;
+ $page_id = str_replace($matches[0][$id], $char, $page_id);
+ }
+
+ return $page_id;
}
/**
@@ -2771,36 +2771,36 @@
function commatize($num)
{
- $num = (string)$num;
- if ( strpos($num, '.') )
- {
- $whole = explode('.', $num);
- $num = $whole[0];
- $dec = $whole[1];
- }
- else
- {
- $whole = $num;
- }
- $offset = ( strlen($num) ) % 3;
- $len = strlen($num);
- $offset = ( $offset == 0 )
- ? 3
- : $offset;
- for ( $i = $offset; $i < $len; $i=$i+3 )
- {
- $num = substr($num, 0, $i) . ',' . substr($num, $i, $len);
- $len = strlen($num);
- $i++;
- }
- if ( isset($dec) )
- {
- return $num . '.' . $dec;
- }
- else
- {
- return $num;
- }
+ $num = (string)$num;
+ if ( strpos($num, '.') )
+ {
+ $whole = explode('.', $num);
+ $num = $whole[0];
+ $dec = $whole[1];
+ }
+ else
+ {
+ $whole = $num;
+ }
+ $offset = ( strlen($num) ) % 3;
+ $len = strlen($num);
+ $offset = ( $offset == 0 )
+ ? 3
+ : $offset;
+ for ( $i = $offset; $i < $len; $i=$i+3 )
+ {
+ $num = substr($num, 0, $i) . ',' . substr($num, $i, $len);
+ $len = strlen($num);
+ $i++;
+ }
+ if ( isset($dec) )
+ {
+ return $num . '.' . $dec;
+ }
+ else
+ {
+ return $num;
+ }
}
/**
@@ -2811,25 +2811,25 @@
function humanize_filesize($size)
{
- global $lang;
-
- if ( $size > ( 1099511627776 * 0.9 ) )
- {
- return number_format($size / 1099511627776, 1) . $lang->get('etc_unit_terabytes_short');
- }
- if ( $size > ( 1073741824 * 0.9 ) )
- {
- return number_format($size / 1073741824, 1) . $lang->get('etc_unit_gigabytes_short');
- }
- if ( $size > ( 1048576 * 0.9 ) )
- {
- return number_format($size / 1048576, 1) . $lang->get('etc_unit_megabytes_short');
- }
- if ( $size > ( 1024 * 0.9 ) )
- {
- return number_format($size / 1024, 1) . $lang->get('etc_unit_kilobytes_short');
- }
- return "$size " . $lang->get('etc_unit_bytes');
+ global $lang;
+
+ if ( $size > ( 1099511627776 * 0.9 ) )
+ {
+ return number_format($size / 1099511627776, 1) . $lang->get('etc_unit_terabytes_short');
+ }
+ if ( $size > ( 1073741824 * 0.9 ) )
+ {
+ return number_format($size / 1073741824, 1) . $lang->get('etc_unit_gigabytes_short');
+ }
+ if ( $size > ( 1048576 * 0.9 ) )
+ {
+ return number_format($size / 1048576, 1) . $lang->get('etc_unit_megabytes_short');
+ }
+ if ( $size > ( 1024 * 0.9 ) )
+ {
+ return number_format($size / 1024, 1) . $lang->get('etc_unit_kilobytes_short');
+ }
+ return "$size " . $lang->get('etc_unit_bytes');
}
/**
@@ -2841,10 +2841,10 @@
function inject_substr($haystack, $needle, $pos)
{
- $str1 = substr($haystack, 0, $pos);
- $pos++;
- $str2 = substr($haystack, $pos);
- return "{$str1}{$needle}{$str2}";
+ $str1 = substr($haystack, 0, $pos);
+ $pos++;
+ $str2 = substr($haystack, $pos);
+ return "{$str1}{$needle}{$str2}";
}
/**
@@ -2855,14 +2855,14 @@
function is_valid_ip($ip)
{
- // This next one came from phpBB3.
- $ipv4 = '(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])';
- $ipv6 = '(?:[a-f0-9]{0,4}):(?:[a-f0-9]{0,4}):(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{1,4})';
-
- if ( preg_match("/^{$ipv4}$/", $ip) || preg_match("/^{$ipv6}$/", $ip) )
- return true;
- else
- return false;
+ // This next one came from phpBB3.
+ $ipv4 = '(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])';
+ $ipv6 = '(?:[a-f0-9]{0,4}):(?:[a-f0-9]{0,4}):(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{1,4})';
+
+ if ( preg_match("/^{$ipv4}$/", $ip) || preg_match("/^{$ipv6}$/", $ip) )
+ return true;
+ else
+ return false;
}
/**
@@ -2874,14 +2874,14 @@
function str_replace_once($needle, $thread, $haystack)
{
- $needle_len = strlen($needle);
- if ( $pos = strstr($haystack, $needle) )
- {
- $upto = substr($haystack, 0, ( strlen($haystack) - strlen($pos) ));
- $from = substr($pos, $needle_len);
- return "{$upto}{$thread}{$from}";
- }
- return $haystack;
+ $needle_len = strlen($needle);
+ if ( $pos = strstr($haystack, $needle) )
+ {
+ $upto = substr($haystack, 0, ( strlen($haystack) - strlen($pos) ));
+ $from = substr($pos, $needle_len);
+ return "{$upto}{$thread}{$from}";
+ }
+ return $haystack;
}
/**
@@ -2894,22 +2894,22 @@
function str_replace_i($needle, $thread, $haystack)
{
- $needle_len = strlen($needle);
- $haystack_len = strlen($haystack);
- for ( $i = 0; $i < $haystack_len; $i++ )
- {
- $test = substr($haystack, $i, $needle_len);
- if ( strtolower($test) == strtolower($needle) )
- {
- // Got it!
- $upto = substr($haystack, 0, $i);
- $from = substr($haystack, ( $i + $needle_len ));
- $haystack = "{$upto}{$thread}{$from}";
- $haystack_len = strlen($haystack);
- $i = $i + strlen($thread);
- }
- }
- return $haystack;
+ $needle_len = strlen($needle);
+ $haystack_len = strlen($haystack);
+ for ( $i = 0; $i < $haystack_len; $i++ )
+ {
+ $test = substr($haystack, $i, $needle_len);
+ if ( strtolower($test) == strtolower($needle) )
+ {
+ // Got it!
+ $upto = substr($haystack, 0, $i);
+ $from = substr($haystack, ( $i + $needle_len ));
+ $haystack = "{$upto}{$thread}{$from}";
+ $haystack_len = strlen($haystack);
+ $i = $i + strlen($thread);
+ }
+ }
+ return $haystack;
}
/**
@@ -2923,22 +2923,22 @@
function highlight_term($needle, $haystack, $start_tag = '<b>', $end_tag = '</b>')
{
- $needle_len = strlen($needle);
- $haystack_len = strlen($haystack);
- for ( $i = 0; $i < $haystack_len; $i++ )
- {
- $test = substr($haystack, $i, $needle_len);
- if ( strtolower($test) == strtolower($needle) )
- {
- // Got it!
- $upto = substr($haystack, 0, $i);
- $from = substr($haystack, ( $i + $needle_len ));
- $haystack = "{$upto}{$start_tag}{$test}{$end_tag}{$from}";
- $haystack_len = strlen($haystack);
- $i = $i + strlen($needle) + strlen($start_tag) + strlen($end_tag);
- }
- }
- return $haystack;
+ $needle_len = strlen($needle);
+ $haystack_len = strlen($haystack);
+ for ( $i = 0; $i < $haystack_len; $i++ )
+ {
+ $test = substr($haystack, $i, $needle_len);
+ if ( strtolower($test) == strtolower($needle) )
+ {
+ // Got it!
+ $upto = substr($haystack, 0, $i);
+ $from = substr($haystack, ( $i + $needle_len ));
+ $haystack = "{$upto}{$start_tag}{$test}{$end_tag}{$from}";
+ $haystack_len = strlen($haystack);
+ $i = $i + strlen($needle) + strlen($start_tag) + strlen($end_tag);
+ }
+ }
+ return $haystack;
}
/**
@@ -2961,33 +2961,33 @@
* - additionalwhere: additional SQL to inject into WHERE clause, in the format of "AND foo = bar"
* @example Working example of adding users to search results:
<code>
- register_search_handler(array(
- 'table' => 'users',
- 'titlecolumn' => 'username',
- 'uniqueid' => 'ns=User;cid={username}',
- 'additionalcolumns' => array('user_id'),
- 'resultnote' => '[Member]',
- 'linkformat' => array(
- 'page_id' => '{username}',
- 'namespace' => 'User'
- ),
- 'formatcallback' => 'format_user_search_result',
- ));
-
- function format_user_search_result($row)
- {
- global $session, $lang;
- $rankdata = $session->get_user_rank(intval($row['user_id']));
- $rankspan = '<span style="' . $rankdata['rank_style'] . '">' . $lang->get($rankdata['rank_title']) . '</span>';
- if ( empty($rankdata['user_title']) )
- {
- return $rankspan;
- }
- else
- {
- return '"' . htmlspecialchars($rankdata['user_title']) . "\" (<b>$rankspan</b>)";
- }
- }
+ register_search_handler(array(
+ 'table' => 'users',
+ 'titlecolumn' => 'username',
+ 'uniqueid' => 'ns=User;cid={username}',
+ 'additionalcolumns' => array('user_id'),
+ 'resultnote' => '[Member]',
+ 'linkformat' => array(
+ 'page_id' => '{username}',
+ 'namespace' => 'User'
+ ),
+ 'formatcallback' => 'format_user_search_result',
+ ));
+
+ function format_user_search_result($row)
+ {
+ global $session, $lang;
+ $rankdata = $session->get_user_rank(intval($row['user_id']));
+ $rankspan = '<span style="' . $rankdata['rank_style'] . '">' . $lang->get($rankdata['rank_title']) . '</span>';
+ if ( empty($rankdata['user_title']) )
+ {
+ return $rankspan;
+ }
+ else
+ {
+ return '"' . htmlspecialchars($rankdata['user_title']) . "\" (<b>$rankspan</b>)";
+ }
+ }
</code>
* @param array Options array - see function documentation
* @return null
@@ -2998,18 +2998,18 @@
function register_search_handler($options)
{
- global $search_handlers;
-
- $required = array('table', 'titlecolumn', 'uniqueid', 'linkformat');
- foreach ( $required as $key )
- {
- if ( !isset($options[$key]) )
- {
- throw new Exception("Required search handler option '$key' is missing");
- }
- }
- $search_handlers[] = $options;
- return null;
+ global $search_handlers;
+
+ $required = array('table', 'titlecolumn', 'uniqueid', 'linkformat');
+ foreach ( $required as $key )
+ {
+ if ( !isset($options[$key]) )
+ {
+ throw new Exception("Required search handler option '$key' is missing");
+ }
+ }
+ $search_handlers[] = $options;
+ return null;
}
/**
@@ -3020,55 +3020,55 @@
function decode_unicode_url($str)
{
- $res = '';
-
- $i = 0;
- $max = strlen($str) - 6;
- while ($i <= $max)
- {
- $character = $str[$i];
- if ($character == '%' && $str[$i + 1] == 'u')
- {
- if ( !preg_match('/^([a-f0-9]{2})+$/', substr($str, $i + 2, 4)) )
- {
- $res .= substr($str, $i, 6);
- $i += 6;
- continue;
- }
-
- $value = hexdec(substr($str, $i + 2, 4));
- $i += 6;
-
- if ($value < 0x0080)
- {
- // 1 byte: 0xxxxxxx
- $character = chr($value);
- }
- else if ($value < 0x0800)
- {
- // 2 bytes: 110xxxxx 10xxxxxx
- $character =
- chr((($value & 0x07c0) >> 6) | 0xc0)
- . chr(($value & 0x3f) | 0x80);
- }
- else
- {
- // 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx
- $character =
- chr((($value & 0xf000) >> 12) | 0xe0)
- . chr((($value & 0x0fc0) >> 6) | 0x80)
- . chr(($value & 0x3f) | 0x80);
- }
- }
- else
- {
- $i++;
- }
-
- $res .= $character;
- }
-
- return $res . substr($str, $i);
+ $res = '';
+
+ $i = 0;
+ $max = strlen($str) - 6;
+ while ($i <= $max)
+ {
+ $character = $str[$i];
+ if ($character == '%' && $str[$i + 1] == 'u')
+ {
+ if ( !preg_match('/^([a-f0-9]{2})+$/', substr($str, $i + 2, 4)) )
+ {
+ $res .= substr($str, $i, 6);
+ $i += 6;
+ continue;
+ }
+
+ $value = hexdec(substr($str, $i + 2, 4));
+ $i += 6;
+
+ if ($value < 0x0080)
+ {
+ // 1 byte: 0xxxxxxx
+ $character = chr($value);
+ }
+ else if ($value < 0x0800)
+ {
+ // 2 bytes: 110xxxxx 10xxxxxx
+ $character =
+ chr((($value & 0x07c0) >> 6) | 0xc0)
+ . chr(($value & 0x3f) | 0x80);
+ }
+ else
+ {
+ // 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx
+ $character =
+ chr((($value & 0xf000) >> 12) | 0xe0)
+ . chr((($value & 0x0fc0) >> 6) | 0x80)
+ . chr(($value & 0x3f) | 0x80);
+ }
+ }
+ else
+ {
+ $i++;
+ }
+
+ $res .= $character;
+ }
+
+ return $res . substr($str, $i);
}
/**
@@ -3079,18 +3079,18 @@
function decode_unicode_array($array)
{
- foreach ( $array as $i => $val )
- {
- if ( is_string($val) )
- {
- $array[$i] = decode_unicode_url($val);
- }
- else if ( is_array($val) )
- {
- $array[$i] = decode_unicode_array($val);
- }
- }
- return $array;
+ foreach ( $array as $i => $val )
+ {
+ if ( is_string($val) )
+ {
+ $array[$i] = decode_unicode_url($val);
+ }
+ else if ( is_array($val) )
+ {
+ $array[$i] = decode_unicode_array($val);
+ }
+ }
+ return $array;
}
/**
@@ -3101,11 +3101,11 @@
function sanitize_tag($tag)
{
- $tag = strtolower($tag);
- $tag = preg_replace('/[^\w @\$%\^&-]+/', '', $tag);
- $tag = str_replace('_', ' ', $tag);
- $tag = trim($tag);
- return $tag;
+ $tag = strtolower($tag);
+ $tag = preg_replace('/[^\w @\$%\^&-]+/', '', $tag);
+ $tag = str_replace('_', ' ', $tag);
+ $tag = trim($tag);
+ return $tag;
}
/**
@@ -3119,17 +3119,17 @@
function enano_gzencode($data = "", $level = 6, $filename = "", $comments = "")
{
- $flags = (empty($comment)? 0 : 16) + (empty($filename)? 0 : 8);
- $mtime = time();
-
- if ( !function_exists('gzdeflate') )
- return false;
+ $flags = (empty($comment)? 0 : 16) + (empty($filename)? 0 : 8);
+ $mtime = time();
+
+ if ( !function_exists('gzdeflate') )
+ return false;
- return (pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, $flags, $mtime, 2, 0xFF) .
- (empty($filename) ? "" : $filename . "\0") .
- (empty($comment) ? "" : $comment . "\0") .
- gzdeflate($data, $level) .
- pack("VV", crc32($data), strlen($data)));
+ return (pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, $flags, $mtime, 2, 0xFF) .
+ (empty($filename) ? "" : $filename . "\0") .
+ (empty($comment) ? "" : $comment . "\0") .
+ gzdeflate($data, $level) .
+ pack("VV", crc32($data), strlen($data)));
}
$php_errors = array();
@@ -3142,56 +3142,56 @@
function enano_handle_error($errno, $errstr, $errfile, $errline)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- $er = error_reporting();
- if ( ! $er & $errno || $er == 0 )
- {
- return true;
- }
- global $do_gzip, $php_errors;
-
- if ( defined('ENANO_DEBUG') )
- {
- // turn off gzip and echo out error immediately for debug installs
- $do_gzip = false;
- }
-
- $error_type = 'error';
- if ( in_array($errno, array(E_WARNING, E_USER_WARNING)) )
- $error_type = 'warning';
- else if ( in_array($errno, array(E_NOTICE, E_USER_NOTICE)) )
- $error_type = 'notice';
-
- if ( @is_object(@$plugins) )
- {
- $code = $plugins->setHook('php_error');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
- }
-
- // bypass errors in date() and mktime() (Enano has its own code for this anyway)
- if ( strstr($errstr, "It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.") )
- {
- return true;
- }
-
- if ( $do_gzip )
- {
- $php_errors[] = array(
- 'num' => $errno,
- 'type' => $error_type,
- 'error' => $errstr,
- 'file' => $errfile,
- 'line' => $errline
- );
- }
- else
- {
- echo "[ <b>PHP $error_type:</b> $errstr in <b>$errfile</b>:<b>$errline</b> ]<br />";
- }
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $er = error_reporting();
+ if ( ! $er & $errno || $er == 0 )
+ {
+ return true;
+ }
+ global $do_gzip, $php_errors;
+
+ if ( defined('ENANO_DEBUG') )
+ {
+ // turn off gzip and echo out error immediately for debug installs
+ $do_gzip = false;
+ }
+
+ $error_type = 'error';
+ if ( in_array($errno, array(E_WARNING, E_USER_WARNING)) )
+ $error_type = 'warning';
+ else if ( in_array($errno, array(E_NOTICE, E_USER_NOTICE)) )
+ $error_type = 'notice';
+
+ if ( @is_object(@$plugins) )
+ {
+ $code = $plugins->setHook('php_error');
+ foreach ( $code as $cmd )
+ {
+ eval($cmd);
+ }
+ }
+
+ // bypass errors in date() and mktime() (Enano has its own code for this anyway)
+ if ( strstr($errstr, "It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.") )
+ {
+ return true;
+ }
+
+ if ( $do_gzip )
+ {
+ $php_errors[] = array(
+ 'num' => $errno,
+ 'type' => $error_type,
+ 'error' => $errstr,
+ 'file' => $errfile,
+ 'line' => $errline
+ );
+ }
+ else
+ {
+ echo "[ <b>PHP $error_type:</b> $errstr in <b>$errfile</b>:<b>$errline</b> ]<br />";
+ }
}
set_error_handler('enano_handle_error');
@@ -3202,46 +3202,46 @@
function gzip_output()
{
- global $do_gzip;
-
- $gzip_supported = false;
- if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
- {
- $encodings = explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']);
- $gzip_supported = in_array('gzip', $encodings) || in_array('deflate', $encodings);
- }
-
- //
- // Compress buffered output if required and send to browser
- // Sorry, doesn't work in IE. What else is new?
- //
- if ( $do_gzip && getConfig('gzip_output', false) == 1 && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() && $gzip_supported )
- {
- $gzip_contents = ob_get_contents();
- ob_end_clean();
-
- global $php_errors;
- if ( !empty($php_errors) )
- {
- $errors = '';
- foreach ( $php_errors as $error )
- {
- $errors .= "[ <b>PHP {$error['type']}:</b> {$error['error']} in <b>{$error['file']}</b>:<b>{$error['line']}</b> ]<br />";
- }
- $gzip_contents = str_replace("</body>", "$errors</body>", $gzip_contents);
- }
-
- $return = @enano_gzencode($gzip_contents);
- if ( $return )
- {
- header('Content-encoding: gzip');
- echo $return;
- }
- else
- {
- echo $gzip_contents;
- }
- }
+ global $do_gzip;
+
+ $gzip_supported = false;
+ if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
+ {
+ $encodings = explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']);
+ $gzip_supported = in_array('gzip', $encodings) || in_array('deflate', $encodings);
+ }
+
+ //
+ // Compress buffered output if required and send to browser
+ // Sorry, doesn't work in IE. What else is new?
+ //
+ if ( $do_gzip && getConfig('gzip_output', false) == 1 && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() && $gzip_supported )
+ {
+ $gzip_contents = ob_get_contents();
+ ob_end_clean();
+
+ global $php_errors;
+ if ( !empty($php_errors) )
+ {
+ $errors = '';
+ foreach ( $php_errors as $error )
+ {
+ $errors .= "[ <b>PHP {$error['type']}:</b> {$error['error']} in <b>{$error['file']}</b>:<b>{$error['line']}</b> ]<br />";
+ }
+ $gzip_contents = str_replace("</body>", "$errors</body>", $gzip_contents);
+ }
+
+ $return = @enano_gzencode($gzip_contents);
+ if ( $return )
+ {
+ header('Content-encoding: gzip');
+ echo $return;
+ }
+ else
+ {
+ echo $gzip_contents;
+ }
+ }
}
/**
@@ -3252,93 +3252,93 @@
function aggressive_optimize_html($html)
{
- $size_before = strlen($html);
-
- // kill carriage returns
- $html = str_replace("\r", "", $html);
-
- // Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
- $strip_tags = Array('enano:no-opt');
- $strip_tags = implode('|', $strip_tags);
-
- // Strip out the tags and replace with placeholders
- preg_match_all("#<($strip_tags)([ ]+.*?)?>(.*?)</($strip_tags)>#is", $html, $matches);
- $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
- for ($i = 0;$i < sizeof($matches[1]); $i++)
- {
- $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
- }
-
- // Optimize (but don't obfuscate) Javascript
- preg_match_all('/<script([ ]+.*?)?>(.*?)(\]\]>)?<\/script>/is', $html, $jscript);
- require_once(ENANO_ROOT . '/includes/js-compressor.php');
- $jsc = new JavascriptCompressor();
-
- // list of Javascript reserved words - from about.com
- $reserved_words = array('abstract', 'as', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'continue', 'const', 'debugger', 'default', 'delete', 'do',
- 'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
- 'in', 'instanceof', 'int', 'interface', 'is', 'long', 'namespace', 'native', 'new', 'null', 'package', 'private', 'protected', 'public',
- 'return', 'short', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'use', 'var',
- 'void', 'volatile', 'while', 'with');
-
- $reserved_words = '(' . implode('|', $reserved_words) . ')';
-
- for ( $i = 0; $i < count($jscript[0]); $i++ )
- {
- $js =& $jscript[2][$i];
- if ( empty($js) )
- continue;
-
- $js = $jsc->getClean($js);
-
- $replacement = "<script{$jscript[1][$i]}>/* <![CDATA[ */ $js /* ]]> */</script>";
- // apply changes
- $html = str_replace($jscript[0][$i], $replacement, $html);
-
- }
-
- // Re-insert untouchable tags
- for ($i = 0;$i < sizeof($matches[1]); $i++)
- {
- $html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
- }
-
- // Which tags to strip - you can change this if needed
- $strip_tags = Array('pre', 'script', 'style', 'enano:no-opt', 'textarea');
- $strip_tags = implode('|', $strip_tags);
-
- // Strip out the tags and replace with placeholders
- preg_match_all("#<($strip_tags)(.*?)>(.*?)</($strip_tags)>#is", $html, $matches);
- $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
- for ($i = 0;$i < sizeof($matches[1]); $i++)
- {
- $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
- }
-
- // Finally, process the HTML
- $html = preg_replace("#\n([ ]*)#", " ", $html);
-
- // Remove annoying spaces between tags
- $html = preg_replace("#>([ ][ ]+)<#", "> <", $html);
-
- // Re-insert untouchable tags
- for ($i = 0;$i < sizeof($matches[1]); $i++)
- {
- $html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
- }
-
- // Remove <enano:no-opt> blocks (can be used by themes that don't want their HTML optimized)
- $html = preg_replace('#<(\/|)enano:no-opt(.*?)>#', '', $html);
-
- $size_after = strlen($html);
-
- // Tell snoopish users what's going on
- $html = str_replace('<html', "\n".'<!-- NOTE: Enano has performed an HTML optimization routine on the HTML you see here. This is to enhance page loading speeds.
- To view the uncompressed source of this page, add the "nocompress" parameter to the URI of this page: index.php?title=Main_Page&nocompress or Main_Page?nocompress'."
- Size before compression: $size_before bytes
- Size after compression: $size_after bytes
- -->\n<html", $html);
- return $html;
+ $size_before = strlen($html);
+
+ // kill carriage returns
+ $html = str_replace("\r", "", $html);
+
+ // Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
+ $strip_tags = Array('enano:no-opt');
+ $strip_tags = implode('|', $strip_tags);
+
+ // Strip out the tags and replace with placeholders
+ preg_match_all("#<($strip_tags)([ ]+.*?)?>(.*?)</($strip_tags)>#is", $html, $matches);
+ $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
+ for ($i = 0;$i < sizeof($matches[1]); $i++)
+ {
+ $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
+ }
+
+ // Optimize (but don't obfuscate) Javascript
+ preg_match_all('/<script([ ]+.*?)?>(.*?)(\]\]>)?<\/script>/is', $html, $jscript);
+ require_once(ENANO_ROOT . '/includes/js-compressor.php');
+ $jsc = new JavascriptCompressor();
+
+ // list of Javascript reserved words - from about.com
+ $reserved_words = array('abstract', 'as', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'continue', 'const', 'debugger', 'default', 'delete', 'do',
+ 'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
+ 'in', 'instanceof', 'int', 'interface', 'is', 'long', 'namespace', 'native', 'new', 'null', 'package', 'private', 'protected', 'public',
+ 'return', 'short', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'use', 'var',
+ 'void', 'volatile', 'while', 'with');
+
+ $reserved_words = '(' . implode('|', $reserved_words) . ')';
+
+ for ( $i = 0; $i < count($jscript[0]); $i++ )
+ {
+ $js =& $jscript[2][$i];
+ if ( empty($js) )
+ continue;
+
+ $js = $jsc->getClean($js);
+
+ $replacement = "<script{$jscript[1][$i]}>/* <![CDATA[ */ $js /* ]]> */</script>";
+ // apply changes
+ $html = str_replace($jscript[0][$i], $replacement, $html);
+
+ }
+
+ // Re-insert untouchable tags
+ for ($i = 0;$i < sizeof($matches[1]); $i++)
+ {
+ $html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
+ }
+
+ // Which tags to strip - you can change this if needed
+ $strip_tags = Array('pre', 'script', 'style', 'enano:no-opt', 'textarea');
+ $strip_tags = implode('|', $strip_tags);
+
+ // Strip out the tags and replace with placeholders
+ preg_match_all("#<($strip_tags)(.*?)>(.*?)</($strip_tags)>#is", $html, $matches);
+ $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
+ for ($i = 0;$i < sizeof($matches[1]); $i++)
+ {
+ $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
+ }
+
+ // Finally, process the HTML
+ $html = preg_replace("#\n([ ]*)#", " ", $html);
+
+ // Remove annoying spaces between tags
+ $html = preg_replace("#>([ ][ ]+)<#", "> <", $html);
+
+ // Re-insert untouchable tags
+ for ($i = 0;$i < sizeof($matches[1]); $i++)
+ {
+ $html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
+ }
+
+ // Remove <enano:no-opt> blocks (can be used by themes that don't want their HTML optimized)
+ $html = preg_replace('#<(\/|)enano:no-opt(.*?)>#', '', $html);
+
+ $size_after = strlen($html);
+
+ // Tell snoopish users what's going on
+ $html = str_replace('<html', "\n".'<!-- NOTE: Enano has performed an HTML optimization routine on the HTML you see here. This is to enhance page loading speeds.
+ To view the uncompressed source of this page, add the "nocompress" parameter to the URI of this page: index.php?title=Main_Page&nocompress or Main_Page?nocompress'."
+ Size before compression: $size_before bytes
+ Size after compression: $size_after bytes
+ -->\n<html", $html);
+ return $html;
}
/**
@@ -3349,23 +3349,23 @@
function int_range($range)
{
- if ( strval(intval($range)) == $range )
- return $range;
- if ( !preg_match('/^[0-9]+(-[0-9]+)?$/', $range) )
- return false;
- $ends = explode('-', $range);
- if ( count($ends) != 2 )
- return $range;
- $ret = array();
- if ( $ends[1] < $ends[0] )
- $ends = array($ends[1], $ends[0]);
- else if ( $ends[0] == $ends[1] )
- return array($ends[0]);
- for ( $i = $ends[0]; $i <= $ends[1]; $i++ )
- {
- $ret[] = $i;
- }
- return $ret;
+ if ( strval(intval($range)) == $range )
+ return $range;
+ if ( !preg_match('/^[0-9]+(-[0-9]+)?$/', $range) )
+ return false;
+ $ends = explode('-', $range);
+ if ( count($ends) != 2 )
+ return $range;
+ $ret = array();
+ if ( $ends[1] < $ends[0] )
+ $ends = array($ends[1], $ends[0]);
+ else if ( $ends[0] == $ends[1] )
+ return array($ends[0]);
+ for ( $i = $ends[0]; $i <= $ends[1]; $i++ )
+ {
+ $ret[] = $i;
+ }
+ return $ret;
}
/**
@@ -3377,47 +3377,47 @@
function parse_ip_range($range)
{
- $octets = explode('.', $range);
- if ( count($octets) != 4 )
- // invalid range
- return $range;
- $i = 0;
- $possibilities = array( 0 => array(), 1 => array(), 2 => array(), 3 => array() );
- foreach ( $octets as $octet )
- {
- $existing =& $possibilities[$i];
- $inner = explode('|', $octet);
- foreach ( $inner as $bit )
- {
- if ( $i >= 2 )
- {
- $bits = int_range($bit);
- if ( $bits === false )
- return false;
- else if ( !is_array($bits) )
- $existing[] = intval($bits);
- else
- $existing = array_merge($existing, $bits);
- }
- else
- {
- $bit = intval($bit);
- $existing[] = $bit;
- }
- }
- $existing = array_unique($existing);
- $i++;
- }
- $ips = array();
-
- // The only way to combine all those possibilities. ;-)
- foreach ( $possibilities[0] as $oc1 )
- foreach ( $possibilities[1] as $oc2 )
- foreach ( $possibilities[2] as $oc3 )
- foreach ( $possibilities[3] as $oc4 )
- $ips[] = "$oc1.$oc2.$oc3.$oc4";
-
- return $ips;
+ $octets = explode('.', $range);
+ if ( count($octets) != 4 )
+ // invalid range
+ return $range;
+ $i = 0;
+ $possibilities = array( 0 => array(), 1 => array(), 2 => array(), 3 => array() );
+ foreach ( $octets as $octet )
+ {
+ $existing =& $possibilities[$i];
+ $inner = explode('|', $octet);
+ foreach ( $inner as $bit )
+ {
+ if ( $i >= 2 )
+ {
+ $bits = int_range($bit);
+ if ( $bits === false )
+ return false;
+ else if ( !is_array($bits) )
+ $existing[] = intval($bits);
+ else
+ $existing = array_merge($existing, $bits);
+ }
+ else
+ {
+ $bit = intval($bit);
+ $existing[] = $bit;
+ }
+ }
+ $existing = array_unique($existing);
+ $i++;
+ }
+ $ips = array();
+
+ // The only way to combine all those possibilities. ;-)
+ foreach ( $possibilities[0] as $oc1 )
+ foreach ( $possibilities[1] as $oc2 )
+ foreach ( $possibilities[2] as $oc3 )
+ foreach ( $possibilities[3] as $oc4 )
+ $ips[] = "$oc1.$oc2.$oc3.$oc4";
+
+ return $ips;
}
/**
@@ -3428,14 +3428,14 @@
function parse_ip_range_regex($range)
{
- if ( strstr($range, ':') )
- {
- return parse_ipv6_range_regex($range);
- }
- else
- {
- return parse_ipv4_range_regex($range);
- }
+ if ( strstr($range, ':') )
+ {
+ return parse_ipv6_range_regex($range);
+ }
+ else
+ {
+ return parse_ipv4_range_regex($range);
+ }
}
/**
@@ -3446,62 +3446,62 @@
function parse_ipv4_range_regex($range)
{
- // Regular expression to test the range string for validity
- $regex = '/^(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
- . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
- . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
- . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)$/';
- if ( !preg_match($regex, $range) )
- {
- return false;
- }
- $octets = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
- list($octets[0], $octets[1], $octets[2], $octets[3]) = explode('.', $range);
- $return = '^';
- foreach ( $octets as $octet )
- {
- // alternatives array
- $alts = array();
- if ( strpos($octet, '|') )
- {
- $particles = explode('|', $octet);
- }
- else
- {
- $particles = array($octet);
- }
- foreach ( $particles as $atom )
- {
- // each $atom will be either
- if ( strval(intval($atom)) == $atom )
- {
- $alts[] = $atom;
- continue;
- }
- else
- {
- // it's a range - parse it out
- $alt2 = int_range($atom);
- if ( !$alt2 )
- return false;
- foreach ( $alt2 as $neutrino )
- $alts[] = $neutrino;
- }
- }
- $alts = array_unique($alts);
- $alts = '|' . implode('|', $alts) . '|';
- // we can further optimize/compress this by weaseling our way into using some character ranges
- for ( $i = 1; $i <= 25; $i++ )
- {
- $alts = str_replace("|{$i}0|{$i}1|{$i}2|{$i}3|{$i}4|{$i}5|{$i}6|{$i}7|{$i}8|{$i}9|", "|{$i}[0-9]|", $alts);
- }
- $alts = str_replace("|1|2|3|4|5|6|7|8|9|", "|[1-9]|", $alts);
- $alts = '(' . substr($alts, 1, -1) . ')';
- $return .= $alts . '\.';
- }
- $return = substr($return, 0, -2);
- $return .= '$';
- return $return;
+ // Regular expression to test the range string for validity
+ $regex = '/^(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
+ . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
+ . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
+ . '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)$/';
+ if ( !preg_match($regex, $range) )
+ {
+ return false;
+ }
+ $octets = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
+ list($octets[0], $octets[1], $octets[2], $octets[3]) = explode('.', $range);
+ $return = '^';
+ foreach ( $octets as $octet )
+ {
+ // alternatives array
+ $alts = array();
+ if ( strpos($octet, '|') )
+ {
+ $particles = explode('|', $octet);
+ }
+ else
+ {
+ $particles = array($octet);
+ }
+ foreach ( $particles as $atom )
+ {
+ // each $atom will be either
+ if ( strval(intval($atom)) == $atom )
+ {
+ $alts[] = $atom;
+ continue;
+ }
+ else
+ {
+ // it's a range - parse it out
+ $alt2 = int_range($atom);
+ if ( !$alt2 )
+ return false;
+ foreach ( $alt2 as $neutrino )
+ $alts[] = $neutrino;
+ }
+ }
+ $alts = array_unique($alts);
+ $alts = '|' . implode('|', $alts) . '|';
+ // we can further optimize/compress this by weaseling our way into using some character ranges
+ for ( $i = 1; $i <= 25; $i++ )
+ {
+ $alts = str_replace("|{$i}0|{$i}1|{$i}2|{$i}3|{$i}4|{$i}5|{$i}6|{$i}7|{$i}8|{$i}9|", "|{$i}[0-9]|", $alts);
+ }
+ $alts = str_replace("|1|2|3|4|5|6|7|8|9|", "|[1-9]|", $alts);
+ $alts = '(' . substr($alts, 1, -1) . ')';
+ $return .= $alts . '\.';
+ }
+ $return = substr($return, 0, -2);
+ $return .= '$';
+ return $return;
}
/**
@@ -3512,89 +3512,89 @@
function parse_ipv6_range_regex($range)
{
- $range = strtolower(trim($range));
- $valid = '/^';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
- $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4})$/';
- if ( !preg_match($valid, $range) )
- return false;
-
- // expand address range.
- // this takes short ranges like:
- // 2001:470-471:054-b02b::5-bb
- // up to:
- // 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb
- $range = preg_replace('/^:/', '0000:', $range);
- $range = explode(':', $range);
- $expanded = '';
- $size = count($range);
- foreach ( $range as $byteset )
- {
- if ( empty($byteset) )
- {
- // ::
- while ( $size < 9 )
- {
- $expanded .= '0000:';
- $size++;
- }
- }
- else
- {
- if ( strstr($byteset, '-') )
- {
- // this is a range
- $sides = explode('-', $byteset);
- foreach ( $sides as &$bytepair )
- {
- while ( strlen($bytepair) < 4 )
- {
- $bytepair = "0$bytepair";
- }
- }
- $byteset = implode('-', $sides);
- }
- else
- {
- while ( strlen($byteset) < 4 )
- {
- $byteset = "0$byteset";
- }
- }
- $expanded .= "$byteset:";
- }
- }
- $expanded = explode(':', rtrim($expanded, ':'));
-
- // ready to dive in and start generating range regexes.
- // this has to be pretty optimized... we want to end up with regexes like:
- // range: 54-b12b
- /*
- /005[4-9a-f]|
- 00[6-9a-f][0-9a-f]|
- 0[1-9a-f][0-9a-f][0-9a-f]|
- [1-9a][0-9a-f][0-9a-f][0-9a-f]|
- b[0-0][0-1][0-9a-f]|
- b0[0-1][0-9a-f]|
- b02[0-9a-b]/x
- */
- foreach ( $expanded as &$word )
- {
- if ( strstr($word, '-') )
- {
- // oh... damn.
- $word = '(?:' . generate_hex_numeral_range($word) . ')';
- }
- }
-
- // return print_r($expanded, true);
- return '^' . implode(':', $expanded) . '$';
+ $range = strtolower(trim($range));
+ $valid = '/^';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ $valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4})$/';
+ if ( !preg_match($valid, $range) )
+ return false;
+
+ // expand address range.
+ // this takes short ranges like:
+ // 2001:470-471:054-b02b::5-bb
+ // up to:
+ // 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb
+ $range = preg_replace('/^:/', '0000:', $range);
+ $range = explode(':', $range);
+ $expanded = '';
+ $size = count($range);
+ foreach ( $range as $byteset )
+ {
+ if ( empty($byteset) )
+ {
+ // ::
+ while ( $size < 9 )
+ {
+ $expanded .= '0000:';
+ $size++;
+ }
+ }
+ else
+ {
+ if ( strstr($byteset, '-') )
+ {
+ // this is a range
+ $sides = explode('-', $byteset);
+ foreach ( $sides as &$bytepair )
+ {
+ while ( strlen($bytepair) < 4 )
+ {
+ $bytepair = "0$bytepair";
+ }
+ }
+ $byteset = implode('-', $sides);
+ }
+ else
+ {
+ while ( strlen($byteset) < 4 )
+ {
+ $byteset = "0$byteset";
+ }
+ }
+ $expanded .= "$byteset:";
+ }
+ }
+ $expanded = explode(':', rtrim($expanded, ':'));
+
+ // ready to dive in and start generating range regexes.
+ // this has to be pretty optimized... we want to end up with regexes like:
+ // range: 54-b12b
+ /*
+ /005[4-9a-f]|
+ 00[6-9a-f][0-9a-f]|
+ 0[1-9a-f][0-9a-f][0-9a-f]|
+ [1-9a][0-9a-f][0-9a-f][0-9a-f]|
+ b[0-0][0-1][0-9a-f]|
+ b0[0-1][0-9a-f]|
+ b02[0-9a-b]/x
+ */
+ foreach ( $expanded as &$word )
+ {
+ if ( strstr($word, '-') )
+ {
+ // oh... damn.
+ $word = '(?:' . generate_hex_numeral_range($word) . ')';
+ }
+ }
+
+ // return print_r($expanded, true);
+ return '^' . implode(':', $expanded) . '$';
}
/**
@@ -3606,152 +3606,152 @@
function generate_hex_numeral_range($word)
{
- list($low, $high) = explode('-', $word);
-
- if ( hexdec($low) > hexdec($high) )
- {
- $_ = $low;
- $low = $high;
- $high = $_;
- unset($_);
- }
-
- while ( strlen($low) < strlen($high) )
- {
- $low = "0$low";
- }
-
- // trim off everything that's the same
- $trimmed = '';
- $len = strlen($low);
- for ( $i = 0; $i < $len; $i++ )
- {
- if ( $low{0} === $high{0} )
- {
- $trimmed .= $low{0};
- $low = substr($low, 1);
- $high = substr($high, 1);
- }
- else
- {
- break;
- }
- }
-
- $len = strlen($high);
- if ( $len == 1 )
- {
- // this does happen sometimes, so we can save a bit of CPU power here.
- return $trimmed . __hexdigitrange($low, $high);
- }
-
- $return = '';
- // lower half
- for ( $i = $len - 1; $i > 0; $i-- )
- {
- if ( $low{$i} == 'f' )
- continue;
- $return .= $trimmed;
- for ( $j = 0; $j < $len; $j++ )
- {
- if ( $j < $i )
- {
- $return .= $low{$j};
- }
- else if ( $j == $i && ( $i == $len - 1 || $low{$j} == 'f' ) )
- {
- $return .= __hexdigitrange($low{$j}, 'f');
- }
- else if ( $j == $i && $i != $len - 1 )
- {
- $return .= __hexdigitrange(dechex(hexdec($low{$j}) + 1), 'f');
- }
- else
- {
- $return .= __hexdigitrange('0', 'f');
- }
- }
- $return .= '|';
- }
- // middle block
- if ( hexdec($low{0}) + 1 < hexdec($high{0}) )
- {
- if ( hexdec($low{0}) + 1 < hexdec($high{0}) - 1 )
- $return .= $trimmed . __hexdigitrange(dechex(hexdec($low{0}) + 1), dechex(hexdec($high{0}) - 1));
- else
- $return .= $trimmed . __hexdigitrange($low{0}, $high{0});
- if ( $len - 1 > 0 )
- $return .= '[0-9a-f]{' . ( $len - 1 ) . '}|';
- }
- // higher half
- for ( $i = 1; $i < $len; $i++ )
- {
- if ( $high{$i} == '0' )
- continue;
- $return .= $trimmed;
- for ( $j = 0; $j < $len; $j++ )
- {
- if ( $j < $i )
- {
- $return .= $high{$j};
- }
- else if ( $j == $i && ( $i == $len - 1 || $high{$j} == '0' ) )
- {
- $return .= __hexdigitrange('0', $high{$j});
- }
- else if ( $j == $i && $i != $len - 1 )
- {
- $return .= __hexdigitrange('0', dechex(hexdec($high{$j}) - 1));
- }
- else if ( $j > $i )
- {
- $return .= __hexdigitrange('0', 'f');
- }
- else
- {
- die("I don't know what to do! i $i j $j");
- }
- }
- $return .= '|';
- }
-
- return rtrim($return, '|');
+ list($low, $high) = explode('-', $word);
+
+ if ( hexdec($low) > hexdec($high) )
+ {
+ $_ = $low;
+ $low = $high;
+ $high = $_;
+ unset($_);
+ }
+
+ while ( strlen($low) < strlen($high) )
+ {
+ $low = "0$low";
+ }
+
+ // trim off everything that's the same
+ $trimmed = '';
+ $len = strlen($low);
+ for ( $i = 0; $i < $len; $i++ )
+ {
+ if ( $low{0} === $high{0} )
+ {
+ $trimmed .= $low{0};
+ $low = substr($low, 1);
+ $high = substr($high, 1);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ $len = strlen($high);
+ if ( $len == 1 )
+ {
+ // this does happen sometimes, so we can save a bit of CPU power here.
+ return $trimmed . __hexdigitrange($low, $high);
+ }
+
+ $return = '';
+ // lower half
+ for ( $i = $len - 1; $i > 0; $i-- )
+ {
+ if ( $low{$i} == 'f' )
+ continue;
+ $return .= $trimmed;
+ for ( $j = 0; $j < $len; $j++ )
+ {
+ if ( $j < $i )
+ {
+ $return .= $low{$j};
+ }
+ else if ( $j == $i && ( $i == $len - 1 || $low{$j} == 'f' ) )
+ {
+ $return .= __hexdigitrange($low{$j}, 'f');
+ }
+ else if ( $j == $i && $i != $len - 1 )
+ {
+ $return .= __hexdigitrange(dechex(hexdec($low{$j}) + 1), 'f');
+ }
+ else
+ {
+ $return .= __hexdigitrange('0', 'f');
+ }
+ }
+ $return .= '|';
+ }
+ // middle block
+ if ( hexdec($low{0}) + 1 < hexdec($high{0}) )
+ {
+ if ( hexdec($low{0}) + 1 < hexdec($high{0}) - 1 )
+ $return .= $trimmed . __hexdigitrange(dechex(hexdec($low{0}) + 1), dechex(hexdec($high{0}) - 1));
+ else
+ $return .= $trimmed . __hexdigitrange($low{0}, $high{0});
+ if ( $len - 1 > 0 )
+ $return .= '[0-9a-f]{' . ( $len - 1 ) . '}|';
+ }
+ // higher half
+ for ( $i = 1; $i < $len; $i++ )
+ {
+ if ( $high{$i} == '0' )
+ continue;
+ $return .= $trimmed;
+ for ( $j = 0; $j < $len; $j++ )
+ {
+ if ( $j < $i )
+ {
+ $return .= $high{$j};
+ }
+ else if ( $j == $i && ( $i == $len - 1 || $high{$j} == '0' ) )
+ {
+ $return .= __hexdigitrange('0', $high{$j});
+ }
+ else if ( $j == $i && $i != $len - 1 )
+ {
+ $return .= __hexdigitrange('0', dechex(hexdec($high{$j}) - 1));
+ }
+ else if ( $j > $i )
+ {
+ $return .= __hexdigitrange('0', 'f');
+ }
+ else
+ {
+ die("I don't know what to do! i $i j $j");
+ }
+ }
+ $return .= '|';
+ }
+
+ return rtrim($return, '|');
}
function __hexdigitrange($low, $high)
{
- if ( $low == $high )
- return $low;
- if ( empty($low) )
- $low = '0';
-
- $low_type = ( preg_match('/[0-9]/', $low) ) ? 'num' : 'alph';
- $high_type = ( preg_match('/[0-9]/', $high) ) ? 'num' : 'alph';
- if ( ( $low_type == 'num' && $high_type == 'num') || ( $low_type == 'alph' && $high_type == 'alph' ) )
- {
- return "[$low-$high]";
- }
- else if ( $low_type == 'num' && $high_type == 'alph' )
- {
- $ret = '[';
-
- if ( $low == '9' )
- $ret .= '9';
- else
- $ret .= "$low-9";
- if ( $high == 'a' )
- $ret .= 'a';
- else
- $ret .= "a-$high";
-
- $ret .= "]";
- return $ret;
- }
- else if ( $low_type == 'alph' && $high_type == 'num' )
- {
- // ???? this should never happen
- return __hexdigitrange($high, $low);
- }
+ if ( $low == $high )
+ return $low;
+ if ( empty($low) )
+ $low = '0';
+
+ $low_type = ( preg_match('/[0-9]/', $low) ) ? 'num' : 'alph';
+ $high_type = ( preg_match('/[0-9]/', $high) ) ? 'num' : 'alph';
+ if ( ( $low_type == 'num' && $high_type == 'num') || ( $low_type == 'alph' && $high_type == 'alph' ) )
+ {
+ return "[$low-$high]";
+ }
+ else if ( $low_type == 'num' && $high_type == 'alph' )
+ {
+ $ret = '[';
+
+ if ( $low == '9' )
+ $ret .= '9';
+ else
+ $ret .= "$low-9";
+ if ( $high == 'a' )
+ $ret .= 'a';
+ else
+ $ret .= "a-$high";
+
+ $ret .= "]";
+ return $ret;
+ }
+ else if ( $low_type == 'alph' && $high_type == 'num' )
+ {
+ // ???? this should never happen
+ return __hexdigitrange($high, $low);
+ }
}
/**
@@ -3762,26 +3762,26 @@
function expand_ipv6_address($addr)
{
- $expanded = array();
- $addr = explode(':', $addr);
- foreach ( $addr as $i => $bytepair )
- {
- if ( empty($bytepair) )
- {
- // ::
- while ( count($expanded) < (8 - count($addr) + $i + 1) )
- {
- $expanded[] = '0000';
- }
- }
- else
- {
- while ( strlen($bytepair) < 4 )
- $bytepair = "0$bytepair";
- $expanded[] = $bytepair;
- }
- }
- return implode(':', $expanded);
+ $expanded = array();
+ $addr = explode(':', $addr);
+ foreach ( $addr as $i => $bytepair )
+ {
+ if ( empty($bytepair) )
+ {
+ // ::
+ while ( count($expanded) < (8 - count($addr) + $i + 1) )
+ {
+ $expanded[] = '0000';
+ }
+ }
+ else
+ {
+ while ( strlen($bytepair) < 4 )
+ $bytepair = "0$bytepair";
+ $expanded[] = $bytepair;
+ }
+ }
+ return implode(':', $expanded);
}
/**
@@ -3792,19 +3792,19 @@
function check_email_address($email)
{
- static $regexp = '(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*|(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*(?:(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*)*<[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*(?:,[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*)*:[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*>)';
- return ( preg_match("/^$regexp$/", $email) ) ? true : false;
+ static $regexp = '(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*|(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*(?:(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*)*<[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*(?:,[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*)*:[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*>)';
+ return ( preg_match("/^$regexp$/", $email) ) ? true : false;
}
function password_score_len($password)
{
- if ( !is_string($password) )
- {
- return -10;
- }
- $len = strlen($password);
- $score = $len - 7;
- return $score;
+ if ( !is_string($password) )
+ {
+ return -10;
+ }
+ $len = strlen($password);
+ $score = $len - 7;
+ return $score;
}
/**
@@ -3818,159 +3818,159 @@
function password_score($password, &$debug = false)
{
- if ( !is_string($password) )
- {
- return -10;
- }
- $score = 0;
- $debug = array();
- // length check
- $lenscore = password_score_len($password);
-
- $debug[] = "<b>How this score was calculated</b>\nYour score was tallied up based on an extensive algorithm which outputted\nthe following scores based on traits of your password. Above you can see the\ncomposite score; your individual scores based on certain tests are below.\n\nThe scale is open-ended, with a minimum score of -10. 10 is very strong, 4\nis strong, 1 is good and -3 is fair. Below -3 scores \"Weak.\"\n";
-
- $debug[] = 'Adding '.$lenscore.' points for length';
-
- $score += $lenscore;
-
- $has_upper_lower = false;
- $has_symbols = false;
- $has_numbers = false;
-
- // contains uppercase and lowercase
- if ( preg_match('/[A-z]+/', $password) && strtolower($password) != $password )
- {
- $score += 1;
- $has_upper_lower = true;
- $debug[] = 'Adding 1 point for having uppercase and lowercase';
- }
-
- // contains symbols
- if ( preg_match('/[^A-z0-9]+/', $password) )
- {
- $score += 1;
- $has_symbols = true;
- $debug[] = 'Adding 1 point for having nonalphanumeric characters (matching /[^A-z0-9]+/)';
- }
-
- // contains numbers
- if ( preg_match('/[0-9]+/', $password) )
- {
- $score += 1;
- $has_numbers = true;
- $debug[] = 'Adding 1 point for having numbers';
- }
-
- if ( $has_upper_lower && $has_symbols && $has_numbers && strlen($password) >= 9 )
- {
- // if it has uppercase and lowercase letters, symbols, and numbers, and is of considerable length, add some serious points
- $score += 4;
- $debug[] = 'Adding 4 points for having uppercase and lowercase, numbers, and nonalphanumeric and being more than 8 characters';
- }
- else if ( $has_upper_lower && $has_symbols && $has_numbers )
- {
- // still give some points for passing complexity check
- $score += 2;
- $debug[] = 'Adding 2 points for having uppercase and lowercase, numbers, and nonalphanumeric';
- }
- else if ( ( $has_upper_lower && $has_symbols ) ||
- ( $has_upper_lower && $has_numbers ) ||
- ( $has_symbols && $has_numbers ) )
- {
- // if 2 of the three main complexity checks passed, add a point
- $score += 1;
- $debug[] = 'Adding 1 point for having 2 of 3 complexity checks';
- }
- else if ( preg_match('/^[0-9]*?([a-z]+)[0-9]?$/', $password) )
- {
- // password is something like magnum1 which will be cracked in seconds
- $score += -4;
- $debug[] = 'Adding -4 points for being of the form [number][word][number]';
- }
- else if ( ( !$has_upper_lower && !$has_numbers && $has_symbols ) ||
- ( !$has_upper_lower && !$has_symbols && $has_numbers ) ||
- ( !$has_numbers && !$has_symbols && $has_upper_lower ) )
- {
- $score += -2;
- $debug[] = 'Adding -2 points for only meeting 1 complexity check';
- }
- else if ( !$has_upper_lower && !$has_numbers && !$has_symbols )
- {
- $debug[] = 'Adding -3 points for not meeting any complexity checks';
- $score += -3;
- }
-
- //
- // Repetition
- // Example: foobar12345 should be deducted points, where f1o2o3b4a5r should be given points
- //
-
- if ( preg_match('/([A-Z][A-Z][A-Z][A-Z]|[a-z][a-z][a-z][a-z])/', $password) )
- {
- $debug[] = 'Adding -2 points for having more than 4 letters of the same case in a row';
- $score += -2;
- }
- else if ( preg_match('/([A-Z][A-Z][A-Z]|[a-z][a-z][a-z])/', $password) )
- {
- $debug[] = 'Adding -1 points for having more than 3 letters of the same case in a row';
- $score += -1;
- }
- else if ( preg_match('/[A-z]/', $password) && !preg_match('/([A-Z][A-Z][A-Z]|[a-z][a-z][a-z])/', $password) )
- {
- $debug[] = 'Adding 1 point for never having more than 2 letters of the same case in a row';
- $score += 1;
- }
-
- if ( preg_match('/[0-9][0-9][0-9][0-9]/', $password) )
- {
- $debug[] = 'Adding -2 points for having 4 or more numbers in a row';
- $score += -2;
- }
- else if ( preg_match('/[0-9][0-9][0-9]/', $password) )
- {
- $debug[] = 'Adding -1 points for having 3 or more numbers in a row';
- $score += -1;
- }
- else if ( $has_numbers && !preg_match('/[0-9][0-9][0-9]/', $password) )
- {
- $debug[] = 'Adding 1 point for never more than 2 numbers in a row';
- $score += -1;
- }
-
- // make passwords like fooooooooooooooooooooooooooooooooooooo totally die by subtracting a point for each character repeated at least 3 times in a row
- $prev_char = '';
- $warn = false;
- $loss = 0;
- for ( $i = 0; $i < strlen($password); $i++ )
- {
- $chr = $password{$i};
- if ( $chr == $prev_char && $warn )
- {
- $loss += -1;
- }
- else if ( $chr == $prev_char && !$warn )
- {
- $warn = true;
- }
- else if ( $chr != $prev_char && $warn )
- {
- $warn = false;
- }
- $prev_char = $chr;
- }
- if ( $loss < 0 )
- {
- $debug[] = 'Adding '.$loss.' points for immediate character repetition';
- $score += $loss;
- // this can bring the score below -10 sometimes
- if ( $score < -10 )
- {
- $debug[] = 'Setting score to -10 because it went below ('.$score.')';
- $score = -10;
- }
- }
-
- return $score;
+ if ( !is_string($password) )
+ {
+ return -10;
+ }
+ $score = 0;
+ $debug = array();
+ // length check
+ $lenscore = password_score_len($password);
+
+ $debug[] = "<b>How this score was calculated</b>\nYour score was tallied up based on an extensive algorithm which outputted\nthe following scores based on traits of your password. Above you can see the\ncomposite score; your individual scores based on certain tests are below.\n\nThe scale is open-ended, with a minimum score of -10. 10 is very strong, 4\nis strong, 1 is good and -3 is fair. Below -3 scores \"Weak.\"\n";
+
+ $debug[] = 'Adding '.$lenscore.' points for length';
+
+ $score += $lenscore;
+
+ $has_upper_lower = false;
+ $has_symbols = false;
+ $has_numbers = false;
+
+ // contains uppercase and lowercase
+ if ( preg_match('/[A-z]+/', $password) && strtolower($password) != $password )
+ {
+ $score += 1;
+ $has_upper_lower = true;
+ $debug[] = 'Adding 1 point for having uppercase and lowercase';
+ }
+
+ // contains symbols
+ if ( preg_match('/[^A-z0-9]+/', $password) )
+ {
+ $score += 1;
+ $has_symbols = true;
+ $debug[] = 'Adding 1 point for having nonalphanumeric characters (matching /[^A-z0-9]+/)';
+ }
+
+ // contains numbers
+ if ( preg_match('/[0-9]+/', $password) )
+ {
+ $score += 1;
+ $has_numbers = true;
+ $debug[] = 'Adding 1 point for having numbers';
+ }
+
+ if ( $has_upper_lower && $has_symbols && $has_numbers && strlen($password) >= 9 )
+ {
+ // if it has uppercase and lowercase letters, symbols, and numbers, and is of considerable length, add some serious points
+ $score += 4;
+ $debug[] = 'Adding 4 points for having uppercase and lowercase, numbers, and nonalphanumeric and being more than 8 characters';
+ }
+ else if ( $has_upper_lower && $has_symbols && $has_numbers )
+ {
+ // still give some points for passing complexity check
+ $score += 2;
+ $debug[] = 'Adding 2 points for having uppercase and lowercase, numbers, and nonalphanumeric';
+ }
+ else if ( ( $has_upper_lower && $has_symbols ) ||
+ ( $has_upper_lower && $has_numbers ) ||
+ ( $has_symbols && $has_numbers ) )
+ {
+ // if 2 of the three main complexity checks passed, add a point
+ $score += 1;
+ $debug[] = 'Adding 1 point for having 2 of 3 complexity checks';
+ }
+ else if ( preg_match('/^[0-9]*?([a-z]+)[0-9]?$/', $password) )
+ {
+ // password is something like magnum1 which will be cracked in seconds
+ $score += -4;
+ $debug[] = 'Adding -4 points for being of the form [number][word][number]';
+ }
+ else if ( ( !$has_upper_lower && !$has_numbers && $has_symbols ) ||
+ ( !$has_upper_lower && !$has_symbols && $has_numbers ) ||
+ ( !$has_numbers && !$has_symbols && $has_upper_lower ) )
+ {
+ $score += -2;
+ $debug[] = 'Adding -2 points for only meeting 1 complexity check';
+ }
+ else if ( !$has_upper_lower && !$has_numbers && !$has_symbols )
+ {
+ $debug[] = 'Adding -3 points for not meeting any complexity checks';
+ $score += -3;
+ }
+
+ //
+ // Repetition
+ // Example: foobar12345 should be deducted points, where f1o2o3b4a5r should be given points
+ //
+
+ if ( preg_match('/([A-Z][A-Z][A-Z][A-Z]|[a-z][a-z][a-z][a-z])/', $password) )
+ {
+ $debug[] = 'Adding -2 points for having more than 4 letters of the same case in a row';
+ $score += -2;
+ }
+ else if ( preg_match('/([A-Z][A-Z][A-Z]|[a-z][a-z][a-z])/', $password) )
+ {
+ $debug[] = 'Adding -1 points for having more than 3 letters of the same case in a row';
+ $score += -1;
+ }
+ else if ( preg_match('/[A-z]/', $password) && !preg_match('/([A-Z][A-Z][A-Z]|[a-z][a-z][a-z])/', $password) )
+ {
+ $debug[] = 'Adding 1 point for never having more than 2 letters of the same case in a row';
+ $score += 1;
+ }
+
+ if ( preg_match('/[0-9][0-9][0-9][0-9]/', $password) )
+ {
+ $debug[] = 'Adding -2 points for having 4 or more numbers in a row';
+ $score += -2;
+ }
+ else if ( preg_match('/[0-9][0-9][0-9]/', $password) )
+ {
+ $debug[] = 'Adding -1 points for having 3 or more numbers in a row';
+ $score += -1;
+ }
+ else if ( $has_numbers && !preg_match('/[0-9][0-9][0-9]/', $password) )
+ {
+ $debug[] = 'Adding 1 point for never more than 2 numbers in a row';
+ $score += -1;
+ }
+
+ // make passwords like fooooooooooooooooooooooooooooooooooooo totally die by subtracting a point for each character repeated at least 3 times in a row
+ $prev_char = '';
+ $warn = false;
+ $loss = 0;
+ for ( $i = 0; $i < strlen($password); $i++ )
+ {
+ $chr = $password{$i};
+ if ( $chr == $prev_char && $warn )
+ {
+ $loss += -1;
+ }
+ else if ( $chr == $prev_char && !$warn )
+ {
+ $warn = true;
+ }
+ else if ( $chr != $prev_char && $warn )
+ {
+ $warn = false;
+ }
+ $prev_char = $chr;
+ }
+ if ( $loss < 0 )
+ {
+ $debug[] = 'Adding '.$loss.' points for immediate character repetition';
+ $score += $loss;
+ // this can bring the score below -10 sometimes
+ if ( $score < -10 )
+ {
+ $debug[] = 'Setting score to -10 because it went below ('.$score.')';
+ $score = -10;
+ }
+ }
+
+ return $score;
}
/**
@@ -3981,11 +3981,11 @@
function register_cron_task($func, $hour_interval = 24)
{
- global $cron_tasks;
- $hour_interval = strval($hour_interval);
- if ( !isset($cron_tasks[$hour_interval]) )
- $cron_tasks[$hour_interval] = array();
- $cron_tasks[$hour_interval][] = $func;
+ global $cron_tasks;
+ $hour_interval = strval($hour_interval);
+ if ( !isset($cron_tasks[$hour_interval]) )
+ $cron_tasks[$hour_interval] = array();
+ $cron_tasks[$hour_interval][] = $func;
}
/**
@@ -3995,10 +3995,10 @@
function get_cron_next_run()
{
- global $cron_tasks;
- $lowest_ivl = min(array_keys($cron_tasks));
- $last_run = intval(getConfig("cron_lastrun_ivl_$lowest_ivl"));
- return intval($last_run + ( 3600 * $lowest_ivl )) - 30;
+ global $cron_tasks;
+ $lowest_ivl = min(array_keys($cron_tasks));
+ $last_run = intval(getConfig("cron_lastrun_ivl_$lowest_ivl"));
+ return intval($last_run + ( 3600 * $lowest_ivl )) - 30;
}
/**
@@ -4011,53 +4011,53 @@
function install_language($lang_code, $lang_name_neutral, $lang_name_local, $lang_file = false)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = \'' . $db->escape($lang_code) . '\';');
- if ( !$q )
- $db->_die('functions.php - checking for language existence');
-
- if ( $db->numrows() > 0 )
- // Language already exists
- return false;
-
- $q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native)
- VALUES(
- \'' . $db->escape($lang_code) . '\',
- \'' . $db->escape($lang_name_neutral) . '\',
- \'' . $db->escape($lang_name_local) . '\'
- );');
- if ( !$q )
- $db->_die('functions.php - installing language');
-
- if ( ENANO_DBLAYER == 'PGSQL' )
- {
- // exception for Postgres, which doesn't support insert IDs
- // This will cause the Language class to just load by lang code
- // instead of by numeric ID
- $lang_id = $lang_code;
- }
- else
- {
- $lang_id = $db->insert_id();
- if ( empty($lang_id) || $lang_id == 0 )
- {
- $db->_die('functions.php - invalid returned lang_id');
- }
- }
-
- // Do we also need to install a language file?
- if ( is_string($lang_file) && file_exists($lang_file) )
- {
- $lang = new Language($lang_id);
- $lang->import($lang_file);
- }
- else if ( is_string($lang_file) && !file_exists($lang_file) )
- {
- echo '<b>Notice:</b> Can\'t load language file, so the specified language wasn\'t fully installed.<br />';
- return false;
- }
- return true;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = \'' . $db->escape($lang_code) . '\';');
+ if ( !$q )
+ $db->_die('functions.php - checking for language existence');
+
+ if ( $db->numrows() > 0 )
+ // Language already exists
+ return false;
+
+ $q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native)
+ VALUES(
+ \'' . $db->escape($lang_code) . '\',
+ \'' . $db->escape($lang_name_neutral) . '\',
+ \'' . $db->escape($lang_name_local) . '\'
+ );');
+ if ( !$q )
+ $db->_die('functions.php - installing language');
+
+ if ( ENANO_DBLAYER == 'PGSQL' )
+ {
+ // exception for Postgres, which doesn't support insert IDs
+ // This will cause the Language class to just load by lang code
+ // instead of by numeric ID
+ $lang_id = $lang_code;
+ }
+ else
+ {
+ $lang_id = $db->insert_id();
+ if ( empty($lang_id) || $lang_id == 0 )
+ {
+ $db->_die('functions.php - invalid returned lang_id');
+ }
+ }
+
+ // Do we also need to install a language file?
+ if ( is_string($lang_file) && file_exists($lang_file) )
+ {
+ $lang = new Language($lang_id);
+ $lang->import($lang_file);
+ }
+ else if ( is_string($lang_file) && !file_exists($lang_file) )
+ {
+ echo '<b>Notice:</b> Can\'t load language file, so the specified language wasn\'t fully installed.<br />';
+ return false;
+ }
+ return true;
}
/**
@@ -4067,43 +4067,43 @@
function list_available_languages()
{
- // Pulled from install/includes/common.php
-
- // Build a list of available languages
- $dir = @opendir( ENANO_ROOT . '/language' );
- if ( !$dir )
- die('CRITICAL: could not open language directory');
-
- $languages = array();
-
- while ( $dh = @readdir($dir) )
- {
- if ( $dh == '.' || $dh == '..' )
- continue;
- if ( file_exists( ENANO_ROOT . "/language/$dh/meta.json" ) )
- {
- // Found a language directory, determine metadata
- $meta = @file_get_contents( ENANO_ROOT . "/language/$dh/meta.json" );
- if ( empty($meta) )
- // Could not read metadata file, continue silently
- continue;
-
- // Do some syntax correction on the metadata
- $meta = enano_clean_json($meta);
-
- $meta = enano_json_decode($meta);
- if ( isset($meta['lang_name_english']) && isset($meta['lang_name_native']) && isset($meta['lang_code']) )
- {
- $languages[$meta['lang_code']] = array(
- 'name' => $meta['lang_name_native'],
- 'name_eng' => $meta['lang_name_english'],
- 'dir' => $dh
- );
- }
- }
- }
-
- return $languages;
+ // Pulled from install/includes/common.php
+
+ // Build a list of available languages
+ $dir = @opendir( ENANO_ROOT . '/language' );
+ if ( !$dir )
+ die('CRITICAL: could not open language directory');
+
+ $languages = array();
+
+ while ( $dh = @readdir($dir) )
+ {
+ if ( $dh == '.' || $dh == '..' )
+ continue;
+ if ( file_exists( ENANO_ROOT . "/language/$dh/meta.json" ) )
+ {
+ // Found a language directory, determine metadata
+ $meta = @file_get_contents( ENANO_ROOT . "/language/$dh/meta.json" );
+ if ( empty($meta) )
+ // Could not read metadata file, continue silently
+ continue;
+
+ // Do some syntax correction on the metadata
+ $meta = enano_clean_json($meta);
+
+ $meta = enano_json_decode($meta);
+ if ( isset($meta['lang_name_english']) && isset($meta['lang_name_native']) && isset($meta['lang_code']) )
+ {
+ $languages[$meta['lang_code']] = array(
+ 'name' => $meta['lang_name_native'],
+ 'name_eng' => $meta['lang_name_english'],
+ 'dir' => $dh
+ );
+ }
+ }
+ }
+
+ return $languages;
}
/**
@@ -4120,154 +4120,154 @@
function scale_image($in_file, $out_file, $width = 225, $height = 225, $unlink = false)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- if ( !is_int($width) || !is_int($height) )
- throw new Exception('Invalid height or width.');
-
- if ( !file_exists($in_file) )
- throw new Exception('Input file does not exist');
-
- $in_file_sh = escapeshellarg($in_file);
- $out_file_sh = escapeshellarg($out_file);
-
- if ( file_exists($out_file) && !$unlink )
- throw new Exception('Refusing to write output file as it already exists and $unlink was not specified.');
- else if ( file_exists($out_file) && $unlink )
- @unlink($out_file);
- if ( file_exists($out_file) )
- // couldn't unlink (delete) the output file
- throw new Exception('Failed to delete existing output file.');
-
- $file_ext = strtolower(substr($in_file, ( strrpos($in_file, '.') + 1)));
- switch($file_ext)
- {
- case 'png':
- $func = 'imagecreatefrompng';
- break;
- case 'jpg':
- case 'jpeg':
- $func = 'imagecreatefromjpeg';
- break;
- case 'gif':
- $func = 'imagecreatefromgif';
- break;
- case 'xpm':
- $func = 'imagecreatefromxpm';
- break;
- default:
- throw new Exception('Invalid extension of input file.');
- }
-
- $magick_path = getConfig('imagemagick_path');
- $can_use_magick = (
- getConfig('enable_imagemagick') == '1' &&
- file_exists($magick_path) &&
- is_executable($magick_path)
- );
- $can_use_gd = (
- function_exists('getimagesize') &&
- function_exists('imagecreatetruecolor') &&
- function_exists('imagecopyresampled') &&
- function_exists($func)
- );
- if ( $can_use_magick )
- {
- if ( !preg_match('/^([\/A-z0-9:\. _-]+)$/', $magick_path) )
- {
- die('SECURITY: ImageMagick path is screwy');
- }
- $cmdline = "$magick_path $in_file_sh -resize \"{$width}x{$height}>\" $out_file_sh";
- system($cmdline, $return);
- if ( !file_exists($out_file) )
- throw new Exception('ImageMagick: did not produce output image file.');
- return true;
- }
- else if ( $can_use_gd )
- {
- @list($width_orig, $height_orig) = @getimagesize($in_file);
- if ( !$width_orig || !$height_orig )
- throw new Exception('GD: Could not get height and width of input file.');
- // calculate new width and height
-
- $ratio = $width_orig / $height_orig;
- if ( $ratio > 1 )
- {
- // orig. width is greater that height
- $new_width = $width;
- $new_height = round( $width / $ratio );
- }
- else if ( $ratio < 1 )
- {
- // orig. height is greater than width
- $new_width = round( $height / $ratio );
- $new_height = $height;
- }
- else if ( $ratio == 1 )
- {
- $new_width = $width;
- $new_height = $width;
- }
- if ( $new_width > $width_orig || $new_height > $height_orig )
- {
- // Too big for our britches here; set it to only convert the file
- $new_width = $width_orig;
- $new_height = $height_orig;
- }
-
- $newimage = @imagecreatetruecolor($new_width, $new_height);
- if ( !$newimage )
- throw new Exception('GD: Request to create new truecolor image refused.');
- $oldimage = @$func($in_file);
- if ( !$oldimage )
- throw new Exception('GD: Request to load input image file failed.');
-
- // Perform scaling
- imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
-
- // Get output format
- $out_ext = strtolower(substr($out_file, ( strrpos($out_file, '.') + 1)));
- switch($out_ext)
- {
- case 'png':
- $outfunc = 'imagepng';
- break;
- case 'jpg':
- case 'jpeg':
- $outfunc = 'imagejpeg';
- break;
- case 'gif':
- $outfunc = 'imagegif';
- break;
- case 'xpm':
- $outfunc = 'imagexpm';
- break;
- default:
- imagedestroy($newimage);
- imagedestroy($oldimage);
- throw new Exception('GD: Invalid extension of output file.');
- }
-
- // Write output
- $outfunc($newimage, $out_file);
-
- // clean up
- imagedestroy($newimage);
- imagedestroy($oldimage);
-
- // done!
- return true;
- }
- // Neither scaling method worked; we'll let plugins try to scale it, and then if the file still doesn't exist, die
- $code = $plugins->setHook('scale_image_failure');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
- if ( file_exists($out_file) )
- return true;
-
- throw new Exception('Failed to find an appropriate method for scaling.');
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( !is_int($width) || !is_int($height) )
+ throw new Exception('Invalid height or width.');
+
+ if ( !file_exists($in_file) )
+ throw new Exception('Input file does not exist');
+
+ $in_file_sh = escapeshellarg($in_file);
+ $out_file_sh = escapeshellarg($out_file);
+
+ if ( file_exists($out_file) && !$unlink )
+ throw new Exception('Refusing to write output file as it already exists and $unlink was not specified.');
+ else if ( file_exists($out_file) && $unlink )
+ @unlink($out_file);
+ if ( file_exists($out_file) )
+ // couldn't unlink (delete) the output file
+ throw new Exception('Failed to delete existing output file.');
+
+ $file_ext = strtolower(substr($in_file, ( strrpos($in_file, '.') + 1)));
+ switch($file_ext)
+ {
+ case 'png':
+ $func = 'imagecreatefrompng';
+ break;
+ case 'jpg':
+ case 'jpeg':
+ $func = 'imagecreatefromjpeg';
+ break;
+ case 'gif':
+ $func = 'imagecreatefromgif';
+ break;
+ case 'xpm':
+ $func = 'imagecreatefromxpm';
+ break;
+ default:
+ throw new Exception('Invalid extension of input file.');
+ }
+
+ $magick_path = getConfig('imagemagick_path');
+ $can_use_magick = (
+ getConfig('enable_imagemagick') == '1' &&
+ file_exists($magick_path) &&
+ is_executable($magick_path)
+ );
+ $can_use_gd = (
+ function_exists('getimagesize') &&
+ function_exists('imagecreatetruecolor') &&
+ function_exists('imagecopyresampled') &&
+ function_exists($func)
+ );
+ if ( $can_use_magick )
+ {
+ if ( !preg_match('/^([\/A-z0-9:\. _-]+)$/', $magick_path) )
+ {
+ die('SECURITY: ImageMagick path is screwy');
+ }
+ $cmdline = "$magick_path $in_file_sh -resize \"{$width}x{$height}>\" $out_file_sh";
+ system($cmdline, $return);
+ if ( !file_exists($out_file) )
+ throw new Exception('ImageMagick: did not produce output image file.');
+ return true;
+ }
+ else if ( $can_use_gd )
+ {
+ @list($width_orig, $height_orig) = @getimagesize($in_file);
+ if ( !$width_orig || !$height_orig )
+ throw new Exception('GD: Could not get height and width of input file.');
+ // calculate new width and height
+
+ $ratio = $width_orig / $height_orig;
+ if ( $ratio > 1 )
+ {
+ // orig. width is greater that height
+ $new_width = $width;
+ $new_height = round( $width / $ratio );
+ }
+ else if ( $ratio < 1 )
+ {
+ // orig. height is greater than width
+ $new_width = round( $height / $ratio );
+ $new_height = $height;
+ }
+ else if ( $ratio == 1 )
+ {
+ $new_width = $width;
+ $new_height = $width;
+ }
+ if ( $new_width > $width_orig || $new_height > $height_orig )
+ {
+ // Too big for our britches here; set it to only convert the file
+ $new_width = $width_orig;
+ $new_height = $height_orig;
+ }
+
+ $newimage = @imagecreatetruecolor($new_width, $new_height);
+ if ( !$newimage )
+ throw new Exception('GD: Request to create new truecolor image refused.');
+ $oldimage = @$func($in_file);
+ if ( !$oldimage )
+ throw new Exception('GD: Request to load input image file failed.');
+
+ // Perform scaling
+ imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+
+ // Get output format
+ $out_ext = strtolower(substr($out_file, ( strrpos($out_file, '.') + 1)));
+ switch($out_ext)
+ {
+ case 'png':
+ $outfunc = 'imagepng';
+ break;
+ case 'jpg':
+ case 'jpeg':
+ $outfunc = 'imagejpeg';
+ break;
+ case 'gif':
+ $outfunc = 'imagegif';
+ break;
+ case 'xpm':
+ $outfunc = 'imagexpm';
+ break;
+ default:
+ imagedestroy($newimage);
+ imagedestroy($oldimage);
+ throw new Exception('GD: Invalid extension of output file.');
+ }
+
+ // Write output
+ $outfunc($newimage, $out_file);
+
+ // clean up
+ imagedestroy($newimage);
+ imagedestroy($oldimage);
+
+ // done!
+ return true;
+ }
+ // Neither scaling method worked; we'll let plugins try to scale it, and then if the file still doesn't exist, die
+ $code = $plugins->setHook('scale_image_failure');
+ foreach ( $code as $cmd )
+ {
+ eval($cmd);
+ }
+ if ( file_exists($out_file) )
+ return true;
+
+ throw new Exception('Failed to find an appropriate method for scaling.');
}
/**
@@ -4280,39 +4280,39 @@
function is_gif_animated($filename)
{
- $filecontents = @file_get_contents($filename);
- if ( empty($filecontents) )
- return false;
-
- $str_loc = 0;
- $count = 0;
- while ( $count < 2 ) // There is no point in continuing after we find a 2nd frame
- {
- $where1 = strpos($filecontents,"\x00\x21\xF9\x04", $str_loc);
- if ( $where1 === false )
- {
- break;
- }
- else
- {
- $str_loc = $where1 + 1;
- $where2 = strpos($filecontents,"\x00\x2C", $str_loc);
- if ( $where2 === false )
- {
- break;
- }
- else
- {
- if ( $where1 + 8 == $where2 )
- {
- $count++;
- }
- $str_loc = $where2 + 1;
- }
- }
- }
-
- return ( $count > 1 ) ? true : false;
+ $filecontents = @file_get_contents($filename);
+ if ( empty($filecontents) )
+ return false;
+
+ $str_loc = 0;
+ $count = 0;
+ while ( $count < 2 ) // There is no point in continuing after we find a 2nd frame
+ {
+ $where1 = strpos($filecontents,"\x00\x21\xF9\x04", $str_loc);
+ if ( $where1 === false )
+ {
+ break;
+ }
+ else
+ {
+ $str_loc = $where1 + 1;
+ $where2 = strpos($filecontents,"\x00\x2C", $str_loc);
+ if ( $where2 === false )
+ {
+ break;
+ }
+ else
+ {
+ if ( $where1 + 8 == $where2 )
+ {
+ $count++;
+ }
+ $str_loc = $where2 + 1;
+ }
+ }
+ }
+
+ return ( $count > 1 ) ? true : false;
}
/**
@@ -4323,17 +4323,17 @@
function gif_get_dimensions($filename)
{
- $filecontents = @file_get_contents($filename);
- if ( empty($filecontents) )
- return false;
- if ( strlen($filecontents) < 10 )
- return false;
-
- $width = substr($filecontents, 6, 2);
- $height = substr($filecontents, 8, 2);
- $width = unpack('v', $width);
- $height = unpack('v', $height);
- return array($width[1], $height[1]);
+ $filecontents = @file_get_contents($filename);
+ if ( empty($filecontents) )
+ return false;
+ if ( strlen($filecontents) < 10 )
+ return false;
+
+ $width = substr($filecontents, 6, 2);
+ $height = substr($filecontents, 8, 2);
+ $width = unpack('v', $width);
+ $height = unpack('v', $height);
+ return array($width[1], $height[1]);
}
/**
@@ -4344,19 +4344,19 @@
function is_png_animated($filename)
{
- $filecontents = @file_get_contents($filename);
- if ( empty($filecontents) )
- return false;
-
- $parsed = parse_png($filecontents);
- if ( !$parsed )
- return false;
-
- if ( !isset($parsed['fdAT']) )
- return false;
-
- if ( count($parsed['fdAT']) > 1 )
- return true;
+ $filecontents = @file_get_contents($filename);
+ if ( empty($filecontents) )
+ return false;
+
+ $parsed = parse_png($filecontents);
+ if ( !$parsed )
+ return false;
+
+ if ( !isset($parsed['fdAT']) )
+ return false;
+
+ if ( count($parsed['fdAT']) > 1 )
+ return true;
}
/**
@@ -4367,22 +4367,22 @@
function png_get_dimensions($filename)
{
- $filecontents = @file_get_contents($filename);
- if ( empty($filecontents) )
- return false;
-
- $parsed = parse_png($filecontents);
- if ( !$parsed )
- return false;
-
- $ihdr_stream = $parsed['IHDR'][0];
- $width = substr($ihdr_stream, 0, 4);
- $height = substr($ihdr_stream, 4, 4);
- $width = unpack('N', $width);
- $height = unpack('N', $height);
- $x = $width[1];
- $y = $height[1];
- return array($x, $y);
+ $filecontents = @file_get_contents($filename);
+ if ( empty($filecontents) )
+ return false;
+
+ $parsed = parse_png($filecontents);
+ if ( !$parsed )
+ return false;
+
+ $ihdr_stream = $parsed['IHDR'][0];
+ $width = substr($ihdr_stream, 0, 4);
+ $height = substr($ihdr_stream, 4, 4);
+ $width = unpack('N', $width);
+ $height = unpack('N', $height);
+ $x = $width[1];
+ $y = $height[1];
+ return array($x, $y);
}
/**
@@ -4393,37 +4393,37 @@
function parse_png($data)
{
- // Trim off first 8 bytes to check for PNG header
- $header = substr($data, 0, 8);
- if ( $header != "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
- {
- return false;
- }
- $return = array();
- $data = substr($data, 8);
- while ( strlen($data) > 0 )
- {
- $chunklen_bin = substr($data, 0, 4);
- $chunk_type = substr($data, 4, 4);
- $chunklen = unpack('N', $chunklen_bin);
- $chunklen = $chunklen[1];
- $chunk_data = substr($data, 8, $chunklen);
-
- // If the chunk type is not valid, this may be a malicious PNG with bad offsets. Break out of the loop.
- if ( !preg_match('/^[A-z]{4}$/', $chunk_type) )
- break;
-
- if ( !isset($return[$chunk_type]) )
- $return[$chunk_type] = array();
- $return[$chunk_type][] = $chunk_data;
-
- $offset_next = 4 // Length
- + 4 // Type
- + $chunklen // Data
- + 4; // CRC
- $data = substr($data, $offset_next);
- }
- return $return;
+ // Trim off first 8 bytes to check for PNG header
+ $header = substr($data, 0, 8);
+ if ( $header != "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
+ {
+ return false;
+ }
+ $return = array();
+ $data = substr($data, 8);
+ while ( strlen($data) > 0 )
+ {
+ $chunklen_bin = substr($data, 0, 4);
+ $chunk_type = substr($data, 4, 4);
+ $chunklen = unpack('N', $chunklen_bin);
+ $chunklen = $chunklen[1];
+ $chunk_data = substr($data, 8, $chunklen);
+
+ // If the chunk type is not valid, this may be a malicious PNG with bad offsets. Break out of the loop.
+ if ( !preg_match('/^[A-z]{4}$/', $chunk_type) )
+ break;
+
+ if ( !isset($return[$chunk_type]) )
+ $return[$chunk_type] = array();
+ $return[$chunk_type][] = $chunk_data;
+
+ $offset_next = 4 // Length
+ + 4 // Type
+ + $chunklen // Data
+ + 4; // CRC
+ $data = substr($data, $offset_next);
+ }
+ return $return;
}
/**
@@ -4436,51 +4436,51 @@
function get_jpeg_intrinsic_values( $jpeg_header_data )
{
- // Create a blank array for the output
- $Outputarray = array( );
-
- //Cycle through the header segments until Start Of Frame (SOF) is found or we run out of segments
- $i = 0;
- while ( ( $i < count( $jpeg_header_data) ) && ( substr( $jpeg_header_data[$i]['SegName'], 0, 3 ) != "SOF" ) )
- {
- $i++;
- }
-
- // Check if a SOF segment has been found
- if ( substr( $jpeg_header_data[$i]['SegName'], 0, 3 ) == "SOF" )
- {
- // SOF segment was found, extract the information
-
- $data = $jpeg_header_data[$i]['SegData'];
-
- // First byte is Bits per component
- $Outputarray['Bits per Component'] = ord( $data{0} );
-
- // Second and third bytes are Image Height
- $Outputarray['Image Height'] = ord( $data{ 1 } ) * 256 + ord( $data{ 2 } );
-
- // Forth and fifth bytes are Image Width
- $Outputarray['Image Width'] = ord( $data{ 3 } ) * 256 + ord( $data{ 4 } );
-
- // Sixth byte is number of components
- $numcomponents = ord( $data{ 5 } );
-
- // Following this is a table containing information about the components
- for( $i = 0; $i < $numcomponents; $i++ )
- {
- $Outputarray['Components'][] = array ( 'Component Identifier' => ord( $data{ 6 + $i * 3 } ),
- 'Horizontal Sampling Factor' => ( ord( $data{ 7 + $i * 3 } ) & 0xF0 ) / 16,
- 'Vertical Sampling Factor' => ( ord( $data{ 7 + $i * 3 } ) & 0x0F ),
- 'Quantization table destination selector' => ord( $data{ 8 + $i * 3 } ) );
- }
- }
- else
- {
- // Couldn't find Start Of Frame segment, hence can't retrieve info
- return FALSE;
- }
-
- return $Outputarray;
+ // Create a blank array for the output
+ $Outputarray = array( );
+
+ //Cycle through the header segments until Start Of Frame (SOF) is found or we run out of segments
+ $i = 0;
+ while ( ( $i < count( $jpeg_header_data) ) && ( substr( $jpeg_header_data[$i]['SegName'], 0, 3 ) != "SOF" ) )
+ {
+ $i++;
+ }
+
+ // Check if a SOF segment has been found
+ if ( substr( $jpeg_header_data[$i]['SegName'], 0, 3 ) == "SOF" )
+ {
+ // SOF segment was found, extract the information
+
+ $data = $jpeg_header_data[$i]['SegData'];
+
+ // First byte is Bits per component
+ $Outputarray['Bits per Component'] = ord( $data{0} );
+
+ // Second and third bytes are Image Height
+ $Outputarray['Image Height'] = ord( $data{ 1 } ) * 256 + ord( $data{ 2 } );
+
+ // Forth and fifth bytes are Image Width
+ $Outputarray['Image Width'] = ord( $data{ 3 } ) * 256 + ord( $data{ 4 } );
+
+ // Sixth byte is number of components
+ $numcomponents = ord( $data{ 5 } );
+
+ // Following this is a table containing information about the components
+ for( $i = 0; $i < $numcomponents; $i++ )
+ {
+ $Outputarray['Components'][] = array ( 'Component Identifier' => ord( $data{ 6 + $i * 3 } ),
+ 'Horizontal Sampling Factor' => ( ord( $data{ 7 + $i * 3 } ) & 0xF0 ) / 16,
+ 'Vertical Sampling Factor' => ( ord( $data{ 7 + $i * 3 } ) & 0x0F ),
+ 'Quantization table destination selector' => ord( $data{ 8 + $i * 3 } ) );
+ }
+ }
+ else
+ {
+ // Couldn't find Start Of Frame segment, hence can't retrieve info
+ return FALSE;
+ }
+
+ return $Outputarray;
}
/**
@@ -4493,103 +4493,103 @@
function get_jpeg_header_data( $filename )
{
- // Attempt to open the jpeg file - the at symbol supresses the error message about
- // not being able to open files. The file_exists would have been used, but it
- // does not work with files fetched over http or ftp.
- $filehnd = @fopen($filename, 'rb');
-
- // Check if the file opened successfully
- if ( ! $filehnd )
- {
- // Could't open the file - exit
- return FALSE;
- }
-
-
- // Read the first two characters
- $data = fread( $filehnd, 2 );
-
- // Check that the first two characters are 0xFF 0xDA (SOI - Start of image)
- if ( $data != "\xFF\xD8" )
- {
- // No SOI (FF D8) at start of file - This probably isn't a JPEG file - close file and return;
- fclose($filehnd);
- return FALSE;
- }
-
-
- // Read the third character
- $data = fread( $filehnd, 2 );
-
- // Check that the third character is 0xFF (Start of first segment header)
- if ( $data{0} != "\xFF" )
- {
- // NO FF found - close file and return - JPEG is probably corrupted
- fclose($filehnd);
- return FALSE;
- }
-
- // Flag that we havent yet hit the compressed image data
- $hit_compressed_image_data = FALSE;
-
-
- // Cycle through the file until, one of: 1) an EOI (End of image) marker is hit,
- // 2) we have hit the compressed image data (no more headers are allowed after data)
- // 3) or end of file is hit
-
- while ( ( $data{1} != "\xD9" ) && (! $hit_compressed_image_data) && ( ! feof( $filehnd ) ))
- {
- // Found a segment to look at.
- // Check that the segment marker is not a Restart marker - restart markers don't have size or data after them
- if ( ( ord($data{1}) < 0xD0 ) || ( ord($data{1}) > 0xD7 ) )
- {
- // Segment isn't a Restart marker
- // Read the next two bytes (size)
- $sizestr = fread( $filehnd, 2 );
-
- // convert the size bytes to an integer
- $decodedsize = unpack ("nsize", $sizestr);
-
- // Save the start position of the data
- $segdatastart = ftell( $filehnd );
-
- // Read the segment data with length indicated by the previously read size
- $segdata = fread( $filehnd, $decodedsize['size'] - 2 );
-
-
- // Store the segment information in the output array
- $headerdata[] = array( "SegType" => ord($data{1}),
- "SegName" => $GLOBALS[ "JPEG_Segment_Names" ][ ord($data{1}) ],
- "SegDataStart" => $segdatastart,
- "SegData" => $segdata );
- }
-
- // If this is a SOS (Start Of Scan) segment, then there is no more header data - the compressed image data follows
- if ( $data{1} == "\xDA" )
- {
- // Flag that we have hit the compressed image data - exit loop as no more headers available.
- $hit_compressed_image_data = TRUE;
- }
- else
- {
- // Not an SOS - Read the next two bytes - should be the segment marker for the next segment
- $data = fread( $filehnd, 2 );
-
- // Check that the first byte of the two is 0xFF as it should be for a marker
- if ( $data{0} != "\xFF" )
- {
- // NO FF found - close file and return - JPEG is probably corrupted
- fclose($filehnd);
- return FALSE;
- }
- }
- }
-
- // Close File
- fclose($filehnd);
-
- // Return the header data retrieved
- return $headerdata;
+ // Attempt to open the jpeg file - the at symbol supresses the error message about
+ // not being able to open files. The file_exists would have been used, but it
+ // does not work with files fetched over http or ftp.
+ $filehnd = @fopen($filename, 'rb');
+
+ // Check if the file opened successfully
+ if ( ! $filehnd )
+ {
+ // Could't open the file - exit
+ return FALSE;
+ }
+
+
+ // Read the first two characters
+ $data = fread( $filehnd, 2 );
+
+ // Check that the first two characters are 0xFF 0xDA (SOI - Start of image)
+ if ( $data != "\xFF\xD8" )
+ {
+ // No SOI (FF D8) at start of file - This probably isn't a JPEG file - close file and return;
+ fclose($filehnd);
+ return FALSE;
+ }
+
+
+ // Read the third character
+ $data = fread( $filehnd, 2 );
+
+ // Check that the third character is 0xFF (Start of first segment header)
+ if ( $data{0} != "\xFF" )
+ {
+ // NO FF found - close file and return - JPEG is probably corrupted
+ fclose($filehnd);
+ return FALSE;
+ }
+
+ // Flag that we havent yet hit the compressed image data
+ $hit_compressed_image_data = FALSE;
+
+
+ // Cycle through the file until, one of: 1) an EOI (End of image) marker is hit,
+ // 2) we have hit the compressed image data (no more headers are allowed after data)
+ // 3) or end of file is hit
+
+ while ( ( $data{1} != "\xD9" ) && (! $hit_compressed_image_data) && ( ! feof( $filehnd ) ))
+ {
+ // Found a segment to look at.
+ // Check that the segment marker is not a Restart marker - restart markers don't have size or data after them
+ if ( ( ord($data{1}) < 0xD0 ) || ( ord($data{1}) > 0xD7 ) )
+ {
+ // Segment isn't a Restart marker
+ // Read the next two bytes (size)
+ $sizestr = fread( $filehnd, 2 );
+
+ // convert the size bytes to an integer
+ $decodedsize = unpack ("nsize", $sizestr);
+
+ // Save the start position of the data
+ $segdatastart = ftell( $filehnd );
+
+ // Read the segment data with length indicated by the previously read size
+ $segdata = fread( $filehnd, $decodedsize['size'] - 2 );
+
+
+ // Store the segment information in the output array
+ $headerdata[] = array( "SegType" => ord($data{1}),
+ "SegName" => $GLOBALS[ "JPEG_Segment_Names" ][ ord($data{1}) ],
+ "SegDataStart" => $segdatastart,
+ "SegData" => $segdata );
+ }
+
+ // If this is a SOS (Start Of Scan) segment, then there is no more header data - the compressed image data follows
+ if ( $data{1} == "\xDA" )
+ {
+ // Flag that we have hit the compressed image data - exit loop as no more headers available.
+ $hit_compressed_image_data = TRUE;
+ }
+ else
+ {
+ // Not an SOS - Read the next two bytes - should be the segment marker for the next segment
+ $data = fread( $filehnd, 2 );
+
+ // Check that the first byte of the two is 0xFF as it should be for a marker
+ if ( $data{0} != "\xFF" )
+ {
+ // NO FF found - close file and return - JPEG is probably corrupted
+ fclose($filehnd);
+ return FALSE;
+ }
+ }
+ }
+
+ // Close File
+ fclose($filehnd);
+
+ // Return the header data retrieved
+ return $headerdata;
}
/**
@@ -4600,33 +4600,33 @@
function jpg_get_dimensions($filename)
{
- if ( !file_exists($filename) )
- {
- echo "Doesn't exist<br />";
- return false;
- }
-
- $headers = get_jpeg_header_data($filename);
- if ( !$headers )
- {
- echo "Bad headers<br />";
- return false;
- }
-
- $metadata = get_jpeg_intrinsic_values($headers);
- if ( !$metadata )
- {
- echo "Bad metadata: <pre>" . print_r($metadata, true) . "</pre><br />";
- return false;
- }
-
- if ( !isset($metadata['Image Width']) || !isset($metadata['Image Height']) )
- {
- echo "No metadata<br />";
- return false;
- }
-
- return array($metadata['Image Width'], $metadata['Image Height']);
+ if ( !file_exists($filename) )
+ {
+ echo "Doesn't exist<br />";
+ return false;
+ }
+
+ $headers = get_jpeg_header_data($filename);
+ if ( !$headers )
+ {
+ echo "Bad headers<br />";
+ return false;
+ }
+
+ $metadata = get_jpeg_intrinsic_values($headers);
+ if ( !$metadata )
+ {
+ echo "Bad metadata: <pre>" . print_r($metadata, true) . "</pre><br />";
+ return false;
+ }
+
+ if ( !isset($metadata['Image Width']) || !isset($metadata['Image Height']) )
+ {
+ echo "No metadata<br />";
+ return false;
+ }
+
+ return array($metadata['Image Width'], $metadata['Image Height']);
}
/**
@@ -4639,42 +4639,42 @@
function make_avatar_url($user_id, $avi_type, $user_email = false)
{
- static $img_types = array(
- 'png' => IMAGE_TYPE_PNG,
- 'gif' => IMAGE_TYPE_GIF,
- 'jpg' => IMAGE_TYPE_JPG,
- 'grv' => IMAGE_TYPE_GRV
- );
-
- if ( !is_int($user_id) )
- return false;
- if ( !isset($img_types[$avi_type]) )
- return false;
-
- if ( $avi_type == 'grv' )
- {
- if ( $user_email )
- {
- return make_gravatar_url($user_email);
- }
- }
- else
- {
- $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type;
- if ( !file_exists(ENANO_ROOT . $avi_relative_path) )
- {
- return '';
- }
- }
-
- $img_type = $img_types[$avi_type];
-
- $dateline = @filemtime(ENANO_ROOT . $avi_relative_path);
- $avi_id = pack('VVv', $dateline, $user_id, $img_type);
- $avi_id = hexencode($avi_id, '', '');
-
- // return scriptPath . $avi_relative_path;
- return makeUrlNS('Special', "Avatar/$avi_id");
+ static $img_types = array(
+ 'png' => IMAGE_TYPE_PNG,
+ 'gif' => IMAGE_TYPE_GIF,
+ 'jpg' => IMAGE_TYPE_JPG,
+ 'grv' => IMAGE_TYPE_GRV
+ );
+
+ if ( !is_int($user_id) )
+ return false;
+ if ( !isset($img_types[$avi_type]) )
+ return false;
+
+ if ( $avi_type == 'grv' )
+ {
+ if ( $user_email )
+ {
+ return make_gravatar_url($user_email);
+ }
+ }
+ else
+ {
+ $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type;
+ if ( !file_exists(ENANO_ROOT . $avi_relative_path) )
+ {
+ return '';
+ }
+ }
+
+ $img_type = $img_types[$avi_type];
+
+ $dateline = @filemtime(ENANO_ROOT . $avi_relative_path);
+ $avi_id = pack('VVv', $dateline, $user_id, $img_type);
+ $avi_id = hexencode($avi_id, '', '');
+
+ // return scriptPath . $avi_relative_path;
+ return makeUrlNS('Special', "Avatar/$avi_id");
}
/**
@@ -4686,28 +4686,28 @@
function make_gravatar_url($email, $size = false)
{
- $email = md5($email);
-
- // gravatar parameters
- if ( $size )
- {
- $max_size = intval($size);
- }
- else
- {
- $max_x = intval(getConfig('avatar_max_width', '150'));
- $max_y = intval(getConfig('avatar_max_height', '150'));
- // ?s=
- $max_size = ( $max_x > $max_y ) ? $max_y : $max_x;
- }
-
- // ?r=
- $rating = getConfig('gravatar_rating', 'g');
-
- // final URL
- $url = "http://www.gravatar.com/avatar/$email?r=$rating&s=$max_size";
-
- return $url;
+ $email = md5($email);
+
+ // gravatar parameters
+ if ( $size )
+ {
+ $max_size = intval($size);
+ }
+ else
+ {
+ $max_x = intval(getConfig('avatar_max_width', '150'));
+ $max_y = intval(getConfig('avatar_max_height', '150'));
+ // ?s=
+ $max_size = ( $max_x > $max_y ) ? $max_y : $max_x;
+ }
+
+ // ?r=
+ $rating = getConfig('gravatar_rating', 'g');
+
+ // final URL
+ $url = "http://www.gravatar.com/avatar/$email?r=$rating&s=$max_size";
+
+ return $url;
}
/**
@@ -4718,20 +4718,20 @@
function get_image_filetype($filename)
{
- $filecontents = @file_get_contents($filename);
- if ( empty($filecontents) )
- return false;
-
- if ( substr($filecontents, 0, 8) == "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
- return 'png';
-
- if ( substr($filecontents, 0, 6) == 'GIF87a' || substr($filecontents, 0, 6) == 'GIF89a' )
- return 'gif';
-
- if ( substr($filecontents, 0, 2) == "\xFF\xD8" )
- return 'jpg';
-
- return false;
+ $filecontents = @file_get_contents($filename);
+ if ( empty($filecontents) )
+ return false;
+
+ if ( substr($filecontents, 0, 8) == "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
+ return 'png';
+
+ if ( substr($filecontents, 0, 6) == 'GIF87a' || substr($filecontents, 0, 6) == 'GIF89a' )
+ return 'gif';
+
+ if ( substr($filecontents, 0, 2) == "\xFF\xD8" )
+ return 'jpg';
+
+ return false;
}
/**
@@ -4741,11 +4741,11 @@
function enano_json_singleton()
{
- static $json_obj;
- if ( !is_object($json_obj) )
- $json_obj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE | SERVICES_JSON_SUPPRESS_ERRORS);
-
- return $json_obj;
+ static $json_obj;
+ if ( !is_object($json_obj) )
+ $json_obj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE | SERVICES_JSON_SUPPRESS_ERRORS);
+
+ return $json_obj;
}
/**
@@ -4756,15 +4756,15 @@
function enano_json_encode($data)
{
- /*
- if ( function_exists('json_encode') )
- {
- // using PHP5 with JSON support
- return json_encode($data);
- }
- */
-
- return Zend_Json::encode($data, true);
+ /*
+ if ( function_exists('json_encode') )
+ {
+ // using PHP5 with JSON support
+ return json_encode($data);
+ }
+ */
+
+ return Zend_Json::encode($data, true);
}
/**
@@ -4775,15 +4775,15 @@
function enano_json_decode($data)
{
- /*
- if ( function_exists('json_decode') )
- {
- // using PHP5 with JSON support
- return json_decode($data);
- }
- */
-
- return Zend_Json::decode($data, Zend_Json::TYPE_ARRAY);
+ /*
+ if ( function_exists('json_decode') )
+ {
+ // using PHP5 with JSON support
+ return json_decode($data);
+ }
+ */
+
+ return Zend_Json::decode($data, Zend_Json::TYPE_ARRAY);
}
/**
@@ -4794,19 +4794,19 @@
function enano_clean_json($json)
{
- // eliminate comments
- $json = preg_replace(array(
- // eliminate single line comments in '// ...' form
- '#^\s*//(.*)$#m',
- // eliminate multi-line comments in '/* ... */' form, at start of string
- '#^\s*/\*(.+)\*/#Us',
- // eliminate multi-line comments in '/* ... */' form, at end of string
- '#/\*(.+)\*/\s*$#Us'
- ), '', $json);
-
- $json = preg_replace('/([,\{\[])(?:[\r\n]+)([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $json);
-
- return $json;
+ // eliminate comments
+ $json = preg_replace(array(
+ // eliminate single line comments in '// ...' form
+ '#^\s*//(.*)$#m',
+ // eliminate multi-line comments in '/* ... */' form, at start of string
+ '#^\s*/\*(.+)\*/#Us',
+ // eliminate multi-line comments in '/* ... */' form, at end of string
+ '#/\*(.+)\*/\s*$#Us'
+ ), '', $json);
+
+ $json = preg_replace('/([,\{\[])(?:[\r\n]+)([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $json);
+
+ return $json;
}
/**
@@ -4817,7 +4817,7 @@
function enano_trim_json($json)
{
- return preg_replace('/^([^{]+)\{/', '{', preg_replace('/\}([^}]+)$/', '}', $json));
+ return preg_replace('/^([^{]+)\{/', '{', preg_replace('/\}([^}]+)$/', '}', $json));
}
/**
@@ -4826,22 +4826,22 @@
function profiler_start()
{
- global $_profiler;
- $_profiler = array();
-
- if ( !defined('ENANO_DEBUG') )
- return false;
-
- $_profiler[] = array(
- 'point' => 'Profiling started',
- 'time' => microtime_float(),
- 'backtrace' => false,
- 'mem' => false
- );
- if ( function_exists('memory_get_usage') )
- {
- $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
- }
+ global $_profiler;
+ $_profiler = array();
+
+ if ( !defined('ENANO_DEBUG') )
+ return false;
+
+ $_profiler[] = array(
+ 'point' => 'Profiling started',
+ 'time' => microtime_float(),
+ 'backtrace' => false,
+ 'mem' => false
+ );
+ if ( function_exists('memory_get_usage') )
+ {
+ $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+ }
}
/**
@@ -4854,27 +4854,27 @@
function profiler_log($point, $allow_backtrace = true, $parent_event = false)
{
- if ( !defined('ENANO_DEBUG') )
- return false;
-
- global $_profiler;
- $backtrace = false;
- if ( $allow_backtrace && function_exists('debug_print_backtrace') )
- {
- list(, $backtrace) = explode("\n", enano_debug_print_backtrace(true));
- }
- $_profiler[] = array(
- 'point' => $point,
- 'time' => microtime_float(),
- 'backtrace' => $backtrace,
- 'mem' => false,
- 'parent_event' => $parent_event
- );
- if ( function_exists('memory_get_usage') )
- {
- $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
- }
- return count($_profiler) - 1;
+ if ( !defined('ENANO_DEBUG') )
+ return false;
+
+ global $_profiler;
+ $backtrace = false;
+ if ( $allow_backtrace && function_exists('debug_print_backtrace') )
+ {
+ list(, $backtrace) = explode("\n", enano_debug_print_backtrace(true));
+ }
+ $_profiler[] = array(
+ 'point' => $point,
+ 'time' => microtime_float(),
+ 'backtrace' => $backtrace,
+ 'mem' => false,
+ 'parent_event' => $parent_event
+ );
+ if ( function_exists('memory_get_usage') )
+ {
+ $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+ }
+ return count($_profiler) - 1;
}
/**
@@ -4884,14 +4884,14 @@
function profiler_message($message)
{
- if ( !defined('ENANO_DEBUG') )
- return false;
-
- global $_profiler;
-
- $_profiler[] = array(
- 'message' => $message,
- );
+ if ( !defined('ENANO_DEBUG') )
+ return false;
+
+ global $_profiler;
+
+ $_profiler[] = array(
+ 'message' => $message,
+ );
}
/**
@@ -4901,7 +4901,7 @@
function profiler_dump()
{
- return $GLOBALS['_profiler'];
+ return $GLOBALS['_profiler'];
}
/**
@@ -4911,91 +4911,91 @@
function profiler_make_html()
{
- if ( !defined('ENANO_DEBUG') )
- return '';
-
- $profile = profiler_dump();
-
- $html = '<div class="tblholder">';
- $html .= '<table border="0" cellspacing="1" cellpadding="4">';
-
- $time_start = $time_last = $profile[0]['time'];
-
- foreach ( $profile as $i => $entry )
- {
- // $time_since_last = $entry['time'] - $time_last;
- // if ( $time_since_last < 0.01 )
- // continue;
-
- if ( isset($entry['message']) )
- {
- $html .= "<!-- ########################################################## -->\n<tr>\n <th colspan=\"2\">Message $i</th>\n</tr>";
-
- $html .= '<tr>' . "\n";
- $html .= ' <td class="row2">Message:</td>' . "\n";
- $html .= ' <td class="row1">' . htmlspecialchars($entry['message']) . '</td>' . "\n";
- $html .= '</tr>' . "\n";
- continue;
- }
-
- $html .= "<!-- ########################################################## -->\n<tr>\n <th colspan=\"2\">Event $i</th>\n</tr>";
-
- $html .= '<tr>' . "\n";
- $html .= ' <td class="row2">Event:</td>' . "\n";
- $html .= ' <td class="row1">' . htmlspecialchars($entry['point']) . '</td>' . "\n";
- $html .= '</tr>' . "\n";
-
- $time = $entry['time'] - $time_start;
-
- $html .= '<tr>' . "\n";
- $html .= ' <td class="row2">Time since start:</td>' . "\n";
- $html .= ' <td class="row1">' . $time . 's</td>' . "\n";
- $html .= '</tr>' . "\n";
-
- $time_label = 'Time since last event:';
- if ( $entry['parent_event'] && is_int($entry['parent_event']) && isset($profile[$entry['parent_event']]) )
- {
- $time_last = $profile[$entry['parent_event']]['time'];
- $time_label = "Time since event #{$entry['parent_event']}:";
- }
-
- $time = $entry['time'] - $time_last;
- if ( $time < 0.0001 )
- $time_html = 'Marginal';
- else
- $time_html = number_format($time, 6) . "s";
-
- if ( $time > 0.02 )
- $time_html = "<span style=\"background-color: #a00; padding: 4px; color: #fff; font-weight: bold;\">$time_html</span>";
-
- $html .= '<tr>' . "\n";
- $html .= ' <td class="row2">' . $time_label . '</td>' . "\n";
- $html .= ' <td class="row1">' . $time_html . '</td>' . "\n";
- $html .= '</tr>' . "\n";
-
- if ( $entry['backtrace'] )
- {
- $html .= '<tr>' . "\n";
- $html .= ' <td class="row2">Called from:</td>' . "\n";
- $html .= ' <td class="row1">' . htmlspecialchars($entry['backtrace']) . '</td>' . "\n";
- $html .= '</tr>' . "\n";
- }
-
- if ( $entry['mem'] )
- {
- $html .= '<tr>' . "\n";
- $html .= ' <td class="row2">Total mem usage:</td>' . "\n";
- $html .= ' <td class="row1">' . htmlspecialchars($entry['mem']) . ' (bytes)</td>' . "\n";
- $html .= '</tr>' . "\n";
- }
-
- $html .= "\n";
-
- $time_last = $entry['time'];
- }
- $html .= '</table></div>';
-
- return $html;
+ if ( !defined('ENANO_DEBUG') )
+ return '';
+
+ $profile = profiler_dump();
+
+ $html = '<div class="tblholder">';
+ $html .= '<table border="0" cellspacing="1" cellpadding="4">';
+
+ $time_start = $time_last = $profile[0]['time'];
+
+ foreach ( $profile as $i => $entry )
+ {
+ // $time_since_last = $entry['time'] - $time_last;
+ // if ( $time_since_last < 0.01 )
+ // continue;
+
+ if ( isset($entry['message']) )
+ {
+ $html .= "<!-- ########################################################## -->\n<tr>\n <th colspan=\"2\">Message $i</th>\n</tr>";
+
+ $html .= '<tr>' . "\n";
+ $html .= ' <td class="row2">Message:</td>' . "\n";
+ $html .= ' <td class="row1">' . htmlspecialchars($entry['message']) . '</td>' . "\n";
+ $html .= '</tr>' . "\n";
+ continue;
+ }
+
+ $html .= "<!-- ########################################################## -->\n<tr>\n <th colspan=\"2\">Event $i</th>\n</tr>";
+
+ $html .= '<tr>' . "\n";
+ $html .= ' <td class="row2">Event:</td>' . "\n";
+ $html .= ' <td class="row1">' . htmlspecialchars($entry['point']) . '</td>' . "\n";
+ $html .= '</tr>' . "\n";
+
+ $time = $entry['time'] - $time_start;
+
+ $html .= '<tr>' . "\n";
+ $html .= ' <td class="row2">Time since start:</td>' . "\n";
+ $html .= ' <td class="row1">' . $time . 's</td>' . "\n";
+ $html .= '</tr>' . "\n";
+
+ $time_label = 'Time since last event:';
+ if ( $entry['parent_event'] && is_int($entry['parent_event']) && isset($profile[$entry['parent_event']]) )
+ {
+ $time_last = $profile[$entry['parent_event']]['time'];
+ $time_label = "Time since event #{$entry['parent_event']}:";
+ }
+
+ $time = $entry['time'] - $time_last;
+ if ( $time < 0.0001 )
+ $time_html = 'Marginal';
+ else
+ $time_html = number_format($time, 6) . "s";
+
+ if ( $time > 0.02 )
+ $time_html = "<span style=\"background-color: #a00; padding: 4px; color: #fff; font-weight: bold;\">$time_html</span>";
+
+ $html .= '<tr>' . "\n";
+ $html .= ' <td class="row2">' . $time_label . '</td>' . "\n";
+ $html .= ' <td class="row1">' . $time_html . '</td>' . "\n";
+ $html .= '</tr>' . "\n";
+
+ if ( $entry['backtrace'] )
+ {
+ $html .= '<tr>' . "\n";
+ $html .= ' <td class="row2">Called from:</td>' . "\n";
+ $html .= ' <td class="row1">' . htmlspecialchars($entry['backtrace']) . '</td>' . "\n";
+ $html .= '</tr>' . "\n";
+ }
+
+ if ( $entry['mem'] )
+ {
+ $html .= '<tr>' . "\n";
+ $html .= ' <td class="row2">Total mem usage:</td>' . "\n";
+ $html .= ' <td class="row1">' . htmlspecialchars($entry['mem']) . ' (bytes)</td>' . "\n";
+ $html .= '</tr>' . "\n";
+ }
+
+ $html .= "\n";
+
+ $time_last = $entry['time'];
+ }
+ $html .= '</table></div>';
+
+ return $html;
}
// Might as well start the profiler, it has no external dependencies except from this file.
@@ -5010,14 +5010,14 @@
function get_char_count($string, $char)
{
- $char = substr($char, 0, 1);
- $count = 0;
- for ( $i = 0; $i < strlen($string); $i++ )
- {
- if ( $string{$i} == $char )
- $count++;
- }
- return $count;
+ $char = substr($char, 0, 1);
+ $count = 0;
+ for ( $i = 0; $i < strlen($string); $i++ )
+ {
+ if ( $string{$i} == $char )
+ $count++;
+ }
+ return $count;
}
/**
@@ -5028,52 +5028,52 @@
function get_line_count($string)
{
- return ( get_char_count($string, "\n") ) + 1;
+ return ( get_char_count($string, "\n") ) + 1;
}
if ( !function_exists('sys_get_temp_dir') )
{
- // Based on http://www.phpit.net/
- // article/creating-zip-tar-archives-dynamically-php/2/
- /**
- * Attempt to get the system's temp directory.
- * @return string or bool false on failure
- */
-
- function sys_get_temp_dir()
- {
- // Try to get from environment variable
- if ( !empty($_ENV['TMP']) )
- {
- return realpath( $_ENV['TMP'] );
- }
- else if ( !empty($_ENV['TMPDIR']) )
- {
- return realpath( $_ENV['TMPDIR'] );
- }
- else if ( !empty($_ENV['TEMP']) )
- {
- return realpath( $_ENV['TEMP'] );
- }
-
- // Detect by creating a temporary file
- else
- {
- // Try to use system's temporary directory
- // as random name shouldn't exist
- $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
- if ( $temp_file )
- {
- $temp_dir = realpath( dirname($temp_file) );
- unlink( $temp_file );
- return $temp_dir;
- }
- else
- {
- return FALSE;
- }
- }
- }
+ // Based on http://www.phpit.net/
+ // article/creating-zip-tar-archives-dynamically-php/2/
+ /**
+ * Attempt to get the system's temp directory.
+ * @return string or bool false on failure
+ */
+
+ function sys_get_temp_dir()
+ {
+ // Try to get from environment variable
+ if ( !empty($_ENV['TMP']) )
+ {
+ return realpath( $_ENV['TMP'] );
+ }
+ else if ( !empty($_ENV['TMPDIR']) )
+ {
+ return realpath( $_ENV['TMPDIR'] );
+ }
+ else if ( !empty($_ENV['TEMP']) )
+ {
+ return realpath( $_ENV['TEMP'] );
+ }
+
+ // Detect by creating a temporary file
+ else
+ {
+ // Try to use system's temporary directory
+ // as random name shouldn't exist
+ $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
+ if ( $temp_file )
+ {
+ $temp_dir = realpath( dirname($temp_file) );
+ unlink( $temp_file );
+ return $temp_dir;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ }
}
/**
@@ -5082,25 +5082,25 @@
function fetch_rank_data()
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- $sql = $session->generate_rank_sql();
- $q = $db->sql_query($sql);
- if ( !$q )
- $db->_die();
-
- $GLOBALS['user_ranks'] = array();
- global $user_ranks;
-
- while ( $row = $db->fetchrow($q) )
- {
- $user_id = $row['user_id'];
- $username = $row['username'];
- $row = $session->calculate_user_rank($row);
- $user_ranks[$username] = $row;
- $user_ranks[$user_id] =& $user_ranks[$username];
- }
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang;
+
+ $sql = $session->generate_rank_sql();
+ $q = $db->sql_query($sql);
+ if ( !$q )
+ $db->_die();
+
+ $GLOBALS['user_ranks'] = array();
+ global $user_ranks;
+
+ while ( $row = $db->fetchrow($q) )
+ {
+ $user_id = $row['user_id'];
+ $username = $row['username'];
+ $row = $session->calculate_user_rank($row);
+ $user_ranks[$username] = $row;
+ $user_ranks[$user_id] =& $user_ranks[$username];
+ }
}
/**
@@ -5109,42 +5109,42 @@
function generate_cache_userranks()
{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
- global $user_ranks;
-
- fetch_rank_data();
-
- $user_ranks_stripped = array();
- foreach ( $user_ranks as $key => $value )
- {
- if ( is_int($key) )
- $user_ranks_stripped[$key] = $value;
- }
-
- $ranks_exported = "<?php\n\n// Automatically generated user rank cache.\nglobal \$user_ranks;\n" . '$user_ranks = ' . $lang->var_export_string($user_ranks_stripped) . ';';
- $uid_map = array();
- foreach ( $user_ranks as $id => $row )
- {
- if ( !is_int($id) )
- {
- $username = $id;
- continue;
- }
-
- $un_san = addslashes($username);
- $ranks_exported .= "\n\$user_ranks['$un_san'] =& \$user_ranks[{$row['user_id']}];";
- }
- $ranks_exported .= "\n\ndefine('ENANO_RANKS_CACHE_LOADED', 1); \n?>";
-
- // open ranks cache file
- $fh = @fopen( ENANO_ROOT . '/cache/cache_ranks.php', 'w' );
- if ( !$fh )
- return false;
- fwrite($fh, $ranks_exported);
- fclose($fh);
-
- return true;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang;
+ global $user_ranks;
+
+ fetch_rank_data();
+
+ $user_ranks_stripped = array();
+ foreach ( $user_ranks as $key => $value )
+ {
+ if ( is_int($key) )
+ $user_ranks_stripped[$key] = $value;
+ }
+
+ $ranks_exported = "<?php\n\n// Automatically generated user rank cache.\nglobal \$user_ranks;\n" . '$user_ranks = ' . $lang->var_export_string($user_ranks_stripped) . ';';
+ $uid_map = array();
+ foreach ( $user_ranks as $id => $row )
+ {
+ if ( !is_int($id) )
+ {
+ $username = $id;
+ continue;
+ }
+
+ $un_san = addslashes($username);
+ $ranks_exported .= "\n\$user_ranks['$un_san'] =& \$user_ranks[{$row['user_id']}];";
+ }
+ $ranks_exported .= "\n\ndefine('ENANO_RANKS_CACHE_LOADED', 1); \n?>";
+
+ // open ranks cache file
+ $fh = @fopen( ENANO_ROOT . '/cache/cache_ranks.php', 'w' );
+ if ( !$fh )
+ return false;
+ fwrite($fh, $ranks_exported);
+ fclose($fh);
+
+ return true;
}
/**
@@ -5153,14 +5153,14 @@
function load_rank_data()
{
- if ( file_exists( ENANO_ROOT . '/cache/cache_ranks.php' ) )
- {
- @include(ENANO_ROOT . '/cache/cache_ranks.php');
- }
- if ( !defined('ENANO_RANKS_CACHE_LOADED') )
- {
- fetch_rank_data();
- }
+ if ( file_exists( ENANO_ROOT . '/cache/cache_ranks.php' ) )
+ {
+ @include(ENANO_ROOT . '/cache/cache_ranks.php');
+ }
+ if ( !defined('ENANO_RANKS_CACHE_LOADED') )
+ {
+ fetch_rank_data();
+ }
}
/**
@@ -5169,45 +5169,45 @@
function purge_all_caches()
{
- global $cache;
- if ( $dh = opendir(ENANO_ROOT . '/cache') )
- {
- $cache->purge('page_meta');
- $cache->purge('anon_sidebar');
- $cache->purge('plugins');
- $cache->purge('wiki_edit_notice');
-
- $data_files = array(
- 'aes_decrypt.php',
- // ranks cache is stored using a custom engine (not enano's default cache)
- 'cache_ranks.php'
- );
- while ( $file = @readdir($dh) )
- {
- $fullpath = ENANO_ROOT . "/cache/$file";
- // we don't want to mess with directories
- if ( !is_file($fullpath) )
- continue;
-
- // data files
- if ( in_array($file, $data_files) )
- unlink($fullpath);
- // template files
- else if ( preg_match('/\.(?:tpl|css)\.php$/', $file) )
- unlink($fullpath);
- // compressed javascript
- else if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) )
- unlink($fullpath);
- // tinymce stuff
- else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) )
- unlink($fullpath);
- // language files
- else if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) )
- unlink($fullpath);
- }
- return true;
- }
- return false;
+ global $cache;
+ if ( $dh = opendir(ENANO_ROOT . '/cache') )
+ {
+ $cache->purge('page_meta');
+ $cache->purge('anon_sidebar');
+ $cache->purge('plugins');
+ $cache->purge('wiki_edit_notice');
+
+ $data_files = array(
+ 'aes_decrypt.php',
+ // ranks cache is stored using a custom engine (not enano's default cache)
+ 'cache_ranks.php'
+ );
+ while ( $file = @readdir($dh) )
+ {
+ $fullpath = ENANO_ROOT . "/cache/$file";
+ // we don't want to mess with directories
+ if ( !is_file($fullpath) )
+ continue;
+
+ // data files
+ if ( in_array($file, $data_files) )
+ unlink($fullpath);
+ // template files
+ else if ( preg_match('/\.(?:tpl|css)\.php$/', $file) )
+ unlink($fullpath);
+ // compressed javascript
+ else if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) )
+ unlink($fullpath);
+ // tinymce stuff
+ else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) )
+ unlink($fullpath);
+ // language files
+ else if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) )
+ unlink($fullpath);
+ }
+ return true;
+ }
+ return false;
}
/**
@@ -5218,27 +5218,27 @@
function which($executable)
{
- $path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
- if ( !$path )
- // couldn't get OS's PATH
- return false;
-
- $win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
- $extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
- $separator = $win32 ? ';' : ':';
- $paths = explode($separator, $path);
- foreach ( $paths as $dir )
- {
- foreach ( $extensions as $ext )
- {
- $fullpath = "$dir/{$executable}{$ext}";
- if ( @file_exists($fullpath) && @is_executable($fullpath) )
- {
- return $fullpath;
- }
- }
- }
- return false;
+ $path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
+ if ( !$path )
+ // couldn't get OS's PATH
+ return false;
+
+ $win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
+ $extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
+ $separator = $win32 ? ';' : ':';
+ $paths = explode($separator, $path);
+ foreach ( $paths as $dir )
+ {
+ foreach ( $extensions as $ext )
+ {
+ $fullpath = "$dir/{$executable}{$ext}";
+ if ( @file_exists($fullpath) && @is_executable($fullpath) )
+ {
+ return $fullpath;
+ }
+ }
+ }
+ return false;
}
/**
@@ -5249,51 +5249,51 @@
function write_test($filename)
{
- // We need to actually _open_ the file to make sure it can be written, because sometimes this fails even when is_writable() returns
- // true on Windows/IIS servers. Don't ask me why.
-
- $file = ENANO_ROOT . '/' . $filename;
- if ( is_dir($file) )
- {
- $file = rtrim($file, '/') . '/' . 'enanoinstalltest.txt';
- if ( file_exists($file) )
- {
- $fp = @fopen($file, 'a+');
- if ( !$fp )
- return false;
- fclose($fp);
- unlink($file);
- return true;
- }
- else
- {
- $fp = @fopen($file, 'w');
- if ( !$fp )
- return false;
- fclose($fp);
- unlink($file);
- return true;
- }
- }
- else
- {
- if ( file_exists($file) )
- {
- $fp = @fopen($file, 'a+');
- if ( !$fp )
- return false;
- fclose($fp);
- return true;
- }
- else
- {
- $fp = @fopen($file, 'w');
- if ( !$fp )
- return false;
- fclose($fp);
- return true;
- }
- }
+ // We need to actually _open_ the file to make sure it can be written, because sometimes this fails even when is_writable() returns
+ // true on Windows/IIS servers. Don't ask me why.
+
+ $file = ENANO_ROOT . '/' . $filename;
+ if ( is_dir($file) )
+ {
+ $file = rtrim($file, '/') . '/' . 'enanoinstalltest.txt';
+ if ( file_exists($file) )
+ {
+ $fp = @fopen($file, 'a+');
+ if ( !$fp )
+ return false;
+ fclose($fp);
+ unlink($file);
+ return true;
+ }
+ else
+ {
+ $fp = @fopen($file, 'w');
+ if ( !$fp )
+ return false;
+ fclose($fp);
+ unlink($file);
+ return true;
+ }
+ }
+ else
+ {
+ if ( file_exists($file) )
+ {
+ $fp = @fopen($file, 'a+');
+ if ( !$fp )
+ return false;
+ fclose($fp);
+ return true;
+ }
+ else
+ {
+ $fp = @fopen($file, 'w');
+ if ( !$fp )
+ return false;
+ fclose($fp);
+ return true;
+ }
+ }
}
/**
@@ -5303,20 +5303,20 @@
function install_get_crypto_backend()
{
- $crypto_backend = 'none';
-
- // Extension test: BCMath
- if ( function_exists('bcadd') )
- $crypto_backend = 'bcmath';
-
- // Extension test: Big_Int
- if ( function_exists('bi_from_str') )
- $crypto_backend = 'bigint';
-
- // Extension test: GMP
- if ( function_exists('gmp_init') )
- $crypto_backend = 'gmp';
-
- return $crypto_backend;
+ $crypto_backend = 'none';
+
+ // Extension test: BCMath
+ if ( function_exists('bcadd') )
+ $crypto_backend = 'bcmath';
+
+ // Extension test: Big_Int
+ if ( function_exists('bi_from_str') )
+ $crypto_backend = 'bigint';
+
+ // Extension test: GMP
+ if ( function_exists('gmp_init') )
+ $crypto_backend = 'gmp';
+
+ return $crypto_backend;
}