2024-03-18 19:48:59 -06:00
|
|
|
<?php
|
|
|
|
|
2024-05-09 11:24:12 -06:00
|
|
|
namespace App\Http\Controllers;
|
2024-03-18 19:48:59 -06:00
|
|
|
|
2024-05-06 15:09:24 -06:00
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
2024-05-12 22:14:53 -06:00
|
|
|
use App\Services\Assets\AssetService;
|
|
|
|
use App\Services\Data\SettingsService;
|
|
|
|
use App\Services\Data\SortingService;
|
2025-05-16 17:37:53 -06:00
|
|
|
use App\Services\Upkeep\InitService;
|
|
|
|
use App\Http\Controllers\DashController;
|
|
|
|
use Illuminate\Http\Request;
|
2024-05-06 15:09:24 -06:00
|
|
|
|
|
|
|
use function _\find;
|
2024-03-18 19:48:59 -06:00
|
|
|
|
2024-05-09 11:24:12 -06:00
|
|
|
class FrontController extends Controller
|
2024-03-18 19:48:59 -06:00
|
|
|
{
|
2024-04-16 15:36:57 -06:00
|
|
|
protected $settings;
|
2024-05-06 15:09:24 -06:00
|
|
|
protected PageRepositoryInterface $pages;
|
|
|
|
protected AssetService $assets;
|
|
|
|
protected SortingService $sort;
|
2025-05-16 17:37:53 -06:00
|
|
|
protected $init;
|
|
|
|
protected $dash;
|
2024-04-16 15:36:57 -06:00
|
|
|
|
2024-05-06 15:09:24 -06:00
|
|
|
public function __construct(
|
|
|
|
PageRepositoryInterface $pageRepository,
|
|
|
|
SettingsService $settingsService,
|
|
|
|
AssetService $assetService,
|
|
|
|
SortingService $sortService,
|
2025-05-16 17:37:53 -06:00
|
|
|
InitService $initService,
|
|
|
|
DashController $dashController,
|
2024-05-06 15:09:24 -06:00
|
|
|
) {
|
|
|
|
$this->pages = $pageRepository;
|
2024-05-06 13:37:26 -06:00
|
|
|
$this->settings = $settingsService;
|
2024-05-06 15:09:24 -06:00
|
|
|
$this->assets = $assetService;
|
|
|
|
$this->sort = $sortService;
|
2025-05-16 17:37:53 -06:00
|
|
|
$this->init = $initService;
|
|
|
|
$this->dash = $dashController;
|
2024-03-18 19:48:59 -06:00
|
|
|
}
|
|
|
|
|
2025-05-16 17:37:53 -06:00
|
|
|
public function start($one = 00, $two = 00, $three = 00)
|
2024-03-18 19:48:59 -06:00
|
|
|
{
|
2024-05-06 15:09:24 -06:00
|
|
|
$global = $this->settings->getGlobal();
|
|
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
|
|
$template;
|
|
|
|
$pageData = [];
|
|
|
|
$pages = $this->pages->getAll();
|
2025-05-16 17:37:53 -06:00
|
|
|
//weird bug where the whole url is being passed with optional params
|
|
|
|
//for now, just split it manually and set it to the vars used
|
|
|
|
|
|
|
|
$paths = explode('/', $one);
|
|
|
|
if (isset($paths[0])) {
|
|
|
|
$one = $paths[0];
|
|
|
|
}
|
|
|
|
if (isset($paths[1])) {
|
|
|
|
$two = $paths[1];
|
|
|
|
}
|
|
|
|
if (isset($paths[2])) {
|
|
|
|
$three = $paths[2];
|
|
|
|
}
|
|
|
|
|
2024-04-16 15:36:57 -06:00
|
|
|
//check if configs are present
|
|
|
|
if (file_exists(env('FOLKS_PATH')) && file_exists(env('SETTINGS_PATH'))) {
|
2024-05-06 13:37:26 -06:00
|
|
|
if ($global['dynamicRender'] == 'true') {
|
2025-05-16 17:37:53 -06:00
|
|
|
if (is_numeric($one)) {
|
|
|
|
if ($one == 00 || !isset($one)) {
|
|
|
|
$page = $pages->where('id', 0)->first();
|
2025-03-19 23:39:14 -06:00
|
|
|
$pageData = $this->sort->page($page, false);
|
2024-05-06 15:09:24 -06:00
|
|
|
$template = $currentTheme . '.index';
|
|
|
|
} else {
|
2025-05-16 17:37:53 -06:00
|
|
|
$page = $this->pages->getBySlug($three);
|
2025-03-19 23:39:14 -06:00
|
|
|
$pageData = $this->sort->page($page, false);
|
2024-05-06 15:09:24 -06:00
|
|
|
$template = $currentTheme . '.' . $page['layout'];
|
|
|
|
}
|
2024-05-06 13:37:26 -06:00
|
|
|
} else {
|
2025-05-16 17:37:53 -06:00
|
|
|
if ($one == null || $one == '') {
|
2025-03-19 23:39:14 -06:00
|
|
|
$page = $pages->where('id', 0)->first();
|
|
|
|
$pageData = $this->sort->page($page, false);
|
2024-05-06 15:09:24 -06:00
|
|
|
$template = $currentTheme . '.index';
|
|
|
|
} else {
|
2025-05-16 17:37:53 -06:00
|
|
|
if ($one == 'archives' || $one == 'archive' || $one == 'tags') {
|
|
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
|
|
switch ($one) {
|
|
|
|
case 'archive':
|
|
|
|
case 'archives':
|
|
|
|
$template = $currentTheme . '.archive';
|
|
|
|
$pageData = $this->sort->archive(false);
|
|
|
|
break;
|
|
|
|
case 'tags':
|
|
|
|
$template = $currentTheme . '.tags';
|
|
|
|
$tags = $this->sort->tags(false);
|
|
|
|
$tagData = find($tags['tags'], ['tag_name' => $two]);
|
|
|
|
$pageData = [
|
|
|
|
'theme' => $currentTheme, // for theme kit
|
|
|
|
'title' => 'Pages Tagged as ' . $two,
|
|
|
|
'dynamicRender' => $tags['dynamicRender'],
|
|
|
|
'info' => $tags['info'],
|
|
|
|
'menu' => $tags['menu'],
|
|
|
|
'pages' => $tagData['pages'],
|
|
|
|
'media' => $tags['media'],
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$page = $this->pages->getBySlug($one);
|
|
|
|
$pageData = $this->sort->page($page, false);
|
|
|
|
$template = $currentTheme . '.' . $page['layout'];
|
|
|
|
}
|
2024-05-06 15:09:24 -06:00
|
|
|
}
|
2024-05-06 13:37:26 -06:00
|
|
|
}
|
2024-05-06 15:09:24 -06:00
|
|
|
return view($template, $pageData);
|
2024-05-06 13:37:26 -06:00
|
|
|
} else {
|
2024-07-05 13:17:53 -06:00
|
|
|
if (is_file('../public/index.html')) {
|
|
|
|
return response()->file('../public/index.html');
|
|
|
|
} else {
|
|
|
|
return redirect()->intended('dashboard/start');
|
|
|
|
}
|
2024-05-06 13:37:26 -06:00
|
|
|
}
|
2024-04-16 15:36:57 -06:00
|
|
|
} else {
|
|
|
|
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
|
|
}
|
2024-03-18 19:48:59 -06:00
|
|
|
}
|
2024-05-06 15:09:24 -06:00
|
|
|
|
2025-05-16 17:37:53 -06:00
|
|
|
//setup up a new site or restore from back up
|
|
|
|
public function init($task, Request $request)
|
2024-05-06 15:09:24 -06:00
|
|
|
{
|
2025-05-16 17:37:53 -06:00
|
|
|
$result = [];
|
|
|
|
switch ($task) {
|
|
|
|
case 'fresh':
|
|
|
|
$result = $this->init->fresh(json_decode($request->getContent()));
|
2024-05-06 15:09:24 -06:00
|
|
|
break;
|
2025-05-16 17:37:53 -06:00
|
|
|
case 'restore':
|
|
|
|
$result = $this->init->restore($request);
|
2024-05-06 15:09:24 -06:00
|
|
|
break;
|
|
|
|
}
|
2025-05-16 17:37:53 -06:00
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
2024-05-06 15:09:24 -06:00
|
|
|
}
|
2024-03-18 19:48:59 -06:00
|
|
|
}
|