2019-08-11 21:04:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers;
|
|
|
|
|
|
|
|
use BookStack\Entities\Repos\PageRepo;
|
|
|
|
use BookStack\Exceptions\NotFoundException;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class PageTemplateController extends Controller
|
|
|
|
{
|
|
|
|
protected $pageRepo;
|
|
|
|
|
|
|
|
/**
|
2019-10-05 13:55:01 +02:00
|
|
|
* PageTemplateController constructor
|
2019-08-11 21:04:43 +02:00
|
|
|
*/
|
|
|
|
public function __construct(PageRepo $pageRepo)
|
|
|
|
{
|
|
|
|
$this->pageRepo = $pageRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a list of templates from the system.
|
|
|
|
*/
|
|
|
|
public function list(Request $request)
|
|
|
|
{
|
|
|
|
$page = $request->get('page', 1);
|
|
|
|
$search = $request->get('search', '');
|
2019-10-05 13:55:01 +02:00
|
|
|
$templates = $this->pageRepo->getTemplates(10, $page, $search);
|
2019-08-11 21:04:43 +02:00
|
|
|
|
|
|
|
if ($search) {
|
|
|
|
$templates->appends(['search' => $search]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('pages.template-manager-list', [
|
|
|
|
'templates' => $templates
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the content of a template.
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
2019-10-05 13:55:01 +02:00
|
|
|
public function get(int $templateId)
|
2019-08-11 21:04:43 +02:00
|
|
|
{
|
2019-10-05 13:55:01 +02:00
|
|
|
$page = $this->pageRepo->getById($templateId);
|
2019-08-11 21:04:43 +02:00
|
|
|
|
|
|
|
if (!$page->template) {
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'html' => $page->html,
|
|
|
|
'markdown' => $page->markdown,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|