The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
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; 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> Thanks in advance ![]() Peter |
#2
|
||||
|
||||
![]()
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
|
#3
|
|||
|
|||
![]()
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? |
#4
|
||||
|
||||
![]()
And what code are you using to preregister it and where?
|
#5
|
|||
|
|||
![]()
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); The only other change I made was to replace $vbulletin->userinfo with $bbuserinfo. Other than that, the code is the same as above. |
#6
|
||||
|
||||
![]()
According to your code, you preregistered to use a variable called "option", but that variable isn't in your template at all.
|
#7
|
|||
|
|||
![]() Quote:
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 ![]() |
#8
|
||||
|
||||
![]()
Whoops, I read that wrong. But, this is the format I use to preregister variables (my cheatsheet blurb below):
PHP Code:
According to what you wrote above (without extra $): Code:
$templatevalues['optoutforumbits'] = $templater->render(); vB_Template::preRegister('option', $templatevalues); |
#9
|
|||
|
|||
![]()
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. |
#10
|
||||
|
||||
![]()
Looking at your code, in the foreach loop you may want to change:
PHP Code:
PHP Code:
|
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|