vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Some basics of vB3(mini howto) (https://vborg.vbsupport.ru/showthread.php?t=59939)

Zachery 01-08-2004 10:00 PM

Some basics of vB3(mini howto)
 
Some basics of vB3(mini howto)
also some basic php junk
the most important thing if you want to make pages based on templates or anything of the such would be to first know how to "

connect" to vbulletin, and then learn how to call and eval templates. so lets take a look at the most BASIC page we can do
PHP Code:

<?php
// ## Changes Directory so it can accesss vBulletin IF we are outside the forums folder, if not this is not nessary ##
chdir("./forums");
 
// ## Error Reporting ( we use error reporting in php so we can control the display of error messages
// ## we will use this because all vBulletin files follow the same error reporting rules) ##
error_reporting(E_ALL & ~E_NOTICE);
 
// ## this action here cache's the templates so that everytime their needed a querry wont be needed to run 
// ## the names in there are just the template names :), there must be a comma after everyone but the last ##
$globaltemplates = array(
'main'
);
 
// ## Grabs global.php this grabs vbulletins global.php so we can use the most basic of vBulletins functions ##
require_once("./global.php");
 
// ## this calls to print out one main template ##
eval('print_output("' fetch_template('main') . '");');
?>

So theres a basic file, if your going to make one, that would i think be the mininum needed. now if you are going to be making

somthing abit more advanced. suchas calling more than one template, or doing an action it becomes abit more complicated


PHP Code:

<?php
// ## Changes Directory so it can accesss vBulletin IF we are outside the forums folder, if not this is not nessary ##
chdir("./forums");
 
// ## Error Reporting ( we use error reporting in php so we can control the display of error messages
// ## we will use this because all vBulletin files follow the same error reporting rules) ##
error_reporting(E_ALL & ~E_NOTICE);
 
// ## this here defines the "this_script" function, which if you use template conditionals, it will come in handy :) ##
define('THIS_SCRIPT''page');
 
// ## this action here cache's the templates so that everytime their needed a querry wont be needed to run
// ## the names in there are just the template names :), there must be a comma after everyone but the last ##
$globaltemplates = array(
'main',
'big',
'small'
);
 
// ## Grabs global.php this grabs vbulletins global.php so we can use the most basic of vBulletins functions ##
require_once("./global.php");
 
// ## ok this next set of lines "eval"'s our templates so they can be called inside the template we will print out ##
eval('$big = "' fetch_template('big') . '";');
eval(
'$small = "' fetch_template('small') . '";');
 
// ## this calls to print out one main template ##
eval('print_output("' fetch_template('main') . '");');
?>


PHP Code:

// ## if were going to use actions and their templates
// ## arnt used anywhere else in the file but the actions we add this
// ## under $globaltemplates = array();
// ## where small is would be the action name
// ## and other is the template used ##
$actiontemplates = array(
                            
'small' => array(
                                                     
'other'
                                                    
)
); 
// ## this is a action, and it can be added before the final
// ## eval('print_output("' . fetch_template('main') . '");');
// ## anything done before this request can be called inside the template
// ## so lets say if you evalled the template big, as $bit, it can be called
// ## here with other. ##
if ($_REQUEST['do'] == 'small')

eval(
'print_output("' fetch_template('other') . '");'); 


one more note

if your going to write a script that is ALL actions you should add somthing like this right after the call to gobal.php
PHP Code:

if (empty($_REQUEST['do'])) 
{
$_REQUEST['do'] == 'small';


this will ensure that if the usergoes to foo.php instead of foo.php?do=small they will still see the correct page :)

Mini Tut by Faranth
(with some help from Brad.loo fixing my silly newbie mistakes :) )

Hobbes 01-09-2004 03:24 AM

...Nice....good for n00bs like me :)

paddysplace 01-09-2004 03:36 AM

Quality work there Faranth. DEFINITELY a good resource for those wanting to make a custom page but don't know where to start! This might inspire me to chime in myself and write up a few mini tutorials. Keep up the good work bro! Cheers!

Regards,
Patrick

Apoco 01-09-2004 03:40 AM

Quote:

Originally Posted by Hobbes
...Nice....good for n00bs like me :)

I agree you really need it hobbierz :-p, rofl, jk GreatJob Faranthierz!!

Link14716 01-09-2004 04:01 AM

Yeah, nice job. ^^ :)

Brad 01-09-2004 04:33 AM

Just a little note, if you are going to be writing scripts that are a bit more advanced. Sometimes you will need to retrive information from vBulletin datastore templates, to do so add this above the call to global.php

PHP Code:

// get special data templates from the datastore
$specialtemplates = array(
    
'smiliecache',
    
'bbcodecache'
); 

That will pull the smilie and bbcodecache which would be needed if you where say, pulling post information from the database (think news scripts). If you need to pull something from the datastore look in the vBulletin file that emulates what you would like to do and find out what it is pulling from the datastore.

Zachery 01-09-2004 05:24 AM

Quote:

Originally Posted by Brad.loo
Just a little note, if you are going to be writing scripts that are a bit more advanced. Sometimes you will need to retrive information from vBulletin datastore templates, to do so add this above the call to global.php

PHP Code:

// get special data templates from the datastore
$specialtemplates = array(
    
'smiliecache',
    
'bbcodecache'
); 

That will pull the smilie and bbcodecache which would be needed if you where say, pulling post information from the database (think news scripts). If you need to pull something from the datastore look in the vBulletin file that emulates what you would like to do and find out what it is pulling from the datastore.

thanks brad :)

MindTrix 01-09-2004 03:12 PM

Handy // Confusing tips there :) Thanks

Zachery 01-09-2004 03:16 PM

confusing?

MindTrix 01-09-2004 03:34 PM

If you want too be ;)

Zachery 01-09-2004 03:49 PM

[high]* Faranth is now confused :([/high]

MindTrix 01-09-2004 04:18 PM

Yup that was my main aim :) Lol, nah i meant at first that it was confusing because i was reading too fast, and still scratching up on the ol' PHP

Zachery 01-09-2004 04:19 PM

Quote:

Originally Posted by MindTrix
Yup that was my main aim :) Lol, nah i meant at first that it was confusing because i was reading too fast, and still scratching up on the ol' PHP

you worried me for a moment :P

:) hope it helped

Floris 01-09-2004 04:50 PM

Quote:

Originally Posted by Faranth
you worried me for a moment :P

:) hope it helped

Good job faranth, looks complete and hopefully helps some noobs :)

Zachery 01-10-2004 02:28 AM

Quote:

Originally Posted by Mr. HillBilly
Nice jobs, could you make a mini guide for making templates?

whatcha mean? templates are simple to make, its just html >.<

Brad 01-10-2004 05:22 AM

Hi, I notcied one error with the action templates call. It should be:

PHP Code:

$actiontemplates = array(
                            
'small' => array(
                                                     
'other'
                                                    
)
); 

:)

Zachery 01-10-2004 05:23 AM

whatchu talkin about foo :P

Mr. HillBilly 01-10-2004 06:32 AM

Thanks much for the guide!

I made a page, first time I've ever done it.

http://ph33rnet.com/uc.php

rrottman 01-11-2004 07:49 PM

Faranth, any hint:
I copied the first code block (the very easy one :-) ) and tried it: Nothing gets displayed. Any hint?

rrottman 01-11-2004 07:52 PM

I created a new, empty file. This is all and exactly what's in there:

PHP Code:

<?php
    chdir
("./forum");
    
error_reporting(E_ALL & ~E_NOTICE);
    
$globaltemplates = array('main');
    require_once(
"./global.php");
    eval(
'print_output("' fetch_template('main') . '");');
?>

It's saved as index.php in the website root, while vB sits in /forum.
If I open http://www.mydomain.com in a browser, this is what I receive:

HTML Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>

Any idea?
For troubleshooting I replaced the print_output with:

echo fetch_template('main');

and received an empty string, too.

Please help.

rrottman 01-11-2004 08:00 PM

@Faranth:
Additionally, you say that

$globaltemplates = array('main');

is for caching templates? How does this work? To me it appears as if you just declare a local array? The fetch_template function in functions.php does not reference any var named $globaltemplates. Could you possibly explain why you init this array in the page?

And I'm still not getting the template :-(

THANKS FOR BEING PATIENT WITH ME! :-)

rrottman 01-11-2004 08:03 PM

Some more troubleshooting steps it now appears as if the fetch_template does not return any content. It's empty... hmm... HELP!

Zachery 01-11-2004 08:14 PM

Quote:

Originally Posted by rrottman
Some more troubleshooting steps it now appears as if the fetch_template does not return any content. It's empty... hmm... HELP!

sorry ive been working on stuff, you can wait more than 3 min for a nother post too ;D

yes $globaltemplates cach's the template

do you HAVE a template called main in the database?

rrottman 01-11-2004 08:22 PM

Faranth, my capitalized "help" was in no way ment to offend you in any way. It's just I was in such a despair...

Do I have a template called "main"... honestly, I don't know. Maybe. Is there any standard template, comming with the clean default vB3 RC2 install I could test instead?

And: I understood that you were saying that the $globaltemplates array is done to cache templates but I don't know how it does so. Is there a GLOBAL variable named $globaltemplates in the vB system? I mean, if I put this statement at the top of my script, all it does is create an array with a single string value but how does this "instruct" vb to cache a template?

Zachery 01-11-2004 08:25 PM

lol thats most lily your problem you dont have another tempalte atm lol ^^


make a new template called main and add anything you like to it :)

rrottman 01-11-2004 08:29 PM

And one more question, Faranth (sorry, knowing that you're online is just too attractive.. :-) ):

Why do I have to use eval(...). Couldn't I just do a

$output = fetch_template(...);
echo $output;

?

Zachery 01-11-2004 08:31 PM

why two lines?

eval('print_output("' . fetch_template('main') . '");');

one simple line, plus this is how its done for all files in vb

rrottman 01-11-2004 08:34 PM

Hmm. I see. I might not have asked my question the right way. (I'm not a native English speaker. Sorry again.)

I was wondering why to use the eval() at all?
Why not:

echo fetch_template("FORUMHOME");

but instead:

eval('echo "'.fetch_template(...).'");');

So my main question was: Why do we use eval here? Is it, because templates might contain php code, too? or vars?

(Btw.: You were right with the "main" template. If I replace it with e.g. FORUMHOME, it works great.)

I still do not understand how the declaration of the local variable $globaltemplates helps caching...

Zachery 01-11-2004 08:35 PM

ah yes, actually , if conditions are inlaid php :) all of the tempaltes are stored in php format to boot

VodkaFish 01-12-2004 08:35 PM

If I slap your (longer) example into a blank .php page and use the shell_blank as my template (unchanged); I get an "object expected" error when the page tries to run this script:
Code:

<script type="text/javascript">
<!--
        // Main vBulletin Javascript Initialization
        vBulletin_init();
//-->
</script>

* The page I wrote was in a different directory, so I used this:
PHP Code:

chdir("../forums"); 


Zachery 01-12-2004 08:37 PM

Quote:

Originally Posted by VodkaFish
If I slap your (longer) example into a blank .php page and use the shell_blank as my template (unchanged); I get an "object expected" error when the page tries to run this script:
Code:

<script type="text/javascript">
<!--
        // Main vBulletin Javascript Initialization
        vBulletin_init();
//-->
</script>

* The page I wrote was in a different directory, so I used this:
PHP Code:

chdir("../forums"); 


you know i also ran into that problem(with other things) i think its somthing with the header include but im not sure >.<

VodkaFish 01-13-2004 03:56 PM

Code:

<script type="text/javascript">
<!--
var SESSIONURL = "";
var IMGDIR_MISC = "images/misc";
// -->
</script>

<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>
<script type="text/javascript" src="clientscript/vbulletin_menu.js"></script>

Well, this was in my header, and why the errors are probably showing. Seems the script locations aren't automatically changed. Probably just a header edit needed.

I put this in my forums directory and it was error-free.

However - despite the nav (with the user cp/register, faqs, etc.) being included in the shell, I still don't see that. Am I missing some other include?

NTLDR 01-13-2004 04:06 PM

If your not using Gamma you should prefix all the JS includes with $vboptions[bburl]/ to make sure they get included properly if you have pages outside of the forums directory.

Zachery 01-13-2004 04:08 PM

doh! i knew i forgot about sumthing, thanks NTLDR :)

VodkaFish 01-13-2004 06:07 PM

Surely, easy fix... but how do I get that main/top nav into my page?

Zachery 01-13-2004 06:52 PM

Quote:

Originally Posted by VodkaFish
Surely, easy fix... but how do I get that main/top nav into my page?

try

eval('$front_header = "' . fetch_template('header') . '";');

VodkaFish 01-13-2004 10:25 PM

Isn't that already called by shell_blank though?

Code:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$pagetitle</title>
$headinclude
</head>
<body>
$header
$navbar

$html

$footer
</body>
</html>


VodkaFish 01-16-2004 04:39 AM

To follow up my own question, I needed this within my code:
Code:

eval('$navbar = "' . fetch_template('navbar') . '";');
I find that weird, since I didn't need the header or footer, etc. but I needed to call the navbar.

However - links, etc. were all wrong since the navbar template isn't pathed correctly (would need to add $vboptions[bburl]/ in many places I'm assuming).

Just thought I'd update.

Zachery 01-16-2004 04:40 AM

yeap you would

Ryan Ashbrook 01-16-2004 03:24 PM

Is it hard to set permissions for a page, if not, how would I do that?

I want to restrict usergroups to this page.


All times are GMT. The time now is 07:09 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.01456 seconds
  • Memory Usage 1,864KB
  • 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
  • (1)bbcode_html_printable
  • (10)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (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