Multi function library
| > Module written by Matt Mecham
| > Date started: 14th February 2002
|
| > Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/
class FUNC {
var $time_formats = array();
var $time_options = array();
var $offset = "";
var $offset_set = 0;
var $num_format = "";
var $allow_unicode = 1;
var $get_magic_quotes = 0;
// Set up some standards to save CPU later
function FUNC() {
global $INFO;
$this->time_options = array( 'JOINED' => $INFO['clock_joined'],
'SHORT' => $INFO['clock_short'],
'LONG' => $INFO['clock_long']
);
$this->num_format = ($INFO['number_format'] == 'space') ? ' ' : $INFO['number_format'];
$this->get_magic_quotes = get_magic_quotes_gpc();
}
/*-------------------------------------------------------------------------*/
// expire_subscription
// ------------------
// Remove member's subscription
/*-------------------------------------------------------------------------*/
function expire_subscription()
{
global $DB, $ibforums;
$query = "sub_end=0";
// Get subscription details...
$DB->query("SELECT * FROM ibf_subscription_trans WHERE subtrans_state='paid' AND subtrans_member_id={$ibforums->member['id']}");
if ( $row = $DB->fetch_row() )
{
if ( $row['subtrans_old_group'] > 0 )
{
$DB->query("SELECT g_id FROM ibf_groups WHERE g_id={$row['subtrans_old_group']}");
if ( $group = $DB->fetch_row() )
{
$query .= ", mgroup={$row['subtrans_old_group']}";
}
else
{
// Group has been deleted, reset back to base member group
$query .= ", mgroup={$ibforums->vars['member_group']}";
}
}
$DB->query("UPDATE ibf_subscription_trans SET subtrans_state='expired' WHERE subtrans_id={$row['subtrans_id']}");
}
$DB->query("UPDATE ibf_members SET $query WHERE id={$ibforums->member['id']}");
}
/*-------------------------------------------------------------------------*/
// txt_stripslashes
// ------------------
// Make Big5 safe - only strip if not already...
/*-------------------------------------------------------------------------*/
function txt_stripslashes($t)
{
if ( $this->get_magic_quotes )
{
$t = stripslashes($t);
}
return $t;
}
/*-------------------------------------------------------------------------*/
// txt_raw2form
// ------------------
// makes _POST text safe for text areas
/*-------------------------------------------------------------------------*/
function txt_raw2form($t="")
{
$t = str_replace( '$', "$", $t);
if ( get_magic_quotes_gpc() )
{
$t = stripslashes($t);
}
$t = preg_replace( "/\\\(?!&#|\?#)/", "\", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// Safe Slashes - ensures slashes are saved correctly
// ------------------
//
/*-------------------------------------------------------------------------*/
function txt_safeslashes($t="")
{
return str_replace( '\\', "\\\\", $this->txt_stripslashes($t));
}
/*-------------------------------------------------------------------------*/
// txt_htmlspecialchars
// ------------------
// Custom version of htmlspecialchars to take into account mb chars
/*-------------------------------------------------------------------------*/
function txt_htmlspecialchars($t="")
{
// Use forward look up to only convert & not {
$t = preg_replace("/&(?!#[0-9]+;)/s", '&', $t );
$t = str_replace( "<", "<" , $t );
$t = str_replace( ">", ">" , $t );
$t = str_replace( '"', """, $t );
return $t; // A nice cup of?
}
/*-------------------------------------------------------------------------*/
// txt_UNhtmlspecialchars
// ------------------
// Undoes what the above function does. Yes.
/*-------------------------------------------------------------------------*/
function txt_UNhtmlspecialchars($t="")
{
$t = str_replace( "&" , "&", $t );
$t = str_replace( "<" , "<", $t );
$t = str_replace( ">" , ">", $t );
$t = str_replace( """, '"', $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// return_md5_check
// ------------------
// md5 hash for server side validation of form / link stuff
/*-------------------------------------------------------------------------*/
function return_md5_check()
{
global $ibforums;
if ( $ibforums->member['id'] )
{
return md5($ibforums->member['email'].'&'.$ibforums->member['password'].'&'.$ibforums->member['joined']);
}
else
{
return md5("this is only here to prevent it breaking on guests");
}
}
/*-------------------------------------------------------------------------*/
// C.O.C.S (clean old comma-delimeted strings)
// ------------------
// <>
/*-------------------------------------------------------------------------*/
function trim_leading_comma($t)
{
return preg_replace( "/^,/", "", $t );
}
function trim_trailing_comma($t)
{
return preg_replace( "/,$/", "", $t );
}
function clean_comma($t)
{
return preg_replace( "/,{2,}/", ",", $t );
}
function clean_perm_string($t)
{
$t = $this->clean_comma($t);
$t = $this->trim_leading_comma($t);
$t = $this->trim_trailing_comma($t);
return $t;
}
/*-------------------------------------------------------------------------*/
// size_format
// ------------------
// Give it a byte to eat and it'll return nice stuff!
/*-------------------------------------------------------------------------*/
function size_format($bytes="")
{
global $ibforums;
$retval = "";
if ($bytes >= 1048576)
{
$retval = round($bytes / 1048576 * 100 ) / 100 . $ibforums->lang['sf_mb'];
}
else if ($bytes >= 1024)
{
$retval = round($bytes / 1024 * 100 ) / 100 . $ibforums->lang['sf_k'];
}
else
{
$retval = $bytes . $ibforums->lang['sf_bytes'];
}
return $retval;
}
/*-------------------------------------------------------------------------*/
// print_forum_rules
// ------------------
// Checks and prints forum rules (if required)
/*-------------------------------------------------------------------------*/
function print_forum_rules($forum)
{
global $ibforums, $skin_universal;
$ruleshtml = "";
if ($forum['show_rules'])
{
if ( $forum['rules_title'] )
{
$rules['title'] = $forum['rules_title'];
$rules['body'] = $forum['rules_text'];
$rules['fid'] = $forum['id'];
$ruleshtml = $forum['show_rules'] == 2 ? $skin_universal->forum_show_rules_full($rules) : $skin_universal->forum_show_rules_link($rules);
}
}
return $ruleshtml;
}
/*-------------------------------------------------------------------------*/
//
// hdl_ban_line() : Get / set ban info
// Returns array on get and string on "set"
//
/*-------------------------------------------------------------------------*/
function hdl_ban_line($bline)
{
global $ibforums;
if ( is_array( $bline ) )
{
// Set ( 'timespan' 'unit' )
$factor = $bline['unit'] == 'd' ? 86400 : 3600;
$date_end = time() + ( $bline['timespan'] * $factor );
return time() . ':' . $date_end . ':' . $bline['timespan'] . ':' . $bline['unit'];
}
else
{
$arr = array();
list( $arr['date_start'], $arr['date_end'], $arr['timespan'], $arr['unit'] ) = explode( ":", $bline );
return $arr;
}
}
/*-------------------------------------------------------------------------*/
//
// check_perms() : Nice little sub to check perms
// Returns TRUE if access is allowed, FALSE if not.
//
/*-------------------------------------------------------------------------*/
function check_perms($forum_perm="")
{
global $ibforums;
if ( $forum_perm == "" )
{
return FALSE;
}
else if ( $forum_perm == '*' )
{
return TRUE;
}
else
{
$forum_perm_array = explode( ",", $forum_perm );
foreach( $ibforums->perm_id_array as $u_id )
{
if ( in_array( $u_id, $forum_perm_array ) )
{
return TRUE;
}
}
// Still here? Not a match then.
return FALSE;
}
}
/*-------------------------------------------------------------------------*/
//
// do_number_format() : Nice little sub to handle common stuff
//
/*-------------------------------------------------------------------------*/
function do_number_format($number)
{
global $ibforums;
if ($ibforums->vars['number_format'] != 'none')
{
return number_format($number , 0, '', $this->num_format);
}
else
{
return $number;
}
}
/*-------------------------------------------------------------------------*/
//
// hdl_forum_read_cookie()
//
/*-------------------------------------------------------------------------*/
function hdl_forum_read_cookie($set="")
{
global $ibforums;
if ( $set == "" )
{
// Get cookie and return array...
if ( $fread = $this->my_getcookie('forum_read') )
{
$farray = unserialize(stripslashes($fread));
if ( is_array($farray) and count($farray) > 0 )
{
foreach( $farray as $id => $stamp )
{
$ibforums->forum_read[$id] = $stamp;
}
}
}
return TRUE;
}
else
{
// Set cookie...
$fread = addslashes(serialize($ibforums->forum_read));
$this->my_setcookie('forum_read', $fread);
return TRUE;
}
}
/*-------------------------------------------------------------------------*/
//
// Return scaled down image
//
/*-------------------------------------------------------------------------*/
function scale_image($arg)
{
// max_width, max_height, cur_width, cur_height
$ret = array(
'img_width' => $arg['cur_width'],
'img_height' => $arg['cur_height']
);
if ( $arg['cur_width'] > $arg['max_width'] )
{
$ret['img_width'] = $arg['max_width'];
$ret['img_height'] = ceil( ( $arg['cur_height'] * ( ( $arg['max_width'] * 100 ) / $arg['cur_width'] ) ) / 100 );
$arg['cur_height'] = $ret['img_height'];
$arg['cur_width'] = $ret['img_width'];
}
if ( $arg['cur_height'] > $arg['max_height'] )
{
$ret['img_height'] = $arg['max_height'];
$ret['img_width'] = ceil( ( $arg['cur_width'] * ( ( $arg['max_height'] * 100 ) / $arg['cur_height'] ) ) / 100 );
}
return $ret;
}
/*-------------------------------------------------------------------------*/
//
// Show NORMAL created security image(s)...
//
/*-------------------------------------------------------------------------*/
function show_gif_img($this_number="")
{
global $ibforums, $DB;
$numbers = array( 0 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUDH5hiKsOnmqSPjtT1ZdnnjCUqBQAOw==',
1 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUjAEWyMqoXIprRkjxtZJWrz3iCBQAOw==',
2 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUDH5hiKubnpPzRQvoVbvyrDHiWAAAOw==',
3 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVDH5hiKbaHgRyUZtmlPtlfnnMiGUFADs=',
4 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVjAN5mLDtjFJMRjpj1Rv6v1SHN0IFADs=',
5 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUhA+Bpxn/DITL1SRjnps63l1M9RQAOw==',
6 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVjIEYyWwH3lNyrQTbnVh2Tl3N5wQFADs=',
7 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUhI9pwbztAAwP1napnFnzbYEYWAAAOw==',
8 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVDH5hiKubHgSPWXoxVUxC33FZZCkFADs=',
9 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVDA6hyJabnnISnsnybXdS73hcZlUFADs=',
);
flush();
header("Content-type: image/gif");
echo base64_decode($numbers[ $this_number ]);
exit();
}
/*-------------------------------------------------------------------------*/
//
// Show GD created security image...
//
/*-------------------------------------------------------------------------*/
function show_gd_img($content="")
{
global $ibforums, $DB;
flush();
@header("Content-Type: image/jpeg");
if ( $ibforums->vars['use_ttf'] != 1 )
{
$font_style = 5;
$no_chars = strlen($content);
$charheight = ImageFontHeight($font_style);
$charwidth = ImageFontWidth($font_style);
$strwidth = $charwidth * intval($no_chars);
$strheight = $charheight;
$imgwidth = $strwidth + 15;
$imgheight = $strheight + 15;
$img_c_x = $imgwidth / 2;
$img_c_y = $imgheight / 2;
$im = ImageCreate($imgwidth, $imgheight);
$text_col = ImageColorAllocate($im, 0, 0, 0);
$back_col = ImageColorAllocate($im, 200,200,200);
ImageFilledRectangle($im, 0, 0, $imgwidth, $imgheight, $text_col);
ImageFilledRectangle($im, 3, 3, $imgwidth - 4, $imgheight - 4, $back_col);
$draw_pos_x = $img_c_x - ($strwidth / 2) + 1;
$draw_pos_y = $img_c_y - ($strheight / 2) + 1;
ImageString($im, $font_style, $draw_pos_x, $draw_pos_y, $content, $text_col);
}
else
{
$image_x = isset($ibforums->vars['gd_width']) ? $ibforums->vars['gd_width'] : 250;
$image_y = isset($ibforums->vars['gd_height']) ? $ibforums->vars['gd_height'] : 70;
$im = imagecreate($image_x,$image_y);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
$grey = ImageColorAllocate($im, 200, 200, 200 );
$no_x_lines = ($image_x - 1) / 5;
for ( $i = 0; $i <= $no_x_lines; $i++ )
{
// X lines
ImageLine( $im, $i * $no_x_lines, 0, $i * $no_x_lines, $image_y, $grey );
// Diag lines
ImageLine( $im, $i * $no_x_lines, 0, ($i * $no_x_lines)+$no_x_lines, $image_y, $grey );
}
$no_y_lines = ($image_y - 1) / 5;
for ( $i = 0; $i <= $no_y_lines; $i++ )
{
ImageLine( $im, 0, $i * $no_y_lines, $image_x, $i * $no_y_lines, $grey );
}
$font = isset($ibforums->vars['gd_font']) ? $ibforums->vars['gd_font'] : getcwd().'/fonts/progbot.ttf';
$text_bbox = ImageTTFBBox(20, 0, $font, $content);
$sx = ($image_x - ($text_bbox[2] - $text_bbox[0])) / 2;
$sy = ($image_y - ($text_bbox[1] - $text_bbox[7])) / 2;
$sy -= $text_bbox[7];
imageTTFtext($im, 20, 0, $sx, $sy, $black, $font, $content);
}
ImageJPEG($im);
ImageDestroy($im);
exit();
}
/*-------------------------------------------------------------------------*/
//
// Convert newlines to
nl2br is buggy with
on early PHP builds
//
/*-------------------------------------------------------------------------*/
function my_nl2br($t="")
{
return str_replace( "\n", "
", $t );
}
/*-------------------------------------------------------------------------*/
//
// Convert
to newlines
//
/*-------------------------------------------------------------------------*/
function my_br2nl($t="")
{
$t = preg_replace( "#(?:\n|\r)?
(?:\n|\r)?#", "\n", $t );
$t = preg_replace( "#(?:\n|\r)?
(?:\n|\r)?#" , "\n", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
//
// Load a template file from DB or from PHP file
//
/*-------------------------------------------------------------------------*/
function load_template( $name, $id='' )
{
global $ibforums, $DB;
$tags = 1;
if ($ibforums->vars['safe_mode_skins'] == 0)
{
// Simply require and return
require ROOT_PATH."Skin/".$ibforums->skin_id."/$name.php";
return new $name();
}
else
{
// We're using safe mode skins, yippee
// Load the data from the DB
$DB->query("SELECT func_name, func_data, section_content FROM ibf_skin_templates WHERE set_id='".$ibforums->skin_rid."' AND group_name='$name'");
if ( ! $DB->get_num_rows() )
{
fatal_error("Could not fetch the templates from the database. Template $name, ID {$ibforums->skin_rid}");
}
else
{
$new_class = "class $name {\n";
while( $row = $DB->fetch_row() )
{
if ($tags == 1)
{
$comment = "\n";
}
$new_class .= 'function '.$row['func_name'].'('.$row['func_data'].") {\n";
$new_class .= "global \$ibforums;\n";
$new_class .= 'return << 0)
{
return "$name";
}
else
{
return $name;
}
}
/*-------------------------------------------------------------------------*/
//
// Redirect using HTTP commands, not a page meta tag.
//
/*-------------------------------------------------------------------------*/
function boink_it($url)
{
global $ibforums;
// Ensure &s are taken care of
$url = str_replace( "&", "&", $url );
if ($ibforums->vars['header_redirect'] == 'refresh')
{
@header("Refresh: 0;url=".$url);
}
else if ($ibforums->vars['header_redirect'] == 'html')
{
@flush();
echo("");
exit();
}
else
{
@header("Location: ".$url);
}
exit();
}
/*-------------------------------------------------------------------------*/
//
// Create a random 8 character password
//
/*-------------------------------------------------------------------------*/
function make_password()
{
$pass = "";
$chars = array(
"1","2","3","4","5","6","7","8","9","0",
"a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
"k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
"u","U","v","V","w","W","x","X","y","Y","z","Z");
$count = count($chars) - 1;
srand((double)microtime()*1000000);
for($i = 0; $i < 8; $i++)
{
$pass .= $chars[rand(0, $count)];
}
return($pass);
}
/*-------------------------------------------------------------------------*/
//
// Generate the appropriate folder icon for a forum
//
/*-------------------------------------------------------------------------*/
function forum_new_posts($forum_data, $sub=0) {
global $ibforums, $std;
$rtime = $ibforums->input['last_visit'];
$fid = $forum_data['fid'] == "" ? $forum_data['id'] : $forum_data['fid'];
$ftime = $ibforums->forum_read[ $fid ];
$rtime = $ftime > $rtime ? $ftime : $rtime;
if ($sub == 0)
{
if ( ! $forum_data['status'] )
{
return "<{C_LOCKED}>";
}
$sub_cat_img = '';
}
else
{
$sub_cat_img = '_CAT';
}
if ($forum_data['password'] and $sub == 0)
{
return $forum_data['last_post'] > $rtime ? "<{C_ON_RES}>"
: "<{C_OFF_RES}>";
}
return $forum_data['last_post'] > $rtime ? "<{C_ON".$sub_cat_img."}>"
: "<{C_OFF".$sub_cat_img."}>";
}
/*-------------------------------------------------------------------------*/
//
// Generate the appropriate folder icon for a topic
//
/*-------------------------------------------------------------------------*/
function folder_icon($topic, $dot="", $last_time=-1) {
global $ibforums;
$last_time = $last_time > $ibforums->input['last_visit'] ? $last_time : $ibforums->input['last_visit'];
if ($dot != "")
{
$dot = "_DOT";
}
if ($topic['state'] == 'closed')
{
return "<{B_LOCKED}>";
}
if ($topic['poll_state'])
{
if ( ! $ibforums->member['id'] )
{
return "<{B_POLL".$dot."}>";
}
if ($topic['last_post'] > $topic['last_vote'])
{
$topic['last_vote'] = $topic['last_post'];
}
if ($last_time && ($topic['last_vote'] > $last_time ))
{
return "<{B_POLL".$dot."}>";
}
if ($last_time && ($topic['last_vote'] < $last_time ))
{
return "<{B_POLL_NN".$dot."}>";
}
return "<{B_POLL".$dot."}>";
}
if ($topic['state'] == 'moved' or $topic['state'] == 'link')
{
return "<{B_MOVED}>";
}
if ( ! $ibforums->member['id'] )
{
return "<{B_NORM".$dot."}>";
}
if (($topic['posts'] + 1 >= $ibforums->vars['hot_topic']) and ( (isset($last_time) ) && ($topic['last_post'] <= $last_time )))
{
return "<{B_HOT_NN".$dot."}>";
}
if ($topic['posts'] + 1 >= $ibforums->vars['hot_topic'])
{
return "<{B_HOT".$dot."}>";
}
if ($last_time && ($topic['last_post'] > $last_time))
{
return "<{B_NEW".$dot."}>";
}
return "<{B_NORM".$dot."}>";
}
/*-------------------------------------------------------------------------*/
// text_tidy:
// Takes raw text from the DB and makes it all nice and pretty - which also
// parses un-HTML'd characters. Use this with caution!
/*-------------------------------------------------------------------------*/
function text_tidy($txt = "") {
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$txt = strtr( $txt, $trans );
$txt = preg_replace( "/\s{2}/" , " " , $txt );
$txt = preg_replace( "/\r/" , "\n" , $txt );
$txt = preg_replace( "/\t/" , " " , $txt );
//$txt = preg_replace( "/\\n/" , "\n" , $txt );
return $txt;
}
/*-------------------------------------------------------------------------*/
// compile_db_string:
// Takes an array of keys and values and formats them into a string the DB
// can use.
// $array = ( 'THIS' => 'this', 'THAT' => 'that' );
// will be returned as THIS, THAT 'this', 'that'
/*-------------------------------------------------------------------------*/
function compile_db_string($data) {
$field_names = "";
$field_values = "";
foreach ($data as $k => $v) {
$v = preg_replace( "/'/", "\\'", $v );
$field_names .= "$k,";
$field_values .= "'$v',";
}
$field_names = preg_replace( "/,$/" , "" , $field_names );
$field_values = preg_replace( "/,$/" , "" , $field_values );
return array( 'FIELD_NAMES' => $field_names,
'FIELD_VALUES' => $field_values,
);
}
/*-------------------------------------------------------------------------*/
// Build up page span links
/*-------------------------------------------------------------------------*/
function build_pagelinks($data)
{
global $ibforums, $skin_universal;
$work = array();
$section = ($data['leave_out'] == "") ? 2 : $data['leave_out']; // Number of pages to show per section( either side of current), IE: 1 ... 4 5 [6] 7 8 ... 10
$work['pages'] = 1;
if ( ($data['TOTAL_POSS'] % $data['PER_PAGE']) == 0 )
{
$work['pages'] = $data['TOTAL_POSS'] / $data['PER_PAGE'];
}
else
{
$number = ($data['TOTAL_POSS'] / $data['PER_PAGE']);
$work['pages'] = ceil( $number);
}
$work['total_page'] = $work['pages'];
$work['current_page'] = $data['CUR_ST_VAL'] > 0 ? ($data['CUR_ST_VAL'] / $data['PER_PAGE']) + 1 : 1;
if ($work['pages'] > 1)
{
$work['first_page'] = $skin_universal->make_page_jump($data['TOTAL_POSS'],$data['PER_PAGE'], $data['BASE_URL'])." (".$work['pages'].")";
for( $i = 0; $i <= $work['pages'] - 1; ++$i )
{
$RealNo = $i * $data['PER_PAGE'];
$PageNo = $i+1;
if ($RealNo == $data['CUR_ST_VAL'])
{
$work['page_span'] .= " [{$PageNo}]";
}
else
{
if ($PageNo < ($work['current_page'] - $section))
{
$work['st_dots'] = " « {$ibforums->lang['ps_first']} ...";
continue;
}
// If the next page is out of our section range, add some dotty dots!
if ($PageNo > ($work['current_page'] + $section))
{
$work['end_dots'] = "... {$ibforums->lang['ps_last']} »";
break;
}
$work['page_span'] .= " {$PageNo}";
}
}
$work['return'] = $work['first_page'].$work['st_dots'].$work['page_span'].' '.$work['end_dots'];
}
else
{
$work['return'] = $data['L_SINGLE'];
}
return $work['return'];
}
/*-------------------------------------------------------------------------*/
// Build the forum jump menu
/*-------------------------------------------------------------------------*/
function build_forum_jump($html=1, $override=0, $remove_redirects=0)
{
global $INFO, $DB, $ibforums;
// $html = 0 means don't return the select html stuff
// $html = 1 means return the jump menu with select and option stuff
$last_cat_id = -1;
if ( $remove_redirects )
{
$qe = 'AND f.redirect_on <> 1';
}
else
{
$qe = '';
}
$DB->query("SELECT f.id as forum_id, f.parent_id, f.subwrap, f.sub_can_post, f.name as forum_name, f.position, f.redirect_on, f.read_perms, c.id as cat_id, c.name
FROM ibf_forums f
LEFT JOIN ibf_categories c ON (c.id=f.category)
WHERE c.state IN (1,2) $qe
ORDER BY c.position, f.position");
if ($html == 1) {
$the_html = "";
}
return $the_html;
}
function clean_email($email = "") {
$email = trim($email);
$email = str_replace( " ", "", $email );
$email = preg_replace( "#[\;\#\n\r\*\'\"<>&\%\!\(\)\{\}\[\]\?\\/\s]#", "", $email );
if ( preg_match( "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/", $email) )
{
return $email;
}
else
{
return FALSE;
}
}
/*-------------------------------------------------------------------------*/
// SKIN, sort out the skin stuff
/*-------------------------------------------------------------------------*/
function load_skin() {
global $ibforums, $INFO, $DB;
$id = -1;
$skin_set = 0;
if ( ( $ibforums->is_bot == 1 ) and ($ibforums->vars['spider_suit'] != "") )
{
$skin_set = 1;
$id = $ibforums->vars['spider_suit'];
}
else
{
//------------------------------------------------
// Do we have a skin for a particular forum?
//------------------------------------------------
if ($ibforums->input['f'] and $ibforums->input['act'] != 'UserCP')
{
if ( $ibforums->vars[ 'forum_skin_'.$ibforums->input['f'] ] != "" )
{
$id = $ibforums->vars[ 'forum_skin_'.$ibforums->input['f'] ];
$skin_set = 1;
}
}
//------------------------------------------------
// Are we allowing user chooseable skins?
//------------------------------------------------
$extra = "";
if ($skin_set != 1 and $ibforums->vars['allow_skins'] == 1)
{
if (isset($ibforums->input['skinid']))
{
$id = intval($ibforums->input['skinid']);
$extra = " AND s.hidden=0";
$skin_set = 1;
}
else if ( $ibforums->member['skin'] != "" and intval($ibforums->member['skin']) >= 0 )
{
$id = $ibforums->member['skin'];
if ($id == 'Default') $id = -1;
$skin_set = 1;
}
}
}
//------------------------------------------------
// Load the info from the database.
//------------------------------------------------
if ( $id >= 0 and $skin_set == 1)
{
$DB->query("SELECT s.*, t.template, c.css_text
FROM ibf_skins s
LEFT JOIN ibf_templates t ON (t.tmid=s.tmpl_id)
LEFT JOIN ibf_css c ON (c.cssid=s.css_id)
WHERE s.sid=$id".$extra);
// Didn't get a row?
if (! $DB->get_num_rows() )
{
// Update this members profile
if ( $ibforums->member['id'] )
{
$DB->query("UPDATE ibf_members SET skin='-1' WHERE id='".$ibforums->member['id']."'");
}
$DB->query("SELECT s.*, t.template, c.css_text
FROM ibf_skins s
LEFT JOIN ibf_templates t ON (t.tmid=s.tmpl_id)
LEFT JOIN ibf_css c ON (s.css_id=c.cssid)
WHERE s.default_set=1");
}
}
else
{
$DB->query("SELECT s.*, t.template, c.css_text
FROM ibf_skins s
LEFT JOIN ibf_templates t ON (t.tmid=s.tmpl_id)
LEFT JOIN ibf_css c ON (s.css_id=c.cssid)
WHERE s.default_set=1");
}
if ( ! $row = $DB->fetch_row() )
{
echo("Could not query the skin information!");
exit();
}
//-------------------------------------------
// Setting the skin?
//-------------------------------------------
if ( ($ibforums->input['setskin']) and ($ibforums->member['id']) )
{
$DB->query( "UPDATE ibf_members SET skin=".intval($row['sid'])." WHERE id=".intval($ibforums->member['id']) );
$ibforums->member['skin'] = $row['sid'];
}
return $row;
}
/*-------------------------------------------------------------------------*/
// Require, parse and return an array containing the language stuff
/*-------------------------------------------------------------------------*/
function load_words($current_lang_array, $area, $lang_type) {
require ROOT_PATH."lang/".$lang_type."/".$area.".php";
foreach ($lang as $k => $v)
{
$current_lang_array[$k] = stripslashes($v);
}
unset($lang);
return $current_lang_array;
}
/*-------------------------------------------------------------------------*/
// Return a date or '--' if the date is undef.
// We use the rather nice gmdate function in PHP to synchronise our times
// with GMT. This gives us the following choices:
//
// If the user has specified a time offset, we use that. If they haven't set
// a time zone, we use the default board time offset (which should automagically
// be adjusted to match gmdate.
/*-------------------------------------------------------------------------*/
function get_date($date, $method) {
global $ibforums;
if (!$date)
{
return '--';
}
if (empty($method))
{
$method = 'LONG';
}
if ($this->offset_set == 0)
{
// Save redoing this code for each call, only do once per page load
$this->offset = $this->get_time_offset();
$this->offset_set = 1;
}
return gmdate($this->time_options[$method], ($date + $this->offset) );
}
/*-------------------------------------------------------------------------*/
// Returns the offset needed and stuff - quite groovy.
/*-------------------------------------------------------------------------*/
function get_time_offset()
{
global $ibforums;
$r = 0;
$r = (($ibforums->member['time_offset'] != "") ? $ibforums->member['time_offset'] : $ibforums->vars['time_offset']) * 3600;
if ( $ibforums->vars['time_adjust'] )
{
$r += ($ibforums->vars['time_adjust'] * 60);
}
if ($ibforums->member['dst_in_use'])
{
$r += 3600;
}
return $r;
}
/*-------------------------------------------------------------------------*/
// Sets a cookie, abstract layer allows us to do some checking, etc
/*-------------------------------------------------------------------------*/
function my_setcookie($name, $value = "", $sticky = 1) {
global $INFO;
//$expires = "";
if ($sticky == 1)
{
$expires = time() + 60*60*24*365;
}
$INFO['cookie_domain'] = $INFO['cookie_domain'] == "" ? "" : $INFO['cookie_domain'];
$INFO['cookie_path'] = $INFO['cookie_path'] == "" ? "/" : $INFO['cookie_path'];
$name = $INFO['cookie_id'].$name;
@setcookie($name, $value, $expires, $INFO['cookie_path'], $INFO['cookie_domain']);
}
/*-------------------------------------------------------------------------*/
// Cookies, cookies everywhere and not a byte to eat.
/*-------------------------------------------------------------------------*/
function my_getcookie($name)
{
global $INFO, $HTTP_COOKIE_VARS;
if (isset($HTTP_COOKIE_VARS[$INFO['cookie_id'].$name]))
{
return urldecode($HTTP_COOKIE_VARS[$INFO['cookie_id'].$name]);
}
else
{
return FALSE;
}
}
/*-------------------------------------------------------------------------*/
// Makes incoming info "safe"
/*-------------------------------------------------------------------------*/
function parse_incoming()
{
global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_CLIENT_IP, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR;
$return = array();
if( is_array($HTTP_GET_VARS) )
{
while( list($k, $v) = each($HTTP_GET_VARS) )
{
if ( $k == 'INFO' )
{
continue;
}
if( is_array($HTTP_GET_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
{
$return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
}
}
else
{
$return[$k] = $this->clean_value($v);
}
}
}
// Overwrite GET data with post data
if( is_array($HTTP_POST_VARS) )
{
while( list($k, $v) = each($HTTP_POST_VARS) )
{
if ( is_array($HTTP_POST_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
{
$return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
}
}
else
{
$return[$k] = $this->clean_value($v);
}
}
}
//----------------------------------------
// Sort out the accessing IP
// (Thanks to Cosmos and schickb)
//----------------------------------------
$addrs = array();
foreach( array_reverse( explode( ',', $HTTP_X_FORWARDED_FOR ) ) as $x_f )
{
$x_f = trim($x_f);
if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $x_f ) )
{
$addrs[] = $x_f;
}
}
$addrs[] = $_SERVER['REMOTE_ADDR'];
$addrs[] = $HTTP_PROXY_USER;
$addrs[] = $REMOTE_ADDR;
//header("Content-type: text/plain"); print_r($addrs); print $_SERVER['HTTP_X_FORWARDED_FOR']; exit();
$return['IP_ADDRESS'] = $this->select_var( $addrs );
// Make sure we take a valid IP address
$return['IP_ADDRESS'] = preg_replace( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3.\\4", $return['IP_ADDRESS'] );
$return['request_method'] = ( $_SERVER['REQUEST_METHOD'] != "" ) ? strtolower($_SERVER['REQUEST_METHOD']) : strtolower($REQUEST_METHOD);
return $return;
}
/*-------------------------------------------------------------------------*/
// Key Cleaner - ensures no funny business with form elements
/*-------------------------------------------------------------------------*/
function clean_key($key) {
if ($key == "")
{
return "";
}
$key = preg_replace( "/\.\./" , "" , $key );
$key = preg_replace( "/\_\_(.+?)\_\_/" , "" , $key );
$key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key );
return $key;
}
function clean_value($val)
{
global $ibforums;
if ($val == "")
{
return "";
}
$val = str_replace( " ", " ", $val );
if ( $ibforums->vars['strip_space_chr'] )
{
$val = str_replace( chr(0xCA), "", $val ); //Remove sneaky spaces
}
$val = str_replace( "&" , "&" , $val );
$val = str_replace( "" , "-->" , $val );
$val = preg_replace( "/