Convert html to vbcode and post to vbulletin
using vbulletin files :
1 2 3 4 5 6 | chdir('/path/to/forum'); define('THIS_SCRIPT', 'login'); require_once( './global.php'); require_once( DIR . '/includes/functions_wysiwyg.php' ); echo convert_wysiwyg_html_to_bbcode('<i>hello world</i>'); |
using external function :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | function html2vb($html){ $htmltags = array( '/\<div align=\"([^\"]+)\".*?\>(.*?)\<\/div\>/is', '/\<(\/?)(?:b|strong)\>/is', '/\<(\/?)(i|u)\>/is', '/\<(\/?)ul\>/is', '/\<li\>(.*?)\<\/li\>/is', '/\<img(.*?) src=\"([^\"]+)\" (.*?)\>/is', "/\<br[^>]*\>\n?/is", '/\<a .*?href=\"(http:\/\/[^\"]+)\"(?:.*?)\>(.*?)\<\/a\>/is', ); $bbtags = array( '[$1]$2[/$1]', '[$1b]', '[$1$2]', '[$1list]', '[*]$1', '[img]$2[/img]', "\n", '[url="$1"]$2[/url]', ); $html = preg_replace($htmltags, $bbtags, $html); while( preg_match('/\<font face=\"(.*?)\".*?\>(.*?)\<\/font\>/i', $html ) ) $html = preg_replace('/\<font face=\"(.*?)\".*?\>(.*?)\<\/font\>/is', '[font="$1"]$2[/font]', $html); while( preg_match('/\<font (.*?)=\"(.*?)\".*?\>(.*?)\<\/font\>/i', $html ) ) $html = preg_replace('/\<font (.*?)=\"(.*?)\".*?\>(.*?)\<\/font\>/is', '[$1="$2"]$3[/$1]' , $html); // Strip HTML tags $html = strip_tags($html); return $html; } |
posting to vbulletin :
chdir('/path/to/forum'); define('THIS_SCRIPT', 'login'); require_once( './global.php'); require_once( DIR . '/includes/functions_newpost.php'); $post = "[i]hello world[/i]"; $vbulletin->options['postminchars'] = 1; $itemdata =& datamanager_init('Thread_FirstPost', $vbulletin, $error_type, 'threadpost'); $itemdata->set('forumid', 2); $itemdata->set('userid', 1); $itemdata->set('title', 'post title' ); $itemdata->set('pagetext', $post); $itemdata->set('visible', 1 ); $itemdata->set('allowsmilie', 1 ); $itemdata->set('showsignature', 1 ); $itemdata->set('ipaddress', ''); if ($itemid = $itemdata->save() ) { $itemtitle = $itemdata->fetch_field('title'); $itemlink = FORUM_URL . "/showthread.php?t=$itemid"; echo "Posted <a href={$itemlink}>{$itemtitle}</a>"; }
