View source
<?php
function message_digest_cron() {
foreach (message_notify_get_notifiers() as $plugin_name => $plugin) {
if (strpos($plugin_name, 'digest') === FALSE) {
continue;
}
$plugin = message_notify_get_notifier($plugin_name);
$class = ctools_plugin_load_class('message_notify', 'notifier', $plugin_name, 'class');
$notifier = new $class($plugin, new Message());
$interval = $notifier
->getInterval();
$last_run = variable_get('message_digest_' . $interval . '_last_run', 0);
if ($last_run > strtotime("-" . $interval)) {
continue;
}
$digests = $notifier
->aggregate();
foreach ($digests as $uid => $groups) {
foreach ($groups as $gid => $messages) {
$context = array(
'uid' => $uid,
'gid' => $gid,
'view_modes' => $plugin['view_modes'],
'deliver' => TRUE,
'plugin' => $plugin,
'messages' => $messages,
);
drupal_alter('message_digest_view_mode', $context);
if ($context['deliver']) {
$formatted_messages = $notifier
->format($context['messages'], $context['view_modes']);
$result = $notifier
->deliverDigest($uid, $context['gid'], $formatted_messages);
}
}
$notifier
->markSent($uid, $plugin_name);
}
variable_set('message_digest_' . $interval . '_last_run', time());
}
}
function message_digest_mail($key, &$message, $params) {
if ($key == 'digest') {
$title = variable_get('site_name', 'Open Atrium');
if (!empty($params['gid'])) {
$group = node_load($params['gid']);
$title = $group->title;
}
$message['subject'] = $title . t(' Message Digest');
$message['body'][] = $params['body'];
}
}
function message_digest_ctools_plugin_api($module, $api) {
if ($module == 'message_notify' && $api == 'notifier') {
return array(
'version' => 1,
);
}
}
function message_digest_ctools_plugin_directory($module, $plugin) {
if ($module == 'message_notify') {
return 'plugins/' . $plugin;
}
}
function message_digest_theme() {
return array(
'message_digest' => array(
'variables' => array(
'messages' => NULL,
'plugin' => NULL,
),
),
'message_digest_row' => array(
'variables' => array(
'rows' => NULL,
'plugin' => NULL,
'message' => NULL,
),
),
);
}
function theme_message_digest($vars) {
return implode("\n<hr />", $vars['messages']);
}
function theme_message_digest_row($vars) {
return implode($vars['rows']);
}