You are here

userpoints_basic.module in User Points 5

Same filename and directory in other branches
  1. 5.3 userpoints_basic.module
  2. 5.2 userpoints_basic.module

File

userpoints_basic.module
View source
<?php

// Copyright 2005 Khalid Baheyeldin http://2bits.com
define('USERPOINTS_POST', 'userpoints_post_');
define('USERPOINTS_POST_COMMENT', 'userpoints_post_comment');
define('USERPOINTS_MODERATE_COMMENT', 'userpoints_moderate_comment');
function userpoints_basic_help($section) {
  switch ($section) {
    case 'admin/settings/userpoints_basic':
      $output = t('<strong>UP:</strong> Some basic interfaces for userpoints, such as posting nodes, comments, ...etc.');
      break;
  }
  return $output;
}
function userpoints_basic_userpoints($op, $points = 0, $uid = 0, $event = '') {
  switch ($op) {
    case 'setting':
      $group = 'basic';
      $form[$group] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('!Points for basic events', userpoints_translation()),
      );
      foreach (node_get_types() as $type => $name) {
        $form[$group][USERPOINTS_POST . $type] = array(
          '#type' => 'textfield',
          '#title' => t('!Points for posting a !node-name', array_merge(userpoints_translation(), array(
            '!node-name' => $name->name,
          ))),
          '#default_value' => variable_get(USERPOINTS_POST . $type, '0'),
          '#size' => 5,
          '#maxlength' => 5,
        );
      }
      $form[$group][USERPOINTS_POST_COMMENT] = array(
        '#type' => 'textfield',
        '#title' => t('!Points for posting a comment', userpoints_translation()),
        '#default_value' => variable_get(USERPOINTS_POST_COMMENT, 0),
        '#size' => 5,
        '#maxlength' => 5,
      );
      $form[$group][USERPOINTS_MODERATE_COMMENT] = array(
        '#type' => 'textfield',
        '#title' => t('!Points for moderating a comment', userpoints_translation()),
        '#default_value' => variable_get(USERPOINTS_MODERATE_COMMENT, 0),
        '#size' => 5,
        '#maxlength' => 5,
      );
      return $form;
      break;
  }
}
function userpoints_nodeapi(&$node, $op, $teaser, $page) {
  static $orig_uid;
  $points = variable_get(USERPOINTS_POST . $node->type, 0);
  switch ($op) {
    case 'insert':
      $points = $points;
      userpoints_userpointsapi('points', $points, $node->uid, $node->type);
      break;
    case 'delete':
      $points = -$points;
      userpoints_userpointsapi('points', $points, $node->uid, $node->type);
      break;
    case 'prepare':
      $orig_uid = $node->uid;
      break;
    case 'update':
      if ($node->uid != $orig_uid) {

        // Add to the new node owner
        userpoints_userpointsapi('points', $points, $node->uid, $node->type);

        // subtract from the original node owner
        $points = -$points;
        userpoints_userpointsapi('points', $points, $orig_uid, $node->type);
      }
      break;
  }
}
function userpoints_comment($comment, $op) {
  global $user;
  static $orig_uid;
  $points = variable_get(USERPOINTS_POST_COMMENT, 0);
  switch ($op) {
    case 'insert':
      userpoints_userpointsapi('points', $points, $user->uid, 'post comment');
      break;
    case 'delete':
      $points = -$points;
      userpoints_userpointsapi('points', $points, $comment->uid, 'post comment');
      break;
    case 'moderate':
      $points = variable_get(USERPOINTS_MODERATE_COMMENT, 0);
      userpoints_userpointsapi('points', $points, $comment->uid, 'moderate comment');
      break;
    case 'form':
      $orig_uid = $comment['uid']['#value'];
    case 'update':
      break;
  }
}