| 1 |
<?php |
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Block CPR is a module to provide weighted role specific content. Drupal allows block access per role, |
| 7 |
|
* but what if a user has 1 or more roles beside authenticated? Odds are, you would see two or more blocks as |
| 8 |
|
* each one matches a role the user has. This module gets around this by allowing weights to decide which order |
| 9 |
|
* the roles are checked. The first match is the one that shows. Each roles gets its own content. |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
/** |
| 14 |
|
* Implementation of hook_menu(). |
| 15 |
|
*/ |
| 16 |
function block_cpr_menu($may_cache) { |
function block_cpr_menu($may_cache) { |
| 17 |
$items = array(); |
$items = array(); |
| 18 |
|
|
| 19 |
if ($may_cache) { |
if ($may_cache) { |
| 20 |
$items[] = array( |
$items[] = array( |
| 21 |
'path' => 'admin/build/block/cpr', |
'path' => 'admin/build/block/cpr', |
| 22 |
'title' => t('CPR'), |
'title' => t('CPR Blocks'), |
| 23 |
'description' => t('Configure block containing content for specific weighted roles.'), |
'description' => t('Configure block containing content for specific weighted roles.'), |
| 24 |
'access' => user_access('administer blocks'), |
'access' => user_access('administer blocks'), |
| 25 |
'callback' => 'drupal_get_form', |
'callback' => 'block_cpr_overview_form', |
|
'callback arguments' => array('block_cpr_overview_form'), |
|
| 26 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 27 |
); |
); |
| 28 |
$items[] = array( |
$items[] = array( |
| 64 |
} |
} |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
/** |
| 68 |
|
* Implementation of hook_block(). |
| 69 |
|
*/ |
| 70 |
function block_cpr_block($op = 'list', $delta = 0, $edit = array()) { |
function block_cpr_block($op = 'list', $delta = 0, $edit = array()) { |
| 71 |
switch ($op) { |
switch ($op) { |
| 72 |
case 'list': |
case 'list': |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
/** |
| 87 |
|
* Handler for displaying a blocks contents |
| 88 |
|
*/ |
| 89 |
function block_cpr_block_view($delta) { |
function block_cpr_block_view($delta) { |
| 90 |
$settings = variable_get('block_cpr_settings', array()); |
$settings = variable_get('block_cpr_settings', array()); |
| 91 |
if (isset($settings[$delta])) { |
if (isset($settings[$delta])) { |
| 92 |
global $user; |
global $user; |
| 93 |
foreach ($settings[$delta] as $role_id => $block_settings) { |
foreach ($settings[$delta] as $role_id => $block_settings) { |
| 94 |
if (isset($user->roles[$role_id])) { |
if (isset($user->roles[$role_id])) { |
|
$body = token_replace($settings[$delta][$role_id]['content']['body']); |
|
|
|
|
| 95 |
return array( |
return array( |
| 96 |
'subject' => '', |
'subject' => '', |
| 97 |
'content' => check_markup($body, $settings[$delta][$role_id]['content']['format'], FALSE), |
'content' => check_markup($settings[$delta][$role_id]['content']['body'], $settings[$delta][$role_id]['content']['format'], FALSE), |
| 98 |
); |
); |
| 99 |
} |
} |
| 100 |
} |
} |