Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like main_controller often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use main_controller, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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 string */ |
||
40 | private $return_args_url; |
||
41 | /** @var string */ |
||
42 | private $u_action; |
||
43 | |||
44 | /** |
||
45 | * Constructor |
||
46 | * |
||
47 | * @param \phpbb\auth\auth $auth Auth object |
||
48 | * @param \phpbb\config\config $config Config object |
||
49 | * @param ContainerInterface $container Service container interface |
||
50 | * @param \phpbb\extension\manager $extension_manager An instance of the phpBB extension manager |
||
51 | * @param \phpbb\controller\helper $helper Controller helper object |
||
52 | * @param \skouat\ppde\entity\currency $ppde_entity_currency Currency entity object |
||
53 | * @param \skouat\ppde\entity\donation_pages $ppde_entity_donation_pages Donation pages entity object |
||
54 | * @param \skouat\ppde\entity\transactions $ppde_entity_transactions Transactions log entity object |
||
55 | * @param \skouat\ppde\operators\currency $ppde_operator_currency Currency operator object |
||
56 | * @param \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages Donation pages operator object |
||
57 | * @param \skouat\ppde\operators\transactions $ppde_operator_transactions Transactions log operator object |
||
58 | * @param \phpbb\request\request $request Request object |
||
59 | * @param \phpbb\template\template $template Template object |
||
60 | * @param \phpbb\user $user User object |
||
61 | * @param string $root_path phpBB root path |
||
62 | * @param string $php_ext phpEx |
||
63 | * |
||
64 | * @return \skouat\ppde\controller\main_controller |
||
65 | * @access public |
||
66 | */ |
||
67 | 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) |
||
68 | { |
||
69 | $this->auth = $auth; |
||
70 | $this->config = $config; |
||
71 | $this->container = $container; |
||
72 | $this->extension_manager = $extension_manager; |
||
73 | $this->helper = $helper; |
||
74 | $this->ppde_entity_currency = $ppde_entity_currency; |
||
75 | $this->ppde_entity_donation_pages = $ppde_entity_donation_pages; |
||
76 | $this->ppde_entity_transactions = $ppde_entity_transactions; |
||
77 | $this->ppde_operator_currency = $ppde_operator_currency; |
||
78 | $this->ppde_operator_donation_pages = $ppde_operator_donation_pages; |
||
79 | $this->ppde_operator_transactions = $ppde_operator_transactions; |
||
80 | $this->request = $request; |
||
81 | $this->template = $template; |
||
82 | $this->user = $user; |
||
83 | $this->root_path = $root_path; |
||
84 | $this->php_ext = $php_ext; |
||
85 | } |
||
86 | |||
87 | public function handle() |
||
88 | { |
||
89 | // When this extension is disabled, redirect users back to the forum index |
||
90 | // Else if user is not allowed to use it, disallow access to the extension main page |
||
91 | if (empty($this->config['ppde_enable'])) |
||
92 | { |
||
93 | redirect(append_sid("{$this->root_path}index.{$this->php_ext}")); |
||
1 ignored issue
–
show
|
|||
94 | } |
||
95 | else if (!$this->can_use_ppde()) |
||
96 | { |
||
97 | trigger_error('NOT_AUTHORISED'); |
||
98 | } |
||
99 | |||
100 | $this->set_return_args_url($this->request->variable('return', 'body')); |
||
101 | |||
102 | // Prepare message for display |
||
103 | if ($this->get_donation_content_data($this->return_args_url)) |
||
104 | { |
||
105 | $this->ppde_entity_donation_pages->get_vars(); |
||
106 | $this->donation_body = $this->ppde_entity_donation_pages->replace_template_vars($this->ppde_entity_donation_pages->get_message_for_display()); |
||
107 | } |
||
108 | |||
109 | $this->template->assign_vars(array( |
||
110 | 'DEFAULT_CURRENCY' => $this->build_currency_select_menu($this->config['ppde_default_currency']), |
||
111 | 'DONATION_BODY' => $this->donation_body, |
||
112 | 'PPDE_DEFAULT_VALUE' => $this->config['ppde_default_value'] ? $this->config['ppde_default_value'] : 0, |
||
113 | 'PPDE_LIST_VALUE' => $this->build_currency_value_select_menu(), |
||
114 | |||
115 | 'S_HIDDEN_FIELDS' => $this->paypal_hidden_fields(), |
||
116 | 'S_PPDE_FORM_ACTION' => $this->get_paypal_url(), |
||
117 | 'S_RETURN_ARGS' => $this->return_args_url, |
||
118 | 'S_SANDBOX' => $this->use_sandbox(), |
||
119 | )); |
||
120 | |||
121 | $this->display_stats(); |
||
122 | |||
123 | // Send all data to the template file |
||
124 | return $this->send_data_to_template(); |
||
125 | } |
||
126 | |||
127 | public function donorlist_handle() |
||
128 | { |
||
129 | // If the donorlist is not enabled, redirect users back to the forum index |
||
130 | // Else if user is not allowed to view the donors list, disallow access to the extension page |
||
131 | if (!$this->donorlist_is_enabled()) |
||
132 | { |
||
133 | redirect(append_sid($this->root_path . 'index.' . $this->php_ext)); |
||
134 | } |
||
135 | else if (!$this->can_view_ppde_donorlist()) |
||
136 | { |
||
137 | trigger_error('NOT_AUTHORISED'); |
||
138 | } |
||
139 | |||
140 | // Get needed container |
||
141 | /** @type \phpbb\pagination $pagination */ |
||
142 | $pagination = $this->container->get('pagination'); |
||
143 | /** @type \phpbb\path_helper $path_helper */ |
||
144 | $path_helper = $this->container->get('path_helper'); |
||
145 | |||
146 | // Set up general vars |
||
147 | $default_key = 'd'; |
||
148 | $sort_key = $this->request->variable('sk', $default_key); |
||
149 | $sort_dir = $this->request->variable('sd', 'd'); |
||
150 | $start = $this->request->variable('start', 0); |
||
151 | |||
152 | // Sorting and order |
||
153 | $sort_key_sql = array('a' => 'amount', 'd' => 'txn.payment_date', 'u' => 'u.username_clean'); |
||
154 | |||
155 | if (!isset($sort_key_sql[$sort_key])) |
||
156 | { |
||
157 | $sort_key = $default_key; |
||
158 | } |
||
159 | |||
160 | $order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC'); |
||
161 | |||
162 | // Build a relevant pagination_url and sort_url |
||
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 | 'start' => array('start', 0), |
||
168 | ); |
||
169 | |||
170 | $params = $this->check_params($check_params, array('start')); |
||
171 | $sort_params = $this->check_params($check_params, array('sk', 'sd')); |
||
172 | |||
173 | // Set '$this->u_action' |
||
174 | $use_page = ($this->u_action) ? $this->u_action : $this->user->page['page_name']; |
||
175 | $this->u_action = reapply_sid($path_helper->get_valid_page($use_page, $this->config['enable_mod_rewrite'])); |
||
176 | |||
177 | $pagination_url = append_sid($this->u_action, implode('&', $params), true, false, true); |
||
178 | $sort_url = $this->set_url_delim(append_sid($this->u_action, implode('&', $sort_params), true, false, true), $sort_params); |
||
179 | |||
180 | $get_donorlist_sql_ary = $this->ppde_operator_transactions->get_sql_donorlist_ary(false, $order_by); |
||
181 | $total_donors = $this->ppde_operator_transactions->query_sql_count($get_donorlist_sql_ary, 'txn.user_id'); |
||
182 | $start = $pagination->validate_start($start, $this->config['topics_per_page'], $total_donors); |
||
183 | |||
184 | $pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_donors, $this->config['topics_per_page'], $start); |
||
185 | |||
186 | // adds fields to the table schema needed by entity->import() |
||
187 | $additional_table_schema = array( |
||
188 | 'item_username' => array('name' => 'username', 'type' => 'string'), |
||
189 | 'item_user_colour' => array('name' => 'user_colour', 'type' => 'string'), |
||
190 | 'item_amount' => array('name' => 'amount', 'type' => 'float'), |
||
191 | 'item_max_txn_id' => array('name' => 'max_txn_id', 'type' => 'integer'), |
||
192 | ); |
||
193 | |||
194 | $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); |
||
195 | |||
196 | // Get default currency data from the database |
||
197 | $default_currency_data = $this->get_default_currency_data($this->config['ppde_default_currency']); |
||
198 | $this->template->assign_vars(array( |
||
199 | 'TOTAL_DONORS' => $this->user->lang('PPDE_DONORS', $total_donors), |
||
200 | 'U_SORT_AMOUNT' => $sort_url . 'sk=a&sd=' . $this->set_sort_key($sort_key, 'a', $sort_dir), |
||
201 | 'U_SORT_DONATED' => $sort_url . 'sk=d&sd=' . $this->set_sort_key($sort_key, 'd', $sort_dir), |
||
202 | 'U_SORT_USERNAME' => $sort_url . 'sk=u&sd=' . $this->set_sort_key($sort_key, 'u', $sort_dir), |
||
203 | )); |
||
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->currency_on_left(number_format($last_donation_data[0]['mc_gross'], 2), $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->currency_on_left(number_format($data['amount'], 2), $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 | * Set the sort key value |
||
226 | * |
||
227 | * @param string $sk |
||
228 | * @param string $sk_comp |
||
229 | * @param string $sd |
||
230 | * |
||
231 | * @return string |
||
232 | * @access private |
||
233 | */ |
||
234 | private function set_sort_key($sk, $sk_comp, $sd) |
||
235 | { |
||
236 | return ($sk == $sk_comp && $sd == 'a') ? 'd' : 'a'; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Simply adds an url or & delimiter to the url when params is empty |
||
241 | * |
||
242 | * @param $url |
||
243 | * @param $params |
||
244 | * |
||
245 | * @return string |
||
246 | * @access private |
||
247 | */ |
||
248 | private function set_url_delim($url, $params) |
||
249 | { |
||
250 | return (empty($params)) ? $url . '?' : $url . '&'; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @param array $params_ary |
||
255 | * @param string[] $excluded_keys |
||
256 | * |
||
257 | * @return array |
||
258 | * @access private |
||
259 | */ |
||
260 | private function check_params($params_ary, $excluded_keys) |
||
261 | { |
||
262 | $params = array(); |
||
263 | |||
264 | foreach ($params_ary as $key => $call) |
||
265 | { |
||
266 | if (!isset($_REQUEST[$key])) |
||
267 | { |
||
268 | continue; |
||
269 | } |
||
270 | |||
271 | $param = call_user_func_array('request_var', $call); |
||
272 | $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param); |
||
273 | |||
274 | if (!in_array($key, $excluded_keys)) |
||
275 | { |
||
276 | $params[] = $param; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | return $params; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @return bool |
||
285 | * @access public |
||
286 | */ |
||
287 | public function can_use_ppde() |
||
288 | { |
||
289 | return $this->auth->acl_get('u_ppde_use'); |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return bool |
||
294 | * @access public |
||
295 | */ |
||
296 | public function can_view_ppde_donorlist() |
||
297 | { |
||
298 | return $this->auth->acl_get('u_ppde_view_donorlist'); |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * @return bool |
||
303 | * @access private |
||
304 | */ |
||
305 | private function donorlist_is_enabled() |
||
306 | { |
||
307 | return $this->use_ipn() && $this->config['ppde_ipn_donorlist_enable']; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * @param string $set_return_args_url |
||
312 | * |
||
313 | * @return null |
||
314 | * @access private |
||
315 | */ |
||
316 | private function set_return_args_url($set_return_args_url) |
||
317 | { |
||
318 | switch ($set_return_args_url) |
||
319 | { |
||
320 | case 'cancel': |
||
321 | case 'success': |
||
322 | $this->template->assign_vars(array( |
||
323 | 'L_PPDE_DONATION_TITLE' => $this->user->lang['PPDE_' . strtoupper($set_return_args_url) . '_TITLE'], |
||
324 | )); |
||
325 | $this->return_args_url = $set_return_args_url; |
||
326 | break; |
||
327 | case 'donorlist': |
||
328 | $this->template->assign_vars(array( |
||
329 | 'L_PPDE_DONORLIST_TITLE' => $this->user->lang['PPDE_DONORLIST_TITLE'], |
||
330 | )); |
||
331 | $this->return_args_url = $set_return_args_url; |
||
332 | break; |
||
333 | default: |
||
334 | $this->return_args_url = 'body'; |
||
335 | } |
||
336 | |||
337 | } |
||
338 | |||
339 | /** |
||
340 | * Get content of current donation pages |
||
341 | * |
||
342 | * @param string $return_args_url |
||
343 | * |
||
344 | * @return array |
||
345 | * @access private |
||
346 | */ |
||
347 | private function get_donation_content_data($return_args_url) |
||
348 | { |
||
349 | return $this->ppde_entity_donation_pages->get_data( |
||
350 | $this->ppde_operator_donation_pages->build_sql_data($this->user->get_iso_lang_id(), $return_args_url) |
||
351 | ); |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * Build pull down menu options of available currency |
||
356 | * |
||
357 | * @param int $config_value Currency identifier; default: 0 |
||
358 | * |
||
359 | * @return null |
||
360 | * @access public |
||
361 | */ |
||
362 | public function build_currency_select_menu($config_value = 0) |
||
363 | { |
||
364 | // Grab the list of all enabled currencies; 0 is for all data |
||
365 | $currency_items = $this->ppde_entity_currency->get_data($this->ppde_operator_currency->build_sql_data(0, true)); |
||
366 | |||
367 | // Process each rule menu item for pull-down |
||
368 | foreach ($currency_items as $currency_item) |
||
369 | { |
||
370 | // Set output block vars for display in the template |
||
371 | $this->template->assign_block_vars('options', array( |
||
372 | 'CURRENCY_ID' => (int) $currency_item['currency_id'], |
||
373 | 'CURRENCY_ISO_CODE' => $currency_item['currency_iso_code'], |
||
374 | 'CURRENCY_NAME' => $currency_item['currency_name'], |
||
375 | 'CURRENCY_SYMBOL' => $currency_item['currency_symbol'], |
||
376 | 'S_CURRENCY_DEFAULT' => $config_value == $currency_item['currency_id'], |
||
377 | )); |
||
378 | } |
||
379 | unset ($currency_items, $currency_item); |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * Build pull down menu options of available currency value |
||
384 | * |
||
385 | * @return string List of currency value set in ACP for dropdown menu |
||
386 | * @access private |
||
387 | */ |
||
388 | private function build_currency_value_select_menu() |
||
389 | { |
||
390 | $list_donation_value = ''; |
||
391 | |||
392 | if ($this->get_dropbox_status()) |
||
393 | { |
||
394 | $donation_ary_value = explode(',', $this->config['ppde_dropbox_value']); |
||
395 | |||
396 | foreach ($donation_ary_value as $value) |
||
397 | { |
||
398 | $int_value = $this->settype_dropbox_int_value($value); |
||
399 | $list_donation_value .= !empty($int_value) ? '<option value="' . $int_value . '">' . $int_value . '</option>' : ''; |
||
400 | } |
||
401 | unset($value); |
||
402 | } |
||
403 | |||
404 | return $list_donation_value; |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * Get dropbox config value |
||
409 | * |
||
410 | * @return bool |
||
411 | * @access private |
||
412 | */ |
||
413 | private function get_dropbox_status() |
||
414 | { |
||
415 | return $this->config['ppde_dropbox_enable'] && $this->config['ppde_dropbox_value']; |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * Force dropbox value to integer |
||
420 | * |
||
421 | * @param int $value |
||
422 | * |
||
423 | * @return int |
||
424 | * @access private |
||
425 | */ |
||
426 | private function settype_dropbox_int_value($value = 0) |
||
427 | { |
||
428 | if (settype($value, 'integer') && $value != 0) |
||
429 | { |
||
430 | return $value; |
||
431 | } |
||
432 | |||
433 | return 0; |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * Build PayPal hidden fields |
||
438 | * |
||
439 | * @return string PayPal hidden field needed to fill PayPal forms |
||
440 | * @access private |
||
441 | */ |
||
442 | private function paypal_hidden_fields() |
||
443 | { |
||
444 | return build_hidden_fields(array( |
||
445 | 'cmd' => '_donations', |
||
446 | 'business' => $this->get_account_id(), |
||
447 | 'item_name' => $this->user->lang['PPDE_DONATION_TITLE_HEAD'] . ' ' . $this->config['sitename'], |
||
448 | 'no_shipping' => 1, |
||
449 | 'return' => $this->generate_paypal_return_url('success'), |
||
450 | 'notify_url' => $this->generate_paypal_notify_return_url(), |
||
451 | 'cancel_return' => $this->generate_paypal_return_url('cancel'), |
||
452 | 'item_number' => 'uid_' . $this->user->data['user_id'] . '_' . time(), |
||
453 | 'tax' => 0, |
||
454 | 'bn' => 'Board_Donate_WPS', |
||
455 | 'charset' => 'utf-8', |
||
456 | )); |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * Get PayPal account id |
||
461 | * |
||
462 | * @return string $this Paypal account Identifier |
||
463 | * @access private |
||
464 | */ |
||
465 | private function get_account_id() |
||
469 | |||
470 | /** |
||
471 | * Check if Sandbox is enabled based on config value |
||
472 | * |
||
473 | * @return bool |
||
474 | * @access public |
||
475 | */ |
||
476 | public function use_sandbox() |
||
477 | { |
||
478 | return $this->use_ipn() && !empty($this->config['ppde_sandbox_enable']) && $this->is_sandbox_founder_enable(); |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * Check if Sandbox could be use by founders based on config value |
||
483 | * |
||
484 | * @return bool |
||
485 | * @access public |
||
486 | */ |
||
487 | public function is_sandbox_founder_enable() |
||
491 | |||
492 | /** |
||
493 | * Check if IPN is enabled based on config value |
||
494 | * |
||
495 | * @return bool |
||
496 | * @access public |
||
497 | */ |
||
498 | public function use_ipn() |
||
502 | /** |
||
503 | * Check if remote is detected based on config value |
||
504 | * |
||
505 | * @return bool |
||
506 | * @access public |
||
507 | */ |
||
508 | public function is_remote_detected() |
||
512 | |||
513 | /** |
||
514 | * Generate PayPal return URL |
||
515 | * |
||
516 | * @param string $arg |
||
517 | * |
||
518 | * @return string |
||
519 | * @access private |
||
520 | */ |
||
521 | private function generate_paypal_return_url($arg) |
||
525 | |||
526 | /** |
||
527 | * Generate PayPal return notify URL |
||
528 | * |
||
529 | * @return string |
||
530 | * @access private |
||
531 | */ |
||
532 | private function generate_paypal_notify_return_url() |
||
536 | |||
537 | /** |
||
538 | * Get PayPal URL |
||
539 | * Used in form and in IPN process |
||
540 | * |
||
541 | * @param bool $is_test_ipn |
||
542 | * |
||
543 | * @return string |
||
544 | * @access public |
||
545 | */ |
||
546 | public function get_paypal_url($is_test_ipn = false) |
||
550 | |||
551 | /** |
||
552 | * Assign statistics vars to the template |
||
553 | * |
||
554 | * @return null |
||
555 | * @access public |
||
556 | */ |
||
557 | public function display_stats() |
||
578 | |||
579 | /** |
||
580 | * Get default currency symbol |
||
581 | * |
||
582 | * @param int $id |
||
583 | * |
||
584 | * @return array |
||
585 | * @access public |
||
586 | */ |
||
587 | public function get_default_currency_data($id = 0) |
||
591 | |||
592 | /** |
||
593 | * Retrieve the language key for donation goal |
||
594 | * |
||
595 | * @param string $currency_symbol Currency symbol |
||
596 | * @param bool $on_left Symbol position |
||
597 | * |
||
598 | * @return string |
||
599 | * @access public |
||
600 | */ |
||
601 | public function get_ppde_goal_langkey($currency_symbol, $on_left = true) |
||
618 | |||
619 | /** |
||
620 | * Put the currency on the left or on the right of the amount |
||
621 | * |
||
622 | * @param int $value |
||
623 | * @param string $currency |
||
624 | * @param bool $on_left |
||
625 | * |
||
626 | * @return string |
||
627 | * @access public |
||
628 | */ |
||
629 | public function currency_on_left($value, $currency, $on_left = true) |
||
633 | |||
634 | /** |
||
635 | * Retrieve the language key for donation raised |
||
636 | * |
||
637 | * @param string $currency_symbol Currency symbol |
||
638 | * @param bool $on_left Symbol position |
||
639 | * |
||
640 | * @return string |
||
641 | * @access public |
||
642 | */ |
||
643 | public function get_ppde_raised_langkey($currency_symbol, $on_left = true) |
||
656 | |||
657 | /** |
||
658 | * Retrieve the language key for donation used |
||
659 | * |
||
660 | * @param string $currency_symbol Currency symbol |
||
661 | * @param bool $on_left Symbol position |
||
662 | * |
||
663 | * @return string |
||
664 | * @access public |
||
665 | */ |
||
666 | public function get_ppde_used_langkey($currency_symbol, $on_left = true) |
||
683 | |||
684 | /** |
||
685 | * Generate statistics percent for display |
||
686 | * |
||
687 | * @return null |
||
688 | * @access private |
||
689 | */ |
||
690 | private function generate_stats_percent() |
||
706 | |||
707 | /** |
||
708 | * Checks if stats can be displayed |
||
709 | * |
||
710 | * @return bool |
||
711 | * @access private |
||
712 | */ |
||
713 | private function is_ppde_goal_stats() |
||
717 | |||
718 | /** |
||
719 | * Checks if stats can be displayed |
||
720 | * |
||
721 | * @return bool |
||
722 | * @access private |
||
723 | */ |
||
724 | private function is_ppde_used_stats() |
||
728 | |||
729 | |||
730 | /** |
||
731 | * Returns percent value |
||
732 | * |
||
733 | * @param integer $multiplicand |
||
734 | * @param integer $dividend |
||
735 | * |
||
736 | * @return float |
||
737 | * @access private |
||
738 | */ |
||
739 | private function percent_value($multiplicand, $dividend) |
||
743 | |||
744 | /** |
||
745 | * Assign statistics percent vars to template |
||
746 | * |
||
747 | * @param float $percent |
||
748 | * @param string $type |
||
749 | * |
||
750 | * @return null |
||
751 | * @access private |
||
752 | */ |
||
753 | private function assign_vars_stats_percent($percent, $type) |
||
760 | |||
761 | /** |
||
762 | * Returns the CSS class name based on the percent of stats |
||
763 | * |
||
764 | * @param float $value |
||
765 | * @param bool $reverse |
||
766 | * |
||
767 | * @return string |
||
768 | * @access private |
||
769 | */ |
||
770 | private function ppde_css_classname($value, $reverse = false) |
||
806 | |||
807 | /** |
||
808 | * Send data to the template file |
||
809 | * |
||
810 | * @return \Symfony\Component\HttpFoundation\Response |
||
811 | * @access private |
||
812 | */ |
||
813 | private function send_data_to_template() |
||
826 | |||
827 | /** |
||
828 | * Do action if it's the first time the extension is accessed |
||
829 | * |
||
830 | * @return null |
||
831 | * @access public |
||
832 | */ |
||
833 | public function first_start() |
||
842 | |||
843 | /** |
||
844 | * Check if cURL is available |
||
845 | * |
||
846 | * @param bool $check_version |
||
847 | * |
||
848 | * @return array|bool |
||
849 | * @access public |
||
850 | */ |
||
851 | public function check_curl($check_version = false) |
||
876 | |||
877 | /** |
||
878 | * Set config value for cURL version |
||
879 | * |
||
880 | * @return null |
||
881 | * @access public |
||
882 | */ |
||
883 | public function set_curl_info() |
||
892 | |||
893 | /** |
||
894 | * Set config value for cURL and fsockopen |
||
895 | * |
||
896 | * @return null |
||
897 | * @access public |
||
898 | */ |
||
899 | public function set_remote_detected() |
||
904 | |||
905 | /** |
||
906 | * Get extension metadata |
||
907 | * |
||
908 | * @return null |
||
909 | * @access protected |
||
910 | */ |
||
911 | protected function get_ext_meta() |
||
918 | |||
919 | /** |
||
920 | * Load metadata for this extension |
||
921 | * |
||
922 | * @return array |
||
923 | * @access public |
||
924 | */ |
||
925 | public function load_metadata() |
||
947 | |||
948 | /** |
||
949 | * Retrieve the extension name |
||
950 | * |
||
951 | * @return null |
||
952 | * @access protected |
||
953 | */ |
||
954 | protected function retrieve_ext_name() |
||
959 | |||
960 | /** |
||
961 | * Check if fsockopen is available |
||
962 | * |
||
963 | * @return bool |
||
964 | * @access public |
||
965 | */ |
||
966 | public function check_fsockopen() |
||
981 | } |
||
982 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.