mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
251 lines
6.2 KiB
PHP
251 lines
6.2 KiB
PHP
<?php
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
|
|
|
/**
|
|
* @class DisplayHandler
|
|
* @author NAVER (developers@xpressengine.com)
|
|
* DisplayHandler is responsible for displaying the execution result. \n
|
|
* Depending on the request type, it can display either HTML or XML content.\n
|
|
* Xml content is simple xml presentation of variables in oModule while html content
|
|
* is the combination of the variables of oModue and template files/.
|
|
*/
|
|
class DisplayHandler extends Handler
|
|
{
|
|
|
|
var $content_size = 0; // /< The size of displaying contents
|
|
var $gz_enabled = FALSE; // / <a flog variable whether to call contents after compressing by gzip
|
|
var $handler = NULL;
|
|
|
|
/**
|
|
* 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::getInstance()->checkSessionStatus();
|
|
|
|
// header output
|
|
|
|
$httpStatusCode = $oModule->getHttpStatusCode();
|
|
if($httpStatusCode && $httpStatusCode != 200)
|
|
{
|
|
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
|
|
ob_flush();
|
|
if(headers_sent())
|
|
{
|
|
$this->gz_enabled = FALSE;
|
|
}
|
|
|
|
// enable gzip using zlib extension
|
|
if($this->gz_enabled)
|
|
{
|
|
ini_set('zlib.output_compression', true);
|
|
}
|
|
|
|
// results directly output
|
|
print $output;
|
|
|
|
// debugOutput output
|
|
$this->content_size = strlen($output);
|
|
print $this->getDebugInfo();
|
|
|
|
// call a trigger after display
|
|
ModuleHandler::triggerCall('display', 'after', $output);
|
|
|
|
flushSlowlog();
|
|
}
|
|
|
|
/**
|
|
* Get debug information.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getDebugInfo()
|
|
{
|
|
// Check if debugging is enabled for this request.
|
|
if (!config('debug.enabled'))
|
|
{
|
|
return;
|
|
}
|
|
$display_to = config('debug.display_to');
|
|
switch ($display_to)
|
|
{
|
|
case 'everyone':
|
|
break;
|
|
|
|
case 'ip':
|
|
$allowed_ip = config('debug.allow');
|
|
foreach ($allowed_ip as $range)
|
|
{
|
|
if (Rhymix\Framework\IpFilter::inRange(RX_CLIENT_IP, $range))
|
|
{
|
|
break 2;
|
|
}
|
|
}
|
|
return;
|
|
|
|
case 'admin':
|
|
default:
|
|
$logged_info = Context::get('logged_info');
|
|
if ($logged_info && $logged_info->is_admin === 'Y')
|
|
{
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Set some useful variables.
|
|
$basedir_len = strlen(RX_BASEDIR);
|
|
$timestamp = sprintf('[%s]', Rhymix\Framework\DateTime::formatTimestampForCurrentUser('Y-m-d H:i:s P', RX_TIME));
|
|
|
|
// Collect debug information.
|
|
$entries = Rhymix\Framework\Debug::getEntries();
|
|
$errors = config('debug.log_errors') ? Rhymix\Framework\Debug::getErrors() : null;
|
|
$queries = config('debug.log_queries') ? Rhymix\Framework\Debug::getQueries() : null;
|
|
|
|
// Print debug information.
|
|
switch ($display_type = config('debug.display_type'))
|
|
{
|
|
case 'panel':
|
|
break;
|
|
|
|
case 'comment':
|
|
case 'file':
|
|
default:
|
|
if ($display_type === 'comment' && Context::getResponseMethod() !== 'HTML')
|
|
{
|
|
return;
|
|
}
|
|
ob_start();
|
|
include RX_BASEDIR . 'common/tpl/debug_comment.html';
|
|
$content = ob_get_clean();
|
|
if ($display_type === 'file')
|
|
{
|
|
$debug_file = RX_BASEDIR . 'files/_debug_message.php';
|
|
FileHandler::writeFile($debug_file, $content, 'a');
|
|
return '';
|
|
}
|
|
else
|
|
{
|
|
return '<!--' . PHP_EOL . $content . PHP_EOL . '-->';
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* print a HTTP HEADER for XML, which is encoded in UTF-8
|
|
* @return void
|
|
*/
|
|
public static function _printXMLHeader()
|
|
{
|
|
header("Content-Type: text/xml; charset=UTF-8");
|
|
}
|
|
|
|
/**
|
|
* print a HTTP HEADER for HTML, which is encoded in UTF-8
|
|
* @return void
|
|
*/
|
|
public static function _printHTMLHeader()
|
|
{
|
|
header("Content-Type: text/html; charset=UTF-8");
|
|
}
|
|
|
|
/**
|
|
* print a HTTP HEADER for JSON, which is encoded in UTF-8
|
|
* @return void
|
|
*/
|
|
public static function _printJSONHeader()
|
|
{
|
|
header("Content-Type: text/javascript; charset=UTF-8");
|
|
}
|
|
|
|
/**
|
|
* print a HTTP HEADER for HTML, which is encoded in UTF-8
|
|
* @return void
|
|
*/
|
|
public static function _printHttpStatusCode($code)
|
|
{
|
|
$statusMessage = Context::get('http_status_message');
|
|
header("HTTP/1.0 $code $statusMessage");
|
|
}
|
|
|
|
}
|
|
/* End of file DisplayHandler.class.php */
|
|
/* Location: ./classes/display/DisplayHandler.class.php */
|