Implementing blocks

Public

Warning message

We recommend you to assign at least one category to this snippet so you could easily navigate it in the future. Edit your snippet here.

Get raw version
php
  1. <?php
  2. // $Id$
  3.  
  4. /**
  5. * @file
  6. * Implements various blocks to improve pending content workflow.
  7. */
  8.  
  9.  
  10. /**
  11.  * Implements hook_block_info().
  12.  */
  13. function approval_block_info() {
  14. $blocks['pending_comments'] = array(
  15. 'info' => t('Pending Comments'),
  16. 'status' => TRUE,
  17. 'region' => 'sidebar_first',
  18. 'weight' => 0,
  19. );
  20. $blocks['unpublished_nodes'] = array(
  21. 'info' => t('Unpublished Nodes'),
  22. 'status' => TRUE,
  23. 'region' => 'sidebar_first',
  24. 'weight' => 0,
  25. );
  26. return $blocks;
  27. }
  28.  
  29. /**
  30.  * Implements hook_block_configure().
  31.  */
  32. function approval_block_configure($delta) {
  33.  
  34. $form = array();
  35.  
  36. switch($delta) {
  37.  
  38. case 'pending_comments':
  39. $form['pending_comment_count'] = array(
  40. '#type' => 'textfield',
  41. '#title' => t('Configure Number of Comments to Display'),
  42. '#size' => 6,
  43. '#description' => t('Enter the number of pending comments that will appear in the block.'),
  44. '#default_value' => variable_get('pending_comment_count', 5),
  45. );
  46. break;
  47.  
  48. case 'unpublished_nodes':
  49. $form['unpublished_node_count'] = array(
  50. '#type' => 'textfield',
  51. '#title' => t('Configure Number of Nodes to Display'),
  52. '#size' => 6,
  53. '#description' => t('Enter the number of unpublished nodes that will appear in the block.'),
  54. '#default_value' => variable_get('unpublished_node_count', 5),
  55. );
  56. break;
  57.  
  58. }
  59. return $form;
  60. }
  61.  
  62.  
  63.  
  64. /**
  65.  * Implements hook_block_save().
  66.  */
  67. function approval_block_save($delta = '', $edit = array()) {
  68.  
  69. switch($delta) {
  70. case 'pending_comments':
  71. variable_set('pending_comment_count', (int)$edit['pending_comment_count']);
  72. break;
  73. case 'unpublished_nodes':
  74. variable_set('unpublished_node_count', (int)$edit['unpublished_node_count']);
  75. break;
  76. }
  77.  
  78. return;
  79. }
  80.  
  81. /**
  82.  * Implements hook_block_view().
  83.  */
  84. function approval_block_view($delta = '') {
  85.  
  86. switch ($delta) {
  87. case 'pending_comments':
  88. $block['subject'] = t('Pending Comments');
  89. $block['content'] = approval_block_contents($delta);
  90. return $block;
  91. break;
  92. case 'unpublished_nodes':
  93. $block['subject'] = t('Unpublished Nodes');
  94. $block['content'] = approval_block_contents($delta);
  95. return $block;
  96. break;
  97. }
  98.  
  99. }
  100.  
  101.  
  102. /**
  103.  * A module-defined block content function.
  104.  */
  105. function approval_block_contents($delta) {
  106. switch ($delta) {
  107. case 'pending_comments':
  108. if (user_access('administer comments')) {
  109. $nbr_comments = variable_get('pending_comment_count');
  110. $result = db_query("SELECT cid, subject FROM {comment} WHERE status = 0 limit $nbr_comments");
  111. $items = array();
  112. foreach ($result as $row) {
  113. $items[] = l($row->subject, 'comment/'.$row->cid.'/edit');
  114. }
  115. return array('#markup' => theme('item_list', array('items' => $items)));
  116. }
  117. break;
  118.  
  119. case 'unpublished_nodes':
  120. if (user_access('administer nodes')) {
  121. $nbr_nodes = variable_get('unpublished_node_count');
  122. $result = db_query("SELECT nid, title FROM {node} WHERE status = 0 limit $nbr_nodes");
  123. $items = array();
  124. foreach ($result as $row) {
  125. $items[] = l($row->title, 'node/'.$row->nid.'/edit');
  126. }
  127. return array('#markup' => theme('item_list', array('items' => $items)));
  128. }
  129. break;
  130. }
  131. }