vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   How to create your own vBulletin-powered page! (uses vB templates) (https://vborg.vbsupport.ru/showthread.php?t=62164)

MrEyes 03-07-2008 11:35 AM

Here is a question:

Using the instructions given it took about 30 seconds to get an additional template driven page into my forum, which was nice :)

Now I am fiddling around trying to get data from the database into a html table in the template and have hit a wall. Just for the sake of testing I am attempting to select all users from a specific user group and display their username in a table.

So to do this after this line:

Code:

$navbits[$parent] = 'Test Page';
I have added

Code:

$userlist = $db->query_read_slave("SELECT userid, username FROM " . TABLE_PREFIX . "user WHERE usergroupid = 2");

while ($user = $db->fetch_array($userlist))
{
        //print_r($user);
}

$db->free_result($userlist);

This gets the data I want and if I uncomment the print_r function it prints the data. However I can't work out how to get the data into a table within the template.

As an example if the select return 2 users (Bob & Dave) I want to render a table that looks like this:

Code:

<table>
        <tr>
                <td>Username</td<
        </tr>
        <tr>
                <td>Bob</td>
        </tr>
        <tr>
                <td>Dave</td>
        </tr>
</table>

Could somebody push me in the right direction?

DivineMessenger 03-07-2008 11:55 AM

Is it against the law to embed other websites into your own? because I got a complaint lol

Mum 03-07-2008 04:46 PM

It's not another website, it's one i own. I own www.mummybrain.com but want to open www.mummybrain.com/tickers/ inside looking like it's vB. Is that the best way to do this? All i really need is just the header, but thought this might be able to do it. But i can't copy and paste all the code, cos then it doesn't work.

Digital Jedi 03-08-2008 04:18 AM

Quote:

Originally Posted by Mum (Post 1459484)
It's not another website, it's one i own. I own www.mummybrain.com but want to open www.mummybrain.com/tickers/ inside looking like it's vB. Is that the best way to do this? All i really need is just the header, but thought this might be able to do it. But i can't copy and paste all the code, cos then it doesn't work.

You could do that with an iframe, but it seems to me the simplest thing to do would be just to put the HTML of that page into your template, and make that page tickers.php.

Quote:

Originally Posted by DivineMessenger (Post 1459239)
Is it against the law to embed other websites into your own? because I got a complaint lol

It's not against the law. It's more like free advertisment. They still get the hit to their website, and your not hotlinking anything.

gdll 03-08-2008 05:35 AM

Does anyone know how to insert $forumbits in test.php so that it will display some threads ??? (or any reason this wouldnt work ?)

edit: seems to be working now.

soundbarrierpro 03-08-2008 06:47 PM

Can I have the php pages set outside the forum root. Basically at the host root?

jambo_1969 03-09-2008 12:18 PM

Amazing !

Works perfectly - even managed to get it into the Navbar

:D

robertpro2a 03-20-2008 03:15 AM

Thank you to the original poster for providing this source code.

I have successfully installed the test page. Is there a way to only allow the test page to load if the user is logged in? I allow guests to browse my forums; but I do not want them to be able to browse my test page.

Regards,
Robert

amcd 03-20-2008 08:12 AM

Quote:

Originally Posted by robertpro2a (Post 1469319)
Thank you to the original poster for providing this source code.

I have successfully installed the test page. Is there a way to only allow the test page to load if the user is logged in? I allow guests to browse my forums; but I do not want them to be able to browse my test page.

Regards,
Robert

Read through the thread. It has been discussed.

dismas 03-27-2008 11:27 PM

I keep running into parse errors for some reason. I don't know why though since I've used this writeup before to add pages to another of my forums. On this other forum, I'm having issues. The forums are with different hosting companies. Would that make a difference?

The first error that I got said that there was a parse error due to an unexpected ~ on line 4. I took the tilde out and then it told me this:

Code:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/v/e/r/vermontoutdoor/html/forum/writeups.php on line 8
Line 8 is the last line here:

Code:

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'writeups'); // change this depending on your filename


Lynne 03-27-2008 11:43 PM

Quote:

Originally Posted by dismas (Post 1476315)
I keep running into parse errors for some reason. I don't know why though since I've used this writeup before to add pages to another of my forums. On this other forum, I'm having issues. The forums are with different hosting companies. Would that make a difference?

The first error that I got said that there was a parse error due to an unexpected ~ on line 4. I took the tilde out and then it told me this:

Code:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/v/e/r/vermontoutdoor/html/forum/writeups.php on line 8
Line 8 is the last line here:

Code:

//+####################+DEFINE+IMPORTANT+CONSTANTS+#######################
define('NO_REGISTER_GLOBALS',+1);
define('THIS_SCRIPT',+'writeups');+//+change+this+depending+on+your+filename


Um....
define('THIS_SCRIPT',+'writeups');+//+change+this+depending+on+your+filename

You've got a + after the ; and before the // You can't do that. And I don't know about the + before 'writeups' either.

dismas 03-27-2008 11:59 PM

Actually, I have no idea where the + came from. I did a straight copy/paste and the + is not in there.

Lynne 03-28-2008 02:59 AM

Quote:

Originally Posted by dismas (Post 1476327)
Actually, I have no idea where the + came from. I did a straight copy/paste and the + is not in there.

What are you using to edit the page? You need to use something like bbedit/notepad not word. If you don't use a plain text editor, then it could be adding extra characters which would then cause the problems you are seeing.

dismas 03-28-2008 03:49 AM

Actually, it's funny that you say that since it is BBEdit that I used. I even tried copying and pasting the php from this thread into a text document in TextEdit and still, the same errors came up.

Lynne 03-28-2008 02:32 PM

Quote:

Originally Posted by dismas (Post 1476469)
Actually, it's funny that you say that since it is BBEdit that I used. I even tried copying and pasting the php from this thread into a text document in TextEdit and still, the same errors came up.

So you copy/pasted what was in the first post into a page and tried it on that site and you got the errors?

(Is this thread the best place to discuss this or would it be better off in it's own thread where more people can come and help?)

dismas 03-28-2008 03:52 PM

Nevermind... I don't know what I have set different but it's the version of BBEdit that is screwing this up somehow. (Although I'm not sure why I got the same results with TextEdit)

What I was doing last night was on my MacBook.

I just tried to create the custom page again on my G4 tower and it worked fine. The G4 has BBEdit version 7 on it while the MacBook as the updated ver. 8.

Well, it's either that or my FTP software is doing something funky... Both of the computers have the same version of that but maybe one is sending the file in a different manner...

Either way, this is my issue to fix... Sorry for wasting everyone's time.

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

Quote:

Originally Posted by VeoMorphine (Post 483072)

PHP Code:

<?php

require_once('./global.php');

if (
$_REQUEST[filename])
{
    if (
is_member_of($bbuserinfo6) OR is_member_of($bbuserinfo5) OR is_member_of($bbuserinfo7));
    {
        
header("Location: $_REQUEST[filename]");
    }
}

?>

that makes it so usergroup 6 5 and 7 can download that file.

Oh, one more question... Where would this code segment go? Would it just replace this part:
Code:

require_once('./global.php');

RetroDreams 03-30-2008 12:28 AM

How do you adapt this article to add queries and pull data from the database? Is there an additional article out there? I've searched but came up empty.

Opserty 03-30-2008 11:46 AM

Quote:

Originally Posted by RetroDreams (Post 1478001)
How do you adapt this article to add queries and pull data from the database? Is there an additional article out there? I've searched but came up empty.

You just add the PHP you need to the PHP page...

RetroDreams 03-30-2008 04:54 PM

Yeah, I end up figuring it out with trial and error. My problem was I didn't realize you needed a separate template for looping but I got it squared away.

dfc005 04-02-2008 10:44 AM

So, I'm thinking of implementing this into my forum but I have a question, do you have to edit any vbulletin files to make this work? Or is it just templates and then creating my own php files?

amcd 04-02-2008 11:43 AM

Quote:

Originally Posted by dfc005 (Post 1480763)
So, I'm thinking of implementing this into my forum but I have a question, do you have to edit any vbulletin files to make this work? Or is it just templates and then creating my own php files?

just templates and new php

dfc005 04-02-2008 08:29 PM

In the instructions it says I have to open up includes/functions_online.php and edit to enable Who's Online. Isn't that a file?

Sorry if these are stupid questions.

lukemax 04-02-2008 09:04 PM

1 Attachment(s)
I have like 30 lines of php code which I want inside the box instead of Text. How do I make it so that I can have the template read my php code? (Take a look at the template I created), how do I get the php to be executed?

dfc005 04-02-2008 11:17 PM

Quote:

Originally Posted by lukemax (Post 1481345)
I have like 30 lines of php code which I want inside the box instead of Text. How do I make it so that I can have the template read my php code? (Take a look at the template I created), how do I get the php to be executed?

I was coming here to ask the same thing. Need to use a plugin don't we?

But what hook do I use?

lukemax 04-03-2008 03:23 AM

I know the global_start hook location works, but I think there is a way around the hook/plugin system.

dfc005 04-03-2008 03:36 AM

Yeah, I was pretty sure global_start would work but thought there might be a better hook location, don't want the piece of code being executed for every page call....

lukemax 04-03-2008 03:57 AM

ea, same here. I'm trying to figure out a way to do this without using the hook thing, if I find it, ill let you know, k?

dfc005 04-03-2008 04:05 AM

Cheers mate, that'd be great.

The powered pages are exactly what I'm after but if I can't include a bunch of PHP code in the actual templated, they are pretty useless to me.

amcd 04-03-2008 04:09 AM

You dont have to edit any vbulletin php file to make new pages work. Who's online can be done using hooks.

php code is not supposed to be written in templates.

Hooks are needed only if you want to insert code into the existing pages. This thread is about creating new pages.

The idea is to have a new page. See the countries page on my site for example.

For a general explanation of how templates and hooks work, see the vbulletin manual.

lukemax 04-03-2008 04:22 AM

is this what you used http://www.vbulletin.com/docs/html/m..._externalfiles ?

What hook location did you use?
Thanks...

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

Also, did you create a custom template, like this tutorial?

amcd 04-03-2008 04:28 AM

Quote:

Originally Posted by lukemax (Post 1481638)
is this what you used http://www.vbulletin.com/docs/html/m..._externalfiles ?

What hook location did you use?
Thanks...

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

Also, did you create a custom template, like this tutorial?

That approach is different. It is suitable for cases where you want to include a bit of your own stuff in the default vbulletin pages, and where you are unable to modify the other php file.

This thread is about creating a completely new page using the vbulletin framework, with vbulletin's header, navbar and footer.

lukemax 04-03-2008 04:31 AM

I'm trying to import this table (like your countries one)
http://www.lvasp.com/providers_hook.php
into
http://www.lvasp.com/forum/providers.php

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

What tutorial did you follow to create your page then? (cause thats what I'm trying to emulate)
Thanks, and sorry for being thick-headed.

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

I'm looking at the vbulletin manual and I cant seem to find a tutorial for a page like yours.

amcd 04-03-2008 04:58 AM

I followed this tutorial to create the countries page. Hooks did not exists when this article was written (March 2004). Therefore, you can be certain that hooks are not needed for the page itself (apart from the fact that I am telling you).

The article tells you to edit original php files for "Who's online". In newer vbulletin versions, we can do this through hooks.


Your provider.php is fine. I suppose you are following test.php from the article in this file. Note the part where it says "START MAIN SCRIPT". The code from providers_hook.php will go here.

How are you displaying the output from providers_hook.php? The vbulletin method is to calculate all the variables and then call a template. In the article, the template is called test. Everything between $navbar and $footer in this template is your custom stuff.

If there are any loops in the page (such as a table with multiple rows, like my countries page), then you have to create an additional template - the bit template. Default vbulletin has many examples of this - postbit, threadbit, reputationbit, forumbit etc etc. Within your php code, you must have a loop and within that you call the 'bit' template and store the result into a variable. In the main template for the page, you just put the variable where you want that table.

Here is my countries template for reference (I call it countries_countries, meaning that its the main template of the countries page).
Code:

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

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" align="center">
<tr>
    <td class="tcat">
        Country Code
    </td>
    <td class="tcat">
        Currently Online
    </td>
    <td class="tcat">
        Country Name
    </td>
    <td class="tcat">
        Continent
    </td>
</tr>
$showlistbits
</table>

$footer
</body>
</html>

And here is the countries_countrybit template.
Code:

<tr>
    <td class="$altclass">
        $country[country]
    </td>
    <td class="$altclass">
        $country[tot]
    </td>
    <td class="$altclass">
        $country[printable_name]
    </td>
    <td class="$altclass">
        $country[continent]
    </td>
</tr>

The code from countries.php looks like this:
Code:

<?php
/*======================================================================*\
|| #################################################################### ||
|| # countries.php                                                    # ||
|| # ---------------------------------------------------------------- # ||
|| # for displaying a list of number of logged in users by country    # ||
|| # ---------------------------------------------------------------- # ||
|| # by GodFather                                    15-October-2007 # ||
|| #################################################################### ||
\*======================================================================*/

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

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'countries');

// ################### 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(
    'countries_countries',
    'countries_countrybit'
);

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

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

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

// ### STANDARD INITIALIZATIONS ###
$showlistbits = '';
$altclass = 'alt1';

// ############################### show list of countries ###############################
$countries = $db->query_read("
    SELECT s.country, count(*) as tot, c.printable_name, c.continent
    FROM " . TABLE_PREFIX . "session s
    JOIN " . TABLE_PREFIX . "country c ON s.country=c.iso
    GROUP BY s.country
    ORDER BY printable_name ASC
");
while ($country = $db->fetch_array($countries))
{
    $altclass = ($altclass=='alt1') ? 'alt2' : alt1;
    eval('$showlistbits .= "' . fetch_template('countries_countrybit') . '";');
}

$navbits = array();
$navbits[$parent] = "Who's Online by Countries";
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('countries_countries') . '");');

/*======================================================================*\
|| ####################################################################
|| #
|| ####################################################################
\*======================================================================*/
?>

Hope that helps.


p.s.: The code above is unaltered, but its not usable because you also need supporting code which stores the countries data in the session table.

lukemax 04-03-2008 06:28 AM

ok (thanks soo much for your help thus far) Here is my PROVIDERS template
Code:

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

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">Providers</td>
</tr>
<tr>
<td class="panelsurround">
<div class="panel">
<table width='70%' cellpading=7 border=1 bordercolor='black' rules='rows' align='center'>
<tr><th width='120px' class='tcat'>Thumbnail</th>
<th align='left' class='tcat'>Name</th></tr>
$providers_providerbit
</table>
</div>
</td>
</tr>
</table>

$footer
</body>
</html>

Here is the providers_providerbit template
Code:

if(empty($provider[featured_pic])) {
$thumb_nail = "<img src='/images/ASP_Images/thumbs/default.jpg' border='0' />";
} else {
$thumb_nail = '<img src="'.$provider[featured_pic].'" alt="'.$provider[Name].'" border="0" />';
}
<tr>
<th class="$altclass">
<a href="/provider_page.php?ID=$provider[ID]">$thumb_nail</a>
</th>
<th class="$altclass" align="left">
<a href="/provider_page.php?ID=$provider[ID]" class="link">$provider[Name]</a>
</th></tr>

Lastly, heres my providers.php
Code:

<?php

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

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'providers'); // 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(
    'PROVIDERS',
        'providers_providerbit'
);

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

);

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

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

// ### STANDARD INITIALIZATIONS ###
$showlistbits = '';
$altclass = 'alt1';

//is it ok to include these variabl;es here
// how many rows to show per page
$rowsPerPage = 20;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

// ############################### show list of providers ###############################
$providers = $db->query_read("
    SELECT Approve, ID, Name, featured_pic
        FROM provider
        WHERE Approve = '1'
        ORDER BY rand()
        LIMIT $offset, $rowsPerPage
");
while ($provider = $db->fetch_array($providers))
{
    $altclass = ($altclass=='alt1') ? 'alt2' : alt1;
    eval('$showlistbits .= "' . fetch_template('providers_providerbit') . '";');
}

$navbits = array();
$navbits[$parent] = 'Providers';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('PROVIDERS') . '");');
?>

Did I make an error?

dfc005 04-03-2008 10:15 AM

amcd, thanks for that. Makes complete sense.

Reckon you could give us the heads up on how we do the hooks for "Who's online"?

Cheers!

lukemax 04-03-2008 04:22 PM

GOT it, thanks

asandhanam 04-03-2008 09:50 PM

I'm trying to create a page within a folder called 'template' in the forum root.
[root]/template/test.php. I tried this method, it worked fine as long as the pages were in the root. What changes do i need to do to make it work when inside 'template' folder in the root.?

acegames 04-05-2008 02:05 PM

Is there an update for 3.70 I need to add online location

CrashPush 04-05-2008 07:20 PM

Quote:

Originally Posted by acegames (Post 1483571)
Is there an update for 3.70 I need to add online location

You want to show the page the user is viewing in the 'Who's Online' page?

amcd 04-05-2008 07:51 PM

Quote:

Originally Posted by dfc005 (Post 1481843)
amcd, thanks for that. Makes complete sense.

Reckon you could give us the heads up on how we do the hooks for "Who's online"?

Cheers!

hook online_location_process:
Code:

switch ($filename)
{
    case 'countries.php':
        $userinfo['activity'] = 'countries';
        break;
// add more cases here if you have more than one custom page. no need for multiple plugins. one plugin can handle all.
}


hook online_location_unknown
Code:

switch ($userinfo['activity'])
{
    case 'countries':
        $userinfo['where'] = '<a href="countries.php?'.$vbulletin->session->vars[sessionurl].'">Viewing the countries page</a>';
        $userinfo['action'] = "Who's Online by Country";
        $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.



All times are GMT. The time now is 03:28 PM.

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.05514 seconds
  • Memory Usage 1,884KB
  • 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
  • (16)bbcode_code_printable
  • (1)bbcode_php_printable
  • (13)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)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