use BookStack\Actions\View;
use BookStack\Entities\Tools\BookContents;
+use BookStack\Entities\Tools\NextPreviousContentLocator;
use BookStack\Entities\Tools\PageContent;
use BookStack\Entities\Tools\PageEditActivity;
use BookStack\Entities\Models\Page;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Throwable;
-use Views;
class PageController extends Controller
{
$page->load(['comments.createdBy']);
}
- $chapterId = $page->getParentChapter();
- $allPageSlugs = $this->pageRepo->getPageByChapterID($chapterId[0]->id);
- $pos = 0;
- foreach ($allPageSlugs as $slug){
- if($pageSlug === $slug->slug){
- $currPagePos = $pos;
- }
- $pos++;
- $pageUrl = $this->pageRepo->getBySlug($bookSlug, $slug->slug);
- $urlLink[] = $pageUrl->getUrl();
- }
- for($i=0; $i <= $currPagePos; $i++){
- $nextCount = $i+1;
- $prevCount = $i-1;
- $prevPage = '#';
- $nextPage = '#';
- if($nextCount < count($urlLink)){
- $nextPage = $urlLink[$nextCount];
- }
- if($currPagePos == $i && $currPagePos != 0){
- $prevPage = $urlLink[$prevCount];
- }
- }
+ $nextPreviousLocator = new NextPreviousContentLocator($page, $sidebarTree);
- $disablePrev = "";
- $disableNxt = "";
- if($prevPage == "#"){
- $disablePrev = "disabled";
- }
- if($nextPage == "#"){
- $disableNxt = "disabled";
- }
-
View::incrementFor($page);
$this->setPageTitle($page->getShortName());
return view('pages.show', [
'sidebarTree' => $sidebarTree,
'commentsEnabled' => $commentsEnabled,
'pageNav' => $pageNav,
- 'prevPage' => $prevPage,
- 'nextPage' => $nextPage,
- 'disablePrev' => $disablePrev,
- 'disableNxt' => $disableNxt
+ 'next' => $nextPreviousLocator->getNext(),
+ 'previous' => $nextPreviousLocator->getPrevious(),
]);
}
$updateTime = $draft->updated_at->timestamp;
return response()->json([
- 'status' => 'success',
- 'message' => trans('entities.pages_edit_draft_save_at'),
+ 'status' => 'success',
+ 'message' => trans('entities.pages_edit_draft_save_at'),
'timestamp' => $updateTime
]);
}
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-delete', $page);
- $this->setPageTitle(trans('entities.pages_delete_named', ['pageName'=>$page->getShortName()]));
+ $this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
return view('pages.delete', [
'book' => $page->book,
'page' => $page,
{
$page = $this->pageRepo->getById($pageId);
$this->checkOwnablePermission('page-update', $page);
- $this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName'=>$page->getShortName()]));
+ $this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName' => $page->getShortName()]));
return view('pages.delete', [
'book' => $page->book,
'page' => $page,
try {
$parent = $this->pageRepo->move($page, $entitySelection);
} catch (Exception $exception) {
- if ($exception instanceof PermissionsException) {
+ if ($exception instanceof PermissionsException) {
$this->showPermissionError();
}
try {
$pageCopy = $this->pageRepo->copy($page, $entitySelection, $newName);
} catch (Exception $exception) {
- if ($exception instanceof PermissionsException) {
+ if ($exception instanceof PermissionsException) {
$this->showPermissionError();
}
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('restrictions-manage', $page);
return view('pages.permissions', [
- 'page' => $page,
+ 'page' => $page,
]);
}