public function build($runData)
 {
     $userId = $runData->getUserId();
     $pl = $runData->getParameterList();
     $pageNumber = $pl->getParameterValue("page");
     if ($pageNumber == null || !is_numeric($pageNumber) || $pageNumber < 1) {
         $pageNumber = 1;
     }
     // now just get notifications for the user...
     $perPage = 30;
     $offset = ($pageNumber - 1) * $perPage;
     $count = $perPage * 2 + 1;
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->addOrderDescending('notification_id');
     $c->setLimit($count, $offset);
     $nots = DB_NotificationPeer::instance()->select($c);
     // now see if number of selected is equal $perPage + 1. If so -
     // there is at least 1 more page to show...
     $counted = count($nots);
     $pagerData = array();
     $pagerData['current_page'] = $pageNumber;
     if ($counted > $perPage * 2) {
         $knownPages = $pageNumber + 2;
         $pagerData['known_pages'] = $knownPages;
     } elseif ($counted > $perPage) {
         $knownPages = $pageNumber + 1;
         $pagerData['total_pages'] = $knownPages;
     } else {
         $totalPages = $pageNumber;
         $pagerData['total_pages'] = $totalPages;
     }
     $nots = array_slice($nots, 0, $perPage);
     $runData->contextAdd("pagerData", $pagerData);
     $runData->contextAdd("notifications", $nots);
 }
 public function build($runData)
 {
     $user = $runData->getTemp("user");
     $userId = $user->getUserId();
     // set language for the user
     $lang = $user->getLanguage();
     $runData->setLanguage($lang);
     $GLOBALS['lang'] = $lang;
     // and for gettext too:
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             break;
         case 'en':
             $glang = "en_US";
             break;
     }
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
     // now just get notifications for the user...
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->addOrderDescending('notification_id');
     $c->setLimit(20);
     $nots = DB_NotificationPeer::instance()->select($c);
     $channel['title'] = sprintf(_('%s account notifications for user'), GlobalProperties::$SERVICE_NAME) . ' "' . htmlspecialchars($user->getNickName()) . '"';
     $channel['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/notifications";
     $items = array();
     foreach ($nots as $not) {
         $extra = $not->getExtra();
         $item = array();
         $item['title'] = $not->getTitle();
         switch ($not->getType()) {
             case "new_private_message":
                 $item['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/messages/inboxmessage/" . $extra['message_id'];
                 break;
             case "new_membership_invitation":
                 $item['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/invitations";
                 break;
             case 'membership_application_accepted':
                 $item['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/applications";
                 break;
             case 'membership_application_declined':
                 $item['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/applications";
                 break;
             default:
                 $item['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/notifications" . "#notification-" . $not->getNotificationId();
         }
         $body = $not->getBody();
         $body = preg_replace('/onclick="[^"]+"/', '', $body);
         $item['description'] = $body;
         $item['guid'] = $channel['link'] . "#notification-" . $not->getNotificationId();
         $item['date'] = date('r', $not->getDate()->getTimestamp());
         // TODO: replace relative links with absolute links!
         $content = '';
         $items[] = $item;
     }
     $runData->contextAdd("channel", $channel);
     $runData->contextAdd("items", $items);
 }
Esempio n. 3
0
 public function handleUser($user)
 {
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("notify_email", true);
     $c->addOrderAscending("notification_id");
     $nots = DB_NotificationPeer::instance()->select($c);
     if (count($nots) == 0) {
         $db->commit();
         return;
     }
     if (count($nots) > 0) {
         $q = "UPDATE notification SET notify_email=FALSE " . "WHERE user_id='" . $user->getUserId() . "' AND " . "notify_email = TRUE";
         $db->query($q);
     }
     // set language
     $lang = $user->getLanguage();
     OZONE::getRunData()->setLanguage($lang);
     $GLOBALS['lang'] = $lang;
     // and for gettext too:
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             break;
         case 'en':
             $glang = "en_US";
             break;
     }
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
     $nots2 = array();
     foreach ($nots as &$not) {
         if ($not->getType() == "new_private_message") {
             // check if the message is read or still new
             $extra = $not->getExtra();
             $pm = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($extra['message_id']);
             if ($pm && $pm->getFlagNew()) {
                 $body = $not->getBody();
                 $body = preg_replace('/<br\\/>Preview.*$/sm', '', $body);
                 $body = preg_replace(';You have.*?<br/>;sm', '', $body);
                 $not->setBody($body);
                 $nots2[] = $not;
             }
         } else {
             $nots2[] = $not;
         }
     }
     $count = count($nots2);
     // now send an email
     $oe = new OzoneEmail();
     $oe->addAddress($user->getName());
     $oe->setSubject(sprintf(_("%s Account Notifications"), GlobalProperties::$SERVICE_NAME));
     $oe->contextAdd('user', $user);
     $oe->contextAdd('notifications', $nots2);
     $oe->contextAdd('count', $count);
     $oe->setBodyTemplate('DigestEmail');
     if (!$oe->send()) {
         throw new ProcessException("The email can not be sent to address " . $user->getName(), "email_failed");
     }
     $db->commit();
 }
Esempio n. 4
0
 private function handleNotifications($runData)
 {
     // check not earlier than 2 minutes after the previous check
     $user = $runData->getUser();
     if ($user == null) {
         return;
     }
     // get last check date
     $lastCheck = $_COOKIE['lastncheck'];
     if ($lastCheck !== null && is_numeric($lastCheck) && time() - $lastCheck < 120) {
         return;
     }
     $cookieResult = setcookie('lastncheck', time(), time() + 10000000, "/", GlobalProperties::$SESSION_COOKIE_DOMAIN);
     // ok. go get the notifications now.
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("notify_online", true);
     $c->addOrderDescending("notification_id");
     $nots = DB_NotificationPeer::instance()->select($c);
     if (count($nots) == 0) {
         return;
     }
     if (count($nots) > 0) {
         $q = "UPDATE notification SET notify_online=FALSE, notify_email=FALSE " . "WHERE user_id='" . $user->getUserId() . "' AND " . "notify_online = TRUE";
         $db = Database::connection();
         $db->query($q);
     }
     $nots2 = array();
     foreach ($nots as &$not) {
         if ($not->getType() == "new_private_message") {
             // check if the message is read or still new
             $extra = $not->getExtra();
             $pm = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($extra['message_id']);
             if ($pm && $pm->getFlagNew()) {
                 $body = $not->getBody();
                 $body = preg_replace('/<br\\/>Preview.*$/sm', '', $body);
                 $body = preg_replace(';You have.*?<br/>;sm', '', $body);
                 $not->setBody($body);
                 $nots2[] = $not;
             }
         } else {
             $nots2[] = $not;
         }
     }
     if (count($nots2) == 0) {
         return;
     }
     $lang = $user->getLanguage();
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             $wp = "pl";
             break;
         case 'en':
             $glang = "en_US";
             $wp = "www";
             break;
     }
     $runData->setLanguage($lang);
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
     // get Smarty and render a dialog
     $smarty = Ozone::getSmartyPlain();
     $dialogTemplateFile = PathManager::screenTemplate("NotificationDialog");
     $count = count($nots2);
     if ($count > 3) {
         $nots2 = array_slice($nots2, 0, 3);
         $smarty->assign("more", $count - 3);
     }
     $smarty->assign("count", $count);
     $smarty->assign("notifications", $nots2);
     $out = $smarty->fetch($dialogTemplateFile);
     $this->vars['notificationsDialog'] = $out;
     $lang = $GLOBALS['lang'];
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             break;
         case 'en':
             $glang = "en_US";
             break;
     }
     $runData->setLanguage($lang);
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
 }