|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* oledrion |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright {@link http://xoops.org/ XOOPS Project} |
|
16
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
17
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Classe chargée de la manipulation des passerelles de paiement |
|
22
|
|
|
* |
|
23
|
|
|
* Normalement la classe est utilisable de manière statique |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class Oledrion_gateways |
|
32
|
|
|
*/ |
|
33
|
|
|
class Oledrion_gateways |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Retourne la passerelle de paiement en cours d'utilisation |
|
37
|
|
|
* |
|
38
|
|
|
* @param null $gateway |
|
39
|
|
|
* @return string Le nom de la passerelle de paiement (en fait le nom de son répertoire) |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function getCurrentGateway($gateway = null) |
|
42
|
|
|
{ |
|
43
|
|
|
if ($gateway) { |
|
44
|
|
|
$return = $gateway; |
|
45
|
|
|
} else { |
|
46
|
|
|
$return = xoops_trim(Oledrion_utils::getModuleOption('used_gateway')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($return == '') { |
|
50
|
|
|
$return = 'paypal'; // Valeur par défaut |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $return; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Retourne la passerelle de paiement en cours d'utilisation |
|
58
|
|
|
* |
|
59
|
|
|
* @return string Le nom de la passerelle de paiement (en fait le nom de son répertoire) |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function getDefaultGateway() |
|
62
|
|
|
{ |
|
63
|
|
|
$return = xoops_trim(Oledrion_utils::getModuleOption('used_gateway')); |
|
64
|
|
|
if ($return == '') { |
|
65
|
|
|
$return = 'paypal'; // Valeur par défaut |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Nettoie le nom de la passerelle de paiement |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function purifyGatewayName($gatewayName) |
|
78
|
|
|
{ |
|
79
|
|
|
return str_replace('..', '', $gatewayName); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Retourne la liste des passerelles de paiement installées |
|
84
|
|
|
* |
|
85
|
|
|
* @return array |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function getInstalledGatewaysList() |
|
88
|
|
|
{ |
|
89
|
|
|
return XoopsLists::getDirListAsArray(OLEDRION_ADMIN_PATH . 'gateways/'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Retourne le chemin d'accès à une passerelle de paiement |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement (son répertoire) |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function getGatewayPath($gatewayName) |
|
99
|
|
|
{ |
|
100
|
|
|
return OLEDRION_ADMIN_PATH . 'gateways' . '/' . $gatewayName; // Par exemple c:/inetpub/wwwroot/xoops/modules/oledrion/admin/gateways/paypal |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Retourne le chemin complet vers le fichier de langue de la passerelle |
|
105
|
|
|
* |
|
106
|
|
|
* @param unknown_type $gatewayName |
|
107
|
|
|
* @return unknown |
|
|
|
|
|
|
108
|
|
|
*/ |
|
109
|
|
|
public static function getGatewayLanguageFilename($gatewayName) |
|
110
|
|
|
{ |
|
111
|
|
|
global $xoopsConfig; |
|
|
|
|
|
|
112
|
|
|
$gatewayPath = self::getGatewayPath($gatewayName); |
|
113
|
|
|
|
|
114
|
|
|
return $gatewayPath . '/language/' . $xoopsConfig['language'] . '/main.php'; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Charge le fichier de traductions d'une passerelle de paiement |
|
119
|
|
|
* |
|
120
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement (son répertoire) |
|
121
|
|
|
* @param string $languageFilename Utilisé pour retourner le nom du fichier de langue inclu |
|
|
|
|
|
|
122
|
|
|
* @param bool $includeIt |
|
123
|
|
|
* @return bool True si le chargement a réussi sinon Faux |
|
124
|
|
|
*/ |
|
125
|
|
|
public static function loadGatewaysLanguageDefines($gatewayName, &$languageFilename = null, $includeIt = true) |
|
126
|
|
|
{ |
|
127
|
|
|
$gatewayPath = self::getGatewayPath($gatewayName); |
|
128
|
|
|
$languageFileIncluded = false; |
|
129
|
|
|
$languageFile = self::getGatewayLanguageFilename($gatewayName); |
|
|
|
|
|
|
130
|
|
|
$defaultLanguageFile = $gatewayPath . '/language/english/main.php'; |
|
131
|
|
|
if (file_exists($languageFile)) { |
|
132
|
|
|
if ($includeIt) { |
|
133
|
|
|
require_once $languageFile; |
|
134
|
|
|
} |
|
135
|
|
|
$languageFileIncluded = true; |
|
136
|
|
|
$languageFilename = $languageFile; |
|
137
|
|
|
} elseif (file_exists($defaultLanguageFile)) { |
|
138
|
|
|
$languageFileIncluded = true; |
|
139
|
|
|
if ($includeIt) { |
|
140
|
|
|
require_once $defaultLanguageFile; |
|
141
|
|
|
} |
|
142
|
|
|
$languageFilename = $defaultLanguageFile; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return $languageFileIncluded; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Retourne le chemin d'accès complet à une passerelle de paiement |
|
150
|
|
|
* |
|
151
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement (son répertoire) |
|
152
|
|
|
* @return string |
|
153
|
|
|
*/ |
|
154
|
|
|
public static function getGatewayFullClassPath($gatewayName) |
|
155
|
|
|
{ |
|
156
|
|
|
$gatewayPath = self::getGatewayPath($gatewayName); |
|
157
|
|
|
|
|
158
|
|
|
return $gatewayPath . '/gateway.php'; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Indique si le fichier contenant la classe d'une passerelle de paiement existe |
|
163
|
|
|
* |
|
164
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement (son répertoire) |
|
165
|
|
|
* @return boolean True si le fichier de la classe existe sinon Faux |
|
166
|
|
|
*/ |
|
167
|
|
|
public static function gatewayClassFileExists($gatewayName) |
|
168
|
|
|
{ |
|
169
|
|
|
$gatewayClassPath = self::getGatewayFullClassPath($gatewayName); |
|
170
|
|
|
if (file_exists($gatewayClassPath)) { |
|
171
|
|
|
return true; |
|
172
|
|
|
} else { |
|
173
|
|
|
return false; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Chargement (inclusion) du fichier de la classe de la passerelle de paiement |
|
179
|
|
|
* |
|
180
|
|
|
* @param string $gatewayName |
|
181
|
|
|
*/ |
|
182
|
|
|
public static function includeGatewayClass($gatewayName) |
|
183
|
|
|
{ |
|
184
|
|
|
$gatewayClassPath = self::getGatewayFullClassPath($gatewayName); |
|
185
|
|
|
require_once $gatewayClassPath; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Retourne le nom de la classe attendu pour une passerelle de paiement |
|
190
|
|
|
* |
|
191
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement (son répertoire) |
|
192
|
|
|
* @return string |
|
193
|
|
|
*/ |
|
194
|
|
|
public static function gatewayClassName($gatewayName) |
|
195
|
|
|
{ |
|
196
|
|
|
return 'oledrion_' . $gatewayName; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Indique si la classe de la passerelle de paiement existe |
|
201
|
|
|
* |
|
202
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement (son répertoire) |
|
203
|
|
|
* @return boolean |
|
204
|
|
|
*/ |
|
205
|
|
|
public static function gatewayClassExists($gatewayName) |
|
206
|
|
|
{ |
|
207
|
|
|
$gatewayClassName = self::gatewayClassName($gatewayName); |
|
208
|
|
|
if (class_exists($gatewayClassName)) { |
|
209
|
|
|
return true; |
|
210
|
|
|
} else { |
|
211
|
|
|
return false; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Indique si un objet de type gateway étend bien la classe abstraite |
|
217
|
|
|
* |
|
218
|
|
|
* @param object $gateway L'objet à vérifier |
|
219
|
|
|
* @return boolean |
|
220
|
|
|
*/ |
|
221
|
|
|
public static function asGoodAncestor($gateway) |
|
222
|
|
|
{ |
|
223
|
|
|
if (get_parent_class($gateway) === 'oledrion_gateway') { |
|
224
|
|
|
return true; |
|
225
|
|
|
} else { |
|
226
|
|
|
return false; |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Indique si Le nom de la passerelle de paiement se trouve sur le site |
|
232
|
|
|
* |
|
233
|
|
|
* @param string $gatewayName Le nom de la passerelle de paiement |
|
234
|
|
|
* @return boolean |
|
235
|
|
|
*/ |
|
236
|
|
|
public static function isInstalledGatewayName($gatewayName) |
|
237
|
|
|
{ |
|
238
|
|
|
$installedGateways = self::getInstalledGatewaysList(); |
|
239
|
|
|
if (!in_array($gatewayName, $installedGateways)) { |
|
240
|
|
|
return false; |
|
241
|
|
|
} else { |
|
242
|
|
|
return true; |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Raccourcis pour récupérer l'objet gateway courant |
|
248
|
|
|
* |
|
249
|
|
|
* @param null $gateway |
|
250
|
|
|
* @return mixed Soit l'objet gateway soit null |
|
251
|
|
|
* |
|
252
|
|
|
*/ |
|
253
|
|
|
public static function getGatewayObject($gateway = null) |
|
254
|
|
|
{ |
|
255
|
|
|
$gateway = self::getCurrentGateway($gateway); |
|
256
|
|
|
if (self::isInstalledGatewayName($gateway)) { |
|
257
|
|
|
if (self::gatewayClassFileExists($gateway)) { |
|
258
|
|
|
if (self::loadGatewaysLanguageDefines($gateway)) { |
|
259
|
|
|
self::includeGatewayClass($gateway); |
|
260
|
|
|
if (self::gatewayClassExists($gateway)) { |
|
261
|
|
|
$gatewayClassName = self::gatewayClassName($gateway); |
|
262
|
|
|
$temporaryGateway = new $gatewayClassName(); |
|
263
|
|
|
if (self::asGoodAncestor($temporaryGateway)) { |
|
264
|
|
|
return $temporaryGateway; |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
return null; |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.