-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListener.php
More file actions
80 lines (71 loc) · 1.88 KB
/
Listener.php
File metadata and controls
80 lines (71 loc) · 1.88 KB
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
<?php
/*
* This file is part of a XenForo add-on.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jrahmy\CountryRegistrationBlock;
/**
* Contains event listener callbacks.
*/
class Listener
{
/**
* @var bool
*/
protected static $countryBlocked = false;
/**
* @param \XF\Pub\App $app
*/
public static function appPubSetup(\XF\Pub\App $app)
{
$visitor = \XF::visitor();
if ($visitor->user_id !== 0) {
return;
}
$options = $app->options();
$blockOptions = $options->jCRB;
$geoIpHeader = $blockOptions['geoIpHeader'];
$disallowedCountries = preg_split(
'/\r?\n/',
$blockOptions['disallowedCountries'],
PREG_SPLIT_NO_EMPTY
);
if (!empty($_SERVER[$geoIpHeader])) {
static::$countryBlocked = in_array(
$_SERVER[$geoIpHeader],
$disallowedCountries
);
}
if (static::$countryBlocked) {
\XF\Pub\App::$allowPageCache = false;
$options->registrationSetup['enabled'] = 0;
}
}
/**
* @param \XF\Pub\App $app
* @param \XF\NoticeList $noticeList
* @param array $pageParams
*/
public static function noticesSetup(
\XF\Pub\App $app,
\XF\NoticeList $noticeList,
array $pageParams
) {
$visitor = \XF::visitor();
if ($visitor->user_id !== 0) {
return;
}
if (static::$countryBlocked) {
$noticeList->addNotice(
'j_crb_blocked',
'block',
$app->templater()->renderTemplate(
'public:j_crb_notice_blocked',
$pageParams
)
);
}
}
}