vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW TO - vB4] Create your own vBulletin page (https://vborg.vbsupport.ru/showthread.php?t=228112)

Lynne 11-15-2009 10:00 PM

[HOW TO - vB4] Create your own vBulletin page
 
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

cellarius 11-17-2009 01:03 PM

Thanks Lynne for compiling this - this will be most helpful for many users, no doubt :)

So, I gather you agree with my doubts that the NO_REGISTER_GLOBALS constant is still needed?

Lynne 11-17-2009 02:18 PM

Quote:

Originally Posted by cellarius (Post 1915881)
Thanks Lynne for compiling this - this will be most helpful for many users, no doubt :)

So, I gather you agree with my doubts that the NO_REGISTER_GLOBALS constant is still needed?

Yep. I did a search in the vb pages and couldn't find NO_REGISTER_GLOBALS lurking around in any of them. :)

cellarius 11-17-2009 02:29 PM

Excellent! :)

Brandon Sheley 11-17-2009 02:32 PM

Thanks for the article Lynne :)

[high]* Brandon Sheley bookmarks this one[/high]

Mythotical 11-17-2009 06:40 PM

Might want to add if conditions to your article as well. I did a search through templates and found this:

To do an if condition in a template:
HTML Code:

<vb:if condition="$myvar['mytable']">
&nbsp; blah
<vb:else />
&nbsp; bleh
</vb:if>

Just replace $myvar with the variable you are using from your db query and mytable should be replaced with the row or column you are calling from the db.

Lynne 11-17-2009 07:22 PM

There are already articles about conditions to use in templates. I would just be repeating them by putting them in this article. There are also articles about rendering templates and registering variables also (which I linked to). I wanted to put this up as just a basic outline to get someone started.

Mythotical 11-17-2009 08:07 PM

Actually you point me to one article referring to conditions. I have not found one anywhere. You do that then your my savior.

bobster65 11-17-2009 08:35 PM

Quote:

Originally Posted by Steve M (Post 1916161)
Actually you point me to one article referring to conditions. I have not found one anywhere. You do that then your my savior.

https://vborg.vbsupport.ru/showthread.php?t=217570

Mythotical 11-17-2009 08:35 PM

Quote:

Originally Posted by bobster65 (Post 1916183)

Actually I found that, seems I wasn't searching for the right term.

nomoreturn 11-17-2009 10:34 PM

Where we have to upload test.php

cellarius 11-17-2009 10:45 PM

Quote:

Originally Posted by nomoreturn@hotm (Post 1916232)
Where we have to upload test.php

Put it in your forum root.

Lionel 11-18-2009 01:11 AM

Nice, and what do you do if you want to have 3 columns in your page? Right now I had to create a table with 3 td, but I had rather avoid that

Lynne 11-18-2009 01:39 AM

Quote:

Originally Posted by Lionel (Post 1916357)
Nice, and what do you do if you want to have 3 columns in your page? Right now I had to create a table with 3 td, but I had rather avoid that

There is no reason you can't use a table if you don't want to use divs. But, if you want to use divs to make 3 columns, google is a great place to start. There are lots of sites that will show you how to use divs in place of tables.

Lionel 11-18-2009 02:22 AM

Got your first reply. Sorry Lynne. I asked because I found you extremely helpful and because I could not find any places by vb to explain about the new css, until I saw that there were new templates.

Specially whatever you put in $stylevar does not necessarily gets implemented. So instead of thinking that they were bugs, I inquire first.

Mythotical 11-18-2009 03:22 AM

Lynne, so how would we call multiple templates for the same custom page and it actually work?

Lynne 11-18-2009 03:33 AM

You would do it as before, only use the new syntax. So, something like this:
PHP Code:

$pagetitle 'My Page Title';

$foo 'hello';
$bar 'world';
$templater vB_Template::create('first_template');
$templater->register('foo'$foo);
$templater->register('bar'$bar);
$my_variable $templater->render();  


$templater vB_Template::create('TEST');
$templater->register_page_templates();
$templater->register('my_variable'$my_variable);
$templater->register('navbar'$navbar);
$templater->register('pagetitle''Test Page');
print_output($templater->render()); 

You would use {vb:var foo} and {vb:var bar} in your first_template to insert the variables $foo and $bar and then you would use {vb:var my_variable} in the TEST template to insert the output from $my_variable.

Mythotical 11-18-2009 03:37 AM

EDIT: I'm a fruitcake, damn pain pill is kicking my butt right now.

PHP Code:

$templater->register('my_variable'$my_variable); 

Missing that from my print_output area.

Thanks tho, at least I understand now.

--------------- Added [DATE]1258523530[/DATE] at [TIME]1258523530[/TIME] ---------------

Ok next question, I am reusing the same variable for different pages so I am not having a cluster of different variables within conditional statements. Right now it seems that is confusing me or its the meds, either way is it safe to say I can keep doing that or should I change it?

PHP Code:

$templater->register('display'$display); 

That var is what I am reusing for each page load of do=cat or do=file, etc. Do I need to change it to print_output or what?

LoveStream 11-18-2009 03:51 PM

Thank your tutor.
I had met following error, when I using this template page, there is a cookie sent already.

Uh!
PHP Code:

Unable to add cookiesheader already sent.
File: /www/forum/phoenixjournals.php
Line
1

Forums test 

I create scripts as phoenixjournals.php, but it occur if I logout.

How could I solve it? or what deos it mean in this case?

I hope your teaching. Thanks.

ragtek 11-18-2009 04:16 PM

Be sure that there's nothing before <?php

Lynne 11-18-2009 05:58 PM

Quote:

Originally Posted by Steve M (Post 1916417)
Ok next question, I am reusing the same variable for different pages so I am not having a cluster of different variables within conditional statements. Right now it seems that is confusing me or its the meds, either way is it safe to say I can keep doing that or should I change it?

PHP Code:

$templater->register('display'$display); 

That var is what I am reusing for each page load of do=cat or do=file, etc. Do I need to change it to print_output or what?

You should be able to use the same variable name on different pages - vb does that alot.

If you are wanting to register that variable on each page for use in the template, you need to put that line inbetween the $templater = vB_Template::create('whatever_template') and the $templater->render() lines.

edit: Or actually, you may be able to just preregister it at the top of you page for the template. See the article I link to in my first post to find out about preregistering variables.

cory_booth 11-18-2009 06:06 PM

Replace the line:
require_one ./gobal

With:
PHP Code:

$curdir getcwd ();
chdir('/yourpath/to/site/public_html/forum');
require_once(
'/yourpath/to/site/public_html/global.php');
chdir ($curdir); 

Will allow you to put the php files anywhere on the site (i.e. mydomain.com/pages/)

LoveStream 11-19-2009 01:02 AM

Quote:

Originally Posted by ragtek (Post 1916684)
Be sure that there's nothing before <?php

Yes, I double checked it but it still remains. I suspect that affected by server programs. When I logged there is no problem. It is only just for guest than member logged.

I create new my.php file. and do define this scripts refer to template files.

Regards.

--------------- Added [DATE]1258599895[/DATE] at [TIME]1258599895[/TIME] ---------------

Quote:

Originally Posted by cory_booth (Post 1916733)
Replace the line:
require_one ./gobal

With:
PHP Code:

$curdir getcwd ();
chdir('/yourpath/to/site/public_html/forum');
require_once(
'/yourpath/to/site/public_html/global.php');
chdir ($curdir); 

Will allow you to put the php files anywhere on the site (i.e. mydomain.com/pages/)

Thanks. I do put it the same path with vB. When I trial as logged it's run very well.

Lynne 11-19-2009 01:10 AM

Quote:

Originally Posted by cory_booth (Post 1916733)
Replace the line:
require_one ./gobal

With:
PHP Code:

$curdir getcwd ();
chdir('/yourpath/to/site/public_html/forum');
require_once(
'/yourpath/to/site/public_html/global.php');
chdir ($curdir); 

Will allow you to put the php files anywhere on the site (i.e. mydomain.com/pages/)

Actually, if you chdir, you don't want to then put the whole path to the global.php file. You would just go:
PHP Code:

$curdir getcwd ();
chdir('/yourpath/to/site/public_html/forum');
require_once(
'./global.php');
chdir ($curdir); 


Mythotical 11-19-2009 02:52 AM

Quote:

Originally Posted by Lynne (Post 1916727)
You should be able to use the same variable name on different pages - vb does that alot.

If you are wanting to register that variable on each page for use in the template, you need to put that line inbetween the $templater = vB_Template::create('whatever_template') and the $templater->render() lines.

edit: Or actually, you may be able to just preregister it at the top of you page for the template. See the article I link to in my first post to find out about preregistering variables.

Good point, I will look into doing that tomorrow. Need sleep first.

ragtek 11-19-2009 09:14 AM

What's with
PHP Code:

require_once(DIR '/includes/class_bootstrap_framework.php');
vB_Bootstrap_Framework::init(); 

Do we need it?
Some files in vB4 have it^^

Lynne 11-19-2009 01:41 PM

You may need to add those lines depending on what you do in your code. But, every page doesn't need those lines. I *think*, but I'm not positive, that if you have hooks in your page, you will want to include those lines. But, since usually there aren't any hooks added into a custom page, then those lines aren't needed.

EidolonAH 11-21-2009 12:14 PM

Brilliant, thank you Lynne.:up:

Anseur 11-21-2009 04:05 PM

I've set this up on my test site, and it works OK while i'm logged in, but when I'm not logged in, and I visit this custom page, I just get a plain white screen.

looking at a source of this plain white pages shows me:
Code:

<!-- BEGIN TEMPLATE: dkp_template -->
 
<!-- END TEMPLATE: dkp_template -->

Here is the code currently used in the template for this custom .php page:

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}</title>
    {vb:raw headinclude}
  </head>
  <body>
   
    {vb:raw header}
   
    {vb:raw navbar}
   
    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
  <li class="popupmenu">
    <h2 class="blockhead">The MCO DKP System</h2>
    <h2 class="blocksubhead"> <vb:if condition="$show['modcplink']">
                                <a href="javascript://" class="popupctrl">Administration</a>
                                <ul class="popupbody popuphover">
                                        <li><a href="/25manwrathplus/admin/" target=”dkp_frame”>Admin Index</a></li>
                                        <li><a href="sublink2.php">SubLink 2</a></li>
                                        <li><a href="sublink3.php">SubLink 3</a></li>
                                </ul>
                            </li>
</vb:if> </h2>
                         
    <div class="blockbody">
      <div {height:auto;}>

<iframe name="dkp_frame" width=100% height=1700px SCROLLING=no FRAMEBORDER=0 src="/25manwrathplus">dkp_frame</iframe>
               
      </div>
    </div>
   
    {vb:raw footer}
  </body>
</html>


Lynne 11-21-2009 04:34 PM

Quote:

Originally Posted by Anseur (Post 1918381)
I've set this up on my test site, and it works OK while i'm logged in, but when I'm not logged in, and I visit this custom page, I just get a plain white screen.

looking at a source of this plain white pages shows me:
[code]
<!-- BEGIN TEMPLATE: dkp_template -->

<!-- END TEMPLATE: dkp_template -->

What is in your error_logs? (If you don't know where they are, ask your host.) What is in your php page that you created?

Anseur 11-21-2009 05:06 PM

Assuming you mean the error log I have access to via my hosts cpanel interface, the white page does not generate an error in there at all.

here's the contents of the php file. (dkp.php)

PHP Code:

<?php

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

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

define('THIS_SCRIPT''dkp.php');
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('dkp_template',
);

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

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

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

$navbits construct_navbits(array('' => 'MCO DKP'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'MCO DKP';

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

$templater vB_Template::create('dkp_template');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('pagetitle''MCO DKP');
print_output($templater->render());

?>


Lynne 11-21-2009 05:31 PM

Take this line out of your template and see if it works:
HTML Code:

<iframe name="dkp_frame" width=100% height=1700px SCROLLING=no FRAMEBORDER=0 src="/25manwrathplus">dkp_frame</iframe>
You may have to register the $show variable also - I can't remember if that one is required, but you might try it. (And please use the code tags for code, not quote tags.)

As for error_logs, I have no idea where they are in cPanel, I just know I get mine from a logs folder where the access_logs are also kept.

Anseur 11-21-2009 05:37 PM

Ok, did that, but I'm afraid it dosen't help.

happens in both IE8 and Firefox 3.5

I dunno if it is suppose to help, but I even rebuilt the styles from the ACP after the change and it still didn't change.

Lynne 11-21-2009 05:39 PM

You did what? I suggested a couple of things (remove the code, register the variable).

edit: It works just fine for me if I remove the line I suggested you remove.

Anseur 11-21-2009 05:52 PM

I think you edited your post. I did what you suggested before you edited your post. (remove the iframe)

I'm afraid I dont understand what "register the $show variable" means.

I know where the error logs are in cpanel, they are just called "error logs" (I know the log works because the live version of my site generates a few errors sometimes with one of the less used styles) and they dont generate an errors relating to this custom page.

Lynne 11-21-2009 06:00 PM

And I edited my post while you were writing your post again. It works just fine for me if I remove that line from the template. I get a page that just says "MCO DKP" (then new line) "The MCO DKP System".

Anseur 11-21-2009 06:08 PM

ok, can you confirm the iframe is what breaks it for you? (you doing this to your own test site or something?) ie, does it go white while logged out if you add the iframe?

thanks for your time.

Lynne 11-21-2009 06:12 PM

It goes white if I logout if I add the iframe, yes. That line is definitely the problem. I also get an error when logged in with that line (cannot find/25manwrathplus).

Anseur 11-21-2009 06:50 PM

Ok, Can't immagine why an iframe would do that.

Well thanks for your time anyway.

Parture 11-21-2009 06:55 PM

What's the CSS page for this page? Is it vbulletin.css


All times are GMT. The time now is 05:59 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.02185 seconds
  • Memory Usage 1,898KB
  • 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
  • (5)bbcode_code_printable
  • (3)bbcode_html_printable
  • (11)bbcode_php_printable
  • (11)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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