| 1 |
// $Id: API.txt,v 1.3 2008/01/24 01:57:10 cwgordon7 Exp $
|
| 2 |
|
| 3 |
There are three major hooks to implement, hook_flexifilters, hook_flexifilter_conditions, and hook_flexifilter_components. Hook_flexifilters is for defining default flexifilters; hook_flexifilter_conditions is for describing your module's conditions to flexifilter; hook_flexifilter_components is for describing your module's components to flexifilter.
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
For hook_flexifilters, an array should be returned, each value of the array corresponding to an exported flexifilter (as an array itself).
|
| 9 |
|
| 10 |
function hook_flexifilter() {
|
| 11 |
return array(
|
| 12 |
array(
|
| 13 |
// Exported flexifilter here.
|
| 14 |
),
|
| 15 |
array(
|
| 16 |
// Another exported flexifilter here.
|
| 17 |
),
|
| 18 |
);
|
| 19 |
}
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
A description of hook_flexifilter_components:
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_flexifilter_components()
|
| 28 |
*
|
| 29 |
* @return An array of components to be used by the Flexifilter module. The keys of this array
|
| 30 |
* are unique identifiers for the component (called the component class), and the values of the
|
| 31 |
* array are again arrays, with the following keys:
|
| 32 |
* - label : A human readable name for the component
|
| 33 |
* - description (optional) : A human readable description of what the component does (defaults to none)
|
| 34 |
* - is_container (optional) : TRUE if any of the #contains_ fields are TRUE (set automatically)
|
| 35 |
* - contains_condition (optional) : TRUE if the component has a condition associated with it (defaults to FALSE)
|
| 36 |
* - contains_components (optional) : TRUE if the component has children components (defaults to FALSE)
|
| 37 |
* - callback : A callback function which implements the component
|
| 38 |
* - callback_arguments (optional) : An array of arguments to pass to the callback function (defaults to none)
|
| 39 |
* - group (optional) : A human readable name of the group that the component belongs to (defaults to "Other")
|
| 40 |
* - step : The step in which this is to be performed. Can be 'both', 'either', 'process', or 'prepare'.
|
| 41 |
* - If 'either' is specified, it will default to process, and the user will not be given the option to change it
|
| 42 |
* unless they have "show advanced options" checked.
|
| 43 |
*/
|
| 44 |
|
| 45 |
Hook_flexifilter_conditions works in a similar way with only one modification:
|
| 46 |
|
| 47 |
- It has no 'step' attribute.
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
Two examples of a function specified in the 'callback' key follows:
|
| 53 |
|
| 54 |
function flexifilter_component_foo($op, $settings, $text) {
|
| 55 |
switch ($op) {
|
| 56 |
case 'settings':
|
| 57 |
// Here we're passing back a settings form.
|
| 58 |
$form = array();
|
| 59 |
return $form;
|
| 60 |
|
| 61 |
case 'prepare':
|
| 62 |
case 'process':
|
| 63 |
// This filter does the same thing for both prepare and process, as its 'step' is set to 'either'.
|
| 64 |
// This step will append that message to the text being filtered.
|
| 65 |
$text .= ' - This message brought to you by flexifilter.';
|
| 66 |
return $text;
|
| 67 |
|
| 68 |
default:
|
| 69 |
return $text;
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
function flexifilter_condition_foo($op, $settings, $text) {
|
| 74 |
switch ($op) {
|
| 75 |
case 'settings':
|
| 76 |
// Here we're passing back a settings form.
|
| 77 |
$form = array();
|
| 78 |
return $form;
|
| 79 |
|
| 80 |
case 'prepare':
|
| 81 |
case 'process':
|
| 82 |
// We return TRUE if 1 + 1 = 2.
|
| 83 |
if ((1 + 1) == 2) {
|
| 84 |
return TRUE;
|
| 85 |
}
|
| 86 |
// If we get here, 1 + 1 is not equal to two.
|
| 87 |
return FALSE;
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
Some useful API functions follow:
|
| 94 |
|
| 95 |
flexifilter_invoke_condition($condition, $op, $text); - This will invoke the condition specified in 'condition' with $op and $text. It will return either TRUE or FALSE, depending on what the condition returned.
|
| 96 |
|
| 97 |
flexifilter_invoke_component($component, $op, $settings = array(), $text = ''); - This will invoke the component specified in 'component' with $op, $settings, and $text.
|
| 98 |
|
| 99 |
flexifilter_components_involve_step($components, $step); - This will return TRUE if any of the components in the components array will run in the current step 'process' or 'prepare'.
|
| 100 |
|
| 101 |
flexifilter_save_filter($filter); - This will save the filter specified in $filter. It can be used for both INSERTs and UPDATEs.
|