Skip to content

Commit

Permalink
[ADD] Check Role and Blade directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed May 17, 2023
1 parent 235d42b commit ff1d0b7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 55 deletions.
4 changes: 2 additions & 2 deletions core/config/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
],
'compiled' => EVO_STORAGE_PATH . 'blade',
'directive' => [

'evoParser' => [EvolutionCMS\Support\BladeDirective::class, 'evoParser'],
'evoLang' => [EvolutionCMS\Support\BladeDirective::class, 'evoLang'],
'evoStyle' => [EvolutionCMS\Support\BladeDirective::class, 'evoStyle'],
Expand All @@ -15,6 +14,7 @@
'evoAdminThemeName' => [EvolutionCMS\Support\BladeDirective::class, 'evoAdminThemeName'],
'makeUrl' => [EvolutionCMS\Support\BladeDirective::class, 'makeUrl'],
'csrf' => [EvolutionCMS\Support\BladeDirective::class, 'csrf'],

'evoRole' => [EvolutionCMS\Support\BladeDirective::class, 'evoRole'],
'evoEndRole' => [EvolutionCMS\Support\BladeDirective::class, 'evoEndRole'],
]
];
41 changes: 38 additions & 3 deletions core/functions/utils.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
<?php

if (!function_exists('evo_guest')) {
/**
* Show content if User isn't authenticated
* @param $content
* @return mixed|string
*/
function evo_guest($content)
{
if(!EvolutionCMS()->getLoginUserID()){
if (evo()->getLoginUserID()) {
$content = '';
}
return $content;
}
}

if (!function_exists('evo_auth')) {
/**
* Show content if User is authenticated
* @param $content
* @return mixed|string
*/
function evo_auth($content)
{
if (!EvolutionCMS()->getLoginUserID()) {
if (!evo()->getLoginUserID()) {
$content = '';
}
return $content;
}
}

if (!function_exists('evo_role')) {
/**
* Show content if User is Role or authenticated is role is empty
* @param string $role
* @return bool
*/
function evo_role(string $role = ''): bool
{
$out = false;
if (!empty($role)) {
$pms = get_by_key($_SESSION, 'webPermissions', [], 'is_array') ?: get_by_key($_SESSION, 'mgrPermissions', [], 'is_array');
if (count($pms) && isset($pms['name']) && $role == $pms['name']) {
$out = true;
}
} else {
$pms = get_by_key($_SESSION, 'webValidated', false, 'is_int') ?: get_by_key($_SESSION, 'mgrValidated', false, 'is_int');
if ($pms) {
$out = true;
}
}

return $out;
}
}

if (!function_exists('var_debug')) {
/**
* Dumps information about a variable in Tracy Debug Bar.
Expand All @@ -38,7 +73,7 @@ function var_debug($var, $title = null, array $options = null)
if (!function_exists('evo_parser')) {
function evo_parser($content)
{
$core = evolutionCMS();
$core = evo();
$minParserPasses = $core->minParserPasses;
$maxParserPasses = $core->maxParserPasses;

Expand Down
109 changes: 59 additions & 50 deletions core/src/Support/BladeDirective.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
<?php namespace EvolutionCMS\Support;

class BladeDirective
{

public static function evoParser($content) : string
{
return '<?php echo evo_parser(' . $content . ');?>';
}

public static function evoLang($key) : string
{
return '<?php echo ManagerTheme::getLexicon(' . $key . ');?>';
}

public static function evoStyle($key) : string
{
return '<?php echo ManagerTheme::getStyle(' . $key . ');?>';
}

public static function evoAdminLang() : string
{
return '<?php echo ManagerTheme::getLangName();?>';
}

public static function evoCharset() : string
{
return '<?php echo ManagerTheme::getCharset();?>';
}

public static function evoAdminThemeUrl() : string
{
return '<?php echo ManagerTheme::getThemeUrl();?>';
}

public static function evoAdminThemeName() : string
{
return '<?php echo ManagerTheme::getTheme();?>';
}

public static function makeUrl($id) : string
{
return '<?php echo app("UrlProcessor")->makeUrlWithString(' . $id . ');?>';
}
public static function csrf() : string
{
return '<?php echo csrf_field();?>';
}

}
<?php namespace EvolutionCMS\Support;

class BladeDirective
{

public static function evoParser($content): string
{
return '<?php echo evo_parser(' . $content . ');?>';
}

public static function evoLang($key): string
{
return '<?php echo ManagerTheme::getLexicon(' . $key . ');?>';
}

public static function evoStyle($key): string
{
return '<?php echo ManagerTheme::getStyle(' . $key . ');?>';
}

public static function evoAdminLang(): string
{
return '<?php echo ManagerTheme::getLangName();?>';
}

public static function evoCharset(): string
{
return '<?php echo ManagerTheme::getCharset();?>';
}

public static function evoAdminThemeUrl(): string
{
return '<?php echo ManagerTheme::getThemeUrl();?>';
}

public static function evoAdminThemeName(): string
{
return '<?php echo ManagerTheme::getTheme();?>';
}

public static function makeUrl($id): string
{
return '<?php echo app("UrlProcessor")->makeUrlWithString(' . $id . ');?>';
}
public static function csrf(): string
{
return '<?php echo csrf_field();?>';
}

public static function evoRole($role = ''): string
{
return "<?php if(evo_role($role)): ?>";
}

public static function evoEndRole(): string
{
return '<?php endif; ?>';
}
}

0 comments on commit ff1d0b7

Please sign in to comment.