Topics

Convert html to vbcode and post to vbulletin

using vbulletin files :

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 :

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>";
}

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close