'vote', 'title' => t('vote on content'), 'callback' => 'simplevote_vote', 'access' => true, 'type' => MENU_CALLBACK); } return $items; } function simplevote_help($section) { switch ($section) { case 'admin/modules#description': return t('Adds a five-star vote widget to every node and comment.'); break; } } function simplevote_vote($type, $cid, $value) { // sanity-check the incoming values. if (is_numeric($cid) && is_numeric($value)) { if ($value > 100) { $value = 100; } $vote->value = $value; $vote->value_type = 'percent'; $vote->tag = VOTINGAPI_VALUE_DEFAULT_TAG; votingapi_set_vote($type, $cid, $vote); } drupal_goto(drupal_get_destination()); } function theme_simplevote_widget($cid, $type) { // Get the current vote. It should come in as a percentage, $vote = votingapi_get_voting_result($type, $cid, 'percent', VOTINGAPI_VALUE_DEFAULT_TAG, 'average'); if ($vote) { $stars = round($vote->value); } else { $stars = 0; } $output = '
' . t("Rating"); for ($i = 20; $i <= 100; $i += 20) { $output .= theme('simplevote_icon', $type, $cid, $i, $stars >= $i); } $output .= '
'; return $output; } function theme_simplevote_icon($type, $cid, $value, $filled) { global $user; $url = 'vote/' . $type . '/' . $cid . '/' . $value; if ($filled) { $class = 'vote-on'; } else { $class = 'vote-off'; } // If the user isn't logged in, show the vote but don't let them change it. // We do this by writing out a span with the same classes, rather than an tag. if ($user->uid == 0) { return ''; } else { return l('', $url, array('class' => $class), drupal_get_destination(), NULL, FALSE, TRUE); } } function theme_simplevote_css_path() { return drupal_get_path('module', 'simplevote') . '/theme/simplevote.css'; } function simplevote_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'view': if ($teaser == false) { $node->body = theme('simplevote_widget', $node->nid, 'node') . $node->body; } break; } } function simplevote_votingapi($vobj, $op, $arg3) { if ($op == 'format') { if ($vobj->value_type == 'percent') { switch ($arg3) { case 'value': $score = round($vobj->value / 20, 1); return $score . ' stars'; break; case 'result': switch ($vobj->function) { case 'average': $score = round($vobj->value / 20, 1); return $score . ' stars'; break; case 'count': return $vobj->value . ' votes'; break; } break; } } } } function simplevote_votingapi_action_sets() { $sets = array(); $set->name = 'SimpleVote promotion'; $set->content_type = 'node'; $set->required = TRUE; $set->mask = 'AND'; $set->enabled = 1; $set->source = 'SimpleVote'; // set up the conditions. this is pretty basic. $set->conditions = array(); $condition->handler = 'votingapi_vote_result_handler'; // Each handler requires its own data. $condition->value = array( 'function' => 'average', 'tags' => array('vote'), 'value' => array('>' => '50'), ); $set->conditions[] = $condition; // Set up the actions. Also very basic. $set->actions = array(); $set->actions[] = 'action_node_promote'; $sets[] = $set; return $sets; }