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\admin; |
12
|
|
|
|
13
|
|
|
use phpbb\config\config; |
14
|
|
|
use phpbb\language\language; |
15
|
|
|
use phpbb\log\log; |
16
|
|
|
use phpbb\request\request; |
17
|
|
|
use phpbb\template\template; |
18
|
|
|
use phpbb\user; |
19
|
|
|
use skouat\ppde\actions\currency; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @property config config Config object |
23
|
|
|
* @property string id_prefix_name Prefix name for identifier in the URL |
24
|
|
|
* @property string lang_key_prefix Prefix for the messages thrown by exceptions |
25
|
|
|
* @property language language Language user object |
26
|
|
|
* @property log log The phpBB log system |
27
|
|
|
* @property string module_name Name of the module currently used |
28
|
|
|
* @property request request Request object |
29
|
|
|
* @property bool submit State of submit $_POST variable |
30
|
|
|
* @property template template Template object |
31
|
|
|
* @property string u_action Action URL |
32
|
|
|
* @property user user User object |
33
|
|
|
*/ |
34
|
|
|
class settings_controller extends admin_main |
35
|
|
|
{ |
36
|
|
|
protected $ppde_actions_currency; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructor |
40
|
|
|
* |
41
|
|
|
* @param config $config Config object |
42
|
|
|
* @param language $language Language user object |
43
|
|
|
* @param log $log The phpBB log system |
44
|
|
|
* @param currency $ppde_actions_currency Main controller object |
45
|
|
|
* @param request $request Request object |
46
|
|
|
* @param template $template Template object |
47
|
|
|
* @param user $user User object |
48
|
|
|
* |
49
|
|
|
* @access public |
50
|
|
|
*/ |
51
|
|
|
public function __construct( |
52
|
|
|
config $config, |
53
|
|
|
language $language, |
54
|
|
|
log $log, |
55
|
|
|
currency $ppde_actions_currency, |
56
|
|
|
request $request, |
57
|
|
|
template $template, |
58
|
|
|
user $user |
59
|
|
|
) |
60
|
|
|
{ |
61
|
|
|
$this->config = $config; |
62
|
|
|
$this->language = $language; |
63
|
|
|
$this->log = $log; |
64
|
|
|
$this->ppde_actions_currency = $ppde_actions_currency; |
65
|
|
|
$this->request = $request; |
66
|
|
|
$this->template = $template; |
67
|
|
|
$this->user = $user; |
68
|
|
|
parent::__construct( |
69
|
|
|
'settings', |
70
|
|
|
'PPDE_SETTINGS', |
71
|
|
|
'' |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Display the general settings a user can configure for this extension |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
* @access public |
80
|
|
|
*/ |
81
|
|
|
public function display_settings() |
82
|
|
|
{ |
83
|
|
|
// Define the name of the form for use as a form key |
84
|
|
|
add_form_key('ppde_settings'); |
85
|
|
|
|
86
|
|
|
// Create an array to collect errors that will be output to the user |
87
|
|
|
$errors = array(); |
88
|
|
|
|
89
|
|
|
$this->submit_settings(); |
90
|
|
|
|
91
|
|
|
// Set output vars for display in the template |
92
|
|
|
$this->s_error_assign_template_vars($errors); |
93
|
|
|
$this->u_action_assign_template_vars(); |
94
|
|
|
$this->ppde_actions_currency->build_currency_select_menu((int) $this->config['ppde_default_currency']); |
95
|
|
|
$this->template->assign_vars(array( |
96
|
|
|
// Global Settings vars |
97
|
|
|
'PPDE_ACCOUNT_ID' => $this->check_config($this->config['ppde_account_id'], 'string', ''), |
98
|
|
|
'PPDE_DEFAULT_VALUE' => $this->check_config($this->config['ppde_default_value'], 'integer', 0), |
99
|
|
|
'PPDE_DROPBOX_VALUE' => $this->check_config($this->config['ppde_dropbox_value'], 'string', '1,2,3,4,5,10,20,25,50,100'), |
100
|
|
|
'S_PPDE_DROPBOX_ENABLE' => $this->check_config($this->config['ppde_dropbox_enable']), |
101
|
|
|
'S_PPDE_ENABLE' => $this->check_config($this->config['ppde_enable']), |
102
|
|
|
'S_PPDE_HEADER_LINK' => $this->check_config($this->config['ppde_header_link']), |
103
|
|
|
|
104
|
|
|
// Statistics Settings vars |
105
|
|
|
'PPDE_GOAL' => $this->check_config($this->config['ppde_goal'], 'float', 0), |
106
|
|
|
'PPDE_RAISED' => $this->check_config($this->config['ppde_raised'], 'float', 0), |
107
|
|
|
'PPDE_USED' => $this->check_config($this->config['ppde_used'], 'float', 0), |
108
|
|
|
'S_PPDE_GOAL_ENABLE' => $this->check_config($this->config['ppde_goal_enable']), |
109
|
|
|
'S_PPDE_RAISED_ENABLE' => $this->check_config($this->config['ppde_raised_enable']), |
110
|
|
|
'S_PPDE_STATS_INDEX_ENABLE' => $this->check_config($this->config['ppde_stats_index_enable']), |
111
|
|
|
'S_PPDE_USED_ENABLE' => $this->check_config($this->config['ppde_used_enable']), |
112
|
|
|
)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Set the options a user can configure |
117
|
|
|
* |
118
|
|
|
* @return void |
119
|
|
|
* @access protected |
120
|
|
|
*/ |
121
|
|
|
protected function set_settings() |
122
|
|
|
{ |
123
|
|
|
// Set options for Global settings |
124
|
|
|
$this->config->set('ppde_default_currency', $this->request->variable('ppde_default_currency', 0)); |
125
|
|
|
$this->config->set('ppde_default_value', $this->request->variable('ppde_default_value', 0)); |
126
|
|
|
$this->config->set('ppde_dropbox_enable', $this->request->variable('ppde_dropbox_enable', false)); |
127
|
|
|
$this->config->set('ppde_dropbox_value', $this->rebuild_items_list($this->request->variable('ppde_dropbox_value', '1,2,3,4,5,10,20,25,50,100'), $this->config['ppde_default_value'])); |
128
|
|
|
$this->config->set('ppde_enable', $this->request->variable('ppde_enable', false)); |
129
|
|
|
$this->config->set('ppde_header_link', $this->request->variable('ppde_header_link', false)); |
130
|
|
|
|
131
|
|
|
// Set options for Statistics Settings |
132
|
|
|
$this->config->set('ppde_stats_index_enable', $this->request->variable('ppde_stats_index_enable', false)); |
133
|
|
|
$this->config->set('ppde_raised_enable', $this->request->variable('ppde_raised_enable', false)); |
134
|
|
|
$this->config->set('ppde_raised', $this->request->variable('ppde_raised', 0.0)); |
135
|
|
|
$this->config->set('ppde_goal_enable', $this->request->variable('ppde_goal_enable', false)); |
136
|
|
|
$this->config->set('ppde_goal', $this->request->variable('ppde_goal', 0.0)); |
137
|
|
|
$this->config->set('ppde_used_enable', $this->request->variable('ppde_used_enable', false)); |
138
|
|
|
$this->config->set('ppde_used', $this->request->variable('ppde_used', 0.0)); |
139
|
|
|
|
140
|
|
|
// Settings with dependencies are the last to be set. |
141
|
|
|
$this->config->set('ppde_account_id', $this->required_settings($this->request->variable('ppde_account_id', ''), $this->depend_on('ppde_enable'))); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Rebuild items list to conserve only numeric values |
146
|
|
|
* |
147
|
|
|
* @param string $config_value |
148
|
|
|
* @param string $added_value |
149
|
|
|
* |
150
|
|
|
* @return string |
151
|
|
|
* @access private |
152
|
|
|
*/ |
153
|
|
|
private function rebuild_items_list($config_value, $added_value = '') |
154
|
|
|
{ |
155
|
|
|
$items_list = explode(',', $config_value); |
156
|
|
|
$merge_items = array(); |
157
|
|
|
|
158
|
|
|
$this->add_int_data_in_array($merge_items, $added_value); |
159
|
|
|
|
160
|
|
|
foreach ($items_list as $item) |
161
|
|
|
{ |
162
|
|
|
$this->add_int_data_in_array($merge_items, $item); |
163
|
|
|
} |
164
|
|
|
unset($items_list, $item); |
165
|
|
|
|
166
|
|
|
natsort($merge_items); |
167
|
|
|
|
168
|
|
|
return $this->check_config(implode(',', array_unique($merge_items)), 'string', ''); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Add integer data in an array() |
173
|
|
|
* |
174
|
|
|
* @param array &$array |
175
|
|
|
* @param string $var |
176
|
|
|
* |
177
|
|
|
* @return void |
178
|
|
|
* @access private |
179
|
|
|
*/ |
180
|
|
|
private function add_int_data_in_array(&$array, $var) |
181
|
|
|
{ |
182
|
|
|
if (settype($var, 'integer') && $var != 0) |
183
|
|
|
{ |
184
|
|
|
$array[] = $var; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|