function block_inject_process_condition in Block Inject 7
Helper function to process the condition for an injection.
Parameters
$node_type: The node type
$body: The node body
Return value
bool|int False if no condition, or the number of paragraphs to offset.*
3 calls to block_inject_process_condition()
- block_inject_do_injection in ./
block_inject.module - Helper function that prepares and calls the injection on a node.
- block_inject_exceptions_list in ./
block_inject.admin.inc - Callback for the Block Inject Exceptions page.
- block_inject_form_node_form_alter in ./
block_inject.module - Implements hook_form_FORM-ID_alter().
File
- ./
block_inject.module, line 811 - The Block Inject module functions.
Code
function block_inject_process_condition($node_type, $body) {
// Get injectable region ID.
$id = block_inject_find_bi_id($node_type);
// Get the injectable region.
$region = block_inject_get_region_by_id($id->id);
if ($region->bi_condition) {
// Get condition information.
$condition = unserialize($region->bi_condition);
$operator = $condition['condition']['operator'];
$compare_to = $condition['condition']['paragraph_no'];
$action_offset = $condition['action']['offset'];
// Break up the body field string into an array of paragraphs.
$array_explode = explode("<p>", render($body));
if ($array_explode[0] === "") {
unset($array_explode[0]);
}
// Count the body paragraphs.
$body_paragraphs = count($array_explode);
// Process condition.
switch ($operator) {
case '=':
if ($body_paragraphs = $compare_to) {
return $action_offset;
}
break;
case '>':
if ($body_paragraphs > $compare_to) {
return $action_offset;
}
break;
case '<':
if ($body_paragraphs < $compare_to) {
return $action_offset;
}
break;
}
}
return FALSE;
}