function render() { # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_send_notifications_services, 'twitter'); # Instantieer het Spot user system & notificatiesysteem $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings); $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $this->_currentSession); $requestArray = array_merge_recursive($this->_currentSession['user']['prefs']['notifications']['twitter'], array('consumer_key' => $this->_settings->get('twitter_consumer_key'), 'consumer_secret' => $this->_settings->get('twitter_consumer_secret'))); if ($this->_params['action'] == 'verify') { $this->_notificationService = Notifications_Factory::build('Spotweb', 'twitter', $requestArray); # een foute PIN invoeren geeft een notice, terwijl we zonder notice al een prima foutafhandeling hebben list($http_code, $access_token) = @$this->_notificationService->verifyPIN($this->_params['pin']); if ($http_code == 200) { # request_token hebben we niet meer nodig $this->_currentSession['user']['prefs']['notifications']['twitter']['request_token'] = ''; $this->_currentSession['user']['prefs']['notifications']['twitter']['request_token_secret'] = ''; # access_token is wat we wel willen opslaan $this->_currentSession['user']['prefs']['notifications']['twitter']['screen_name'] = $access_token['screen_name']; $this->_currentSession['user']['prefs']['notifications']['twitter']['access_token'] = $access_token['oauth_token']; $this->_currentSession['user']['prefs']['notifications']['twitter']['access_token_secret'] = $access_token['oauth_token_secret']; $spotUserSystem->setUser($this->_currentSession['user']); echo "Account " . $access_token['screen_name'] . " geverifiëerd."; } else { echo "Code " . $http_code . ": " . $this->getError($http_code); } # if } elseif ($this->_params['action'] == 'remove') { $screen_name = $this->_currentSession['user']['prefs']['notifications']['twitter']['screen_name']; $this->_currentSession['user']['prefs']['notifications']['twitter']['screen_name'] = ''; $this->_currentSession['user']['prefs']['notifications']['twitter']['access_token'] = ''; $this->_currentSession['user']['prefs']['notifications']['twitter']['access_token_secret'] = ''; $spotUserSystem->setUser($this->_currentSession['user']); echo "Account " . $screen_name . " verwijderd."; } else { $this->_notificationService = Notifications_Factory::build('Spotweb', 'twitter', $requestArray); list($http_code, $request_token, $registerURL) = @$this->_notificationService->requestAuthorizeURL(); if ($http_code == 200) { # request_token slaan we op in de preferences, deze hebben we # weer nodig wanneer de PIN wordt ingevoerd $this->_currentSession['user']['prefs']['notifications']['twitter']['request_token'] = $request_token['oauth_token']; $this->_currentSession['user']['prefs']['notifications']['twitter']['request_token_secret'] = $request_token['oauth_token_secret']; $spotUserSystem->setUser($this->_currentSession['user']); echo $registerURL; } else { echo "Code " . $http_code . ": " . $this->getError($http_code); } # if } # if }
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 }