Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[HOW TO - vB4] Create your own vBulletin page
Lynne's Avatar
Lynne
Join Date: Sep 2004
Posts: 41,180

 

California/Idaho
Show Printable Version Email this Page Subscription
Lynne Lynne is offline 11-15-2009, 10:00 PM

This is an updated article on how to create your own vbulletin powered page. It's only for use with vB4.

This is NOT my work. I'm posting this from another thread where vB Style took the time to write this out. And his work is based on the article by Gary King here - How to create your own vBulletin-powered page! (uses vB templates)

Instructions to Create your Own Page:


1. Create the php page:
- Create a new file, whatever you want to call it (let's say test.php).
- Open up test.php and add the following (replace TEST with whatever template you want to show - WARNING: the template name is CASE SENSITIVE!!!):
Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'test');
define('CSRF_PROTECTION', true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('TEST',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits = construct_navbits(array('' => 'Test Page'));
$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'My Page Title';

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater = vB_Template::create('TEST');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());

?>
- Be sure to change 'TEST' to the actual template name (WARNING: the template name is CASE SENSITIVE!!!), and change 'test' to the filename or a unique name for the page. Also, change 'Test Page' and 'My Page Title' to whatever you want to show in the navbits, such as 'Viewing Member Profile' (just an example).

2. Create the Template:
- If you are in debug mode, create the template in your MASTER STYLE so it shows up in all your styles, otherwise make sure you create the template in the style you are using. If following the page above, call the template TEST (WARNING: the template name is CASE SENSITIVE!!!) with the following content:
HTML Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    
    {vb:raw header}
    
    {vb:raw navbar}
    
    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
    
    <h2 class="blockhead">Title</h2>
    <div class="blockbody">
      <div class="blockrow">
        Text
      </div>
    </div>
    
    {vb:raw footer}
  </body>
</html>
.
Instructions to Add your Page to the Who's Online List (WOL):
Create two plugins using the following hooks. Replace mypage and similar with your information.

1. hook location - online_location_process:
Code:
switch ($filename)
{
    case 'test.php':
        $userinfo['activity'] = 'mypage';
        break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
}
.
2. hook location online_location_unknown:
Code:
switch ($userinfo['activity'])
{
    case 'mypage':
        $userinfo['where'] = '<a href="test.php?'.$vbulletin->session->vars[sessionurl].'">My Page</a>';
        $userinfo['action'] = "Viewing My Page";
        $handled = true;
        break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
}
.
The colored part in the code above shows what you need to change in the plugins (both reds should be the same and both blues should be the same, whereas green can be whatever you want).


Please see this article for help with rendering templates - [vB4] Rendering templates and registering variables - a short guide
Reply With Quote
  #1102  
Old 10-22-2015, 09:23 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

THIS_SCRIPT is the actual variable name, so...

HTML Code:
<vb:if condition="THIS_SCRIPT != 'custom page'">
You would get that from this area in your php page:

PHP Code:
define('THIS_SCRIPT''test'); 
Replace 'custom page' with whatever you set that variable to in your php (in the above example, it would be 'test').
Reply With Quote
  #1103  
Old 10-22-2015, 09:53 PM
I.G.O.T.A.'s Avatar
I.G.O.T.A. I.G.O.T.A. is offline
 
Join Date: Mar 2011
Location: USA
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did that and now for some reason getting this. It looks like all tags are closed, but obviously I'm missing one, lol.

The following error occurred when attempting to evaluate this template:
Unclosed Tag
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Reply With Quote
  #1104  
Old 10-23-2015, 12:09 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didn't look closely at the code, but you only want the tags around the specific code you are adding to your page and don't want doubled.

HTML Code:
<vb:if condition="THIS_SCRIPT != 'custom page'">
<meta name="description" content="test">
<meta name="keywords" content="test">
<meta name="author" content="I.G.O.T.A.?">
</vb:if>
Reply With Quote
  #1105  
Old 12-12-2015, 03:15 PM
Alice Alice is offline
 
Join Date: Mar 2013
Location: Great Lakes Area
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
They are working as defined - both of these are from the reset-fonts.css file:
HTML Code:
h1, h2, h3, h4, h5, h6 {font-size:100%;font-weight:normal;}body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td {margin:0;padding:0;}
If you want it different, give it a class and define it yourself.
Okay so I checked the css template and I found that the tags: UL, OL, LI; which are necessary for coding bullet points onto the page, are already there and properly defined, and yet, this page still will not show the properly formatting of bullet points. I have included the exact code that is present in my reset-fonts.css template below.

I would appreciate any support that you are able to provide.

Thank you,

Code:
/*
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.7.0
*/
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var,optgroup{font-style:inherit;font-weight:inherit;}del,ins{text-decoration:none;}li{list-style:none;}caption,th{text-align: {vb:stylevar left};}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:baseline;}sub{vertical-align:baseline;}legend{color:#fff;}input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}input,button,textarea,select{*font-size:100%;}body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}select,input,button,textarea,button{font:99% arial,helvetica,clean,sans-serif;}table{font-size:inherit;font:100%;}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%;}
Reply With Quote
  #1106  
Old 12-12-2015, 04:14 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Seraphyn View Post
Okay so I checked the css template and I found that the tags: UL, OL, LI; which are necessary for coding bullet points onto the page, are already there and properly defined, and yet, this page still will not show the properly formatting of bullet points. I have included the exact code that is present in my reset-fonts.css template below.

I would appreciate any support that you are able to provide.

Thank you,

For your list, create a custom class and use it to define the bullets
Reply With Quote
Благодарность от:
Lynne
  #1107  
Old 05-11-2016, 11:51 AM
sr20de_99 sr20de_99 is offline
 
Join Date: Mar 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Should the samples listed in the first post work for a custom page when people aren't logged in?

Based on what was in the first post I've created the following, which seems to only work if I'm logged in. I need to setup a custom public page for people to sign up for various events.

ACME_CUSTOM_PAGE_TEMPLATE
HTML Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    {vb:raw header}
    
    {vb:raw navbar}
    
    <h2 id="acme_bannerTitle"class="blockhead">{vb:raw bannerTitle}</h2>
    <div class="blockbody">
      <div class="blockrow">
        <div id="acmeContents">
           {vb:raw my_var}
        </div>
      </div>
    </div>

    {vb:raw footer}
  </body>
</html>
acme_vbPublic.php (This is the file that my vBulletin "Public" Tab points to.)
Code:
<?php
	$tabScriptName = 'PublicTabScript';
	$pagetitle = 'ACME Public ($pagetitle)';
	$phpFile = './acme_custom/acme_public.php';
	$navTitle = 'Public Tab';
	$bannerTitle = 'Public Page Example';

	require_once($_SERVER['DOCUMENT_ROOT'] . "/acme_custom/acme_vb.php");
?>
acme_vb.php
Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
	error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
	define('THIS_SCRIPT', $tabScriptName);
	define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
	$phrasegroups = array();

// get special data templates from the datastore
	$specialtemplates = array();

// pre-cache templates used by all actions
	$globaltemplates = array('ACME_CUSTOM_PAGE_TEMPLATE');

// pre-cache templates used by specific actions
	$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
	chdir($_SERVER['DOCUMENT_ROOT']);
	require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
	$navbits = construct_navbits(array('' => $navTitle));
	$navbar = render_navbar_template($navbits);

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
?>

<?php

	ob_start();
	include($phpFile);
	$includedphp = ob_get_contents();
	ob_end_clean();

	$my_var .= $includedphp;

	$templater = vB_Template::create('ACME_CUSTOM_PAGE_TEMPLATE');
	$templater->register_page_templates();
	$templater->register('navbar', $navbar);
	$templater->register('pagetitle', $pagetitle);
	$templater->register('bannerTitle', $bannerTitle);
	$templater->register('my_var', $my_var);
	print_output($templater->render());
?>
acme_public.php
Code:
<div>
	This is my public page.
</div>
Navigation Tab Setup
Reply With Quote
  #1108  
Old 05-11-2016, 01:10 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Based on the code you posted, I don't see anything out of the ordinary that should cause such thing to happen.
Reply With Quote
  #1109  
Old 05-11-2016, 01:31 PM
sr20de_99 sr20de_99 is offline
 
Join Date: Mar 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ARGH!!!

Nothing to see here, move along. I figured it out. My template is currently only applied to one style. When I'm not logged in and visit the page, the style where my template is not selected. When I select the style then click on my "Public" tab, then everything works.
Reply With Quote
  #1110  
Old 05-11-2016, 01:34 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sr20de_99 View Post
ARGH!!!

Nothing to see here, move along. I figured it out. My template is currently only applied to one style. When I'm not logged in and visit the page, the style where my template is not selected. When I select the style then click on my "Public" tab, then everything works.
Put your site into debug mode, and then add the template to the "Master Style" so it will be auto-added to every style.
Reply With Quote
  #1111  
Old 06-02-2016, 07:38 PM
sr20de_99 sr20de_99 is offline
 
Join Date: Mar 2012
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK I'm back again. Everything seems to work fine for me on my local machine, but I ran into 404 errors when trying my code on my live site.

On my live site vBulletin is loaded directly under httpdocs folder. I have placed all of my code under httpdocs/acme_custom. When I load the page all of the styling is off, and upon further investigation I have a bunch of 404 errors, and none of the standard vBulletin links like Forum or Contact Us work. If I place my custom php file (acme_vbPublic.php) in httpdocs then everything works.

I performed a chgdir prior to the globl.php, so I'm not sure where I've gone wrong.
Code:
chdir($_SERVER['DOCUMENT_ROOT']);
require_once('./global.php');
Here's a screen shot of the page and the errors:


If I inspect the 404 errors, the request url is http://my-site.ca/acme_custom/client...event.js?v=423

I do not reference any of those resources that have 404 errors, I'm assuming that they are part of the global.php script.

Any clues? I'd prefer to keep all of my code under the acme_custom directory.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:27 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07497 seconds
  • Memory Usage 2,390KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (8)bbcode_code
  • (5)bbcode_html
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (3)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (59)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete