Welcome Guest, Not a member yet? Register   Sign In
Plugin Handling Class - Extends the CI_Hooks Class
#8

[eluser]Xeoncross[/eluser]
That is mostly right. It is the SAME EXACT way the current hooks works - only it allows more hook points (other than the standard 8 and also adds a "filter" function for hooks that should return data (and not just run).


Here is the code:

Hooks.php
Code:
$hook['filter_comment'][] = array(
    'function' => 'filter',
    'filename' => 'filter.php',
    'filepath' => 'hooks',
);

controller:
Code:
//Create data (array, string, object, whatever)
$data = $this->somemodel->getSampleContent();

//Run the hook on the data
$data = $this->hooks->filter('filter_comment', $data);

filter.php
Code:
function filter($data)
{
    $data = htmlentities($data);
    $data = stripslashes($data);
    return $data;
}

And you now have a filter that process comments! You can also pass by reference (if you don't want return statements in your code) and you can register multiple functions/objects to run on data. I.E.

Code:
//Check akismet for spam
$hook['filter_comment'][] = array(
    'function' => 'check_for_spam',
    'filename' => 'akismet.php',
    'filepath' => 'plugins',
);

//Remove Bad stuff
$hook['filter_comment'][] = array(
    'function' => 'remove',
    'filename' => 'filter.php',
    'filepath' => 'hooks',
);

//Filter text
$hook['filter_comment'][] = array(
    'function' => 'filter',
    'filename' => 'filter.php',
    'filepath' => 'hooks',
);

There is no need to load the hooks class in your controller because CI loads it already!

The perfect example of this whole hooks/plugins thing is parsing a comment/text body. Some people want markup others use Cleaned HTML - still others only use BBCODE! With a simple plugin/hook call like above you can swap out the text filter to any type you want!


Messages In This Thread
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 08-05-2008, 06:23 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 08-05-2008, 07:00 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 08-05-2008, 07:15 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 08-05-2008, 07:24 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 08-05-2008, 07:34 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 08-05-2008, 07:42 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 04:02 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 05:32 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 05:46 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 05:50 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 06:20 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 06:29 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 06:34 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 06:41 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 06:47 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-30-2008, 06:51 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 04:22 AM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 11:42 AM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 11:43 AM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 11:49 AM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 11:51 AM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 11:55 AM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 12:00 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 12-31-2008, 12:08 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 07-15-2009, 12:55 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 07-15-2009, 01:04 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 07-15-2009, 01:55 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 07-15-2009, 02:00 PM
Plugin Handling Class - Extends the CI_Hooks Class - by El Forum - 07-16-2009, 08:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB