web-components must not be self-closing (no "<et2-button .../>", but "<et2-button ...></et2-button>")

This commit is contained in:
Ralf Becker 2021-08-16 19:54:58 +02:00
parent cfb8f5d453
commit 6d37e22499

View File

@ -14,9 +14,8 @@ use EGroupware\Api;
// add et2- prefix to following widgets/tags // add et2- prefix to following widgets/tags
/* disabling v/hbox replacement for now as it fails with nextmatch headers /* disabling v/hbox replacement for now as it fails with nextmatch headers
const ADD_ET2_PREFIX_REGEXP = '#(\s|^|>)<((/?)([vh]?box|button))(\s|/?>)#m';*/ const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box|textbox|button))(/?|\s[^>]*)>#m';*/
const ADD_ET2_PREFIX_REGEXP = '#(\s|^|>)<((/?)(box|button))(\s|/?>)#m'; const ADD_ET2_PREFIX_REGEXP = '#<((/?)(box|textbox|button))(/?|\s[^>]*)>#m';
const ADD_ET2_PREFIX_REPLACE = '$1<$3et2-$4$5';
// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression // switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression
ini_set('zlib.output_compression', 0); ini_set('zlib.output_compression', 0);
@ -25,7 +24,7 @@ $GLOBALS['egw_info'] = array(
'flags' => array( 'flags' => array(
'currentapp' => 'api', 'currentapp' => 'api',
'noheader' => true, 'noheader' => true,
// misuse session creation callback to send the template, in case we have no session // miss-use session creation callback to send the template, in case we have no session
'autocreate_session_callback' => 'send_template', 'autocreate_session_callback' => 'send_template',
'nocachecontrol' => true, 'nocachecontrol' => true,
) )
@ -66,16 +65,12 @@ function send_template()
// fix <menulist...><menupopup type="select-*"/></menulist> --> <select type="select-*" .../> // fix <menulist...><menupopup type="select-*"/></menulist> --> <select type="select-*" .../>
$str = preg_replace('#<menulist([^>]*)>[\r\n\s]*<menupopup([^>]+>)[\r\n\s]*</menulist>#', '<select$1$2', $str); $str = preg_replace('#<menulist([^>]*)>[\r\n\s]*<menupopup([^>]+>)[\r\n\s]*</menulist>#', '<select$1$2', $str);
// if there are multiple tags on one line, we need to run the regexp multiple times (eg. twice for the following example) $str = preg_replace_callback(ADD_ET2_PREFIX_REGEXP, static function(array $matches)
//$str = "<overlay>\n<template name='test'>\n\t<!-- this is a comment -->\n\t<box><button id='test'/></box>\n</template>\n</overlay>\n";
$iterations = 0;
do
{ {
$iterations++; return '<'.$matches[2].'et2-'.$matches[3].
$original = $str; // web-components must not be self-closing (no "<et2-button .../>", but "<et2-button ...></et2-button>")
$str = preg_replace(ADD_ET2_PREFIX_REGEXP, ADD_ET2_PREFIX_REPLACE, $original); (substr($matches[4], -1) === '/' ? substr($matches[4], 0, -1).'></et2-'.$matches[3] : $matches[4]).'>';
} while (strlen($str) !== strlen($original) || $str !== $original); }, $str);
header('X-Required-Replace-Iterations: ' . ($iterations - 1));
$processing = microtime(true); $processing = microtime(true);