public static function getByTitle($title, $initial = true) { if ($initial) { Session::forget('redirect'); } $page = HandbookPage::where('title', 'LIKE', $title)->first(); if ($page && Session::get('redirect') != $title) { $found = null; preg_replace_callback("/\\[\\[([\\w\\W]+?)\\]\\]/", function ($match) use(&$found) { $parts = explode("/", $match[1]); if (sizeof($parts) > 1) { //This is a command switch (strtolower($parts[0])) { case "redirect": $source_page = HandbookPage::where('title', $parts[1])->first(); if ($source_page) { if (Input::get('redirect') != "no") { $found = $parts[1]; } } } } }, $page->body); if ($found) { Session::set('redirect', $page->title); return HandbookPage::getByTitle($found, false); } } return $page; }
<?php $page = HandbookPage::getByTitle($title); $user = Auth::user(); ?> <div class="row"> <div class="small-12 columns"> @if($page && !$page->userCanRead($user)) <h1>This Handbook Page is Hidden</h1> <p>You do not have permission to view this page.</p> @else <h1 class="handbook-title">@if($page && $page->read_permission && $page->readPermission->hasRestrictions()) <i class="handbook-lock icon-lock" data-tooltip title="Restricted to {{$page->readPermissionList()}}"></i> @endif {{$page ? $page->title : "Page not found"}}</h1> @if(Session::get('redirect')) <div class="redirect">(Redirected from <a href="/handbook/{{HandbookPage::getURLReadyLink(Session::get('redirect'))}}?redirect=no">{{Session::get('redirect')}}</a>)</div> @endif @if($user) <ul class="button-group handbook-edit-options"> @if(isset($showNewPage)) <li><a class="button small new-page" href="/handbook/directory">{{Auth::user()->isStoryteller() ? "Directory" : "My Pages"}}</a></li> <li><a class="button small new-page" href="/handbook/create">New Page</a></li> @endif @if($page && $page->userCanWrite($user))<li><a class="button small edit-page" href="/handbook/{{$title}}/edit">Edit Page</a></li>@endif </ul> @endif @if($page) {{$page->body()}} <div class="handbook-stats">