|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\IDealBasic; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Title: iDEAL Basic data helper class |
|
7
|
|
|
* Description: |
|
8
|
|
|
* Copyright: 2005-2019 Pronamic |
|
9
|
|
|
* Company: Pronamic |
|
10
|
|
|
* |
|
11
|
|
|
* @author Remco Tolsma |
|
12
|
|
|
* @version 2.0.0 |
|
13
|
|
|
* @since 1.0.1 |
|
14
|
|
|
* @see http://pronamic.nl/wp-content/uploads/2011/12/IDealBasic_EN_v2.3.pdf |
|
15
|
|
|
*/ |
|
16
|
|
|
class DataHelper { |
|
17
|
|
|
/** |
|
18
|
|
|
* Alphanumerical, free text |
|
19
|
|
|
* |
|
20
|
|
|
* The iDEAL Basic documentation is not very clear about which characters |
|
21
|
|
|
* are allowed within the alphanumeric (AN) specification. Pronamic |
|
22
|
|
|
* contacted some of the iDEAL providers and the ING Customer Support |
|
23
|
|
|
* Desk ([email protected]) replied with the following message (Dutch): |
|
24
|
|
|
* |
|
25
|
|
|
* > Naast A-Z, a-z en 0-9 is alleen de spatie nog een geaccepteerd teken binnen AN. |
|
26
|
|
|
* > |
|
27
|
|
|
* > Andere karakters zijn niet toegestaan. Het is met name belangrijk dat er geen html tags in voorkomen.: |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private static $characters_an = array( 'A-Z', 'a-z', '0-9', ' ' ); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Strictly alphanumerical (letters and numbers only) |
|
35
|
|
|
* |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
private static $characters_ans = array( 'A-Z', 'a-z', '0-9' ); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Numerical |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
private static $characters_n = array( '0-9' ); |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Filter the specified characters from the string |
|
49
|
|
|
* |
|
50
|
|
|
* @param array $characters |
|
51
|
|
|
* @param string $string |
|
52
|
|
|
* @param int $max |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
private static function filter( array $characters, $string, $max = null ) { |
|
57
|
|
|
$pattern = '#[^' . implode( $characters ) . ']#'; |
|
58
|
|
|
|
|
59
|
|
|
$string = preg_replace( $pattern, '', $string ); |
|
60
|
|
|
|
|
61
|
|
|
if ( isset( $max ) ) { |
|
62
|
|
|
$string = substr( $string, 0, $max ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $string; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Alphanumerical, free text |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $string |
|
72
|
|
|
* @param string $max |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function an( $string, $max = null ) { |
|
77
|
|
|
return self::filter( self::$characters_an, $string, $max ); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public static function an16( $string ) { |
|
81
|
|
|
return self::an( $string, 16 ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public static function an32( $string ) { |
|
85
|
|
|
return self::an( $string, 32 ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Strictly alphanumerical (letters and numbers only) |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $string |
|
92
|
|
|
* @param string $max |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public static function ans( $string, $max = null ) { |
|
97
|
|
|
return self::filter( self::$characters_ans, $string, $max ); |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public static function ans16( $string ) { |
|
101
|
|
|
return self::ans( $string, 16 ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public static function ans32( $string ) { |
|
105
|
|
|
return self::ans( $string, 32 ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Strictly alphanumerical (numbers only) |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $string |
|
112
|
|
|
* @param string $max |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public static function n( $string, $max = null ) { |
|
117
|
|
|
return self::filter( self::$characters_n, $string, $max ); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|