fipamo/app/Http/Controllers/FrontController.php
ro 4c9fbc3ded
Added RSS
plugged in a simple rss component so fipamo sites can be subscribed to
through feed reeders.

routing needed a bit of updating to make it work, so it's been edited to
accomodate any new url that deviate from created pages.

long live RSS
2025-05-20 17:10:57 -06:00

154 lines
5.2 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 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 response()->file('../public/index.html');
}
}
}
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()
{
//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;
}
//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');
}
}