|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* General template helpers. |
|
4
|
|
|
* |
|
5
|
|
|
* @package ThreemaGateway |
|
6
|
|
|
* @author rugk |
|
7
|
|
|
* @copyright Copyright (c) 2015-2016 rugk |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
class ThreemaGateway_Helper_General |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* XenForo template helper: threemaregex. |
|
15
|
|
|
* |
|
16
|
|
|
* Returns the regular expression for a group of Threema IDs from |
|
17
|
|
|
* ThreemaGateway_Constants::REGEX_THREEMA_ID. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $idgroup gateway, personal or any |
|
20
|
|
|
* @return string |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function threemaRegEx($idgroup) |
|
23
|
|
|
{ |
|
24
|
|
|
return ThreemaGateway_Constants::REGEX_THREEMA_ID[$idgroup]; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* XenForo template helper: threemaidverify. |
|
29
|
|
|
* |
|
30
|
|
|
* Checks whether a passed string is a Threema ID. This uses |
|
31
|
|
|
* ThreemaGateway_Handler->checkThreemaId(). |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $threemaid The Threema ID to check. |
|
34
|
|
|
* @param string $type The type of the Threema ID: personal, |
|
35
|
|
|
* gateway, any (default: personal) |
|
36
|
|
|
* @param bool $checkExistence Whether not only formal aspects should |
|
37
|
|
|
* be checked, but also the existence of the |
|
38
|
|
|
* ID. |
|
39
|
|
|
* @return bool |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function isThreemaId($threemaid, $type = 'personal', $checkExistence) |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var array $error */ |
|
44
|
|
|
$error = []; //error array is not used anyway |
|
45
|
|
|
return ThreemaGateway_Handler_Validation::checkThreemaId($threemaid, $type, $error, $checkExistence); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* XenForo template helper: threemagwcensor. |
|
50
|
|
|
* |
|
51
|
|
|
* Censores the beginning of a string. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $string The string to censor. |
|
54
|
|
|
* @param int $charsLeave (optional) How much characters should *not* be |
|
55
|
|
|
* censored at the end of the string |
|
56
|
|
|
* @param string $censorChar (optional) The char which should be used to |
|
57
|
|
|
* censor the string. |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function censorString($string, $charsLeave = 0, $censorChar = '*') |
|
62
|
|
|
{ |
|
63
|
|
|
/** @var int $length The length to censor */ |
|
64
|
|
|
$length = strlen($string) - $charsLeave; |
|
65
|
|
|
if ($length <= 0) { //error |
|
66
|
|
|
return $string; |
|
67
|
|
|
} |
|
68
|
|
|
/** @var string $orgstr The original/unmodified string part */ |
|
69
|
|
|
$orgstr = str_split($string, $length); |
|
70
|
|
|
/** @var string $censorstr The censored string part */ |
|
71
|
|
|
$censorstr = str_repeat($censorChar, $length); |
|
72
|
|
|
|
|
73
|
|
|
if (count($orgstr) < 2) { |
|
74
|
|
|
//happens if $charsLeave = 0 -> censor whole string |
|
75
|
|
|
return $censorstr; |
|
76
|
|
|
} |
|
77
|
|
|
return $censorstr . $orgstr[1]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Rounds a given timestamp (unix time) to the day. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $time |
|
84
|
|
|
* @param bool $roundUp set to true to round up to the next day |
|
85
|
|
|
* |
|
86
|
|
|
* @return int |
|
87
|
|
|
*/ |
|
88
|
|
|
public static function roundToDay($time, $roundUp = false) |
|
89
|
|
|
{ |
|
90
|
|
|
// calculate days and round down to previous day time |
|
91
|
|
|
/** @var int $days */ |
|
92
|
|
|
$days = floor($time / 60 / 60 / 24); |
|
93
|
|
|
|
|
94
|
|
|
// round up if needed |
|
95
|
|
|
if ($roundUp) { |
|
96
|
|
|
$days += 1; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// calculate seconds again |
|
100
|
|
|
return $days * 24 * 60 * 60; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Rounds a given amount of minutes. |
|
105
|
|
|
* |
|
106
|
|
|
* Also just uses {@see roundToDay()} in the background, but minutes must be |
|
107
|
|
|
* given as a parameter. |
|
108
|
|
|
* |
|
109
|
|
|
* @return int |
|
110
|
|
|
*/ |
|
111
|
|
|
public static function roundToDayRelative($minutes, $roundUp = false) |
|
112
|
|
|
{ |
|
113
|
|
|
return self::roundToDay($minutes * 60, $roundUp); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: