|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FatFramework; |
|
4
|
|
|
|
|
5
|
|
|
class Functions |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* String Transformer |
|
9
|
|
|
* Formats a 16-digit credit card number into 4-digit-blocks |
|
10
|
|
|
* |
|
11
|
|
|
* @param string $cc 16-digit credit cardnum |
|
12
|
|
|
* |
|
13
|
|
|
* @return string 4-digit-block formatted credit cardnum |
|
14
|
|
|
*/ |
|
15
|
1 |
|
public static function formatCreditCardNum($cc) { |
|
16
|
1 |
|
$sDivider = ' '; |
|
17
|
1 |
|
$cc_length = strlen($cc); |
|
18
|
1 |
|
$newCreditCard = substr($cc, -4); |
|
19
|
|
|
|
|
20
|
1 |
|
for ($i = $cc_length - 5; $i >= 0; $i--) { |
|
21
|
1 |
|
if ((($i + 1) - $cc_length)%4 == 0) { |
|
22
|
1 |
|
$newCreditCard = $sDivider . $newCreditCard; |
|
23
|
1 |
|
} |
|
24
|
1 |
|
$newCreditCard = $cc[$i] . $newCreditCard; |
|
25
|
1 |
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
return $newCreditCard; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* String Transformer |
|
32
|
|
|
* Date string converter for dates loaded from database |
|
33
|
|
|
* and shown in templates, mails etc. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $sDate Date formatted like 2000-12-24 |
|
36
|
|
|
* |
|
37
|
|
|
* @return string $sGermanDate Date formatted like 24.12.2000 |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public static function formatMysqlDate($sDate) |
|
40
|
|
|
{ |
|
41
|
1 |
|
$aD = explode("-", $sDate); |
|
42
|
1 |
|
$sGermanDate = sprintf("%02d.%02d.%04d", $aD[2], $aD[1], $aD[0]); |
|
43
|
1 |
|
return $sGermanDate; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get cleaned GET or POST parameters. |
|
48
|
|
|
* Avoid SQL-Injection etc. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $sParam Parameter-name |
|
|
|
|
|
|
51
|
|
|
* |
|
52
|
|
|
* @return string $sParamValue Parameter-value OR false |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public static function getRequestParameter($param) { |
|
|
|
|
|
|
55
|
|
|
$return = false; |
|
56
|
1 |
|
if (isset($_REQUEST[$param])) { |
|
57
|
|
|
$paramValue = $_REQUEST[$param]; |
|
58
|
1 |
|
} |
|
59
|
1 |
|
if (isset($paramValue) && is_string($paramValue)) { |
|
60
|
1 |
|
$return = self::stripString($paramValue); |
|
61
|
|
|
} elseif (isset($paramValue) && is_array($paramValue)) { |
|
62
|
1 |
|
foreach ($paramValue AS $key => $value) { |
|
63
|
1 |
|
$return[$key] = self::stripString($value); |
|
64
|
1 |
|
} |
|
65
|
1 |
|
} |
|
66
|
|
|
return $return; |
|
67
|
1 |
|
} |
|
68
|
1 |
|
|
|
69
|
|
|
/** |
|
70
|
1 |
|
* Auto loads all php files in $directoryPath (not recursive) |
|
71
|
|
|
* auto include all files in given directory |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $directoryPath |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function includeDir($directoryPath) |
|
78
|
|
|
{ |
|
79
|
|
|
$aIncludeFiles = scandir($directoryPath); |
|
80
|
|
|
$i = 1; |
|
81
|
1 |
|
foreach ($aIncludeFiles AS $file) { |
|
82
|
|
|
if ($i >= 3 && !is_dir($directoryPath . $file) && substr($directoryPath . $file, -3, 3) == 'php') { |
|
83
|
1 |
|
include_once($directoryPath . $file); |
|
84
|
1 |
|
} |
|
85
|
1 |
|
$i++; |
|
86
|
1 |
|
} |
|
87
|
1 |
|
} |
|
88
|
1 |
|
|
|
89
|
1 |
|
/** |
|
90
|
1 |
|
* String Trasformer |
|
91
|
1 |
|
* Removes whitespace and empty lines from a html-source. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $sHtml HTML sourcecode |
|
94
|
|
|
* |
|
95
|
|
|
* @return string $sCleanedHtml Reduced HTML sourcecode |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function reduceHtml($sHtml) { |
|
98
|
|
|
$sCleanedHtml = ""; |
|
99
|
|
|
$aHtmlLines = explode("\n", $sHtml); |
|
100
|
|
|
foreach ($aHtmlLines as $sLine) { |
|
101
|
1 |
|
if (trim($sLine) != "") { |
|
102
|
1 |
|
$sCleanedHtml .= trim($sLine) . "\n"; |
|
103
|
1 |
|
} |
|
104
|
1 |
|
} |
|
105
|
1 |
|
return $sCleanedHtml; |
|
106
|
1 |
|
} |
|
107
|
1 |
|
|
|
108
|
1 |
|
/** |
|
109
|
1 |
|
* Strip evil chars from a parameter-string to avoid hacking. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $sString |
|
112
|
|
|
* |
|
113
|
|
|
* @return string $sStrippedString |
|
114
|
|
|
*/ |
|
115
|
|
|
public static function stripString($sString) { |
|
116
|
|
|
$sStrippedString = str_replace( |
|
117
|
|
|
array('&', '<', '>', '"', "'", chr(0), '\\', "\n", "\r"), |
|
118
|
|
|
array('&', '<', '>', '"', ''', '', '\', ' ', ' '), $sString |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
return $sStrippedString; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.