First Commit

This commit is contained in:
marco
2026-09-01 10:46:29 -03:00
commit bf96b77e9c
10000 changed files with 3508600 additions and 0 deletions
+288
View File
@@ -0,0 +1,288 @@
<?php
/**
* SysCMS - Content Management System
*
* Copyright (c) 2025 Marco Costa
* All rights reserved.
*
* Author: Marco Costa
* Email: contato@syspanel.com.br
* Project: SysCMS
*
* This software is licensed, not sold.
* Permission is granted to use this software
* subject to the terms of the SysCMS Commercial License.
*
* Redistribution, sublicensing, resale, or
* disclosure of this software, in whole or in part,
* is strictly prohibited without prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
*/
// Loads the environment helper first
require_once __DIR__ . '/Helpers/Environment.php';
use Kernel\Translator;
use App\Helpers\Log;
use Kernel\Application;
if (!function_exists('__')) {
/**
* Translate a string using the translator
*
* @param string $key The translation key
* @param array $params Parameters to replace in the translation
* @return string The translated string
*/
function __(string $key, array $params = []): string
{
return Translator::translate($key, $params);
}
}
if (!function_exists('add_action')) {
function add_action(string $hook, callable $listener, int $priority = 10): void
{
Application::getInstance()->getHookManager()->addAction($hook, $listener, $priority);
}
}
if (!function_exists('do_action')) {
function do_action(string $hook, ...$args): void
{
Application::getInstance()->getHookManager()->doAction($hook, ...$args);
}
}
if (!function_exists('add_filter')) {
function add_filter(string $hook, callable $listener, int $priority = 10): void
{
Application::getInstance()->getHookManager()->addFilter($hook, $listener, $priority);
}
}
if (!function_exists('apply_filters')) {
function apply_filters(string $hook, $value, ...$args)
{
return Application::getInstance()->getHookManager()->applyFilters($hook, $value, ...$args);
}
}
if (!function_exists('get_active_theme')) {
/**
* Get the currently active theme name
*/
function get_active_theme(): string
{
static $activeTheme = null;
if ($activeTheme === null) {
try {
$themeConfig = \Illuminate\Database\Capsule\Manager::table('system_config')
->where('system_config_key', 'active_theme')
->first();
$activeTheme = $themeConfig ? $themeConfig->system_config_value : 'default';
} catch (\Exception $e) {
$activeTheme = 'default';
}
}
return $activeTheme;
}
}
if (!function_exists('asset_url')) {
/**
* Generate asset URL with theme support
*
* @param string $path The asset path
* @return string The complete asset URL
*/
function asset_url(string $path): string
{
$activeTheme = get_active_theme();
$themeAssetPath = 'themes/' . $activeTheme . '/assets/' . ltrim($path, '/');
// Check if the asset exists in the theme folder
if (file_exists(dirname(__DIR__) . '/' . $themeAssetPath)) {
return '/' . $themeAssetPath;
}
return '/assets/' . ltrim($path, '/');
}
}
if (!function_exists('url')) {
/**
* Generate application URL
*
* @param string $path The path to append to the base URL
* @return string The complete URL
*/
function url(string $path = ''): string
{
return '/' . ltrim($path, '/');
}
}
if (!function_exists('route')) {
/**
* Generate route URL (placeholder for future implementation)
*
* @param string $name The route name
* @param array $params Route parameters
* @return string The route URL
*/
function route(string $name, array $params = []): string
{
// This will be implemented when we have a named route system
return url($name);
}
}
if (!function_exists('csrf_field')) {
/**
* Generate CSRF token field
*
* @return string HTML input with CSRF token
*/
function csrf_field(): string
{
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
$token = $_SESSION['csrf_token'];
return '<input type="hidden" name="csrf_token" value="' . htmlspecialchars($token) . '">';
}
}
if (!function_exists('csrf_token')) {
/**
* Get CSRF token value
*
* @return string The CSRF token
*/
function csrf_token(): string
{
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
return $_SESSION['csrf_token'];
}
}
if (!function_exists('verify_csrf_token')) {
/**
* Verify CSRF token
*
* @param string $token The token to verify
* @return bool True if valid, false otherwise
*/
function verify_csrf_token(string $token): bool
{
return isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token);
}
}
if (!function_exists('logger')) {
/**
* Log a message to the application log
*
* @param string $message The message to log
* @param array $context Contextual information
* @param string $level Log level (info, error, warning, debug)
*/
function logger(string $message, array $context = [], string $level = 'info'): void
{
switch ($level) {
case 'error':
Log::error($message, $context);
break;
case 'warning':
Log::warning($message, $context);
break;
case 'debug':
Log::debug($message, $context);
break;
default:
Log::info($message, $context);
break;
}
}
}
if (!function_exists('is_multi_lang_enabled')) {
/**
* Check if multi-language is enabled
*
* @return bool True if multi-language is enabled, false otherwise
*/
function is_multi_lang_enabled(): bool
{
return ($_ENV['APP_MULTI_LANG'] ?? 'false') === 'true';
}
}
if (!function_exists('bus_module_enabled')) {
/**
* Check if a module is enabled for the current authenticated user's company.
*
* @param string $moduleName The module name to check (e.g., 'erppoe')
* @return bool
*/
function bus_module_enabled(string $moduleName): bool
{
if (session_status() === PHP_SESSION_NONE) {
return false;
}
if (!isset($_SESSION['user_id'])) {
return false;
}
try {
$user = \Modules\Auth\Models\User::find($_SESSION['user_id']);
if (!$user) {
return false;
}
if ($user->users_role === 'super_admin') {
return \App\Models\Module::where('modules_name', $moduleName)
->where('modules_ative', true)
->exists();
}
return \App\Models\Module::join('bus_modules', 'modules.modules_id', '=', 'bus_modules.bus_modules_module_id')
->where('bus_modules.bus_modules_bus_id', $user->users_bus_id)
->where('bus_modules.bus_modules_is_enabled', true)
->where('modules.modules_name', $moduleName)
->where('modules.modules_ative', true)
->exists();
} catch (\Exception $e) {
return false;
}
}
}
if (!function_exists('get_config')) {
/**
* Get a system configuration value from the database.
*
* @param string $key The configuration key.
* @param mixed $default Default value if the key is not found.
* @return mixed
*/
function get_config(string $key, $default = null)
{
try {
$config = \Illuminate\Database\Capsule\Manager::table('system_config')
->where('system_config_key', $key)
->first();
return $config ? $config->system_config_value : $default;
} catch (\Exception $e) {
return $default;
}
}
}