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
|
|
|
/** |
16
|
|
|
* @property \phpbb\config\config config Config object |
17
|
|
|
* @property ContainerInterface container The phpBB log system |
18
|
|
|
* @property string id_prefix_name Prefix name for identifier in the URL |
19
|
|
|
* @property string lang_key_prefix Prefix for the messages thrown by exceptions |
20
|
|
|
* @property string module_name Name of the module currently used |
21
|
|
|
* @property \phpbb\request\request request Request object |
22
|
|
|
* @property bool submit State of submit $_POST variable |
23
|
|
|
* @property \phpbb\template\template template Template object |
24
|
|
|
* @property string u_action Action URL |
25
|
|
|
* @property \phpbb\user user User object |
26
|
|
|
*/ |
27
|
|
|
class admin_paypal_features_controller extends admin_main |
28
|
|
|
{ |
29
|
|
|
protected $ppde_controller_main; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor |
33
|
|
|
* |
34
|
|
|
* @param \phpbb\config\config $config Config object |
35
|
|
|
* @param ContainerInterface $container Service container interface |
36
|
|
|
* @param \skouat\ppde\controller\main_controller $ppde_controller_main Main controller object |
37
|
|
|
* @param \phpbb\request\request $request Request object |
38
|
|
|
* @param \phpbb\template\template $template Template object |
39
|
|
|
* @param \phpbb\user $user User object |
40
|
|
|
* |
41
|
|
|
* @access public |
42
|
|
|
*/ |
43
|
|
|
public function __construct(\phpbb\config\config $config, ContainerInterface $container, \skouat\ppde\controller\main_controller $ppde_controller_main, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) |
44
|
|
|
{ |
45
|
|
|
$this->config = $config; |
46
|
|
|
$this->container = $container; |
47
|
|
|
$this->ppde_controller_main = $ppde_controller_main; |
48
|
|
|
$this->request = $request; |
49
|
|
|
$this->template = $template; |
50
|
|
|
$this->user = $user; |
51
|
|
|
parent::__construct( |
52
|
|
|
'paypal_features', |
53
|
|
|
'PPDE_PAYPAL_FEATURES', |
54
|
|
|
'' |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Display the settings a user can configure for this extension |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
* @access public |
63
|
|
|
*/ |
64
|
|
|
public function display_settings() |
65
|
|
|
{ |
66
|
|
|
$this->ppde_controller_main->first_start(); |
67
|
|
|
|
68
|
|
|
// Define the name of the form for use as a form key |
69
|
|
|
add_form_key('ppde_settings'); |
70
|
|
|
|
71
|
|
|
// Create an array to collect errors that will be output to the user |
72
|
|
|
$errors = array(); |
73
|
|
|
|
74
|
|
|
$this->submit_settings(); |
75
|
|
|
|
76
|
|
|
// Set output vars for display in the template |
77
|
|
|
$this->s_error_assign_template_vars($errors); |
78
|
|
|
$this->u_action_assign_template_vars(); |
79
|
|
|
$this->template->assign_vars(array( |
80
|
|
|
// PayPal IPN vars |
81
|
|
|
'S_PPDE_IPN_AG_ENABLE' => $this->check_config($this->config['ppde_ipn_autogroup_enable']), |
82
|
|
|
'S_PPDE_IPN_AG_GROUP_AS_DEFAULT' => $this->check_config($this->config['ppde_ipn_group_as_default']), |
83
|
|
|
'S_PPDE_IPN_DL_ENABLE' => $this->check_config($this->config['ppde_ipn_donorlist_enable']), |
84
|
|
|
'S_PPDE_IPN_ENABLE' => $this->check_config($this->config['ppde_ipn_enable']), |
85
|
|
|
'S_PPDE_IPN_GROUP_OPTIONS' => group_select_options($this->config['ppde_ipn_group_id']), |
86
|
|
|
'S_PPDE_IPN_LOGGING' => $this->check_config($this->config['ppde_ipn_logging']), |
87
|
|
|
'S_PPDE_IPN_NOTIFICATION_ENABLE' => $this->check_config($this->config['ppde_ipn_notification_enable']), |
88
|
|
|
|
89
|
|
|
// Sandbox Settings vars |
90
|
|
|
'PPDE_SANDBOX_ADDRESS' => $this->check_config($this->config['ppde_sandbox_address'], 'string', ''), |
91
|
|
|
'S_PPDE_SANDBOX_ENABLE' => $this->check_config($this->config['ppde_sandbox_enable']), |
92
|
|
|
'S_PPDE_SANDBOX_FOUNDER_ENABLE' => $this->check_config($this->config['ppde_sandbox_founder_enable']), |
93
|
|
|
)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* The form submitting if 'submit' is true |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
* @access private |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
private function submit_settings() |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$this->submit = $this->request->is_set_post('submit'); |
105
|
|
|
|
106
|
|
|
// Test if the submitted form is valid |
107
|
|
|
$errors = $this->is_invalid_form('ppde_settings', $this->submit); |
108
|
|
|
|
109
|
|
|
if ($this->can_submit_data($errors)) |
110
|
|
|
{ |
111
|
|
|
// Set the options the user configured |
112
|
|
|
$this->set_settings(); |
113
|
|
|
|
114
|
|
|
// Add option settings change action to the admin log |
115
|
|
|
$phpbb_log = $this->container->get('log'); |
116
|
|
|
$phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_' . $this->lang_key_prefix . '_UPDATED'); |
117
|
|
|
|
118
|
|
|
// Option settings have been updated and logged |
119
|
|
|
// Confirm this to the user and provide link back to previous page |
120
|
|
|
trigger_error($this->user->lang($this->lang_key_prefix . '_SAVED') . adm_back_link($this->u_action)); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set the options a user can configure |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
* @access private |
129
|
|
|
*/ |
130
|
|
|
private function set_settings() |
131
|
|
|
{ |
132
|
|
|
// Set options for PayPal IPN |
133
|
|
|
$this->config->set('ppde_ipn_autogroup_enable', $this->request->variable('ppde_ipn_autogroup_enable', false)); |
134
|
|
|
$this->config->set('ppde_ipn_donorlist_enable', $this->request->variable('ppde_ipn_donorlist_enable', false)); |
135
|
|
|
$this->config->set('ppde_ipn_enable', $this->request->variable('ppde_ipn_enable', false)); |
136
|
|
|
$this->config->set('ppde_ipn_group_as_default', $this->request->variable('ppde_ipn_group_as_default', false)); |
137
|
|
|
$this->config->set('ppde_ipn_group_id', $this->request->variable('ppde_ipn_group_id', 0)); |
138
|
|
|
$this->config->set('ppde_ipn_logging', $this->request->variable('ppde_ipn_logging', false)); |
139
|
|
|
$this->config->set('ppde_ipn_notification_enable', $this->request->variable('ppde_ipn_notification_enable', false)); |
140
|
|
|
|
141
|
|
|
// Set options for Sandbox Settings |
142
|
|
|
$this->config->set('ppde_sandbox_enable', $this->request->variable('ppde_sandbox_enable', false)); |
143
|
|
|
$this->config->set('ppde_sandbox_founder_enable', $this->request->variable('ppde_sandbox_founder_enable', true)); |
144
|
|
|
|
145
|
|
|
// Set misc settings |
146
|
|
|
$this->ppde_controller_main->set_curl_info(); |
147
|
|
|
$this->ppde_controller_main->set_remote_detected(); |
148
|
|
|
|
149
|
|
|
// Settings with dependencies are the last to be set. |
150
|
|
|
$this->config->set('ppde_sandbox_address', $this->required_settings($this->request->variable('ppde_sandbox_address', ''), $this->depend_on('ppde_sandbox_enable'))); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.