function sendMessages($userId) { if ($userId == 0) { $userList = $this->_db->listUsers("", 0, 9999999); } else { $thisUser = $this->_db->getUser($userId); $userList['list'] = array($thisUser); } # else foreach ($userList['list'] as $user) { # Omdat we vanuit listUsers() niet alle velden meekrijgen # vragen we opnieuw het user record op $user = $this->_db->getUser($user['userid']); $security = new SpotSecurity($this->_db, $this->_settings, $user); $newMessages = $this->_db->getUnsentNotifications($user['userid']); foreach ($newMessages as $newMessage) { $objectId = $newMessage['objectid']; $spotweburl = ($this->_settings->get('spotweburl') == 'http://mijnuniekeservernaam/spotweb/') ? '' : $this->_settings->get('spotweburl'); $notifProviders = Notifications_Factory::getActiveServices(); foreach ($notifProviders as $notifProvider) { if ($user['prefs']['notifications'][$notifProvider]['enabled'] && $user['prefs']['notifications'][$notifProvider]['events'][$objectId]) { if ($security->allowed(SpotSecurity::spotsec_send_notifications_services, $notifProvider)) { $this->_notificationServices[$notifProvider] = Notifications_Factory::build('Spotweb', $notifProvider, $user['prefs']['notifications'][$notifProvider]); } # if } # if } # foreach # nu wordt het bericht pas echt verzonden foreach($this->_notificationServices as $notificationService) { $notificationService->sendMessage($newMessage['type'], $newMessage['title'], $newMessage['body'], $spotweburl); } # foreach # Alle services resetten, deze mogen niet hergebruikt worden $this->_notificationServices = array(); $this->_db->markNotificationSent($newMessage['id']); } # foreach message } # foreach user } # sendMessages
function sendMessages($userId) { if ($userId == 0) { $userList = $this->_db->listUsers("", 0, 9999999); } else { $thisUser = $this->_db->getUser($userId); $userList['list'] = array($thisUser); } # else foreach ($userList['list'] as $user) { # Omdat we vanuit listUsers() niet alle velden meekrijgen # vragen we opnieuw het user record op $user = $this->_db->getUser($user['userid']); $security = new SpotSecurity($this->_db, $this->_settings, $user); # Om e-mail te kunnen versturen hebben we iets meer data nodig $adminUsr = $this->_db->getUser(SPOTWEB_ADMIN_USERID); $user['prefs']['notifications']['email']['sender'] = $adminUsr['mail']; $user['prefs']['notifications']['email']['receiver'] = $user['mail']; # Twitter heeft ook extra settings nodig $user['prefs']['notifications']['twitter']['consumer_key'] = $this->_settings->get('twitter_consumer_key'); $user['prefs']['notifications']['twitter']['consumer_secret'] = $this->_settings->get('twitter_consumer_secret'); $newMessages = $this->_db->getUnsentNotifications($user['userid']); foreach ($newMessages as $newMessage) { $objectId = $newMessage['objectid']; $spotweburl = $this->_settings->get('spotweburl') == 'http://mijnuniekeservernaam/spotweb/' ? '' : $this->_settings->get('spotweburl'); $notifProviders = Notifications_Factory::getActiveServices(); foreach ($notifProviders as $notifProvider) { if ($user['prefs']['notifications'][$notifProvider]['enabled'] && $user['prefs']['notifications'][$notifProvider]['events'][$objectId]) { if ($security->allowed(SpotSecurity::spotsec_send_notifications_services, $notifProvider)) { $this->_notificationServices[$notifProvider] = Notifications_Factory::build('Spotweb', $notifProvider, $user['prefs']['notifications'][$notifProvider]); } # if } # if } # foreach # nu wordt het bericht pas echt verzonden foreach ($this->_notificationServices as $notificationService) { $notificationService->sendMessage($newMessage['type'], $newMessage['title'], $newMessage['body'], $spotweburl); } # foreach # Alle services resetten, deze mogen niet hergebruikt worden $this->_notificationServices = array(); # Als dit bericht ging over het aanmaken van een nieuwe user, verwijderen we # het plaintext wachtwoord uit de database uit veiligheidsoverwegingen. if ($objectId == SpotNotifications::notifytype_user_added) { $body = explode(" ", $newMessage['body']); $body[4] = '[deleted]'; $newMessage['body'] = implode(" ", $body); } # if $newMessage['sent'] = 1; $this->_db->updateNotification($newMessage); } # foreach message } # foreach user }