]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/PageController.php
Closes #55. Allows you to set the primary color.
[bookstack] / app / Http / Controllers / PageController.php
index b4ab9682b7308d55141b2df8f3303b495b38e913..e78ae13e4c2972067ef9ed4232f6771426ab852d 100644 (file)
@@ -11,6 +11,7 @@ use BookStack\Http\Requests;
 use BookStack\Repos\BookRepo;
 use BookStack\Repos\ChapterRepo;
 use BookStack\Repos\PageRepo;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Views;
 
 class PageController extends Controller
@@ -81,6 +82,8 @@ class PageController extends Controller
 
     /**
      * Display the specified page.
+     * If the page is not found via the slug the
+     * revisions are searched for a match.
      *
      * @param $bookSlug
      * @param $pageSlug
@@ -89,7 +92,15 @@ class PageController extends Controller
     public function show($bookSlug, $pageSlug)
     {
         $book = $this->bookRepo->getBySlug($bookSlug);
-        $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+
+        try {
+            $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+        } catch (NotFoundHttpException $e) {
+            $page = $this->pageRepo->findPageUsingOldSlug($pageSlug, $bookSlug);
+            if ($page === null) abort(404);
+            return redirect($page->getUrl());
+        }
+
         $sidebarTree = $this->bookRepo->getChildren($book);
         Views::add($page);
         $this->setPageTitle($page->getShortName());
@@ -278,4 +289,30 @@ class PageController extends Controller
         ]);
     }
 
+    /**
+     * Show a listing of recently created pages
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+     */
+    public function showRecentlyCreated()
+    {
+        $pages = $this->pageRepo->getRecentlyCreatedPaginated(20);
+        return view('pages/detailed-listing', [
+            'title' => 'Recently Created Pages',
+            'pages' => $pages
+        ]);
+    }
+
+    /**
+     * Show a listing of recently created pages
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+     */
+    public function showRecentlyUpdated()
+    {
+        $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20);
+        return view('pages/detailed-listing', [
+            'title' => 'Recently Updated Pages',
+            'pages' => $pages
+        ]);
+    }
+
 }