1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18use Fisharebest\Webtrees\Html; 19use Fisharebest\Webtrees\Session; 20use Fisharebest\Webtrees\View; 21 22/** 23 * Generate a CSRF token form field. 24 * 25 * @return string 26 */ 27function csrf_field() 28{ 29 return '<input type="hidden" name="csrf" value="' . e(Session::getCsrfToken()) . '">'; 30} 31 32/** 33 * Get the CSRF token value. 34 * 35 * @return string 36 */ 37function csrf_token() 38{ 39 return \Fisharebest\Webtrees\Session::getCsrfToken(); 40} 41 42/** 43 * Generate a URL for a named route. 44 * 45 * @param string $route 46 * @param array $parameters 47 * @param bool $absolute 48 * 49 * @return string 50 */ 51function route(string $route, array $parameters = [], bool $absolute = true): string 52{ 53 $parameters = ['route' => $route] + $parameters; 54 55 if ($absolute) { 56 return Html::url(WT_BASE_URL . 'index.php', $parameters); 57 } 58 59 return Html::url('index.php', $parameters); 60} 61 62/** 63 * Cerate and render a view in a single operation. 64 * 65 * @param string $name 66 * @param mixed[] $data 67 * 68 * @return string 69 */ 70function view(string $name, array $data = []) 71{ 72 return View::make($name, $data); 73} 74