related_blog.module

Tracking 6.x-3.x branch
  1. drupal
    1. 6 contributions/util/contribs/related_blog/related_blog.module

Provides block to show blog of node's author.

Functions & methods

NameDescription
related_blog_blockImplements hook_block();
related_blog_block_configureFunction for related_blog_block(op = 'configure').
related_blog_block_listFunction for related_blog_block(op = 'list').
related_blog_block_saveFunction for related_blog_block(op = 'save').
related_blog_block_viewFunction for related_blog_block(op = 'view').

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Provides block to show blog of node's author.
  5. */
  6. /**
  7. * Implements hook_block();
  8. */
  9. function related_blog_block($op = 'list', $delta = 0, $edit = array()) {
  10. switch ($op) {
  11. case 'list':
  12. return related_blog_block_list();
  13. case 'view':
  14. return related_blog_block_view($delta);
  15. case 'configure':
  16. return related_blog_block_configure($delta);
  17. case 'save':
  18. return related_blog_block_save($delta, $edit);
  19. }
  20. }
  21. /**
  22. * Function for related_blog_block(op = 'list').
  23. */
  24. function related_blog_block_list() {
  25. return array(
  26. 'related_blog' => array(
  27. 'info' => t('Util: Related Blog'),
  28. 'visibility' => 1, /* Show only on. */
  29. 'pages' => 'node/*',
  30. 'cache' => BLOCK_NO_CACHE,
  31. ),
  32. );
  33. }
  34. /**
  35. * Function for related_blog_block(op = 'view').
  36. */
  37. function related_blog_block_view($delta = 0) {
  38. $block = array();
  39. switch ($delta) {
  40. case 'related_blog':
  41. // Make sure it makes sense to show this.
  42. // That is, not on node add/edit, etc.
  43. $extra = arg(2);
  44. if ($extra) {
  45. return $block;
  46. }
  47. // Get configured content types.
  48. $types = variable_get('related_blog_types', array());
  49. // Get the currently displayed node.
  50. $node = menu_get_object();
  51. // Make sure it's one of our types.
  52. if (in_array($node->type, $types)) {
  53. $account = user_load(array('uid' => $node->uid));
  54. // Get the current title (note that this is already sanitized).
  55. $title = drupal_get_title();
  56. // Make sure the blog code is loaded.
  57. module_load_include('inc', 'blog', 'blog.pages');
  58. // Call the blog page code.
  59. $block['content'] = blog_page_user($account);
  60. // Restore the title as blog_page_user will screw it up.
  61. drupal_set_title($title);
  62. }
  63. break;
  64. }
  65. return $block;
  66. }
  67. /**
  68. * Function for related_blog_block(op = 'configure').
  69. */
  70. function related_blog_block_configure($delta = 0) {
  71. $form = array();
  72. switch ($delta) {
  73. case 'related_blog':
  74. $form['types'] = array(
  75. '#type' => 'checkboxes',
  76. '#title' => t('Show on these content types'),
  77. '#default_value' => variable_get('related_blog_types', array()),
  78. '#options' => node_get_types('names'),
  79. '#attributes' => array('class' => 'container-inline'),
  80. );
  81. break;
  82. }
  83. return $form;
  84. }
  85. /**
  86. * Function for related_blog_block(op = 'save').
  87. */
  88. function related_blog_block_save($delta = 0, $edit = array()) {
  89. switch ($delta) {
  90. case 'related_blog':
  91. variable_set('related_blog_types', $edit['types']);
  92. return;
  93. }
  94. }