PHP code example of beebmx / kirby-patrol

1. Go to this page and download the library: Download beebmx/kirby-patrol library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beebmx / kirby-patrol example snippets


use Kirby\Cms\App;
use Kirby\Cms\Pages;
use Kirby\Cms\Site;

'beebmx.kirby-patrol' => [
    'content' => [
        'query' => function (Site $site, Pages $pages, App $kirby) {
            return $site->find('secure-page')->children()->listed();
        },
    ],
],

'beebmx.kirby-patrol' => [
    'content' => [
        'depth' => 3,
    ],
],

use Kirby\Http\Response;
use Beebmx\KirbyMiddleware\Request;

'beebmx.kirby-patrol' => [
    'permissions' => [
        'middleware' => [
            function (Request $request, Closure $next) {
                if(page($request->path())->is('secure-page')) {
                    return Response::redirect('login')
                }

                return $next($request);
            },
        ],
    ],
],

'beebmx.kirby-patrol' => [
    'permissions' => [
        'middleware' => [
            MyCustomMiddleware::class,
        ],
    ],
],

use Beebmx\KirbyMiddleware\Request;
use Closure;
use Kirby\Cms\App;
use Kirby\Exception\ErrorPageException;

class MyCustomMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        $kirby = App::instance();

        if ($kirby->site()->isDisabled()->toBool()) {
            return throw new ErrorPageException([
                'fallback' => 'Unauthorized',
                'httpCode' => 401,
            ]);
        }

        return $next($data);
    }
}

'beebmx.kirby-patrol' => [
    'permissions' => [
        'redirect' => 'login',
    ],
],

user()->can($page)

user()->patrol(bool)

pages()->patrol(bool)

use Beebmx\KirbyMiddleware\Request;
use Closure;

'beebmx.kirby-patrol' => [
    'name' => 'Profiles',
    'icon' => 'shield',
    'content' => [
        'columns' => 4,
        'depth' => 3,
        'query' => function (Site $site, Pages $pages, Kirby $kirby) {
            return $site->find('private-content')->children()->listed();
        },
    ],
    'permissions' => [
        'redirect' => 'login',
        'default' => true,
        'middleware' => [
            function (Request $request, Closure $next) {
                if(page($request->path())->id() === 'super-secret-page') {
                    return throw new ErrorPageException([
                        'fallback' => 'Unauthorized',
                        'httpCode' => 401,
                    ]);
                }

                return $next($request);
            },
        ]
    ],
],