]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/PageTemplateController.php
Default OpenID display name set to standard value
[bookstack] / app / Http / Controllers / PageTemplateController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\Repos\PageRepo;
6 use BookStack\Exceptions\NotFoundException;
7 use Illuminate\Http\Request;
8
9 class PageTemplateController extends Controller
10 {
11     protected $pageRepo;
12
13     /**
14      * PageTemplateController constructor
15      */
16     public function __construct(PageRepo $pageRepo)
17     {
18         $this->pageRepo = $pageRepo;
19         parent::__construct();
20     }
21
22     /**
23      * Fetch a list of templates from the system.
24      */
25     public function list(Request $request)
26     {
27         $page = $request->get('page', 1);
28         $search = $request->get('search', '');
29         $templates = $this->pageRepo->getTemplates(10, $page, $search);
30
31         if ($search) {
32             $templates->appends(['search' => $search]);
33         }
34
35         return view('pages.template-manager-list', [
36             'templates' => $templates
37         ]);
38     }
39
40     /**
41      * Get the content of a template.
42      * @throws NotFoundException
43      */
44     public function get(int $templateId)
45     {
46         $page = $this->pageRepo->getById($templateId);
47
48         if (!$page->template) {
49             throw new NotFoundException();
50         }
51
52         return response()->json([
53             'html' => $page->html,
54             'markdown' => $page->markdown,
55         ]);
56     }
57 }