function fivestar_nodeapi in Fivestar 6
Same name and namespace in other branches
- 5 fivestar.module \fivestar_nodeapi()
- 6.2 fivestar.module \fivestar_nodeapi()
Implementation of hook_nodeapi().
Adds the fievestar widget to the node view.
File
- ./
fivestar.module, line 917 - A simple n-star voting widget, usable in other forms.
Code
function fivestar_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
$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) && !isset($node->modr8_form_teaser) && variable_get('fivestar_' . $node->type, 0)) {
if ($teaser) {
$position = variable_get('fivestar_position_teaser_' . $node->type, 'above');
}
else {
$position = variable_get('fivestar_position_' . $node->type, 'above');
}
switch ($position) {
case 'above':
case 'below':
if (user_access('rate content') && fivestar_validate_target('node', $node->nid)) {
$node->content['fivestar_widget'] = array(
'#value' => fivestar_widget_form($node),
'#weight' => $position == 'above' ? -10 : 50,
);
break;
}
// Fall through to static if not allowed to rate.
$position .= '_static';
case 'above_static':
case 'below_static':
$stars = variable_get('fivestar_stars_' . $node->type, 5);
$node->content['fivestar_widget'] = array(
'#value' => fivestar_static('node', $node->nid, NULL, $node->type),
'#weight' => strpos($position, 'above') === 0 ? -10 : 50,
);
break;
default:
// We'll do nothing.
break;
}
}
break;
}
}