function _customfilter_filter_process in Custom filter 7
Same name and namespace in other branches
- 7.2 customfilter.module \_customfilter_filter_process()
Process the text, apply the filters
Parameters
string $text: The text to process(the node content)
object $filter: Information about the filter from drupal
object $format: Information about the format from drupal
Return value
string The text after all changes by the filters are done
1 string reference to '_customfilter_filter_process'
- customfilter_filter_info in ./
customfilter.module - Implements hook_filter_info().
File
- ./
customfilter.module, line 85 - Allows the users with the right permission to define custom filters.
Code
function _customfilter_filter_process($text, $filter, $format) {
// If the text passed is an empty string, then return it immediately.
if (empty($text)) {
return '';
}
$filters = _customfilter_get_filters();
$item = '';
// @todo look if there is not a php function for this
foreach ($filters as $itens) {
if ($itens['type'] == $filter->name) {
$item = $itens;
}
}
// If the filter cannot be loaded from the database, then return the text
// passed to the function.
if (!$item) {
return $text;
}
$globals =& _customfilter_globals('push');
$globals->text = $text;
$result = db_query("SELECT fid FROM {customfilter_filter} WHERE name = :name", array(
':name' => $item['name'],
))
->fetchField();
$rules = _customfilter_get_rules($result);
if (is_array($rules) && count($rules)) {
// Reset the object containing the global variables.
_customfilter_code_vars(TRUE);
// Prepare the stack used to save the parent rule.
$globals->stack = array();
foreach ($rules as $rule) {
if ($rule['enabled']) {
$globals->stack[] = $rule;
$globals->text = preg_replace_callback($rule['pattern'], '_customfilter_process', $globals->text);
array_pop($globals->stack);
}
}
}
$result = $globals->text;
_customfilter_globals('pop');
return $result;
}