/[drupal]/contributions/modules/block_cpr/block_cpr.module
ViewVC logotype

Diff of /contributions/modules/block_cpr/block_cpr.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by njt1982, Tue Nov 17 17:16:39 2009 UTC revision 1.1.2.1 by njt1982, Thu Nov 19 19:08:13 2009 UTC
# Line 1  Line 1 
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(
# Line 52  function block_cpr_menu($may_cache) { Line 64  function block_cpr_menu($may_cache) {
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':
# Line 70  function block_cpr_block($op = 'list', $ Line 83  function block_cpr_block($op = '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      }      }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.3