1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2015 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\controller; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
14
|
|
|
|
15
|
|
|
class main_controller |
16
|
|
|
{ |
17
|
|
|
protected $auth; |
18
|
|
|
protected $config; |
19
|
|
|
protected $container; |
20
|
|
|
protected $extension_manager; |
21
|
|
|
protected $helper; |
22
|
|
|
protected $ppde_entity_currency; |
23
|
|
|
protected $ppde_entity_donation_pages; |
24
|
|
|
protected $ppde_entity_transactions; |
25
|
|
|
protected $ppde_operator_currency; |
26
|
|
|
protected $ppde_operator_donation_pages; |
27
|
|
|
protected $ppde_operator_transactions; |
28
|
|
|
protected $request; |
29
|
|
|
protected $template; |
30
|
|
|
protected $user; |
31
|
|
|
protected $root_path; |
32
|
|
|
protected $php_ext; |
33
|
|
|
/** @var array */ |
34
|
|
|
protected $ext_meta = array(); |
35
|
|
|
/** @var string */ |
36
|
|
|
protected $ext_name; |
37
|
|
|
/** @var string */ |
38
|
|
|
private $donation_body; |
39
|
|
|
/** @var array */ |
40
|
|
|
private $donation_content_data; |
41
|
|
|
/** @var string */ |
42
|
|
|
private $return_args_url; |
43
|
|
|
/** @var string */ |
44
|
|
|
private $u_action; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor |
48
|
|
|
* |
49
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
50
|
|
|
* @param \phpbb\config\config $config Config object |
51
|
|
|
* @param ContainerInterface $container Service container interface |
52
|
|
|
* @param \phpbb\extension\manager $extension_manager An instance of the phpBB extension |
53
|
|
|
* manager |
54
|
|
|
* @param \phpbb\controller\helper $helper Controller helper object |
55
|
|
|
* @param \skouat\ppde\entity\currency $ppde_entity_currency Currency entity object |
56
|
|
|
* @param \skouat\ppde\entity\donation_pages $ppde_entity_donation_pages Donation pages entity object |
57
|
|
|
* @param \skouat\ppde\entity\transactions $ppde_entity_transactions Transactions log entity object |
58
|
|
|
* @param \skouat\ppde\operators\currency $ppde_operator_currency Currency operator object |
59
|
|
|
* @param \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages Donation pages operator object |
60
|
|
|
* @param \skouat\ppde\operators\transactions $ppde_operator_transactions Transactions log operator object |
61
|
|
|
* @param \phpbb\request\request $request Request object |
62
|
|
|
* @param \phpbb\template\template $template Template object |
63
|
|
|
* @param \phpbb\user $user User object |
64
|
|
|
* @param string $root_path phpBB root path |
65
|
|
|
* @param string $php_ext phpEx |
66
|
|
|
* |
67
|
|
|
* @return \skouat\ppde\controller\main_controller |
68
|
|
|
* @access public |
69
|
|
|
*/ |
70
|
|
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, ContainerInterface $container, \phpbb\extension\manager $extension_manager, \phpbb\controller\helper $helper, \skouat\ppde\entity\currency $ppde_entity_currency, \skouat\ppde\entity\donation_pages $ppde_entity_donation_pages, \skouat\ppde\entity\transactions $ppde_entity_transactions, \skouat\ppde\operators\currency $ppde_operator_currency, \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages, \skouat\ppde\operators\transactions $ppde_operator_transactions, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $root_path, $php_ext) |
71
|
|
|
{ |
72
|
|
|
$this->auth = $auth; |
73
|
|
|
$this->config = $config; |
74
|
|
|
$this->container = $container; |
75
|
|
|
$this->extension_manager = $extension_manager; |
76
|
|
|
$this->helper = $helper; |
77
|
|
|
$this->ppde_entity_currency = $ppde_entity_currency; |
78
|
|
|
$this->ppde_entity_donation_pages = $ppde_entity_donation_pages; |
79
|
|
|
$this->ppde_entity_transactions = $ppde_entity_transactions; |
80
|
|
|
$this->ppde_operator_currency = $ppde_operator_currency; |
81
|
|
|
$this->ppde_operator_donation_pages = $ppde_operator_donation_pages; |
82
|
|
|
$this->ppde_operator_transactions = $ppde_operator_transactions; |
83
|
|
|
$this->request = $request; |
84
|
|
|
$this->template = $template; |
85
|
|
|
$this->user = $user; |
86
|
|
|
$this->root_path = $root_path; |
87
|
|
|
$this->php_ext = $php_ext; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function handle() |
91
|
|
|
{ |
92
|
|
|
// When this extension is disabled, redirect users back to the forum index |
93
|
|
|
// Else if user is not allowed to use it, disallow access to the extension main page |
94
|
|
|
if (empty($this->config['ppde_enable'])) |
95
|
|
|
{ |
96
|
|
|
redirect(append_sid("{$this->root_path}index.{$this->php_ext}")); |
97
|
|
|
} |
98
|
|
|
else if (!$this->can_use_ppde()) |
99
|
|
|
{ |
100
|
|
|
trigger_error('NOT_AUTHORISED'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$entity = $this->container->get('skouat.ppde.entity.donation_pages'); |
104
|
|
|
$this->set_return_args_url($this->request->variable('return', 'body')); |
105
|
|
|
|
106
|
|
|
// Prepare message for display |
107
|
|
|
if ($this->get_donation_content_data($this->return_args_url)) |
108
|
|
|
{ |
109
|
|
|
$entity->get_vars(); |
110
|
|
|
$this->donation_body = $entity->replace_template_vars($entity->get_message_for_display( |
111
|
|
|
$this->donation_content_data[0]['page_content'], |
112
|
|
|
$this->donation_content_data[0]['page_content_bbcode_uid'], |
113
|
|
|
$this->donation_content_data[0]['page_content_bbcode_bitfield'], |
114
|
|
|
$this->donation_content_data[0]['page_content_bbcode_options'] |
115
|
|
|
)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->template->assign_vars(array( |
119
|
|
|
'DEFAULT_CURRENCY' => $this->build_currency_select_menu($this->config['ppde_default_currency']), |
120
|
|
|
'DONATION_BODY' => $this->donation_body, |
121
|
|
|
'IMG_LOADER' => '<img src="' . $this->root_path . '../ext/skouat/ppde/images/loader.gif' . '" />', |
122
|
|
|
'PPDE_DEFAULT_VALUE' => $this->config['ppde_default_value'] ? $this->config['ppde_default_value'] : 0, |
123
|
|
|
'PPDE_LIST_VALUE' => $this->build_currency_value_select_menu(), |
124
|
|
|
|
125
|
|
|
'S_HIDDEN_FIELDS' => $this->paypal_hidden_fields(), |
126
|
|
|
'S_PPDE_FORM_ACTION' => $this->get_paypal_url(), |
127
|
|
|
'S_RETURN_ARGS' => $this->return_args_url, |
128
|
|
|
'S_SANDBOX' => $this->use_sandbox(), |
129
|
|
|
)); |
130
|
|
|
|
131
|
|
|
$this->display_stats(); |
132
|
|
|
|
133
|
|
|
// Send all data to the template file |
134
|
|
|
return $this->send_data_to_template(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function donorlist_handle() |
138
|
|
|
{ |
139
|
|
|
// When this extension is disabled, redirect users back to the forum index |
140
|
|
|
// Else if user is not allowed to use it, disallow access to the extension main page |
141
|
|
|
if (!$this->use_ipn()) |
142
|
|
|
{ |
143
|
|
|
redirect(append_sid("{$this->root_path}index.{$this->php_ext}")); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
else if (!$this->can_view_ppde_donorlist()) |
146
|
|
|
{ |
147
|
|
|
trigger_error('NOT_AUTHORISED'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
// Get needed container |
151
|
|
|
/** @type \phpbb\pagination $pagination */ |
152
|
|
|
$pagination = $this->container->get('pagination'); |
153
|
|
|
/** @type \phpbb\path_helper $path_helper */ |
154
|
|
|
$path_helper = $this->container->get('path_helper'); |
155
|
|
|
|
156
|
|
|
// Set up general vars |
157
|
|
|
$default_key = 'd'; |
158
|
|
|
$start = $this->request->variable('start', 0); |
159
|
|
|
|
160
|
|
|
// Build a relevant pagination_url |
161
|
|
|
$params = array(); |
162
|
|
|
|
163
|
|
|
// We do not use request_var() here directly to save some calls (not all variables are set) |
164
|
|
|
$check_params = array( |
165
|
|
|
'sk' => array('sk', $default_key), |
166
|
|
|
'sd' => array('sd', 'a'), |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
foreach ($check_params as $key => $call) |
170
|
|
|
{ |
171
|
|
|
if (!isset($_REQUEST[$key])) |
172
|
|
|
{ |
173
|
|
|
continue; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$param = call_user_func_array('request_var', $call); |
177
|
|
|
$param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param); |
178
|
|
|
$params[] = $param; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
// Set '$this->u_action' |
182
|
|
|
$use_page = ($this->u_action) ? $this->u_action : $this->user->page['page_name']; |
183
|
|
|
$this->u_action = reapply_sid($path_helper->get_valid_page($use_page, $this->config['enable_mod_rewrite'])); |
184
|
|
|
|
185
|
|
|
$get_donorlist_sql_ary = $this->ppde_operator_transactions->get_sql_donorlist_ary(); |
186
|
|
|
$count = $this->ppde_operator_transactions->query_sql_count($get_donorlist_sql_ary, 'txn.user_id'); |
187
|
|
|
$start = $pagination->validate_start($start, $this->config['topics_per_page'], $count); |
188
|
|
|
|
189
|
|
|
$pagination_url = $this->u_action . implode('&', $params); |
190
|
|
|
$pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $count, $this->config['topics_per_page'], $start); |
191
|
|
|
|
192
|
|
|
// adds fields to the table schema needed by entity->import() |
193
|
|
|
$additional_table_schema = array( |
194
|
|
|
'item_username' => array('name' => 'username', 'type' => 'string'), |
195
|
|
|
'item_user_colour' => array('name' => 'user_colour', 'type' => 'string'), |
196
|
|
|
'item_amount' => array('name' => 'amount', 'type' => 'string'), |
197
|
|
|
'item_max_txn_id' => array('name' => 'max_txn_id', 'type' => 'integer'), |
198
|
|
|
); |
199
|
|
|
|
200
|
|
|
$data_ary = $this->ppde_entity_transactions->get_data($this->ppde_operator_transactions->build_sql_donorlist_data($get_donorlist_sql_ary), $additional_table_schema, $this->config['topics_per_page'], $start); |
201
|
|
|
|
202
|
|
|
// Get default currency data from the database |
203
|
|
|
$default_currency_data = $this->get_default_currency_data($this->config['ppde_default_currency']); |
204
|
|
|
|
205
|
|
|
foreach ($data_ary as $data) |
206
|
|
|
{ |
207
|
|
|
$get_last_transaction_sql_ary = $this->ppde_operator_transactions->get_sql_donorlist_ary($data['max_txn_id']); |
208
|
|
|
$last_donation_data = $this->ppde_entity_transactions->get_data($this->ppde_operator_transactions->build_sql_donorlist_data($get_last_transaction_sql_ary)); |
209
|
|
|
$this->template->assign_block_vars('donorrow', array( |
210
|
|
|
'PPDE_DONOR_USERNAME' => get_username_string('full', $data['user_id'], $data['username'], $data['user_colour']), |
211
|
|
|
'PPDE_LAST_DONATED_AMOUNT' => $this->get_amount($data['amount'], $default_currency_data[0]['currency_symbol'], (bool) $default_currency_data[0]['currency_on_left']), |
212
|
|
|
'PPDE_LAST_PAYMENT_DATE' => $this->user->format_date($last_donation_data[0]['payment_date']), |
213
|
|
|
'PPDE_TOTAL_DONATED_AMOUNT' => $this->get_amount($last_donation_data[0]['mc_gross'], $default_currency_data[0]['currency_symbol'], (bool) $default_currency_data[0]['currency_on_left']), |
214
|
|
|
)); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// Set "return_args_url" object before sending data to template |
218
|
|
|
$this->set_return_args_url('donorlist'); |
219
|
|
|
|
220
|
|
|
// Send all data to the template file |
221
|
|
|
return $this->send_data_to_template(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return bool |
226
|
|
|
* @access public |
227
|
|
|
*/ |
228
|
|
|
public function can_use_ppde() |
229
|
|
|
{ |
230
|
|
|
return $this->auth->acl_get('u_ppde_use'); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return bool |
235
|
|
|
* @access public |
236
|
|
|
*/ |
237
|
|
|
public function can_view_ppde_donorlist() |
238
|
|
|
{ |
239
|
|
|
return $this->auth->acl_get('u_ppde_view_donorlist'); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param string $set_return_args_url |
244
|
|
|
* |
245
|
|
|
* @return null |
246
|
|
|
* @access private |
247
|
|
|
*/ |
248
|
|
|
private function set_return_args_url($set_return_args_url) |
249
|
|
|
{ |
250
|
|
|
switch ($set_return_args_url) |
251
|
|
|
{ |
252
|
|
|
case 'cancel': |
253
|
|
|
case 'success': |
254
|
|
|
$this->template->assign_vars(array( |
255
|
|
|
'L_PPDE_DONATION_TITLE' => $this->user->lang['PPDE_' . strtoupper($set_return_args_url) . '_TITLE'], |
256
|
|
|
)); |
257
|
|
|
$this->return_args_url = $set_return_args_url; |
258
|
|
|
break; |
259
|
|
|
case 'donorlist': |
260
|
|
|
$this->template->assign_vars(array( |
261
|
|
|
'L_PPDE_DONORLIST_TITLE' => $this->user->lang['PPDE_DONORLIST_TITLE'], |
262
|
|
|
)); |
263
|
|
|
$this->return_args_url = $set_return_args_url; |
264
|
|
|
break; |
265
|
|
|
default: |
266
|
|
|
$this->return_args_url = 'body'; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Get content of current donation pages |
273
|
|
|
* |
274
|
|
|
* @param string $return_args_url |
275
|
|
|
* |
276
|
|
|
* @return array |
277
|
|
|
* @access private |
278
|
|
|
*/ |
279
|
|
|
private function get_donation_content_data($return_args_url) |
280
|
|
|
{ |
281
|
|
|
return $this->donation_content_data = |
282
|
|
|
$this->ppde_entity_donation_pages->get_data( |
283
|
|
|
$this->ppde_operator_donation_pages->build_sql_data($this->user->get_iso_lang_id(), $return_args_url)); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Build pull down menu options of available currency |
288
|
|
|
* |
289
|
|
|
* @param int $config_value Currency identifier; default: 0 |
290
|
|
|
* |
291
|
|
|
* @return null |
292
|
|
|
* @access public |
293
|
|
|
*/ |
294
|
|
|
public function build_currency_select_menu($config_value = 0) |
295
|
|
|
{ |
296
|
|
|
// Grab the list of all enabled currencies; 0 is for all data |
297
|
|
|
$currency_items = $this->ppde_entity_currency->get_data($this->ppde_operator_currency->build_sql_data(0, true)); |
298
|
|
|
|
299
|
|
|
// Process each rule menu item for pull-down |
300
|
|
|
foreach ($currency_items as $currency_item) |
301
|
|
|
{ |
302
|
|
|
// Set output block vars for display in the template |
303
|
|
|
$this->template->assign_block_vars('options', array( |
304
|
|
|
'CURRENCY_ID' => (int) $currency_item['currency_id'], |
305
|
|
|
'CURRENCY_ISO_CODE' => $currency_item['currency_iso_code'], |
306
|
|
|
'CURRENCY_NAME' => $currency_item['currency_name'], |
307
|
|
|
'CURRENCY_SYMBOL' => $currency_item['currency_symbol'], |
308
|
|
|
|
309
|
|
|
'S_CURRENCY_DEFAULT' => $config_value == $currency_item['currency_id'], |
310
|
|
|
)); |
311
|
|
|
} |
312
|
|
|
unset ($currency_items, $currency_item); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Build pull down menu options of available currency value |
317
|
|
|
* |
318
|
|
|
* @return string List of currency value set in ACP for dropdown menu |
319
|
|
|
* @access private |
320
|
|
|
*/ |
321
|
|
|
private function build_currency_value_select_menu() |
322
|
|
|
{ |
323
|
|
|
$list_donation_value = ''; |
324
|
|
|
|
325
|
|
|
if ($this->get_dropbox_status()) |
326
|
|
|
{ |
327
|
|
|
$donation_ary_value = explode(',', $this->config['ppde_dropbox_value']); |
328
|
|
|
|
329
|
|
|
foreach ($donation_ary_value as $value) |
330
|
|
|
{ |
331
|
|
|
$int_value = $this->settype_dropbox_int_value($value); |
332
|
|
|
$list_donation_value .= !empty($int_value) ? '<option value="' . $int_value . '">' . $int_value . '</option>' : ''; |
333
|
|
|
} |
334
|
|
|
unset($value); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
return $list_donation_value; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Get dropbox config value |
342
|
|
|
* |
343
|
|
|
* @return bool |
344
|
|
|
* @access private |
345
|
|
|
*/ |
346
|
|
|
private function get_dropbox_status() |
347
|
|
|
{ |
348
|
|
|
return $this->config['ppde_dropbox_enable'] && $this->config['ppde_dropbox_value']; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Force dropbox value to integer |
353
|
|
|
* |
354
|
|
|
* @param int $value |
355
|
|
|
* |
356
|
|
|
* @return int |
357
|
|
|
*/ |
358
|
|
|
private function settype_dropbox_int_value($value = 0) |
359
|
|
|
{ |
360
|
|
|
if (settype($value, 'integer') && $value != 0) |
361
|
|
|
{ |
362
|
|
|
return $value; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
return 0; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Build PayPal hidden fields |
370
|
|
|
* |
371
|
|
|
* @return string PayPal hidden field needed to fill PayPal forms |
372
|
|
|
* @access private |
373
|
|
|
*/ |
374
|
|
|
private function paypal_hidden_fields() |
375
|
|
|
{ |
376
|
|
|
return build_hidden_fields(array( |
377
|
|
|
'cmd' => '_donations', |
378
|
|
|
'business' => $this->get_account_id(), |
379
|
|
|
'item_name' => $this->user->lang['PPDE_DONATION_TITLE_HEAD'] . ' ' . $this->config['sitename'], |
380
|
|
|
'no_shipping' => 1, |
381
|
|
|
'return' => $this->generate_paypal_return_url('success'), |
382
|
|
|
'notify_url' => $this->generate_paypal_notify_return_url(), |
383
|
|
|
'cancel_return' => $this->generate_paypal_return_url('cancel'), |
384
|
|
|
'item_number' => 'uid_' . $this->user->data['user_id'] . '_' . time(), |
385
|
|
|
'tax' => 0, |
386
|
|
|
'bn' => 'Board_Donate_WPS', |
387
|
|
|
'charset' => 'utf-8', |
388
|
|
|
)); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Get PayPal account id |
393
|
|
|
* |
394
|
|
|
* @return string $this Paypal account Identifier |
395
|
|
|
* @access private |
396
|
|
|
*/ |
397
|
|
|
private function get_account_id() |
398
|
|
|
{ |
399
|
|
|
return $this->use_sandbox() ? $this->config['ppde_sandbox_address'] : $this->config['ppde_account_id']; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Check if Sandbox is enabled |
404
|
|
|
* |
405
|
|
|
* @return bool |
406
|
|
|
* @access public |
407
|
|
|
*/ |
408
|
|
|
public function use_sandbox() |
409
|
|
|
{ |
410
|
|
|
return !empty($this->config['ppde_sandbox_enable']) && (!empty($this->config['ppde_sandbox_founder_enable']) && ($this->user->data['user_type'] == USER_FOUNDER) || empty($this->config['ppde_sandbox_founder_enable'])); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Check if IPN is enabled |
415
|
|
|
* |
416
|
|
|
* @return bool |
417
|
|
|
* @access public |
418
|
|
|
*/ |
419
|
|
|
public function use_ipn() |
420
|
|
|
{ |
421
|
|
|
return !empty($this->config['ppde_enable']) && !empty($this->config['ppde_ipn_enable']) && (!empty($this->config['ppde_curl_detected']) || !empty($this->config['ppde_fsockopen_detected'])); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Generate PayPal return URL |
426
|
|
|
* |
427
|
|
|
* @param string $arg |
428
|
|
|
* |
429
|
|
|
* @return string |
430
|
|
|
* @access private |
431
|
|
|
*/ |
432
|
|
|
private function generate_paypal_return_url($arg) |
433
|
|
|
{ |
434
|
|
|
return generate_board_url(true) . $this->helper->route('skouat_ppde_donate', array('return' => $arg)); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Generate PayPal return notify URL |
439
|
|
|
* |
440
|
|
|
* @return string |
441
|
|
|
* @access private |
442
|
|
|
*/ |
443
|
|
|
private function generate_paypal_notify_return_url() |
444
|
|
|
{ |
445
|
|
|
return generate_board_url(true) . $this->helper->route('skouat_ppde_ipn_listener'); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Get PayPal URL |
450
|
|
|
* Used in form and in IPN process |
451
|
|
|
* |
452
|
|
|
* @param bool $is_test_ipn |
453
|
|
|
* |
454
|
|
|
* @return string |
455
|
|
|
* @access public |
456
|
|
|
*/ |
457
|
|
|
public function get_paypal_url($is_test_ipn = false) |
458
|
|
|
{ |
459
|
|
|
return ($is_test_ipn || $this->use_sandbox()) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* Assign statistics vars to the template |
464
|
|
|
* |
465
|
|
|
* @return null |
466
|
|
|
* @access public |
467
|
|
|
*/ |
468
|
|
|
public function display_stats() |
469
|
|
|
{ |
470
|
|
|
if ($this->config['ppde_goal_enable'] || $this->config['ppde_raised_enable'] || $this->config['ppde_used_enable']) |
471
|
|
|
{ |
472
|
|
|
// Get data from the database |
473
|
|
|
$default_currency_data = $this->get_default_currency_data($this->config['ppde_default_currency']); |
474
|
|
|
|
475
|
|
|
$this->template->assign_vars(array( |
476
|
|
|
'PPDE_GOAL_ENABLE' => $this->config['ppde_goal_enable'], |
477
|
|
|
'PPDE_RAISED_ENABLE' => $this->config['ppde_raised_enable'], |
478
|
|
|
'PPDE_USED_ENABLE' => $this->config['ppde_used_enable'], |
479
|
|
|
|
480
|
|
|
'L_PPDE_GOAL' => $this->get_ppde_goal_langkey($default_currency_data[0]['currency_symbol'], (bool) $default_currency_data[0]['currency_on_left']), |
481
|
|
|
'L_PPDE_RAISED' => $this->get_ppde_raised_langkey($default_currency_data[0]['currency_symbol'], (bool) $default_currency_data[0]['currency_on_left']), |
482
|
|
|
'L_PPDE_USED' => $this->get_ppde_used_langkey($default_currency_data[0]['currency_symbol'], (bool) $default_currency_data[0]['currency_on_left']), |
483
|
|
|
)); |
484
|
|
|
|
485
|
|
|
// Generate statistics percent for display |
486
|
|
|
$this->generate_stats_percent(); |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Get default currency symbol |
492
|
|
|
* |
493
|
|
|
* @param int $id |
494
|
|
|
* |
495
|
|
|
* @return array |
496
|
|
|
* @access public |
497
|
|
|
*/ |
498
|
|
|
public function get_default_currency_data($id = 0) |
499
|
|
|
{ |
500
|
|
|
return $this->ppde_entity_currency->get_data($this->ppde_operator_currency->build_sql_data($id, true)); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Retrieve the language key for donation goal |
505
|
|
|
* |
506
|
|
|
* @param string $currency_symbol Currency symbol |
507
|
|
|
* @param bool $on_left Symbol position |
508
|
|
|
* |
509
|
|
|
* @return string |
510
|
|
|
* @access public |
511
|
|
|
*/ |
512
|
|
|
public function get_ppde_goal_langkey($currency_symbol, $on_left = true) |
513
|
|
|
{ |
514
|
|
|
if ((int) $this->config['ppde_goal'] <= 0) |
515
|
|
|
{ |
516
|
|
|
$l_ppde_goal = $this->user->lang['DONATE_NO_GOAL']; |
517
|
|
|
} |
518
|
|
View Code Duplication |
else if ((int) $this->config['ppde_goal'] < (int) $this->config['ppde_raised']) |
519
|
|
|
{ |
520
|
|
|
$l_ppde_goal = $this->user->lang['DONATE_GOAL_REACHED']; |
521
|
|
|
} |
522
|
|
|
else |
523
|
|
|
{ |
524
|
|
|
$l_ppde_goal = $this->user->lang('DONATE_GOAL_RAISE', $this->get_amount((int) $this->config['ppde_goal'], $currency_symbol, $on_left)); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
return $l_ppde_goal; |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
/** |
531
|
|
|
* Put the currency on the left or on the right of the amount |
532
|
|
|
* |
533
|
|
|
* @param int $value |
534
|
|
|
* @param string $currency |
535
|
|
|
* @param bool $on_left |
536
|
|
|
* |
537
|
|
|
* @return string |
538
|
|
|
*/ |
539
|
|
|
private function get_amount($value, $currency, $on_left = true) |
540
|
|
|
{ |
541
|
|
|
return $on_left ? $currency . $value : $value . $currency; |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* Retrieve the language key for donation raised |
546
|
|
|
* |
547
|
|
|
* @param string $currency_symbol Currency symbol |
548
|
|
|
* @param bool $on_left Symbol position |
549
|
|
|
* |
550
|
|
|
* @return string |
551
|
|
|
* @access public |
552
|
|
|
*/ |
553
|
|
|
public function get_ppde_raised_langkey($currency_symbol, $on_left = true) |
554
|
|
|
{ |
555
|
|
View Code Duplication |
if ((int) $this->config['ppde_raised'] <= 0) |
556
|
|
|
{ |
557
|
|
|
$l_ppde_raised = $this->user->lang['DONATE_NOT_RECEIVED']; |
558
|
|
|
} |
559
|
|
|
else |
560
|
|
|
{ |
561
|
|
|
$l_ppde_raised = $this->user->lang('DONATE_RECEIVED', $this->get_amount((int) $this->config['ppde_raised'], $currency_symbol, $on_left)); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
return $l_ppde_raised; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Retrieve the language key for donation used |
569
|
|
|
* |
570
|
|
|
* @param string $currency_symbol Currency symbol |
571
|
|
|
* @param bool $on_left Symbol position |
572
|
|
|
* |
573
|
|
|
* @return string |
574
|
|
|
* @access public |
575
|
|
|
*/ |
576
|
|
|
public function get_ppde_used_langkey($currency_symbol, $on_left = true) |
577
|
|
|
{ |
578
|
|
|
if ((int) $this->config['ppde_used'] <= 0) |
579
|
|
|
{ |
580
|
|
|
$l_ppde_used = $this->user->lang['DONATE_NOT_USED']; |
581
|
|
|
} |
582
|
|
|
else if ((int) $this->config['ppde_used'] < (int) $this->config['ppde_raised']) |
583
|
|
|
{ |
584
|
|
|
$l_ppde_used = $this->user->lang('DONATE_USED', $this->get_amount((int) $this->config['ppde_used'], $currency_symbol, $on_left), $this->get_amount((int) $this->config['ppde_raised'], $currency_symbol, $on_left)); |
585
|
|
|
} |
586
|
|
|
else |
587
|
|
|
{ |
588
|
|
|
$l_ppde_used = $this->user->lang('DONATE_USED_EXCEEDED', $this->get_amount((int) $this->config['ppde_used'], $currency_symbol, $on_left)); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
return $l_ppde_used; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* Generate statistics percent for display |
596
|
|
|
* |
597
|
|
|
* @return null |
598
|
|
|
* @access private |
599
|
|
|
*/ |
600
|
|
|
private function generate_stats_percent() |
601
|
|
|
{ |
602
|
|
|
if ($this->config['ppde_goal_enable'] && (int) $this->config['ppde_goal'] > 0) |
603
|
|
|
{ |
604
|
|
|
$this->assign_vars_stats_percent((int) $this->config['ppde_raised'], (int) $this->config['ppde_goal'], 'GOAL_NUMBER'); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
if ($this->config['ppde_used_enable'] && (int) $this->config['ppde_raised'] > 0 && (int) $this->config['ppde_used'] > 0) |
608
|
|
|
{ |
609
|
|
|
$this->assign_vars_stats_percent((int) $this->config['ppde_used'], (int) $this->config['ppde_raised'], 'USED_NUMBER'); |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Assign statistics percent vars to template |
615
|
|
|
* |
616
|
|
|
* @param integer $multiplicand |
617
|
|
|
* @param integer $dividend |
618
|
|
|
* @param string $type |
619
|
|
|
* |
620
|
|
|
* @return null |
621
|
|
|
* @access public |
622
|
|
|
*/ |
623
|
|
|
private function assign_vars_stats_percent($multiplicand, $dividend, $type = '') |
624
|
|
|
{ |
625
|
|
|
$this->template->assign_vars(array( |
626
|
|
|
'PPDE_' . $type => round(($multiplicand * 100) / $dividend, 2), |
627
|
|
|
'S_' . $type => !empty($type) ? true : false, |
628
|
|
|
)); |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
/** |
632
|
|
|
* Send data to the template file |
633
|
|
|
* |
634
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
635
|
|
|
* @access private |
636
|
|
|
*/ |
637
|
|
|
private function send_data_to_template() |
638
|
|
|
{ |
639
|
|
|
switch ($this->return_args_url) |
640
|
|
|
{ |
641
|
|
|
case 'cancel': |
642
|
|
|
case 'success': |
643
|
|
|
return $this->helper->render('donate_body.html', $this->user->lang('PPDE_' . strtoupper($this->return_args_url) . '_TITLE')); |
644
|
|
|
case 'donorlist': |
645
|
|
|
return $this->helper->render('donorlist_body.html', $this->user->lang('PPDE_DONORLIST_TITLE')); |
646
|
|
|
default: |
647
|
|
|
return $this->helper->render('donate_body.html', $this->user->lang('PPDE_DONATION_TITLE')); |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* Check if cURL is available |
653
|
|
|
* |
654
|
|
|
* @return bool |
655
|
|
|
* @access public |
656
|
|
|
*/ |
657
|
|
|
public function check_curl() |
658
|
|
|
{ |
659
|
|
|
if (function_exists('curl_init') && function_exists('curl_exec')) |
660
|
|
|
{ |
661
|
|
|
$this->get_ext_meta(); |
662
|
|
|
|
663
|
|
|
$ch = curl_init($this->ext_meta['extra']['version-check']['host']); |
664
|
|
|
|
665
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
666
|
|
|
|
667
|
|
|
$response = curl_exec($ch); |
668
|
|
|
$response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE)); |
669
|
|
|
|
670
|
|
|
curl_close($ch); |
671
|
|
|
|
672
|
|
|
return ($response !== false || $response_status !== '0') ? true : false; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
return false; |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* Get extension metadata |
680
|
|
|
* |
681
|
|
|
* @return null |
682
|
|
|
* @access protected |
683
|
|
|
*/ |
684
|
|
|
protected function get_ext_meta() |
685
|
|
|
{ |
686
|
|
|
if (empty($this->ext_meta)) |
687
|
|
|
{ |
688
|
|
|
$this->load_metadata(); |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* Load metadata for this extension |
694
|
|
|
* |
695
|
|
|
* @return array |
696
|
|
|
* @access public |
697
|
|
|
*/ |
698
|
|
|
public function load_metadata() |
699
|
|
|
{ |
700
|
|
|
// Retrieve the extension name based on the namespace of this file |
701
|
|
|
$this->retrieve_ext_name(); |
702
|
|
|
|
703
|
|
|
// If they've specified an extension, let's load the metadata manager and validate it. |
704
|
|
|
if ($this->ext_name) |
705
|
|
|
{ |
706
|
|
|
$md_manager = new \phpbb\extension\metadata_manager($this->ext_name, $this->config, $this->extension_manager, $this->template, $this->user, $this->root_path); |
707
|
|
|
|
708
|
|
|
try |
709
|
|
|
{ |
710
|
|
|
$this->ext_meta = $md_manager->get_metadata('all'); |
711
|
|
|
} |
712
|
|
|
catch (\phpbb\extension\exception $e) |
713
|
|
|
{ |
714
|
|
|
trigger_error($e, E_USER_WARNING); |
715
|
|
|
} |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
return $this->ext_meta; |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* Retrieve the extension name |
723
|
|
|
* |
724
|
|
|
* @return null |
725
|
|
|
* @access protected |
726
|
|
|
*/ |
727
|
|
|
protected function retrieve_ext_name() |
728
|
|
|
{ |
729
|
|
|
$namespace_ary = explode('\\', __NAMESPACE__); |
730
|
|
|
$this->ext_name = $namespace_ary[0] . '/' . $namespace_ary[1]; |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* Check if fsockopen is available |
735
|
|
|
* |
736
|
|
|
* @return bool |
737
|
|
|
* @access public |
738
|
|
|
*/ |
739
|
|
|
public function check_fsockopen() |
740
|
|
|
{ |
741
|
|
|
if (function_exists('fsockopen')) |
742
|
|
|
{ |
743
|
|
|
$this->get_ext_meta(); |
744
|
|
|
|
745
|
|
|
$url = parse_url($this->ext_meta['extra']['version-check']['host']); |
746
|
|
|
|
747
|
|
|
$fp = @fsockopen($url['path'], 80); |
748
|
|
|
|
749
|
|
|
return ($fp !== false) ? true : false; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
return false; |
753
|
|
|
} |
754
|
|
|
} |
755
|
|
|
|
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.