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 08-12-2010, 03:49 PM
AfterWorldForum AfterWorldForum is offline
 
Join Date: Dec 2008
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vB4 plugin problem - Not showing in profile

Hi everyone,

My forum uses the opt-out forums modification which enables users to select certain (sub) forums from showing up on their "New posts" searches. We're upgrading to vB4 during the weekend, but the mod has not been converted for vB4 yet.

I have attempted converting it myself, in order to ensure my users can continue using the functionality offered by it, but seem to be running into some trouble with getting it to show up. I am hoping someone here might be able to help me figure out where I am going wrong.

Let's have a look at the plugin code first. It's been set to the hook profile_editoptions_start:

Code:
function fetch_optout_forumids_array($parentid = -1, $depthmark = '')
{
	global $optoutforumids, $vbulletin;
	static $indexed_forum_cache;

	if ($parentid == -1)
	{
		$optoutforumids = array();
		$indexed_forum_cache = array();
		foreach ($vbulletin->forumcache AS $forumid => $forum)
		{
			$indexed_forum_cache["$forum[parentid]"]["$forumid"] =& $vbulletin->forumcache["$forumid"];
		}
	}

	if (is_array($indexed_forum_cache["$parentid"]))
	{
		foreach ($indexed_forum_cache["$parentid"] AS $forumid => $forum)
		{
			$forumperms =& $vbulletin->userinfo['forumpermissions']["$forumid"];
			if ($forum['displayorder'] != 0
				AND ($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])
				AND ($forumperms & $vbulletin->bf_ugp_forumpermissions['cansearch'])
				AND ($forumperms & $vbulletin->bf_ugp_forumpermissions['canoptoutgnp'])
				AND ($forum['options'] & $vbulletin->bf_misc_forumoptions['active'])
				AND verify_forum_password($forum['forumid'], $forum['password'], false)
			)
			{
				$vbulletin->forumcache["$forumid"]['depthmark'] = $depthmark;
				$optoutforumids[] = $forumid;
				fetch_optout_forumids_array($forumid, $depthmark . FORUM_PREPEND);
			}
		}
	}
} 	
fetch_optout_forumids_array();
$optoutforumbits = '';
$haveforum = false;
$gnpoptoutforums = explode(',', $vbulletin->userinfo['excludeforumsgnp']);

foreach ($optoutforumids AS $forumid)
{
	$forum =& $vbulletin->forumcache["$forumid"];

	if (trim($forum['link']))
	{
		continue;
	}

	$optionvalue = $forumid;
	$optiontitle = "$forum[depthmark] $forum[title_clean]";
	$optionclass = 'fjdpth' . (($forum['depth'] > 4) ? '4' : $forum['depth']);

	if (in_array($forumid, $gnpoptoutforums))
	{
		$optionselected = 'selected="selected"';
		$haveforum = true;
	}
	else
	{
		$optionselected = '';
	}

	$templater = vB_Template::create('option');
	$templater->register('optionvalue', $optionvalue);
	$templater->register('optiontitle', $optiontitle);
	$templater->register('optionclass', $optionclass);
	$templater->register('optionselected', $optionselected);
	$templater->register('show', $show);
	$optoutforumbits = $templater->render();
}
$show['optoutgnp'] = sizeof($optoutforumids) > 0;
And this is the changes made to the option template (right below {vb:raw customfields.other})
Code:
<div class="blockrow">

   <legend>{vb:phrase exclude_forums_from_gnp}</legend>
   	<div><phrase>{vb:phrase exclude_forums_from_gnp_desc, {session.sessionurl}}</phrase></div>
   	<label for="sel_optoutgnp">{vb:phrase exclude_forums}:</label>
   	<select style="width: 100%" size="13" name="optoutgnp[]" id="sel_optoutgnp" multiple="multiple">
   		<option value="">{vb:phrase none}</option>
		{vb:raw optoutforumbits}
   	</select>
</div>
It looks alright to me, but I cannot see anything happening whenever I go to my profile and select the settings. Any ideas, please?

Thanks in advance

Peter
Reply With Quote
  #2  
Old 08-12-2010, 10:49 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You will need to register (preregister) the variable for use in that template. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
Reply With Quote
  #3  
Old 08-13-2010, 04:17 AM
AfterWorldForum AfterWorldForum is offline
 
Join Date: Dec 2008
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Lynne, and thanks for responding.

The article has been very helpful before, so I definitly used it while converting the rest of my forum. I think I did try the preregister before.

I changed the code just now and tested, but I still cannot see the list I am expecting. Using debug mode, I can see that the option template is being loaded, and that it is actually processed a few times (which would make sense, seeing it loops through the whole list of forums and is supposed to add a line for every forum), but nothing is being rendered.

This seriously has had me stumped for a while now, hence trying to see if anyone would be able to offer some help here. Sometimes one overlooks somethign incredibly simple, and a few other eyes easily will spot the error. Alternatively, are there any good tutorials on writing plugins for vB4 anywhere?
Reply With Quote
  #4  
Old 08-13-2010, 04:54 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And what code are you using to preregister it and where?
Reply With Quote
  #5  
Old 08-13-2010, 02:54 PM
AfterWorldForum AfterWorldForum is offline
 
Join Date: Dec 2008
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
And what code are you using to preregister it and where?
Hi Lynn,

The block of code dealing with the template now looks like this:

Code:
    $templater = vB_Template::create('mytemplate'); 
    $templater->register('optionvalue', $optionvalue); 
    $templater->register('optiontitle', $optiontitle); 
    $templater->register('optionclass', $optionclass); 
    $templater->register('optionselected', $optionselected); 
    $templater->register('show', $show); 
    $templatevalues['$optoutforumbits'] = $templater->render(); 
    vB_Template::preRegister('option', $templatevalues);
I also tried using $templater = vB_Template::create('option'); by the way. Also no luck.

The only other change I made was to replace $vbulletin->userinfo with $bbuserinfo. Other than that, the code is the same as above.
Reply With Quote
  #6  
Old 08-13-2010, 07:51 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

According to your code, you preregistered to use a variable called "option", but that variable isn't in your template at all.
Reply With Quote
  #7  
Old 08-14-2010, 08:38 AM
AfterWorldForum AfterWorldForum is offline
 
Join Date: Dec 2008
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
According to your code, you preregistered to use a variable called "option", but that variable isn't in your template at all.
Hi Lynne,

That does not seem to correspond to the article by Cellarius, or this article.

I take these to mean that the first variable is the name of the template to preregister the variable for. In my case, that is option (I think. I want it in the Settings (Formerly known as User CP) / General Settings).

However, I did notice that I left in a dollarsign in front of the optoutforumbits line prior to the preRegister. Fixing that, however, did nothing to improve the situation
Reply With Quote
  #8  
Old 08-14-2010, 02:34 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Whoops, I read that wrong. But, this is the format I use to preregister variables (my cheatsheet blurb below):

PHP Code:
vB_Template::preRegister('FORUMHOME', array('uid' => $uid)); 
Now you can use {vb:raw uid} in the FORUMHOME template

According to what you wrote above (without extra $):
Code:
    $templatevalues['optoutforumbits'] = $templater->render(); 
    vB_Template::preRegister('option', $templatevalues);
The variable you would be using in the template would be {vb:raw templatevalues.optoutforumbits}
Reply With Quote
  #9  
Old 08-16-2010, 04:31 AM
AfterWorldForum AfterWorldForum is offline
 
Join Date: Dec 2008
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, Lynne. I tried substituting my variable and included the templatevalues, but to no result.

I will rewrite the code in the plugin to the way you posted, and see if that does anything.

Thanks again.
Reply With Quote
  #10  
Old 08-16-2010, 11:46 AM
Eric's Avatar
Eric Eric is offline
 
Join Date: May 2006
Location: Kentucky
Posts: 792
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looking at your code, in the foreach loop you may want to change:

PHP Code:
$optoutforumbits $templater->render(); 
To:
PHP Code:
$optoutforumbits .= $templater->render(); 
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 05:55 AM.


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.06708 seconds
  • Memory Usage 2,265KB
  • 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
  • (4)bbcode_code
  • (3)bbcode_php
  • (2)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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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_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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete