function _nodesinblock_show in Nodes In Block 7
Same name and namespace in other branches
- 6 nodesinblock.module \_nodesinblock_show()
Function callback: get content for a block.
1 call to _nodesinblock_show()
- nodesinblock_block_view in ./
nodesinblock.module - Implements hook_block_view().
File
- ./
nodesinblock.module, line 392 - Nodes in block makes it possible to add multiple nodes in one block.
Code
function _nodesinblock_show($delta, $visibility) {
static $nids = array();
$i = 0;
$output = '';
$path = drupal_get_path_alias($_GET['q']);
$query = db_select('nodesinblock', 'nib');
$query
->join('node', 'n', 'nib.nid = n.nid');
$query
->fields('nib', array(
'nid',
'visibility',
'render',
'weight',
))
->condition('n.status', 1)
->condition('delta', $delta)
->orderBy('weight', 'ASC')
->addTag('node_access');
$results = $query
->execute()
->fetchAll();
$num_items = count($results);
foreach ($results as $row) {
$paths = explode("\n", trim($row->visibility));
foreach ($paths as $key => $val) {
// Match the path.
$page_match = drupal_match_path($path, $val);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $val);
}
$page_match = !($visibility xor $page_match);
// We have a match, load the node.
if ($page_match && !isset($nids[$delta][$row->nid])) {
$nids[$delta][$row->nid] = $row->nid;
$node = node_load($row->nid);
// Support for translation. Use Translation Helpers module if it's installed.
// @todo Provide granular control. Maybe we want to show nodes of language x in a block which gets
// displayed on language y. This might break other contexts (i.e. show blocks on language)
if (function_exists('translation_helpers_get_translation')) {
$tnode = translation_helpers_get_translation($node, $language->language);
if ($tnode) {
$node = $tnode;
}
}
$node->nodesinblock = TRUE;
// In case the the render selection has changed, make sure
// we select the exact render mode.
if (variable_get('nodesinblock_' . $node->type . '_render', '0') != '0') {
$row->render = variable_get('nodesinblock_' . $node->type . '_render', '0');
}
// Assemble classes.
$classes = array(
'nodesinblock',
);
if ($i == 0) {
$classes[] = 'first';
}
if ($i == $num_items - 1) {
$classes[] = 'last';
}
if ($i % 2 == 0) {
$classes[] = 'odd';
}
else {
$classes[] = 'even';
}
$i++;
// Render node.
list($view_mode, $links) = explode(':', $row->render);
$node_content = node_view($node, $view_mode);
if (!$links) {
unset($node_content['links']);
}
// Return output.
$output .= '<div class="' . implode(' ', $classes) . '" id="nodesinblock-' . $node->nid . '">';
$output .= render($node_content);
$output .= '</div>';
}
}
}
return $output;
}