vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Beta Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=34)
-   -   VBulletin News Hack (https://vborg.vbsupport.ru/showthread.php?t=96588)

dcncdrew 09-19-2005 10:00 PM

VBulletin News Hack
 
This is something I want to implement on my site. It pulls all first posts from a specific forum you specify in descending order by post date. The only issue is that it does not take into account permissions at this point. This is a work in progress. I just wanted something simple but it's looking like it might be more trouble to do so. I had issues with VB's RSS so this is why I started this. I put it together using a few know scripts out there.

The below template.html and include.php file need to be in a folder called "news" in your forum directory.

To implment just write a simple include into a php page outside of your forums using the include.php file.



include.php
Code:

<?php
//config//
$includepath = "/path/to/forum/news/";  //path where the news folder resides
$mainurl = "http://www.yoursite.com";
$forumurl = "http://www.yoursite.com/forum/";
$includeurl = "http://www.yoursite.com/forum/news/"; //URL where the news folder resides
$newstemp = "template.html";

// Database Information
$dbserver = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbase = 'your_database';

$db = mysql_connect($dbserver, $dbuser, $dbpass) or die('Could not connect to DB server!');
mysql_select_db($dbase) or die("Could not connect to database: ".mysql_error());


function replace_bb_code($text) {
        $text = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $text);
        $text = preg_replace( "#\[b\](.+?)\[/b\]#is", "<b>\\1</b>", $text );
        $text = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>\\1</i>", $text );
        $text = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>\\1</u>", $text );
        $text = preg_replace( "#\[s\](.+?)\[/s\]#is", "<s>\\1</s>", $text );
    $text = eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$text);
    $text = eregi_replace("\\[url=([^\\[]+)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$text);
    $text = eregi_replace("\\[img\\]([^\\[]*)\\[/img\\]","<img src=\"\\1\" border=0>",$text);
        $text = eregi_replace("\\[color=([^\\[]+)\\]([^\\[]*)\\[/color\\]","<font color=\"\\1\">\\2</font>",$text);
    $text = eregi_replace("\\[quote\\]([^\\[]*)\\[/quote\\]","<br><br><strong>Quote:</strong><table width='80%' border='0' cellspacing='0' cellpadding='3'><tr><td bgcolor='#EFEFEF'><font color='#000000' size='-2'>\\1</font></td></tr></table><br>",$text);
    $text = eregi_replace("\\[code\\]([^\\[]*)\\[/code\\]","<br><br><strong>Code:</strong><table width='80%' border='0' cellpadding='3' cellspacing='0' bgcolor='#FFFFFF' style='border:1px solid gray;'><tr><td bgcolor='#FFFFFF'><font color='#009900' size='-2'>\\1</font></td></tr></table><br>",$text);
        $text = eregi_replace("\\[size=([^\\[]+)\\]([^\\[]*)\\[/size\\]","<font size='2'>\\2</font>",$text);
        return $text;
        }

$forumid = '12';  // You can set your forum ID here to pull the posts from the forum you want
$post_count = $_REQUEST['postcount'];

if (!$post_count) { $post_count = 3; }  // You may Change the amount of posts that are returned here by changing the number
$changetemplate = $_REQUEST['template'];
if ($changetemplate == "") { } else { $newstemp = $changetemplate; }
$truncate = $_REQUEST['truncate'];
if (!$truncate) { $truncate = 100000; }

if($_REQUEST['reverse']==1) {  ////you may need to change your database prefix from vbforum_ to what yours is
$query = "SELECT * FROM vbforum_post p, vbforum_thread t WHERE p.threadid = t.threadid AND t.forumid ='".$forumid."' ORDER BY p.threadid ASC, p.postid;";
} else {
$query = "SELECT * FROM vbforum_post p, vbforum_thread t WHERE p.threadid = t.threadid AND t.forumid ='".$forumid."' ORDER BY p.threadid DESC, p.postid;";
}

$result = mysql_query($query);
$num = mysql_num_rows($result);
$post = 0;

while($post < $post_count) {
$row = mysql_fetch_object($result);
        if($row=="") { break; }
        if ($previous_topic == $row->threadid) {  // do nothing.
        }
        else {
        $previous_topic = $row->threadid;
        $post++;
               
        $posttextquery = "SELECT * FROM vbforum_post WHERE postid='".$row->postid."';";
        $posttextresult = mysql_query($posttextquery);
        $posttextrow = mysql_fetch_object($posttextresult);
       
        $useridquery = "SELECT * FROM vbforum_user WHERE userid='".$row->userid."';";
        $useridresults = mysql_query($useridquery);
        $useridrow = mysql_fetch_object($useridresults);
       
        $responsesquery = "SELECT * FROM vbforum_post WHERE threadid='".$row->threadid."';";
        $responsesresults = mysql_query($responsesquery);
        $num_responses = mysql_num_rows($responsesresults)-1;
               
        $fileopen = fopen($includeurl.$newstemp, "r");
        $newsstring = fread($fileopen, filesize($includepath.$newstemp));
       
       
        $subject = $posttextrow->title;
   
        $newsstring = str_replace("((post_date))", date("F j, Y", $row->dateline), $newsstring);
        $newsstring = str_replace("((post_time))", date("g:i a", $row->dateline), $newsstring);
        $newsstring = str_replace("((poster_name))", "<a href='".$forumurl."member.php?u=".$row->userid."' target='_blank'>".$useridrow->username."</a>", $newsstring);
        $newsstring = str_replace("((post_subject))", $subject, $newsstring);
        if (strlen($newsstring) > $truncate) {
        $newsstring = str_replace("((post_text))", substr(nl2br($posttextrow->pagetext),0,$truncate)."... <a href='".$forumurl."showthread.php?t=".$row->postid."' target='_blank'>READ MORE</a>", $newsstring);
        } else {
        $newsstring = str_replace("((post_text))", nl2br($posttextrow->pagetext), $newsstring);
        }
        $newsstring = str_replace("((comment))", "<a href='".$forumurl."showthread.php?t=".$row->threadid."' target='_blank'>Comments</a>", $newsstring);
        $newsstring = str_replace("((responses))", $num_responses, $newsstring);
 

       
        $newsstring = replace_bb_code($newsstring);
        $newsstring = replace_bb_code($newsstring);
       
        echo $newsstring;
        }
}


?>

template.html

Code:

<table width='535' border='0' align="center" cellpadding='4' cellspacing='1' style='font-family:Verdana;font-size:11px'>
  <tr>
    <td align='left' bgcolor='#8A8A8A' background="images/header_news.jpg" height="32">
       
        <table width="300" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="286" valign="middle" style='font-family:Verdana;font-size:9px;padding-left:3px'><span class="style1">
                  Posted By: <strong><font color="#FFFFFF"></font>((poster_name))</font></strong><br>
          Posted On: ((post_date)) | ((post_time))</span></td>
        </tr>
      </table>
       
        </td>
  </tr>
  <tr>
    <td align='left' bgcolor='#BFBBBA'>
 <strong><font color="#343434" size="2" face="Verdana, Arial, Helvetica, sans-serif">
      ((post_subject))</font></strong><font face="Verdana, Arial, Helvetica, sans-serif"><br>
      <br>

      <table style='border:1px dotted gray;width:100%;font-family:Verdana;font-size:10px'>
        <tr>
          <td>
<script language="javascript" type="text/javascript">
<!--
function pointercursor(){document.body.style.cursor = "move";}
function unpointercursor(){document.body.style.cursor="";}
//-->
</script>((post_text))

</td>
        </tr>
      </table>
      </font>  <p>
((comment)) - ((responses))</p></td>
  </tr>
</table>
<div align="center"><br>
</div>


Snake 09-20-2005 12:01 PM

Screenshots please?

dcncdrew 09-20-2005 12:25 PM

Dont have any.

Snake 09-20-2005 02:34 PM

Then get a few one.

dcncdrew 09-20-2005 10:17 PM

you can figure it out

G-Unot 09-20-2005 11:25 PM

Argh, I rather seeing a screenshot first, then installing, you know why? what if I install it and I don't like it =/ I don't like wasting time.

dcncdrew 09-20-2005 11:57 PM

me either

Dreamgun 09-21-2005 04:42 AM

dcncdrew, mind posting some or getting a demo link...? I mean it'll take you 5 minutes tops and oh yeah, you made the hack.

tcs 09-21-2005 10:24 AM

Using the add on.
Really cool for pulling content from the forums mysql to display on another site.

Can you have it pull the 1st image attachment too?

dcncdrew 09-21-2005 10:47 AM

^ I guess we can try to do that.

I'll get some screens for the lazy later today

Quote:

and oh yeah, you made the hack.
I know and I also know that it works to an extent and thats why I am tracking it here.
Also, I am not trying to be rude. I just am working on making changes so thats all. And if you cant understand the layout by looking at the html then thats a whole nother problem all together.

The html template means you have the option to have it displayed any way you want. So what I deem a good and logical layout to me is different to you.

That is why it's called a template.


All times are GMT. The time now is 08:58 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01098 seconds
  • Memory Usage 1,759KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete