*/
class HTMLDisplayHandler
{
/**
* jQuery versions
*/
const JQUERY_V1 = '1.12.4';
const JQUERY_V2 = '2.2.4';
/**
* Reserved scripts
*/
public static $reservedCSS = '@\bcommon/css/(?:xe|rhymix|mobile)\.(?:min\.)?(?:s?css|less)$@';
public static $reservedJS = '@\bcommon/js/(?:jquery(?:-[123][0-9.x-]+)?|xe?|common|js_app|xml_handler|xml_js_filter)\.(?:min\.)?js$@';
/**
* List of scripts to block loading
*/
public static $blockedScripts = array(
'@(?:^|/)j[Qq]uery(?:-[0-9]+(?:\.[0-9x]+)*|-latest)?(?:\.min)?\.js$@',
);
/**
* Replacement table for XE compatibility
*/
public static $replacements = array(
'@\bcommon/xeicon/@' => 'common/css/xeicon/',
'@\beditor/skins/xpresseditor/js/xe_textarea\.(?:min\.)?js@' => 'editor/skins/ckeditor/js/xe_textarea.js',
);
/**
* Produce HTML compliant content given a module object.\n
* @param ModuleObject $oModule the module object
* @return string compiled template string
*/
function toDoc(&$oModule)
{
$oTemplate = TemplateHandler::getInstance();
// SECISSUE https://github.com/xpressengine/xe-core/issues/1583
$oSecurity = new Security();
$oSecurity->encodeHTML('is_keyword', 'search_keyword', 'search_target', 'order_target', 'order_type');
$template_path = $oModule->getTemplatePath();
if(!is_dir($template_path))
{
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))
{
$theme_skin = explode('|@|', $skin);
$template_path = $oModule->getTemplatePath();
if(count($theme_skin) == 2)
{
$theme_path = sprintf('./themes/%s', $theme_skin[0]);
// FIXME $theme_path $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]);
}
}
}
else
{
$template_path = $oModule->getTemplatePath();
}
}
else
{
$template_path = $oModule->getTemplatePath();
}
}
$tpl_file = $oModule->getTemplateFile();
$output = $oTemplate->compile($template_path, $tpl_file);
// add .x div for adminitration pages
if(Context::getResponseMethod() == 'HTML')
{
if(Context::get('module') != 'admin' && strpos(Context::get('act'), 'Admin') > 0 && Context::get('act') != 'dispPageAdminContentModify' && Context::get('act') != 'dispPageAdminMobileContentModify')
{
$output = '
' . $output . '
';
}
if(Context::get('layout') != 'none')
{
$start = microtime(true);
Context::set('content', $output, false);
$layout_path = $oModule->getLayoutPath();
$layout_file = $oModule->getLayoutFile();
$edited_layout_file = $oModule->getEditedLayoutFile();
// get the layout information currently requested
$oLayoutModel = getModel('layout');
$layout_info = Context::get('layout_info');
$layout_srl = $layout_info->layout_srl;
// compile if connected to the layout
if($layout_srl > 0)
{
// handle separately if the layout is faceoff
if($layout_info && $layout_info->type == 'faceoff')
{
$oLayoutModel->doActivateFaceOff($layout_info);
Context::set('layout_info', $layout_info);
}
// search if the changes CSS exists in the admin layout edit window
$edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl);
if(FileHandler::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';
}
$output = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file);
// if popup_layout, remove admin bar.
$realLayoutPath = FileHandler::getRealPath($layout_path);
if(substr_compare($realLayoutPath, '/', -1) !== 0)
{
$realLayoutPath .= '/';
}
$pathInfo = pathinfo($layout_file);
$onlyLayoutFile = $pathInfo['filename'];
$GLOBALS['__layout_compile_elapsed__'] = microtime(true) - $start;
if(stripos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE && (Context::get('_use_ssl') == 'optional' || Context::get('_use_ssl') == 'always'))
{
Context::addHtmlFooter('');
}
}
}
// Add OpenGraph metadata
if (config('seo.og_enabled') && Context::get('module') !== 'admin')
{
$this->_addOpenGraphMetadata();
}
// set icon
$site_module_info = Context::get('site_module_info');
$oAdminModel = getAdminModel('admin');
$favicon_url = $oAdminModel->getFaviconUrl($site_module_info->domain_srl);
$mobicon_url = $oAdminModel->getMobileIconUrl($site_module_info->domain_srl);
Context::set('favicon_url', $favicon_url);
Context::set('mobicon_url', $mobicon_url);
return $output;
}
/**
* when display mode is HTML, prepare code before print.
* @param string $output compiled template string
* @return void
*/
function prepareToPrint(&$output)
{
if(Context::getResponseMethod() != 'HTML')
{
return;
}
$start = microtime(true);
// move in body to the header
$output = preg_replace_callback('!