issue 2119. supporting php 5.4. display classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12687 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-04 09:48:05 +00:00
parent 41fdaf00c3
commit 1de3e9cd17
6 changed files with 258 additions and 117 deletions

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @class DisplayHandler * @class DisplayHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -9,9 +10,10 @@
*/ */
class DisplayHandler extends Handler class DisplayHandler extends Handler
{ {
var $content_size = 0; // /< The size of displaying contents 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 $gz_enabled = FALSE; // / <a flog variable whether to call contents after compressing by gzip
var $handler = null; var $handler = NULL;
/** /**
* print either html or xml content given oModule object * print either html or xml content given oModule object
@ -24,13 +26,17 @@ class DisplayHandler extends Handler
// Check if the gzip encoding supported // Check if the gzip encoding supported
if( if(
(defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1) && (defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1) &&
strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')!==false && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE &&
function_exists('ob_gzhandler') && function_exists('ob_gzhandler') &&
extension_loaded('zlib') && extension_loaded('zlib') &&
$oModule->gzhandler_enable $oModule->gzhandler_enable
) $this->gz_enabled = true; )
{
$this->gz_enabled = TRUE;
}
// Extract contents to display by the request method // Extract contents to display by the request method
if(Context::get('xeVirtualRequestMethod')=='xml') if(Context::get('xeVirtualRequestMethod') == 'xml')
{ {
require_once("./classes/display/VirtualXMLDisplayHandler.php"); require_once("./classes/display/VirtualXMLDisplayHandler.php");
$handler = new VirtualXMLDisplayHandler(); $handler = new VirtualXMLDisplayHandler();
@ -39,7 +45,10 @@ class DisplayHandler extends Handler
{ {
require_once("./classes/display/XMLDisplayHandler.php"); require_once("./classes/display/XMLDisplayHandler.php");
$handler = new XMLDisplayHandler(); $handler = new XMLDisplayHandler();
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) $this->gz_enabled = false; if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
$this->gz_enabled = FALSE;
}
} }
else if(Context::getRequestMethod() == 'JSON') else if(Context::getRequestMethod() == 'JSON')
{ {
@ -58,38 +67,65 @@ class DisplayHandler extends Handler
} }
$output = $handler->toDoc($oModule); $output = $handler->toDoc($oModule);
// call a trigger before display // call a trigger before display
ModuleHandler::triggerCall('display', 'before', $output); ModuleHandler::triggerCall('display', 'before', $output);
// execute add-on // execute add-on
$called_position = 'before_display_content'; $called_position = 'before_display_content';
$oAddonController = &getController('addon'); $oAddonController = &getController('addon');
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone()?"mobile":"pc"); $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
@include($addon_file); @include($addon_file);
if(method_exists($handler, "prepareToPrint")) $handler->prepareToPrint($output); if(method_exists($handler, "prepareToPrint"))
{
$handler->prepareToPrint($output);
}
// header output // header output
if($this->gz_enabled) header("Content-Encoding: gzip"); if($this->gz_enabled)
{
header("Content-Encoding: gzip");
}
$httpStatusCode = $oModule->getHttpStatusCode(); $httpStatusCode = $oModule->getHttpStatusCode();
if($httpStatusCode && $httpStatusCode != 200) $this->_printHttpStatusCode($httpStatusCode); if($httpStatusCode && $httpStatusCode != 200)
{
$this->_printHttpStatusCode($httpStatusCode);
}
else else
{ {
if(Context::getResponseMethod() == 'JSON' || Context::getResponseMethod() == 'JS_CALLBACK') $this->_printJSONHeader(); if(Context::getResponseMethod() == 'JSON' || Context::getResponseMethod() == 'JS_CALLBACK')
else if(Context::getResponseMethod() != 'HTML') $this->_printXMLHeader(); {
else $this->_printHTMLHeader(); $this->_printJSONHeader();
}
else if(Context::getResponseMethod() != 'HTML')
{
$this->_printXMLHeader();
}
else
{
$this->_printHTMLHeader();
}
} }
// debugOutput output // debugOutput output
$this->content_size = strlen($output); $this->content_size = strlen($output);
$output .= $this->_debugOutput(); $output .= $this->_debugOutput();
// results directly output // results directly output
if($this->gz_enabled) print ob_gzhandler($output, 5); if($this->gz_enabled)
else print $output; {
print ob_gzhandler($output, 5);
}
else
{
print $output;
}
// call a trigger after display // call a trigger after display
ModuleHandler::triggerCall('display', 'after', $content); ModuleHandler::triggerCall('display', 'after', $content);
} }
/** /**
* Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n * Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n
* This method only functions when __DEBUG__ variable is set to 1. * This method only functions when __DEBUG__ variable is set to 1.
@ -98,14 +134,21 @@ class DisplayHandler extends Handler
*/ */
function _debugOutput() function _debugOutput()
{ {
if(!__DEBUG__) return; if(!__DEBUG__)
{
return;
}
$end = getMicroTime(); $end = getMicroTime();
// Firebug console output // Firebug console output
if(__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '6.0.0') === -1) if(__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '6.0.0') === -1)
{ {
static $firephp; static $firephp;
if(!isset($firephp)) $firephp = FirePHP::getInstance(true); if(!isset($firephp))
{
$firephp = FirePHP::getInstance(true);
}
if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR'])
{ {
@ -116,36 +159,39 @@ class DisplayHandler extends Handler
if(__DEBUG__ & 2) if(__DEBUG__ & 2)
{ {
$firephp->fb( $firephp->fb(
array('Request / Response info >>> '.$_SERVER['REQUEST_METHOD'].' / '.Context::getResponseMethod(), array(
'Request / Response info >>> ' . $_SERVER['REQUEST_METHOD'] . ' / ' . Context::getResponseMethod(),
array( array(
array('Request URI', 'Request method', 'Response method', 'Response contents size'), array('Request URI', 'Request method', 'Response method', 'Response contents size'),
array( array(
sprintf("%s:%s%s%s%s", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']), sprintf("%s:%s%s%s%s", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING'] ? '?' : '', $_SERVER['QUERY_STRING']),
$_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_METHOD'],
Context::getResponseMethod(), Context::getResponseMethod(),
$this->content_size.' byte' $this->content_size . ' byte'
)
) )
), )
),
'TABLE' 'TABLE'
); );
$firephp->fb( $firephp->fb(
array('Elapsed time >>> Total : '.sprintf('%0.5f sec', $end - __StartTime__), array(
'Elapsed time >>> Total : ' . sprintf('%0.5f sec', $end - __StartTime__),
array(array('DB queries', 'class file load', 'Template compile', 'XmlParse compile', 'PHP', 'Widgets', 'Trans Content'), array(array('DB queries', 'class file load', 'Template compile', 'XmlParse compile', 'PHP', 'Widgets', 'Trans Content'),
array( array(
sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']), sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']),
sprintf('%0.5f sec', $GLOBALS['__elapsed_class_load__']), sprintf('%0.5f sec', $GLOBALS['__elapsed_class_load__']),
sprintf('%0.5f sec (%d called)', $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']), sprintf('%0.5f sec (%d called)', $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']),
sprintf('%0.5f sec', $GLOBALS['__xmlparse_elapsed__']), sprintf('%0.5f sec', $GLOBALS['__xmlparse_elapsed__']),
sprintf('%0.5f sec', $end-__StartTime__-$GLOBALS['__template_elapsed__']-$GLOBALS['__xmlparse_elapsed__']-$GLOBALS['__db_elapsed_time__']-$GLOBALS['__elapsed_class_load__']), sprintf('%0.5f sec', $end - __StartTime__ - $GLOBALS['__template_elapsed__'] - $GLOBALS['__xmlparse_elapsed__'] - $GLOBALS['__db_elapsed_time__'] - $GLOBALS['__elapsed_class_load__']),
sprintf('%0.5f sec', $GLOBALS['__widget_excute_elapsed__']), sprintf('%0.5f sec', $GLOBALS['__widget_excute_elapsed__']),
sprintf('%0.5f sec', $GLOBALS['__trans_content_elapsed__']) sprintf('%0.5f sec', $GLOBALS['__trans_content_elapsed__'])
)
) )
), )
),
'TABLE' 'TABLE'
); );
} }
// display DB query history // display DB query history
if((__DEBUG__ & 4) && $GLOBALS['__db_queries__']) if((__DEBUG__ & 4) && $GLOBALS['__db_queries__'])
{ {
@ -156,11 +202,11 @@ class DisplayHandler extends Handler
} }
$firephp->fb( $firephp->fb(
array( array(
'DB Queries >>> '.count($GLOBALS['__db_queries__']).' Queries, '.sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']), 'DB Queries >>> ' . count($GLOBALS['__db_queries__']) . ' Queries, ' . sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']),
$queries_output $queries_output
), ),
'TABLE' 'TABLE'
); );
} }
// dislpay the file and HTML comments // dislpay the file and HTML comments
} }
@ -173,24 +219,29 @@ class DisplayHandler extends Handler
{ {
return; return;
} }
// Request/Response information // Request/Response information
$buff .= "\n- Request/ Response info\n"; $buff .= "\n- Request/ Response info\n";
$buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']); $buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING'] ? '?' : '', $_SERVER['QUERY_STRING']);
$buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']); $buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']);
$buff .= sprintf("\tResponse method \t\t: %s\n", Context::getResponseMethod()); $buff .= sprintf("\tResponse method \t\t: %s\n", Context::getResponseMethod());
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->content_size); $buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->content_size);
// total execution time // total execution time
$buff .= sprintf("\n- Total elapsed time : %0.5f sec\n", $end-__StartTime__); $buff .= sprintf("\n- Total elapsed time : %0.5f sec\n", $end - __StartTime__);
$buff .= sprintf("\tclass file load elapsed time \t: %0.5f sec\n", $GLOBALS['__elapsed_class_load__']); $buff .= sprintf("\tclass file load elapsed time \t: %0.5f sec\n", $GLOBALS['__elapsed_class_load__']);
$buff .= sprintf("\tTemplate compile elapsed time\t: %0.5f sec (%d called)\n", $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']); $buff .= sprintf("\tTemplate compile elapsed time\t: %0.5f sec (%d called)\n", $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']);
$buff .= sprintf("\tXmlParse compile elapsed time\t: %0.5f sec\n", $GLOBALS['__xmlparse_elapsed__']); $buff .= sprintf("\tXmlParse compile elapsed time\t: %0.5f sec\n", $GLOBALS['__xmlparse_elapsed__']);
$buff .= sprintf("\tPHP elapsed time \t\t: %0.5f sec\n", $end-__StartTime__-$GLOBALS['__template_elapsed__']-$GLOBALS['__xmlparse_elapsed__']-$GLOBALS['__db_elapsed_time__']-$GLOBALS['__elapsed_class_load__']); $buff .= sprintf("\tPHP elapsed time \t\t: %0.5f sec\n", $end - __StartTime__ - $GLOBALS['__template_elapsed__'] - $GLOBALS['__xmlparse_elapsed__'] - $GLOBALS['__db_elapsed_time__'] - $GLOBALS['__elapsed_class_load__']);
$buff .= sprintf("\tDB class elapsed time \t\t: %0.5f sec\n", $GLOBALS['__dbclass_elapsed_time__'] -$GLOBALS['__db_elapsed_time__']); $buff .= sprintf("\tDB class elapsed time \t\t: %0.5f sec\n", $GLOBALS['__dbclass_elapsed_time__'] - $GLOBALS['__db_elapsed_time__']);
// widget execution time // widget execution time
$buff .= sprintf("\n\tWidgets elapsed time \t\t: %0.5f sec", $GLOBALS['__widget_excute_elapsed__']); $buff .= sprintf("\n\tWidgets elapsed time \t\t: %0.5f sec", $GLOBALS['__widget_excute_elapsed__']);
// layout execution time // layout execution time
$buff .= sprintf("\n\tLayout compile elapsed time \t: %0.5f sec", $GLOBALS['__layout_compile_elapsed__']); $buff .= sprintf("\n\tLayout compile elapsed time \t: %0.5f sec", $GLOBALS['__layout_compile_elapsed__']);
// Widgets, the editor component replacement time // Widgets, the editor component replacement time
$buff .= sprintf("\n\tTrans Content \t\t\t: %0.5f sec\n", $GLOBALS['__trans_content_elapsed__']); $buff .= sprintf("\n\tTrans Content \t\t\t: %0.5f sec\n", $GLOBALS['__trans_content_elapsed__']);
} }
@ -222,6 +273,7 @@ class DisplayHandler extends Handler
} }
} }
} }
// Output in HTML comments // Output in HTML comments
if($buff && __DEBUG_OUTPUT__ == 1 && Context::getResponseMethod() == 'HTML') if($buff && __DEBUG_OUTPUT__ == 1 && Context::getResponseMethod() == 'HTML')
{ {
@ -232,18 +284,23 @@ class DisplayHandler extends Handler
$buff = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php'; $buff = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php';
} }
return "<!--\r\n".$buff."\r\n-->"; return "<!--\r\n" . $buff . "\r\n-->";
} }
// Output to a file // Output to a file
if($buff && __DEBUG_OUTPUT__ == 0) if($buff && __DEBUG_OUTPUT__ == 0)
{ {
$debug_file = _XE_PATH_.'files/_debug_message.php'; $debug_file = _XE_PATH_ . 'files/_debug_message.php';
$buff = sprintf("[%s %s:%d]\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($buff, true)); $buff = sprintf("[%s %s:%d]\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($buff, true));
$buff = str_repeat('=', 40)."\n".$buff.str_repeat('-', 40); $buff = str_repeat('=', 40) . "\n" . $buff . str_repeat('-', 40);
$buff = "\n<?php\n/*".$buff."*/\n?>\n"; $buff = "\n<?php\n/*" . $buff . "*/\n?>\n";
if(@!$fp = fopen($debug_file, 'a'))
{
return;
}
if(@!$fp = fopen($debug_file, 'a')) return;
fwrite($fp, $buff); fwrite($fp, $buff);
fclose($fp); fclose($fp);
} }
@ -264,7 +321,6 @@ class DisplayHandler extends Handler
header("Pragma: no-cache"); header("Pragma: no-cache");
} }
/** /**
* print a HTTP HEADER for HTML, which is encoded in UTF-8 * print a HTTP HEADER for HTML, which is encoded in UTF-8
* @return void * @return void
@ -279,7 +335,6 @@ class DisplayHandler extends Handler
header("Pragma: no-cache"); header("Pragma: no-cache");
} }
/** /**
* print a HTTP HEADER for JSON, which is encoded in UTF-8 * print a HTTP HEADER for JSON, which is encoded in UTF-8
* @return void * @return void
@ -294,7 +349,6 @@ class DisplayHandler extends Handler
header("Pragma: no-cache"); header("Pragma: no-cache");
} }
/** /**
* print a HTTP HEADER for HTML, which is encoded in UTF-8 * print a HTTP HEADER for HTML, which is encoded in UTF-8
* @return void * @return void
@ -304,6 +358,7 @@ class DisplayHandler extends Handler
$statusMessage = Context::get('http_status_message'); $statusMessage = Context::get('http_status_message');
header("HTTP/1.0 $code $statusMessage"); header("HTTP/1.0 $code $statusMessage");
} }
} }
/* End of file DisplayHandler.class.php */ /* End of file DisplayHandler.class.php */
/* Location: ./classes/display/DisplayHandler.class.php */ /* Location: ./classes/display/DisplayHandler.class.php */

View file

@ -1,6 +1,8 @@
<?php <?php
class HTMLDisplayHandler class HTMLDisplayHandler
{ {
/** /**
* Produce HTML compliant content given a module object.\n * Produce HTML compliant content given a module object.\n
* @param ModuleObject $oModule the module object * @param ModuleObject $oModule the module object
@ -8,7 +10,7 @@ class HTMLDisplayHandler
*/ */
function toDoc(&$oModule) function toDoc(&$oModule)
{ {
$oTemplate = &TemplateHandler::getInstance(); $oTemplate = TemplateHandler::getInstance();
// compile module tpl // compile module tpl
// deprecated themes skin // deprecated themes skin
@ -17,32 +19,36 @@ class HTMLDisplayHandler
if(!is_dir($template_path)) if(!is_dir($template_path))
{ {
if ($oModule->module_info->module == $oModule->module) if($oModule->module_info->module == $oModule->module)
$skin = $oModule->origin_module_info->skin;
else
$skin = $oModule->module_config->skin;
if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin') === false)
{ {
if ($skin && is_string($skin)) $skin = $oModule->origin_module_info->skin;
}
else
{
$skin = $oModule->module_config->skin;
}
if(Context::get('module') != 'admin' && strpos(Context::get('act'), 'Admin') === false)
{
if($skin && is_string($skin))
{ {
$theme_skin = explode('|@|', $skin); $theme_skin = explode('|@|', $skin);
$template_path = $oModule->getTemplatePath(); $template_path = $oModule->getTemplatePath();
if(count($theme_skin) == 2) if(count($theme_skin) == 2)
{ {
$theme_path = sprintf('./themes/%s',$theme_skin[0]); $theme_path = sprintf('./themes/%s', $theme_skin[0]);
if(substr($theme_path,0,strlen($theme_path)) != $theme_path) if(substr($theme_path, 0, strlen($theme_path)) != $theme_path)
{ {
$template_path = sprintf('%s/modules/%s/', $theme_path, $theme_skin[1]); $template_path = sprintf('%s/modules/%s/', $theme_path, $theme_skin[1]);
} }
} }
} }
else else
{ {
$template_path = $oModule->getTemplatePath(); $template_path = $oModule->getTemplatePath();
} }
} }
else else
{ {
$template_path = $oModule->getTemplatePath(); $template_path = $oModule->getTemplatePath();
} }
@ -55,11 +61,17 @@ class HTMLDisplayHandler
// add .x div for adminitration pages // add .x div for adminitration pages
if(Context::getResponseMethod() == 'HTML') if(Context::getResponseMethod() == 'HTML')
{ {
if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin')>0) $output = '<div class="x">'.$output.'</div>'; if(Context::get('module') != 'admin' && strpos(Context::get('act'), 'Admin') > 0)
{
$output = '<div class="x">' . $output . '</div>';
}
if(Context::get('layout') != 'none') if(Context::get('layout') != 'none')
{ {
if(__DEBUG__==3) $start = getMicroTime(); if(__DEBUG__ == 3)
{
$start = getMicroTime();
}
Context::set('content', $output, false); Context::set('content', $output, false);
@ -69,7 +81,7 @@ class HTMLDisplayHandler
$edited_layout_file = $oModule->getEditedLayoutFile(); $edited_layout_file = $oModule->getEditedLayoutFile();
// get the layout information currently requested // get the layout information currently requested
$oLayoutModel = &getModel('layout'); $oLayoutModel = getModel('layout');
$layout_info = Context::get('layout_info'); $layout_info = Context::get('layout_info');
$layout_srl = $layout_info->layout_srl; $layout_srl = $layout_info->layout_srl;
@ -87,10 +99,19 @@ class HTMLDisplayHandler
// search if the changes CSS exists in the admin layout edit window // search if the changes CSS exists in the admin layout edit window
$edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl); $edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl);
if(file_exists($edited_layout_css)) Context::loadFile(array($edited_layout_css,'all','',100)); if(file_exists($edited_layout_css))
{
Context::loadFile(array($edited_layout_css, 'all', '', 100));
}
}
if(!$layout_path)
{
$layout_path = './common/tpl';
}
if(!$layout_file)
{
$layout_file = 'default_layout';
} }
if(!$layout_path) $layout_path = './common/tpl';
if(!$layout_file) $layout_file = 'default_layout';
$output = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file); $output = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file);
// if popup_layout, remove admin bar. // if popup_layout, remove admin bar.
@ -108,9 +129,12 @@ class HTMLDisplayHandler
Context::set('admin_bar', 'false'); Context::set('admin_bar', 'false');
} }
if(__DEBUG__==3) $GLOBALS['__layout_compile_elapsed__'] = getMicroTime()-$start; if(__DEBUG__ == 3)
{
$GLOBALS['__layout_compile_elapsed__'] = getMicroTime() - $start;
}
if(preg_match('/MSIE/i',$_SERVER['HTTP_USER_AGENT']) && (Context::get('_use_ssl') == 'optional' || Context::get('_use_ssl') == 'always')) if(preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT']) && (Context::get('_use_ssl') == 'optional' || Context::get('_use_ssl') == 'always'))
{ {
Context::addHtmlFooter('<iframe id="xeTmpIframe" name="xeTmpIframe" style="width:1px;height:1px;position:absolute;top:-2px;left:-2px;"></iframe>'); Context::addHtmlFooter('<iframe id="xeTmpIframe" name="xeTmpIframe" style="width:1px;height:1px;position:absolute;top:-2px;left:-2px;"></iframe>');
} }
@ -126,21 +150,27 @@ class HTMLDisplayHandler
*/ */
function prepareToPrint(&$output) function prepareToPrint(&$output)
{ {
if(Context::getResponseMethod() != 'HTML') return; if(Context::getResponseMethod() != 'HTML')
{
return;
}
if(__DEBUG__==3) $start = getMicroTime(); if(__DEBUG__ == 3)
{
$start = getMicroTime();
}
// move <style ..></style> in body to the header // move <style ..></style> in body to the header
$output = preg_replace_callback('!<style(.*?)>(.*?)<\/style>!is', array($this,'_moveStyleToHeader'), $output); $output = preg_replace_callback('!<style(.*?)>(.*?)<\/style>!is', array($this, '_moveStyleToHeader'), $output);
// move <link ..></link> in body to the header // move <link ..></link> in body to the header
$output = preg_replace_callback('!<link(.*?)/>!is', array($this,'_moveLinkToHeader'), $output); $output = preg_replace_callback('!<link(.*?)/>!is', array($this, '_moveLinkToHeader'), $output);
// move <meta ../> in body to the header // move <meta ../> in body to the header
$output = preg_replace_callback('!<meta(.*?)(?:\/|)>!is', array($this,'_moveMetaToHeader'), $output); $output = preg_replace_callback('!<meta(.*?)(?:\/|)>!is', array($this, '_moveMetaToHeader'), $output);
// change a meta fine(widget often put the tag like <!--Meta:path--> to the content because of caching) // change a meta fine(widget often put the tag like <!--Meta:path--> to the content because of caching)
$output = preg_replace_callback('/<!--(#)?Meta:([a-z0-9\_\/\.\@]+)-->/is', array($this,'_transMeta'), $output); $output = preg_replace_callback('/<!--(#)?Meta:([a-z0-9\_\/\.\@]+)-->/is', array($this, '_transMeta'), $output);
// handles a relative path generated by using the rewrite module // handles a relative path generated by using the rewrite module
if(Context::isAllowRewrite()) if(Context::isAllowRewrite())
@ -149,14 +179,14 @@ class HTMLDisplayHandler
$real_path = $url['path']; $real_path = $url['path'];
$pattern = '/src=("|\'){1}(\.\/)?(files\/attach|files\/cache|files\/faceOff|files\/member_extra_info|modules|common|widgets|widgetstyle|layouts|addons)\/([^"\']+)\.(jpg|jpeg|png|gif)("|\'){1}/s'; $pattern = '/src=("|\'){1}(\.\/)?(files\/attach|files\/cache|files\/faceOff|files\/member_extra_info|modules|common|widgets|widgetstyle|layouts|addons)\/([^"\']+)\.(jpg|jpeg|png|gif)("|\'){1}/s';
$output = preg_replace($pattern, 'src=$1'.$real_path.'$3/$4.$5$6', $output); $output = preg_replace($pattern, 'src=$1' . $real_path . '$3/$4.$5$6', $output);
$pattern = '/href=("|\'){1}(\?[^"\']+)/s'; $pattern = '/href=("|\'){1}(\?[^"\']+)/s';
$output = preg_replace($pattern, 'href=$1'.$real_path.'$2', $output); $output = preg_replace($pattern, 'href=$1' . $real_path . '$2', $output);
if(Context::get('vid')) if(Context::get('vid'))
{ {
$pattern = '/\/'.Context::get('vid').'\?([^=]+)=/is'; $pattern = '/\/' . Context::get('vid') . '\?([^=]+)=/is';
$output = preg_replace($pattern, '/?$1=', $output); $output = preg_replace($pattern, '/?$1=', $output);
} }
} }
@ -168,20 +198,23 @@ class HTMLDisplayHandler
{ {
$INPUT_ERROR = Context::get('INPUT_ERROR'); $INPUT_ERROR = Context::get('INPUT_ERROR');
$keys = array_keys($INPUT_ERROR); $keys = array_keys($INPUT_ERROR);
$keys = '('.implode('|', $keys).')'; $keys = '(' . implode('|', $keys) . ')';
$output = preg_replace_callback('@(<input)([^>]*?)\sname="'.$keys.'"([^>]*?)/?>@is', array(&$this, '_preserveValue'), $output); $output = preg_replace_callback('@(<input)([^>]*?)\sname="' . $keys . '"([^>]*?)/?>@is', array(&$this, '_preserveValue'), $output);
$output = preg_replace_callback('@<select[^>]*\sname="'.$keys.'".+</select>@isU', array(&$this, '_preserveSelectValue'), $output); $output = preg_replace_callback('@<select[^>]*\sname="' . $keys . '".+</select>@isU', array(&$this, '_preserveSelectValue'), $output);
$output = preg_replace_callback('@<textarea[^>]*\sname="'.$keys.'".+</textarea>@isU', array(&$this, '_preserveTextAreaValue'), $output); $output = preg_replace_callback('@<textarea[^>]*\sname="' . $keys . '".+</textarea>@isU', array(&$this, '_preserveTextAreaValue'), $output);
} }
if(__DEBUG__==3) $GLOBALS['__trans_content_elapsed__'] = getMicroTime()-$start; if(__DEBUG__ == 3)
{
$GLOBALS['__trans_content_elapsed__'] = getMicroTime() - $start;
}
// Remove unnecessary information // Remove unnecessary information
$output = preg_replace('/member\_\-([0-9]+)/s','member_0',$output); $output = preg_replace('/member\_\-([0-9]+)/s', 'member_0', $output);
// set icon // set icon
$oAdminModel = &getAdminModel('admin'); $oAdminModel = getAdminModel('admin');
$favicon_url = $oAdminModel->getFaviconUrl(); $favicon_url = $oAdminModel->getFaviconUrl();
$mobicon_url = $oAdminModel->getMobileIconUrl(); $mobicon_url = $oAdminModel->getMobileIconUrl();
Context::set('favicon_url', $favicon_url); Context::set('favicon_url', $favicon_url);
@ -189,7 +222,7 @@ class HTMLDisplayHandler
// convert the final layout // convert the final layout
Context::set('content', $output); Context::set('content', $output);
$oTemplate = &TemplateHandler::getInstance(); $oTemplate = TemplateHandler::getInstance();
if(Mobile::isFromMobilePhone()) if(Mobile::isFromMobilePhone())
{ {
$output = $oTemplate->compile('./common/tpl', 'mobile_layout'); $output = $oTemplate->compile('./common/tpl', 'mobile_layout');
@ -201,7 +234,7 @@ class HTMLDisplayHandler
} }
// replace the user-defined-language // replace the user-defined-language
$oModuleController = &getController('module'); $oModuleController = getController('module');
$oModuleController->replaceDefinedLangCode($output); $oModuleController->replaceDefinedLangCode($output);
} }
@ -214,17 +247,20 @@ class HTMLDisplayHandler
{ {
$INPUT_ERROR = Context::get('INPUT_ERROR'); $INPUT_ERROR = Context::get('INPUT_ERROR');
$str = $match[1].$match[2].' name="'.$match[3].'"'.$match[4]; $str = $match[1] . $match[2] . ' name="' . $match[3] . '"' . $match[4];
// get type // get type
$type = 'text'; $type = 'text';
if(preg_match('/\stype="([a-z]+)"/i', $str, $m)) $type = strtolower($m[1]); if(preg_match('/\stype="([a-z]+)"/i', $str, $m))
{
$type = strtolower($m[1]);
}
switch($type) switch($type)
{ {
case 'text': case 'text':
case 'hidden': case 'hidden':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.@htmlspecialchars($INPUT_ERROR[$match[3]]).'"'; $str = preg_replace('@\svalue="[^"]*?"@', ' ', $str) . ' value="' . @htmlspecialchars($INPUT_ERROR[$match[3]]) . '"';
break; break;
case 'password': case 'password':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str); $str = preg_replace('@\svalue="[^"]*?"@', ' ', $str);
@ -232,14 +268,14 @@ class HTMLDisplayHandler
case 'radio': case 'radio':
case 'checkbox': case 'checkbox':
$str = preg_replace('@\schecked(="[^"]*?")?@', ' ', $str); $str = preg_replace('@\schecked(="[^"]*?")?@', ' ', $str);
if(@preg_match('@\s(?i:value)="'.$INPUT_ERROR[$match[3]].'"@', $str)) if(@preg_match('@\s(?i:value)="' . $INPUT_ERROR[$match[3]] . '"@', $str))
{ {
$str .= ' checked="checked"'; $str .= ' checked="checked"';
} }
break; break;
} }
return $str.' />'; return $str . ' />';
} }
/** /**
@ -263,7 +299,7 @@ class HTMLDisplayHandler
$m[0][$key] = preg_replace('@(\svalue=".*?")@is', '$1 selected="selected"', $m[0][$key]); $m[0][$key] = preg_replace('@(\svalue=".*?")@is', '$1 selected="selected"', $m[0][$key]);
return $mm[0].implode('', $m[0]).'</select>'; return $mm[0] . implode('', $m[0]) . '</select>';
} }
/** /**
@ -275,7 +311,7 @@ class HTMLDisplayHandler
{ {
$INPUT_ERROR = Context::get('INPUT_ERROR'); $INPUT_ERROR = Context::get('INPUT_ERROR');
preg_match('@<textarea.*?>@is', $matches[0], $mm); preg_match('@<textarea.*?>@is', $matches[0], $mm);
return $mm[0].$INPUT_ERROR[$matches[1]].'</textarea>'; return $mm[0] . $INPUT_ERROR[$matches[1]] . '</textarea>';
} }
/** /**
@ -322,7 +358,10 @@ class HTMLDisplayHandler
*/ */
function _transMeta($matches) function _transMeta($matches)
{ {
if($matches[1]) return ''; if($matches[1])
{
return '';
}
Context::loadFile($matches[2]); Context::loadFile($matches[2]);
} }
@ -332,8 +371,8 @@ class HTMLDisplayHandler
*/ */
function _loadJSCSS() function _loadJSCSS()
{ {
$oContext =& Context::getInstance(); $oContext = Context::getInstance();
$lang_type = Context::getLangType(); $lang_type = Context::getLangType();
// add common JS/CSS files // add common JS/CSS files
if(__DEBUG__) if(__DEBUG__)
@ -355,7 +394,7 @@ class HTMLDisplayHandler
} }
// for admin page, add admin css // for admin page, add admin css
if(Context::get('module')=='admin' || strpos(Context::get('act'),'Admin')>0) if(Context::get('module') == 'admin' || strpos(Context::get('act'), 'Admin') > 0)
{ {
if(__DEBUG__) if(__DEBUG__)
{ {
@ -370,7 +409,7 @@ class HTMLDisplayHandler
else else
{ {
$oContext->loadFile(array('./modules/admin/tpl/css/admin.min.css', '', '', 10), true); $oContext->loadFile(array('./modules/admin/tpl/css/admin.min.css', '', '', 10), true);
$oContext->loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.css", '', '',10), true); $oContext->loadFile(array("./modules/admin/tpl/css/admin_{$lang_type}.css", '', '', 10), true);
$oContext->loadFile(array("./modules/admin/tpl/css/admin.iefix.min.css", '', 'ie', 10), true); $oContext->loadFile(array("./modules/admin/tpl/css/admin.iefix.min.css", '', 'ie', 10), true);
$oContext->loadFile('./modules/admin/tpl/js/admin.min.js', true); $oContext->loadFile('./modules/admin/tpl/js/admin.min.js', true);
$oContext->loadFile(array('./modules/admin/tpl/css/admin.bootstrap.min.css', '', '', 1), true); $oContext->loadFile(array('./modules/admin/tpl/css/admin.bootstrap.min.css', '', '', 1), true);
@ -379,6 +418,7 @@ class HTMLDisplayHandler
} }
} }
} }
} }
/* End of file HTMLDisplayHandler.class.php */ /* End of file HTMLDisplayHandler.class.php */
/* Location: ./classes/display/HTMLDisplayHandler.class.php */ /* Location: ./classes/display/HTMLDisplayHandler.class.php */

View file

@ -1,6 +1,8 @@
<?php <?php
class JSCallbackDisplayHandler class JSCallbackDisplayHandler
{ {
/** /**
* Produce JSCallback compliant content given a module object.\n * Produce JSCallback compliant content given a module object.\n
* @param ModuleObject $oModule the module object * @param ModuleObject $oModule the module object
@ -11,10 +13,11 @@ class JSCallbackDisplayHandler
$variables = $oModule->getVariables(); $variables = $oModule->getVariables();
$variables['error'] = $oModule->getError(); $variables['error'] = $oModule->getError();
$variables['message'] = $oModule->getMessage(); $variables['message'] = $oModule->getMessage();
$json = str_replace(array("\r\n","\n","\t"),array('\n','\n','\t'),json_encode2($variables)); $json = str_replace(array("\r\n", "\n", "\t"), array('\n', '\n', '\t'), json_encode2($variables));
$output = sprintf('<script>%s(%s);</script>', Context::getJSCallbackFunc(), $json); $output = sprintf('<script>%s(%s);</script>', Context::getJSCallbackFunc(), $json);
return $output; return $output;
} }
} }
/* End of file JSCallback.class.php */ /* End of file JSCallback.class.php */
/* Location: ./classes/display/JSCallback.class.php */ /* Location: ./classes/display/JSCallback.class.php */

View file

@ -1,6 +1,8 @@
<?php <?php
class JSONDisplayHandler class JSONDisplayHandler
{ {
/** /**
* Produce JSON compliant content given a module object.\n * Produce JSON compliant content given a module object.\n
* @param ModuleObject $oModule the module object * @param ModuleObject $oModule the module object
@ -11,9 +13,10 @@ class JSONDisplayHandler
$variables = $oModule->getVariables(); $variables = $oModule->getVariables();
$variables['error'] = $oModule->getError(); $variables['error'] = $oModule->getError();
$variables['message'] = $oModule->getMessage(); $variables['message'] = $oModule->getMessage();
$json = str_replace(array("\r\n","\n","\t"),array('\n','\n','\t'),json_encode2($variables)); $json = str_replace(array("\r\n", "\n", "\t"), array('\n', '\n', '\t'), json_encode2($variables));
return $json; return $json;
} }
} }
/* End of file JSONDisplayHandler.class.php */ /* End of file JSONDisplayHandler.class.php */
/* Location: ./classes/display/JSONDisplayHandler.class.php */ /* Location: ./classes/display/JSONDisplayHandler.class.php */

View file

@ -1,12 +1,13 @@
<?php <?php
class VirtualXMLDisplayHandler class VirtualXMLDisplayHandler
{ {
/** /**
* Produce virtualXML compliant content given a module object.\n * Produce virtualXML compliant content given a module object.\n
* @param ModuleObject $oModule the module object * @param ModuleObject $oModule the module object
* @return string * @return string
*/ */
function toDoc(&$oModule) function toDoc(&$oModule)
{ {
$error = $oModule->getError(); $error = $oModule->getError();
@ -14,29 +15,49 @@ class VirtualXMLDisplayHandler
$redirect_url = $oModule->get('redirect_url'); $redirect_url = $oModule->get('redirect_url');
$request_uri = Context::get('xeRequestURI'); $request_uri = Context::get('xeRequestURI');
$request_url = Context::get('xeVirtualRequestUrl'); $request_url = Context::get('xeVirtualRequestUrl');
if(substr($request_url,-1)!='/') $request_url .= '/'; if(substr($request_url, -1) != '/')
{
$request_url .= '/';
}
if($error === 0) if($error === 0)
{ {
if($message != 'success') $output->message = $message; if($message != 'success')
if($redirect_url) $output->url = $redirect_url; {
else $output->url = $request_uri; $output->message = $message;
}
if($redirect_url)
{
$output->url = $redirect_url;
}
else
{
$output->url = $request_uri;
}
} }
else else
{ {
if($message != 'fail') $output->message = $message; if($message != 'fail')
{
$output->message = $message;
}
} }
$html = '<script>'."\n"; $html = '<script>' . "\n";
if($output->message) $html .= 'alert("'.$output->message.'");'."\n";
if($output->message)
{
$html .= 'alert("' . $output->message . '");' . "\n";
}
if($output->url) if($output->url)
{ {
$url = preg_replace('/#(.+)$/i','',$output->url); $url = preg_replace('/#(.+)$/i', '', $output->url);
$html .= 'self.location.href = "'.$request_url.'common/tpl/redirect.html?redirect_url='.urlencode($url).'";'."\n"; $html .= 'self.location.href = "' . $request_url . 'common/tpl/redirect.html?redirect_url=' . urlencode($url) . '";' . "\n";
} }
$html .= '</script>'."\n"; $html .= '</script>' . "\n";
return $html; return $html;
} }
} }
/* End of file VirtualXMLDisplayHandler.class.php */ /* End of file VirtualXMLDisplayHandler.class.php */
/* Location: ./classes/display/VirtualXMLDisplayHandler.class.php */ /* Location: ./classes/display/VirtualXMLDisplayHandler.class.php */

View file

@ -1,6 +1,8 @@
<?php <?php
class XMLDisplayHandler class XMLDisplayHandler
{ {
/** /**
* Produce XML compliant content given a module object.\n * Produce XML compliant content given a module object.\n
* @param ModuleObject $oModule the module object * @param ModuleObject $oModule the module object
@ -10,9 +12,9 @@ class XMLDisplayHandler
{ {
$variables = $oModule->getVariables(); $variables = $oModule->getVariables();
$xmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n"; $xmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n";
$xmlDoc .= sprintf("<error>%s</error>\n",$oModule->getError()); $xmlDoc .= sprintf("<error>%s</error>\n", $oModule->getError());
$xmlDoc .= sprintf("<message>%s</message>\n",str_replace(array('<','>','&'),array('&lt;','&gt;','&amp;'),$oModule->getMessage())); $xmlDoc .= sprintf("<message>%s</message>\n", str_replace(array('<', '>', '&'), array('&lt;', '&gt;', '&amp;'), $oModule->getMessage()));
$xmlDoc .= $this->_makeXmlDoc($variables); $xmlDoc .= $this->_makeXmlDoc($variables);
@ -26,22 +28,39 @@ class XMLDisplayHandler
* @param object $obj * @param object $obj
* @return string * @return string
*/ */
function _makeXmlDoc($obj) { function _makeXmlDoc($obj)
if(!count($obj)) return; {
if(!count($obj))
{
return;
}
$xmlDoc = ''; $xmlDoc = '';
foreach($obj as $key => $val) foreach($obj as $key => $val)
{ {
if(is_numeric($key)) $key = 'item'; if(is_numeric($key))
{
$key = 'item';
}
if(is_string($val)) $xmlDoc .= sprintf('<%s><![CDATA[%s]]></%s>%s', $key, $val, $key,"\n"); if(is_string($val))
else if(!is_array($val) && !is_object($val)) $xmlDoc .= sprintf('<%s>%s</%s>%s', $key, $val, $key,"\n"); {
else $xmlDoc .= sprintf('<%s>%s%s</%s>%s',$key, "\n", $this->_makeXmlDoc($val), $key, "\n"); $xmlDoc .= sprintf('<%s><![CDATA[%s]]></%s>%s', $key, $val, $key, "\n");
}
else if(!is_array($val) && !is_object($val))
{
$xmlDoc .= sprintf('<%s>%s</%s>%s', $key, $val, $key, "\n");
}
else
{
$xmlDoc .= sprintf('<%s>%s%s</%s>%s', $key, "\n", $this->_makeXmlDoc($val), $key, "\n");
}
} }
return $xmlDoc; return $xmlDoc;
} }
} }
/* End of file XMLDisplayHandler.class.php */ /* End of file XMLDisplayHandler.class.php */
/* Location: ./classes/display/XMLDisplayHandler.class.php */ /* Location: ./classes/display/XMLDisplayHandler.class.php */