|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2024 Rafael San José <[email protected]> |
|
4
|
|
|
* |
|
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
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17
|
|
|
* or see https://www.gnu.org/ |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Alxarafe\Lib; |
|
21
|
|
|
|
|
22
|
|
|
abstract class Functions |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Obtains the main url |
|
26
|
|
|
* |
|
27
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function getUrl() |
|
30
|
|
|
{ |
|
31
|
|
|
$ssl = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'; |
|
32
|
|
|
$proto = strtolower($_SERVER['SERVER_PROTOCOL']); |
|
33
|
|
|
$proto = substr($proto, 0, strpos($proto, '/')) . ($ssl ? 's' : ''); |
|
34
|
|
|
if (isset($_SERVER['HTTP_HOST'])) { |
|
35
|
|
|
$host = $_SERVER['HTTP_HOST']; |
|
36
|
|
|
} else { |
|
37
|
|
|
$port = $_SERVER['SERVER_PORT']; |
|
38
|
|
|
$port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port; |
|
39
|
|
|
$host = $_SERVER['SERVER_NAME'] . $port; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$script = $_SERVER['SCRIPT_NAME']; |
|
43
|
|
|
|
|
44
|
|
|
$script = substr($script, 0, strlen($script) - strlen('/index.php')); |
|
45
|
|
|
return $proto . '://' . $host . $script; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* This function is used to obtain the value of a POST variable, and if it does not exist |
|
50
|
|
|
* (for example, the first time the form is loaded), take a default value. |
|
51
|
|
|
* |
|
52
|
|
|
* @param $postVar |
|
53
|
|
|
* @param $defaultValue |
|
54
|
|
|
* @return mixed |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function getIfIsset($postVar, $defaultValue) |
|
57
|
|
|
{ |
|
58
|
|
|
$return = filter_input(INPUT_POST, $postVar); |
|
59
|
|
|
if ($return === null || $return === false) { |
|
60
|
|
|
return $defaultValue; |
|
61
|
|
|
} |
|
62
|
|
|
return $return; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|