2019-08-12 03:04:43 +08: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 19:55:01 +08:00
|
|
|
* PageTemplateController constructor
|
2019-08-12 03:04:43 +08: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 19:55:01 +08:00
|
|
|
$templates = $this->pageRepo->getTemplates(10, $page, $search);
|
2019-08-12 03:04:43 +08: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 19:55:01 +08:00
|
|
|
public function get(int $templateId)
|
2019-08-12 03:04:43 +08:00
|
|
|
{
|
2019-10-05 19:55:01 +08:00
|
|
|
$page = $this->pageRepo->getById($templateId);
|
2019-08-12 03:04:43 +08:00
|
|
|
|
|
|
|
if (!$page->template) {
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'html' => $page->html,
|
|
|
|
'markdown' => $page->markdown,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|