You are here

function birthdays_cron in Birthdays 6

Same name and namespace in other branches
  1. 5 birthdays.module \birthdays_cron()
  2. 7 birthdays.module \birthdays_cron()

Implementation of hook_cron().

File

./birthdays.module, line 251
The Birthdays module allows users to add their birthday to their profile. It lists birthdays on a seperate page and in different blocks. Users can receive an e-mail on their birthday automatically, and the administrator can receive daily reminders of…

Code

function birthdays_cron() {
  global $_birthdays_field;

  // Either user mail or admin mail is activated, and the birthdays profile field has been set.
  if (isset($_birthdays_field) && (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) != BIRTHDAYS_USER_MAIL_NO || variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED) != BIRTHDAYS_ADMIN_MAIL_DISABLED)) {

    // Perform the check just once a day
    $time = time();
    if (variable_get('birthdays_last_cron', 0) <= $time - 24 * 3600) {

      // The message functions are now necessary, lets include them.
      module_load_include('inc', 'birthdays', 'birthdays.mail');

      // Reset time limit, round to nearest 100 seconds.
      variable_set('birthdays_last_cron', floor($time / 100) * 100);
      $remind_frequency = variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED);

      // Send user e-mails.
      _birthdays_send_user_message();

      // Send admin message if frequency is daily.
      if ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_DAILY) {
        _birthdays_send_admin_message(1);
      }
      elseif ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_WEEKLY && date('w', $time) == variable_get('date_first_day', 0)) {
        _birthdays_send_admin_message(7);
      }
      elseif ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_MONTHLY && date('j', $time) == 1) {
        _birthdays_send_admin_message(date('t', $time));
      }
    }
  }
}