Hook System

http://community.havefnubb.org/hfnu/images/flags/United-Kingdom.gif

Introduction

The Hook system permits to add in the templates of his choice, the fonctionnalities that we wish.

To exploit the hooks we will write in the template :

{hook 'event', $params}

where event is the event name triggered the grabbind of all the functionalities and $params is the array of parameters given to the listener answering to event.

Example :

{hook 'SampleBannerAnnouncement'}

will display a banner of announcement in the template of your choice by answering to the event SampleBannerAnnouncement.

Hooks list

  • Category :
    • hfbBeforeCategoryList
    • hfbCategoryList (parm => id_cat)
    • hfbAfterCategoryList
  • Forum :
    • hfbBeforeForumIndex
    • hfbForumIndex (parm => id_forum)
    • hfbAfterForumIndex
  • Posts :
    • hfbBeforePostsEdit (parm => id_posts)
    • hfbPostsEdit (parm => id_posts)
    • hfbAfterPostsEdit (parm => id_posts)
    • hfbBeforePostsReplies (parm => id_posts)
    • hfbPostsReplies (parm => id_posts)
    • hfbPostRepliesFooter (parm =>'action'=>'one jurl','parms'=>array()))
    • hfbAfterPostsReplies (parm => id_posts)
    • hfbBeforePostsList (parm => id_posts)
    • hfbPostsList (parm => id_posts)
    • hfbAfterPostsList (parm => id_posts)
  • Statistics
    • hfbBeforeStats
    • hfbStats
    • hfbAfterStats
    • hfbBeforeOnlineToday
    • hfbOnlineToday
    • hfbAfterOnlineToday
    • hfbBeforeOnline
    • hfbOnline
    • hfbAfterOnline
  • Flood :
    • hfbBeforeFlood
    • hfbFlood
    • hfbAfterFlood
  • Ban :
    • hfbBeforeBan
    • hfbBan
    • hfbAfterBan
  • Account :
    • hfbAccountShowBefore (parm => login)
    • hfbAccountShowTab (parm => login)
    • hfbAccountShowDiv (parm => login)
    • hfbAccountShowAfter (parm => login)
    • hfbAccountEditBefore (parm => login)
    • hfbAccountEditTab (parm => login)
    • hfbAccountEditDiv (parm => login)
    • hfbAccountEditAfter (parm => login)
  • Membres
    • hfbBeforeMembersList
    • hfbMembersList ( parm => user )
    • hfbAfterMembersList
    • hfbBeforeMemberProfile ( parm => id )
    • hfbMemberProfile ( parm => id )
    • hfbAfterMemberProfile ( parm => id )
  • Search
    • hfbBeforeSearch
    • hfbSearch
    • hfbAfterSearch
  • Main
    • hfbMainInHeader
    • hfbMainInFooter
  • Status (jCommunity)
    • JcommunityStatusConnected (parm = login)

Hooks naming convention

this will permit you to understand, by reading the event name, to which page / template the hook is linked

  • BeforeTemplateName
  • TemplateName
  • AfterTemplateName

where :

  • TemplateName is the name of the template where the hook is used
  • BeforeTemplateName is the name of the hook called at the beginning of the template TemplateName
  • TemplateName is also the place where the hook is called (in the middle of the template)
  • AfterTemplateName is the name of the hook called at the end the template TemplateName

Hooks Repository

Where ?

The repository is located in the dedicated folder modules-hook

Why a Repository?

This permits to centralize all modules responding to events of those hooks

How to respond to hooks ?

We have to produce a module (cf le module d'exemple modules-hook/hook ) :

  • a listener
  • a zone
  • a template
  • the Listener will be in charge of responding to the event in calling a zone
    class hookListener extends jEventListener{
        
       function onhfbSampleBannerAnnouncement ($event) {
            $event->add( jZone::get('hook~samplebanner_accouncement') );
       } 
    }
    
  • file events.xml to define the listener which will respond to the event
    <?xml version="1.0" encoding="iso-8859-1"?>
    <events xmlns="http://jelix.org/ns/events/1.0">
       <listener name="hook">
    	<event name="hfbSampleBannerAnnouncement" />
       </listener>
    </events>
    
  • the zone will exploit the data of your choice and will provide them to the template
    class samplebanner_accouncementZone extends jZone {
        protected $_tplname='zone.samplebanner_accouncement';
        
        protected function _prepareTpl(){    
            $this->_tpl->assign('text',jLocale::get('hook~main.welcome'));
        }        
    }
    
  • the template will display the data
    <div class="grid_16">
        <div class="box">
        <h2>Banner</h2>
        {$text}
        </div>
    </div>
    <div class="clear"></div>
    

all of this will be returned to the Hook in the wanted template at the place you want