Integration Project For vbAdvanced and Logican's WebTemplates

Integration Project For vbAdvanced and Logican's WebTemplates
by TigerWare
11 Sep 2007 02:43
1 Attachment(s)
Integration Project For vbAdvanced and Logican's WebTemplates

Pre-requisites!

This is the system on which the article was written, I have no idea whether it will work on earlier versions of vBulletin.

* vBulletin 3.6.8
* vbAdvanced CMPS 3.0 RC1
* Logican's WebTemplate CMS 3.6.02


Introduction

What follows is a very simplistic solution to a problem that may face others. I use vbAdvanced CMPS for my main website page, and Logican's WebTemplate CMS for all other static pages. I prefer this because the LWT provides for me a much better platform for the creation of extra pages.

My problem was this. I wanted to share a standard side navigation solution across both products. I am a C# Applications Developer by trade, and I am totally into GUI design. Having identical look and feel across disperate systems is vital for me, and code reuse is also highly important. Anyway, enough with the lecture on geekdom. Simply, I wanted a menu system in both areas to enhance the user experience so they can't see the joins.

So, how to accomplish? I tried different things but could not get the content of a menu system to display in both systems. In the end I went ahead and created an external .js file to solve the issue. It did work, but it was a very rubbish solution. Time to read.

I found a very good article by Kerry-Anne concerning the creation of a simple template, and how to use the plugin system to actually be able to consume the output elsewhere. [How To Include A Custom Template Via Plugins]. This was the turning point of my 3rd day trying to solve this problem. So, big thanks to Kerry-Anne who is now officially my hero.

After a good deal of fumbling, testing, fiddling and hair pulling I discovered that to make this work in a good way, I had to create a template for my own raw HTML content, another template specifically for the vBa specification, which contains a little extra HTML and consumes the content of my first template. Both templates use 2 plugins each, and we are displaying content successfully from a single source accross 2 different products... bonzer!

What we end up with is a solution that has no database changes, no additional files to upload and no code changes. Of course, changes to what is being displayed (in my case a menu) is edited in the template itself; one location, dead simple!

Step By Step

1. Create Template for Logican's WebTemplate

AdminCP >> Styles & Templates >> Style Manager >> Add New Template
Quote:
Title: sitemenu
Template:
HTML Code:
<b>Raw HTML Content!</b>
2. Create 2 Plugins for "sitemenu" Template

AdminCP >> Plugins & Products >> Add New Plugin
Quote:
##Plugin 1##
Product: vBulletin
Hook Location: global_start
Title: Sitemenu LWT - Start
Execution Order: 5 (default)
Plugin PHP Code:
PHP Code:
eval('$sitemenu_plugin = "' . fetch_template('sitemenu') . '";');
Plugin Is Active: Yes
Quote:
##Plugin 2##
Product: vBulletin
Hook Location: cache_templates
Title: Sitemenu LWT - Cache
Execution Order: 5 (default)
Plugin PHP Code:
PHP Code:
$globaltemplates[]='sitemenu';
Plugin Is Active: Yes
3. Displaying Output In Logican's WebTemplate Theme

AdminCP >> Logician's WebTemplates >> WebTemplates >> Edit Theme

It is already assumed that you have an appropriate theme. To display the output from the template created in steps 1 and 2 you would simply type in the variable name at the appropriate place.

HTML Code:
$sitemenu_plugin
4. Create Template for vbAdvanced

We have to create a seperate template for 2 reasons. First, to consume the template in vBa, the title must be prefixed with "adv_portal_" and secondly, the actual template contains some required additional HTML to make it display correctly inside the module (once we create it). As you can see, the variable name we used here is the same one that was displayed directly in LWT, so now we have a template inside a template.

AdminCP >> Styles & Templates >> Style Manager >> Add New Template
Quote:
Title: adv_portal_sitemenu
Template:
HTML Code:
<tr>
<td class="$bgclass">
$sitemenu_plugin
</td>
</tr>
5. Create 2 Plugins for "adv_portal_sitemenu" Template

AdminCP >> Plugins & Products >> Add New Plugin
Quote:
##Plugin 1##
Product: vBulletin
Hook Location: global_start
Title: Sitemenu vBa - Start
Execution Order: 5 (default)
Plugin PHP Code:
PHP Code:
eval('$sitemenu_adv_plugin = "' . fetch_template('adv_portal_sitemenu') . '";');
Plugin Is Active: Yes
Quote:
##Plugin 2##
Product: vBulletin
Hook Location: cache_templates
Title: Sitemenu vBa - Cache
Execution Order: 5 (default)
Plugin PHP Code:
PHP Code:
$globaltemplates[]='adv_portal_sitemenu';
Plugin Is Active: Yes
6. Displaying Output in vbAdvanced CMPS

AdminCP >> vBa CMPS >> Add Module
Quote:
Module Type: Template
Name: Whatever
Active: Yes
Template to Include: adv_portal_sitemenu (prefix not required)
Now you can add the newly created module to the required location on your CMPS Page, and viola! You are displaying the same content as we have already seen.

Summary

Your final step would be to hone the HTML in your LWT Theme to mirror that of your vBa theme, and in my case the positioning of the output from both products has to be pixel perfect, which it is... but that is a whole different article!

At the time of writing I do not have a publically accessible site* to allow a demo of this integration, but I have attached an image to show what the output looks like in both product pages. The area inside the red rectangle is the bit being producted by this technique. On the left is the vBa page and on the right is the LWT page.

* edit Jan-19-2008 - My site is now live so a working demonstration is available here.

I am no vBulletin expert, and I'm pretty sure that there will be other ways to accomplish the same task, but for me this is a solution I'm very proud to have cracked. If this technique is of any use to others, then I'm happy that I have been able to give just a little back, with my thanks to the extended communities that make vBulletin A#1!

Cheers!

****************************

****************************

help with phrases.. what are {1} ??
by !!!cyr0n_k0r
22 Dec 2007 02:15
Code:
There have been <b>{1}</b> post{7} and <b>{2}</b> thread{8} since your last visit at {3}.
The above is part of a phrase. I am trying to use on a non VB page. I have all the correct backend stuff, as everything shows up correctly when calling the phrase, however the things inside {1}, {7} which should be numbers aren't being displayed.

What are these things?
I'm new to coding in VB 3.5.x and have been out of the loop for several years.

Danny.VBT 22 Dec 2007 02:22
It's a wrapper for the sprintf function, basically those are the inputted variables that are inserted into the phrase. The number inside the {} is based on the order of the parameters of the vbphrase function. (Which I can't remember off the top of my head)

construct_phrase() maybe...

!!!cyr0n_k0r 22 Dec 2007 02:48
and where can I find these sprintf functions? Where can they be edited?

Also, why aren't they showing up on a non-VB page when everything else VB related does. I can call for templates and phrases, but these wrappers don't work.

Danny.VBT 22 Dec 2007 03:02
Here is the info:

Quote:
construct_phrase (line 2107)
Construct Phrase
this function is actually just a wrapper for sprintf but makes identification of phrase code easier and will not error if there are no additional arguments. The first parameter is the phrase text, and the (unlimited number of) following parameters are the variables to be parsed into that phrase.

* return: The parsed phrase

string construct_phrase (string 0, mixed 1, mixed 2)

* string 0: Text of the phrase
* mixed 1: First variable to be inserted
* mixed 2: Nth variable to be inserted

You need to call that and add the appropriate values with PHP (A plugin or inside the php file you are using)

!!!cyr0n_k0r 22 Dec 2007 03:25
Thanks!

For people ever having the same issues this is the fix.

Code:
<phrase 1="$pmbox[lastvisitdate]" 2="$pmbox[lastvisittime]">$vbphrase[last_visited_x_at_y]</phrase>
Notice the 1="blah blah"

That would be what is filled into {1}

and so on. :D

--------------- Added 22 Dec 2007 at 03:56 ---------------

Well, it seems some work and some don't. Can anyone shed light as to why the second group of wrappers aren't working?

PHP Code:
<phrase 1="{$bbuserinfo['posts']}">$vbphrase[kor_comments]</phrase><br><br>
<phrase 1="{$numbermembers}" 2="$totalthreads" 3="$totalposts">$vbphrase[kor_forum_stats]</phrase>
The first phrase works fine, the one that calls for $bbuserinfo[posts]

But the second group of stats aren't working. $totalposts, etc.

I have installed the "Welcome Panel Rewrite" hack and the stats work on the index.php, but on my own custom page, they numbers aren't showing up, just the text.

Danny.VBT 22 Dec 2007 04:58
The are not working because they only have scope within the plugins of the Member Rewrite modifications. You are either going to have to duplicate code or create your own variation of it.

!!!cyr0n_k0r 22 Dec 2007 06:04
The hack doesn't modify PHP files or templates though. So how is it that it will work in index.php, but not my page?

What needs to be called to allows those phrases to work?

--------------- Added 22 Dec 2007 at 06:14 ---------------

Also, it can't be the hack, because there is a built in vbulletin variable for total number of members registered.

$numbermembers


However, even when I call that it still isn't working.

Danny.VBT 22 Dec 2007 06:16
Okay, even it they are default vBulletin variables, they are out of scope with your custom script.

!!!cyr0n_k0r 22 Dec 2007 07:13
correct :D

Here is the solution for anyone searching.

PHP Code:
// ### BOARD STATISTICS #################################################

// get total threads & posts from the forumcache
$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
foreach ($vbulletin->forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);

// get total members and newest member from template
$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
// ### BOARD STATISTICS #################################################
Add this code to your custom PHP file.

Also include this:
PHP Code:
require_once(DIR . '/includes/functions_forumlist.php');
cache_ordered_forums(1);
Add that below require global.
 
Back
Top