Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 08 Jun 2012, 06:20
codewaggle codewaggle is offline
 
Join Date: Dec 2011
forumbit Template - How to Get Forum ID For Use In Included Template?

Hi,

I created a product based on the existing Advertising functionality. I added a slot next to each forum name on the forum.php page.

I'm able to display an image next to each forum name, but I'd like to show different images for different forum ID's.

---------------------------------
I created a template called board_inside_forum_listing (InsideListing).

InsideListing is loaded into the forumhome_forumbit_level2_post (ForumbitLev2) template. like this:

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


The first line of ForumbitLev2 uses the forum ID:

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

So I tried using that in InsideListing, but no output. Here are some samples of what I tried using in the InsideListing template:

Nothing displayed with any of these:

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


Values were displayed for these:

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


-----------------------------------------
I've also tried creating a plugin using the the forumbit_display hook. Seemed like a good location because the code for each forum is rendered just after that.

Here's my plugin code:

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


Here's the contents of forum_id_hook_forumbit_display.php:

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


I tried the following in my InsideListing template:

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

Only the word "TEST" appeared next to each forum name.

Any thoughts?
Reply With Quote
  #2  
Old 08 Jun 2012, 11:31
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
In your board_inside_forum_listing template, you can only use variables that have been registered to it (or certain variables that are registered automatically). You don't show the code where you rendered your template, but I assume somewhere you have something like:


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


you'd want to add a register line in the middle to register the forumid (I'm not sure if $forumid would be the right variable - it depends where you're registering it). Then in board_inside_forum_listing you could use {vb:raw forumid}, or $forumid in a condition.


The second example you show might have worked, but the ob_start()/ob_end_clean() thing captures the output of any code that's between it, and yours didn't output anything. But that code is from an example of how to include an external php file that outputs some html (for instance), so that isn't what you want to use for your siutuation.

If you haven't seen this article yet, it might help: http://www.vbulletin.org/forum/showthread.php?t=228078
Reply With Quote
  #3  
Old 08 Jun 2012, 17:44
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Thanks for your assistance,

I forgot to include the full info about my board_inside_forum_listing template.

I used the native Advertising functionality as a starting point, I copied and modified these files:
/admincp/ad.php => /admincp/marbuzz_insert_block.php
/includes/functions_ad.php => /includes/functions_marbuzz_insert_block.php
/includes/xml/ad_locations_vbulletin.xml => /includes/xml/block_locations_marbuzz_insert_block.xml

I basically just changed the db table references (I copied the tables used by the Ad functionality) and the names of the templates that are loaded to display the bloack of code.

So on the forum.php page, Ads uses these templates: board_after_forums and board_below_whats_going_on, I'm using board_inside_forum_listing.

I created a plugin (marbuzz_forumhome_start_hook.php) that uses the forumhome_start hook (I can't use the forumhome_complete hook, because it occurs after $forumbits is constructed), that's where I render the template, the plugin code is:


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


When that template is rendered, I don't want to key on the variable I need (forum ID), because the forum ID isn't available then.
When forum.php is rendered, the construct_forum_bit function is run near the end, it creates each forum entry that's displayed.

construct_forum_bit() uses the forumhome_forumbit_level2_post template to create forum entries for display (there are a few templates used depending on forum level and posts).
My ad_board_inside_forum_listing template is loaded inside the forumhome_forumbit_level2_post template, I need to key on the ID of the forum whose entry is being created.

So I'd like the ad_board_inside_forum_listing template to contain a reference to the forum ID, like this:

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

At the end of the forum.php code, the ad_location and forumbits template arrays (among others) are registered for use within the FORUMHOME template and the page is rendered.

--------------------------------------------------------------

I just tried a different approach, I used the forumbit_display hook near the end of the construct_forum_bit function. I registered the forumid variable as you suggested and used the $forum array that is registered when each forum entry is created.


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

I tested it using the following as the contents of the ad_board_inside_forum_listing template:


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


It worked somewhat, I can access the current forumid, but it's only displayed in the row for the first forum listing.

I'm trying to render the ad_board_inside_forum_listing template once for each forum in the loop, can templates be rendered multiple times or only once (explaining the single output in this test)?

Be Well
Reply With Quote
  #4  
Old 08 Jun 2012, 18:25
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
I would think this code (copied from above) using the forumbit_display hook should work:


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


but I assume that 3rd line should be $ad_location['board_inside_forum_listing']. Yes, you can render a template more than once, so it should work. I don't see offhand why it's only displaying in the first line. Are you seeing the 2 forum id numbers from the first two lines in your template? Are you sure they're all using the level2 forumbit template?

Last edited by kh99; 08 Jun 2012 at 21:17. Reason: fixed "this this"
Reply With Quote
  #5  
Old 08 Jun 2012, 19:19
codewaggle codewaggle is offline
 
Join Date: Dec 2011
The first forum was ID 25, so all three lines in my template worked, I saw:
25 25 Show this if forum id is 25

I added the include to all four forumbit templates:
forumhome_forumbit_level2_post
forumhome_forumbit_level2_nopost
forumhome_forumbit_level1_post
forumhome_forumbit_level1_nopost

But the output only appeared next to the first forum listing.

For the include, I used the ad_location array when using the hook on forum.php because it was registered there:
$ad_location['board_inside_forum_listing']

I used the forum array when I used the forumbit_display hook because the forum array was being registered there:
$forum['board_inside_forum_listing']


I'll try using the ad_location array while using the forumbit_display hook and check through my code for mistakes.

Be Well

--------------- Added 08 Jun 2012 at 20:44 ---------------

One more time.

Here is my plugin code:

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

Here is the code in the file called by the plugin:

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

Here is the code in my template named "ad_board_inside_forum_listing":

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

Here's the code I place in "forumhome_forumbit_level2_post" and the other forumbit files:

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

Case A:
Use the forumhome_start hook and the $ad_location variable. The text appears next to each forum name, no ID.

Case B:
Use the forumbit_display hook and the $ad_location variable. Nothing appears.

Case C:
Use the forumbit_display hook and the $forum variable. THe Text and ID appears next to the name of the first forum only.

I tried echoing and printing the ID and then using the plugin variable "marbuzz_insert_block_forumhome_start" to display it, but nothing there.

Any idea why it doesn't work past the first forum?
Be Well

Last edited by codewaggle; 08 Jun 2012 at 20:52.
Reply With Quote
  #6  
Old 08 Jun 2012, 21:28
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by joe-marinas View Post
For the include, I used the ad_location array when using the hook on forum.php because it was registered there:
$ad_location['board_inside_forum_listing']

I used the forum array when I used the forumbit_display hook because the forum array was being registered there:
$forum['board_inside_forum_listing']
That's OK then, you can use $forum. Sorry I added to the confusion.

I still don't see why it would appear only once. Maybe I'll try some of it and if I figure out anything I'll let you know (or maybe someone else will see the problem).
Reply With Quote
  #7  
Old 08 Jun 2012, 22:05
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Got It!

I used require_once() when I created the plugin. I changed it to require() and it displays next to all of the forums.

Now I need to figure out how to store and process multiple versions of the ad_board_inside_forum_listing template so I can display different images next to different forums.
Edit: This is already done in the ad code, I just need to add my own criteria for the forum home listings.

In your first post, you said:
Originally Posted by kh99 View Post
(or certain variables that are registered automatically)
Is there a list of the variables that are registered automatically?


Thanks for your help, it gave me a better understanding of how things work.

Be Well

Last edited by codewaggle; 08 Jun 2012 at 23:26. Reason: Update and add question
Reply With Quote
  #8  
Old 09 Jun 2012, 01:00
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Glad you got it figured out.

Originally Posted by joe-marinas View Post
Is there a list of the variables that are registered automatically?

From includes/class_core.php, around line 4568, these variable are registered for you:

$vbulletin->userinfo (as 'bbuserinfo')
$vbulletin->options (as 'vboptions')
$vbulletin->session->vars (as 'session')
$vbphrase
$vbcollapse
$ad_location
$style
$show
$template_hook

There are a few other special cases, but you probably don't care about those.
Reply With Quote
  #9  
Old 10 Jun 2012, 10:51
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Your pointer to the register_globals() function came in handy. I used what I learned to register my template globally for use in all four "forumhome_forumbit_levelx_xxx" templates.

I used this in the file called by my plugin:

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


Then in the forumbit templates I used:

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


Be Well

Last edited by codewaggle; 10 Jun 2012 at 17:03.
Reply With Quote
  #10  
Old 10 Jun 2012, 13:19
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
I didn't mention register_globals() - I don't think that's something you normally want to call directly.

GLOBALS.name seems to work to access a global even if you don't registered it. So I suppose you could say that $GLOBALS[] is also "registered" by default.

Last edited by kh99; 10 Jun 2012 at 13:27.
Reply With Quote
  #11  
Old 10 Jun 2012, 16:33
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Originally Posted by kh99 View Post
Glad you got it figured out.
From includes/class_core.php, around line 4568, these variable are registered for you:
$vbulletin->userinfo (as 'bbuserinfo')
... Contents removed for brevity ...
$vbphrase
$vbcollapse
... Contents removed for brevity ...
$template_hook
There are a few other special cases, but you probably don't care about those.
Originally Posted by kh99 View Post
I didn't mention register_globals() - I don't think that's something you normally want to call directly.

GLOBALS.name seems to work to access a global even if you don't registered it. So I suppose you could say that $GLOBALS[] is also "registered" by default.
In your previous post, you kind of mentioned register_globals(). You pointed out that certain variables are registered automatically and where in the code it happens. The variables you pointed out are registered in the register_globals() function. Within that function the register_global() (no "s") function is called:
$this->register_global('vbphrase');
$this->register_global('vbcollapse');

I was using the register_global() (no "s") function incorrectly. I was thinking it made a reference to the variable available globally, but as you point out, that's what $GLOBALS does anyway.


Thanks again for the help

-------------------------------------------

For anyone reading this after us:

register_globals() is called with the purpose of registering certain variables within the scope of the particular template being rendered (they are already in the $GLOBALS array). Basically, it does a $templater->register(), but it passes the global variable by reference so that it will have the latest value when used rather than the value it held when it was registered. The final result is:

$templater->registered['vbphrase'] =& $GLOBALS['vbphrase'];

In the end, the difference between using register_globals() and not is the way you reference a variable within the template as it's being rendered.

Using register_globals():
{vb:raw vbphrase.monday}

Not using register_globals():
{vb:raw GLOBALS.vbphrase.monday}

Be Well
Reply With Quote
  #12  
Old 10 Jun 2012, 17:10
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Ah, I see - that does make sense. And it probably is good for readability, if nothing else, to explicitly register the variables you use.
Reply With Quote
Reply



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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 03:27.

Layout Options | Width: Wide Color: