vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   vB4 plugin problem - Not showing in profile (https://vborg.vbsupport.ru/showthread.php?t=248459)

AfterWorldForum 08-12-2010 03:49 PM

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

Lynne 08-12-2010 10:49 PM

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

AfterWorldForum 08-13-2010 04:17 AM

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?

Lynne 08-13-2010 04:54 AM

And what code are you using to preregister it and where?

AfterWorldForum 08-13-2010 02:54 PM

Quote:

Originally Posted by Lynne (Post 2083065)
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.

Lynne 08-13-2010 07:51 PM

According to your code, you preregistered to use a variable called "option", but that variable isn't in your template at all.

AfterWorldForum 08-14-2010 08:38 AM

Quote:

Originally Posted by Lynne (Post 2083386)
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 :(

Lynne 08-14-2010 02:34 PM

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}

AfterWorldForum 08-16-2010 04:31 AM

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.

Eric 08-16-2010 11:46 AM

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

PHP Code:

$optoutforumbits $templater->render(); 

To:
PHP Code:

$optoutforumbits .= $templater->render(); 



All times are GMT. The time now is 03:34 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.01200 seconds
  • Memory Usage 1,759KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete