Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2012, 04:20 AM
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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:
Code:
{vb:raw ad_location.board_inside_forum_listing}

The first line of ForumbitLev2 uses the forum ID:
Code:
{vb:raw forum.forumid}
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:
Code:
{vb:raw forum.forumid}
{vb:var forum.forumid}

<vb:if condition="$vbulletin->GPC['forumid'] == 10">
Has Value
</vb:if>

<vb:if condition="$vbulletin->GPC['forumid']">
Has Value
</vb:if>

{vb:var global}

{vb:var templater->forumid}

Values were displayed for these:
Code:
<img src="images/forum_logos/forum_10.png">

Plain Text

{vb:var vbulletin->forumcache['10']['forumid']} // displayed "10" next to each forum name

-----------------------------------------
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:
Code:
ob_start();
  require_once('includes/forum_id_hook_forumbit_display.php');
  $marbuzz_forumbit_display_hook = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('ad_board_inside_forum_listing',array('marbuzz_forumbit_display_hook' => $marbuzz_forumbit_display_hook));

Here's the contents of forum_id_hook_forumbit_display.php:
Code:
$marbuzz_forumbit_display_hook['forum_id'] = $forumid;
return $marbuzz_forumbit_display_hook;

I tried the following in my InsideListing template:
Code:
<vb:if condition="$marbuzz_forumbit_display_hook['forum_id']">
Has Value
</vb:if>

{vb:var marbuzz_forumbit_display_hook.forum_id}
{vb:raw marbuzz_forumbit_display_hook.forum_id}
TEST
Only the word "TEST" appeared next to each forum name.

Any thoughts?
Reply With Quote
  #2  
Old 06-08-2012, 09:31 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:

Code:
$template = vB_Template::create('board_inside_forum_listing');
$template->register('forumid', $forumid);
$template->render(); // of course you'd assign the result of this to something...

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: https://vborg.vbsupport.ru/showthread.php?t=228078
Reply With Quote
  #3  
Old 06-08-2012, 03:44 PM
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:

Code:
array_push($globaltemplates, 'ad_board_inside_forum_listing');
$ad_location['board_inside_forum_listing'] = vB_Template::create('ad_board_inside_forum_listing')->render();

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:
Code:
<vb:if condition="$forumid == 10">  //10 stands for the forum ID, it would vary depending on which forum row the image should appear in.
Display Image
</vb:if>
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.

Code:
$template = vB_Template::create('ad_board_inside_forum_listing');
$template->register('forumid', $forumid);
$forum['board_inside_forum_listing'] = $template->render();
I tested it using the following as the contents of the ad_board_inside_forum_listing template:

Code:
{vb:var forumid}
{vb:raw forumid}
<vb:if condition="$forumid == 25">Show this if forum id is 25</vb:if>

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 06-08-2012, 04:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would think this code (copied from above) using the forumbit_display hook should work:

Code:
$template = vB_Template::create('ad_board_inside_forum_listing');
$template->register('forumid', $forumid);
$forum['board_inside_forum_listing'] = $template->render();

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?
Reply With Quote
  #5  
Old 06-08-2012, 05:19 PM
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 [DATE]1339184649[/DATE] at [TIME]1339184649[/TIME] ---------------

One more time.

Here is my plugin code:
Code:
ob_start();
  require_once('includes/plugin_marbuzz_insert_block_hook_forumhome_start.php');
  $marbuzz_insert_block_forumhome_start = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('ad_board_inside_forum_listing',array('marbuzz_insert_b
Here is the code in the file called by the plugin:
Code:
array_push($globaltemplates, 'ad_board_inside_forum_listing');
$template = vB_Template::create('ad_board_inside_forum_listing');
$template->register('forumid', $forumid);

$ad_location['board_inside_forum_listing'] = $template->render();
OR
$forum['board_inside_forum_listing'] = $template->render();

print $forumid;
echo $forumid;
Here is the code in my template named "ad_board_inside_forum_listing":
Code:
test
{vb:var forumid}
{vb:raw forumid}
<vb:if condition="$forumid == 25">Show this if forum id is 25</vb:if>

{vb:var marbuzz_forumbit_display_hook}
{vb:raw marbuzz_forumbit_display_hook}
<vb:if condition="$marbuzz_forumbit_display_hook== 25">Show this if forum id is 25</vb:if>
Here's the code I place in "forumhome_forumbit_level2_post" and the other forumbit files:
Code:
{vb:raw ad_location.board_inside_forum_listing}
OR
{vb:raw forum.board_inside_forum_listing}
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
Reply With Quote
  #6  
Old 06-08-2012, 07:28 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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 06-08-2012, 08:05 PM
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Quote:
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
Reply With Quote
  #8  
Old 06-08-2012, 11:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Glad you got it figured out.

Quote:
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
Благодарность от:
codewaggle
  #9  
Old 06-10-2012, 08:51 AM
codewaggle codewaggle is offline
 
Join Date: Dec 2011
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Code:
$template = vB_Template::create('ad_board_inside_forum_listing');
$template->register('forumid', $forumid);
$cw_forumbit_global_with_id['board_inside_forum_listing'] = $template->render();
$GLOBALS[cw_forumbit_global_with_id] = $cw_forumbit_global_with_id;

UPDATE: (Thanks to kh99 for his guidance.)
The following line isn't needed and was used incorrectly:
$template->register_global('cw_forumbit_global_with_id');

Then in the forumbit templates I used:
Code:
{vb:raw GLOBALS.cw_forumbit_global_with_id.board_inside_forum_listing}

Be Well
Reply With Quote
  #10  
Old 06-10-2012, 11:19 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 08: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.04784 seconds
  • Memory Usage 2,289KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (19)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete