function vud_node_nodeapi in Vote Up/Down 6.2
Same name and namespace in other branches
- 6.3 vud_node/vud_node.module \vud_node_nodeapi()
Implementation of hook_nodeapi().
File
- vud_node/
vud_node.module, line 131 - Adds a voting widget to nodes.
Code
function vud_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view':
// avoid showing the widget in some node builds
$exclude_modes = array(
NODE_BUILD_PREVIEW,
NODE_BUILD_SEARCH_INDEX,
NODE_BUILD_SEARCH_RESULT,
NODE_BUILD_RSS,
);
if (in_array($node->build_mode, $exclude_modes)) {
break;
}
if (($can_edit = user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) {
$node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
$widget_showmode = variable_get('vud_node_widget_show', VUD_NODE_DISPLAY_BOTH);
$tag = variable_get('vud_tag', 'vote');
$widget = variable_get('vud_node_widget', 'plain');
$vote_on_teaser = (bool) variable_get('vud_node_widget_vote_on_teaser', TRUE);
$teaser = $a3;
$widget_message_code = VUD_WIDGET_MESSAGE_ERROR;
if (!$can_edit) {
$widget_message_code = VUD_WIDGET_MESSAGE_DENIED;
}
elseif (!$vote_on_teaser) {
$widget_message_code = VUD_NODE_WIDGET_MESSAGE_TEASER_DENIED;
}
if ($node_type) {
switch ($widget_showmode) {
case VUD_NODE_DISPLAY_TEASER_ONLY:
if ($teaser == 1) {
$node->content['vud_node_widget_display'] = array(
'#value' => theme('vud_widget', $node->nid, 'node', $tag, $widget, !$vote_on_teaser || !$can_edit, $widget_message_code),
'#weight' => -10,
);
}
break;
case VUD_NODE_DISPLAY_FULL_ONLY:
if ($teaser == 0) {
$node->content['vud_node_widget_display'] = array(
'#value' => theme('vud_widget', $node->nid, 'node', $tag, $widget, !$can_edit, $widget_message_code),
'#weight' => -10,
);
}
break;
case VUD_NODE_DISPLAY_BOTH:
if ($teaser == 1) {
$readonly = !$vote_on_teaser || !$can_edit;
}
else {
$readonly = !$can_edit;
}
$node->content['vud_node_widget_display'] = array(
'#value' => theme('vud_widget', $node->nid, 'node', $tag, $widget, $readonly, $widget_message_code),
'#weight' => -10,
);
break;
}
}
}
break;
}
}