'subscriptions_mail.admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('_subscriptions_mail_purge_queue_form'), 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_cron(). * * Takes items from {subscriptions_queue} and generates notification emails. */ function subscriptions_mail_cron() { // set_time_limit(3600); drupal_set_message('DON\'T FORGET TO REMOVE THE TIME LIMIT EXTENSION!!!'); include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.cron.inc'; _subscriptions_mail_cron(); } /** * Return the 'From:' address to use for sending e-mail. */ function _subscriptions_mail_site_mail($address_only = FALSE) { $email = variable_get('subscriptions_site_mail', ''); if (empty($email)) { $email = variable_get('site_mail', ini_get('sendmail_from')); } if (!$address_only && ($name = variable_get('subscriptions_site_mail_name', FALSE))) { $email = '"'. $name .'" <'. $email .'>'; } return $email; } /** * Implementation of hook_form_alter(). * * Adds to the Mail templates form at admin/build/mail-edit if old D5 tables are found. */ function subscriptions_mail_form_mail_edit_list_form_alter(&$form, $form_state) { if (db_table_exists('subscriptions_mail_edit') || db_table_exists('mail_edit_d5') && db_result(db_query("SELECT COUNT(*) FROM {mail_edit_d5} WHERE mailkey LIKE 'subscriptions-%'")) > 0) { include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.mail_edit_D5.inc'; _subscriptions_mail_form_mail_edit_list_form_alter($form, $form_state); } } /** * Implementation of hook_form_alter(). * * Adds to the General Settings part at admin/settings/subscriptions. */ function subscriptions_mail_form_subscriptions_settings_form_alter(&$form, &$form_state) { include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.admin.inc'; _subscriptions_mail_form_subscriptions_settings_form_alter($form, $form_state); } /** * Form builder for the purge Subscriptions queue confirmation form. */ function _subscriptions_mail_purge_queue_form(&$form_state) { $form['#submit'][] = 'subscriptions_purge_queue'; return confirm_form($form, t('Are you sure you want to purge the !Module queue?', array('!Module' => 'Subscriptions')), array('path' => $_GET['destination'], 'fragment' => 'edit-purge-queue'), NULL, t('Purge the queue')); } /** * Purge the Subscriptions queue. */ function subscriptions_purge_queue() { db_query("DELETE FROM {subscriptions_queue}"); $variables = array('!Module' => 'Subscriptions', '%count' => db_affected_rows()); drupal_set_message(t('All %count items have been purged.', $variables)); $watchdog = 'watchdog'; // keep potx from translating 'cron' $watchdog('cron', t('!Module: all %count items have been purged.', $variables), NULL, WATCHDOG_WARNING); } /** * Implementation of hook_mailkeys(). * * Provide mailkeys for mail_edit. * * @ingroup hooks */ function subscriptions_mail_mailkeys() { $mailkeys['digest'] = t('Digest subscriptions notifications'); return $mailkeys; } /** * Implementation of hook_mail_edit_tokens_list(). * * Provide replacable tokens for mail_edit. * * @ingroup hooks */ function subscriptions_mail_mail_edit_tokens_list($mailkey, $options = array()) { //$tokens = module_invoke('subscriptions_content', 'mail_edit_tokens_list', $mailkey, $options); $tokens = subscriptions_mail_subscriptions_tokens_list($mailkey, $options); $tokens += array( '!bodies' => t('The digested items (separated by a separator), as defined below:'), ); return $tokens; } /** * Implementation of hook_subscriptions_tokens_list(). * * Provide replacable tokens for mail_edit. * mail_edit calls only the hook in the module that registered the mailkey, * but we call this hook function from there to add some common tokens. * * @ingroup hooks */ function subscriptions_mail_subscriptions_tokens_list($mailkey, $options = array()) { $tokens = array(); switch ($mailkey) { case 'digest': break; default: $tokens += array( '!site' => t('The name of the site.'), '!recipient_name' => t('The name of the recipient.'), ); if (module_exists('realname')) { $tokens += array( '!recipient_realname' => t('The real name of the recipient (provided by Realname module).'), ); } $tokens += array( '!recipient_page' => t('The user page of the recipient.'), '!manage_url' => t('The URL where the user can manage her subscriptions.'), '!recipient_uid' => t('The ID of the recipient.'), ); } if (isset($options['tokens'])) { $tokens += $options['tokens']; } return $tokens; } /** * Implementation of hook_mail_edit_text(). * * Provide default templates for mail_edit. * * @ingroup hooks */ function subscriptions_mail_mail_edit_text($mailkey, $language) { include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.templates.inc'; $return = array(); $return['subject'] = subscriptions_mail_template('DSUBJ', $language->language); $return['body'] = subscriptions_mail_template('DBODY', $language->language); return $return; } /** * Implementation of hook_subscriptions_mail_text(). * * Provide default templates for mail_edit. * * @ingroup hooks */ function subscriptions_mail_subscriptions_mail_text($mailkey, $language) { include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.templates.inc'; $return = array(); $return['subject'] = subscriptions_mail_template('SUBJ', $language->language); $return['body'] = subscriptions_mail_template('BODY', $language->language); return $return; } /** * Implementation of hook_form_alter(). * * Add the digest parts to the subscriptions_mail_digest mail_edit page. * * @ingroup hooks * @ingroup form */ function subscriptions_mail_form_mail_edit_trans_alter(&$form, &$form_state) { include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.admin.inc'; _subscriptions_mail_form_mail_edit_trans_alter($form, $form_state); } /** * Get the sanitized value of the 'subscriptions_cron_percent' variable. */ function subscriptions_mail_get_cron_percentage() { return max(array(0, intval(variable_get('subscriptions_cron_percent', 50)))); } /** * Check the $base_url and provide a warning if needed. */ function _subscriptions_mail_check_baseurl($interactive) { // Check the $base_url (#199039, #226335, #1015320). $url = url('', array('absolute' => TRUE)); if (empty($_POST) && preg_match('!//($|/|localhost/|([0-9]{1,3}\.){3}[0-9]{1,3}/)!', $url)) { $msg = t('Your installation returns %url as the base URL of the site. This is probably not what you want, and it can usually be fixed by setting the %variable variable in your %file file.', array('%url' => $url, '%variable' => '$base_url', '%file' => 'settings.php')); if ($interactive) { drupal_set_message($msg, 'error'); } else { $watchdog = 'watchdog'; // keep potx from translating 'cron' $watchdog('cron', $msg .' '. t('If it happens only when running from cron, then it could be due to a mis-configuration of your cron job.'), NULL, WATCHDOG_WARNING); } } }