First Commit
This commit is contained in:
+259
@@ -0,0 +1,259 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Modules\Index\Controllers;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Controllers\BaseController;
|
||||
use Modules\Auth\Models\User;
|
||||
use App\Models\Module;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
class IndexController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Helper to render a view from the module's views folder
|
||||
*/
|
||||
protected function renderThemeView(string $viewName, array $data = []): Response
|
||||
{
|
||||
return $this->renderView('@index/' . $viewName . '.twig', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the application language.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $lang
|
||||
* @return Response
|
||||
*/
|
||||
public function changeLanguage(Request $request, string $lang): Response
|
||||
{
|
||||
// Checks if multi-language is enabled
|
||||
if (!is_multi_lang_enabled()) {
|
||||
// Redirects to previous page without changing language
|
||||
$redirect = $request->query->get('redirect');
|
||||
if ($redirect && strpos($redirect, '/language/') === false) {
|
||||
return new RedirectResponse($redirect);
|
||||
}
|
||||
|
||||
$referer = $request->headers->get('referer');
|
||||
if (!$referer || strpos($referer, '/language/') !== false) {
|
||||
$referer = '/';
|
||||
}
|
||||
|
||||
return new RedirectResponse($referer);
|
||||
}
|
||||
|
||||
$allowedLanguages = ['pt_BR', 'en_US', 'es_ES', 'de_DE', 'fr_FR'];
|
||||
|
||||
if (in_array($lang, $allowedLanguages)) {
|
||||
$_SESSION['lang'] = $lang;
|
||||
}
|
||||
|
||||
// Check for explicit redirect param
|
||||
$redirect = $request->query->get('redirect');
|
||||
if ($redirect && strpos($redirect, '/language/') === false) {
|
||||
return new RedirectResponse($redirect);
|
||||
}
|
||||
|
||||
// Redirect back to previous page or home
|
||||
$referer = $request->headers->get('referer');
|
||||
|
||||
// Prevent redirect loop if referer contains the language switch URL itself
|
||||
if (!$referer || strpos($referer, '/language/') !== false) {
|
||||
$referer = '/';
|
||||
}
|
||||
|
||||
return new RedirectResponse($referer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the about page.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function about(Request $request): Response
|
||||
{
|
||||
$pageContent = null;
|
||||
$metaTitle = null;
|
||||
$metaDescription = null;
|
||||
$title = __('index.about_title');
|
||||
|
||||
if (class_exists('Modules\\Configindex\\Models\\ConfigPage')) {
|
||||
try {
|
||||
$busId = $_SESSION['current_company_id'] ?? 1;
|
||||
$page = \Modules\Configindex\Models\ConfigPage::getByKey('about', $busId);
|
||||
if ($page) {
|
||||
$pageContent = $page->config_index_content;
|
||||
if ($page->config_index_title) {
|
||||
$title = $page->config_index_title;
|
||||
}
|
||||
$metaTitle = $page->config_index_meta_title;
|
||||
$metaDescription = $page->config_index_meta_description;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignore if table not found or other error
|
||||
}
|
||||
}
|
||||
|
||||
return $this->renderThemeView('about', [
|
||||
'title' => $title,
|
||||
'page_content' => $pageContent,
|
||||
'meta_title' => $metaTitle,
|
||||
'meta_description' => $metaDescription
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a dynamic page from config_index.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $key
|
||||
* @return Response
|
||||
*/
|
||||
public function page(Request $request, string $key): Response
|
||||
{
|
||||
$pageContent = null;
|
||||
$metaTitle = null;
|
||||
$metaDescription = null;
|
||||
$title = ucfirst($key);
|
||||
|
||||
if (class_exists('Modules\\Configindex\\Models\\ConfigPage')) {
|
||||
try {
|
||||
$busId = $_SESSION['current_company_id'] ?? 1;
|
||||
$page = \Modules\Configindex\Models\ConfigPage::getByKey($key, $busId);
|
||||
if ($page) {
|
||||
$pageContent = $page->config_index_content;
|
||||
if ($page->config_index_title) {
|
||||
$title = $page->config_index_title;
|
||||
}
|
||||
$metaTitle = $page->config_index_meta_title;
|
||||
$metaDescription = $page->config_index_meta_description;
|
||||
} else {
|
||||
// Se não estiver no banco, verifica se o arquivo físico existe
|
||||
$viewsDir = dirname(__DIR__, 2) . '/views';
|
||||
if (!is_file($viewsDir . '/' . $key . '.twig') && !is_file($viewsDir . '/' . $key . '.php')) {
|
||||
return new Response('Page not found', 404);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignore error
|
||||
}
|
||||
}
|
||||
|
||||
return $this->renderThemeView($key, [
|
||||
'title' => $title,
|
||||
'page_content' => $pageContent,
|
||||
'meta_title' => $metaTitle,
|
||||
'meta_description' => $metaDescription
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the services page.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function services(Request $request): Response
|
||||
{
|
||||
$pageContent = null;
|
||||
$metaTitle = null;
|
||||
$metaDescription = null;
|
||||
$title = __('index.services_title');
|
||||
|
||||
if (class_exists('Modules\\Configindex\\Models\\ConfigPage')) {
|
||||
try {
|
||||
$busId = $_SESSION['current_company_id'] ?? 1;
|
||||
$page = \Modules\Configindex\Models\ConfigPage::getByKey('services', $busId);
|
||||
if ($page) {
|
||||
$pageContent = $page->config_index_content;
|
||||
if ($page->config_index_title) {
|
||||
$title = $page->config_index_title;
|
||||
}
|
||||
$metaTitle = $page->config_index_meta_title;
|
||||
$metaDescription = $page->config_index_meta_description;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignore if table not found or other error
|
||||
}
|
||||
}
|
||||
|
||||
return $this->renderThemeView('services', [
|
||||
'title' => $title,
|
||||
'page_content' => $pageContent,
|
||||
'meta_title' => $metaTitle,
|
||||
'meta_description' => $metaDescription
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the homepage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
// Get active public modules
|
||||
$publicModules = Module::active()->public()->ordered()->get();
|
||||
|
||||
// Get featured content (could be from blog, news, etc.)
|
||||
$featuredContent = $this->getFeaturedContent();
|
||||
|
||||
return $this->renderThemeView('index', [
|
||||
'title' => __('index.welcome_title'),
|
||||
'public_modules' => $publicModules,
|
||||
'featured_content' => $featuredContent
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get featured content for homepage.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFeaturedContent(): array
|
||||
{
|
||||
// This is a placeholder implementation
|
||||
// In a real app, this would fetch from blog posts, news, etc.
|
||||
return [
|
||||
[
|
||||
'type' => 'blog',
|
||||
'title' => 'Últimas Publicações',
|
||||
'content' => 'Confira nossos artigos mais recentes...',
|
||||
'icon' => 'bi bi-journal-richtext',
|
||||
'link' => '/blog'
|
||||
],
|
||||
[
|
||||
'type' => 'news',
|
||||
'title' => 'Notícias e Atualizações',
|
||||
'content' => 'Fique por dentro das novidades do sistema...',
|
||||
'icon' => 'bi bi-newspaper',
|
||||
'link' => '/news'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Index\Providers;
|
||||
|
||||
use Kernel\Application;
|
||||
|
||||
class IndexServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$app = Application::getInstance();
|
||||
$app->addPublicPath('/');
|
||||
$app->addPublicPath('/home');
|
||||
$app->addPublicPath('/about');
|
||||
$app->addPublicPath('/services');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user