Example #1
0
 public static function instance()
 {
     if (self::$manager == null) {
         self::$manager = new ScreenCacheManager();
     }
     return self::$manager;
 }
Example #2
0
 /**
  * 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;
 }
 public function process()
 {
     global $timeStart;
     // initialize logging service
     $logger = OzoneLogger::instance();
     $loggerFileOutput = new OzoneLoggerFileOutput();
     $loggerFileOutput->setLogFileName(WIKIDOT_ROOT . "/logs/ozone.log");
     $logger->addLoggerOutput($loggerFileOutput);
     $logger->setDebugLevel(GlobalProperties::$LOGGER_LEVEL);
     $logger->debug("request processing started, logger initialized");
     Ozone::init();
     $runData = new RunData();
     $runData->init();
     Ozone::setRunData($runData);
     $logger->debug("RunData object created and initialized");
     // handle session at the begging of procession
     $runData->handleSessionStart();
     $template = $runData->getScreenTemplate();
     $classFile = $runData->getScreenClassPath();
     $className = $runData->getScreenClassName();
     $logger->debug("processing template: " . $runData->getScreenTemplate() . ", class: {$className}");
     require_once $classFile;
     $screen = new $className();
     // screen security check
     if (!$screen->isAllowed($runData)) {
         if ($classFile == $runData->getScreenClassPath()) {
             $runData->setScreenTemplate("errors/NotAllowed");
         } else {
             // $screen->isAllowed() should set the error template!!! if not -
             // default NotAllowed is used
             // reload the class again - we do not want the unsecure screen to render!
             $classFile = $runData->getScreenClassPath();
             $className = $runData->getScreenClassName();
             $logger->debug("processing template: " . $runData->getScreenTemplate() . ", class: {$className}");
             require_once $classFile;
             $screen = new $className();
             $runData->setAction(null);
         }
     }
     $logger->info("Ozone engines successfully initialized");
     // caching of LAYOUT tasks should start here
     $cacheSettings = $screen->getScreenCacheSettings();
     $updateLayoutContentLater = false;
     if ($runData->getRequestMethod() == "GET" && $runData->getAction() == null && $cacheSettings != null && $cacheSettings->isLayoutCacheable($runData)) {
         $content = ScreenCacheManager::instance()->cachedLayout($runData, $screen->getScreenCacheSettings());
         if ($content != null && $content != "") {
             // process modules!!!
             // process modules...
             $moduleProcessor = new ModuleProcessor($runData);
             $out = $moduleProcessor->process($content);
             echo $out;
             $runData->handleSessionEnd();
             return;
         } else {
             $updateLayoutContentLater = true;
         }
     }
     // PROCESS ACTION
     $actionClass = $runData->getAction();
     $logger->debug("processing action {$actionClass}");
     while ($actionClass != null) {
         require_once PathManager::actionClass($actionClass);
         $tmpa1 = explode('/', $actionClass);
         $actionClassStripped = end($tmpa1);
         $action = new $actionClassStripped();
         $classFile = $runData->getScreenClassPath();
         if (!$action->isAllowed($runData)) {
             if ($classFile == $runData->getScreenClassPath()) {
                 $runData->setScreenTemplate("errors/NotAllowed");
             }
             // $action->isAllowed() should set the error template!!! if not -
             // default NotAllowed is used
             break;
         }
         $actionEvent = $runData->getActionEvent();
         if ($actionEvent != null) {
             $action->{$actionEvent}($runData);
             $logger->debug("processing action: {$actionClass}, event: {$actionEvent}");
         } else {
             $logger->debug("processing action: {$actionClass}");
             $action->perform($runData);
         }
         // this is in case action changes the action name so that
         // the next action can be executed.
         if ($runData->getNextAction() != null) {
             $actionClass = $runData->getNextAction();
             $runData->setAction($actionClass);
             $runData->setActionEvent($runData->getNextActionEvent());
         } else {
             $actionClass = null;
         }
     }
     // end action process
     // check if template has been changed by the action. if so...
     if ($template != $runData->getScreenTemplate) {
         $classFile = $runData->getScreenClassPath();
         $className = $runData->getScreenClassName();
         $logger->debug("processing template: " . $runData->getScreenTemplate() . ", class: {$className}");
         require_once $classFile;
         $screen = new $className();
     }
     $rendered = $screen->render($runData);
     if ($rendered != null) {
         // process modules...
         $moduleProcessor = new ModuleProcessor($runData);
         $out = $moduleProcessor->process($rendered);
     }
     if ($updateLayoutContentLater == true) {
         ScreenCacheManager::instance()->updateCachedLayout($runData, $rendered);
     }
     $runData->handleSessionEnd();
     echo $out;
 }