fix <button...></button> was removed and reorganized preprocessor to only consider boxes for <overlay legacy="true">

This commit is contained in:
ralf 2022-07-27 11:04:08 +02:00
parent 879fb84229
commit e1097d9ea3

View File

@ -13,12 +13,12 @@
use EGroupware\Api;
// add et2- prefix to following widgets/tags, if NO <overlay legacy="true"
const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box|date(-time[^\s]*|-duration|-since)?|colorpicker|url(-email|-phone|-fax)?))(/?|\s[^>]*)>#m';
const ADD_ET2_PREFIX_LAST_GROUP = 6;
const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box))(/?|\s[^>]*)>#m';
const ADD_ET2_PREFIX_LAST_GROUP = 4;
// unconditional of legacy add et2- prefix to this widgets
const ADD_ET2_PREFIX_LEGACY_REGEXP = '#<(description|searchbox|textbox|label|avatar|lavatar|image|vfs-mime|vfs-uid|vfs-gid|link|link-[a-z]+|favorites)\s([^>]+)/>#m';
const ADD_ET2_PREFIX_LEGACY_LAST_GROUP = 2;
const ADD_ET2_PREFIX_LEGACY_REGEXP = '#<(description|searchbox|textbox|label|avatar|lavatar|image|colorpicker|url(-email|-phone|-fax)?|vfs-mime|vfs-uid|vfs-gid|link|link-[a-z]+|favorites)\s([^>]+)/>#m';
const ADD_ET2_PREFIX_LEGACY_LAST_GROUP = 3;
// switch evtl. set output-compression off, as we can't calculate a Content-Length header with transparent compression
ini_set('zlib.output_compression', 0);
@ -263,61 +263,60 @@ function send_template()
return '<et2-nextmatch-header-' . $matches[2] . ' ' . stringAttrs($attrs) . '/>';
}, $str);
$str = preg_replace('#<passwd ([^/>]+)/>#', '<et2-password $1></et2-password>', $str);
$str = preg_replace('#<passwd ([^/>]+)(/|></passwd)>#', '<et2-password $1></et2-password>', $str);
// fix <button(only)?.../> --> <et2-(button|image) (noSubmit="true")?.../>
$str = preg_replace_callback('#<button(only)?\s(.*?)(/|></button)>#s', function ($matches) use ($name)
{
$tag = 'et2-button';
$attrs = parseAttrs($matches[2]);
// replace buttononly tag with noSubmit="true" attribute
if (!empty($matches[1]))
{
$attrs['noSubmit'] = 'true';
}
// novalidation --> noValidation
if (!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true))
{
unset($attrs['novalidation']);
$attrs['noValidation'] = 'true';
}
// replace not set background_image attribute with et2-image tag, if not in NM / lists
if (!empty($attrs['image']) && (empty($attrs['background_image']) || $attrs['background_image'] === 'false') &&
!preg_match('/^(index|list)/', $name))
{
$tag = 'et2-image';
$attrs['src'] = $attrs['image'];
unset($attrs['image']);
// Was expected to submit. Images don't have noValidation, so add directly
if (!array_key_exists('onclick', $attrs) && empty($attrs['noSubmit']))
{
$attrs['onclick'] = 'this.getInstanceManager().submit(this, undefined, ' . $attrs['noValidation'] . ')';
}
}
unset($attrs['background_image']);
return "<$tag " . stringAttrs($attrs) . '></' . $tag . '>';
}, $str);
$str = preg_replace_callback('#<date(-time[^\s]*|-duration|-since)?\s([^>]+)/>#', static function($matches)
{
if ($matches[1] === 'date-time_today') $matches[1] = 'date-time-today';
return "<et2-date$matches[1] $matches[2]></et2-date$matches[1]>";
}, $str);
// ^^^^^^^^^^^^^^^^ above widgets get transformed independent of legacy="true" set in overlay ^^^^^^^^^^^^^^^^^^
// eTemplate marked as legacy --> replace only some widgets (eg. requiring jQueryUI) with web-components
if (preg_match('/<overlay[^>]* legacy="true"/', $str))
if (!preg_match('/<overlay[^>]* legacy="true"/', $str))
{
$str = preg_replace_callback('#<date(-time[^\s]*|-duration|-since)?\s([^>]+)/>#', static function($matches)
{
if ($matches[1] === 'date-time_today') $matches[1] = 'date-time-today';
return "<et2-date$matches[1] $matches[2]></et2-date$matches[1]>";
}, $str);
}
else
{
// fix <button(only)?.../> --> <et2-button(-image)? noSubmit="true".../>
$str = preg_replace_callback('#<button(only)?\s(.*?)/>#s', function ($matches) use ($name) {
$tag = 'et2-button';
$attrs = parseAttrs($matches[2]);
// replace buttononly tag with noSubmit="true" attribute
if (!empty($matches[1]))
{
$attrs['noSubmit'] = 'true';
}
// novalidation --> noValidation
if (!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true))
{
unset($attrs['novalidation']);
$attrs['noValidation'] = 'true';
}
// replace not set background_image attribute with et2-image tag, if not in NM / lists
if (!empty($attrs['image']) && (empty($attrs['background_image']) || $attrs['background_image'] === 'false') &&
!preg_match('/^(index|list)/', $name))
{
$tag = 'et2-image';
$attrs['src'] = $attrs['image'];
unset($attrs['image']);
// Was expected to submit. Images don't have noValidation, so add directly
if (!array_key_exists('onclick', $attrs) && empty($attrs['noSubmit']))
{
$attrs['onclick'] = 'this.getInstanceManager().submit(this, undefined, ' . $attrs['noValidation'] . ')';
}
}
unset($attrs['background_image']);
return "<$tag " . stringAttrs($attrs) . '></' . $tag . '>';
}, $str);
$str = preg_replace_callback(ADD_ET2_PREFIX_REGEXP, static function (array $matches) {
if ($matches[3] === 'date-time_today') $matches[3] = 'date-time-today';
return '<' . $matches[2] . 'et2-' . $matches[3] .
// web-components must not be self-closing (no "<et2-button .../>", but "<et2-button ...></et2-button>")
(substr($matches[ADD_ET2_PREFIX_LAST_GROUP], -1) === '/' ? substr($matches[ADD_ET2_PREFIX_LAST_GROUP], 0, -1) .
'></et2-' . $matches[3] : $matches[ADD_ET2_PREFIX_LAST_GROUP]) . '>';
}, $str);
}
// change all attribute-names of new et2-* widgets to camelCase, and other attribute modifications for all web-components
$str = preg_replace_callback('/<(et2|records)-([a-z-]+)\s([^>]+)>/', static function(array $matches)
{