Example #1
0
 /**
  * print either html or xml content given oModule object
  * @remark addon execution and the trigger execution are included within this method, which might create inflexibility for the fine grained caching
  * @param ModuleObject $oModule the module object
  * @return void
  */
 public function printContent(&$oModule)
 {
     // Check if the gzip encoding supported
     if (config('view.use_gzip') && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && extension_loaded('zlib') && $oModule->gzhandler_enable) {
         $this->gz_enabled = TRUE;
     }
     // Extract contents to display by the request method
     if (Context::get('xeVirtualRequestMethod') == 'xml') {
         $handler = new VirtualXMLDisplayHandler();
     } elseif (Context::getRequestMethod() == 'JSON' || isset($_POST['_rx_ajax_compat'])) {
         $handler = new JSONDisplayHandler();
     } elseif (Context::getRequestMethod() == 'JS_CALLBACK') {
         $handler = new JSCallbackDisplayHandler();
     } elseif (Context::getRequestMethod() == 'XMLRPC') {
         $handler = new XMLDisplayHandler();
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
             $this->gz_enabled = FALSE;
         }
     } else {
         $handler = new HTMLDisplayHandler();
     }
     $output = $handler->toDoc($oModule);
     // call a trigger before display
     ModuleHandler::triggerCall('display', 'before', $output);
     $original_output = $output;
     // execute add-on
     $called_position = 'before_display_content';
     $oAddonController = getController('addon');
     $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
     if (file_exists($addon_file)) {
         include $addon_file;
     }
     if ($output === false || $output === null || $output instanceof Object) {
         $output = $original_output;
     }
     if (method_exists($handler, "prepareToPrint")) {
         $handler->prepareToPrint($output);
     }
     // Start the session if $_SESSION was touched
     Context::checkSessionStatus();
     // header output
     $httpStatusCode = $oModule->getHttpStatusCode();
     if ($httpStatusCode !== 200 && !in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON', 'JS_CALLBACK'))) {
         self::_printHttpStatusCode($httpStatusCode);
     } else {
         if (Context::getResponseMethod() == 'JSON' || Context::getResponseMethod() == 'JS_CALLBACK') {
             if (strpos($_SERVER['HTTP_ACCEPT'], 'json') !== false) {
                 self::_printJSONHeader();
             }
         } else {
             if (Context::getResponseMethod() != 'HTML') {
                 self::_printXMLHeader();
             } else {
                 self::_printHTMLHeader();
             }
         }
     }
     // disable gzip if output already exists
     while (ob_get_level()) {
         ob_end_flush();
     }
     if (headers_sent()) {
         $this->gz_enabled = FALSE;
     }
     // enable gzip using zlib extension
     if ($this->gz_enabled) {
         ini_set('zlib.output_compression', true);
     }
     // call a trigger after display
     self::$response_size = $this->content_size = strlen($output);
     ModuleHandler::triggerCall('display', 'after', $output);
     // Output the page content and debug data.
     $debug = $this->getDebugInfo($output);
     print $output;
     print $debug;
 }