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
This commit is contained in:
parent
c4d759c311
commit
4c9fbc3ded
3 changed files with 198 additions and 80 deletions
|
@ -20,6 +20,7 @@ class FrontController extends Controller
|
|||
protected SortingService $sort;
|
||||
protected $init;
|
||||
protected $dash;
|
||||
protected $words;
|
||||
|
||||
public function __construct(
|
||||
PageRepositoryInterface $pageRepository,
|
||||
|
@ -35,91 +36,107 @@ class FrontController extends Controller
|
|||
$this->sort = $sortService;
|
||||
$this->init = $initService;
|
||||
$this->dash = $dashController;
|
||||
$this->words = ['words'];
|
||||
}
|
||||
|
||||
public function start($one = 00, $two = 00, $three = 00)
|
||||
public function start()
|
||||
{
|
||||
$global = $this->settings->getGlobal();
|
||||
$currentTheme = $this->assets->getCurrentTheme();
|
||||
$template;
|
||||
$pageData = [];
|
||||
$pages = $this->pages->getAll();
|
||||
//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];
|
||||
}
|
||||
|
||||
//check if configs are present
|
||||
if (file_exists(env('FOLKS_PATH')) && file_exists(env('SETTINGS_PATH'))) {
|
||||
if ($this->configCheck()) {
|
||||
$pages = $this->pages->getAll();
|
||||
$global = $this->settings->getGlobal();
|
||||
$currentTheme = $this->assets->getCurrentTheme();
|
||||
if ($global['dynamicRender'] == 'true') {
|
||||
if (is_numeric($one)) {
|
||||
if ($one == 00 || !isset($one)) {
|
||||
$page = $pages->where('id', 0)->first();
|
||||
$pageData = $this->sort->page($page, false);
|
||||
$template = $currentTheme . '.index';
|
||||
} else {
|
||||
$page = $this->pages->getBySlug($three);
|
||||
$pageData = $this->sort->page($page, false);
|
||||
$template = $currentTheme . '.' . $page['layout'];
|
||||
}
|
||||
} else {
|
||||
if ($one == null || $one == '') {
|
||||
$page = $pages->where('id', 0)->first();
|
||||
$pageData = $this->sort->page($page, false);
|
||||
$template = $currentTheme . '.index';
|
||||
} else {
|
||||
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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$page = $pages->where('id', 0)->first();
|
||||
$pageData = $this->sort->page($page, false);
|
||||
$template = $currentTheme . '.index';
|
||||
return view($template, $pageData);
|
||||
} else {
|
||||
if (is_file('../public/index.html')) {
|
||||
return response()->file('../public/index.html');
|
||||
} else {
|
||||
return redirect()->intended('dashboard/start');
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
|
88
app/Http/Controllers/RSSController.php
Normal file
88
app/Http/Controllers/RSSController.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Interfaces\PageRepositoryInterface;
|
||||
use App\Services\Data\SettingsService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class RSSController extends Controller
|
||||
{
|
||||
protected PageRepositoryInterface $pages;
|
||||
protected SettingsService $settings;
|
||||
|
||||
public function __construct(
|
||||
PageRepositoryInterface $pageRepo,
|
||||
SettingsService $settingsService,
|
||||
) {
|
||||
$this->settings = $settingsService;
|
||||
$this->pages = $pageRepo;
|
||||
}
|
||||
|
||||
public function getFeed(Request $request)
|
||||
{
|
||||
$pages = $this->pages->getAll();
|
||||
$global = $this->settings->getGlobal();
|
||||
$feedContent = "<?xml version='1.0' encoding='ISO-8859-1'?>
|
||||
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
|
||||
<channel>
|
||||
<title>{$global['title']}</title>
|
||||
<atom:link href='{$global['base_url']}/rss/feed/' rel='self' type='application/rss+xml' />
|
||||
<link>{$global['base_url']}</link>
|
||||
<description>Feed @ {$global['title']}</description>
|
||||
<language>en-us</language>";
|
||||
|
||||
// Loop over the content and add it to the feed
|
||||
foreach ($pages as $item) {
|
||||
$title = urldecode($item['title']);
|
||||
$html = urldecode($item['html']);
|
||||
$updatedAt = Carbon::parse($item['rawUpdated']);
|
||||
$date = $updatedAt->format('D, d M Y H:i:s O');
|
||||
$feedContent .= "
|
||||
<item>
|
||||
<title>{$title}</title>
|
||||
<link>{$global['base_url']}/rss/feed/item/{$item['uuid']}</link>
|
||||
<guid>{$global['base_url']}/rss/feed/item/{$item['uuid']}</guid>
|
||||
<pubDate>{$date}</pubDate>
|
||||
<description><![CDATA[{$html}]]></description>
|
||||
</item>";
|
||||
}
|
||||
|
||||
$feedContent .= "
|
||||
</channel>
|
||||
</rss>";
|
||||
|
||||
return response($feedContent, 200)->header('Content-Type', 'application/rss+xml');
|
||||
/**
|
||||
//set up feed info
|
||||
header("Content-Type: text/xml");
|
||||
echo("<?xml version='1.0' encoding='ISO-8859-1'?>");
|
||||
echo("<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>");
|
||||
echo("<channel>");
|
||||
echo("<title>" . $global['title'] . "</title>");
|
||||
echo("<link>" . $global['base_url'] . "</link>");
|
||||
echo("<description>The Feed for " . $global['title'] . "</description>");
|
||||
|
||||
//item loop start
|
||||
|
||||
foreach ($pages as $item) {
|
||||
echo("<item id='" . $item['id'] . "'>");
|
||||
echo("<title>" . urldecode($item['title']) . "</title>");
|
||||
echo("<link>" . $global['base_url'] . "/rss/feed/item/" . $item['uuid'] . "</link>");
|
||||
echo("<guid>" . $global['base_url'] . "/rss/feed/item/" . $item['uuid'] . "</guid>");
|
||||
echo("<displayDate>" . $item['updated'] . "</displayDate>");
|
||||
echo("<pubDate>" . $item['created'] . "</pubDate>");
|
||||
echo("<description> <![CDATA[" . $item['html'] . "]]></description>");
|
||||
echo("<author>" . $item['author'] . "</author>");
|
||||
echo("</item>");
|
||||
}
|
||||
|
||||
//item loop end
|
||||
|
||||
//close it up
|
||||
echo("</channel>");
|
||||
echo("</rss>");
|
||||
**/
|
||||
}
|
||||
}
|
|
@ -8,12 +8,17 @@ use App\Http\Controllers\DashController;
|
|||
use App\Http\Controllers\SettingsController;
|
||||
use App\Http\Controllers\ThemeController;
|
||||
use App\Http\Controllers\SystemMailController;
|
||||
use App\Http\Controllers\RSSController;
|
||||
|
||||
//Frontend
|
||||
Route::prefix('/')
|
||||
->controller(FrontController::class)
|
||||
->group(function () {
|
||||
Route::get("/{one?}/{two?}/{three?}", 'start')->where('one', '^((?!dashboard).)*$');
|
||||
Route::get("/", 'start');
|
||||
Route::get("/{year}/{month}/{slug}", 'page')
|
||||
->where(['year' => '[0-9]+', 'month' => '[0-9]+', 'slug' => '[A-Za-z0-9-]+']);
|
||||
Route::get("/{slug}/{option?}", 'menu')
|
||||
->whereIn('slug', FrontController::items());
|
||||
Route::post("/init/{task}", 'init');
|
||||
});
|
||||
|
||||
|
@ -52,14 +57,6 @@ Route::prefix('dashboard/settings')
|
|||
Route::post("/reset", 'reset');
|
||||
});
|
||||
|
||||
//mailer
|
||||
Route::prefix('dashboard/mailer')
|
||||
->middleware('member.check')
|
||||
->controller(SystemMailController::class)
|
||||
->group(function () {
|
||||
Route::post("/", 'sendNotify');
|
||||
});
|
||||
|
||||
//Themekit
|
||||
Route::prefix('dashboard/themekit')
|
||||
->middleware('member.check')
|
||||
|
@ -68,3 +65,19 @@ Route::prefix('dashboard/themekit')
|
|||
Route::get("/", 'start');
|
||||
Route::get("/view/{view?}/{id?}", 'getView');
|
||||
});
|
||||
|
||||
//mailer
|
||||
Route::prefix('dashboard/mailer')
|
||||
->middleware('member.check')
|
||||
->controller(SystemMailController::class)
|
||||
->group(function () {
|
||||
Route::post("/", 'sendNotify');
|
||||
});
|
||||
|
||||
//RSS
|
||||
|
||||
Route::prefix('rss/feed')
|
||||
->controller(RSSController::class)
|
||||
->group(function () {
|
||||
Route::get("/", 'getFeed');
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue