Announcement

Collapse
No announcement yet.

[Release] Newsscript to vBulletin (External script)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Release] Newsscript to vBulletin (External script)

    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:

    PHP Code:
      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:

    PHP Code:
      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>''[b]'$strVB);
        
    $strVB str_replace('</b>''[/b]'$strVB);
        
    $strVB str_replace('<strong>''[b]'$strVB);
        
    $strVB str_replace('</strong>''[/b]'$strVB);

        
    // vbCodes for italic Text
        
    $strVB str_replace('<i>''[i]'$strVB);
        
    $strVB str_replace('</i>''[/i]'$strVB);
        
    $strVB str_replace('<em>''[i]'$strVB);
        
    $strVB str_replace('</em>''[/i]'$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

  • #2
    well done!

    Comment


    • #3
      damn sorry for this double posting ... IE 6 beta, I hate it

      Comment


      • #4
        tststs, einer von Gamigo sieht gut aus

        for all: well done
        The price of freedom is eternal vigilance!
        - Thomas Jefferson

        Comment


        • #5
          Doesn't work?

          I did exactlly the correct thing, and it didn't work. :-/
          Shane
          CIO, FrakMedia.net
          Director of Information, BattlestarForum.com

          Comment


          • #6
            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!!

            Comment


            • #7
              pernaps there is a better hack to realise that.

              look here: http://www.vbulletin.com/forum/showt...threadid=12324

              Comment


              • #8
                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

                Comment


                • #9
                  Try this...
                  http://www.vbulletin.com/forum/showt...threadid=21875

                  Comment


                  • #10
                    Hmmm... I'll ask again on that thread, but didn't get any reply to it a week ago.

                    Thanks...

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X