07-19-2001, 10:00 PM
Hy there,
we have a self-written newssystem and wanted to use our forum as archive and discussion place for news. So I wrote a little php script which creates a new thread for every newsitem. It's not a big deal:
function createPosting ($headline, $newstext, $newstime, $author, $authorid, $forumid) {
// Create thread
mysql_query("INSERT INTO thread (threadid, title, lastpost, forumid, pollid, open, replycount, postusername,
postuserid, lastposter, dateline, views, iconid, notes, visible, sticky,
votenum, votetotal, attach)
VALUES ('', '". addslashes($headline)."', '$newstime', '$forumid', '0', '1', '0', '$author',
'authorid', '$author', '$newstime', '1', '1', '', '1', '0',
'0', '0', '0');", $GLOBALS[dblink]);
if(mysql_errno($GLOBALS[dblink]) != '0') {
echo '<p>Error creating thread.</p>';
}
else {
$threadid = mysql_insert_id($GLOBALS[dblink]);
$postingtext = html2vb($newstext);
// Create posting
mysql_query("INSERT INTO post (postid, threadid, username, userid, title, dateline, attachmentid, pagetext,
allowsmilie, showsignature, ipaddress, iconid, visible, edituserid, editdate)
VALUES ('', '$threadid', '$author', '$authorid', '" . addslashes($headline) ."',
'$newstime', '0', '" . addslashes($postingtext) ."', '1', '0', '127.0.0.1', '1', '1', '0', '0');", $GLOBALS[dblink]);
if (mysql_errno($GLOBALS[dblink]) != '0') {
echo '<p>Error creating posting.</p>';
}
else {
// Update newsinfo
// I write the threadid into my newsdb to link the thread later
// Update foruminfo
mysql_query("UPDATE forum SET replycount=replycount+1,threadcount=threadcount+1, lastpost='$newstime',lastposter='".addslashes($author)."'
WHERE forumid = '$forumid';", $GLOBALS[dblink]);
echo mysql_error();
}
}
}
And we need a php function html2vb which converts the html to vbCode:
function html2vb ($strHTML) {
$strVB = '';
$strVB = trim($strHTML); // Remove unnecessary whitespaces
$strVB = str_replace(chr(13), '', $strVB); // Remove ascii-char 13
$strVB = str_replace(chr(10), '', $strVB); // Remove ascii-char 10
$strVB = str_replace('<p>', "\n\n", $strVB); // Replace new-paragraph
$strVB = str_replace('<br>', "\n", $strVB); // Replace br's
// vbCodes for bold Text
$strVB = str_replace('<b>', '', $strVB);
$strVB = str_replace('</b>', '', $strVB);
$strVB = str_replace('<strong>', '', $strVB);
$strVB = str_replace('</strong>', '', $strVB);
// vbCodes for italic Text
$strVB = str_replace('<i>', '', $strVB);
$strVB = str_replace('</i>', '', $strVB);
$strVB = str_replace('<em>', '', $strVB);
$strVB = str_replace('</em>', '', $strVB);
// Remove all other tags
$strVB = ereg_replace('[<][^>]*[>]', '', $strVB);
return $strVB;
}
Of course you need to add str_replace for all of your vbCodes.
Hope someone is helped with that :). The best is that you don't need to modify your vBulletin source.
See it in action: http://lionsource.com
we have a self-written newssystem and wanted to use our forum as archive and discussion place for news. So I wrote a little php script which creates a new thread for every newsitem. It's not a big deal:
function createPosting ($headline, $newstext, $newstime, $author, $authorid, $forumid) {
// Create thread
mysql_query("INSERT INTO thread (threadid, title, lastpost, forumid, pollid, open, replycount, postusername,
postuserid, lastposter, dateline, views, iconid, notes, visible, sticky,
votenum, votetotal, attach)
VALUES ('', '". addslashes($headline)."', '$newstime', '$forumid', '0', '1', '0', '$author',
'authorid', '$author', '$newstime', '1', '1', '', '1', '0',
'0', '0', '0');", $GLOBALS[dblink]);
if(mysql_errno($GLOBALS[dblink]) != '0') {
echo '<p>Error creating thread.</p>';
}
else {
$threadid = mysql_insert_id($GLOBALS[dblink]);
$postingtext = html2vb($newstext);
// Create posting
mysql_query("INSERT INTO post (postid, threadid, username, userid, title, dateline, attachmentid, pagetext,
allowsmilie, showsignature, ipaddress, iconid, visible, edituserid, editdate)
VALUES ('', '$threadid', '$author', '$authorid', '" . addslashes($headline) ."',
'$newstime', '0', '" . addslashes($postingtext) ."', '1', '0', '127.0.0.1', '1', '1', '0', '0');", $GLOBALS[dblink]);
if (mysql_errno($GLOBALS[dblink]) != '0') {
echo '<p>Error creating posting.</p>';
}
else {
// Update newsinfo
// I write the threadid into my newsdb to link the thread later
// Update foruminfo
mysql_query("UPDATE forum SET replycount=replycount+1,threadcount=threadcount+1, lastpost='$newstime',lastposter='".addslashes($author)."'
WHERE forumid = '$forumid';", $GLOBALS[dblink]);
echo mysql_error();
}
}
}
And we need a php function html2vb which converts the html to vbCode:
function html2vb ($strHTML) {
$strVB = '';
$strVB = trim($strHTML); // Remove unnecessary whitespaces
$strVB = str_replace(chr(13), '', $strVB); // Remove ascii-char 13
$strVB = str_replace(chr(10), '', $strVB); // Remove ascii-char 10
$strVB = str_replace('<p>', "\n\n", $strVB); // Replace new-paragraph
$strVB = str_replace('<br>', "\n", $strVB); // Replace br's
// vbCodes for bold Text
$strVB = str_replace('<b>', '', $strVB);
$strVB = str_replace('</b>', '', $strVB);
$strVB = str_replace('<strong>', '', $strVB);
$strVB = str_replace('</strong>', '', $strVB);
// vbCodes for italic Text
$strVB = str_replace('<i>', '', $strVB);
$strVB = str_replace('</i>', '', $strVB);
$strVB = str_replace('<em>', '', $strVB);
$strVB = str_replace('</em>', '', $strVB);
// Remove all other tags
$strVB = ereg_replace('[<][^>]*[>]', '', $strVB);
return $strVB;
}
Of course you need to add str_replace for all of your vbCodes.
Hope someone is helped with that :). The best is that you don't need to modify your vBulletin source.
See it in action: http://lionsource.com