xref: /webtrees/app/Helpers/functions.php (revision f97c7170bf492115ce8ddce2b598cccf00cca95a)
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
18*f97c7170SGreg Roachuse Fisharebest\Webtrees\Filter;
191f3fb95cSGreg Roachuse Fisharebest\Webtrees\Html;
201f3fb95cSGreg Roach
211f3fb95cSGreg Roach/**
22*f97c7170SGreg Roach * Generate a CSRF token form field.
23*f97c7170SGreg Roach *
24*f97c7170SGreg Roach * @return string
25*f97c7170SGreg Roach */
26*f97c7170SGreg Roachfunction csrf_field() {
27*f97c7170SGreg Roach	return '<input type="hidden" name="csrf" value="' . e(Filter::getCsrfToken()) . '">';
28*f97c7170SGreg Roach}
29*f97c7170SGreg Roach
30*f97c7170SGreg Roach/**
3178f07ab5SGreg Roach * Escape a string for inclusion within HTML.
3278f07ab5SGreg Roach *
3378f07ab5SGreg Roach * @param $text
3478f07ab5SGreg Roach *
3578f07ab5SGreg Roach * @return string
3678f07ab5SGreg Roach */
3778f07ab5SGreg Roachfunction e(string $text): string {
3878f07ab5SGreg Roach	return Html::escape($text);
3978f07ab5SGreg Roach}
4078f07ab5SGreg Roach
4178f07ab5SGreg Roach/**
421f3fb95cSGreg Roach * Generate a URL for a named route.
431f3fb95cSGreg Roach *
441f3fb95cSGreg Roach * @param string $route
451f3fb95cSGreg Roach * @param array  $parameters
461f3fb95cSGreg Roach *
471f3fb95cSGreg Roach * @return string
481f3fb95cSGreg Roach */
491f3fb95cSGreg Roachfunction route(string $route, array $parameters = []): string {
501f3fb95cSGreg Roach	$parameters = ['route' => $route] + $parameters;
511f3fb95cSGreg Roach
521f3fb95cSGreg Roach	return Html::url('index.php', $parameters);
531f3fb95cSGreg Roach}
54