2021-08-15 14:59:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* API: loading for web-components modified eTemplate from server
|
|
|
|
*
|
|
|
|
* Usage: /egroupware/api/etemplate.php/<app>/templates/default/<name>.xet
|
|
|
|
*
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Ralf Becker <rb@egroupware-org>
|
|
|
|
* @package api
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
use EGroupware\Api;
|
|
|
|
|
2022-05-07 13:31:46 +02:00
|
|
|
// add et2- prefix to following widgets/tags, if NO <overlay legacy="true"
|
2022-08-03 10:57:49 +02:00
|
|
|
const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box))(/?|\s[^>]*)>#m';
|
2022-07-27 11:04:08 +02:00
|
|
|
const ADD_ET2_PREFIX_LAST_GROUP = 4;
|
2021-08-15 14:59:23 +02:00
|
|
|
|
2022-05-07 13:31:46 +02:00
|
|
|
// unconditional of legacy add et2- prefix to this widgets
|
2022-08-07 11:55:02 +02:00
|
|
|
const ADD_ET2_PREFIX_LEGACY_REGEXP = '#<((/?)(tabbox|description|details|searchbox|textbox|label|avatar|lavatar|image|appicon|colorpicker|checkbox|url(-email|-phone|-fax)?|vfs-mime|vfs-uid|vfs-gid|link|link-[a-z]+|favorites))(/?|\s[^>]*)>#m';
|
2022-08-03 10:57:49 +02:00
|
|
|
const ADD_ET2_PREFIX_LEGACY_LAST_GROUP = 5;
|
2022-05-07 13:31:46 +02:00
|
|
|
|
2022-05-13 11:59:13 +02:00
|
|
|
// switch evtl. set output-compression off, as we can't calculate a Content-Length header with transparent compression
|
2021-08-15 14:59:23 +02:00
|
|
|
ini_set('zlib.output_compression', 0);
|
|
|
|
|
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
2021-08-19 01:41:23 +02:00
|
|
|
'currentapp' => 'api',
|
|
|
|
'noheader' => true,
|
2021-08-16 19:54:58 +02:00
|
|
|
// miss-use session creation callback to send the template, in case we have no session
|
2021-08-15 14:59:23 +02:00
|
|
|
'autocreate_session_callback' => 'send_template',
|
2021-08-19 01:41:23 +02:00
|
|
|
'nocachecontrol' => true,
|
2021-08-15 14:59:23 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$start = microtime(true);
|
|
|
|
include '../header.inc.php';
|
|
|
|
|
|
|
|
send_template();
|
|
|
|
|
|
|
|
function send_template()
|
|
|
|
{
|
|
|
|
$header_include = microtime(true);
|
|
|
|
|
|
|
|
// release session, as we don't need it and it blocks parallel requests
|
|
|
|
$GLOBALS['egw']->session->commit_session();
|
|
|
|
|
|
|
|
header('Content-Type: application/xml; charset=UTF-8');
|
|
|
|
|
|
|
|
//$path = EGW_SERVER_ROOT.$_SERVER['PATH_INFO'];
|
|
|
|
// check for customized template in VFS
|
|
|
|
list(, $app, , $template, $name) = explode('/', $_SERVER['PATH_INFO']);
|
2021-08-19 01:41:23 +02:00
|
|
|
$path = Api\Etemplate::rel2path(Api\Etemplate::relPath($app . '.' . basename($name, '.xet'), $template));
|
|
|
|
if(empty($path) || !file_exists($path) || !is_readable($path))
|
2021-08-15 14:59:23 +02:00
|
|
|
{
|
|
|
|
http_response_code(404);
|
|
|
|
exit;
|
|
|
|
}
|
2022-04-29 17:05:43 +02:00
|
|
|
$cache = $GLOBALS['egw_info']['server']['temp_dir'].'/egw_cache/eT2-Cache-'.
|
|
|
|
$GLOBALS['egw_info']['server']['install_id'].'-'.str_replace('/', '-', $_SERVER['PATH_INFO']);
|
|
|
|
if (file_exists($cache) && filemtime($cache) > max(filemtime($path), filemtime(__FILE__)) &&
|
2021-08-15 14:59:23 +02:00
|
|
|
($str = file_get_contents($cache)) !== false)
|
|
|
|
{
|
|
|
|
$cache_read = microtime(true);
|
|
|
|
}
|
2022-04-29 17:05:43 +02:00
|
|
|
elseif(($str = file_get_contents($path)) !== false)
|
2021-08-15 14:59:23 +02:00
|
|
|
{
|
2022-06-13 09:57:24 +02:00
|
|
|
// replace single quote enclosing attribute values with double quotes
|
2022-07-01 14:39:23 +02:00
|
|
|
$str = preg_replace_callback("#([a-z_-]+)='([^']*)'([ />])#i", static function($matches){
|
|
|
|
return $matches[1].'="'.str_replace('"', '"', $matches[2]).'"'.$matches[3];
|
|
|
|
}, $str);
|
2022-06-13 09:57:24 +02:00
|
|
|
|
2021-08-15 14:59:23 +02:00
|
|
|
// fix <menulist...><menupopup type="select-*"/></menulist> --> <select type="select-*" .../>
|
2022-07-27 17:53:56 +02:00
|
|
|
$str = preg_replace('#<menulist([^>]*)>[\r\n\s]*(<!--[^>]+-->[\r\n\s]*)?<menupopup([^>]+>)[\r\n\s]*</menulist>#', '$2<select$1$3', $str);
|
2022-09-18 08:54:39 +02:00
|
|
|
$str = preg_replace('#<menupopup([^>]*)>#', '<select$1>', $str);
|
2021-08-15 14:59:23 +02:00
|
|
|
|
2022-06-01 16:05:34 +02:00
|
|
|
// fix legacy options, so new client-side has not to deal with them
|
|
|
|
$str = preg_replace_callback('#<([^- />]+)(-[^ ]+)?[^>]* (options="([^"]+)")[ />]#', static function ($matches) {
|
|
|
|
// take care of (static) type attribute, if used
|
|
|
|
if (preg_match('/ type="([a-z-]+)"/', $matches[0], $type))
|
|
|
|
{
|
|
|
|
str_replace('<' . $matches[1] . $matches[2], '<' . $type[1], $matches[0]);
|
|
|
|
str_replace($type[0], '', $matches[0]);
|
|
|
|
list($matches[1], $matches[2]) = explode('-', $type[1], 2);
|
2022-06-07 22:16:55 +02:00
|
|
|
if (!empty($matches[2])) $matches[2] = '-'.$matches[2];
|
2022-06-01 16:05:34 +02:00
|
|
|
}
|
2022-07-07 21:18:42 +02:00
|
|
|
static $legacy_options = array(
|
|
|
|
// use "ignore" to ignore further comma-sep. values, otherwise they are all in last attribute
|
|
|
|
'select' => 'empty_label,ignore',
|
|
|
|
'select-account' => 'empty_label,account_type,ignore',
|
|
|
|
'select-number' => 'empty_label,min,max,interval,suffix',
|
2022-08-19 19:07:16 +02:00
|
|
|
'select-cat' => 'empty_label,global_categories,ignore,application,parentCat,owner',
|
2022-07-07 21:18:42 +02:00
|
|
|
'box' => ',cellpadding,cellspacing,keep',
|
|
|
|
'hbox' => 'cellpadding,cellspacing,keep',
|
|
|
|
'vbox' => 'cellpadding,cellspacing,keep',
|
|
|
|
'groupbox' => 'cellpadding,cellspacing,keep',
|
|
|
|
'checkbox' => 'selected_value,unselected_value,ro_true,ro_false',
|
|
|
|
'radio' => 'set_value,ro_true,ro_false',
|
|
|
|
'customfields' => 'sub-type,use-private,field-names',
|
|
|
|
'date' => 'data_format,ignore',
|
2022-06-03 18:18:18 +02:00
|
|
|
// Legacy option "mode" was never implemented in et2
|
2022-07-07 21:18:42 +02:00
|
|
|
'description' => 'bold-italic,link,activate_links,label_for,link_target,link_popup_size,link_title',
|
|
|
|
'button' => 'image,ro_image',
|
|
|
|
'buttononly' => 'image,ro_image',
|
2022-08-16 17:44:03 +02:00
|
|
|
'link' => 'app',
|
2022-07-07 21:18:42 +02:00
|
|
|
'link-entry' => 'only_app,application_list',
|
|
|
|
'nextmatch-filterheader' => 'empty_label',
|
|
|
|
'nextmatch-customfilter' => 'widget_type,widget_options',
|
|
|
|
'nextmatch-accountfilter' => 'empty_label,account_type,ignore',
|
2022-06-01 16:05:34 +02:00
|
|
|
);
|
|
|
|
// prefer more specific type-subtype over just type
|
2022-08-30 21:56:13 +02:00
|
|
|
$names = $legacy_options[$matches[1] . $matches[2]] ?? $legacy_options[trim($matches[1])] ?? null;
|
2022-06-01 16:05:34 +02:00
|
|
|
if (isset($names))
|
|
|
|
{
|
|
|
|
$names = explode(',', $names);
|
|
|
|
$values = Api\Etemplate\Widget::csv_split($matches[4], count($names));
|
|
|
|
if (count($values) < count($names))
|
|
|
|
{
|
|
|
|
$values = array_merge($values, array_fill(count($values), count($names) - count($values), ''));
|
|
|
|
}
|
|
|
|
$attrs = array_diff(array_combine($names, $values), ['', null]);
|
|
|
|
unset($attrs['ignore']);
|
|
|
|
// fix select options can be either multiple or empty_label
|
|
|
|
if ($matches[1] === 'select' && !empty($attrs['empty_label']) && (int)$attrs['empty_label'] > 0)
|
|
|
|
{
|
|
|
|
$attrs['multiple'] = (int)$attrs['empty_label'];
|
|
|
|
unset($matches['empty_label']);
|
|
|
|
}
|
|
|
|
$options = '';
|
|
|
|
foreach ($attrs as $attr => $value)
|
|
|
|
{
|
|
|
|
$options .= $attr . '="' . $value . '" ';
|
|
|
|
}
|
|
|
|
return str_replace($matches[3], $options, $matches[0]);
|
|
|
|
}
|
|
|
|
return $matches[0];
|
|
|
|
}, $str);
|
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
// Change splitter dockside -> primary + vertical
|
2022-06-09 23:02:01 +02:00
|
|
|
$str = preg_replace_callback('#<split([^>]*?)>(.*)</split>#su', static function ($matches)
|
|
|
|
{
|
2022-04-29 17:05:43 +02:00
|
|
|
$tag = 'et2-split';
|
2022-07-26 18:00:12 +02:00
|
|
|
$attrs = parseAttrs($matches[1]);
|
2022-04-29 17:05:43 +02:00
|
|
|
|
|
|
|
$attrs['vertical'] = $attrs['orientation'] === 'h' ? "true" : "false";
|
|
|
|
if (str_contains($attrs['dock_side'], 'top') || str_contains($attrs['dock_side'], 'left'))
|
2022-02-18 08:44:25 +01:00
|
|
|
{
|
2022-04-29 17:05:43 +02:00
|
|
|
$attrs['primary'] = "end";
|
2022-02-18 08:44:25 +01:00
|
|
|
}
|
2022-04-29 17:05:43 +02:00
|
|
|
elseif (str_contains($attrs['dock_side'], 'bottom') || str_contains($attrs['dock_side'], 'right'))
|
2022-02-18 08:44:25 +01:00
|
|
|
{
|
2022-04-29 17:05:43 +02:00
|
|
|
$attrs['primary'] = "start";
|
2022-02-18 08:44:25 +01:00
|
|
|
}
|
2022-04-29 17:05:43 +02:00
|
|
|
unset($attrs['dock_side']);
|
2022-02-18 08:44:25 +01:00
|
|
|
|
2022-07-26 18:00:12 +02:00
|
|
|
return "<$tag " . stringAttrs($attrs) . '>' . $matches[2] . "</$tag>";
|
2022-03-05 14:22:45 +01:00
|
|
|
}, $str);
|
|
|
|
|
2022-05-05 19:07:44 +02:00
|
|
|
// modify <(image|description) expose_view="true" --> <et2-*-expose
|
|
|
|
$str = preg_replace('/<(image|description)\s([^><]*)expose_view="true"\s([^><]*)\\/>/',
|
|
|
|
'<et2-$1-expose $2 $3></et2-$1-expose>', $str);
|
|
|
|
|
2022-07-22 20:43:09 +02:00
|
|
|
// fix <textbox multiline="true" .../> --> <et2-textarea .../>
|
|
|
|
$str = preg_replace('#<textbox(.*?)\smultiline="true"(.*?)/>#', '<et2-textarea$1$2></et2-textarea>', $str);
|
|
|
|
|
|
|
|
// fix <(textbox|int(eger)?|float) precision="int(eger)?|float" .../> --> <et2-number precision=.../> or <et2-textbox .../>
|
|
|
|
$str = preg_replace_callback('#<(textbox|int(eger)?|float|number).*?\s(type="(int(eger)?|float)")?.*?(/|></textbox)>#',
|
|
|
|
static function ($matches)
|
|
|
|
{
|
|
|
|
if ($matches[1] === 'textbox' && !in_array($matches[4], ['float', 'int', 'integer'], true))
|
|
|
|
{
|
|
|
|
return '<et2-'.substr($matches[0], 1, -strlen($matches[6])-1).'></et2-textbox>'; // regular textbox --> nothing to do
|
|
|
|
}
|
|
|
|
$type = $matches[1] === 'float' || $matches[4] === 'float' ? 'float' : 'int';
|
|
|
|
$tag = str_replace('<' . $matches[1], '<et2-number', substr($matches[0], 0, -2));
|
|
|
|
if (!empty($matches[3])) $tag = str_replace($matches[3], '', $tag);
|
|
|
|
if ($type !== 'float') $tag .= ' precision="0"';
|
|
|
|
return $tag . '></et2-number>';
|
|
|
|
}, $str);
|
|
|
|
|
2022-08-09 15:15:17 +02:00
|
|
|
// replace just description, as they often contain >, like label="> %s"
|
2022-08-10 15:44:34 +02:00
|
|
|
$str = preg_replace('#<description\s*/>#', '<et2-description></et2-description>', $str);
|
2022-08-09 16:05:09 +02:00
|
|
|
$str = preg_replace('#<description\s(.*?")\s*/>#s', '<et2-description $1></et2-description>', $str);
|
2022-08-09 15:15:17 +02:00
|
|
|
|
2022-05-07 13:31:46 +02:00
|
|
|
// modify <(vfs-mime|link-string|link-list) --> <et2-*
|
2022-08-03 10:57:49 +02:00
|
|
|
$str = preg_replace_callback(ADD_ET2_PREFIX_LEGACY_REGEXP, static function (array $matches) {
|
|
|
|
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_LEGACY_LAST_GROUP], -1) === '/' ? substr($matches[ADD_ET2_PREFIX_LEGACY_LAST_GROUP], 0, -1) .
|
|
|
|
'></et2-' . $matches[3] : $matches[ADD_ET2_PREFIX_LEGACY_LAST_GROUP]) . '>';
|
|
|
|
}, $str);
|
2022-05-07 13:31:46 +02:00
|
|
|
|
2022-06-09 23:02:01 +02:00
|
|
|
// change link attribute only_app to et2-link attribute app and map r/o link-entry to link
|
|
|
|
$str = preg_replace_callback('#<et2-link(-[a-z]+)?([^>]*?)></et2-link(-[a-z]+)?>#su', static function ($matches)
|
|
|
|
{
|
|
|
|
$tag = 'et2-link'.$matches[1];
|
2022-07-26 18:00:12 +02:00
|
|
|
$attrs = parseAttrs($matches[2]);
|
2022-06-09 23:02:01 +02:00
|
|
|
|
|
|
|
if ($tag === 'et2-link-entry' && !empty($attrs['readonly']) || $tag === 'et2-link')
|
|
|
|
{
|
|
|
|
$tag = 'et2-link';
|
|
|
|
$attrs['app'] = $attrs['only_app'];
|
|
|
|
unset($attrs['only_app'], $attrs['readonly']);
|
|
|
|
}
|
2022-07-26 18:00:12 +02:00
|
|
|
return "<$tag " . stringAttrs($attrs) . "></$tag>";
|
2022-06-09 23:02:01 +02:00
|
|
|
}, $str);
|
|
|
|
|
2022-06-17 22:54:54 +02:00
|
|
|
// handling of select and taglist widget, incl. removing of type attribute
|
2022-08-08 17:27:21 +02:00
|
|
|
$str = preg_replace_callback('#<(select|taglist|listbox)(-[^ ]+)? ([^>]+?)(/|>(.*?)</(select|taglist|listbox))>#s', static function (array $matches)
|
2022-07-26 18:00:12 +02:00
|
|
|
{
|
|
|
|
$attrs = parseAttrs($matches[3]);
|
2022-06-17 22:54:54 +02:00
|
|
|
|
2022-06-22 16:28:09 +02:00
|
|
|
// set multiple for old tags attribute or taglist without maxSelection="1"
|
|
|
|
if (isset($attrs['tags']) || $matches['1'] === 'taglist' && (empty($attrs['maxSelection']) || $attrs['maxSelection'] > 1))
|
2022-06-17 22:54:54 +02:00
|
|
|
{
|
|
|
|
$attrs['multiple'] = 'true';
|
|
|
|
unset($attrs['tags']);
|
|
|
|
}
|
2022-08-08 17:27:21 +02:00
|
|
|
// converting taglist to et2-select
|
|
|
|
if($matches['1'] === 'taglist')
|
2022-06-22 16:28:09 +02:00
|
|
|
{
|
2022-08-08 17:27:21 +02:00
|
|
|
// taglist had allowFreeEntries and enableEditMode with a default of true, while et2-select has it with a default of false
|
|
|
|
if(!$matches[2] && !isset($attrs['allowFreeEntries']) && (empty($matches[5]) || !preg_match('#</?option(\s[^>]+|/)>#', $matches[5])))
|
2022-06-22 16:28:09 +02:00
|
|
|
{
|
|
|
|
$attrs['allowFreeEntries'] = 'true';
|
2022-08-08 17:27:21 +02:00
|
|
|
|
|
|
|
if(!isset($attrs['editModeEnabled']))
|
|
|
|
{
|
|
|
|
$attrs['editModeEnabled'] = 'true';
|
|
|
|
}
|
|
|
|
}
|
2022-09-17 09:50:57 +02:00
|
|
|
$attrs['searchUrl'] = $attrs['autocomplete_url'] ?? 'EGroupware\\Api\\Etemplate\\Widget\\Taglist::'.
|
|
|
|
($matches[2] === '-email' ? 'ajax_email' : 'ajax_search');
|
|
|
|
if (isset($attrs['autocomplete_params']))
|
2022-08-08 17:27:21 +02:00
|
|
|
{
|
2022-09-14 09:09:56 +02:00
|
|
|
$attrs['searchOptions'] = $attrs['autocomplete_params'];
|
2022-06-22 16:28:09 +02:00
|
|
|
}
|
2022-09-14 09:09:56 +02:00
|
|
|
unset($attrs['autocomplete_url'], $attrs['autocomplete_params']);
|
2022-09-17 09:50:57 +02:00
|
|
|
if (isset($attrs['maxSelection']) && $attrs['maxSelection'] === '1')
|
2022-06-22 16:28:09 +02:00
|
|
|
{
|
2022-08-08 17:27:21 +02:00
|
|
|
unset($attrs['multiple'], $attrs['maxSelection']);
|
2022-06-22 16:28:09 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-17 22:54:54 +02:00
|
|
|
// no multiple="toggle" or expand_multiple_rows="N" currently, thought Shoelace's select multiple="true" is relative close
|
|
|
|
// until we find something better, just switch to multiple="true"
|
|
|
|
if (isset($attrs['multiple']) && $attrs['multiple'] === 'toggle' || !empty($attrs['expand_multiple_rows']))
|
|
|
|
{
|
|
|
|
$attrs['multiple'] = 'true';
|
|
|
|
unset($attrs['expand_multiple_rows']);
|
|
|
|
}
|
2022-08-10 15:44:34 +02:00
|
|
|
// <select rows="N" (to show N rows) previously also switched multiple on
|
2022-08-11 14:14:20 +02:00
|
|
|
if (!empty($attrs['rows']) && (int)$attrs['rows'] > 1)
|
2022-08-10 15:44:34 +02:00
|
|
|
{
|
|
|
|
$attrs['multiple'] = true;
|
|
|
|
}
|
2022-08-11 14:14:20 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($attrs['rows']);
|
|
|
|
}
|
2022-06-17 22:54:54 +02:00
|
|
|
// automatic convert empty_label for multiple=true to a placeholder
|
|
|
|
if (!empty($attrs['empty_label']) && !empty($attrs['multiple']))
|
|
|
|
{
|
|
|
|
$attrs['placeholder'] = $attrs['empty_label'];
|
|
|
|
unset($attrs['empty_label']);
|
|
|
|
}
|
|
|
|
// type attribute need to go in widget type <select type="select-account" --> <et2-select-account
|
|
|
|
if (empty($matches[2]) && isset($attrs['type']))
|
|
|
|
{
|
2022-06-18 12:21:05 +02:00
|
|
|
$matches[2] = preg_replace('/^(select|taglist)/', '', $attrs['type']);
|
2022-06-17 22:54:54 +02:00
|
|
|
unset($attrs['type']);
|
|
|
|
}
|
2022-07-26 18:00:12 +02:00
|
|
|
return '<et2-select' . $matches[2] . ' ' . stringAttrs($attrs) . '>'.$matches[5].'</et2-select' . $matches[2] . '>';
|
2022-06-17 22:54:54 +02:00
|
|
|
}, $str);
|
|
|
|
|
2022-07-07 21:18:42 +02:00
|
|
|
// nextmatch headers
|
|
|
|
$str = preg_replace_callback('#<(nextmatch-)([^ ]+)(header|filter) ([^>]+?)/>#s', static function (array $matches)
|
|
|
|
{
|
2022-07-26 18:00:12 +02:00
|
|
|
$attrs = parseAttrs($matches[4]);
|
2022-07-07 21:18:42 +02:00
|
|
|
|
2022-07-21 12:10:45 +02:00
|
|
|
if ($matches[2] === 'custom')
|
|
|
|
{
|
|
|
|
$attrs['widget_type'] = $attrs['type'];
|
|
|
|
}
|
|
|
|
if(!$matches[2] || in_array($matches[2], ['sort']) || ($matches[2] == "custom" && empty($attrs['widget_type'])))
|
2022-07-07 21:18:42 +02:00
|
|
|
{
|
|
|
|
return $matches[0];
|
|
|
|
}
|
|
|
|
// No longer needed & type causes problems
|
|
|
|
unset($attrs['type'], $attrs['tags']);
|
|
|
|
|
2022-07-21 12:10:45 +02:00
|
|
|
if($matches[2] === 'taglist')
|
2022-07-07 21:18:42 +02:00
|
|
|
{
|
|
|
|
$matches[2] = "filter";
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:00:12 +02:00
|
|
|
return '<et2-nextmatch-header-' . $matches[2] . ' ' . stringAttrs($attrs) . '/>';
|
2022-07-07 21:18:42 +02:00
|
|
|
}, $str);
|
|
|
|
|
2022-07-29 15:29:39 +02:00
|
|
|
$str = preg_replace('#<passwd ([^>]+)(/|></passwd)>#', '<et2-password $1></et2-password>', $str);
|
2022-07-22 15:21:27 +02:00
|
|
|
|
2022-08-03 15:48:23 +02:00
|
|
|
// fix <(button|buttononly|timestamper).../> --> <et2-(button|image|button-timestamp) (noSubmit="true")?.../>
|
2022-08-07 12:09:02 +02:00
|
|
|
$str = preg_replace_callback('#<(button|buttononly|timestamper|button-timestamp|dropdown_button)\s(.*?)(/|></(button|buttononly|timestamper|button-timestamp|dropdown_button))>#s', function ($matches) use ($name)
|
2022-03-06 19:14:53 +01:00
|
|
|
{
|
2022-07-27 11:04:08 +02:00
|
|
|
$tag = 'et2-button';
|
|
|
|
$attrs = parseAttrs($matches[2]);
|
2022-08-03 15:48:23 +02:00
|
|
|
switch ($matches[1])
|
2022-05-05 11:38:33 +02:00
|
|
|
{
|
2022-08-03 15:48:23 +02:00
|
|
|
case 'buttononly': // replace buttononly tag with noSubmit="true" attribute
|
2022-07-27 11:04:08 +02:00
|
|
|
$attrs['noSubmit'] = 'true';
|
2022-08-03 15:48:23 +02:00
|
|
|
break;
|
|
|
|
case 'timestamper':
|
|
|
|
case 'button-timestamp':
|
|
|
|
$tag .= '-timestamp';
|
|
|
|
$attrs['background_image'] = 'true';
|
|
|
|
break;
|
2022-08-07 12:09:02 +02:00
|
|
|
case 'dropdown_button':
|
|
|
|
$tag = 'et2-dropdown-button';
|
|
|
|
break;
|
2022-07-27 11:04:08 +02:00
|
|
|
}
|
|
|
|
// novalidation --> noValidation
|
|
|
|
if (!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true))
|
|
|
|
{
|
|
|
|
unset($attrs['novalidation']);
|
|
|
|
$attrs['noValidation'] = 'true';
|
|
|
|
}
|
2022-08-23 11:12:10 +02:00
|
|
|
// replace not set background_image attribute with et2-button-icon tag, if not in NM / lists
|
2022-08-23 11:18:21 +02:00
|
|
|
if (!empty($attrs['image']) && (empty($attrs['background_image']) || $attrs['background_image'] === 'false') &&
|
2022-08-23 12:48:36 +02:00
|
|
|
empty($attrs['label']) && !preg_match('/^(index|list)/', $name))
|
2022-07-27 11:04:08 +02:00
|
|
|
{
|
2022-08-22 22:31:11 +02:00
|
|
|
$tag = 'et2-button-icon';
|
2022-07-27 11:04:08 +02:00
|
|
|
}
|
|
|
|
unset($attrs['background_image']);
|
|
|
|
return "<$tag " . stringAttrs($attrs) . '></' . $tag . '>';
|
|
|
|
}, $str);
|
2022-04-19 17:36:44 +02:00
|
|
|
|
2022-09-18 08:54:39 +02:00
|
|
|
$str = preg_replace('#<time_or_date\s([^>]+)/>#', '<et2-date-time-today $1></et2-date-time-today>', $str);
|
2022-07-27 11:04:08 +02:00
|
|
|
$str = preg_replace_callback('#<date(-time[^\s]*|-duration|-since)?\s([^>]+)/>#', static function($matches)
|
|
|
|
{
|
2022-07-28 16:34:25 +02:00
|
|
|
if ($matches[1] === '-time_today') $matches[1] = '-time-today';
|
2022-07-27 11:04:08 +02:00
|
|
|
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))
|
|
|
|
{
|
2022-04-29 17:05:43 +02:00
|
|
|
$str = preg_replace_callback(ADD_ET2_PREFIX_REGEXP, static function (array $matches) {
|
|
|
|
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);
|
2022-07-21 19:29:43 +02:00
|
|
|
}
|
2022-07-27 11:04:08 +02:00
|
|
|
|
2022-07-22 17:20:44 +02:00
|
|
|
// change all attribute-names of new et2-* widgets to camelCase, and other attribute modifications for all web-components
|
2022-08-22 22:31:11 +02:00
|
|
|
$str = preg_replace_callback('#<(et2|records)-([a-z-]+)\s(.*?")\s*/?>#s', static function(array $matches)
|
2022-07-21 19:29:43 +02:00
|
|
|
{
|
2022-07-26 18:00:12 +02:00
|
|
|
$attrs = parseAttrs($matches[3]);
|
2022-07-21 17:57:50 +02:00
|
|
|
|
2022-07-22 20:43:09 +02:00
|
|
|
// fix deprecated attributes: needed, blur, ...
|
|
|
|
static $deprecated = [
|
|
|
|
'needed' => 'required',
|
|
|
|
'blur' => 'placeholder',
|
|
|
|
];
|
2022-07-21 19:29:43 +02:00
|
|
|
foreach($attrs as $name => $value)
|
2022-07-21 17:57:50 +02:00
|
|
|
{
|
2022-07-22 20:43:09 +02:00
|
|
|
if (isset($deprecated[$name]))
|
|
|
|
{
|
|
|
|
unset($attrs[$name]);
|
|
|
|
$attrs[$name = $deprecated[$name]] = $value;
|
|
|
|
}
|
2022-07-21 19:29:43 +02:00
|
|
|
if (count($parts = preg_split('/[_-]/', $name)) > 1)
|
2022-07-21 17:57:50 +02:00
|
|
|
{
|
2022-07-21 19:29:43 +02:00
|
|
|
if ($name === 'parent_node') $parts[1] = 'Id'; // we can not use DOM property parentNode --> parentId
|
|
|
|
$attrs[array_shift($parts).implode('', array_map('ucfirst', $parts))] = $value;
|
|
|
|
unset($attrs[$name]);
|
2022-07-21 17:57:50 +02:00
|
|
|
}
|
2022-07-21 19:29:43 +02:00
|
|
|
}
|
2022-07-22 15:21:27 +02:00
|
|
|
|
|
|
|
// remove no longer necessary et2_fullWidth class, it's the default now anyway
|
|
|
|
if (isset($attrs['class']) && empty($attrs['class'] = trim(preg_replace('/(^| )et2_fullWidth( |$)/', ' ', $attrs['class']))))
|
|
|
|
{
|
|
|
|
unset($attrs['class']);
|
|
|
|
}
|
2022-07-22 17:20:44 +02:00
|
|
|
|
2022-08-23 11:12:10 +02:00
|
|
|
// Drop all (old) size attributes, if it's not shoelace size format: small, medium or large
|
|
|
|
if (isset($attrs['size']) && !in_array($attrs['size'], ['small', 'medium', 'large']))
|
2022-07-22 17:20:44 +02:00
|
|
|
{
|
|
|
|
unset($attrs['size']);
|
|
|
|
}
|
2022-07-22 15:21:27 +02:00
|
|
|
|
2022-07-26 18:00:12 +02:00
|
|
|
return str_replace($matches[3], stringAttrs($attrs).(substr($matches[3], -1) === '/' ? '/' : ''), $matches[0]);
|
2022-07-21 19:29:43 +02:00
|
|
|
}, $str);
|
|
|
|
|
2021-08-15 14:59:23 +02:00
|
|
|
$processing = microtime(true);
|
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
if (isset($cache) && (file_exists($cache_dir = dirname($cache)) || mkdir($cache_dir, 0755, true) || is_dir($cache_dir)))
|
2021-08-15 14:59:23 +02:00
|
|
|
{
|
|
|
|
file_put_contents($cache, $str);
|
|
|
|
}
|
|
|
|
}
|
2022-04-29 17:05:43 +02:00
|
|
|
// stop here for not existing file or path-traversal for both file and cache here
|
2021-08-19 01:41:23 +02:00
|
|
|
if(empty($str) || strpos($path, '..') !== false)
|
2021-08-15 14:59:23 +02:00
|
|
|
{
|
|
|
|
http_response_code(404);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
|
|
|
|
Api\Session::cache_control(86400); // cache for one day
|
|
|
|
$etag = '"' . md5($str) . '"';
|
|
|
|
Header('ETag: ' . $etag);
|
|
|
|
|
|
|
|
// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
|
2021-08-19 01:41:23 +02:00
|
|
|
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag)
|
2021-08-15 14:59:23 +02:00
|
|
|
{
|
|
|
|
header("HTTP/1.1 304 Not Modified");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we run our own gzip compression, to set a correct Content-Length of the encoded content
|
2021-08-19 01:41:23 +02:00
|
|
|
if(function_exists('gzencode') && in_array('gzip', explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']), true))
|
2021-08-15 14:59:23 +02:00
|
|
|
{
|
|
|
|
$gzip_start = microtime(true);
|
|
|
|
$str = gzencode($str);
|
|
|
|
header('Content-Encoding: gzip');
|
2021-08-19 01:41:23 +02:00
|
|
|
$gziping = microtime(true) - $gzip_start;
|
2021-08-15 14:59:23 +02:00
|
|
|
}
|
2021-08-19 01:41:23 +02:00
|
|
|
header('X-Timing: header-include=' . number_format($header_include - $GLOBALS['start'], 3) .
|
|
|
|
(empty($processing) ? ', cache-read=' . number_format($cache_read - $header_include, 3) :
|
|
|
|
', processing=' . number_format($processing - $header_include, 3)) .
|
|
|
|
(!empty($gziping) ? ', gziping=' . number_format($gziping, 3) : '') .
|
|
|
|
', total=' . number_format(microtime(true) - $GLOBALS['start'], 3)
|
|
|
|
);
|
2021-08-15 14:59:23 +02:00
|
|
|
|
|
|
|
// Content-Length header is important, otherwise browsers dont cache!
|
|
|
|
Header('Content-Length: ' . bytes($str));
|
|
|
|
echo $str;
|
|
|
|
|
2021-08-19 01:41:23 +02:00
|
|
|
exit; // stop further processing eg. redirect to login
|
2022-07-26 18:00:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse attributes in an array
|
|
|
|
*
|
|
|
|
* @param string $str
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function parseAttrs($str)
|
|
|
|
{
|
2022-08-06 12:11:41 +02:00
|
|
|
if (!preg_match_all('/(^|\s)([a-z\d_-]+)="([^"]*)"/i', $str, $attrs, PREG_PATTERN_ORDER))
|
2022-07-26 18:00:12 +02:00
|
|
|
{
|
|
|
|
throw new Exception("Can NOT parse attributes from '$str'");
|
|
|
|
}
|
|
|
|
return array_combine($attrs[2], $attrs[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Combine attribute array into a string
|
|
|
|
*
|
|
|
|
* @param array $attrs
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function stringAttrs(array $attrs)
|
|
|
|
{
|
|
|
|
return implode(' ', array_map(static function ($name, $value) {
|
|
|
|
return $name . '="' . $value . '"';
|
|
|
|
}, array_keys($attrs), $attrs));
|
2022-02-15 08:16:55 +01:00
|
|
|
}
|