matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 1 | <?php |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 2 | function generateRandomString($length = 96) |
| 3 | { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 4 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 5 | $charactersLength = strlen($characters); |
| 6 | $randomString = ''; |
| 7 | for ($i = 0; $i < $length; $i++) { |
| 8 | $randomString .= $characters[rand(0, $charactersLength - 1)]; |
| 9 | } |
| 10 | return $randomString; |
| 11 | } |
| 12 | |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 13 | function getClientIP(): string |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 14 | { |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 15 | $keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'); |
| 16 | foreach ($keys as $k) { |
| 17 | if (!empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP)) { |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 18 | return $_SERVER[$k]; |
| 19 | } |
| 20 | } |
| 21 | return false; |
| 22 | } |
matheusfillipe | 47cf90b | 2021-05-13 03:36:21 -0300 | [diff] [blame] | 23 | |
| 24 | function format(string $string, array $values) |
| 25 | { |
| 26 | foreach ($values as $key => $value) { |
| 27 | $string = str_replace("{{{$key}}}", $value, $string); |
| 28 | } |
| 29 | return $string; |
| 30 | } |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 31 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 32 | function template_path(string $lang_cc = null) |
| 33 | { |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 34 | include "config.php"; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 35 | if (isset($_SESSION["cc"])) $lang_cc = $GLOBALS["cc"]; |
| 36 | if (isset($GLOBALS["cc"])) $lang_cc = $GLOBALS["cc"]; |
Matheus Fillipe | 3c3bf9e | 2021-05-14 09:58:52 +0300 | [diff] [blame] | 37 | if (isset($LANG_CC) && !empty($LANG_CC) && $lang_cc == null) $lang_cc = $LANG_CC; |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 38 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 39 | if ($lang_cc) $INCLUDE_STRINGS_PATH = "templates_" . $lang_cc; |
| 40 | else $INCLUDE_STRINGS_PATH = "templates"; |
| 41 | |
| 42 | if (isset($lang_cc) && !empty($lang_cc)) $TEMPLATE = $INCLUDE_STRINGS_PATH . "/"; |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 43 | else $TEMPLATE = "templates/"; |
| 44 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 45 | include $TEMPLATE . 'strings.php'; |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 46 | |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 47 | if (!isset($RUNTIME_ERROR)) { |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 48 | include_once 'templates/strings.php'; |
| 49 | echo $RUNTIME_ERROR->not_found; |
matheusfillipe | f43dd96 | 2021-05-13 23:27:01 -0300 | [diff] [blame] | 50 | echo format($RUNTIME_ERROR->template_not_found, ["template" => $INCLUDE_STRINGS_PATH, "langcc" => $LANG_CC]); |
matheusfillipe | c0ce7fa | 2021-05-13 05:15:37 -0300 | [diff] [blame] | 51 | die(); |
| 52 | } |
| 53 | |
| 54 | return $TEMPLATE; |
| 55 | } |
Marc Kupietz | a3f3fdb | 2023-03-04 18:13:26 +0100 | [diff] [blame^] | 56 | |
| 57 | function replace_all_user_variables(string $string, User $user, string $url) |
| 58 | { |
| 59 | $string = str_replace("{{url}}", $url, $string); |
| 60 | $string = str_replace("{{full_name}}", $user->first_name . " " . $user->last_name, $string); |
| 61 | $string = str_replace("{{fullname}}", $user->first_name . " " . $user->last_name, $string); |
| 62 | $string = str_replace("{{first_name}}", $user->first_name, $string); |
| 63 | $string = str_replace("{{last_name}}", $user->last_name, $string); |
| 64 | $string = str_replace("{{email}}", $user->email, $string); |
| 65 | $string = str_replace("{{organization}}", $user->organization, $string); |
| 66 | $string = str_replace("{{username}}", $user->user_name, $string); |
| 67 | return $string; |
| 68 | } |