Victory Road Archive

You are viewing an archive of Victory Road.

Victory Road closed on January 8, 2018. Thank you for making us a part of your lives since 2006! Please read this thread for details if you missed it.

Technology → vBulletin Viewer

Page 1 of 1

1. FreezeWarp said on July 2, 2010, 05:44:18 AM (-07:00)

Kyurem
2,186 posts

PHP Code:
/*Vbulletin Viewer
  Copyright © 2010 by Joseph Parsons

  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/****** Description ******/
/* Title: Vbulletin Viewer
 * Creator: Joseph Parsons (FreezeWarp)
 * License: GPLv3
 * Version: 1.6.3
 * Description: This script can be used as a lightweight alternative to vBulletin using existing vBulletin databases. It is meant to be lightweight, and everything is done in this one file. Some nicer features of vBulletin, like the BB code editor, advanced permissions, an easy to use administrator panel, theming, and plugins are not available. This script simply acts as a basic alternative if you are now using a server that can not handle vBulletin, or vBulletin is too much of a hassle.
 * Documentation: The code comments document the basic functionality of this script. Additional documentation, such as how to configure the script, can be found at http://www.victoryroad.net/.

/****** Change Log ******/
/* 1.0: Adaption of Floatzel.net Code
 * 1.2: Fixed several bugs.
 * 1.3: Added new BB Code, including list support, and cleaned up other code.
 * 1.6: Renamed several variables, added full forum viewing and thread viewing, generally cleaned things up.
 * 1.6.1, 1.6.2, 1.6.3 - Fixed BB-code related bugs.*/

/****** Configuration ******/
/* Set this array to each unique forum ID from which threads will be displayed. */
if (!$forums$forums = array('40','68','113');

if (!
$images$images = array(40 =&gt'news.gif'68 =&gt'pokemon.gif');

/* Topic limit. This is the maximum number of threads to display per page. */
if (!$limit$limit '10';

/* The URL path to the forum. This is used for linking. */
if (!$forumpath$forumpath 'http://www.victoryroad.net/';

/* A cutoff where posts will not be displayed. */
if (!$cutoff$cutoff '1262304000';

if (!
$startForum$startForum = -1;

/* Whether or not to hide the page jump. */
if (!isset($hideJump)) $hideJump false;

if (!isset(
$_GET['page'])) $page $defaultPage;
else { 
$page $_GET['page']; }

/* The MySQL login. */
$sqlHost 'localhost';
$sqlUser '';
$sqlPass '';
$sqlDatabase '';

/****** Pre-processing and advanced configuration. ******/
function parsePost($text) {
  global 
$forumpath;
  
$search = array(
  
'/\[b\](.+?)\[\/b\]/is',
  
'/\[s\](.+?)\[\/s\]/is',
  
'/\[i\](.+?)\[\/i\]/is',
  
'/\[u\](.+?)\[\/u\]/is',
  
'/\[quote\](.+?)\[\/quote\]/is',
  
'/\[quote=(.*?);([0-9]+?)\](.*?)\[\/quote\]/is',
  
'/\[quote=(.*?)\](.*?)\[\/quote\]/is',
  
'/\[div=(.*?)\](.*?)\[\/div\]/is',
  
'/\[code\](.+?)\[\/code\]/is',
  
'/\[list(=(.*?)|)\](.+?)\[\/list\]/is',
  
'/\[img\](.*?)\[\/img\]/is',
  
'/\[url=("|)(.*?)("|)\](.*?)\[\/url\]/is',
  
'/\[url\](.*?)\[\/url\]/is',
  
'/\[email=("|)(.*?)("|)\](.*?)\[\/email\]/is',
  
'/\[email\](.*?)\[\/email\]/is',
  
'/\[color=(.*?)\](.*?)\[\/color\]/is',
  
'/\[size=(.*?)\](.*?)\[\/size\]/is',
  
'/\[spoiler\](.*?)\[\/spoiler\]/is',
  
'/\[spoiler=(.+?)\](.*?)\[\/spoiler\]/is',
  
'/\[youtubewide\](.*?)\[\/youtubewide\]/is',
  
'/\[youtube\](.*?)\[\/youtube\]/is',
  
'/\[center\](.*?)\[\/center\]/is',
  
'/\[left\](.*?)\[\/left\]/is',
  
'/\[right\](.*?)\[\/right\]/is',
  
'/\[float=(.+?)\](.*?)\[\/float\]/is',
  
'/:([0-4][0-9][0-9]):/'
  
);
  
$replace = array(
  
'<strong>$1</strong>',
  
'<del>$1</del>',
  
'<i>$1</i>',
  
'<span style="text-decoration: underline;">$1</span>',
  
'<fieldset><legend>Quote:</legend>$1</fieldset>',
  
'<fieldset><legend>Quote by <a href="#$2"><b>$1</b></a>:</legend>$3</fieldset>',
  
'<fieldset><legend>Quote by <b>$1</b>:</legend>$2</fieldset>',
  
'<div style="$1">$2</div>',
  
'<strong>Code</strong><br /><tt>$1</tt>',
  
'<ul>$3</ul>',
  
'<a href="$1" target="_blank"><img src="$1" alt="image" border="0" style="max-width: 300px;" /></a>',
  
'<a href="$2">$4</a>',
  
'<a href="$1">$1</a>',
  
'<a href="mailto:$2">$4</a>',
  
'<a href="mailto:$1">$1</a>',
  
'<span style="color: $1;">$2</span>',
  
'<span style="font-size: $1pt">$2</span>',
  
'<fieldset><legend><strong>Spoiler Alert:</strong> <input type="button" value="Show" onClick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[0].style.display == \'none\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[0].style.display = \'block\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[0].style.display = \'none\'; this.value = \'Show\'; }" style="display: inline;" /></legend><div style="display: none;">$1</div></fieldset>',
  
'<fieldset><legend><strong>Spoiler Alert:</strong> <input type="button" value="Show" onClick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[0].style.display == \'none\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[0].style.display = \'block\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[0].style.display = \'none\'; this.value = \'Show\'; }" style="display: inline;" /></legend><div style="display: none;">$2</div></fieldset>',
  
'<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/$1=en&fs=1&rel=0&border=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/$1&hl=en&fs=1&rel=0&border=0" type="application/x-shockwave-flash" allowfullscreen="true" width="560" height="340"></embed></object>',
  
'<object width="425" height="349"><param name="movie" value="http://www.youtube.com/v/$1=en&rel=0&border=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/$1&hl=en&rel=0&border=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="349"></embed></object>',
  
'<div style="text-align: center;">$1</div>',
  
'<div style="text-align: left;">$1</div>',
  
'<div style="text-align: right;">$1</div>',
  
'<div style="float: $1;">$2</div>',
  
'<img src="/Sprites/DP/PC/Icons/Animated/$1.gif" />',
  );
  
// Parse BB Code
  
foreach ($search as $key =&gt$val) {
    while (
preg_match($val,$text)) {
      
$text preg_replace($val,$replace[$key],$text);
    }
  }
  while (
preg_match("/<ul>(.*?)\[\*\](.+?)\n(.*?)<\/ul>/si",$text)) {
    
$text preg_replace("/<ul>(.*?)\[\*\](.+?)\n(<br>|<br \/>|)(.*?)<\/ul>/si","<ul>$1<li>$2</li>$4</ul>",$text);
  }
  
$text str_ireplace($forumpath 'showthread.php?t=',$_SERVER['PHP_SELF'] . '?page=thread&threadid=',$text);
  
$text str_ireplace("\n""\n<br />\n"$text);
  return 
$text;
}
function 
inArray($needle$haystack) {
  foreach (
$needle as $le) {
    if (!
$le) continue;
    if (
in_array($le,$haystack)) return true;
  }
  return 
false;
}

/****** Connect to MySQL ******/
// Connect to MySQL.
if(!@mysql_connect($sqlHost$sqlUser$sqlPass)) {
  
trigger_error('Could not connect to MySQL. The news will not be displayed.',E_USER_ERROR);
}
elseif(!@
mysql_select_db($sqlDatabase)) {
  
trigger_error('Could not find the database specified. The news will not be displayed.',E_USER_ERROR);
}
elseif (!@
mysql_query('SET NAMES UTF8')) {
  
trigger_error('Could not set the name display to UTF-8. They make not display properly.',E_USER_WARNING);
}

/****** The rest of the script. ******/
else {
  
/*** Thread Display ***/
  
if ($page == 'thread') {
    
// Select the topic information from the correct forums and set it to $grab_threads
    
$grab_posts = @mysql_query('SELECT * FROM `post` WHERE `threadid` = ' . @mysql_real_escape_string($_GET['threadid']) .' AND `visible` = 1 ORDER BY `dateline` ASC');
    
    
$echo_thread = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `thread` WHERE `threadid` = ' . @mysql_real_escape_string($_GET['threadid'])));
    
$echo_forum = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `forum` WHERE `forumid` = ' . @mysql_real_escape_string($echo_thread['forumid'])));

    if (
in_array($echo_forum['forumid'],$forums)) {
      while (
$echo_forum['forumid'] >= 1) {
        
$parent_forums[] = '<a href="' $_SERVER['PHP_SELF'] . '?page=forum&forumid=' $echo_forum['forumid'] . '">' $echo_forum['title'] . '</a>';
        
$echo_forum = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `forum` WHERE `forumid` = ' . @mysql_real_escape_string($echo_forum['parentid'])));
      }
      
$parent_forums array_reverse($parent_forums);

      echo 
'<br /><a href="' $_SERVER['PHP_SELF'] . '?page=forum&forumid="' $startForum '">Home</a> → ' implode(' → ',$parent_forums);

      
// Grab the information using an array and set it to $echo_thread
      
while ($echo_post mysql_fetch_assoc($grab_posts)) {
        
// Find the user that posted
        
$find_user = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `user` WHERE `userid` = ' . @mysql_real_escape_string($echo_post['userid'])));
        
$text parsePost($echo_post['pagetext']);

        echo 
'<table border="1" class="index" id="' $echo_post['postid'] . '"><tr><td class="hrow">' . (($echo_post['title']) ? $echo_post['title'] : 'Re: ' $echo_thread['title']) . '</td></tr><tr><td class="row1">By <strong><a href="' $forumpath 'member.php?u=' $find_user['userid'] . '">' $find_user['username'] . '</a></strong> on <em>' date('F j, Y h:ia',$echo_post['dateline']) . '</em></td></tr><tr class="row"><td>' $text '</td></tr></table><br />';
      }
//      echo '<table class="index" border="1"><tr class="hrow"><td>Reply to Thread</td></tr><tr class="row"><td><form action="' . $_SERVER['PHP_SELF'] . '?page=newpost_submit" method="post"><textarea style="margin-left: auto; margin-right: auto; width: 90%; display: block; height: 400px;" name="post_content"></textarea><input type="submit" value="Reply" name="submit" /><input type="submit" value="Preview" name="submit" /><input type="reset" value="Reset" /><input type="hidden" name="threadid" value="' . $echo_thread['threadid'] . '" /></form></td></tr></table>';
      
if ($_GET['history']) {
        echo 
'<table border="1" class="index"><tr><td class="hrow">Other Versions</td></tr><tr><td class="row">';

        echo 
'</td></tr></table>';
      }
    }
    else {
      echo 
'<table border="1" class="index"><tr class="hrow"><td>Error</td></tr><tr class="row"><td>You are not allowed to view this thread.</td></tr></table><br />';
    }
  }

  
/*** Forum Display ***/
  
elseif ($page == 'forum') {
    
$forumid = ($_GET['forumid'] ? $_GET['forumid'] : $startForum);
    
$home_forum = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `forum` WHERE `forumid` = ' . @mysql_real_escape_string($forumid)));
    if (!
$home_forum) {
      echo 
'<table border="1" class="index"><tr class="hrow"><td>Error</td></tr><tr class="row"><td>The forum you are trying to view does not exist.</td></tr></table><br />';
    }
    elseif ((
inArray(explode(',',$home_forum['childlist']),$forums)) || !$home_forum) {
      
$grab_threads = @mysql_query('SELECT * FROM `thread` WHERE `forumid` = ' . @mysql_real_escape_string($home_forum['forumid']) . ' AND `visible` = 1 ORDER BY `sticky` DESC, `dateline` DESC');
      
$grab_forums = @mysql_query('SELECT * FROM `forum` WHERE `parentid` = ' . (($_GET['forumid']) ? @mysql_real_escape_string($_GET['forumid']) : $startForum) . ' ORDER BY displayorder ASC');

      
$parent_forum $home_forum;
      while (
$parent_forum['forumid'] >= 1) {
        
$parent_forums[] = '<a href="' $_SERVER['PHP_SELF'] . '?page=forum&forumid=' $parent_forum['forumid'] . '">' $parent_forum['title'] . '</a>';
        
$parent_forum = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `forum` WHERE `forumid` = ' . @mysql_real_escape_string($parent_forum['parentid'])));
      }
      
$parent_forums array_reverse($parent_forums);

      echo 
'<br /><a href="' $_SERVER['PHP_SELF'] . '?page=forum&forumid="' $startForum '">Home</a> → ' implode(' → ',$parent_forums);

      echo 
'<table class="index" border="1"><tr class="hrow"><td>Title</td><td>Last Post</td><td>Replies</td></tr>';
      while (
$echo_forum = @mysql_fetch_assoc($grab_forums)) {
        if (
inArray(explode(',',$echo_forum['childlist']),$forums)) {
          
$i += 1;
          
$class 'row' . (($i 2) ? '');
          echo 
'<tr class="' $class '"><td><a href="' $_SERVER['PHP_SELF'] . '?page=forum&forumid=' $echo_forum['forumid'] . '">' $echo_forum['title'] . '</a></td><td>' date('F j, Y h:ia',$echo_forum['lastpost']) .'<br />by ' $echo_forum['lastposter'] . '</td><td>Posts: ' $echo_forum['replycount'] . '<br />Threads: ' $echo_forum['threadcount'] . '</td></tr>';
        }
      }
      echo 
'</table><br />';

      echo 
'<table class="index" border="1"><tr class="hrow"><td>Title</td><td>Last Post</td><td>Replies</td></tr>';
      while (
$echo_thread = @mysql_fetch_assoc($grab_threads)) {
        if (
in_array($echo_thread['forumid'],$forums)) {
          
$i += 1;
          
$class 'row' . (($i 2) ? '');
          echo 
'<tr class="' $class '"><td>' . (($echo_thread['sticky']) ? 'Sticky: ' '') . '<a href="' $_SERVER['PHP_SELF'] . '?page=thread&threadid=' $echo_thread['threadid'] . '">' $echo_thread['title'] . '</a><br />by ' $echo_thread['postusername'] . '</td><td>' date('F j, Y h:ia',$echo_thread['lastpost']) .'<br />by ' $echo_thread['lastposter'] . '</td><td>' $echo_thread['replycount'] . '</td></tr>';
        }
      }
      echo 
'</table><br />';
    }
    else {
      echo 
'<table border="1" class="index"><tr class="hrow"><td>Error</td></tr><tr class="row"><td>You are not allowed to view this forum.</td></tr></table><br />';
    }
  }

  
/*** Blog Display ***/
  
else {
    if (
$_GET['forumid']) {
      
$home_forum mysql_fetch_assoc(mysql_query('SELECT * FROM `forum` WHERE `forumid` = ' $_GET['forumid']));
      
$forumin $home_forum['childlist'];
    }
    else { 
$forumin implode(',',$forums); }

    
// Count the total topics.
    
$topic_count = @mysql_fetch_assoc(@mysql_query('SELECT count(threadid) AS threads FROM thread WHERE (forumid IN (' . @mysql_real_escape_string($forumin) . ')) AND visible = 1 AND dateline >= ' $cutoff ''));
    
$threads $topic_count['threads'];
    
$threads2 ceil($threads/10);

    
// Find the page we're on.
    
$page intval($page);
    if (!
$page$page 1;
    
$start mysql_real_escape_string($page 10 10);
    if (
$start &lt1$start '0';

    
// Generate page jump.
    
$jump 'Page: ';
    for (
$i 1$i &lt$threads2$i++) {
      if (
$i == $page$jump .= $i ' ';
      else 
$jump .= '<a href="' $_SERVER['PHP_SELF'] . '?page=' $i '">' $i '</a> ';
    }

    
// Select the topic information from the correct forums and set it to $grab_threads
    
$grab_threads mysql_query('SELECT * FROM `thread` WHERE (`forumid` IN (' $forumin ')) AND `visible` = 1 AND `dateline` >= ' $cutoff ' ORDER BY `dateline` DESC LIMIT ' $limit ' OFFSET ' $start);

    
// Grab the information using an array and set it to $echo_thread
    
while ($echo_thread mysql_fetch_assoc($grab_threads)) {
      
// Select the post information from the correct forum and set it to $grab_posts
      
$echo_post = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `post` WHERE `threadid` = ' . @mysql_real_escape_string($echo_thread['threadid']) . ' ORDER BY `postid` ASC LIMIT 1'));

      
// Find the user that posted
      
$find_user = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `user` WHERE `userid` = ' . @mysql_real_escape_string($echo_post['userid'])));

      
// Find the forum that was posted in.
      
$find_forum = @mysql_fetch_assoc(@mysql_query('SELECT * FROM `forum` WHERE `forumid` = ' . @mysql_real_escape_string($echo_thread['forumid'])));

      
$text parsePost($echo_post['pagetext']);

      
$echo_thread['topic_time'] = date("F j, Y",$echo_thread['dateline']);
      
$comment_link $forumpath 'showthread.php?t=' $echo_thread['threadid'];

      echo 
'<table border="1" class="index"><tr><td class="tdnews">' . (($images[$echo_thread['forumid']]) ? '<img src="' $images[$echo_thread['forumid']] . '" alt="Pokemon" style="padding-right: 3px;" />' '') . '<a href="' $_SERVER['PHP_SELF'] . '?page=thread&threadid=' $echo_thread['threadid'] . '">' $echo_thread['title'] . '</a></td></tr><tr><td class="tdnews1">By <strong><a href="' $forumPath 'member.php?u=' $find_user['userid'] . '">' $find_user['username'] . '</a></strong> on <em>' $echo_thread['topic_time'] . '</em><br /><br />' $text '<br /><br /><a href="' $comment_link '">' . (($echo_thread['replycount'] == 0) ? 'no comments' $echo_thread['replycount'] . ' comment' . (($echo_thread['replycount'] &gt1) ? 's' '')) . '</a>, Posted in <a href="' $_SERVER['PHP_SELF'] . '?page=thread&threadid=' $find_thread['forumid'] . '">' $echo_thread['title'] . '</a>.</td></tr></table><br />';
    }

    if (!
$hideJump) { echo '<table border="1" class="index"><tr><td class="hrow">Jump to Page→</td></tr><tr><td class="row">' $jump '</td></tr></table><br />'; }
  }

  echo 
'<table border="1" class="index"><tr><td class="hrow">Other Information</td></tr><tr><td class="row">Threads posted before ' date('F jS, Y',$cutoff) . ' will not be displayed.<br />Vbulletin Viewer Version 1.6.2 Copyright © 2010 Joseph Parsons.<br />vBulletin © 2010 vBulletin Solutions. vBulletin™ is a register trademark of vBulletin solutions.</td></tr></table>';

Documentation
To setup:
  1. Upload this file.
  2. In a seperate PHP file include this file with the relevant configuration options.

To configure:
  • $forums - The list of forum IDs to be displayed.
  • $images - A list of Forum icon images for blog view.
  • $limit - Threads per page in blog view.
  • $forumpath - URL of Forum.
  • $cutoff - Unix Timestamp for Thread Cutoff
  • $startForum - Where threads should first be displayed. -1 for home forum. For thread view.
  • $hideJump - Undocumented.
  • $defaultPage - Whether to start in blog or thread mode.

Page 1 of 1

User List - Contact - Privacy Statement - Lycanroc.Net