blob: 0c3ad1f986898f2eef77caf2be68ed8d1248971c [file] [log] [blame]
matheusfillipeabd513e2021-05-11 03:29:11 -03001<?php
matheusfillipe47cf90b2021-05-13 03:36:21 -03002function generateRandomString($length = 96)
3{
matheusfillipeabd513e2021-05-11 03:29:11 -03004 $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
matheusfillipe47cf90b2021-05-13 03:36:21 -030013function getClientIP(): string
matheusfillipeabd513e2021-05-11 03:29:11 -030014{
matheusfillipe47cf90b2021-05-13 03:36:21 -030015 $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)) {
matheusfillipeabd513e2021-05-11 03:29:11 -030018 return $_SERVER[$k];
19 }
20 }
21 return false;
22}
matheusfillipe47cf90b2021-05-13 03:36:21 -030023
24function format(string $string, array $values)
25{
26 foreach ($values as $key => $value) {
27 $string = str_replace("{{{$key}}}", $value, $string);
28 }
29 return $string;
30}
matheusfillipec0ce7fa2021-05-13 05:15:37 -030031
matheusfillipef43dd962021-05-13 23:27:01 -030032function template_path(string $lang_cc = null)
33{
matheusfillipec0ce7fa2021-05-13 05:15:37 -030034 include "config.php";
matheusfillipef43dd962021-05-13 23:27:01 -030035 if (isset($LANG_CC) && !empty($LANG_CC) && $lang_cc == null) $lang_cc = $LANG_CC;
36 if (isset($_SESSION["cc"])) $lang_cc = $GLOBALS["cc"];
37 if (isset($GLOBALS["cc"])) $lang_cc = $GLOBALS["cc"];
matheusfillipec0ce7fa2021-05-13 05:15:37 -030038
matheusfillipef43dd962021-05-13 23:27:01 -030039 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 . "/";
matheusfillipec0ce7fa2021-05-13 05:15:37 -030043 else $TEMPLATE = "templates/";
44
matheusfillipef43dd962021-05-13 23:27:01 -030045 include $TEMPLATE . 'strings.php';
matheusfillipec0ce7fa2021-05-13 05:15:37 -030046
matheusfillipef43dd962021-05-13 23:27:01 -030047 if (!isset($RUNTIME_ERROR)) {
matheusfillipec0ce7fa2021-05-13 05:15:37 -030048 include_once 'templates/strings.php';
49 echo $RUNTIME_ERROR->not_found;
matheusfillipef43dd962021-05-13 23:27:01 -030050 echo format($RUNTIME_ERROR->template_not_found, ["template" => $INCLUDE_STRINGS_PATH, "langcc" => $LANG_CC]);
matheusfillipec0ce7fa2021-05-13 05:15:37 -030051 die();
52 }
53
54 return $TEMPLATE;
55}