Exemple #1
0
 public static function getResponse($request)
 {
     require_once 'web/header.inc';
     require_once 'web/page.inc';
     require_once 'web/footer.inc';
     require_once 'template/TemplateManager.php';
     //inizio il conteggio delle query
     require_once 'session.php';
     Session::initializeQueryCounter();
     self::$user = Session::getUser();
     $data = self::elaborateRequest($request);
     if (self::$requestedObject == "Login") {
         self::redirect("");
     } else {
         if (self::$requestedObject == "Logout") {
             Session::destroy();
             self::redirect("");
         }
     }
     $default = TemplateManager::getDefaultTemplate();
     $parser = null;
     $tentativi = 0;
     while (is_numeric($parser) || is_null($parser)) {
         $template = TemplateManager::getTemplateForRequest(self::$requestedObject, self::$currentID, self::$requestedAction);
         if (is_numeric($parser) || is_null($template) || $template === false) {
             $template = $default;
         }
         if ($tentativi == 1) {
             echo "<h3>ERRORE IN " . $template . "</h3>";
         }
         if ($tentativi == 2) {
             echo "<h3>ERRORE NEL TEMPLATE DI DEFAULT</h3>";
             return;
         }
         $tentativi++;
         $parser = TemplateParser::parseTemplate($template);
         //echo "<p>" . serialize(is_numeric($parser)) . "</p>"; //DEBUG
     }
     //echo "parser creato: " . serialize($parser) . "<br />";  //DEBUG
     $css = array();
     $js = array();
     $title = self::titleForRequest($request);
     $cols_stack = array();
     $write_h = false;
     $write_f = false;
     $ad = false;
     //		$i=0; //DEBUG
     while ($el = $parser->nextElement()) {
         //			if($i==10) //DEBUG
         //				return; //DEBUG
         //			$i++; //DEBUG
         $id = null;
         $class = null;
         switch ($el["tag"]) {
             case "TEMPLATE":
                 break;
             case "HEAD":
                 if ($el["type"] != "close") {
                     continue;
                 }
                 writeHeader($title, $css, $js);
                 break;
             case "STYLESHEET":
                 if (isset($el["attributes"]["CSS"])) {
                     $c = $el["attributes"]["CSS"];
                     if ($c != "default/default") {
                         $css[] = $c;
                     }
                 }
                 break;
             case "JS":
                 if (isset($el["attributes"]["SRC"])) {
                     $js[] = $el["attributes"]["SRC"];
                 }
                 break;
             case "HEADER":
                 $write_h = true;
                 if ($el["type"] == "close") {
                     writePageHeader(self::$user, $ad);
                     $write_h = false;
                 }
                 break;
             case "FOOTER":
                 $write_f = true;
                 if ($el["type"] == "close" || $el["type"] == "complete") {
                     writePageFooter(null, $ad);
                     $write_f = false;
                 }
                 break;
             case "AD":
                 if ($write_h || $write_f) {
                     $ad = true;
                 } else {
                     $style = "default";
                     if (isset($el["attributes"]["STYLE"])) {
                         $style = $el["attributes"]["STYLE"];
                     }
                     writeAD($style);
                 }
                 break;
             case "CONTENT":
                 $id = "content";
             case "COL":
                 //echo "<p>element: " . serialize($el) . "</p>";  //DEBUG
             //echo "<p>element: " . serialize($el) . "</p>";  //DEBUG
             case "DIV":
                 //echo "<p>element: " . serialize($el) . "</p>";  //DEBUG
                 if ($el["type"] == "open" || $el["type"] == "complete") {
                     if (isset($el["attributes"]["COLS"])) {
                         $cols_stack[] = $el["attributes"]["COLS"];
                     } else {
                         $cols_stack[] = 1;
                     }
                     if (isset($el["attributes"]["ID"])) {
                         $id = $el["attributes"]["ID"];
                     }
                     if (isset($el["attributes"]["CLASS"])) {
                         $class = $el["attributes"]["CLASS"];
                     }
                     opendiv($class, $id);
                 }
                 if (isset($el["value"]) && $el["value"] != "\n") {
                     self::evaluateText($el["value"], $data);
                 }
                 if ($el["type"] == "close" || $el["type"] == "complete") {
                     if ($el["type"] == "close") {
                         unset($cols_stack[count($cols_stack) - 1]);
                     }
                     closediv();
                 }
                 break;
         }
         //echo "<p style='color:red;'>element: " . $el["tag"] . "</p>";  //DEBUG
     }
     writeFooter();
 }