... Elxis version 2009.3 codename Aphrodite is out, download it from Elxis Download Center (EDC) ...

Eforum Hooks

From Elxis Official Documentation

Revision as of 05:57, 12 May 2010 by Datahell (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
This page is part of the eForum online user guide.

eForum is a free forum component for Elxis CMS developed by Ioannis Sannos (Is Open Source).
You will find all articles of this manual inside the Eforum category.
License Creative Commons 3.0. Share Alike. Copyright (c) 2008-2010 Is Open Source. All rights reserved.


Contents

What is a Hook

Hook is a mini application which includes additional functions and can be applied in various points

Characteristics:

1. In any applied point we can have unlimited hooks
2. Hooks can have various names and all of them are into folder hooks
3. Hooks can contain many subfolders with names which they depend from the point they act

Example 1: A hook which is applied on authorbox it is in path hooks/authorbox and by a file signature.php we can add under user's profile a signature. So the specific hook is here: hooks/authorbox/signature.php
Example 2: A much more complex hook is the mobile hook (type: init hook) that generates a versin of eForum friendly to devices such as iphone, ipod, ipad, blackberry and android.

In eForum Configuration (tab Hooks) you can enable/disable hooks and, if enabled, set in which areas to enable hooks. Note that for performance reasons do not enable hooks if you dont use them!

Image:elxis_eforum_hooks_1.jpg

Developers notes

Inside each hook folder you will find a readme.txt file containing information on how to create hooks for eForum (example: hooks/mail/readme.txt). With hooks you can:

  • Extend eForum's functionality
  • Append data on the standard generated code.
  • Perform additional tasks.


Usage ideas

Here are some ideas on what you can do with hooks.

  • Display banners and elxis modules inside hook areas.
  • Display special information to specific users.
  • Insert blocks of text bellow posts (all posts, or posts of specific boards, of specific users, etc).
  • Append custom text to e-mail messages sent by eForum
  • Display user specific data from facebook, twitter and any other social network site bellow each user author box.
  • Restrict or grant access to special areas to specific users or groups (although eForum has special permissions for that).


Hook example 1

Create a new file named greetings.php and upload it inside folder hooks/boardtop/.
Now open greetings.php and write in it:

<?php 
echo 'Hello!';
?>

Go to eForum administration and make sure hooks are enabled and BoardTop hooks are also enabled.
Go to eForum's front are, you will see a Hello! message above all boards!


Hook example 2

But what if we wanted to display the message of the example 1 only to specific boards?
Open the hook we created previously (greetings.php) and modify the source code as following:

<?php 
if ($data->bid == 5) {
   echo 'Hello! You are on board with ID 5.';
} else if (in_array($data->bid, array(2, 7, 15))) {
   //the user sees one of these boards: 2, 7 or 15. Let's display to him a special banner!
   echo '<img src="mybanner.jpg" alt="banner" border="0" />';
}
?>
You can name your hook files name to anything you wish. Hooks do not need any kind of installation. Just upload them in a hook directory and they are ready. If you want to remove a hook just delete the hook file. Read carefully the readme.txt file for instructions and the sample hook (signature.php) located at the authorbox folder.


Hook example 3

We will append some text (advertisement) on the e-mail message sent by e-forum on new reply notification.
Create a hook named emailads.php and place it inside folder hooks/mail/

Write inside the file:

<?php 
if ($data == 'replynotify') {
    global $generaltext;
    $generaltext .= 'Check out this cool site: http://www.elxis.org'."\r\n\r\n";
    $GLOBALS['generaltext'] = $generaltext;
}
?>

Read also: eForum hook for iphone, ipod, ipad, black berry and android

Personal tools