Have content authors automatically vote

Last modified: July 31, 2009 - 05:58

Very simple module to have a user vote for content automatically as they create it. Have called this module autovote (autovote.module).

NB: D6 version here.

1. Create a directory under modules named autovote.

2. Put the following in autovote.module:

<?php

/**
* Implementation of hook_nodeapi()
*
* Vote on the node as it's saved.
*/
function autovote_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

 
/* Only vote on database inserts */
 
if ($op != 'insert') return;

 
/* Stop anonymous votes - don't if not logged in. */
 
global $user;
  if (!
$user->uid) return;

 
/* Don't vote if not new */
 
if (!$node->is_new) return;

 
/* Optionally filter content types - modify as you wish. */
  /* Eg. don't vote for anything but images. */
 
if ($node->type != 'image') return;

 
/* OK - let's vote */
 
votingapi_set_vote('node', $node->nid, 100, $user->uid);
}

?>

3. Put the following in autovote.info:

name = Autovote
description = "Have a user automatically vote for content as they create it."
package = Voting
version = "5.x-0.1"

4. Visit modules admin page and enable the new module.

 
 

Drupal is a registered trademark of Dries Buytaert.