sqlite = $db_helper->getDB(); } public function addUsersToCron() { /** @var DokuWiki_Auth_Plugin $auth */ global $auth; $res = $this->sqlite->query('SELECT user from cron_check'); $ourUsers = $this->sqlite->res2arr($res); $ourUsers = array_map(function ($item) { return $item['user']; }, $ourUsers); $allUsers = array_keys($auth->retrieveUsers()); $newUsers = array_diff($allUsers, $ourUsers); if (!is_array($newUsers) || $newUsers === []) return; foreach ($newUsers as $user) { $this->sqlite->storeEntry( 'cron_check', ['user' => $user, 'timestamp' => date('c', 0)] ); } } /** * Gather notification data from plugins * * @param string $user * @return array */ public function getNotificationData($user) { $plugins = []; $event = new Event('PLUGIN_NOTIFICATION_REGISTER_SOURCE', $plugins); $event->trigger(); $notifications_data = [ 'plugins' => $plugins, 'user' => $user, 'notifications' => [] ]; $event = new Event('PLUGIN_NOTIFICATION_GATHER', $notifications_data); $event->trigger(); if (!empty($notifications_data['notifications'])) { $notifications = $notifications_data['notifications']; // get only notifications that have ids $notifications_data['notifications'] = array_filter($notifications, function ($notification) { return array_key_exists('id', $notification); }); } return $notifications_data; } /** * Prune old (already sent) notifications and return only new ones * * @param string $user * @param array $notification_data * @return array */ public function getNewNotifications($user, $notification_data) { /** @var \helper_plugin_notification_db $db_helper */ $db_helper = plugin_load('helper', 'notification_db'); $sqlite = $db_helper->getDB(); $notifications = $notification_data['notifications']; $plugins = $notification_data['plugins']; //get the notifications that have been sent already $res = $sqlite->query('SELECT plugin, notification_id FROM notification WHERE user=?', $user); $sent_notifications = $sqlite->res2arr($res); $sent_notifications_by_plugin = []; foreach ($plugins as $plugin) { $sent_notifications_by_plugin[$plugin] = []; } foreach ($sent_notifications as $sent_notification) { $plugin = $sent_notification['plugin']; $id = $sent_notification['notification_id']; $sent_notifications_by_plugin[$plugin][$id] = true; } // keep only notifications not yet sent $new_notifications = []; foreach ($notifications as $notification) { $plugin = $notification['plugin']; $id = $notification['id']; if (!isset($sent_notifications_by_plugin[$plugin][$id])) { $new_notifications[] = $notification; } } return $new_notifications; } /** * Create text and HTML components of email message * * @param array $new_notifications * @return string[] */ public function composeEmail($new_notifications) { $html = '
' . $this->getLang('mail content') . '
'; $html .= '