11f3fb95cSGreg Roach<?php 21f3fb95cSGreg Roach/** 31f3fb95cSGreg Roach * webtrees: online genealogy 4*8fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 51f3fb95cSGreg Roach * This program is free software: you can redistribute it and/or modify 61f3fb95cSGreg Roach * it under the terms of the GNU General Public License as published by 71f3fb95cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 81f3fb95cSGreg Roach * (at your option) any later version. 91f3fb95cSGreg Roach * This program is distributed in the hope that it will be useful, 101f3fb95cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 111f3fb95cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 121f3fb95cSGreg Roach * GNU General Public License for more details. 131f3fb95cSGreg Roach * You should have received a copy of the GNU General Public License 141f3fb95cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 151f3fb95cSGreg Roach */ 1678f07ab5SGreg Roachdeclare(strict_types=1); 171f3fb95cSGreg Roach 181f3fb95cSGreg Roach/** 19f97c7170SGreg Roach * Generate a CSRF token form field. 20f97c7170SGreg Roach * 21f97c7170SGreg Roach * @return string 22f97c7170SGreg Roach */ 23c1010edaSGreg Roachfunction csrf_field() 24c1010edaSGreg Roach{ 2530ea777aSGreg Roach return '<input type="hidden" name="csrf" value="' . e(\Fisharebest\Webtrees\Session::getCsrfToken()) . '">'; 26f97c7170SGreg Roach} 27f97c7170SGreg Roach 28f97c7170SGreg Roach/** 298655ee66SGreg Roach * Get the CSRF token value. 308655ee66SGreg Roach * 318655ee66SGreg Roach * @return string 328655ee66SGreg Roach */ 33c1010edaSGreg Roachfunction csrf_token() 34c1010edaSGreg Roach{ 35a45f9889SGreg Roach return \Fisharebest\Webtrees\Session::getCsrfToken(); 368655ee66SGreg Roach} 378655ee66SGreg Roach 388655ee66SGreg Roach/** 391f3fb95cSGreg Roach * Generate a URL for a named route. 401f3fb95cSGreg Roach * 411f3fb95cSGreg Roach * @param string $route 421f3fb95cSGreg Roach * @param array $parameters 43571e6fcaSGreg Roach * @param bool $absolute 441f3fb95cSGreg Roach * 451f3fb95cSGreg Roach * @return string 461f3fb95cSGreg Roach */ 47c1010edaSGreg Roachfunction route(string $route, array $parameters = [], bool $absolute = true): string 48c1010edaSGreg Roach{ 491f3fb95cSGreg Roach $parameters = ['route' => $route] + $parameters; 501f3fb95cSGreg Roach 51571e6fcaSGreg Roach if ($absolute) { 5230ea777aSGreg Roach return \Fisharebest\Webtrees\Html::url(WT_BASE_URL . 'index.php', $parameters); 531f3fb95cSGreg Roach } 54b2ce94c6SRico Sonntag 5530ea777aSGreg Roach return \Fisharebest\Webtrees\Html::url('index.php', $parameters); 56571e6fcaSGreg Roach} 578655ee66SGreg Roach 588655ee66SGreg Roach/** 598655ee66SGreg Roach * Cerate and render a view in a single operation. 608655ee66SGreg Roach * 618655ee66SGreg Roach * @param string $name 628655ee66SGreg Roach * @param mixed[] $data 638655ee66SGreg Roach * 648655ee66SGreg Roach * @return string 658655ee66SGreg Roach */ 66c1010edaSGreg Roachfunction view(string $name, array $data = []) 67c1010edaSGreg Roach{ 6830ea777aSGreg Roach return \Fisharebest\Webtrees\View::make($name, $data); 698655ee66SGreg Roach} 70