Register Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Article Options
[How-To] vBulletin API Basics: Creating Custom Pages & Misc.
akanevsky
Join Date: Apr 2005
Posts: 3,973

by akanevsky akanevsky is offline 10 Oct 2005

Ever wanted to create your own vBulletin-powered page but didn't know how? With this [How-To], you can.

NOTE: This is a vBulletin 3.5 version of Gary King's Manual, updated and expanded.

NOTE TO CODERS: THIS TUTORIAL CONTAINS MOST UP TO DATE INFORMATION IN THE WHOLE THREAD. IF ANY FURTHER POSTS BY 3RD PARTIES (INCLUDING OTHER CODERS) CONTAIN ANY INFORMATION THAT COMES INTO A CONFLICT WITH ANYTHING SAID IN THIS TUTORIAL, IT CAN BE CONSIDERED FALSE, UNLESS I VERIFY IT.

BASICS

Creating a custom vBulletin-Powered Script
  1. Create a new file, whatever you want to call it (let's say test.php).
    Open up the newly created file and fill in the following code:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

  2. Read through the code above and change what's commented with "// change this...".
  3. $navbits, just as any other array, can contain an unlimited of items. Note that in $navbits, array key serves an URL (in this case, pre-defined variable $parent contains an URL to the current script itself), and array value is what will actually be displayed as a link in your HTML output.

    Another example:

    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

    The above is going to result in "Sometitle" serving as a link to "somepage.php", followed by "Sometitle2" serving as a link to "somepage2.php".
  4. Create template test_mytesttemplate1. Paste in the following content:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.


You are done!

Note that template names are prefixed with test_. Prefixing is a good practive, as it makes it easier to manage the mass later on. This applies not only to templates, but also to custom phrases and options.

On to the next section:

Adding Custom Online Locations

If you want Who's Online to reflect your new custom page when someone is browsing it (rather than Unknown Location), do the following steps:
  1. Open AdminCP.
  2. Plugin System -> Add New Plugin
  3. Fill in the following:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

  4. Click Save.
  5. Plugin System -> Add New Plugin
  6. Fill in the following:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

  7. In each of the above two, make sure to change "test" values to your own.
  8. Note that $userinfo['where'] is optional. It can be controlled with a usergroup permission "can view detailed location".

You are done!

Using vBulletin-powered scripts outside vBulletin Directory

REPLACE


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

WITH


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Where "/home/site/public_html/forums" must be replaced with an actual system path to your forums.
Also, make sure you add the following code in the beginning of any relative links:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Creating "Subpages"

If you want to create "subpages" within your custom page, simply wrap blocks of code with the following structure:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Limiting Access to the Script

Registered Members Only

UNDER


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

ADD


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Certain Usergroups Only (In this example, 6 and 7)


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

You can also use the limits in your vBulletin templates. Here are to examples that you can use (but you are not limited to using them, so utilize your imagination):


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

ADVANCED CODING
Do not read below unless you have a basic knowledge of PHP and a general idea of what is it that you are doing.

vBulletin Phrase Replacements

As you might now, vBulletin supports phrase replacement. In other words, if your phrase (in this example, "testphrase") contains the following text,


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

What's it for? Well, if you use the following PHP code, you get "The user testuser has written 10 posts" in $testvar:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

You can use as many replacement as you want in the construct_phrase() function. 1st replacement corresponds to {1}, 2nd - to {2}, Nth - to {N}... You can also use these replacements in templates, with a slightly different syntax:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Using Variables in Templates

To use variables in templates, follow these rules:
  • "Regular" Variables ($somevar, $somevar2, etc).
    Use anywhere within template text.
  • "Array-Type" Variables ($somevar['someval'], etc).
    Avoid using single quotes, otherwise you get a parse error. In other words, use $somevar[someval] instead of $somevar['someval'].
  • "Object-Type" Variables ($vbulletin->GPC['somevar']).
    Do use single quotes, but wrap such variables into figure brackets. One valid example is {$vbulletin->GPC['somevar']}.
    If you attempt using $vbulletin->GPC['somevar'] or $vbulletin->GPC[somevar], you will get an error.

Warning: As a security measure, avoid using arrays $_POST[], $_GET[], $_REQUEST etc., in your templates - even though you may if you really need to.

Using Conditionals in Templates

vBulletin 3.0.0 and up features templates conditionals. Example:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

In conditionals (the part highlighted in blue), and ONLY in conditionals, you should use the regular PHP variable-naming syntax (disregarding what's said in "Using Variables in Templates" part of this tutorial). Just put in whatever you would normally put into the if() clause.

Notably, vBulletin does not feature an "else if" clause within its templates system. Therefore if you need more than one conditional, you can nest them. Example:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

You can nest any number of conditional clauses, as long as the code is valid.

Valid vBulletin URL Formation
  • Every URL to a vBulletin page within the same site must contains a sessionurl.
    Note: You do not need to add an ampersand (&) after the sessionurl.

    In PHP Code, an example of a valid URL would be:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

    In templates, you can use $session[sessionurl] instead. E.g.:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

  • If you pass more than one parameter using $_GET, use & instead of just &.
    This way you will preserve valid XHTML code.

Creating Custom Standard Error Messages

Read very carefully. To show standard error messages, you must:
  1. Create a phrase in Front-End Error Messages, prefixed with "error_". The prefix is mandatory.
  2. Use the following PHP code in your manual:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

    Be sure to change "error_myphrase" to your actual phrase (again, the real phrase must be prefixed with "error_").

Creating Redirects

To create a redirect you must:
  1. Make sure there is no output before the redirect, otherwise it might not work correctly.
  2. Define redirect URL using the following PHP code:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

  3. Do not forget to replace "mytestpage.php" with an actual filename.
  4. Make sure to leave $vbulletin->session->vars['sessionurl'] part intact, otherwise the page might not work correctly.
  5. Make sure to replace "somevar=someval" with any variables and their respective values that you want to pass to the next script via $_GET array.

Once you are done with that:
  1. Create a phrase in "Front-End Redirect Messages" group. Must be prefixed with "redirect_".
  2. Add the following code where you want to activate the redirect:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.

  3. Be sure to replace "redirect_myphrase" with an actual phrase name.
  4. Be sure that you end up having a "redirect_" prefix.

Done!

>> END OF MANUAL

Last edited by akanevsky : 29 Nov 2005 at 17:31.
Views: 66479
Comments
  #2  
Old 15 Jan 2006, 14:22
Brad's Avatar
Brad Brad is offline
 
Join Date: Nov 2001
Real name: B-rad
Please direct any questions to this forum:

http://www.vbulletin.org/forum/forumdisplay.php?f=111
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Article Options

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


New To Site? Need Help?

All times are GMT. The time now is 07:30.

Layout Options | Width: Wide Color: