/** * This method renders the page. * */ public function render($runData) { ## render! if ($runData->getScreenTemplate() == null || $runData->getPage()->getLayout() == null) { return null; } $smarty = Ozone::getSmarty(); $templateFile = PathManager::screenTemplate($runData->getScreenTemplate()); ////////// $updateLayoutContentLater = false; $mainContent = null; if (!file_exists($templateFile)) { // some error please! $runData->setScreenTemplate("DefaultError"); $runData->addErrorMessage("Taka strona nie istnieje."); $templateFile = PathManager::screenTemplate($runData->getScreenTemplate()); } else { // process the cache!!! $cacheSettings = $this->getScreenCacheSettings(); if ($runData->getRequestMethod() == "GET" && $runData->getAction() == null && $cacheSettings != null && $cacheSettings->isScreenCacheable($runData)) { $content = ScreenCacheManager::instance()->cachedScreen($runData, $this->getScreenCacheSettings()); if ($content != null && $content != "") { $mainContent = $content; } else { $updateScreenContentLater = true; // run user's method "build" $this->build($runData); } // cache end!!! (for now...) } else { // run user's method "build" $this->build($runData); } } // repeat in case sceen template has changed... $templateFile = PathManager::screenTemplate($runData->getScreenTemplate()); // put context into context $context = $runData->getContext(); if ($context !== null) { foreach ($context as $key => $value) { $smarty->assign($key, $value); } } $page = $runData->getPage(); $smarty->assign("page", $page); // put errorMessages and messages into the smarty's context as well. $dataMessages = $runData->getMessages(); $dataErrorMessages = $runData->getErrorMessages(); if (count($dataMessages) > 0) { $smarty->assign('data_messages', $dataMessages); } if (count($dataErrorMessages) > 0) { $smarty->assign('data_errorMessages', $dataErrorMessages); } if ($mainContent == null) { $mainContent = $smarty->fetch($templateFile); } if ($updateScreenContentLater) { // update the cached content in the database ScreenCacheManager::instance()->updateCachedScreen($runData, $mainContent); } $layoutFile = PathManager::layoutTemplate($page->getLayout()); $smarty->assign("screen_placeholder", $mainContent); $page->setStyleSelector(1); $out = $smarty->fetch($layoutFile); return $out; }
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'); }