Exemplo n.º 1
0
 /**
  * Show the loaded contents using the template engine
  *
  * @param string $content Content to display
  */
 public function display(midgardmvc_core_request $request, $return_output = false)
 {
     $data = $request->get_data();
     $template_file = $this->midgardmvc->cache->template->get($request->get_template_identifier());
     $fp = fopen($template_file, 'r');
     flock($fp, LOCK_SH);
     $content = stream_get_contents($fp);
     fclose($fp);
     if (strlen($content) == 0) {
         throw new midgardmvc_exception('Template from "' . $template_file . '" is empty!');
     }
     if ($this->midgardmvc->configuration->services_templating_engine == 'tal') {
         $content = $this->display_tal($request, $content, $data);
     }
     // TODO: Support for other templating engines like Smarty or plain PHP
     if (isset($data['cache_enabled']) && $data['cache_enabled']) {
         ob_start();
     }
     /*$filters = $this->midgardmvc->configuration->get('output_filters');
       if ($filters)
       {
           foreach ($filters as $filter)
           {
               foreach ($filter as $component => $method)
               {
                   $instance = $this->midgardmvc->component->get($component);
                   if (!$instance)
                   {
                       continue;
                   }
                   $content = $instance->$method($content);
               }
           }
       }*/
     if ($return_output) {
         return $content;
     } else {
         echo $content;
     }
     if (isset($data['cache_enabled']) && $data['cache_enabled']) {
         // Store the contents to content cache and display them
         $this->midgardmvc->cache->content->put($this->midgardmvc->context->cache_request_identifier, ob_get_contents());
         ob_end_flush();
     }
     if ($this->midgardmvc->configuration->enable_uimessages) {
         // TODO: Connect this to some signal that tells the Midgard MVC execution has ended.
         $this->midgardmvc->uimessages->store();
     }
 }