73 lines
1.6 KiB
PHP
73 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Visitor;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests;
|
|
use App\Models\Content;
|
|
use App\Models\Module;
|
|
use App\Models\Template;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ContentPage extends Controller
|
|
{
|
|
/**
|
|
* @var Content
|
|
*/
|
|
protected $content;
|
|
|
|
/**
|
|
* @param Content $content
|
|
*/
|
|
function __construct(Content $content)
|
|
{
|
|
|
|
$this->content = $content;
|
|
}
|
|
|
|
public function getPage($url)
|
|
{
|
|
$page = $this->content->getByURL($url);
|
|
|
|
// no page available
|
|
if (!$page) {
|
|
abort(404);
|
|
}
|
|
|
|
return $this->renderPage($page);
|
|
}
|
|
|
|
/**
|
|
* Method used for rendering page for visitor
|
|
*
|
|
* @param Content $page
|
|
*
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
protected function renderPage(Content $page)
|
|
{
|
|
// test if loaded page is visible or not
|
|
if ($page->status == Content::STATUS_PROTECTED && !Auth::user()) {
|
|
throw new \Exception('Cannot access protected resources');
|
|
}
|
|
|
|
// add one new "view" for page
|
|
$page->view();
|
|
|
|
// decode module settings
|
|
$page->module_settings = json_decode($page->module_settings);
|
|
|
|
// get handler
|
|
$handler = new $page->module_handler;
|
|
|
|
$template = Module::where('is_template', true)->where('enabled', true)->first();
|
|
|
|
// do something template-specific
|
|
call_user_func_array([$template->handler, 'beforeRender'], [&$page]);
|
|
|
|
// render page
|
|
return $handler->render($page, '');
|
|
}
|
|
}
|