Skip to content

Commit ff1d0b7

Browse files
committed
[ADD] Check Role and Blade directive.
1 parent 235d42b commit ff1d0b7

File tree

3 files changed

+99
-55
lines changed

3 files changed

+99
-55
lines changed

core/config/view.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
'compiled' => EVO_STORAGE_PATH . 'blade',
77
'directive' => [
8-
98
'evoParser' => [EvolutionCMS\Support\BladeDirective::class, 'evoParser'],
109
'evoLang' => [EvolutionCMS\Support\BladeDirective::class, 'evoLang'],
1110
'evoStyle' => [EvolutionCMS\Support\BladeDirective::class, 'evoStyle'],
@@ -15,6 +14,7 @@
1514
'evoAdminThemeName' => [EvolutionCMS\Support\BladeDirective::class, 'evoAdminThemeName'],
1615
'makeUrl' => [EvolutionCMS\Support\BladeDirective::class, 'makeUrl'],
1716
'csrf' => [EvolutionCMS\Support\BladeDirective::class, 'csrf'],
18-
17+
'evoRole' => [EvolutionCMS\Support\BladeDirective::class, 'evoRole'],
18+
'evoEndRole' => [EvolutionCMS\Support\BladeDirective::class, 'evoEndRole'],
1919
]
2020
];

core/functions/utils.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
11
<?php
22

33
if (!function_exists('evo_guest')) {
4+
/**
5+
* Show content if User isn't authenticated
6+
* @param $content
7+
* @return mixed|string
8+
*/
49
function evo_guest($content)
510
{
6-
if(!EvolutionCMS()->getLoginUserID()){
11+
if (evo()->getLoginUserID()) {
712
$content = '';
813
}
914
return $content;
1015
}
1116
}
1217

1318
if (!function_exists('evo_auth')) {
19+
/**
20+
* Show content if User is authenticated
21+
* @param $content
22+
* @return mixed|string
23+
*/
1424
function evo_auth($content)
1525
{
16-
if (!EvolutionCMS()->getLoginUserID()) {
26+
if (!evo()->getLoginUserID()) {
1727
$content = '';
1828
}
1929
return $content;
2030
}
2131
}
2232

33+
if (!function_exists('evo_role')) {
34+
/**
35+
* Show content if User is Role or authenticated is role is empty
36+
* @param string $role
37+
* @return bool
38+
*/
39+
function evo_role(string $role = ''): bool
40+
{
41+
$out = false;
42+
if (!empty($role)) {
43+
$pms = get_by_key($_SESSION, 'webPermissions', [], 'is_array') ?: get_by_key($_SESSION, 'mgrPermissions', [], 'is_array');
44+
if (count($pms) && isset($pms['name']) && $role == $pms['name']) {
45+
$out = true;
46+
}
47+
} else {
48+
$pms = get_by_key($_SESSION, 'webValidated', false, 'is_int') ?: get_by_key($_SESSION, 'mgrValidated', false, 'is_int');
49+
if ($pms) {
50+
$out = true;
51+
}
52+
}
53+
54+
return $out;
55+
}
56+
}
57+
2358
if (!function_exists('var_debug')) {
2459
/**
2560
* Dumps information about a variable in Tracy Debug Bar.
@@ -38,7 +73,7 @@ function var_debug($var, $title = null, array $options = null)
3873
if (!function_exists('evo_parser')) {
3974
function evo_parser($content)
4075
{
41-
$core = evolutionCMS();
76+
$core = evo();
4277
$minParserPasses = $core->minParserPasses;
4378
$maxParserPasses = $core->maxParserPasses;
4479

core/src/Support/BladeDirective.php

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,59 @@
1-
<?php namespace EvolutionCMS\Support;
2-
3-
class BladeDirective
4-
{
5-
6-
public static function evoParser($content) : string
7-
{
8-
return '<?php echo evo_parser(' . $content . ');?>';
9-
}
10-
11-
public static function evoLang($key) : string
12-
{
13-
return '<?php echo ManagerTheme::getLexicon(' . $key . ');?>';
14-
}
15-
16-
public static function evoStyle($key) : string
17-
{
18-
return '<?php echo ManagerTheme::getStyle(' . $key . ');?>';
19-
}
20-
21-
public static function evoAdminLang() : string
22-
{
23-
return '<?php echo ManagerTheme::getLangName();?>';
24-
}
25-
26-
public static function evoCharset() : string
27-
{
28-
return '<?php echo ManagerTheme::getCharset();?>';
29-
}
30-
31-
public static function evoAdminThemeUrl() : string
32-
{
33-
return '<?php echo ManagerTheme::getThemeUrl();?>';
34-
}
35-
36-
public static function evoAdminThemeName() : string
37-
{
38-
return '<?php echo ManagerTheme::getTheme();?>';
39-
}
40-
41-
public static function makeUrl($id) : string
42-
{
43-
return '<?php echo app("UrlProcessor")->makeUrlWithString(' . $id . ');?>';
44-
}
45-
public static function csrf() : string
46-
{
47-
return '<?php echo csrf_field();?>';
48-
}
49-
50-
}
1+
<?php namespace EvolutionCMS\Support;
2+
3+
class BladeDirective
4+
{
5+
6+
public static function evoParser($content): string
7+
{
8+
return '<?php echo evo_parser(' . $content . ');?>';
9+
}
10+
11+
public static function evoLang($key): string
12+
{
13+
return '<?php echo ManagerTheme::getLexicon(' . $key . ');?>';
14+
}
15+
16+
public static function evoStyle($key): string
17+
{
18+
return '<?php echo ManagerTheme::getStyle(' . $key . ');?>';
19+
}
20+
21+
public static function evoAdminLang(): string
22+
{
23+
return '<?php echo ManagerTheme::getLangName();?>';
24+
}
25+
26+
public static function evoCharset(): string
27+
{
28+
return '<?php echo ManagerTheme::getCharset();?>';
29+
}
30+
31+
public static function evoAdminThemeUrl(): string
32+
{
33+
return '<?php echo ManagerTheme::getThemeUrl();?>';
34+
}
35+
36+
public static function evoAdminThemeName(): string
37+
{
38+
return '<?php echo ManagerTheme::getTheme();?>';
39+
}
40+
41+
public static function makeUrl($id): string
42+
{
43+
return '<?php echo app("UrlProcessor")->makeUrlWithString(' . $id . ');?>';
44+
}
45+
public static function csrf(): string
46+
{
47+
return '<?php echo csrf_field();?>';
48+
}
49+
50+
public static function evoRole($role = ''): string
51+
{
52+
return "<?php if(evo_role($role)): ?>";
53+
}
54+
55+
public static function evoEndRole(): string
56+
{
57+
return '<?php endif; ?>';
58+
}
59+
}

0 commit comments

Comments
 (0)