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-05-13 11:59:13 +02:00
|
|
|
const ADD_ET2_PREFIX_REGEXP = '#<((/?)([vh]?box|date(-time[^\s]*|-duration|-since)?|textbox|textarea|button|colorpicker|url(-email|-phone|-fax)?))(/?|\s[^>]*)>#m';
|
2022-04-29 17:05:43 +02:00
|
|
|
const ADD_ET2_PREFIX_LAST_GROUP = 6;
|
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-06-13 08:20:53 +02:00
|
|
|
const ADD_ET2_PREFIX_LEGACY_REGEXP = '#<(description|label|image|vfs-mime|vfs-uid|vfs-gid|link|link-[a-z]+|favorites)\s([^>]+)/>#m';
|
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
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
static $legacy_options = array( // use "ignore" to ignore further comma-sep. values, otherwise they are all in last attribute
|
2022-06-03 18:18:18 +02:00
|
|
|
'select' => 'empty_label,ignore',
|
2022-06-01 16:05:34 +02:00
|
|
|
'select-account' => 'empty_label,account_type,ignore',
|
2022-06-03 18:18:18 +02:00
|
|
|
'select-number' => 'empty_label,min,max,interval,suffix',
|
|
|
|
'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',
|
|
|
|
// Legacy option "mode" was never implemented in et2
|
|
|
|
'description' => 'bold-italic,link,activate_links,label_for,link_target,link_popup_size,link_title',
|
|
|
|
'button' => 'image,ro_image',
|
|
|
|
'buttononly' => 'image,ro_image',
|
|
|
|
'link-entry' => 'only_app,application_list',
|
2022-06-01 16:05:34 +02:00
|
|
|
);
|
|
|
|
// prefer more specific type-subtype over just type
|
2022-06-07 22:16:55 +02:00
|
|
|
$names = $legacy_options[$matches[1] . $matches[2]] ?? $legacy_options[$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-05-12 18:14:21 +02:00
|
|
|
preg_match_all('/(^| )([a-z0-9_-]+)="([^"]+)"/i', $matches[1], $attrs, PREG_PATTERN_ORDER);
|
2022-04-29 17:05:43 +02:00
|
|
|
$attrs = array_combine($attrs[2], $attrs[3]);
|
|
|
|
|
|
|
|
$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-04-29 17:05:43 +02:00
|
|
|
return "<$tag " . implode(' ', array_map(function ($name, $value) {
|
|
|
|
return $name . '="' . $value . '"';
|
|
|
|
}, array_keys($attrs), $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-05-07 13:31:46 +02:00
|
|
|
// modify <(vfs-mime|link-string|link-list) --> <et2-*
|
2022-06-08 18:26:42 +02:00
|
|
|
$str = preg_replace(ADD_ET2_PREFIX_LEGACY_REGEXP, '<et2-$1 $2></et2-$1>',
|
|
|
|
str_replace('<description/>', '<et2-description></et2-description>', $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];
|
|
|
|
preg_match_all('/(^| )([a-z0-9_-]+)="([^"]+)"/i', $matches[2], $attrs, PREG_PATTERN_ORDER);
|
|
|
|
$attrs = array_combine($attrs[2], $attrs[3]);
|
|
|
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
return "<$tag " . implode(' ', array_map(function ($name, $value) {
|
|
|
|
return $name . '="' . $value . '"';
|
|
|
|
}, array_keys($attrs), $attrs)
|
|
|
|
) . "></$tag>";
|
|
|
|
}, $str);
|
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
// ^^^^^^^^^^^^^^^^ above widgets get transformed independent of legacy="true" set in overlay ^^^^^^^^^^^^^^^^^^
|
2021-08-21 09:55:21 +02:00
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
// eTemplate marked as legacy --> replace only some widgets (eg. requiring jQueryUI) with web-components
|
|
|
|
if (preg_match('/<overlay[^>]* legacy="true"/', $str))
|
2022-03-06 19:14:53 +01:00
|
|
|
{
|
2022-05-05 11:38:33 +02:00
|
|
|
$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);
|
2022-04-29 17:05:43 +02:00
|
|
|
}
|
|
|
|
else
|
2022-04-07 20:05:32 +02:00
|
|
|
{
|
2022-04-29 17:05:43 +02:00
|
|
|
// fix deprecated attributes: needed, blur, ...
|
|
|
|
static $deprecated = [
|
|
|
|
'needed' => 'required',
|
|
|
|
'blur' => 'placeholder',
|
|
|
|
];
|
|
|
|
$str = preg_replace_callback('#<[^ ]+[^>]* (' . implode('|', array_keys($deprecated)) . ')="([^"]+)"[ />]#',
|
|
|
|
static function ($matches) use ($deprecated) {
|
|
|
|
return str_replace($matches[1] . '="', $deprecated[$matches[1]] . '="', $matches[0]);
|
|
|
|
}, $str);
|
2022-01-19 09:57:06 +01:00
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
// fix <textbox multiline="true" .../> --> <textarea .../> (et2-prefix and self-closing is handled below)
|
|
|
|
$str = preg_replace('#<textbox(.*?)\smultiline="true"(.*?)/>#u', '<textarea$1$2/>', $str);
|
2022-01-19 21:17:07 +01:00
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
// fix <(textbox|int(eger)?|float) precision="int(eger)?|float" .../> --> <et2-number precision=...></et2-number>
|
|
|
|
$str = preg_replace_callback('#<(textbox|int(eger)?|float|number).*?\s(type="(int(eger)?|float)")?.*?/>#u',
|
|
|
|
static function ($matches) {
|
|
|
|
if ($matches[1] === 'textbox' && !in_array($matches[4], ['float', 'int', 'integer'], true))
|
|
|
|
{
|
|
|
|
return $matches[0]; // 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);
|
|
|
|
|
|
|
|
// fix <button(only)?.../> --> <et2-button(-image)? noSubmit="true".../>
|
|
|
|
$str = preg_replace_callback('#<button(only)?\s(.*?)/>#u', function ($matches) use ($name) {
|
|
|
|
$tag = 'et2-button';
|
2022-05-12 18:14:21 +02:00
|
|
|
preg_match_all('/(^| )([a-z0-9_-]+)="([^"]+)"/i', $matches[2], $attrs, PREG_PATTERN_ORDER);
|
2022-04-29 17:05:43 +02:00
|
|
|
$attrs = array_combine($attrs[2], $attrs[3]);
|
|
|
|
// replace buttononly tag with noSubmit="true" attribute
|
|
|
|
if (!empty($matches[1]))
|
2022-02-16 09:38:28 +01:00
|
|
|
{
|
2022-04-29 17:05:43 +02:00
|
|
|
$attrs['noSubmit'] = 'true';
|
2022-02-16 09:38:28 +01:00
|
|
|
}
|
2022-04-29 17:05:43 +02:00
|
|
|
// 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 " . implode(' ', array_map(function ($name, $value) {
|
|
|
|
return $name . '="' . $value . '"';
|
|
|
|
}, array_keys($attrs), $attrs)) . '></' . $tag . '>';
|
|
|
|
}, $str);
|
2022-04-19 17:36:44 +02:00
|
|
|
|
2022-04-29 17:05:43 +02:00
|
|
|
$str = preg_replace_callback(ADD_ET2_PREFIX_REGEXP, static function (array $matches) {
|
2022-05-05 11:38:33 +02:00
|
|
|
if ($matches[3] === 'date-time_today') $matches[3] = 'date-time-today';
|
2022-04-29 17:05:43 +02:00
|
|
|
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-04-19 17:36:44 +02:00
|
|
|
|
2022-06-06 18:21:31 +02:00
|
|
|
// handling of partially implemented select and taglist widget, incl. removing of type attribute
|
|
|
|
$str = preg_replace_callback('#<(select|taglist)(-[^ ]+)? ([^>]+)/>#', static function (array $matches) {
|
2022-05-27 16:24:57 +02:00
|
|
|
preg_match_all('/(^| )([a-z0-9_-]+)="([^"]*)"/i', $matches[3], $attrs, PREG_PATTERN_ORDER);
|
2022-04-29 17:05:43 +02:00
|
|
|
$attrs = array_combine($attrs[2], $attrs[3]);
|
2021-08-15 14:59:23 +02:00
|
|
|
|
2022-06-06 18:21:31 +02:00
|
|
|
if ($matches[1] === 'taglist')
|
2022-04-29 17:05:43 +02:00
|
|
|
{
|
2022-06-13 08:20:53 +02:00
|
|
|
if (empty($matches[2]) || !in_array(substr($matches[2], 1), ['thumbnail']))
|
2022-04-29 17:05:43 +02:00
|
|
|
{
|
2022-06-06 18:21:31 +02:00
|
|
|
$matches[1] = 'select';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $matches[0]; // still use taglist-* for now
|
2022-04-29 17:05:43 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-27 16:24:57 +02:00
|
|
|
|
2022-06-06 18:21:31 +02:00
|
|
|
if (isset($attrs['tags']))
|
2022-05-27 16:24:57 +02:00
|
|
|
{
|
2022-06-06 18:21:31 +02:00
|
|
|
$attrs['multiple'] = 'true';
|
|
|
|
unset($attrs['tags']);
|
2022-05-27 16:24:57 +02:00
|
|
|
}
|
2022-06-06 18:21:31 +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']);
|
|
|
|
}
|
|
|
|
// type attribute need to go in widget type <select type="select-account" --> <et2-select-account
|
|
|
|
if (empty($matches[2]) && isset($attrs['type']))
|
|
|
|
{
|
|
|
|
$matches[1] = $attrs['type'];
|
|
|
|
unset($attrs['type']);
|
|
|
|
}
|
|
|
|
return '<et2-' . $matches[1] . $matches[2] . ' ' . implode(' ', array_map(static function($attr, $val)
|
|
|
|
{
|
|
|
|
return $attr.'="'.$val.'"';
|
|
|
|
}, array_keys($attrs), $attrs)) . '></et2-' . $matches[1] . $matches[2] . '>';
|
|
|
|
}, $str);
|
2022-04-29 17:05:43 +02:00
|
|
|
}
|
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-02-15 08:16:55 +01:00
|
|
|
}
|