11f3fb95cSGreg Roach<?php 21f3fb95cSGreg Roach/** 31f3fb95cSGreg Roach * webtrees: online genealogy 41f3fb95cSGreg Roach * Copyright (C) 2017 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 18f97c7170SGreg Roachuse Fisharebest\Webtrees\Filter; 191f3fb95cSGreg Roachuse Fisharebest\Webtrees\Html; 20*8655ee66SGreg Roachuse Fisharebest\Webtrees\View; 211f3fb95cSGreg Roach 221f3fb95cSGreg Roach/** 23f97c7170SGreg Roach * Generate a CSRF token form field. 24f97c7170SGreg Roach * 25f97c7170SGreg Roach * @return string 26f97c7170SGreg Roach */ 27f97c7170SGreg Roachfunction csrf_field() { 28f97c7170SGreg Roach return '<input type="hidden" name="csrf" value="' . e(Filter::getCsrfToken()) . '">'; 29f97c7170SGreg Roach} 30f97c7170SGreg Roach 31f97c7170SGreg Roach/** 32*8655ee66SGreg Roach * Get the CSRF token value. 33*8655ee66SGreg Roach * 34*8655ee66SGreg Roach * @return string 35*8655ee66SGreg Roach */ 36*8655ee66SGreg Roachfunction csrf_token() { 37*8655ee66SGreg Roach return Filter::getCsrfToken(); 38*8655ee66SGreg Roach} 39*8655ee66SGreg Roach 40*8655ee66SGreg Roach/** 4178f07ab5SGreg Roach * Escape a string for inclusion within HTML. 4278f07ab5SGreg Roach * 4378f07ab5SGreg Roach * @param $text 4478f07ab5SGreg Roach * 4578f07ab5SGreg Roach * @return string 4678f07ab5SGreg Roach */ 4778f07ab5SGreg Roachfunction e(string $text): string { 4878f07ab5SGreg Roach return Html::escape($text); 4978f07ab5SGreg Roach} 5078f07ab5SGreg Roach 5178f07ab5SGreg Roach/** 521f3fb95cSGreg Roach * Generate a URL for a named route. 531f3fb95cSGreg Roach * 541f3fb95cSGreg Roach * @param string $route 551f3fb95cSGreg Roach * @param array $parameters 561f3fb95cSGreg Roach * 571f3fb95cSGreg Roach * @return string 581f3fb95cSGreg Roach */ 591f3fb95cSGreg Roachfunction route(string $route, array $parameters = []): string { 601f3fb95cSGreg Roach $parameters = ['route' => $route] + $parameters; 611f3fb95cSGreg Roach 621f3fb95cSGreg Roach return Html::url('index.php', $parameters); 631f3fb95cSGreg Roach} 64*8655ee66SGreg Roach 65*8655ee66SGreg Roach/** 66*8655ee66SGreg Roach * Cerate and render a view in a single operation. 67*8655ee66SGreg Roach * 68*8655ee66SGreg Roach * @param string $name 69*8655ee66SGreg Roach * @param mixed[] $data 70*8655ee66SGreg Roach * 71*8655ee66SGreg Roach * @return string 72*8655ee66SGreg Roach */ 73*8655ee66SGreg Roachfunction view(string $name, array $data = []) { 74*8655ee66SGreg Roach return View::make($name, $data); 75*8655ee66SGreg Roach} 76