Exemplo n.º 1
0
/**
 * Macro calling method for Smarty.
 */
function smarty_function_macro($params, &$smarty)
{
    if ($params['name'] == '') {
        $smarty->trigger_error("macro: missing attribute 'name' for the macro");
        return;
    }
    ## get macro file name
    $templateFilename = $smarty->getMacroTemplateFileName($params['name']);
    if ($templateFilename == null) {
        $smarty->trigger_error("macro: template file for the macro missing");
        return;
    }
    // get new smarty instance to process the template:
    $subSmarty = Ozone::getSmartyPlain();
    unset($params['name']);
    $subSmarty->assign('params', $params);
    foreach ($params as $key => $value) {
        $subSmarty->assign($key, $value);
    }
    ## copy the macro register
    $subSmarty->setMacroRegister($smarty->getMacroRegister());
    #render the content
    $out = $subSmarty->fetch(PathManager::smartyMacroTemplateDir() . "/" . $templateFilename);
    return $out;
}
Exemplo n.º 2
0
 public function render($runData)
 {
     if ($runData->getModuleTemplate() == null) {
         return;
     }
     $this->build($runData);
     $template = $runData->getModuleTemplate();
     $templateFile = PathManager::moduleTemplate($template);
     // render!
     $smarty = Ozone::getSmartyPlain();
     $page = $runData->getPage();
     $smarty->assign("page", $page);
     // put context into context
     $context = $runData->getContext();
     if ($context !== null) {
         foreach ($context as $key => $value) {
             $smarty->assign($key, $value);
         }
     }
     // 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);
     }
     $out = $smarty->fetch($templateFile);
     return $out;
 }
Exemplo n.º 3
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');
 }