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;
|
|
|
|
|
|
|
|
/**
|
2021-06-26 17:23:15 +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]);
|
|
|
|
}
|
|
|
|
|
2021-08-22 14:15:58 +02:00
|
|
|
return view('pages.parts.template-manager-list', [
|
2021-06-26 17:23:15 +02:00
|
|
|
'templates' => $templates,
|
2019-08-11 21:04:43 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the content of a template.
|
2021-06-26 17:23:15 +02:00
|
|
|
*
|
2019-08-11 21:04:43 +02:00
|
|
|
* @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([
|
2021-06-26 17:23:15 +02:00
|
|
|
'html' => $page->html,
|
2019-08-11 21:04:43 +02:00
|
|
|
'markdown' => $page->markdown,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|