Topics

Convert html to vbcode and post to vbulletin

:

chdir('/path/to/');
define('THIS_SCRIPT', 'login');
require_once( './.');
require_once( DIR . '/includes/functions_wysiwyg.' );

echo convert_wysiwyg__to_bbcode('<i>hello </i>');

using external :

function html2vb($html){
    $htmltags = (
                            '/\<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 = (
                            '[$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>";
}