Skip to content

Commit 8a221b8

Browse files
committed
Update conditional code structure in updateHeaders()
1 parent beea2ff commit 8a221b8

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

extension.driver.php

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -321,66 +321,66 @@ public function addCSS($context) {
321321
public function updateHeaders() {
322322

323323
if (!Frontend::instance()->isLoggedIn()) {
324+
return false;
325+
}
326+
327+
$page_params = Frontend::instance()->Page()->Params();
328+
329+
// search for page settings
330+
//$page_data = Frontend::Page()->pageData();
331+
//$page_settings = $this->getPageSettings($page_data['id']);
332+
$page_settings = $this->getPageSettings($page_params['current-page-id']);
333+
334+
$config = Symphony::Configuration()->get(self::NAME);
324335

325-
$page_params = Frontend::instance()->Page()->Params();
326-
327-
// search for page settings
328-
//$page_data = Frontend::Page()->pageData();
329-
//$page_settings = $this->getPageSettings($page_data['id']);
330-
$page_settings = $this->getPageSettings($page_params['current-page-id']);
331-
332-
$config = Symphony::Configuration()->get(self::NAME);
333-
334-
// @TODO: validate preferences
335-
336-
// if page HTTP caching is not desired
337-
if (($page_settings['caching'] != 'on' && $config['default_caching'] != 'on') ||
338-
($page_settings['caching'] == 'off')) {
339-
return false;
340-
}
341-
342-
// page HTTP caching is desired
343-
$page_http_caching = array();
344-
345-
if (!empty($page_settings['max_age'])) {
346-
$page_http_caching['max_age'] = $page_settings['max_age'];
347-
} elseif (!empty($config['default_max_age'])) {
348-
$page_http_caching['max_age'] = $config['default_max_age'];
349-
} else {
350-
return false;
351-
}
352-
353-
if ($page_settings['intermediary'] == 'no') {
354-
$page_http_caching['intermediary'] = 'private';
355-
} elseif ($page_settings['intermediary'] == 'yes') {
356-
$page_http_caching['intermediary'] = 'public';
357-
} elseif ($config['default_intermediary'] == 'yes') {
358-
$page_http_caching['intermediary'] = 'public';
359-
} else {
360-
$page_http_caching['intermediary'] = 'private';
361-
}
362-
363-
// remove unwanted/unnecessary headers
364-
if (version_compare($page_params['symphony-version'], '2.3.2', '<')) {
365-
// Symphony CMS 2.3 - 2.3.1: set the unwanted header values to be blank
366-
Frontend::Page()->addHeaderToPage('Expires', '');
367-
Frontend::Page()->addHeaderToPage('Last-Modified', '');
368-
Frontend::Page()->addHeaderToPage('Pragma', '');
369-
} else {
370-
// Symphony CMS 2.3.2+: completely remove headers with new removeHeaderFromPage method
371-
Frontend::Page()->removeHeaderFromPage('Expires');
372-
Frontend::Page()->removeHeaderFromPage('Last-Modified');
373-
Frontend::Page()->removeHeaderFromPage('Pragma');
374-
}
375-
376-
// add HTTP cache header
377-
Frontend::Page()->addHeaderToPage(
378-
'Cache-Control',
379-
$page_http_caching['intermediary'] . ', max-age=' . $page_http_caching['max_age']
380-
);
336+
// @TODO: validate preferences
381337

338+
// if page HTTP caching is not desired
339+
if (($page_settings['caching'] != 'on' && $config['default_caching'] != 'on') ||
340+
($page_settings['caching'] == 'off')) {
341+
return false;
342+
}
343+
344+
// page HTTP caching is desired
345+
$page_http_caching = array();
346+
347+
if (!empty($page_settings['max_age'])) {
348+
$page_http_caching['max_age'] = $page_settings['max_age'];
349+
} elseif (!empty($config['default_max_age'])) {
350+
$page_http_caching['max_age'] = $config['default_max_age'];
351+
} else {
352+
return false;
382353
}
383354

355+
if ($page_settings['intermediary'] == 'no') {
356+
$page_http_caching['intermediary'] = 'private';
357+
} elseif ($page_settings['intermediary'] == 'yes') {
358+
$page_http_caching['intermediary'] = 'public';
359+
} elseif ($config['default_intermediary'] == 'yes') {
360+
$page_http_caching['intermediary'] = 'public';
361+
} else {
362+
$page_http_caching['intermediary'] = 'private';
363+
}
364+
365+
// remove unwanted/unnecessary headers
366+
if (version_compare($page_params['symphony-version'], '2.3.2', '<')) {
367+
// Symphony CMS 2.3 - 2.3.1: set the unwanted header values to be blank
368+
Frontend::Page()->addHeaderToPage('Expires', '');
369+
Frontend::Page()->addHeaderToPage('Last-Modified', '');
370+
Frontend::Page()->addHeaderToPage('Pragma', '');
371+
} else {
372+
// Symphony CMS 2.3.2+: completely remove headers with new removeHeaderFromPage method
373+
Frontend::Page()->removeHeaderFromPage('Expires');
374+
Frontend::Page()->removeHeaderFromPage('Last-Modified');
375+
Frontend::Page()->removeHeaderFromPage('Pragma');
376+
}
377+
378+
// add HTTP cache header
379+
Frontend::Page()->addHeaderToPage(
380+
'Cache-Control',
381+
$page_http_caching['intermediary'] . ', max-age=' . $page_http_caching['max_age']
382+
);
383+
384384
}
385385

386386
}

0 commit comments

Comments
 (0)