still finding bugs related to the big routing rewrite, this one being an error when starting a new set up. fortunately, it was just a matter of getting the redirects pointing to where they should, so it's a small fix
161 lines
5.5 KiB
PHP
161 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Services\Assets\AssetService;
|
|
use App\Services\Data\SettingsService;
|
|
use App\Services\Data\SortingService;
|
|
use App\Services\Upkeep\InitService;
|
|
use App\Http\Controllers\DashController;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
use function _\find;
|
|
|
|
class FrontController extends Controller
|
|
{
|
|
protected $settings;
|
|
protected PageRepositoryInterface $pages;
|
|
protected AssetService $assets;
|
|
protected SortingService $sort;
|
|
protected $init;
|
|
protected $dash;
|
|
protected $words;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepository,
|
|
SettingsService $settingsService,
|
|
AssetService $assetService,
|
|
SortingService $sortService,
|
|
InitService $initService,
|
|
DashController $dashController,
|
|
) {
|
|
$this->pages = $pageRepository;
|
|
$this->settings = $settingsService;
|
|
$this->assets = $assetService;
|
|
$this->sort = $sortService;
|
|
$this->init = $initService;
|
|
$this->dash = $dashController;
|
|
$this->words = ['words'];
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$template;
|
|
$pageData = [];
|
|
if ($this->configCheck()) {
|
|
$pages = $this->pages->getAll();
|
|
$global = $this->settings->getGlobal();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
if ($global['dynamicRender'] == 'true') {
|
|
$page = $pages->where('id', 0)->first();
|
|
$pageData = $this->sort->page($page, false);
|
|
$template = $currentTheme . '.index';
|
|
return view($template, $pageData);
|
|
} else {
|
|
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function page($year, $month, $slug)
|
|
{
|
|
$template;
|
|
$pageData = [];
|
|
if ($this->configCheck()) {
|
|
$pages = $this->pages->getAll();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
$page = $this->pages->getBySlug($slug);
|
|
$pageData = $this->sort->page($page, false);
|
|
$template = $currentTheme . '.' . $page['layout'];
|
|
return view($template, $pageData);
|
|
}
|
|
}
|
|
|
|
public function menu($slug, $option = null)
|
|
{
|
|
$template;
|
|
$pageData = [];
|
|
if ($this->configCheck()) {
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
switch ($slug) {
|
|
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' => $option]);
|
|
$pageData = [
|
|
'theme' => $currentTheme, // for theme kit
|
|
'title' => 'Pages Tagged as ' . $option,
|
|
'dynamicRender' => $tags['dynamicRender'],
|
|
'info' => $tags['info'],
|
|
'menu' => $tags['menu'],
|
|
'pages' => $tagData['pages'],
|
|
'media' => $tags['media'],
|
|
];
|
|
break;
|
|
default:
|
|
$pages = $this->pages->getAll();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
$page = $this->pages->getBySlug($slug);
|
|
$pageData = $this->sort->page($page, false);
|
|
$template = $currentTheme . '.' . $page['layout'];
|
|
break;
|
|
}
|
|
|
|
return view($template, $pageData);
|
|
}
|
|
}
|
|
|
|
private function configCheck()
|
|
{
|
|
if (file_exists(env('FOLKS_PATH')) && file_exists(env('SETTINGS_PATH'))) {
|
|
return true;
|
|
} else {
|
|
return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
}
|
|
}
|
|
|
|
public function things()
|
|
{
|
|
return $items = ['archive', 'archives', 'tags'];
|
|
}
|
|
|
|
public static function items()
|
|
{
|
|
if (file_exists(env('SETTINGS_PATH'))) {
|
|
//set permanent links
|
|
$items = ['archive', 'archives', 'tags'];
|
|
//grab menu items and set to array so router knows to look for them
|
|
$settings = json_decode(file_get_contents(env('SETTINGS_PATH')), true);
|
|
foreach ($settings['menu'] as $item) {
|
|
array_push($items, $item['slug']);
|
|
}
|
|
return $items;
|
|
} else {
|
|
//return view('back.init', ["status" => false, "title" => "Set Up"]);
|
|
// return redirect()->route('start');
|
|
return [];
|
|
}
|
|
}
|
|
|
|
//setup up a new site or restore from back up
|
|
public function init($task, Request $request)
|
|
{
|
|
$result = [];
|
|
switch ($task) {
|
|
case 'fresh':
|
|
$result = $this->init->fresh(json_decode($request->getContent()));
|
|
break;
|
|
case 'restore':
|
|
$result = $this->init->restore($request);
|
|
break;
|
|
}
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
}
|
|
}
|