Convert html to vbcode and post to vbulletin

using vbulletin files :

  1.  
  2. chdir('/path/to/forum');
  3. define('THIS_SCRIPT', 'login');
  4. require_once( './global.php');
  5. require_once( DIR . '/includes/functions_wysiwyg.php' );
  6.  
  7. echo convert_wysiwyg_html_to_bbcode('<i>hello world</i>');
  8.  

using external function :

  1.  
  2. function html2vb($html){
  3.     $htmltags = array(
  4.                             '/\<div align=\"([^\"]+)\".*?\>(.*?)\<\/div\>/is',
  5.                             '/\<(\/?)(?:b|strong)\>/is',
  6.                             '/\<(\/?)(i|u)\>/is',
  7.                             '/\<(\/?)ul\>/is',
  8.                             '/\<li\>(.*?)\<\/li\>/is',
  9.                             '/\<img(.*?) src=\"([^\"]+)\" (.*?)\>/is',
  10.                             "/\<br[^>]*\>\n?/is",
  11.                             '/\<a .*?href=\"(http:\/\/[^\"]+)\"(?:.*?)\>(.*?)\<\/a\>/is',
  12.                             );
  13.     $bbtags = array(
  14.                             '[$1]$2[/$1]',
  15.                             '[$1b]',
  16.                             '[$1$2]',
  17.                             '[$1list]',
  18.                             '[*]$1′,
  19.                             '[img]$2[/img]',
  20.                             "\n",
  21.                             '[url="$1"]$2[/url]',
  22.                             );
  23.  
  24.  
  25.     $html = preg_replace($htmltags, $bbtags, $html);
  26.  
  27.     while( preg_match('/\<font face=\"(.*?)\".*?\>(.*?)\<\/font\>/i', $html ) )
  28.         $html = preg_replace('/\<font face=\"(.*?)\".*?\>(.*?)\<\/font\>/is', '[font="$1"]$2[/font]', $html);
  29.     while( preg_match('/\<font (.*?)=\"(.*?)\".*?\>(.*?)\<\/font\>/i', $html ) )
  30.         $html = preg_replace('/\<font (.*?)=\"(.*?)\".*?\>(.*?)\<\/font\>/is', '[$1="$2"]$3[/$1]' , $html);
  31.  
  32.  
  33.     // Strip HTML tags
  34.     $html = strip_tags($html);
  35.  
  36.     return $html;
  37.  
  38. }
  39.  

posting to vbulletin :

  1.  
  2. chdir('/path/to/forum');
  3. define('THIS_SCRIPT', 'login');
  4. require_once( './global.php');
  5. require_once( DIR . '/includes/functions_newpost.php');
  6.  
  7. $post = "[i]hello world[/i]";
  8. $vbulletin->options['postminchars'] = 1;
  9. $itemdata =& datamanager_init('Thread_FirstPost', $vbulletin, $error_type, 'threadpost');
  10. $itemdata->set('forumid', 2);
  11. $itemdata->set('userid', 1);
  12. $itemdata->set('title', 'post title' );
  13. $itemdata->set('pagetext', $post);
  14. $itemdata->set('visible',  1 );
  15. $itemdata->set('allowsmilie',  1 );
  16. $itemdata->set(’showsignature', 1 );
  17. $itemdata->set('ipaddress', );
  18.  
  19.  
  20. if ($itemid = $itemdata->save() )
  21. {
  22.      $itemtitle = $itemdata->fetch_field('title');
  23.      $itemlink =  FORUM_URL . "/showthread.php?t=$itemid";
  24.      echo "Posted <a href={$itemlink}>{$itemtitle}</a>";
  25. }
  26.  
  27.  

Tags :

This entry was posted on Sunday, November 29th, 2009 at 1:21 pm and is filed under Blog. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Convert html to vbcode and post to vbulletin”

  1. Muhammad Says:

    nice sharing

 

Leave a Reply


 Top