You are here

shoutbox_rules.module in Shoutbox 7.2

Includes any rules integration provided by shoutbox.

File

shoutbox_rules/shoutbox_rules.module
View source
<?php

/**
 * RULES INTEGRATION - EVENTS
 */

/**
 * @file Includes any rules integration provided by shoutbox.
 */

/**
 * Implements hook_rules_event_info().
 */
function shoutbox_rules_event_info() {
  $defaults = array(
    'group' => t('Shoutbox'),
    'module' => 'shoutbox',
  );
  $items = array(
    'shoutbox_insert' => $defaults + array(
      'label' => t('After adding a shout'),
      'variables' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('Shoutbox message actor'),
        ),
        'shout_message' => array(
          'type' => 'shoutbox_message',
          'label' => t('Shoutbox message'),
        ),
      ),
    ),
    'shoutbox_edit' => $defaults + array(
      'label' => t('After updating a shout'),
      'variables' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('The user who edited the shout.'),
        ),
        'shout_message' => array(
          'type' => 'shoutbox_message',
          'label' => t('updated shoutbox message'),
        ),
      ),
    ),
    'shoutbox_publish' => $defaults + array(
      'label' => t('After a shout has been published'),
      'variabless' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('The user who published the shout.'),
        ),
        'shout_message' => array(
          'type' => 'shoutbox_message',
          'label' => t('The shout text that was published.'),
        ),
      ),
    ),
    'shoutbox_unpublish' => $defaults + array(
      'label' => t('After a shout has been unpublished'),
      'variables' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('The user who unpublished the shout.'),
        ),
        'shout_message' => array(
          'type' => 'shoutbox_message',
          'label' => t('The shout text that was unpublished.'),
        ),
      ),
    ),
    'shoutbox_delete' => $defaults + array(
      'label' => t('After a shout has been deleted'),
      'variables' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('The user who deleted the shout.'),
        ),
        'shout_message' => array(
          'type' => 'shoutbox_message',
          'label' => t('The shout text that was deleted.'),
        ),
      ),
    ),
  );
  return $items;
}

/**
 * Implements hook_rules_data_info().
 */
function shoutbox_rules_data_info() {
  return array(
    'shoutbox_message' => array(
      'label' => t('Shoutbox'),
      'group' => t('Shoutbox'),
    ),
  );
}

// TODO: Reintroduce shoutbox action
// when version 2.0 is created and shouts
// become entities.
//

/**
 * Implements hook_shoutbox().().
 */
function shoutbox_rules_shoutbox($op, &$shout, &$a1 = NULL, $form_state = NULL) {
  global $user;

  // expose some shoutbox events to Rules
  if (in_array($op, array(
    'insert',
    'edit',
    'unpublish',
    'publish',
    'delete',
  ))) {
    rules_invoke_event('shoutbox_' . $op, $user->uid, $shout);
  }
}