Passed
Push — master ( 146fdc...6e4ec6 )
by Dark❶
02:30
created

acp_base::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.9332
1
<?php
2
/**
3
 *
4
 * Reduce Search Index [RSI]. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2020, Dark❶, https://dark1.tech
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace dark1\reducesearchindex\controller;
12
13
/**
14
 * @ignore
15
 */
16
use phpbb\template\template;
17
use phpbb\user;
18
use phpbb\language\language;
19
use phpbb\log\log;
20
use phpbb\request\request;
21
22
/**
23
 * Reduce Search Index [RSI] ACP controller Base.
24
 */
25
class acp_base
26
{
27
	/** @var \phpbb\language\language */
28
	protected $language;
29
30
	/** @var \phpbb\log\log */
31
	protected $log;
32
33
	/** @var \phpbb\request\request */
34
	protected $request;
35
36
	/** @var \phpbb\template\template */
37
	protected $template;
38
39
	/** @var \phpbb\user */
40
	protected $user;
41
42
	/** @var string The module ID */
43
	protected $id;
44
45
	/** @var string The module mode */
46
	protected $mode;
47
48
	/** @var string Custom form action */
49
	protected $u_action;
50
51
	/**
52
	 * Constructor.
53
	 *
54
	 * @param \phpbb\language\language				$language		Language object
55
	 * @param \phpbb\log\log						$log			Log object
56
	 * @param \phpbb\request\request				$request		Request object
57
	 * @param \phpbb\template\template				$template		Template object
58
	 * @param \phpbb\user							$user			User object
59
	 */
60
	public function __construct(language $language, log $log, request $request, template $template, user $user)
61
	{
62
		$this->language		= $language;
63
		$this->log			= $log;
64
		$this->request		= $request;
65
		$this->template		= $template;
66
		$this->user			= $user;
67
	}
68
69
	/**
70
	 * Set Data form.
71
	 *
72
	 * @param int		$id			The module ID
73
	 * @param string	$mode		The module mode
74
	 * @param string	$u_action	Custom form action
75
	 *
76
	 * @return void
77
	 */
78
	public function set_data($id, $mode, $u_action)
79
	{
80
		$this->id = $id;
81
		$this->mode = $mode;
82
		$this->u_action = $u_action;
83
	}
84
85
	/**
86
	 * Get Data form.
87
	 *
88
	 * @return array Having keys 'tpl_name' & 'page_title'
89
	 */
90
	public function get_data()
91
	{
92
		return [
93
			'tpl_name' => 'dark1_rsi_acp_' . $this->mode,
94
			'page_title' => $this->language->lang('ACP_RSI_TITLE') . ' - ' . $this->language->lang('ACP_RSI_' . strtoupper($this->mode)),
95
		];
96
	}
97
98
	/**
99
	 * Set Display form.
100
	 *
101
	 * @return void
102
	 */
103
	public function setup()
104
	{
105
		$ext_name_rsi = 'Reduce Search Index [RSI]';
106
		$ext_by_dark1 = 'Dark❶ [dark1]';
107
108
		// Add our common language file
109
		$this->language->add_lang('lang_rsi', 'dark1/reducesearchindex');
110
111
		// Create a form key for preventing CSRF attacks
112
		add_form_key('dark1_rsi_acp_' . $this->mode);
113
114
		// Set u_action in the template
115
		$this->template->assign_vars([
116
			'U_ACTION'		=> $this->u_action,
117
			'RSI_MODE'		=> $this->mode,
118
			'RSI_EXT_MODE'	=> $this->language->lang('ACP_RSI_' . strtoupper($this->mode)),
119
			'RSI_EXT_NAME'	=> $ext_name_rsi,
120
			'RSI_EXT_DEV'	=> $ext_by_dark1,
121
		]);
122
	}
123
124
	/**
125
	 * Check Form On Submit .
126
	 *
127
	 * @return void
128
	 */
129
	protected function check_form_on_submit()
130
	{
131
		// Test if the submitted form is valid
132
		if (!check_form_key('dark1_rsi_acp_' . $this->mode))
133
		{
134
			trigger_error('FORM_INVALID', E_USER_WARNING);
135
		}
136
	}
137
138
	/**
139
	 * Success Form On Submit.
140
	 * Used to Log & Trigger Success Err0r.
141
	 *
142
	 * @return void
143
	 */
144
	protected function success_form_on_submit()
145
	{
146
		// Add option settings change action to the admin log
147
		$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_RSI_LOG_SET_SAV', time(), array($this->language->lang('ACP_RSI_' . strtoupper($this->mode))));
148
149
		// Option settings have been updated and logged
150
		// Confirm this to the user and provide link back to previous page
151
		trigger_error($this->language->lang('ACP_RSI_LOG_SET_SAV', $this->language->lang('ACP_RSI_' . strtoupper($this->mode))) . adm_back_link($this->u_action), E_USER_NOTICE);
152
	}
153
}
154