You may use [block:module=delta] tags to display the contents of block delta for module module. To discover module names and deltas, visit admin/build/block and hover over a block\'s configure link and look in your browser\'s status bar. The last "word" you see is the name of the module and the number following that is the delta. If you leave off the delta in an Insert Block tag, the default delta will be used.'); } else { return t('You may use [block:module=delta] tags to display the contents of block delta for module module.', array("@insert_block_help" => url("filter/tips/$format", array('fragment' => 'filter-insert_block')))); } } /** * Implementation of hook_help(). */ function insert_block_help($section = 'admin/help#insert_block', $args = array()) { $output = ''; switch ($section) { case 'admin/help#insert_block': return t('

Use special tags to insert the contents of a block into a node.

You may use [block:module=delta] tags in the body of a node or anywhere that Drupal\'s filter system runs to display the contents of block delta for module module.

To discover module names and deltas, visit admin/build/block and hover over a block\'s configure link and look in your browser\'s status bar. The last "word" you see is the name of the module and the number following that is the delta. If you leave off the delta in an Insert Block tag, the default delta will be used.

'); } } /** * Implementation of hook_filter(). */ function insert_block_filter($op, $delta = 0, $format = -1, $text = '') { // The "list" operation provides the module an opportunity to declare both how // many filters it defines and a human-readable name for each filter. Note that // the returned name should be passed through t() for translation. if ($op == 'list') { return array( 0 => t('insert block filter')); } // go ahead and set this up for multiple filters, though I doubt we'll use it switch ($delta) { case 0: switch ($op) { case 'description': return t('Inserts the contents of a block into a node using [block:module=delta] tags.'); case 'prepare': return $text; case 'process': return _insert_block_substitute_tags($text, $format); case 'no cache': return TRUE; case 'settings': $form['insert_block'] = array( '#type' => 'fieldset', '#title' => t('Insert Block filter'), '#collapsible' => TRUE, ); $form['insert_block']["insert_block_check_roles_$format"] = array( '#type' => 'checkbox', '#title' => t('Check the roles assigned by the Block module'), '#default_value' => variable_get("insert_block_check_roles_$format", 0), '#description' => t('Without this checked, anyone can see inserted blocks.'), ); return $form; } break; } } function _insert_block_substitute_tags($text, $format) { global $user; if (preg_match_all("/\[block:([^=\\]]+)=?([^\\]]*)?\]/i", $text, $match)) { $block_roles = _insert_block_roles(); $raw_tags = $repl = array(); foreach ($match[2] as $key => $value) { $module = $match[1][$key]; $delta = $match[2][$key]; $replacement = ''; $block = (object) module_invoke($module, 'block', 'view', $delta); if (isset($block->content)) { $check_roles_settings = variable_get("insert_block_check_roles_$format", NULL); $check_roles = !empty($check_roles_settings); $block_settings_result = db_query("SELECT * FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta); $block_settings = db_fetch_object($block_settings_result); // If a block has no roles associated, it is displayed for every role. // For blocks with roles associated, if none of the user's roles matches // the settings from this block, remove it from the block list. if ($check_roles && isset($block_roles[$block_settings->module][$block_settings->delta]) && !array_intersect($block_roles[$block_settings->module][$block_settings->delta], array_keys($user->roles))) { // No match. $block = NULL; } if ($block) { init_theme(); global $theme_key; $title = db_result(db_query_range("SELECT b.title FROM {blocks} b WHERE b.theme = '%s' AND b.module = '%s' AND b.delta = '%s'", $theme_key, $module, $delta, 0, 1)); if ($title) { $block->subject = $title == '' ? '' : check_plain($title); } $block->module = $module; $block->delta = $delta; $block->region = 'insert_block'; $raw_tags[] = $match[0][$key]; $replacement = theme('block', $block); } $repl[] = $replacement; } } return str_replace($raw_tags, $repl, $text); } return $text; } /** * Helper function to load and cache the block roles. */ function _insert_block_roles() { // Build an array of roles for each block. static $block_roles; if (!isset($block_roles)) { $block_roles = array(); $result = db_query('SELECT module, delta, rid FROM {blocks_roles}'); while($record = db_fetch_object($result)) { $block_roles[$record->module][$record->delta][] = $record->rid; } } return $block_roles; }