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 }
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
public function getSpotComments($msgId, $userId, $start, $length, $language) { # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_comments, ''); $svcNntpSpotReading = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($this->_settings, 'hdr')); $svcProvComments = new Services_Providers_Comments($this->_daoFactory->getCommentDao(), $svcNntpSpotReading); $tryTranslate = Services_Actions_GetComments::nativeLanguage !== $language; /* * Basically we are retrieving the comments from the database, for them to be translated * if necessary */ $comments = $svcProvComments->fetchSpotComments($msgId, $userId, $start, $length); if (!$tryTranslate) { return $comments; } # if /* * In our cache, we store an key => value pair with the original string and * the translation, so we can do very quick lookups. */ $toBeTranslated = array(); $translated = $this->_cacheDao->getCachedTranslatedComments($msgId, $language); if ($translated === false) { $translated = array(); } # if foreach ($comments as &$comment) { $tmpBody = $comment['body']; if (isset($translated[$tmpBody])) { $comment['body_translated'] = $translated[$tmpBody]; } else { $toBeTranslated[] = $comment; } # else } # foreach /* * Actually translate our list of comments, and merge * them with the actual comments */ if (!empty($toBeTranslated)) { $svcTranslate = new Services_Translation_Microsoft($this->_settings, $this->_cacheDao); if (!$svcTranslate->isAvailable()) { return $comments; } # if $translations = $svcTranslate->translateMultiple($language, $toBeTranslated, 'body'); /* * copy the translations into the cache */ if (!empty($translations)) { foreach ($translations as $v) { $tmpBody = $v['body']; $translated[$tmpBody] = $v['body_translated']; } # foreach /* * Convert the comments once again */ foreach ($comments as &$comment) { $tmpBody = $comment['body']; if (isset($translated[$tmpBody])) { $comment['body_translated'] = $translated[$tmpBody]; } # else } # foreach } # if /* * and save the translated bodies into the cache */ $this->_cacheDao->saveTranslatedCommentCache($msgId, $language, $translated); } # if return $comments; }