├── templates └── redirect.php ├── screenshot.png ├── models └── redirect.php ├── package.json ├── redirect.php ├── blueprints └── redirect.yml ├── controllers └── redirect.php ├── LICENSE └── README.md /templates/redirect.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flokosiol/kirby-redirect/HEAD/screenshot.png -------------------------------------------------------------------------------- /models/redirect.php: -------------------------------------------------------------------------------- 1 | isExternal()) { 7 | return $this->external()->value(); 8 | } 9 | return parent::url(); 10 | } 11 | 12 | public function isExternal() { 13 | if ($this->redirect()->isEmpty() || (!page($this->redirect()->value()))) { 14 | return $this->external()->isNotEmpty(); 15 | } 16 | 17 | return false; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redirect", 3 | "description": "Editable redirects for Kirby CMS", 4 | "authors": [ 5 | { 6 | "name": "Flo Kosiol", 7 | "email": "git@flokosiol.de", 8 | "homepage": "http://flokosiol.de" 9 | }, 10 | { 11 | "name": "Benedict Zinke", 12 | "email": "bz@presentprogressive.de", 13 | "homepage": "http://presentprogressive.de" 14 | } 15 | ], 16 | "version": "1.0", 17 | "type": "kirby-plugin", 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /redirect.php: -------------------------------------------------------------------------------- 1 | set('blueprint', 'redirect', __DIR__ . DS . 'blueprints' . DS . 'redirect.yml'); 5 | 6 | // register controllers 7 | $kirby->set('controller', 'redirect', __DIR__ . DS . 'controllers' . DS . 'redirect.php'); 8 | 9 | // register templates 10 | $kirby->set('template', 'redirect', __DIR__ . DS . 'templates' . DS . 'redirect.php'); 11 | 12 | // register models 13 | require(__DIR__ . DS . 'models' . DS . 'redirect.php'); 14 | $kirby->set('page::model', 'redirect', 'RedirectPage'); 15 | -------------------------------------------------------------------------------- /blueprints/redirect.yml: -------------------------------------------------------------------------------- 1 | title: Redirect 2 | pages: true 3 | files: false 4 | fields: 5 | title: 6 | label: Title 7 | type: text 8 | help: 9 | type: info 10 | help: Leave the following fields empty to redirect to the first visible child (if exists) or to the frontpage. 11 | redirect: 12 | label: Redirect to page 13 | type: page 14 | help: If set, the user will be redirected to the page (if exists) 15 | external: 16 | label: Redirect to external URL 17 | type: url 18 | help: Will be ignored, if 'Redirect to page' is set and valid 19 | -------------------------------------------------------------------------------- /controllers/redirect.php: -------------------------------------------------------------------------------- 1 | redirect()->isNotEmpty() && ($p = page($page->redirect()->value()))) { 6 | // if 'redirect to page' is set (and exists), go for it 7 | $redirect = $p->url(); 8 | } 9 | elseif ($page->external()->isNotEmpty()) { 10 | // if 'external url' is set, go for it 11 | $redirect = $page->external()->value(); 12 | } 13 | elseif ($page->children()->visible()->count()) { 14 | // else if page has visible children, redirect to the first one 15 | $redirect = $page->children()->visible()->first()->url(); 16 | } 17 | else { 18 | // fallback: redirect to homepage 19 | $redirect = $site->homePage()->url(); 20 | } 21 | 22 | return array( 23 | 'redirect' => $redirect, 24 | ); 25 | }; 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Flo Kosiol 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kirby Redirect 2 | 3 | ![Version](https://img.shields.io/badge/version-1.0-green.svg) ![Kirby](https://img.shields.io/badge/Kirby-2.3+-red.svg) 4 | 5 | 6 | With this plugin for [Kirby 2](http://getkirby.com) editors can create pages which redirect to its first visible child, any other page or an external url. 7 | 8 | ## Requirements 9 | 10 | Please notice that you need at least **Kirby 2.3** to use this plugin. 11 | 12 | ## Preview 13 | 14 | ![Preview](screenshot.png) 15 | 16 | ## Installation 17 | 18 | Just put the `redirect` folder in the `site/plugins` folder of your Kirby installation. If this folder doesn't exist, create it. 19 | 20 | There's a `package.json` file included if you want to use the [Kirby CLI](https://github.com/getkirby/cli). 21 | 22 | ## Customization 23 | 24 | If you like, you can copy and paste the blueprint from `site/plugin/redirect/blueprints/redirect.yml` to `site/blueprints/redirect.yml` to adjust the text or add some translations. 25 | 26 | **But please make sure not to change the keys of the fields.** 27 | 28 | ## Changelog 29 | 30 | ### 1.0 31 | + add page model and `isExternal()` page method 32 | + some more documentation (and changelog) 33 | 34 | ### 0.2 35 | 36 | + check if page exists before redirecting 37 | + add possibility to redirect to external url 38 | 39 | ### 0.1 40 | 41 | + initial version 42 | 43 | ## Authors 44 | 45 | + [Flo Kosiol](https://github.com/flokosiol) 46 | + [Benedict Zinke](https://github.com/bezin) 47 | 48 | --------------------------------------------------------------------------------