PDA

View Full Version : Stand Alone Custom vBulletin Page


Pages : [1] 2

Greg
09-02-2007, 04:25 PM
This is a pretty simple hack. The php part of it is the driver to hook into vBulletin where we will store the content for this page.

The template is the content part of the page which is manageable from the style manager in the ACP. You won't need to touch the php page in the future to change content.

First we look at the PHP.


<?php
/*================================================= =================*\
|| ################################################## ############## ||
|| # Stand Alone Custom vBulletin Page - Version .1 # ||
|| # ------------------------------------------------------------ # ||
|| # www.cpurigs.com 2002-2008 # ||
|| ################################################## ############## ||
\*================================================ ==================*/

// Error Reporting
error_reporting(E_ALL & ~E_NOTICE);

// Environment
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'YOUR_CUSTOM_TEMPLATE_NAME');

// init vB arrays
$specialtemplates = array();
$phrasegroups = array();
$actiontemplates = array();
$globaltemplates = array(
'YOUR_CUSTOM_TEMPLATE_NAME'
);

// vb globals
require_once("./global.php");


// NavBar
$navbits = construct_navbits(array('' => 'YOUR_NAVBAR_PAGE_NAME'));
eval('$navbar = "' . fetch_template('navbar') . '";');


// spit out template
eval('print_output("' . fetch_template('YOUR_CUSTOM_TEMPLATE_NAME') . '");');
?>


It's a simple driver file.

1) You name the script something unique so if you need to, you can use the THIS_SCRIPT constant in vBulletin to know what page you are on. (ie. links)

2) You set the template name the script will use. This is a new template we will create next. Name it the same as the script to be consistent. (ie. links)

3) Put the name of the page you want to appear in the breadcrumb of the navbar. (ie. Links)

4) Set the template name again the same as in step 2 for the eval statement.

5) save the file as scriptname.php. For instance, if it's a links page, links.php. (ie. links.php)

6) upload it to your forums folder and make sure it has execute rights. Usually 755, the default on many systems, is ok.

Now we need a template for the content. Here's the shell.

$stylevar[htmldoctype]
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$stylevar[languagecode]" dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>YOUR_PAGE_TITLE - $vboptions[bbtitle]</title>
</head>
<body>
$header
$navbar

<!- example table with some vBulletin CSS -->
<div class="center">
<table width="100%" class="tableline" cellspacing="1" cellpadding="4" border="2">
<tr>
<td colspan="2" class="tcat"><strong>YOUR_TITLE</strong></td>
</tr>
<tr>
<td valign="top" width="50%" class="alt1">


<!-- Content -->


</td>
</tr>
</table>
</div>
<!- /example table with some vBulletin CSS -->

$footer
</body>
</html>


Let's populate it with unique content.

1) Set the page title you want.

2) Put a title in the example html table header or replace all the example content as needed.

3) Copy and paste the whole template into a new template in the vB ACP style manager under add new template with the name you decided in step 2 of the php for the styles you want the new page to appear in and save it.

Go to your /forums/yourscriptname.php and test it.

You can do this for different topics and needs and you can make the page more dynamic with more php code. But those are different how to discussions.

Good luck. It should work out great for you!

Soon you will notice there needs to be a who's online hook or you get an Unknown Location on WOL. That's another discussion too, but we'll try and get to it.

mac27
02-29-2008, 08:50 PM
So is there a way to keep this page for only member viewing. Like lock it so only certain groups could view the page?

mac27
02-29-2008, 09:27 PM
Hey never mind I figured it out. I am a little rusty where I have not coded in a a few months but I got it.

Greg
03-02-2008, 10:03 AM
Good deal. Sorry we missed your post.

mac27
03-02-2008, 11:50 AM
Hey no problems noppid.

Greg
10-30-2008, 06:26 PM
To create a vBulletin driven .html page, follow the instructions above, but save your files as links.html instead of links.php.

IMPORTANT!

Then you need this in your .htaccess file.


AddType application/x-httpd-php .php .html

Greg
10-30-2008, 06:38 PM
So is there a way to keep this page for only member viewing. Like lock it so only certain groups could view the page?

You can add this right after the require_once global.php.


// stop guests
if( !$vbulletin->userinfo[userid] )
{
print_no_permission();
}



// allow only list groups
if( is_member_of($vbulletin->userinfo, 1, 3, 4, 6) )
{
print_no_permission();
}

mac27
11-06-2008, 08:12 PM
How hard would it be to pull the Newest Member, Total threads, total posts info and place it on one of these stand alone pages?

Greg
11-06-2008, 08:51 PM
If you rip those queries out of existing hacks, pretty easy. Each one needs a bit template and a shell for the bit template to load into on the add in page template.

If you are a coder, that may make sense. I've been working all day and still have my propeller on. If you need more details, ask.

mac27
11-06-2008, 08:52 PM
Well I am not a professional coder by all means. I am still in the learning seat. I keep trying to teach myself new stuff but this one has me stumped.

Greg
11-06-2008, 09:01 PM
Let's try and verbalize it...

In the php file before // spit out template is where your stuff goes. The // spit out template is the shell or main template.

So before // spit out template you need a query for each stat and a bit template for each stat. In the shell template above the table is a shell that can be loaded with bits.

Each query pulls some stats, you loop through each result and eval the bit template to a variable, say $newmembers. Then $newmembers goes in the table where content is.

A bit template looks like this...


<tr>
<td valign="top" width="50%" class="alt1">


<!-- Content -->


</td>
</tr>



the shell for it...


<!- example table with some vBulletin CSS -->
<div class="center">
<table width="100%" class="tableline" cellspacing="1" cellpadding="4" border="2">
<tr>
<td colspan="2" class="tcat"><strong>YOUR_TITLE</strong></td>
</tr>
$newmembers
</table>
</div>
<!- /example table with some vBulletin CSS -->



That goes in the template shell above.

I'm toast, I hope I'm getting something across.

mac27
11-06-2008, 09:05 PM
Hmmm that does make sense. I can see what I can do with it from here. Thanks for the help. I will post more if I run into anything with it. Thanks again!

mac27
11-06-2008, 09:21 PM
I got this error:

Fatal error: Call to undefined function fetch_online_status() in /home/xhris/public_html/forum/test.php on line 127

Here is my php file.


<?php

// Error Reporting
error_reporting(E_ALL & ~E_NOTICE);

// Environment
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test');

// init vB arrays
$specialtemplates = array(
'userstats',
'birthdaycache',
'maxloggedin',
'iconcache',
'eventcache',
'mailqueue',
'blogstats',
'blogcategorycache',
);
$phrasegroups = array();
$actiontemplates = array();
$globaltemplates = array(
'test',
'ad_forumhome_afterforums',
'FORUMHOME',
'forumhome_event',
'forumhome_lastpostby',
'forumhome_loggedinuser',
'forumhome_birthdaybit'
);

// vb globals
require_once("./global.php");


// NavBar
$navbits = construct_navbits(array('' => 'test'));
eval('$navbar = "' . fetch_template('navbar') . '";');






// ### LOGGED IN USERS #################################################
$activeusers = '';
if (($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 2 OR ($vbulletin->options['displayloggedin'] > 2 AND $vbulletin->userinfo['userid'])) AND !$show['search_engine'])
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$numbervisible = 0;
$numberregistered = 0;
$numberguest = 0;

$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser_ query')) ? eval($hook) : false;

$forumusers = $db->query_read_slave("
SELECT
user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,
session.userid, session.inforum, session.lastactivity,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
$hook_query_fields
FROM " . TABLE_PREFIX . "session AS session
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)
$hook_query_joins
WHERE session.lastactivity > $datecut
$hook_query_where
" . iif($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 3, "ORDER BY username ASC") . "
");

if ($vbulletin->userinfo['userid'])
{
// fakes the user being online for an initial page view of index.php
$vbulletin->userinfo['joingroupid'] = iif($vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['usergroupid']);
$userinfos = array
(
$vbulletin->userinfo['userid'] => array
(
'userid' =>& $vbulletin->userinfo['userid'],
'username' =>& $vbulletin->userinfo['username'],
'invisible' =>& $vbulletin->userinfo['invisible'],
'inforum' => 0,
'lastactivity' => TIMENOW,
'usergroupid' =>& $vbulletin->userinfo['usergroupid'],
'displaygroupid' =>& $vbulletin->userinfo['displaygroupid'],
'infractiongroupid' =>& $vbulletin->userinfo['infractiongroupid'],
)
);
}
else
{
$userinfos = array();
}
$inforum = array();

while ($loggedin = $db->fetch_array($forumusers))
{
$userid = $loggedin['userid'];
if (!$userid)
{ // Guest
$numberguest++;
$inforum["$loggedin[inforum]"]++;
}
else if (empty($userinfos["$userid"]) OR ($userinfos["$userid"]['lastactivity'] < $loggedin['lastactivity']))
{
$userinfos["$userid"] = $loggedin;
}
}

if (!$vbulletin->userinfo['userid'] AND $numberguest == 0)
{
$numberguest++;
}

foreach ($userinfos AS $userid => $loggedin)
{
$numberregistered++;
if ($userid != $vbulletin->userinfo['userid'])
{
$inforum["$loggedin[inforum]"]++;
}
fetch_musername($loggedin);

($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser' )) ? eval($hook) : false;

if (fetch_online_status($loggedin))
{
$numbervisible++;
$show['comma_leader'] = ($activeusers != '');
eval('$activeusers .= "' . fetch_template('forumhome_loggedinuser') . '";');
}
}

// memory saving
unset($userinfos, $loggedin);

$db->free_result($forumusers);

$totalonline = $numberregistered + $numberguest;
$numberinvisible = $numberregistered - $numbervisible;

// ### MAX LOGGEDIN USERS ################################
if (intval($vbulletin->maxloggedin['maxonline']) <= $totalonline)
{
$vbulletin->maxloggedin['maxonline'] = $totalonline;
$vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
}

$recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
$recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], true);
$recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);

$show['loggedinusers'] = true;
}
else
{
$show['loggedinusers'] = false;
}

// ### GET FORUMS & MODERATOR iCACHES ########################
cache_ordered_forums(1, 1);
if ($vbulletin->options['showmoderatorcolumn'])
{
cache_moderators();
}
else if ($vbulletin->userinfo['userid'])
{
cache_moderators($vbulletin->userinfo['userid']);
}

// define max depth for forums display based on $vbulletin->options[forumhomedepth]
define('MAXFORUMDEPTH', $vbulletin->options['forumhomedepth']);

$forumbits = construct_forum_bit($forumid);
eval('$forumhome_markread_script = "' . fetch_template('forumhome_markread_script') . '";');

// ### BOARD STATISTICS #################################################

// get total threads & posts from the forumcache
$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
foreach ($vbulletin->forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);

// get total members and newest member from template
$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
$newusername = $vbulletin->userstats['newusername'];
$newuserid = $vbulletin->userstats['newuserid'];
$activemembers = vb_number_format($vbulletin->userstats['activemembers']);
$show['activemembers'] = ($vbulletin->options['activememberdays'] > 0 AND ($vbulletin->options['activememberoptions'] & 2)) ? true : false;

eval('$ad_location[\'ad_forumhome_afterforums\'] = "' . fetch_template('ad_forumhome_afterforums') . '";');

// ### ALL DONE! SPIT OUT THE HTML AND LET'S GET OUTTA HERE... ###



// spit out template
eval('print_output("' . fetch_template('test') . '");');
?>

Greg
11-06-2008, 09:43 PM
add an include at the beginning after global.php.

require_once(DIR . '/includes/functions_bigthree.php);

mac27
11-06-2008, 09:49 PM
cool! Fixed that one. Now this one showed up:

Fatal error: Call to undefined function cache_moderators() in /home/xhris/public_html/forum/test.php on line 171

mac27
11-06-2008, 09:52 PM
OK got it fixed. That Part anyways.

mac27
11-06-2008, 10:14 PM
It isn't pulling the info from the database. I copy and pasted the "What's going on" box code into the template. Is that wrong?

mac27
11-07-2008, 12:06 AM
OK it is all good. I finally got it all working.

Greg
11-07-2008, 07:57 AM
Sorry, I walked away and crashed and burned. I put in about 14 hours yesterday coding.

Good job working that out!

mac27
11-07-2008, 12:38 PM
Thanks man and I understand the 14 hour work day. I do that about 3-4 times a week. It sucks. My next task is to figure out how to email out the page I am creating. You know pull the images and links and stuff. Any good websites to help me learn that?