From 3c2fa086d62e69d953d8fbbe00b0867f7fc5f5c4 Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 9 Feb 2021 22:10:26 +0100 Subject: [PATCH] new: [baseurl] added better baseurl handling - set the baseurl via /config/app_local.php - simple set the baseurl to an absolute path or to a relative path if you with to use a subdirectory without setting a baseurl - If no baseurl is set above, Cerebrate will also check the CEREBRATE_BASEURL environment variable --- config/app_local.example.php | 3 ++- src/Controller/AppController.php | 7 ++++++- .../genericElements/IndexTable/Fields/actions.php | 5 +++-- .../genericElements/IndexTable/Fields/alignments.php | 6 ++++-- .../genericElements/IndexTable/Fields/caching.php | 2 +- .../IndexTable/Fields/correlations.php | 3 ++- .../IndexTable/Fields/count_summary.php | 3 ++- .../IndexTable/Fields/distribution_levels.php | 2 +- .../IndexTable/Fields/generic_field.php | 3 ++- .../genericElements/IndexTable/Fields/org.php | 6 +++--- .../genericElements/IndexTable/Fields/role.php | 2 +- .../IndexTable/Fields/self_registration.php | 3 ++- .../IndexTable/Fields/target_event.php | 2 +- .../genericElements/ListTopBar/element_embedded.php | 4 ++-- .../genericElements/ListTopBar/element_simple.php | 2 +- .../SingleViews/Fields/alignmentField.php | 6 ++++-- .../SingleViews/Fields/genericField.php | 3 ++- .../element/genericElements/header_scaffold.php | 12 ++++++++---- .../genericElements/side_menu_dropdown_scaffold.php | 2 +- .../element/genericElements/side_menu_scaffold.php | 4 ++-- 20 files changed, 50 insertions(+), 30 deletions(-) diff --git a/config/app_local.example.php b/config/app_local.example.php index 6ec0087..03aeef1 100644 --- a/config/app_local.example.php +++ b/config/app_local.example.php @@ -91,6 +91,7 @@ return [ ], 'Cerebrate' => [ 'open' => [], - 'dark' => 0 + 'dark' => 0, + 'baseurl' => '' ] ]; diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 4370704..e713f50 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -112,7 +112,12 @@ class AppController extends Controller $this->set('ajax', $this->request->is('ajax')); $this->request->getParam('prefix'); $this->set('darkMode', !empty(Configure::read('Cerebrate.dark'))); - $this->set('baseurl', empty(Configure::read('baseurl')) ? '' : Configure::read('baseurl')); + if (!empty(Configure::read('baseurl'))) { + Configure::write('App.fullBaseUrl', Configure::read('baseurl')); + } else if (!empty(env('CEREBRATE_BASEURL'))) { + Configure::write('App.fullBaseUrl', env('CEREBRATE_BASEURL')); + } + $this->set('baseurl', Configure::read('App.fullBaseUrl')); } private function authApiUser(): void diff --git a/templates/element/genericElements/IndexTable/Fields/actions.php b/templates/element/genericElements/IndexTable/Fields/actions.php index 17707b4..1a58422 100644 --- a/templates/element/genericElements/IndexTable/Fields/actions.php +++ b/templates/element/genericElements/IndexTable/Fields/actions.php @@ -35,7 +35,7 @@ } } $url_param_data_paths = ''; - $url = empty($action['url']) ? '#' : h($action['url']); + $url = empty($action['url']) ? '#' : $baseurl . '/' . h($action['url']); if (!empty($action['url_params_data_paths'])) { if (is_array($action['url_params_data_paths'])) { $temp = array(); @@ -82,7 +82,8 @@ } echo sprintf( - ' ', + ' ', + $baseurl, $url, empty($action['title']) ? '' : h($action['title']), empty($action['title']) ? '' : h($action['title']), diff --git a/templates/element/genericElements/IndexTable/Fields/alignments.php b/templates/element/genericElements/IndexTable/Fields/alignments.php index 1ee3df6..91b3719 100644 --- a/templates/element/genericElements/IndexTable/Fields/alignments.php +++ b/templates/element/genericElements/IndexTable/Fields/alignments.php @@ -8,7 +8,8 @@ if ($field['scope'] === 'individuals') { '
%s @ %s
', h($alignment['type']), sprintf( - '%s', + '%s', + $baseurl, h($alignment['organisation']['id']), h($alignment['organisation']['name']) ), @@ -27,7 +28,8 @@ if ($field['scope'] === 'individuals') { '
[%s] %s
', h($alignment['type']), sprintf( - '%s', + '%s', + $baseurl, h($alignment['individual']['id']), h($alignment['individual']['email']) ), diff --git a/templates/element/genericElements/IndexTable/Fields/caching.php b/templates/element/genericElements/IndexTable/Fields/caching.php index 3020f39..38cc344 100644 --- a/templates/element/genericElements/IndexTable/Fields/caching.php +++ b/templates/element/genericElements/IndexTable/Fields/caching.php @@ -24,7 +24,7 @@ h($ageString), (!$enabled || !$isSiteAdmin) ? '' : sprintf( ' ', - $baseurl . '/feeds/cacheFeeds/' . h($primary), + $baseurl . 'feeds/cacheFeeds/' . h($primary), __('Cache feed'), __('Cache feed') ) diff --git a/templates/element/genericElements/IndexTable/Fields/correlations.php b/templates/element/genericElements/IndexTable/Fields/correlations.php index b5cc013..198da9b 100644 --- a/templates/element/genericElements/IndexTable/Fields/correlations.php +++ b/templates/element/genericElements/IndexTable/Fields/correlations.php @@ -6,7 +6,8 @@ $correlations_html = array(); foreach ($correlations as $id => $name) { $correlations_html[] = sprintf( - '%s', + '%s', + $baseurl, sprintf( '%s/%s', $scope_to_url[empty($scope) ? 'event' : $scope], diff --git a/templates/element/genericElements/IndexTable/Fields/count_summary.php b/templates/element/genericElements/IndexTable/Fields/count_summary.php index 69162cd..ce74e2a 100644 --- a/templates/element/genericElements/IndexTable/Fields/count_summary.php +++ b/templates/element/genericElements/IndexTable/Fields/count_summary.php @@ -15,7 +15,8 @@ $field['url'] = str_replace('{{url_data}}', $url_data_path, $field['url']); } echo sprintf( - '%s', + '%s', + $baseurl, h($field['url']), count($data) ); diff --git a/templates/element/genericElements/IndexTable/Fields/distribution_levels.php b/templates/element/genericElements/IndexTable/Fields/distribution_levels.php index 912ffef..2220f9b 100644 --- a/templates/element/genericElements/IndexTable/Fields/distribution_levels.php +++ b/templates/element/genericElements/IndexTable/Fields/distribution_levels.php @@ -5,7 +5,7 @@ $distributionLevel == 0 ? 'red' : '', $distributionLevel != 4 ? $distributionLevels[$distributionLevel] : sprintf( - '%s', + '%s', $baseurl, h($row['SharingGroup']['id']), h($row['SharingGroup']['name']) diff --git a/templates/element/genericElements/IndexTable/Fields/generic_field.php b/templates/element/genericElements/IndexTable/Fields/generic_field.php index abf1571..edff114 100644 --- a/templates/element/genericElements/IndexTable/Fields/generic_field.php +++ b/templates/element/genericElements/IndexTable/Fields/generic_field.php @@ -36,7 +36,8 @@ } } $data = sprintf( - '%s', + '%s', + $baseurl, h($field['url']), $data ); diff --git a/templates/element/genericElements/IndexTable/Fields/org.php b/templates/element/genericElements/IndexTable/Fields/org.php index 83d35ed..3f255e8 100644 --- a/templates/element/genericElements/IndexTable/Fields/org.php +++ b/templates/element/genericElements/IndexTable/Fields/org.php @@ -18,13 +18,13 @@ if ($field['fields']['allow_picture'] && !empty($org['id'])) { echo sprintf( '%s', - $baseurl . '/organisations/view/' . h($org['id']), + $baseurl . 'organisations/view/' . h($org['id']), h($org['name']) ); //echo $this->OrgImg->getOrgImg(array('name' => $org['name'], 'id' => $org['id'], 'size' => 24)); } else { echo sprintf( - '%s', + '%s', $baseurl, empty($org['id']) ? h($org['uuid']) : h($org['id']), h($org['name']) @@ -37,7 +37,7 @@ if ($field['fields']['allow_picture']) { echo sprintf( '%s', - $baseurl . '/organisations/view/' . h($org['id']), + $baseurl . 'organisations/view/' . h($org['id']), h($org['name']) ); //echo $this->OrgImg->getOrgImg(array('name' => $field['fields']['default_org'], 'size' => 24)); diff --git a/templates/element/genericElements/IndexTable/Fields/role.php b/templates/element/genericElements/IndexTable/Fields/role.php index 377dfef..fd723c5 100644 --- a/templates/element/genericElements/IndexTable/Fields/role.php +++ b/templates/element/genericElements/IndexTable/Fields/role.php @@ -9,7 +9,7 @@ foreach ($roles as $role) { $i++; echo sprintf( - '%s', + '%s', $baseurl, h($role['id']), h($role['name']) diff --git a/templates/element/genericElements/IndexTable/Fields/self_registration.php b/templates/element/genericElements/IndexTable/Fields/self_registration.php index 44efff9..affd042 100644 --- a/templates/element/genericElements/IndexTable/Fields/self_registration.php +++ b/templates/element/genericElements/IndexTable/Fields/self_registration.php @@ -9,7 +9,8 @@ (!empty($self_registration_flag[0])) ? 'check' : 'times', (empty($self_registration_flag[0])) ? '' : sprintf( - ' (' . __('click here') . ')', + ' (' . __('click here') . ')', + $baseurl, h($url) ) ); diff --git a/templates/element/genericElements/IndexTable/Fields/target_event.php b/templates/element/genericElements/IndexTable/Fields/target_event.php index 0422c88..bedf413 100644 --- a/templates/element/genericElements/IndexTable/Fields/target_event.php +++ b/templates/element/genericElements/IndexTable/Fields/target_event.php @@ -11,7 +11,7 @@ } else { if ($data['Feed.event_id']) { echo sprintf( - '%s', + '%s', $baseurl, h($data['Feed.event_id']), __('Fixed event %s', h($data['Feed.event_id'])) diff --git a/templates/element/genericElements/ListTopBar/element_embedded.php b/templates/element/genericElements/ListTopBar/element_embedded.php index a3b540b..6fce738 100644 --- a/templates/element/genericElements/ListTopBar/element_embedded.php +++ b/templates/element/genericElements/ListTopBar/element_embedded.php @@ -34,11 +34,11 @@ empty($data['class']) ? '' : h($data['class']), empty($data['active']) ? '' : 'background-blue', // Change the default class for highlighted/active toggles here empty($data['id']) ? '' : h($data['id']), - empty($data['url']) ? '#' : h($data['url']), // prevent default is passed if the url is not set + empty($data['url']) ? '#' : $baseurl . h($data['url']), // prevent default is passed if the url is not set empty($onClick) ? '' : $onClick, // pass $data['onClick'] for the function name to call and $data['onClickParams'] for the parameter list empty($dataFields) ? '' : $dataFields, empty($data['title']) ? '' : sprintf('title="%s"', h($data['title'])), - !empty($data['text']) ? '' : !empty($data['title']) ? sprintf('aria-label="%s"', h($data['title'])) : '', + !empty($data['text']) ? '' : !empty($data['title']) ? sprintf('aria-label="%s"', h($data['title'])) : '', empty($data['fa-icon']) ? '' : sprintf('', $data['fa-icon']), // this has to be sanitised beforehand! empty($data['html']) ? '' : $data['html'], // this has to be sanitised beforehand! empty($data['text']) ? '' : h($data['text']) diff --git a/templates/element/genericElements/ListTopBar/element_simple.php b/templates/element/genericElements/ListTopBar/element_simple.php index afa5dae..f1b411f 100644 --- a/templates/element/genericElements/ListTopBar/element_simple.php +++ b/templates/element/genericElements/ListTopBar/element_simple.php @@ -44,7 +44,7 @@ empty($data['class']) ? '' : h($data['class']), empty($data['active']) ? 'btn-inverse' : 'btn-primary', // Change the default class for highlighted/active toggles here empty($data['id']) ? '' : 'id="' . h($data['id']) . '"', - empty($data['url']) ? '#' : h($data['url']), // prevent default is passed if the url is not set + empty($data['url']) ? '#' : $baseurl . h($data['url']), // prevent default is passed if the url is not set empty($onClick) ? '' : $onClick, // pass $data['onClick'] for the function name to call and $data['onClickParams'] for the parameter list empty($dataFields) ? '' : $dataFields, empty($data['title']) ? '' : sprintf('title="%s"', h($data['title'])), diff --git a/templates/element/genericElements/SingleViews/Fields/alignmentField.php b/templates/element/genericElements/SingleViews/Fields/alignmentField.php index 8cec8d5..2759642 100644 --- a/templates/element/genericElements/SingleViews/Fields/alignmentField.php +++ b/templates/element/genericElements/SingleViews/Fields/alignmentField.php @@ -14,7 +14,8 @@ if ($field['scope'] === 'individuals') { '
%s @ %s
', h($alignment['type']), sprintf( - '%s', + '%s', + $baseurl, h($alignment['organisation']['id']), h($alignment['organisation']['name']) ), @@ -33,7 +34,8 @@ if ($field['scope'] === 'individuals') { '
[%s] %s
', h($alignment['type']), sprintf( - '%s', + '%s', + $baseurl, h($alignment['individual']['id']), h($alignment['individual']['email']) ), diff --git a/templates/element/genericElements/SingleViews/Fields/genericField.php b/templates/element/genericElements/SingleViews/Fields/genericField.php index 21e23a7..3c54be3 100644 --- a/templates/element/genericElements/SingleViews/Fields/genericField.php +++ b/templates/element/genericElements/SingleViews/Fields/genericField.php @@ -15,7 +15,8 @@ if (!empty($field['url'])) { } } $string = sprintf( - '%s', + '%s', + $baseurl, h($field['url']), $string ); diff --git a/templates/element/genericElements/header_scaffold.php b/templates/element/genericElements/header_scaffold.php index f7ed201..1fe6a2f 100644 --- a/templates/element/genericElements/header_scaffold.php +++ b/templates/element/genericElements/header_scaffold.php @@ -8,8 +8,9 @@ foreach ($data['menu'] as $name => $menuElement) { } if (!empty($menuElement['type']) === 'single' && $menuElement['type'] === 'single') { $navdata .= sprintf( - '