xref: /webtrees/app/Helpers/functions.php (revision 6a3de7e5c46294d14f0a6f1b4a918980eae0030d)
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;
208655ee66SGreg 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/**
328655ee66SGreg Roach * Get the CSRF token value.
338655ee66SGreg Roach *
348655ee66SGreg Roach * @return string
358655ee66SGreg Roach */
368655ee66SGreg Roachfunction csrf_token() {
378655ee66SGreg Roach	return Filter::getCsrfToken();
388655ee66SGreg Roach}
398655ee66SGreg Roach
408655ee66SGreg 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 {
48*6a3de7e5SGreg 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}
648655ee66SGreg Roach
658655ee66SGreg Roach/**
668655ee66SGreg Roach * Cerate and render a view in a single operation.
678655ee66SGreg Roach *
688655ee66SGreg Roach * @param string  $name
698655ee66SGreg Roach * @param mixed[] $data
708655ee66SGreg Roach *
718655ee66SGreg Roach * @return string
728655ee66SGreg Roach */
738655ee66SGreg Roachfunction view(string $name, array $data = []) {
748655ee66SGreg Roach	return View::make($name, $data);
758655ee66SGreg Roach}
76