| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Block Filter provides a simple input filter to allow an editor (with permission) to embed any block on the site into the content
|
| 7 |
*/
|
| 8 |
|
| 9 |
function block_filter_filter($op, $delta = 0, $format = 1, $text = '') {
|
| 10 |
switch ($op) {
|
| 11 |
case 'list' :
|
| 12 |
return array(t('Block Filter'));
|
| 13 |
|
| 14 |
case 'description' :
|
| 15 |
return t('Provides a method of embedding blocks into content');
|
| 16 |
|
| 17 |
case 'process' :
|
| 18 |
return preg_replace_callback('#\[block:(.+):(.+)]#s', 'block_filter_embed', $text);
|
| 19 |
|
| 20 |
default :
|
| 21 |
return $text;
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
function block_filter_embed($match) {
|
| 26 |
global $user;
|
| 27 |
$theme = variable_get('theme_default', 'garland');
|
| 28 |
$module = $match[1];
|
| 29 |
$delta = $match[2];
|
| 30 |
|
| 31 |
|
| 32 |
//Make sure this module implements hook_block
|
| 33 |
if (!module_hook($module, 'block')) return '';
|
| 34 |
|
| 35 |
//Get the users roles
|
| 36 |
$rids = array_keys($user->roles);
|
| 37 |
|
| 38 |
//Create a placeholder for each role ID
|
| 39 |
$placeholders = implode(',', array_fill(0, count($rids), '%d'));
|
| 40 |
|
| 41 |
//Run a query to get the block from the DB (this checks the block is enabled for thie current users role)
|
| 42 |
$block = db_fetch_object(db_query("SELECT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.module = '%s' AND b.delta = '%s' AND b.theme = '%s' AND (r.rid IN ($placeholders) OR r.rid IS NULL)", array_merge(array($module, $delta, $theme), $rids)));
|
| 43 |
|
| 44 |
// CODE BORROWED FROM block_list
|
| 45 |
// Use the user's block visibility setting, if necessary
|
| 46 |
if ($block->custom != 0) {
|
| 47 |
if ($user->uid && isset($user->block[$block->module][$block->delta])) {
|
| 48 |
$enabled = $user->block[$block->module][$block->delta];
|
| 49 |
}
|
| 50 |
else {
|
| 51 |
$enabled = ($block->custom == 1);
|
| 52 |
}
|
| 53 |
}
|
| 54 |
else {
|
| 55 |
$enabled = TRUE;
|
| 56 |
}
|
| 57 |
|
| 58 |
//Check the page display stuff
|
| 59 |
if ($block->pages) {
|
| 60 |
if ($block->visibility < 2) {
|
| 61 |
$path = drupal_get_path_alias($_GET['q']);
|
| 62 |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
|
| 63 |
// Compare with the internal and path alias (if any).
|
| 64 |
$page_match = preg_match($regexp, $path);
|
| 65 |
if ($path != $_GET['q']) {
|
| 66 |
$page_match = $page_match || preg_match($regexp, $_GET['q']);
|
| 67 |
}
|
| 68 |
$page_match = !($block->visibility xor $page_match);
|
| 69 |
}
|
| 70 |
else {
|
| 71 |
$page_match = drupal_eval($block->pages);
|
| 72 |
}
|
| 73 |
}
|
| 74 |
else {
|
| 75 |
$page_match = TRUE;
|
| 76 |
}
|
| 77 |
$block->enabled = $enabled;
|
| 78 |
$block->page_match = $page_match;
|
| 79 |
|
| 80 |
if ($block->enabled && $block->page_match) {
|
| 81 |
// Check the current throttle status and see if block should be displayed based on server load.
|
| 82 |
if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
|
| 83 |
$array = module_invoke($block->module, 'block', 'view', $block->delta);
|
| 84 |
if (isset($array) && is_array($array)) {
|
| 85 |
foreach ($array as $k => $v) {
|
| 86 |
$block->$k = $v;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
if (isset($block->content) && $block->content) {
|
| 92 |
// Override default block title if a custom display title is present.
|
| 93 |
if ($block->title) {
|
| 94 |
// Check plain here to allow module generated titles to keep any markup.
|
| 95 |
$block->subject = $block->title == '<none>' ? '' : check_plain($block->title);
|
| 96 |
}
|
| 97 |
return theme('block', $block);
|
| 98 |
}
|
| 99 |
}
|
| 100 |
|
| 101 |
return '';
|
| 102 |
}
|