You are here

shoutbox_points.module in Shoutbox 7

File

shoutbox_points/shoutbox_points.module
View source
<?php

/**
 * Implements hook_userpoints().
 */
function shoutbox_points_userpoints($op, $params = array()) {
  switch ($op) {
    case 'setting':
      $form['shoutbox'] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('!Points for posting shouts', userpoints_translation()),
      );
      $form['shoutbox']['shoutbox_points_delete_points'] = array(
        '#type' => 'checkbox',
        '#title' => t('Take away !points on shout delete', array_merge(userpoints_translation())),
        '#default_value' => variable_get('shoutbox_points_delete_points', 1),
      );
      $form['shoutbox']['shoutbox_points_amount'] = array(
        '#type' => 'textfield',
        '#title' => t('!Points for posting a shout', array_merge(userpoints_translation())),
        '#default_value' => variable_get('shoutbox_points_amount', '0'),
        '#size' => 5,
        '#maxlength' => 5,
      );
      return $form;
  }
}

/**
 * Implements hook_shoutbox().
 */
function shoutbox_points_shoutbox($op, &$shout, &$a1 = NULL, $form_state = NULL) {

  // If this shout was anonymous, points can't be handled
  if (!isset($shout->uid)) {
    return;
  }
  switch ($op) {
    case 'insert':
      if ($points = variable_get('shoutbox_points_amount', '0')) {
        $params = array(
          'points' => $points,
          'uid' => $shout->uid,
          'operation' => t('shouted'),
          'entity_id' => $shout->shout_id,
          'entity_type' => t('shout'),
          'display' => FALSE,
        );
        userpoints_userpointsapi($params);
      }
      break;
    case 'delete':
      if (variable_get('shoutbox_points_delete_points', 1)) {
        if ($points = variable_get('shoutbox_points_amount', '0')) {
          $params = array(
            'points' => $points * -1,
            'uid' => $shout->uid,
            'operation' => t('shout removed'),
            'entity_id' => $shout->shout_id,
            'entity_type' => t('shout'),
            'display' => FALSE,
          );
          userpoints_userpointsapi($params);
        }
      }
      break;
  }
}

Functions

Namesort descending Description
shoutbox_points_shoutbox Implements hook_shoutbox().
shoutbox_points_userpoints Implements hook_userpoints().