PDA

View Full Version : Newsscript to vBulletin (External script)


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

NORRITT
07-20-2001, 11:33 AM
well done! :)

NORRITT
07-20-2001, 11:34 AM
damn sorry for this double posting ... IE 6 beta, I hate it ;)

Xenon
07-20-2001, 02:05 PM
tststs, einer von Gamigo :) sieht gut aus :)

for all: well done :)

Shane
07-21-2001, 04:30 PM
I did exactlly the correct thing, and it didn't work. :-/

jarvis
07-21-2001, 07:41 PM
Okay, I've really been wanting to get something like this. I'm not so interested in the thread creation part of this hack, but I am really wanting to link to my threads from my home page and be able to display information like the following:

"News article here"

20 comment(s) Last post by Jarvis

I would think that there is a line of code from this hack that I should be able to use and just manually put in the forumid and thread strings, but my question is, where would I have my MySQL user information to pull this data. My main page is HTML-based, but PHP-parsed. I'm a bit nervous about embedding my user information in my homepage. Can this or any other hack do what I am asking?

Newbie questions I'm sure, but any help is greatly appreciated!!!

Thanks!!

:)

NORRITT
07-21-2001, 09:22 PM
pernaps there is a better hack to realise that.

look here: http://www.vbulletin.com/forum/showthread.php?threadid=12324

jarvis
07-21-2001, 09:54 PM
Thanks NORRITT,

I do use that LastXX hack but not in that way. If you go to my site at www.mhogaming.com and see where I have "Discuss this Post" after each news story, I would like to replace it with the above mentioned references to vB itself.

Thanks again, hopefully there is an easy way to do this. :)

-Jarv

Dark_Wizard
07-21-2001, 10:31 PM
Try this...
http://www.vbulletin.com/forum/showthread.php?s=&threadid=21875

jarvis
07-22-2001, 01:59 AM
Hmmm... I'll ask again on that thread, but didn't get any reply to it a week ago.

Thanks...