/*
Common library script for Intellect Board 2
(c) 2004, XXXX Pro, United Open Project
Visit us online: http://iboard.xxxxpro.ru
*/
if (!$IBOARD) die ("Hack attempt!");
$GLOBALS['common']=1;
return;
function load_style($file) {
$link=$GLOBALS['link'];
if (file_exists($GLOBALS['opt_dir']."/styles/".$GLOBALS['inuser']['st_file']."/".$file)) {
require_once($GLOBALS['opt_dir']."/styles/".$GLOBALS['inuser']['st_file']."/".$file);
}
else {
$dir=$GLOBALS['inuser']['st_parent'];
$curdir=$GLOBALS['opt_dir']."/styles/".$dir."/";
while ($dir && !file_exists($curdir.$file)) {
$sql = "SELECT st_parent FROM ".$GLOBALS['DBprefix']."StyleSet WHERE st_file=\"$curdir\"";
$res=db_query($sql,$link);
list($dir)=db_fetch_row($res);
$curdir=$GLOBALS['opt_dir']."/styles/".$dir."/";
}
if (file_exists($curdir.$file)) require_once($curdir.$file);
else global_error("File not found in styles: $file");
}
}
function load_lang($file) {
require_once ($GLOBALS['opt_dir']."/langs/".$GLOBALS['inuser']['ln_file']."/".$file);
}
function build_msg_select($sql,$value="") {
$res = db_query($sql,$GLOBALS['link']);
$tmp = "";
while ($tmpdata=db_fetch_row($res)) {
if ($tmpdata[0]==$value) $tmp.="";
return $flist;
}
function build_level_select() {
$sql = "SELECT * FROM ".$GLOBALS['DBprefix']."UserLevel ORDER BY l_level";
return build_select($sql,$udata['u__level']);
}
function build_userlevel_select($level=0) {
$sql = "SELECT * FROM ".$GLOBALS['DBprefix']."UserLevel WHERE l_level!=0 AND l_level<1024";
return build_select($sql,$level);
}
function error($errmsg) {
if (!$GLOBALS['admin']) load_style("message.php");
$tmp_link1 = "".MSG_go_back."";
$tmp_link2 = "".MSG_go_mainpage."";
output_message(MSG_e.$errmsg,$tmp_link1,$tmp_link2,"");
exit();
}
function message($textmsg,$golink=0) {
if ($_POST['refpage']) $tmp_link1 = $_POST['refpage'];
elseif ($GLOBALS['refpage']) $tmp_link1 = $GLOBALS['refpage'];
elseif ($_SERVER['HTTP_REFERER']) $tmp_link1 =$_SERVER['HTTP_REFERER'];
else $tmp_link1 = "".MSG_go_back."";
$tmp_link2 = "".MSG_go_mainpage."";
if ($golink) $newlink=$tmp_link1;
output_message($textmsg,"".MSG_go_back."",$tmp_link2,"",$newlink);
}
function topic_message($textmsg,$golink=0) {
$tmp_message = $textmsg;
$tmp_link1 = "".MSG_go_topic."";
$tmp_link2 = "".MSG_go_forum."";
$tmp_link3 = "".MSG_go_mainpage."";
if ($golink) $newlink="index.php?f=".$GLOBALS['forum']."&t=".$GLOBALS['topic'];
output_message($tmp_message,$tmp_link1,$tmp_link2,$tmp_link3,$newlink);
}
function month_replace($date) {
$date=str_replace("January",MSG_January,$date);
$date=str_replace("February",MSG_February,$date);
$date=str_replace("March",MSG_March,$date);
$date=str_replace("April",MSG_April,$date);
$date=str_replace("May",MSG_May,$date);
$date=str_replace("June",MSG_June,$date);
$date=str_replace("July",MSG_July,$date);
$date=str_replace("August",MSG_August,$date);
$date=str_replace("September",MSG_September,$date);
$date=str_replace("October",MSG_October,$date);
$date=str_replace("November",MSG_November,$date);
$date=str_replace("December",MSG_December,$date);
$date=str_replace("Jan",MSG_Jan,$date);
$date=str_replace("Feb",MSG_Feb,$date);
$date=str_replace("Mar",MSG_Mar,$date);
$date=str_replace("Apr",MSG_Apr,$date);
$date=str_replace("May",MSG_May,$date);
$date=str_replace("Jun",MSG_Jun,$date);
$date=str_replace("Jul",MSG_Jul,$date);
$date=str_replace("Aug",MSG_Aug,$date);
$date=str_replace("Sep",MSG_Sep,$date);
$date=str_replace("Oct",MSG_Oct,$date);
$date=str_replace("Nov",MSG_Nov,$date);
$date=str_replace("Dec",MSG_Dec,$date);
return $date;
}
function long_date_out($date) {
$date=$date+$GLOBALS['inuser']['u_timeregion']-$GLOBALS['opt_timeregion'];
if ($date<0) $date=0;
if ($date) $date=date($GLOBALS['inuser']['u_lformat'],$date);
else $date=MSG_none;
return month_replace($date);
}
function short_date_out($date) {
$date=$date+$GLOBALS['inuser']['u_timeregion']-$GLOBALS['opt_timeregion'];
if ($date<0) $date=0;
if ($date) $date=date($GLOBALS['inuser']['u_sformat'],$date);
else $date=MSG_none;
return month_replace($date);
}
function addlinks(&$text) {
$text = " ".$text." ";
$text = str_replace("<"," <",$text);
$text = str_replace(">","> ",$text);
$text = preg_replace("/\n/","",$text);
$text = preg_replace("/\r/","",$text);
$text = preg_replace("/ ([^:\t \n\[]+?\@[^\t \n\[]+?) /is"," $1 ",$text);
$text = preg_replace("/ (http:\/\/\S+?) /is"," $1 ",$text);
$text = preg_replace("/ (www\.\S+?) /is"," $1 ",$text);
$text = preg_replace("/ ([\w-\.]+?\.ru) /is"," $1 ",$text);
$text = preg_replace("/ ([\w-\.]+?\.com) /is"," $1 ",$text);
$text = preg_replace("/ ([\w-\.]+?\.net) /is"," $1 ",$text);
$text = preg_replace("/ ([\w-\.]+?\.org) /is"," $1 ",$text);
$text = str_replace(" <","<",$text);
$text = str_replace("> ",">",$text);
}
function check_hidden($posts,$text) {
if (!$GLOBALS['inuserposts'] && $GLOBALS['inuserid']>3) {
$link=$GLOBALS['link'];
$sql = "SELECT COUNT(*) FROM ".$GLOBALS['DBprefix']."Post WHERE p_uid=".$GLOBALS['inuserid']." AND p__premoderate=0";
$res = db_query($sql,$link);
list($count)=db_fetch_row($res);
db_free_result($res);
$GLOBALS['inuserposts']=$count;
}
if ($posts<=$GLOBALS['inuserposts']) return $text;
else return "
".MSG_p_posthide." ".format_word($posts,MSG_p1,MSG_p2,MSG_p3).".
";
}
function check_level($level,$text) {
if ($level<=$GLOBALS['inuserlevel']) return $text;
else return "
".MSG_p_levelhide.".
";
}
function check_url($url) {
$url=strtolower($url);
$res=1;
if (strpos($url,"script:")!==false) $res=0;
if (strpos($url,"/admin")!==false) $res=0;
return $res;
}
function check_img($imgtext) {
preg_match("/src=[\"']?(\S+?)[\"']?[\s>]/is",$imgtext,$matches);
if (check_url($matches[1])) return $imgtext;
else {
$GLOBALS['hackattempt']++;
return "
HACK ATTEMPT: ".$matches[1]."
";
}
}
function check_link($linktext) {
preg_match("/href=[\"']?(\S+?)[\"']?[\s>]/is",$linktext,$matches);
if (check_url($matches[1])) return $linktext;
else {
$GLOBALS['hackattempt']++;
return "
HACK ATTEMPT: ".$matches[1]."
";
}
}
function boardcode(&$text) {
if (strpos($text,"[")!==false) {
$text = str_replace("[hr]","
",$text);
$text = str_replace("[br]","
",$text);
$text = preg_replace("/\[quote\](.*?)\[\/quote\]/is","",$text);
$text = preg_replace("/\[q\](.*?)\[\/q\]/is","",$text);
$text = preg_replace("/\[quote=(.+?)\](.*?)\[\/quote\]/is","$1 ".MSG_written.":",$text);//.short_date_out($2)."
$text = preg_replace("/\[q=(.+?)\](.*?)\[\/q\]/is","$1 ".MSG_written.":",$text);
$text = preg_replace("/\[q(\d+)\](.*?)\[\/q$1\]/is","",$text);
$text = preg_replace("/\[url\](http:\/\/\S+?)\[\/url\]/is","$1",$text);
$text = preg_replace("/\[url\](\S+?)\[\/url\]/is","$1",$text);
$text = preg_replace("/\[url=(http:\/\/.+?)\](.+?)\[\/url\]/is","$2",$text);
$text = preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is","$2",$text);
$text = preg_replace("/\[email\](\S+?\@\S+?)\[\/email\]/is","$1",$text);
$text = preg_replace("/\[email=(\S+?\@\S+?)\](.+?)\[\/email\]/is","$2",$text);
$text = str_replace("[b]","",$text);
$text = str_replace("[/b]","",$text);
$text = str_replace("[i]","",$text);
$text = str_replace("[/i]","",$text);
$text = str_replace("[u]","",$text);
$text = str_replace("[/u]","",$text);
$text = str_replace("[s]","",$text);
$text = str_replace("[/s]","",$text);
$text = preg_replace("/\[font=([^<>]+?)\]/is","",$text);
$text = preg_replace("/\[color=([^<>]+?)\]/is","",$text);
$text = preg_replace("/\[size=([^<>]+?)\]/is","",$text);
$text = str_replace("[/font]","",$text);
$text = str_replace("[/color]","",$text);
$text = str_replace("[/size]","",$text);
$text = str_replace("[list]","",$text);
$text = str_replace("[*]","- ",$text);
$text = str_replace("[/list]","
",$text);
$text = preg_replace("/\[img\](\S+?)\[\/img\]/is","",$text);
$text = preg_replace("/\[img=(\S+?)\]/is","",$text);
$text = preg_replace("/\[table\](.*?)\[\/table\]/is","",$text);
$text = preg_replace("/\[tr\](.*?)\[\/tr\]/is","$1
",$text);
$text = preg_replace("/\[td\](.*?)\[\/td\]/is","$1 | ",$text);
$text = preg_replace("/\[td colspan=(\d+)\](.*?)\[\/td\]/is","$2 | ",$text);
$text = preg_replace("/\[code\](.*?)\[\/code\]/is","
$1
",$text);
$text = preg_replace("/\[off\](.*?)\[\/off\]/is","".MSG_offtopic.": $1
",$text);
$text = preg_replace("/\[center\](.*?)\[\/center\]/is","$1
",$text);
$text = preg_replace("/\[right\](.*)\[\/right\]/is","$1
",$text);
$text = preg_replace("/\[translit\](.*)\[\/translit\]/esi","untransliterate(\"$1\")",$text);
$text = preg_replace("/()/ise","check_img(\"$1\")",$text);
$text = preg_replace("/(.*<\/a>)/ise","check_link(\"$1\")",$text);
$text = preg_replace("/\[hide=(\d+?)\](.*?)\[\/hide\]/esi","check_hidden($1,\"$2\")",$text);
$text = preg_replace("/\[level=(\d+?)\](.*?)\[\/level\]/esi","check_level($1,\"$2\")",$text);
}
$text = str_replace("(c)","©",$text);
$text = str_replace("(C)","©",$text);
$text = str_replace("(r)","®",$text);
$text = str_replace("(R)","®",$text);
$text = str_replace("(tm)","™",$text);
$text = str_replace("(TM)","™",$text);
}
function sign_code(&$text) {
if (strpos($text,"[")!==false) {
$text = preg_replace("/\[br\]/","
",$text);
$text = str_replace("[b]","",$text);
$text = str_replace("[/b]","",$text);
$text = str_replace("[i]","",$text);
$text = str_replace("[/i]","",$text);
$text = str_replace("[u]","",$text);
$text = str_replace("[/u]","",$text);
$text = str_replace("[s]","",$text);
$text = str_replace("[/s]","",$text);
$text = preg_replace("/\[font=([^<>]+?)\]/is","",$text);
$text = preg_replace("/\[color=([^<>]+?)\]/is","",$text);
$text = preg_replace("/\[size=([^<>]+?)\]/is","",$text);
$text = str_replace("[/font]","",$text);
$text = str_replace("[/color]","",$text);
$text = str_replace("[/size]","",$text);
$text = preg_replace("/\[url\](http:\/\/\S+?)\[\/url\]/is","$1",$text);
$text = preg_replace("/\[url\](\S+?)\[\/url\]/is","$1",$text);
$text = preg_replace("/\[url=(http:\/\/\S+?)\](.+?)\[\/url\]/is","$2",$text);
$text = preg_replace("/\[url=(\S+?)\](.+?)\[\/url\]/is","$2",$text);
$text = preg_replace("/\[email\](\S+?\@\S+?)\[\/email\]/is","$1",$text);
$text = preg_replace("/\[email=(\S+?\@\S+?)\](.+?)\[\/email\]/is","$2",$text);
}
$text = str_replace("(c)","©",$text);
$text = str_replace("(C)","©",$text);
$text = str_replace("(r)","®",$text);
$text = str_replace("(R)","®",$text);
$text = str_replace("(tm)","™",$text);
$text = str_replace("(TM)","™",$text);
if ($GLOBALS['opt_sigpics']) {
$text = preg_replace("/\[img\](\S+?)\[\/img\]/is","",$text);
$text = preg_replace("/\[img=(\S+?)\]/is","",$text);
if ($text = preg_replace("//is","HACK ATTEMPT: $1",$text)) $GLOBALS['hackattempts']++;
if ($text = preg_replace("/(.*?)<\/a>/is","HACK ATTEMPT: $1 $2",$text)) $GLOBALS['hackattempt']++;
if ($text = preg_replace("//is","HACK ATTEMPT: $1",$text)) $GLOBALS['hackattempts']++;
if ($text = preg_replace("/(.*?)<\/a>/is","HACK ATTEMPT: $1 $2",$text)) $GLOBALS['hackattempt']++;
}
return $text;
}
function textout($text,$html,$bcode,$smiles) {
if ($html) $text=nl2br($text);
else $text=nl2br(htmlspecialchars($text));
$text=str_replace(""","\"",$text);
addlinks($text);
if ($smiles) smiles($text);
if ($bcode) boardcode($text);
$text=stripslashes($text);
if ($hlight=getvar('hl')) {
$hlight=preg_replace("/\W+/","",$hlight);
$hls=explode(" ",$hlight);
foreach ($hls as $curhl) {
$text=str_replace(" ".$curhl." "," $curhl ",$text);
}
}
return $text;
}
function build_avatar_select() {
$dir=opendir($GLOBALS['opt_dir']."/avatars");
while ($curfile=readdir($dir)) if (!is_dir($GLOBALS['opt_dir']."avatars/".$curfile)) $avatarselect.="