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
  #602  
Old 07-06-2011, 09:39 AM
mohammad6006's Avatar
mohammad6006 mohammad6006 is offline
 
Join Date: May 2008
Location: IRAN (Tabriz)
Posts: 116
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i create a page with this learning

now how can i change this page to a product?
Reply With Quote
  #603  
Old 07-06-2011, 10:51 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by mohammad6006 View Post
i create a page with this learning

now how can i change this page to a product?
You cannot includes files in a product xml file. You need to include them separately. And then to include the templates, you need to be in debug mode (there is an article about this) and then add the template to the product.
Reply With Quote
  #604  
Old 07-11-2011, 03:21 AM
scubasteve3 scubasteve3 is offline
 
Join Date: May 2011
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
You should have no echo statements in your coding or it will go above the template header. All output in your page should be assigned to a variable, that variable registered for use in a template, and then the variable put in the template where you want your output to show.
Sorry, I am not a coder and am still trying to figure out vbulletin.

So I went into my PHP code and replaced the echo with:
$test1 = "..."

I then tested it by adding echo "$test1" and that worked.

So then I tried adding this variable to the template but this is where I am having no luck. Here is what I have in the template:

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>

<h1> Test 1 </h1>
	
{vb:raw test1};
    
    {vb:raw footer}
  </body>
</html>
I'm not sure if I got this wrong
Reply With Quote
  #605  
Old 07-11-2011, 04:29 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to pass it to the template.

Add this before the print_output($templater->render()); line:
PHP Code:
$templater->register('test1'$test1); 
Reply With Quote
  #606  
Old 07-11-2011, 05:08 AM
scubasteve3 scubasteve3 is offline
 
Join Date: May 2011
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
You need to pass it to the template.

Add this before the print_output($templater->render()); line:
PHP Code:
$templater->register('test1'$test1); 
Ah, great that worked somewhat. I think maybe I'm using the wrong command. Basically I am trying to pull out threads from the forum and put the links onto an external page. Here is my PHP Code:
PHP Code:
<?
    //print Today's threads
       $query = "SELECT * from vbthread where dateline >". $one_day_ago . " AND dateline <" . $today . " AND FORUMID in (2,4,6)";
        $result = mysql_query($query . " ORDER BY (views+votetotal) DESC"); 

    //print it
    while ($row = mysql_fetch_assoc($result)) {
        $test1 = "<a href='showthread.php?". $row["threadid"] . "'>".  $row["title"] . " " . $row['postusername'] . " " . $row['votetotal']/$row['votenum'] . " avg score " . "|" . $row['votetotal']  . " votetotal" . "  +  " . $row['views'] . " views " . "  =  " . ($row['votetotal']+$row['views']) . "</a><br/>";
I added your $templater code to and that worked but it only shows the very last thread not all of the threads. I think I need to be using a different code in the template other than {vb:raw variable}?

Also if I want to then add another variable I can just do the same thing? Add another line
PHP Code:
$templater->register('test2'$test2); 
[/QUOTE]
and add the vb code in the template?
Reply With Quote
  #607  
Old 07-11-2011, 05:33 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, you can do that for as many variables as you like.

Regarding your problem that only the last line is shown: In your while loop, you're overwriting your $test1 variable with every single loop, so only the result of the last one is returned in the end. You need not use $test1 = "whatever", but $test .= "whatever". This will not overwrite the existing value of the variable, but preserve the old value and add the new value at the end of the string.
Reply With Quote
  #608  
Old 07-11-2011, 01:46 PM
scubasteve3 scubasteve3 is offline
 
Join Date: May 2011
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
Yes, you can do that for as many variables as you like.

Regarding your problem that only the last line is shown: In your while loop, you're overwriting your $test1 variable with every single loop, so only the result of the last one is returned in the end. You need not use $test1 = "whatever", but $test .= "whatever". This will not overwrite the existing value of the variable, but preserve the old value and add the new value at the end of the string.
Awesome! That works great!

One last problem I have. As I am trying to pull threads from X days ago, for some reason the date seems to be one day off. Here is what I have defined for x days ago:
PHP Code:
$today strtotime("now");
    
$one_day_ago strtotime("-1 day");
    
$two_days_ago strtotime("-2 day");
    
$three_days_ago strtotime("-3 day");
    
$four_days_ago strtotime("-4 day");
    
$five_days_ago strtotime("-5 day");
    
$six_days_ago strtotime("-6 day");
    
$seven_days_ago strtotime("-7 day");
    
$eight_days_ago strtotime("-8 day");
    
$nine_days_ago strtotime("-9 day");
    
$ten_days_ago strtotime("-10 day"); 
Its showing $today values as yesterdays threads instead of today's...seems like all of them are off by one day. I think it is because it is showing the threads that were posted exactly 24 hours, 48 hours, 72 hours, etc from the time the page is loaded. Is there a way to change that to just any threads there were posted on X Date regardless of the time.
Reply With Quote
  #609  
Old 07-11-2011, 04:50 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You really need to open your own thread for this - this has nothing to do with this tutorial.
Reply With Quote
  #610  
Old 07-13-2011, 02:35 AM
thunderclap82 thunderclap82 is offline
 
Join Date: Nov 2008
Posts: 305
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've followed this tutorial to a 'T' (as far as I can tell) yet the php file I'm trying to call (a newsletter form submission) won't load within the template.

I created newssubscription.php and put it in my forum folder.

Code:
<?php

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

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

define('THIS_SCRIPT', 'newslettersubscription');
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('newsletter_subscription',
);

// 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('' => 'Newsletter Subscription'));
$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Newsletter Subscription';

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

$templater = vB_Template::create('newsletter_subscription');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('subscribe_newsletter', $subscribe_newsletter);

print_output($templater->render());

?>
I then created a template called newsletter_subscription.

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>
    
    <center><h2 class="blockhead">Newsletter Subscription</h2></center>
    <div class="blockbody">
      <div class="blockrow">

<center>{vb:raw subscribe_newsletter}</center>

      </div>
    </div>

    {vb:raw footer}
  </body>
</html>
Finally I created a vBulletin, global_start plug-in called subscribe_newsletter that is active.

Code:
ob_start();
include('/home/fpaul46/public_html/forum/newsletter_form/form.php');
$includedphp = ob_get_contents();
ob_end_clean();
I've checked and rechecked and everything seems to be entered correctly. Any thoughts on what's happening? What am I missing that is preventing this from working?
Reply With Quote
  #611  
Old 07-13-2011, 02:51 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There are no plugins in the test.php page. You need to put the php into the test.php page. Plugins are for modifying files you don't want to actually modify. When you create your own php page, you need to put all php in there because they don't use plugins.
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 11:00 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.12077 seconds
  • Memory Usage 2,404KB
  • 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
  • (7)bbcode_code
  • (1)bbcode_html
  • (5)bbcode_php
  • (4)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
  • (4)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (58)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)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