What hook is for when users visits?
#1
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
Reply
#2
global_start if you want to catch any page
Do not ask me help through PM or Discord
Reply
#3
(2020-05-15, 09:16 AM)Crazycat Wrote: global_start if you want to catch any page

hey thx
how bout
pre_output_page
Reply
#4
Do you need to do modifications on the page content with your plugin ? If no, you'd better choose one of the global_* hooks.
Do not ask me help through PM or Discord
Reply
#5
(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!
Reply
#6
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}');
Do not ask me help through PM or Discord
Reply
#7
(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
Reply
#8
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).
Reply
#9
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)
Do not ask me help through PM or Discord
Reply
#10
(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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)