You are here

function shoutbox_cron in Shoutbox 7.2

Same name and namespace in other branches
  1. 5 shoutbox.module \shoutbox_cron()
  2. 6.2 shoutbox.module \shoutbox_cron()
  3. 6 shoutbox.module \shoutbox_cron()
  4. 7 shoutbox.module \shoutbox_cron()

Implements hook_cron().

File

./shoutbox.module, line 156
Shoutbox module displays a block for users to create short messages for the whole site. Uses AHAH to update the database and display content.

Code

function shoutbox_cron() {
  $expiration = variable_get('shoutbox_expire', 0);

  // Check if expiration is turned on.
  if ($expiration > 0) {

    // Fetch shouts that have passed the expiration date.
    $expiration_val = REQUEST_TIME - 60 * 60 * 24 * $expiration;
    $query = db_select('shoutbox', 's')
      ->fields('s')
      ->condition('s.created', $expiration_val, '<');

    // $shouts = db_query("SELECT * FROM {shoutbox} WHERE created < :created", array(':created' => REQUEST_TIME - (60 * 60 * 24 * $expiration)));
    // while ($shout = db_fetch_object($shouts)) {
    $result = $query
      ->execute();
    foreach ($result as $shout) {

      // Delete the shout.
      shoutbox_delete_shout($shout);
    }
  }
}