You are here

function _tableofcontents_block_view in Table of Contents 6.3

Same name and namespace in other branches
  1. 7 tableofcontents_block/tableofcontents_block.module \_tableofcontents_block_view()

Create the block if user has permission and we are viewing a node and the node has enough data to generate a table of contents.

1 call to _tableofcontents_block_view()
tableofcontents_block_block in tableofcontents_block/tableofcontents_block.module
Implementation of hook_block().

File

tableofcontents_block/tableofcontents_block.module, line 14
main file for module providing a block

Code

function _tableofcontents_block_view() {
  global $_tableofcontents_block_processing;
  global $_tableofcontents_block_toc;

  // check whether we are viewing a node
  if (arg(0) != 'node' || !is_numeric(arg(1))) {

    // no block
    return;
  }
  $node = node_load(arg(1));

  // verify user's access to view the node
  if (!node_access('view', $node)) {
    return;
  }
  $_tableofcontents_block_processing = TRUE;
  $text = node_view($node, FALSE, TRUE, FALSE);
  unset($_tableofcontents_block_processing);
  module_load_include('pages.inc', 'tableofcontents');
  $_tableofcontents_block_toc = '[toc]';
  $text = _tableofcontents_process(0, 'block', $text);
  unset($_tableofcontents_block_toc);
  if ($text) {
    $block['content'] = $text;
    $block['subject'] = t('Table of contents');
    $block['weight'] = 0;
    return $block;
  }

  // no block
}