MyBB Community Forums

Full Version: What hook is for when users visits?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
trying to develop a plugin that rewards users for visiting the forum 
which hook would i need to use to know if they visited the forum?

thanks
global_start if you want to catch any page
(2020-05-15, 09:16 AM)Crazycat Wrote: [ -> ]global_start if you want to catch any page

hey thx
how bout
pre_output_page
Do you need to do modifications on the page content with your plugin ? If no, you'd better choose one of the global_* hooks.
(2020-05-15, 10:58 AM)Crazycat Wrote: [ -> ]Do you need to do modifications on the page content with your plugin ? If no, you'd better choose one of the global_* hooks.

yea want to inform the user that they have been given award
thx!
use global_intermediate hook to fill the template you'll add.
Here is what I do in ABP User Map to warn user if they don't fill their localisation:
$plugins->add_hook('global_intermediate', 'abp_umap_toplink');
function abp_umap_toplink() {
    global $mybb, $templates, $templatelist, $lang, $abp_umap_warnuser, $current_page;
    $warnpage = ['index.php', 'showthread.php', 'forumdisplay.php', 'newthread.php', 'newreply.php', 'polls.php', 'search.php'];
    $lang->load(CN_ABPUMAP);
    if ((int)$mybb->user['uid']>0
            && in_array($current_page, $warnpage)
            && $mybb->settings[CN_ABPUMAP.'_warnuser']==1 
            && !$mybb->user['islocalised']) {
        $abp_umap_warningnotset = $lang->sprintf($lang->abp_umap_warningnotset, $mybb->settings['bburl']);
        eval("\$" . CN_ABPUMAP ."_warnuser =\"" . $templates->get(UMAP_TPL . '_warnuser') . "\";");
    } else {
        eval("\$" . CN_ABPUMAP ."_warnuser =\"\";");
    }
}
the warnuser template is added at the end of header template:
find_replace_templatesets("header", "#" . preg_quote('<br />'). "$#i", '<br />{$' . CN_ABPUMAP . '_warnuser}');
(2020-05-15, 03:53 PM)Crazycat Wrote: [ -> ]use global_intermediate hook to fill the template you'll add.
Here is what I do in ABP User Map to warn user if they don't fill their localisation:
$plugins->add_hook('global_intermediate', 'abp_umap_toplink');
function abp_umap_toplink() {
    global $mybb, $templates, $templatelist, $lang, $abp_umap_warnuser, $current_page;
    $warnpage = ['index.php', 'showthread.php', 'forumdisplay.php', 'newthread.php', 'newreply.php', 'polls.php', 'search.php'];
    $lang->load(CN_ABPUMAP);
    if ((int)$mybb->user['uid']>0
            && in_array($current_page, $warnpage)
            && $mybb->settings[CN_ABPUMAP.'_warnuser']==1 
            && !$mybb->user['islocalised']) {
        $abp_umap_warningnotset = $lang->sprintf($lang->abp_umap_warningnotset, $mybb->settings['bburl']);
        eval("\$" . CN_ABPUMAP ."_warnuser =\"" . $templates->get(UMAP_TPL . '_warnuser') . "\";");
    } else {
        eval("\$" . CN_ABPUMAP ."_warnuser =\"\";");
    }
}
the warnuser template is added at the end of header template:
find_replace_templatesets("header", "#" . preg_quote('<br />'). "$#i", '<br />{$' . CN_ABPUMAP . '_warnuser}');

thx for the answer but just wondering if its bad to use pre_output_page?
cuz i have some plugins that uses that to do modifications on the page content
I suppose you could use pre_output_page, but it isn’t called in as many pages as global_start (i.e: some popup windows).
And as I said before: pre_output_page is used to modify the page content before its display (as example to hide all links for guest with a preg_replace)
(2020-05-15, 06:39 PM)Omar G. Wrote: [ -> ]I suppose you could use pre_output_page, but it isn’t called in as many pages as global_start (i.e: some popup windows).

(2020-05-15, 10:10 PM)Crazycat Wrote: [ -> ]And as I said before: pre_output_page is used to modify the page content before its display (as example to hide all links for guest with a preg_replace)

thx for the reply