- Add PublicCampaignsController for public campaign analytics
- Add public routes for /public/analytics/{slug} and /api/campaigns/{slug}
- Add public campaign analytics view with charts and KPIs
- Support for campaign sharing via custom slugs
- Real-time analytics with ApexCharts integration
401 lines
14 KiB
PHP
401 lines
14 KiB
PHP
<?php
|
|
namespace App\Modules\Controllers;
|
|
|
|
use App\Core\InputSanitizer;
|
|
use App\Core\Sanitize;
|
|
use App\Core\View;
|
|
use App\Core\Auth;
|
|
|
|
class PagesController
|
|
{
|
|
public static function starter(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Starter Page',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Starter'
|
|
]);
|
|
// A página starter é uma tela em branco por design.
|
|
// Não há mais nada a renderizar aqui para evitar o ciclo.
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function profile(): void
|
|
{
|
|
try {
|
|
// Get current user ID from session
|
|
$userId = \App\Core\Auth::id();
|
|
if (!$userId) {
|
|
header('Location: /auth/login');
|
|
exit;
|
|
}
|
|
|
|
// Load user data from database (fallback if Users module not available)
|
|
$userData = null;
|
|
if (class_exists('\\App\\Modules\\Users\\Models\\UserModel')) {
|
|
$userModel = new \App\Modules\Users\Models\UserModel();
|
|
$userData = $userModel->find($userId);
|
|
} else {
|
|
// Fallback: create basic user data from Auth
|
|
$authUser = Auth::user();
|
|
$userData = $authUser ?: [
|
|
'first_name' => 'User',
|
|
'last_name' => 'Name',
|
|
'email' => '[email protected]',
|
|
'username' => 'user',
|
|
'job_title' => '',
|
|
'company_name' => '',
|
|
'city' => '',
|
|
'country' => '',
|
|
'phone' => '',
|
|
'website' => '',
|
|
'avatar' => '/assets/images/users/avatar-1.jpg',
|
|
'profile_bg' => '/assets/images/small/img-4.jpg',
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'followers_count' => 0,
|
|
'following_count' => 0,
|
|
'bio' => 'No bio available.',
|
|
'location' => 'N/A',
|
|
'skills' => '[]',
|
|
'social_links' => '{}',
|
|
'profile_completion' => 50
|
|
];
|
|
}
|
|
|
|
if (!$userData) {
|
|
throw new \Exception('User not found');
|
|
}
|
|
|
|
// Prepare user data
|
|
$user = [
|
|
'id' => $userId,
|
|
'first_name' => Sanitize::string($userData['first_name'] ?? ''),
|
|
'last_name' => Sanitize::string($userData['last_name'] ?? ''),
|
|
'username' => Sanitize::string($userData['username'] ?? ''),
|
|
'email' => Sanitize::email($userData['email'] ?? ''),
|
|
'job_title' => Sanitize::string($userData['job_title'] ?? ''),
|
|
'company_name' => Sanitize::string($userData['company_name'] ?? ''),
|
|
'city' => Sanitize::string($userData['city'] ?? ''),
|
|
'country' => Sanitize::string($userData['country'] ?? ''),
|
|
'phone' => Sanitize::string($userData['phone'] ?? ''),
|
|
'website' => Sanitize::url($userData['website'] ?? ''),
|
|
'avatar' => Sanitize::string($userData['avatar'] ?? '/assets/images/users/avatar-1.jpg'),
|
|
'profile_bg' => Sanitize::string($userData['profile_bg'] ?? '/assets/images/small/img-4.jpg'),
|
|
'created_at' => $userData['created_at'] ?? '',
|
|
'followers_count' => $userData['followers_count'] ?? 0,
|
|
'following_count' => $userData['following_count'] ?? 0
|
|
];
|
|
|
|
// Load profile data from database
|
|
$profile = [
|
|
'bio' => Sanitize::string($userData['bio'] ?? 'No bio available.'),
|
|
'location' => Sanitize::string($userData['location'] ?? 'N/A'),
|
|
'skills' => json_decode($userData['skills'] ?? '[]', true) ?: [],
|
|
'social_links' => json_decode($userData['social_links'] ?? '{}', true) ?: [],
|
|
'profile_completion' => $userData['profile_completion'] ?? 50
|
|
];
|
|
|
|
// Load recent activities from database (with fallback)
|
|
$db = \App\Core\DatabaseManager::getInstance();
|
|
$recentActivities = [];
|
|
$recentProjects = [];
|
|
$recentDocuments = [];
|
|
|
|
try {
|
|
$recentActivities = $db->fetchAll("
|
|
SELECT
|
|
a.id,
|
|
a.activity_type,
|
|
a.description,
|
|
a.created_at,
|
|
u.first_name,
|
|
u.last_name,
|
|
u.avatar
|
|
FROM user_activities a
|
|
LEFT JOIN users u ON a.user_id = u.id
|
|
WHERE a.user_id = ? OR a.target_user_id = ?
|
|
ORDER BY a.created_at DESC
|
|
LIMIT 10
|
|
", [$userId, $userId]) ?: [];
|
|
} catch (\Exception $e) {
|
|
// Table might not exist, use empty array
|
|
}
|
|
|
|
try {
|
|
$recentProjects = $db->fetchAll("
|
|
SELECT
|
|
p.id,
|
|
p.name,
|
|
p.description,
|
|
p.status,
|
|
p.created_at,
|
|
p.updated_at
|
|
FROM projects p
|
|
WHERE p.user_id = ?
|
|
ORDER BY p.updated_at DESC
|
|
LIMIT 5
|
|
", [$userId]) ?: [];
|
|
} catch (\Exception $e) {
|
|
// Table might not exist, use empty array
|
|
}
|
|
|
|
try {
|
|
$recentDocuments = $db->fetchAll("
|
|
SELECT
|
|
d.id,
|
|
d.filename,
|
|
d.file_type,
|
|
d.file_size,
|
|
d.uploaded_at
|
|
FROM user_documents d
|
|
WHERE d.user_id = ?
|
|
ORDER BY d.uploaded_at DESC
|
|
LIMIT 10
|
|
", [$userId]) ?: [];
|
|
} catch (\Exception $e) {
|
|
// Table might not exist, use empty array
|
|
}
|
|
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Profile',
|
|
'page_content' => function() use ($user, $profile, $recentActivities, $recentProjects, $recentDocuments) {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Profile'
|
|
]);
|
|
View::render('@pages/profile', [
|
|
'user' => $user,
|
|
'profile' => $profile,
|
|
'recentActivities' => $recentActivities,
|
|
'recentProjects' => $recentProjects,
|
|
'recentDocuments' => $recentDocuments
|
|
]);
|
|
}
|
|
]);
|
|
} catch (\Exception $e) {
|
|
\App\Core\ErrorReporter::report($e, ['context' => 'pages_profile', 'user_id' => $userId ?? 0]);
|
|
|
|
if (strpos($e->getMessage(), 'Authentication required') !== false) {
|
|
header('Location: /auth/login');
|
|
exit;
|
|
} else {
|
|
http_response_code(500);
|
|
echo 'Erro interno do servidor';
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function team(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Team',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Team'
|
|
]);
|
|
View::render('@pages/team');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function timeline(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Timeline',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Timeline'
|
|
]);
|
|
View::render('@pages/timeline');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function faqs(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'FAQs',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'FAQs'
|
|
]);
|
|
View::render('@pages/faqs');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function pricing(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Pricing',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Pricing'
|
|
]);
|
|
View::render('@pages/pricing');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function gallery(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Gallery',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Gallery'
|
|
]);
|
|
View::render('@pages/gallery');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function maintenance(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Maintenance',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Maintenance'
|
|
]);
|
|
View::render('@pages/maintenance');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function comingSoon(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Coming Soon',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Coming Soon'
|
|
]);
|
|
View::render('@pages/coming/soon');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function sitemap(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Sitemap',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Sitemap'
|
|
]);
|
|
View::render('@pages/sitemap');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function searchResults(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Search Results',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Search Results'
|
|
]);
|
|
View::render('@pages/search/results');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function privacyPolicy(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Privacy Policy',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Privacy Policy'
|
|
]);
|
|
View::render('@pages/privacy/policy');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function termsOfService(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Terms of Service',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Terms of Service'
|
|
]);
|
|
View::render('@pages/term/conditions');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function pagesProfileSettingsPage(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Profile Settings',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Profile Settings'
|
|
]);
|
|
View::render('@pages/profile/settings');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function pagesBlogOverviewPage(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Blog Overview',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Blog Overview'
|
|
]);
|
|
View::render('@pages/blog/overview');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function pagesBlogGridPage(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Blog Grid',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Blog Grid'
|
|
]);
|
|
View::render('@pages/blog/grid');
|
|
}
|
|
]);
|
|
}
|
|
|
|
public static function pagesBlogListPage(): void
|
|
{
|
|
View::render('layouts/main.php', [
|
|
'title' => 'Blog List',
|
|
'page_content' => function() {
|
|
View::render('layouts/page-title.php', [
|
|
'pagetitle' => 'Pages',
|
|
'title' => 'Blog List'
|
|
]);
|
|
View::render('@pages/blog/list');
|
|
}
|
|
]);
|
|
}
|
|
}
|