pluginsvbulletinpage-numbering

How can I get page number of thread in my plugin in vbulletin v4?


I need get pagenumber of thread in my plugin in vbulletin. my plugin code is:

global $vbulletin, $threadinfo, $bloginfo, $pagetitle;
if (THIS_SCRIPT == 'showthread'){
   $customTitle = $pagetitle.'-'.$pagenumber;
}
$rows = <<<ROW
<meta property="og:title" content="$customTitle" />
ROW;
$template_hook['headinclude_bottom_css'] .= $rows;

how can I get pagenumber of thread value for set $pagenumber? I know that the template is as follows:

{vb:rawphrase page_x, {vb:raw pagenumber}}

But I need this in plugin.


Solution

  • You should declare $pagenumber global, too

    global $pagenumber;
    if (THIS_SCRIPT == 'showthread'){
        echo '<!-- pageNumber: ' . $pagenumber . ' -->';
    }
    

    Placed in showthread_start hook, this gave me the following output: <!-- pageNumber: 9 -->

    But please note that if you load the plugin code in some global avaliable hook like global_start, those thread-variables may not be avaliable because they got initialized later in vBulletin's code. In this case, try choosing some other hook, that runs earlier. Here, try and error helps.

    I'd recommend trying some POC code in showthread_start to make sure it works. Then change the hooks to find out which is early enough for your planned action and that contains all required variables. Sometimes it's also usefull to see the vB code around a hook.

    You could use e.g. grep in the root of a vBulletin installation to find where global_start is executed:

    # grep -rn --include \*.php "fetch_hook('global_start')" .
    ./global.php:29:($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
    

    Its also possible to search on a Windows system with tools like Notepad++ (search in files).