function fivestar_nodeapi in Fivestar 6.2
Same name and namespace in other branches
- 5 fivestar.module \fivestar_nodeapi()
- 6 fivestar.module \fivestar_nodeapi()
Implementation of hook_nodeapi().
Adds the fievestar widget to the node view.
File
- ./
fivestar.module, line 496 - A simple n-star voting widget, usable in other forms.
Code
function fivestar_nodeapi(&$node, $op, $teaser, $page) {
if ($op == 'view') {
$exclude_modes = array(
NODE_BUILD_PREVIEW,
NODE_BUILD_SEARCH_INDEX,
NODE_BUILD_SEARCH_RESULT,
NODE_BUILD_RSS,
);
if (!in_array($node->build_mode, array(
NODE_BUILD_PREVIEW,
NODE_BUILD_SEARCH_INDEX,
)) && !isset($node->modr8_form_teaser) && fivestar_widget_enabled('fivestar_' . $node->type)) {
foreach (fivestar_get_tags() as $tag) {
$position = fivestar_get_position($node->type, $teaser, $tag);
switch ($position) {
case 'above':
case 'below':
if (user_access('rate content')) {
$content = '';
if (fivestar_validate_target('node', $node->nid, $tag)) {
$content .= fivestar_widget_form($node, $tag);
}
if ($content) {
$node->content['fivestar_widget_' . $tag] = array(
'#value' => $content,
'#weight' => $position == 'above' ? -10 : 50,
);
}
// Fall through to static if not allowed to rate.
}
break;
$position .= '_static';
case 'above_static':
case 'below_static':
$content = '';
if (fivestar_validate_target('node', $node->nid, $tag)) {
$content .= fivestar_static('node', $node->nid, $node->type, $tag);
}
}
if ($content) {
$node->content['fivestar_widget_' . $tag] = array(
'#value' => $content,
'#weight' => strpos($position, 'above') === 0 ? -10 : 50,
);
}
}
}
}
}