function _nodesinblock_show in Nodes In Block 6
Same name and namespace in other branches
- 7 nodesinblock.module \_nodesinblock_show()
Function callback: get content for a block.
1 call to _nodesinblock_show()
- nodesinblock_block in ./
nodesinblock.module - Implementation of hook_block().
File
- ./
nodesinblock.module, line 377 - Nodes in block makes it possible to add multiple nodes in one block.
Code
function _nodesinblock_show($delta, $visibility) {
static $nids = array();
$output = '';
$path = drupal_get_path_alias($_GET['q']);
$query = "SELECT nib.nid, visibility, render, weight FROM {nodesinblock} nib\n LEFT JOIN {node} n on n.nid = nib.nid\n WHERE n.status = 1 AND delta = %d\n ORDER BY weight\n ";
$i = 0;
$result = db_query(db_rewrite_sql($query), $delta);
$num_items = db_affected_rows();
while ($row = db_fetch_object($result)) {
$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);
$node->nodesinblock = 1;
// 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++;
$output .= '<div class="' . implode(' ', $classes) . '" id="nodesinblock-' . $node->nid . '">';
// Support for Node Displays module.
if (module_exists('nd')) {
$node->build_mode = $row->render;
$teaser = $node->build_mode != 'full' ? TRUE : FALSE;
$show_links = ds_show_field('nd', $node->type, $node->build_mode, 'links');
$output .= node_view($node, $teaser, FALSE, $show_links);
}
else {
$links = FALSE;
if ($row->render == NIB_RENDER_PAGE_WITH_LINKS || $row->render == NIB_RENDER_TEASER_WITH_LINKS) {
$links = TRUE;
}
$output .= $row->render == NIB_RENDER_TEASER_WITH_LINKS || $row->render == NIB_RENDER_TEASER_WITHOUT_LINKS ? node_view($node, TRUE, FALSE, $links) : node_view($node, FALSE, TRUE, $links);
}
if (variable_get('nodesinblock_editbuttons', 0) && node_access('update', $node)) {
$edit_button = variable_get('nodesinblock_editbuttons_text', t('(edit)'));
$output .= l(t($edit_button), 'node/' . $node->nid . '/edit', array(
'query' => array(
'destination' => $path,
),
'attributes' => array(
'class' => 'nodesinblock-edit',
),
));
}
$output .= '</div>';
}
}
}
return $output;
}