You are here

function fivestar_nodeapi in Fivestar 5

Same name and namespace in other branches
  1. 6.2 fivestar.module \fivestar_nodeapi()
  2. 6 fivestar.module \fivestar_nodeapi()

Implementation of hook_nodeapi().

Adds the fievestar widget to the node view.

File

./fivestar.module, line 850
A simple n-star voting widget, usable in other forms.

Code

function fivestar_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'view':
      if ($node->in_preview == FALSE && !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, 'vote', $node->type),
              '#weight' => strpos($position, 'above') === 0 ? -10 : 50,
            );
            break;
          default:

            // We'll do nothing.
            break;
        }
      }
      break;
  }
}