-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.php
99 lines (83 loc) · 2.52 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
if (!function_exists('getPathCMS')) {
function getPathCMS(string $filename): string
{
$option = 'Default';
$pathUsed = getcwd();
$pathCMS = dirname(dirname($pathUsed));
if (isset($_SERVER['PWD']) && is_link($_SERVER['PWD'])) {
$option = 'PWD';
$pathUsed = $_SERVER['PWD'];
$pathCMS = dirname(dirname($pathUsed));
} elseif (isset($_SERVER['SCRIPT_FILENAME'])) {
$option = 'File';
$pathUsed = fixPath($_SERVER['SCRIPT_FILENAME']);
$pathCMS = str_replace(
fixPath(sprintf('/modules/%s/%s', getModuleName(), $filename)),
'',
$pathUsed
);
}
if (!file_exists(fixPath($pathCMS . '/config/config.inc.php'))) {
$message = "Miss-configuration in Server [mode: " . php_sapi_name() . "] [{$filename}]" . breakLine();
$message .= "Option [{$option}]" . breakLine();
$message .= "Used [{$pathUsed}]" . breakLine();
$message .= "Path [{$pathCMS}]" . breakLine();
die($message);
}
return $pathCMS;
}
}
if (!function_exists('versionComparePlaceToPay')) {
function versionComparePlaceToPay(string $version, string $operator): bool
{
return version_compare(_PS_VERSION_, $version, $operator);
}
}
if (!function_exists('isDebugEnable')) {
function isDebugEnable(): bool
{
return defined('_PS_MODE_DEV_') && _PS_MODE_DEV_ === true;
}
}
if (!function_exists('isConsole')) {
function isConsole(): bool
{
static $isConsole;
if (is_null($isConsole)) {
$isConsole = \Tools::isPHPCLI();
}
return $isConsole;
}
}
if (!function_exists('breakLine')) {
function breakLine(int $multiplier = 1): string
{
static $breakLine;
if (is_null($breakLine)) {
$breakLine = isConsole() ? PHP_EOL : '<br />';
}
return str_repeat($breakLine, $multiplier);
}
}
if (!function_exists('getModuleName')) {
function getModuleName(): string
{
return 'placetopaypayment';
}
}
if (!function_exists('fixPath')) {
function fixPath(string $path): string
{
// Case:
// IIS: \ (backslash)
// Apache: / (slash)
return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
}
}
if (!function_exists('unmaskString')) {
function unmaskString(string $string): string
{
return str_rot13($string);
}
}