Code: Select all
/*------------------------------------
convert html to BBcode
--------------------------------------*/
function html_bbcode_format ($replace, $bbcode_uid) {
$replace = str_replace(';;','',$replace);
$replace = str_replace('"','"',$replace);
$replace = str_replace('<','<',$replace);
$replace = str_replace('>','>',$replace);
$replace = str_replace('<br />','',$replace);
$replace = preg_replace('</div>', '', $replace);
$replace = preg_replace('<div align="(.*?)">', '', $replace);
$replace = preg_replace('<img src="(.*?)"(.*?) />', '[img:'.$bbcode_uid.']$1[/img:'.$bbcode_uid.']', $replace);
$replace = preg_replace('<img(.*?)src="(.*?)">', '[img:'.$bbcode_uid.']$2[/img:'.$bbcode_uid.']', $replace);
$replace = preg_replace('/\<font size=\"([1-7])\"\>((\s|.)+?)\<\/font>/i', '[size=\\1:'.$bbcode_uid.']\\2[/size:'.$bbcode_uid.']', $replace);
$replace = preg_replace('/\<font color=\"(#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])\"\>((\s|.)+?)\<\/font>/i', '[color=\\1:'.$bbcode_uid.']\\2[/color:'.$bbcode_uid.']', $replace);
$replace = preg_replace('/\<font color=\"([a-zA-Z]+)\]((\s|.)+?)\<\/font>/i', '[color=\\1:'.$bbcode_uid.']\\2[/color:'.$bbcode_uid.']', $replace);
$replace = preg_replace("/\<a href=\"((http|ftp|https|ftps|irc):\/\/[^<>\s]+?)\">((\s|.)+?)\<\/a\>/i","[url=\\1:'.$bbcode_uid.']\\3[/url:'.$bbcode_uid.']", $replace);
$replace = str_replace('<i>','[i:'.$bbcode_uid.']',$replace);
$replace = str_replace('</i>','[/i:'.$bbcode_uid.']',$replace);
$replace = str_replace('<b>','[b:'.$bbcode_uid.']',$replace);
$replace = str_replace('</b>','[/b:'.$bbcode_uid.']',$replace);
$replace = str_replace('<strong>','[b:'.$bbcode_uid.']',$replace);
$replace = str_replace('</strong>','[/b:'.$bbcode_uid.']',$replace);
$replace = str_replace('<u>','[u:'.$bbcode_uid.']',$replace);
$replace = str_replace('</u>','[/u:'.$bbcode_uid.']',$replace);
$replace = str_replace('<','',$replace);
$replace = str_replace('/>','',$replace);
$replace = str_replace('>','',$replace);
$replace = str_replace(' ',' ',$replace);
return $replace;
}
/*---------------------------------------
end convert html to BBcode
-----------------------------------------*/
/*---------------------------------------
insert new topic
-----------------------------------------*/
function newtopic($name, $description, $poster)
{
global $db, $forumpx, $user, $auto_post;
$description = stripslashes($description);
$bbcode_bitfield = "Sg==";
$bbcode_uid = substr(md5(time()), 0, 5);
if (!array_key_exists("HTTP_X_FORWARDED_FOR",$_SERVER)) { # Proxy check. Thanks to an anonymous contributor
$ip = $_SERVER["REMOTE_ADDR"];
} else {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
if($poster == "0") $postername = 'ANONYMOUS';
else
$postername = $user->name;
if($poster == "0") $poster = "1";
else
$poster = get_user_forum_id($poster);
$replace = str_replace(";;"," ",$description);
$description = html_bbcode_format ($replace, $bbcode_uid);
#update topics
$db->sql_query("INSERT INTO `".$forumpx."_topics` (`forum_id`, `topic_title`, `topic_poster` , `topic_time` , `topic_views`, `topic_first_poster_name`, `topic_last_poster_name`, `topic_last_post_subject`, `topic_last_post_time`, `topic_last_view_time`)
VALUES ('" . $auto_post ."', '" . $name . "', '" . $poster . "', '" . time(). "', '1', '" . $postername . "', '" . $postername . "', '" . $name . "', '" . time(). "', '" .time() . "' )");
$topicid = $db->sql_nextid();
#insert post
$db->sql_query("INSERT INTO `".$forumpx."_posts` (`topic_id`, `forum_id`, `poster_id` , `poster_ip`, `post_time`, `post_username`, `post_subject` , `post_text` , `post_checksum`, `post_postcount`, `bbcode_bitfield`, `bbcode_uid`)
VALUES ('" . $topicid ."', '" . $auto_post . "', '" . $poster ."', '" . $ip . "', '" . time(). "', '" . $postername . "', '" . $name . "', '" . $description . "', '" . md5($description) ."', '1', '" . $bbcode_bitfield . "', '" . $bbcode_uid . "')");
$postid = $db->sql_nextid();
#update config
$db->sql_query("UPDATE `".$forumpx."_config` SET `config_value` = config_value + ' 1'
WHERE CONVERT( `".$forumpx."_config`.`config_name` USING utf8 ) = 'num_topics' ;");
$db->sql_query("UPDATE `".$forumpx."_config` SET `config_value` = config_value + ' 1'
WHERE CONVERT( `".$forumpx."_config`.`config_name` USING utf8 ) = 'num_posts' ;");
#update topic posts
$db->sql_query("INSERT INTO `".$forumpx."_topics_posted` ( `user_id` , `topic_id` , `topic_posted` )
VALUES (
'" . $poster . "', '" . $topicid ."', '1'
) ");
#update forum
$db->sql_query("UPDATE `".$forumpx."_forums` SET `forum_posts` = forum_posts + '1',
`forum_topics` = forum_topics + '1',
`forum_topics_real` = forum_topics_real + '1',
`forum_last_post_id` = '" . $postid . "',
`forum_last_poster_id` = '" . $poster . "',
`forum_last_post_subject` = '" . $name . "',
`forum_last_post_time` = ". time() . ",
`forum_last_poster_name` = '" . $postername . "' WHERE `".$forumpx."_forums`.`forum_id` = " . $auto_post . " LIMIT 1 ;");
#if is a user update the user posts and last post time
if($poster >= "1")
{
$db->sql_query("UPDATE `".$forumpx."_users` SET `user_posts` = user_posts + '1',
`user_lastpost_time` = " . time() ."
WHERE `".$forumpx."_users`.`user_id` = " . $poster . "");
}
}
/*---------------------------------------
end insert new topic
-----------------------------------------*/