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
pull/38/head
iglocska 2021-02-09 22:10:26 +01:00
parent c87f6651dc
commit 3c2fa086d6
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
20 changed files with 50 additions and 30 deletions

View File

@ -91,6 +91,7 @@ return [
],
'Cerebrate' => [
'open' => [],
'dark' => 0
'dark' => 0,
'baseurl' => ''
]
];

View File

@ -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

View File

@ -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(
'<a href="%s" title="%s" aria-label="%s" %s %s class="link-unstyled"><i class="%s"></i></a> ',
'<a href="%s%s" title="%s" aria-label="%s" %s %s class="link-unstyled"><i class="%s"></i></a> ',
$baseurl,
$url,
empty($action['title']) ? '' : h($action['title']),
empty($action['title']) ? '' : h($action['title']),

View File

@ -8,7 +8,8 @@ if ($field['scope'] === 'individuals') {
'<div><span class="font-weight-bold">%s</span> @ %s <a href="#" class="fas fa-trash .text-reset .text-decoration-none" onClick="%s"></a></div>',
h($alignment['type']),
sprintf(
'<a href="/organisations/view/%s">%s</a>',
'<a href="%sorganisations/view/%s">%s</a>',
$baseurl,
h($alignment['organisation']['id']),
h($alignment['organisation']['name'])
),
@ -27,7 +28,8 @@ if ($field['scope'] === 'individuals') {
'<div>[<span class="font-weight-bold">%s</span>] %s <a href="#" class="fas fa-trash .text-reset .text-decoration-none" onClick="%s"></a></div>',
h($alignment['type']),
sprintf(
'<a href="/individuals/view/%s">%s</a>',
'<a href="%sindividuals/view/%s">%s</a>',
$baseurl,
h($alignment['individual']['id']),
h($alignment['individual']['email'])
),

View File

@ -24,7 +24,7 @@
h($ageString),
(!$enabled || !$isSiteAdmin) ? '' : sprintf(
' <a href="%s" aria-label="%s" title="%s"><span class="fa fa-memory"></span></a>',
$baseurl . '/feeds/cacheFeeds/' . h($primary),
$baseurl . 'feeds/cacheFeeds/' . h($primary),
__('Cache feed'),
__('Cache feed')
)

View File

@ -6,7 +6,8 @@
$correlations_html = array();
foreach ($correlations as $id => $name) {
$correlations_html[] = sprintf(
'<a href="%s" title="%s">%s</a>',
'<a href="%s%s" title="%s">%s</a>',
$baseurl,
sprintf(
'%s/%s',
$scope_to_url[empty($scope) ? 'event' : $scope],

View File

@ -15,7 +15,8 @@
$field['url'] = str_replace('{{url_data}}', $url_data_path, $field['url']);
}
echo sprintf(
'<a href="%s">%s</a>',
'<a href="%s%s">%s</a>',
$baseurl,
h($field['url']),
count($data)
);

View File

@ -5,7 +5,7 @@
$distributionLevel == 0 ? 'red' : '',
$distributionLevel != 4 ? $distributionLevels[$distributionLevel] :
sprintf(
'<a href="%s/sharing_groups/view/%s">%s</a>',
'<a href="%ssharing_groups/view/%s">%s</a>',
$baseurl,
h($row['SharingGroup']['id']),
h($row['SharingGroup']['name'])

View File

@ -36,7 +36,8 @@
}
}
$data = sprintf(
'<a href="%s">%s</a>',
'<a href="%s%s">%s</a>',
$baseurl,
h($field['url']),
$data
);

View File

@ -18,13 +18,13 @@
if ($field['fields']['allow_picture'] && !empty($org['id'])) {
echo sprintf(
'<a href="%s">%s</a>',
$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(
'<a href="%s/organisations/view/%s">%s</a>',
'<a href="%sorganisations/view/%s">%s</a>',
$baseurl,
empty($org['id']) ? h($org['uuid']) : h($org['id']),
h($org['name'])
@ -37,7 +37,7 @@
if ($field['fields']['allow_picture']) {
echo sprintf(
'<a href="%s">%s</a>',
$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));

View File

@ -9,7 +9,7 @@
foreach ($roles as $role) {
$i++;
echo sprintf(
'<a href="%s/roles/view/%s">%s</a>',
'<a href="%sroles/view/%s">%s</a>',
$baseurl,
h($role['id']),
h($role['name'])

View File

@ -9,7 +9,8 @@
(!empty($self_registration_flag[0])) ? 'check' : 'times',
(empty($self_registration_flag[0])) ? '' :
sprintf(
' (<a href="%s/users/register">' . __('click here') . '</a>)',
' (<a href="%s%s/users/register">' . __('click here') . '</a>)',
$baseurl,
h($url)
)
);

View File

@ -11,7 +11,7 @@
} else {
if ($data['Feed.event_id']) {
echo sprintf(
'<a href="%s/events/view/%s">%s</a>',
'<a href="%sevents/view/%s">%s</a>',
$baseurl,
h($data['Feed.event_id']),
__('Fixed event %s', h($data['Feed.event_id']))

View File

@ -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('<i class="fa fa-%s"></i>', $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'])

View File

@ -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'])),

View File

@ -14,7 +14,8 @@ if ($field['scope'] === 'individuals') {
'<div><span class="font-weight-bold">%s</span> @ %s <a href="#" class="fas fa-trash" onClick="%s"></a></div>',
h($alignment['type']),
sprintf(
'<a href="/organisations/view/%s">%s</a>',
'<a href="%sorganisations/view/%s">%s</a>',
$baseurl,
h($alignment['organisation']['id']),
h($alignment['organisation']['name'])
),
@ -33,7 +34,8 @@ if ($field['scope'] === 'individuals') {
'<div>[<span class="font-weight-bold">%s</span>] %s <a href="#" class="fas fa-trash" onClick="%s"></a></div>',
h($alignment['type']),
sprintf(
'<a href="/individuals/view/%s">%s</a>',
'<a href="%sindividuals/view/%s">%s</a>',
$baseurl,
h($alignment['individual']['id']),
h($alignment['individual']['email'])
),

View File

@ -15,7 +15,8 @@ if (!empty($field['url'])) {
}
}
$string = sprintf(
'<a href="%s">%s</a>',
'<a href="%s%s">%s</a>',
$baseurl,
h($field['url']),
$string
);

View File

@ -8,8 +8,9 @@ foreach ($data['menu'] as $name => $menuElement) {
}
if (!empty($menuElement['type']) === 'single' && $menuElement['type'] === 'single') {
$navdata .= sprintf(
'<li class="nav-item active"><a class="nav-link %s" href="%s">%s</a>',
'<li class="nav-item active"><a class="nav-link %s" href="%s%s">%s</a>',
empty($menuElement['class']) ? '' : h($menuElement['class']),
$baseurl,
empty($menuElement['url']) ? '' : h($menuElement['url']),
empty($name) ? '' : h($name)
);
@ -29,8 +30,9 @@ foreach ($data['menu'] as $name => $menuElement) {
continue;
}
$navdataElements .= sprintf(
'<a class="dropdown-item %s" href="%s">%s</a>',
'<a class="dropdown-item %s" href="%s%s">%s</a>',
empty($child['class']) ? '' : h($child['class']),
$baseurl,
empty($child['url']) ? '' : h($child['url']),
empty($child['label']) ? '' : h($child['label'])
);
@ -51,7 +53,8 @@ foreach ($data['menu'] as $name => $menuElement) {
}
}
$logoutButton = sprintf(
'<span class="nav-item"><a href="/users/logout" class="nav-link">%s</a></span>',
'<span class="nav-item"><a href="%susers/logout" class="nav-link">%s</a></span>',
$baseurl,
__('Logout')
);
$navdata = sprintf(
@ -60,8 +63,9 @@ $navdata = sprintf(
$logoutButton
);
$homeButton = sprintf(
'<a class="navbar-brand %s" href="%s">%s</a>',
'<a class="navbar-brand %s" href="%s%s">%s</a>',
empty($data['home']['class']) ? '' : h($data['home']['class']),
$baseurl,
empty($data['home']['url']) ? '' : h($data['home']['url']),
empty($data['home']['text']) ? '' : h($data['home']['text'])
);

View File

@ -27,7 +27,7 @@ if (isset($menu[$metaGroup])) {
}
$children .= sprintf(
'<a class="dropdown-item" href="%s">%s</a>',
empty($data['url']) ? '#' : h($data['url']),
empty($data['url']) ? '#' : $baseurl . h($data['url']),
empty($data['label']) ? h($action) : $data['label']
);
}

View File

@ -5,7 +5,7 @@ if (isset($menu[$metaGroup])) {
foreach ($menu[$metaGroup] as $scope => $scopeData) {
$children .= sprintf(
'<a href="%s" class="font-weight-bold list-group-item list-group-item-action %s %s pl-1 border-0">%s</a>',
empty($scopeData['url']) ? '#' : h($scopeData['url']),
empty($scopeData['url']) ? '#' : $baseurl . '/' . h($scopeData['url']),
empty($scopeData['class']) ? '' : h($scopeData['class']),
$backgroundColour,
empty($scopeData['label']) ? h($scope) : $scopeData['label']
@ -41,7 +41,7 @@ if (isset($menu[$metaGroup])) {
}
$children .= sprintf(
$link_template,
empty($data['url']) ? '#' : h($data['url']),
empty($data['url']) ? '#' : $baseurl . h($data['url']),
empty($data['class']) ? '' : h($data['class']),
$active ? 'active' : '',
$active ? '' : $backgroundColour,