1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2015-2020 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\controller; |
12
|
|
|
|
13
|
|
|
use phpbb\config\config; |
14
|
|
|
use phpbb\controller\helper; |
15
|
|
|
use phpbb\language\language; |
16
|
|
|
use phpbb\request\request; |
17
|
|
|
use phpbb\template\template; |
18
|
|
|
use phpbb\user; |
19
|
|
|
use phpbb\user_loader; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
21
|
|
|
|
22
|
|
|
class main_controller |
23
|
|
|
{ |
24
|
|
|
protected $config; |
25
|
|
|
protected $container; |
26
|
|
|
protected $helper; |
27
|
|
|
protected $language; |
28
|
|
|
protected $ppde_actions_currency; |
29
|
|
|
protected $request; |
30
|
|
|
protected $template; |
31
|
|
|
protected $user; |
32
|
|
|
protected $user_loader; |
33
|
|
|
protected $root_path; |
34
|
|
|
protected $php_ext; |
35
|
|
|
|
36
|
|
|
public $ppde_actions_auth; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructor |
40
|
|
|
* |
41
|
|
|
* @param config $config Config object |
42
|
|
|
* @param ContainerInterface $container Service container interface |
43
|
|
|
* @param helper $helper Controller helper object |
44
|
|
|
* @param language $language Language user object |
45
|
|
|
* @param \skouat\ppde\actions\auth $ppde_actions_auth PPDE auth actions object |
46
|
|
|
* @param \skouat\ppde\actions\currency $ppde_actions_currency PPDE currency actions object |
47
|
|
|
* @param request $request Request object |
48
|
|
|
* @param template $template Template object |
49
|
|
|
* @param user $user User object |
50
|
|
|
* @param \phpbb\user_loader $user_loader User loader object |
51
|
|
|
* @param string $root_path phpBB root path |
52
|
|
|
* @param string $php_ext phpEx |
53
|
|
|
* |
54
|
|
|
* @access public |
55
|
|
|
*/ |
56
|
|
|
public function __construct( |
57
|
|
|
config $config, |
58
|
|
|
ContainerInterface $container, |
59
|
|
|
helper $helper, |
60
|
|
|
language $language, |
61
|
|
|
\skouat\ppde\actions\auth $ppde_actions_auth, |
62
|
|
|
\skouat\ppde\actions\currency $ppde_actions_currency, |
63
|
|
|
request $request, |
64
|
|
|
template $template, |
65
|
|
|
user $user, |
66
|
|
|
user_loader $user_loader, |
67
|
|
|
$root_path, |
68
|
|
|
$php_ext |
69
|
|
|
) |
70
|
|
|
{ |
71
|
|
|
$this->config = $config; |
72
|
|
|
$this->container = $container; |
73
|
|
|
$this->helper = $helper; |
74
|
|
|
$this->language = $language; |
75
|
|
|
$this->ppde_actions_auth = $ppde_actions_auth; |
76
|
|
|
$this->ppde_actions_currency = $ppde_actions_currency; |
77
|
|
|
$this->request = $request; |
78
|
|
|
$this->template = $template; |
79
|
|
|
$this->user = $user; |
80
|
|
|
$this->user_loader = $user_loader; |
81
|
|
|
$this->root_path = $root_path; |
82
|
|
|
$this->php_ext = $php_ext; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function handle() |
86
|
|
|
{ |
87
|
|
|
// We stop the execution of the code because nothing need to be returned to phpBB. |
88
|
|
|
garbage_collection(); |
89
|
|
|
exit_handler(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return bool |
94
|
|
|
* @access private |
95
|
|
|
*/ |
96
|
|
|
public function donorlist_is_enabled() |
97
|
|
|
{ |
98
|
|
|
return $this->use_ipn() && $this->config['ppde_ipn_donorlist_enable']; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Check if IPN is enabled based on config value |
103
|
|
|
* |
104
|
|
|
* @return bool |
105
|
|
|
* @access public |
106
|
|
|
*/ |
107
|
|
|
public function use_ipn() |
108
|
|
|
{ |
109
|
|
|
return !empty($this->config['ppde_enable']) && !empty($this->config['ppde_ipn_enable']) && $this->is_ipn_requirement_satisfied(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Check if IPN requirements are satisfied based on config value |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
* @access public |
117
|
|
|
*/ |
118
|
|
|
public function is_ipn_requirement_satisfied() |
119
|
|
|
{ |
120
|
|
|
return !empty($this->config['ppde_curl_detected']) && !empty($this->config['ppde_tls_detected']); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get PayPal URI |
125
|
|
|
* Used in form and in IPN process |
126
|
|
|
* |
127
|
|
|
* @param bool $is_test_ipn |
128
|
|
|
* |
129
|
|
|
* @return string |
130
|
|
|
* @access public |
131
|
|
|
*/ |
132
|
|
|
public function get_paypal_uri($is_test_ipn = false) |
133
|
|
|
{ |
134
|
|
|
$remote_list = ipn_paypal::get_remote_uri(); |
135
|
|
|
|
136
|
|
|
if (($is_test_ipn || $this->use_sandbox())) |
137
|
|
|
{ |
138
|
|
|
return $remote_list[$this->config['ppde_sandbox_remote']]['uri']; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $remote_list[$this->config['ppde_default_remote']]['uri']; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Check if Sandbox is enabled based on config value |
146
|
|
|
* |
147
|
|
|
* @return bool |
148
|
|
|
* @access public |
149
|
|
|
*/ |
150
|
|
|
public function use_sandbox() |
151
|
|
|
{ |
152
|
|
|
return $this->use_ipn() && !empty($this->config['ppde_sandbox_enable']) && $this->is_sandbox_founder_enable(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Check if Sandbox could be use by founders based on config value |
157
|
|
|
* |
158
|
|
|
* @return bool |
159
|
|
|
* @access public |
160
|
|
|
*/ |
161
|
|
|
public function is_sandbox_founder_enable() |
162
|
|
|
{ |
163
|
|
|
return (!empty($this->config['ppde_sandbox_founder_enable']) && ($this->user->data['user_type'] == USER_FOUNDER)) || empty($this->config['ppde_sandbox_founder_enable']); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|