Completed
Pull Request — master (#25)
by Erwan
04:33
created
controller/comments.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@
 block discarded – undo
188 188
      *
189 189
      * @throws \phpbb\exception\http_exception
190 190
      *
191
-     * @return null
191
+     * @return \Symfony\Component\HttpFoundation\Response|null
192 192
      */
193 193
     public function new_comment($link_id)
194 194
     {
Please login to merge, or discard this patch.
Indentation   +463 added lines, -463 removed lines patch added patch discarded remove patch
@@ -9,475 +9,475 @@
 block discarded – undo
9 9
 
10 10
 class comments
11 11
 {
12
-    private $captcha;
13
-    private $s_comment;
14
-    private $s_hidden_fields = [];
15
-
16
-    /** @var \phpbb\db\driver\driver_interface */
17
-    protected $db;
18
-
19
-    /** @var \phpbb\config\config */
20
-    protected $config;
21
-
22
-    /** @var \phpbb\template\template */
23
-    protected $template;
24
-
25
-    /** @var \phpbb\user */
26
-    protected $user;
27
-
28
-    /** @var \phpbb\controller\helper */
29
-    protected $helper;
30
-
31
-    /** @var \phpbb\request\request */
32
-    protected $request;
33
-
34
-    /** @var \phpbb\auth\auth */
35
-    protected $auth;
36
-
37
-    /** @var \phpbb\pagination */
38
-    protected $pagination;
39
-
40
-    /** @var \phpbb\captcha\factory */
41
-    protected $captcha_factory;
42
-
43
-    /** @var \ernadoo\phpbbdirectory\core\categorie */
44
-    protected $categorie;
45
-
46
-    /** @var \ernadoo\phpbbdirectory\core\comment */
47
-    protected $comment;
48
-
49
-    /** @var string phpBB root path */
50
-    protected $root_path;
51
-
52
-    /** @var string phpEx */
53
-    protected $php_ext;
54
-
55
-    /**
56
-     * Constructor.
57
-     *
58
-     * @param \phpbb\db\driver\driver_interface      $db              Database object
59
-     * @param \phpbb\config\config                   $config          Config object
60
-     * @param \phpbb\template\template               $template        Template object
61
-     * @param \phpbb\user                            $user            User object
62
-     * @param \phpbb\controller\helper               $helper          Controller helper object
63
-     * @param \phpbb\request\request                 $request         Request object
64
-     * @param \phpbb\auth\auth                       $auth            Auth object
65
-     * @param \phpbb\pagination                      $pagination      Pagination object
66
-     * @param \phpbb\captcha\factory                 $captcha_factory Captcha object
67
-     * @param \ernadoo\phpbbdirectory\core\categorie $categorie       PhpBB Directory extension categorie object
68
-     * @param \ernadoo\phpbbdirectory\core\comment   $comment         PhpBB Directory extension comment object
69
-     * @param string                                 $root_path       phpBB root path
70
-     * @param string                                 $php_ext         phpEx
71
-     */
72
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \phpbb\captcha\factory $captcha_factory, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\comment $comment, $root_path, $php_ext)
73
-    {
74
-        $this->db = $db;
75
-        $this->config = $config;
76
-        $this->template = $template;
77
-        $this->user = $user;
78
-        $this->helper = $helper;
79
-        $this->request = $request;
80
-        $this->auth = $auth;
81
-        $this->pagination = $pagination;
82
-        $this->captcha_factory = $captcha_factory;
83
-        $this->categorie = $categorie;
84
-        $this->comment = $comment;
85
-        $this->root_path = $root_path;
86
-        $this->php_ext = $php_ext;
87
-
88
-        $this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory');
89
-        $user->add_lang(['ucp', 'posting']);
90
-
91
-        $this->template->assign_vars([
92
-            'S_PHPBB_DIRECTORY'                => true,
93
-            'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
94
-            'S_SIMPLE_MESSAGE'                 => true,
95
-        ]);
96
-
97
-        // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
98
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
99
-            $this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
100
-            $this->captcha->init(CONFIRM_POST);
101
-        }
102
-    }
103
-
104
-    /**
105
-     * Populate form when an error occurred.
106
-     *
107
-     * @param int $link_id    The link ID
108
-     * @param int $comment_id The comment ID
109
-     *
110
-     * @throws \phpbb\exception\http_exception
111
-     *
112
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
113
-     */
114
-    public function delete_comment($link_id, $comment_id)
115
-    {
116
-        $this->_check_comments_enable($link_id);
117
-
118
-        if ($this->request->is_set_post('cancel')) {
119
-            $redirect = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
120
-            redirect($redirect);
121
-        }
122
-
123
-        $sql = 'SELECT *
12
+	private $captcha;
13
+	private $s_comment;
14
+	private $s_hidden_fields = [];
15
+
16
+	/** @var \phpbb\db\driver\driver_interface */
17
+	protected $db;
18
+
19
+	/** @var \phpbb\config\config */
20
+	protected $config;
21
+
22
+	/** @var \phpbb\template\template */
23
+	protected $template;
24
+
25
+	/** @var \phpbb\user */
26
+	protected $user;
27
+
28
+	/** @var \phpbb\controller\helper */
29
+	protected $helper;
30
+
31
+	/** @var \phpbb\request\request */
32
+	protected $request;
33
+
34
+	/** @var \phpbb\auth\auth */
35
+	protected $auth;
36
+
37
+	/** @var \phpbb\pagination */
38
+	protected $pagination;
39
+
40
+	/** @var \phpbb\captcha\factory */
41
+	protected $captcha_factory;
42
+
43
+	/** @var \ernadoo\phpbbdirectory\core\categorie */
44
+	protected $categorie;
45
+
46
+	/** @var \ernadoo\phpbbdirectory\core\comment */
47
+	protected $comment;
48
+
49
+	/** @var string phpBB root path */
50
+	protected $root_path;
51
+
52
+	/** @var string phpEx */
53
+	protected $php_ext;
54
+
55
+	/**
56
+	 * Constructor.
57
+	 *
58
+	 * @param \phpbb\db\driver\driver_interface      $db              Database object
59
+	 * @param \phpbb\config\config                   $config          Config object
60
+	 * @param \phpbb\template\template               $template        Template object
61
+	 * @param \phpbb\user                            $user            User object
62
+	 * @param \phpbb\controller\helper               $helper          Controller helper object
63
+	 * @param \phpbb\request\request                 $request         Request object
64
+	 * @param \phpbb\auth\auth                       $auth            Auth object
65
+	 * @param \phpbb\pagination                      $pagination      Pagination object
66
+	 * @param \phpbb\captcha\factory                 $captcha_factory Captcha object
67
+	 * @param \ernadoo\phpbbdirectory\core\categorie $categorie       PhpBB Directory extension categorie object
68
+	 * @param \ernadoo\phpbbdirectory\core\comment   $comment         PhpBB Directory extension comment object
69
+	 * @param string                                 $root_path       phpBB root path
70
+	 * @param string                                 $php_ext         phpEx
71
+	 */
72
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \phpbb\captcha\factory $captcha_factory, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\comment $comment, $root_path, $php_ext)
73
+	{
74
+		$this->db = $db;
75
+		$this->config = $config;
76
+		$this->template = $template;
77
+		$this->user = $user;
78
+		$this->helper = $helper;
79
+		$this->request = $request;
80
+		$this->auth = $auth;
81
+		$this->pagination = $pagination;
82
+		$this->captcha_factory = $captcha_factory;
83
+		$this->categorie = $categorie;
84
+		$this->comment = $comment;
85
+		$this->root_path = $root_path;
86
+		$this->php_ext = $php_ext;
87
+
88
+		$this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory');
89
+		$user->add_lang(['ucp', 'posting']);
90
+
91
+		$this->template->assign_vars([
92
+			'S_PHPBB_DIRECTORY'                => true,
93
+			'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
94
+			'S_SIMPLE_MESSAGE'                 => true,
95
+		]);
96
+
97
+		// The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
98
+		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
99
+			$this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
100
+			$this->captcha->init(CONFIRM_POST);
101
+		}
102
+	}
103
+
104
+	/**
105
+	 * Populate form when an error occurred.
106
+	 *
107
+	 * @param int $link_id    The link ID
108
+	 * @param int $comment_id The comment ID
109
+	 *
110
+	 * @throws \phpbb\exception\http_exception
111
+	 *
112
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
113
+	 */
114
+	public function delete_comment($link_id, $comment_id)
115
+	{
116
+		$this->_check_comments_enable($link_id);
117
+
118
+		if ($this->request->is_set_post('cancel')) {
119
+			$redirect = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
120
+			redirect($redirect);
121
+		}
122
+
123
+		$sql = 'SELECT *
124 124
 			FROM '.DIR_COMMENT_TABLE.'
125 125
 			WHERE comment_id = '.(int) $comment_id;
126
-        $result = $this->db->sql_query($sql);
127
-        $value = $this->db->sql_fetchrow($result);
128
-
129
-        if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_delete_comment_dir') && (!$this->auth->acl_get('u_delete_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id'])) {
130
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
131
-        }
132
-
133
-        if (confirm_box(true)) {
134
-            $this->comment->del($link_id, $comment_id);
135
-
136
-            $meta_info = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
137
-            meta_refresh(3, $meta_info);
138
-            $message = $this->user->lang['DIR_COMMENT_DELETE_OK'];
139
-            $message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_COMMENT', '<a href="'.$meta_info.'">', '</a>');
140
-
141
-            return $this->helper->message($message);
142
-        } else {
143
-            confirm_box(false, 'DIR_COMMENT_DELETE');
144
-        }
145
-    }
146
-
147
-    /**
148
-     * Edit a comment.
149
-     *
150
-     * @param int $link_id    The category ID
151
-     * @param int $comment_id The comment ID
152
-     *
153
-     * @throws \phpbb\exception\http_exception
154
-     *
155
-     * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
156
-     */
157
-    public function edit_comment($link_id, $comment_id)
158
-    {
159
-        $this->_check_comments_enable($link_id);
160
-
161
-        $sql = 'SELECT *
126
+		$result = $this->db->sql_query($sql);
127
+		$value = $this->db->sql_fetchrow($result);
128
+
129
+		if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_delete_comment_dir') && (!$this->auth->acl_get('u_delete_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id'])) {
130
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
131
+		}
132
+
133
+		if (confirm_box(true)) {
134
+			$this->comment->del($link_id, $comment_id);
135
+
136
+			$meta_info = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
137
+			meta_refresh(3, $meta_info);
138
+			$message = $this->user->lang['DIR_COMMENT_DELETE_OK'];
139
+			$message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_COMMENT', '<a href="'.$meta_info.'">', '</a>');
140
+
141
+			return $this->helper->message($message);
142
+		} else {
143
+			confirm_box(false, 'DIR_COMMENT_DELETE');
144
+		}
145
+	}
146
+
147
+	/**
148
+	 * Edit a comment.
149
+	 *
150
+	 * @param int $link_id    The category ID
151
+	 * @param int $comment_id The comment ID
152
+	 *
153
+	 * @throws \phpbb\exception\http_exception
154
+	 *
155
+	 * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
156
+	 */
157
+	public function edit_comment($link_id, $comment_id)
158
+	{
159
+		$this->_check_comments_enable($link_id);
160
+
161
+		$sql = 'SELECT *
162 162
 			FROM '.DIR_COMMENT_TABLE.'
163 163
 			WHERE comment_id = '.(int) $comment_id;
164
-        $result = $this->db->sql_query($sql);
165
-        $value = $this->db->sql_fetchrow($result);
166
-
167
-        if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_edit_comment_dir') && (!$this->auth->acl_get('u_edit_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id'])) {
168
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
169
-        }
170
-
171
-        $comment_text = generate_text_for_edit($value['comment_text'], $value['comment_uid'], $value['comment_flags']);
172
-        $this->s_comment = $comment_text['text'];
173
-
174
-        $submit = $this->request->is_set_post('update_comment') ? true : false;
175
-
176
-        // If form is done
177
-        if ($submit) {
178
-            return $this->_data_processing($link_id, $comment_id, 'edit');
179
-        }
180
-
181
-        return $this->view($link_id, 1, 'edit');
182
-    }
183
-
184
-    /**
185
-     * Post a new comment.
186
-     *
187
-     * @param int $link_id The category ID
188
-     *
189
-     * @throws \phpbb\exception\http_exception
190
-     *
191
-     * @return null
192
-     */
193
-    public function new_comment($link_id)
194
-    {
195
-        $this->_check_comments_enable($link_id);
196
-
197
-        if (!$this->auth->acl_get('u_comment_dir')) {
198
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
199
-        }
200
-
201
-        $submit = $this->request->is_set_post('submit_comment') ? true : false;
202
-        $refresh = $this->request->is_set_post('refresh_vc') ? true : false;
203
-
204
-        // If form is done
205
-        if ($submit || $refresh) {
206
-            return $this->_data_processing($link_id);
207
-        } else {
208
-            $redirect = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
209
-            redirect($redirect);
210
-        }
211
-    }
212
-
213
-    /**
214
-     * Display popup comment.
215
-     *
216
-     * @param int    $link_id The category ID
217
-     * @param int    $page    Page number taken from the URL
218
-     * @param string $mode    add|edit
219
-     *
220
-     * @throws \phpbb\exception\http_exception
221
-     *
222
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
223
-     */
224
-    public function view($link_id, $page, $mode = 'new')
225
-    {
226
-        $this->_check_comments_enable($link_id);
227
-
228
-        $comment_id = $this->request->variable('c', 0);
229
-        $view = $this->request->variable('view', '');
230
-        $start = ($page - 1) * $this->config['dir_comments_per_page'];
231
-
232
-        $this->s_hidden_fields = array_merge($this->s_hidden_fields, ['page' => $page]);
233
-
234
-        $this->_populate_form($link_id, $mode);
235
-
236
-        $sql = 'SELECT COUNT(comment_id) AS nb_comments
164
+		$result = $this->db->sql_query($sql);
165
+		$value = $this->db->sql_fetchrow($result);
166
+
167
+		if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_edit_comment_dir') && (!$this->auth->acl_get('u_edit_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id'])) {
168
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
169
+		}
170
+
171
+		$comment_text = generate_text_for_edit($value['comment_text'], $value['comment_uid'], $value['comment_flags']);
172
+		$this->s_comment = $comment_text['text'];
173
+
174
+		$submit = $this->request->is_set_post('update_comment') ? true : false;
175
+
176
+		// If form is done
177
+		if ($submit) {
178
+			return $this->_data_processing($link_id, $comment_id, 'edit');
179
+		}
180
+
181
+		return $this->view($link_id, 1, 'edit');
182
+	}
183
+
184
+	/**
185
+	 * Post a new comment.
186
+	 *
187
+	 * @param int $link_id The category ID
188
+	 *
189
+	 * @throws \phpbb\exception\http_exception
190
+	 *
191
+	 * @return null
192
+	 */
193
+	public function new_comment($link_id)
194
+	{
195
+		$this->_check_comments_enable($link_id);
196
+
197
+		if (!$this->auth->acl_get('u_comment_dir')) {
198
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
199
+		}
200
+
201
+		$submit = $this->request->is_set_post('submit_comment') ? true : false;
202
+		$refresh = $this->request->is_set_post('refresh_vc') ? true : false;
203
+
204
+		// If form is done
205
+		if ($submit || $refresh) {
206
+			return $this->_data_processing($link_id);
207
+		} else {
208
+			$redirect = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
209
+			redirect($redirect);
210
+		}
211
+	}
212
+
213
+	/**
214
+	 * Display popup comment.
215
+	 *
216
+	 * @param int    $link_id The category ID
217
+	 * @param int    $page    Page number taken from the URL
218
+	 * @param string $mode    add|edit
219
+	 *
220
+	 * @throws \phpbb\exception\http_exception
221
+	 *
222
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
223
+	 */
224
+	public function view($link_id, $page, $mode = 'new')
225
+	{
226
+		$this->_check_comments_enable($link_id);
227
+
228
+		$comment_id = $this->request->variable('c', 0);
229
+		$view = $this->request->variable('view', '');
230
+		$start = ($page - 1) * $this->config['dir_comments_per_page'];
231
+
232
+		$this->s_hidden_fields = array_merge($this->s_hidden_fields, ['page' => $page]);
233
+
234
+		$this->_populate_form($link_id, $mode);
235
+
236
+		$sql = 'SELECT COUNT(comment_id) AS nb_comments
237 237
 			FROM '.DIR_COMMENT_TABLE.'
238 238
 			WHERE comment_link_id = '.(int) $link_id;
239
-        $result = $this->db->sql_query($sql);
240
-        $nb_comments = (int) $this->db->sql_fetchfield('nb_comments');
241
-        $this->db->sql_freeresult($result);
242
-
243
-        // Make sure $start is set to the last page if it exceeds the amount
244
-        $start = $this->pagination->validate_start($start, $this->config['dir_comments_per_page'], $nb_comments);
245
-
246
-        $sql_array = [
247
-            'SELECT'      => 'a.comment_id, a.comment_user_id, a. comment_user_ip, a.comment_date, a.comment_text, a.comment_uid, a.comment_bitfield, a.comment_flags, u.username, u.user_id, u.user_colour, z.foe',
248
-            'FROM'        => [
249
-                    DIR_COMMENT_TABLE    => 'a', ],
250
-            'LEFT_JOIN'    => [
251
-                    [
252
-                        'FROM'    => [USERS_TABLE => 'u'],
253
-                        'ON'      => 'a.comment_user_id = u.user_id',
254
-                    ],
255
-                    [
256
-                        'FROM'    => [ZEBRA_TABLE => 'z'],
257
-                        'ON'      => 'z.user_id = '.$this->user->data['user_id'].' AND z.zebra_id = a.comment_user_id',
258
-                    ],
259
-            ],
260
-            'WHERE'        => 'a.comment_link_id = '.(int) $link_id,
261
-            'ORDER_BY'     => 'a.comment_date DESC', ];
262
-        $sql = $this->db->sql_build_query('SELECT', $sql_array);
263
-        $result = $this->db->sql_query_limit($sql, $this->config['dir_comments_per_page'], $start);
264
-
265
-        $have_result = false;
266
-
267
-        while ($comments = $this->db->sql_fetchrow($result)) {
268
-            $have_result = true;
269
-
270
-            $edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_comment_dir') || (
271
-                $this->user->data['user_id'] == $comments['comment_user_id'] &&
272
-                $this->auth->acl_get('u_edit_comment_dir')
273
-            )));
274
-
275
-            $delete_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_comment_dir') || (
276
-                $this->user->data['user_id'] == $comments['comment_user_id'] &&
277
-                $this->auth->acl_get('u_delete_comment_dir')
278
-            )));
279
-
280
-            $this->template->assign_block_vars('comment', [
281
-                'MINI_POST_IMG'        => $this->user->img('icon_post_target', 'POST'),
282
-                'S_USER'               => get_username_string('full', $comments['comment_user_id'], $comments['username'], $comments['user_colour']),
283
-                'S_USER_IP'            => $comments['comment_user_ip'],
284
-                'S_DATE'               => $this->user->format_date($comments['comment_date']),
285
-                'S_COMMENT'            => generate_text_for_display($comments['comment_text'], $comments['comment_uid'], $comments['comment_bitfield'], $comments['comment_flags']),
286
-                'S_ID'                 => $comments['comment_id'],
287
-
288
-                'U_EDIT'              => ($edit_allowed) ? $this->helper->route('ernadoo_phpbbdirectory_comment_edit_controller', ['link_id' => (int) $link_id, 'comment_id' => (int) $comments['comment_id']]) : '',
289
-                'U_DELETE'            => ($delete_allowed) ? $this->helper->route('ernadoo_phpbbdirectory_comment_delete_controller', ['link_id' => (int) $link_id, 'comment_id' => (int) $comments['comment_id'], '_referer' => $this->helper->get_current_url()]) : '',
290
-
291
-                'S_IGNORE_POST'        => ($comments['foe'] && ($view != 'show' || $comment_id != $comments['comment_id'])) ? true : false,
292
-                'L_IGNORE_POST'        => ($comments['foe']) ? $this->user->lang('POST_BY_FOE', get_username_string('full', $comments['comment_user_id'], $comments['username'], $comments['user_colour']), '<a href="'.$this->helper->url('directory/link/'.$link_id.'/comment'.(($page > 1) ? '/'.$page : '').'?view=show#c'.(int) $comments['comment_id']).'">', '</a>') : '',
293
-                'L_POST_DISPLAY'       => ($comments['foe']) ? $this->user->lang('POST_DISPLAY', '<a class="display_post" data-post-id="'.$comments['comment_id'].'" href="'.$this->helper->url('directory/link/'.$link_id.'/comment'.(($page > 1) ? '/'.$page : '').'?c='.(int) $comments['comment_id'].'&view=show#c'.(int) $comments['comment_id']).'">', '</a>') : '',
294
-
295
-                'S_INFO'            => $this->auth->acl_get('m_info'),
296
-            ]);
297
-        }
298
-
299
-        $base_url = [
300
-            'routes'    => 'ernadoo_phpbbdirectory_comment_view_controller',
301
-            'params'    => ['link_id' => (int) $link_id],
302
-        ];
303
-
304
-        $this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_comments, $this->config['dir_comments_per_page'], $start);
305
-
306
-        $this->template->assign_vars([
307
-            'TOTAL_COMMENTS'       => $this->user->lang('DIR_NB_COMMS', (int) $nb_comments),
308
-            'S_HAVE_RESULT'        => $have_result ? true : false,
309
-        ]);
310
-
311
-        return $this->helper->render('comments.html', $this->user->lang['DIR_COMMENT_TITLE']);
312
-    }
313
-
314
-    /**
315
-     * Routine.
316
-     *
317
-     * @param int    $link_id    The link ID
318
-     * @param int    $comment_id The comment ID
319
-     * @param string $mode       new|edit
320
-     *
321
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
322
-     */
323
-    private function _data_processing($link_id, $comment_id = 0, $mode = 'new')
324
-    {
325
-        if (!check_form_key('dir_form_comment')) {
326
-            return $this->helper->message('FORM_INVALID');
327
-        }
328
-
329
-        $this->s_comment = $this->request->variable('message', '', true);
330
-
331
-        if (!function_exists('validate_data')) {
332
-            include $this->root_path.'includes/functions_user.'.$this->php_ext;
333
-        }
334
-
335
-        $error = validate_data(
336
-            [
337
-                'reply' => $this->s_comment, ],
338
-            [
339
-                'reply' => [
340
-                    ['string', false, 1, $this->config['dir_length_comments']],
341
-                ],
342
-            ]
343
-        );
344
-
345
-        $error = array_map([$this->user, 'lang'], $error);
346
-
347
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
348
-            $vc_response = $this->captcha->validate();
349
-            if ($vc_response !== false) {
350
-                $error[] = $vc_response;
351
-            }
352
-
353
-            if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
354
-                $error[] = $this->user->lang['TOO_MANY_ADDS'];
355
-            }
356
-        }
357
-
358
-        if (!$error) {
359
-            $uid = $bitfield = $flags = '';
360
-            generate_text_for_storage($this->s_comment, $uid, $bitfield, $flags, (bool) $this->config['dir_allow_bbcode'], (bool) $this->config['dir_allow_links'], (bool) $this->config['dir_allow_smilies']);
361
-
362
-            $data_edit = [
363
-                'comment_text'         => $this->s_comment,
364
-                'comment_uid'          => $uid,
365
-                'comment_flags'        => $flags,
366
-                'comment_bitfield'     => $bitfield,
367
-            ];
368
-
369
-            if ($mode == 'edit') {
370
-                $this->comment->edit($data_edit, $comment_id);
371
-            } else {
372
-                $data_add = [
373
-                    'comment_link_id'     => (int) $link_id,
374
-                    'comment_date'        => time(),
375
-                    'comment_user_id'     => $this->user->data['user_id'],
376
-                    'comment_user_ip'     => $this->user->ip,
377
-                ];
378
-
379
-                $data_add = array_merge($data_edit, $data_add);
380
-
381
-                $this->comment->add($data_add);
382
-            }
383
-
384
-            $meta_info = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
385
-            meta_refresh(3, $meta_info);
386
-            $message = $this->user->lang['DIR_'.strtoupper($mode).'_COMMENT_OK'];
387
-            $message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_COMMENT', '<a href="'.$meta_info.'">', '</a>');
388
-
389
-            return $this->helper->message($message);
390
-        } else {
391
-            $this->template->assign_vars([
392
-                'ERROR'    => (count($error)) ? implode('<br />', $error) : '',
393
-            ]);
394
-
395
-            return $this->view($link_id, $this->request->variable('page', 1), $mode);
396
-        }
397
-    }
398
-
399
-    /**
400
-     * Check if comments are enable in a category.
401
-     *
402
-     * @param int $link_id The link ID
403
-     *
404
-     * @throws \phpbb\exception\http_exception
405
-     *
406
-     * @return null Retun null if comments are allowed, http_exception if not
407
-     */
408
-    private function _check_comments_enable($link_id)
409
-    {
410
-        $sql = 'SELECT link_cat
239
+		$result = $this->db->sql_query($sql);
240
+		$nb_comments = (int) $this->db->sql_fetchfield('nb_comments');
241
+		$this->db->sql_freeresult($result);
242
+
243
+		// Make sure $start is set to the last page if it exceeds the amount
244
+		$start = $this->pagination->validate_start($start, $this->config['dir_comments_per_page'], $nb_comments);
245
+
246
+		$sql_array = [
247
+			'SELECT'      => 'a.comment_id, a.comment_user_id, a. comment_user_ip, a.comment_date, a.comment_text, a.comment_uid, a.comment_bitfield, a.comment_flags, u.username, u.user_id, u.user_colour, z.foe',
248
+			'FROM'        => [
249
+					DIR_COMMENT_TABLE    => 'a', ],
250
+			'LEFT_JOIN'    => [
251
+					[
252
+						'FROM'    => [USERS_TABLE => 'u'],
253
+						'ON'      => 'a.comment_user_id = u.user_id',
254
+					],
255
+					[
256
+						'FROM'    => [ZEBRA_TABLE => 'z'],
257
+						'ON'      => 'z.user_id = '.$this->user->data['user_id'].' AND z.zebra_id = a.comment_user_id',
258
+					],
259
+			],
260
+			'WHERE'        => 'a.comment_link_id = '.(int) $link_id,
261
+			'ORDER_BY'     => 'a.comment_date DESC', ];
262
+		$sql = $this->db->sql_build_query('SELECT', $sql_array);
263
+		$result = $this->db->sql_query_limit($sql, $this->config['dir_comments_per_page'], $start);
264
+
265
+		$have_result = false;
266
+
267
+		while ($comments = $this->db->sql_fetchrow($result)) {
268
+			$have_result = true;
269
+
270
+			$edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_comment_dir') || (
271
+				$this->user->data['user_id'] == $comments['comment_user_id'] &&
272
+				$this->auth->acl_get('u_edit_comment_dir')
273
+			)));
274
+
275
+			$delete_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_comment_dir') || (
276
+				$this->user->data['user_id'] == $comments['comment_user_id'] &&
277
+				$this->auth->acl_get('u_delete_comment_dir')
278
+			)));
279
+
280
+			$this->template->assign_block_vars('comment', [
281
+				'MINI_POST_IMG'        => $this->user->img('icon_post_target', 'POST'),
282
+				'S_USER'               => get_username_string('full', $comments['comment_user_id'], $comments['username'], $comments['user_colour']),
283
+				'S_USER_IP'            => $comments['comment_user_ip'],
284
+				'S_DATE'               => $this->user->format_date($comments['comment_date']),
285
+				'S_COMMENT'            => generate_text_for_display($comments['comment_text'], $comments['comment_uid'], $comments['comment_bitfield'], $comments['comment_flags']),
286
+				'S_ID'                 => $comments['comment_id'],
287
+
288
+				'U_EDIT'              => ($edit_allowed) ? $this->helper->route('ernadoo_phpbbdirectory_comment_edit_controller', ['link_id' => (int) $link_id, 'comment_id' => (int) $comments['comment_id']]) : '',
289
+				'U_DELETE'            => ($delete_allowed) ? $this->helper->route('ernadoo_phpbbdirectory_comment_delete_controller', ['link_id' => (int) $link_id, 'comment_id' => (int) $comments['comment_id'], '_referer' => $this->helper->get_current_url()]) : '',
290
+
291
+				'S_IGNORE_POST'        => ($comments['foe'] && ($view != 'show' || $comment_id != $comments['comment_id'])) ? true : false,
292
+				'L_IGNORE_POST'        => ($comments['foe']) ? $this->user->lang('POST_BY_FOE', get_username_string('full', $comments['comment_user_id'], $comments['username'], $comments['user_colour']), '<a href="'.$this->helper->url('directory/link/'.$link_id.'/comment'.(($page > 1) ? '/'.$page : '').'?view=show#c'.(int) $comments['comment_id']).'">', '</a>') : '',
293
+				'L_POST_DISPLAY'       => ($comments['foe']) ? $this->user->lang('POST_DISPLAY', '<a class="display_post" data-post-id="'.$comments['comment_id'].'" href="'.$this->helper->url('directory/link/'.$link_id.'/comment'.(($page > 1) ? '/'.$page : '').'?c='.(int) $comments['comment_id'].'&view=show#c'.(int) $comments['comment_id']).'">', '</a>') : '',
294
+
295
+				'S_INFO'            => $this->auth->acl_get('m_info'),
296
+			]);
297
+		}
298
+
299
+		$base_url = [
300
+			'routes'    => 'ernadoo_phpbbdirectory_comment_view_controller',
301
+			'params'    => ['link_id' => (int) $link_id],
302
+		];
303
+
304
+		$this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_comments, $this->config['dir_comments_per_page'], $start);
305
+
306
+		$this->template->assign_vars([
307
+			'TOTAL_COMMENTS'       => $this->user->lang('DIR_NB_COMMS', (int) $nb_comments),
308
+			'S_HAVE_RESULT'        => $have_result ? true : false,
309
+		]);
310
+
311
+		return $this->helper->render('comments.html', $this->user->lang['DIR_COMMENT_TITLE']);
312
+	}
313
+
314
+	/**
315
+	 * Routine.
316
+	 *
317
+	 * @param int    $link_id    The link ID
318
+	 * @param int    $comment_id The comment ID
319
+	 * @param string $mode       new|edit
320
+	 *
321
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
322
+	 */
323
+	private function _data_processing($link_id, $comment_id = 0, $mode = 'new')
324
+	{
325
+		if (!check_form_key('dir_form_comment')) {
326
+			return $this->helper->message('FORM_INVALID');
327
+		}
328
+
329
+		$this->s_comment = $this->request->variable('message', '', true);
330
+
331
+		if (!function_exists('validate_data')) {
332
+			include $this->root_path.'includes/functions_user.'.$this->php_ext;
333
+		}
334
+
335
+		$error = validate_data(
336
+			[
337
+				'reply' => $this->s_comment, ],
338
+			[
339
+				'reply' => [
340
+					['string', false, 1, $this->config['dir_length_comments']],
341
+				],
342
+			]
343
+		);
344
+
345
+		$error = array_map([$this->user, 'lang'], $error);
346
+
347
+		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
348
+			$vc_response = $this->captcha->validate();
349
+			if ($vc_response !== false) {
350
+				$error[] = $vc_response;
351
+			}
352
+
353
+			if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
354
+				$error[] = $this->user->lang['TOO_MANY_ADDS'];
355
+			}
356
+		}
357
+
358
+		if (!$error) {
359
+			$uid = $bitfield = $flags = '';
360
+			generate_text_for_storage($this->s_comment, $uid, $bitfield, $flags, (bool) $this->config['dir_allow_bbcode'], (bool) $this->config['dir_allow_links'], (bool) $this->config['dir_allow_smilies']);
361
+
362
+			$data_edit = [
363
+				'comment_text'         => $this->s_comment,
364
+				'comment_uid'          => $uid,
365
+				'comment_flags'        => $flags,
366
+				'comment_bitfield'     => $bitfield,
367
+			];
368
+
369
+			if ($mode == 'edit') {
370
+				$this->comment->edit($data_edit, $comment_id);
371
+			} else {
372
+				$data_add = [
373
+					'comment_link_id'     => (int) $link_id,
374
+					'comment_date'        => time(),
375
+					'comment_user_id'     => $this->user->data['user_id'],
376
+					'comment_user_ip'     => $this->user->ip,
377
+				];
378
+
379
+				$data_add = array_merge($data_edit, $data_add);
380
+
381
+				$this->comment->add($data_add);
382
+			}
383
+
384
+			$meta_info = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
385
+			meta_refresh(3, $meta_info);
386
+			$message = $this->user->lang['DIR_'.strtoupper($mode).'_COMMENT_OK'];
387
+			$message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_COMMENT', '<a href="'.$meta_info.'">', '</a>');
388
+
389
+			return $this->helper->message($message);
390
+		} else {
391
+			$this->template->assign_vars([
392
+				'ERROR'    => (count($error)) ? implode('<br />', $error) : '',
393
+			]);
394
+
395
+			return $this->view($link_id, $this->request->variable('page', 1), $mode);
396
+		}
397
+	}
398
+
399
+	/**
400
+	 * Check if comments are enable in a category.
401
+	 *
402
+	 * @param int $link_id The link ID
403
+	 *
404
+	 * @throws \phpbb\exception\http_exception
405
+	 *
406
+	 * @return null Retun null if comments are allowed, http_exception if not
407
+	 */
408
+	private function _check_comments_enable($link_id)
409
+	{
410
+		$sql = 'SELECT link_cat
411 411
 			FROM '.DIR_LINK_TABLE.'
412 412
 			WHERE link_id = '.(int) $link_id;
413
-        $result = $this->db->sql_query($sql);
414
-        $cat_id = (int) $this->db->sql_fetchfield('link_cat');
415
-        $this->db->sql_freeresult($result);
416
-
417
-        if ($cat_id) {
418
-            $this->categorie->get($cat_id);
419
-
420
-            if (!$this->categorie->data['cat_allow_comments']) {
421
-                throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
422
-            }
423
-        } else {
424
-            throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
425
-        }
426
-    }
427
-
428
-    /**
429
-     * Populate form when an error occurred.
430
-     *
431
-     * @param int    $link_id The link ID
432
-     * @param string $mode    add|edit
433
-     *
434
-     * @return null
435
-     */
436
-    private function _populate_form($link_id, $mode)
437
-    {
438
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode != 'edit') {
439
-            $this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
440
-
441
-            $this->template->assign_vars([
442
-                'S_CONFIRM_CODE'          => true,
443
-                'CAPTCHA_TEMPLATE'        => $this->captcha->get_template(),
444
-            ]);
445
-        }
446
-
447
-        if (!function_exists('generate_smilies')) {
448
-            include $this->root_path.'includes/functions_posting.'.$this->php_ext;
449
-        }
450
-        if (!function_exists('display_custom_bbcodes')) {
451
-            include $this->root_path.'includes/functions_display.'.$this->php_ext;
452
-        }
453
-
454
-        generate_smilies('inline', 0);
455
-        display_custom_bbcodes();
456
-        add_form_key('dir_form_comment');
457
-
458
-        $this->template->assign_vars([
459
-            'S_AUTH_COMM'        => $this->auth->acl_get('u_comment_dir'),
460
-
461
-            'BBCODE_STATUS'        => ($this->config['dir_allow_bbcode']) ? $this->user->lang('BBCODE_IS_ON', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>') : $this->user->lang('BBCODE_IS_OFF', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>'),
462
-            'IMG_STATUS'           => ($this->config['dir_allow_bbcode']) ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'],
463
-            'SMILIES_STATUS'       => ($this->config['dir_allow_smilies']) ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'],
464
-            'URL_STATUS'           => ($this->config['dir_allow_links']) ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'],
465
-            'FLASH_STATUS'         => ($this->config['dir_allow_bbcode'] && $this->config['dir_allow_flash']) ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'],
466
-
467
-            'L_DIR_REPLY_EXP'    => $this->user->lang('DIR_REPLY_EXP', $this->config['dir_length_comments']),
468
-
469
-            'S_COMMENT'        => isset($this->s_comment) ? $this->s_comment : '',
470
-
471
-            'S_BBCODE_ALLOWED'    => (bool) $this->config['dir_allow_bbcode'],
472
-            'S_BBCODE_IMG'        => (bool) $this->config['dir_allow_bbcode'],
473
-            'S_BBCODE_FLASH'      => ($this->config['dir_allow_bbcode'] && $this->config['dir_allow_flash']) ? true : false,
474
-            'S_BBCODE_QUOTE'      => true,
475
-            'S_LINKS_ALLOWED'     => (bool) $this->config['dir_allow_links'],
476
-            'S_SMILIES_ALLOWED'   => (bool) $this->config['dir_allow_smilies'],
477
-
478
-            'S_HIDDEN_FIELDS'      => build_hidden_fields($this->s_hidden_fields),
479
-            'S_BUTTON_NAME'        => ($mode == 'edit') ? 'update_comment' : 'submit_comment',
480
-            'S_POST_ACTION'        => ($mode == 'edit') ? '' : $this->helper->route('ernadoo_phpbbdirectory_comment_new_controller', ['link_id' => (int) $link_id]),
481
-        ]);
482
-    }
413
+		$result = $this->db->sql_query($sql);
414
+		$cat_id = (int) $this->db->sql_fetchfield('link_cat');
415
+		$this->db->sql_freeresult($result);
416
+
417
+		if ($cat_id) {
418
+			$this->categorie->get($cat_id);
419
+
420
+			if (!$this->categorie->data['cat_allow_comments']) {
421
+				throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
422
+			}
423
+		} else {
424
+			throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
425
+		}
426
+	}
427
+
428
+	/**
429
+	 * Populate form when an error occurred.
430
+	 *
431
+	 * @param int    $link_id The link ID
432
+	 * @param string $mode    add|edit
433
+	 *
434
+	 * @return null
435
+	 */
436
+	private function _populate_form($link_id, $mode)
437
+	{
438
+		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode != 'edit') {
439
+			$this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
440
+
441
+			$this->template->assign_vars([
442
+				'S_CONFIRM_CODE'          => true,
443
+				'CAPTCHA_TEMPLATE'        => $this->captcha->get_template(),
444
+			]);
445
+		}
446
+
447
+		if (!function_exists('generate_smilies')) {
448
+			include $this->root_path.'includes/functions_posting.'.$this->php_ext;
449
+		}
450
+		if (!function_exists('display_custom_bbcodes')) {
451
+			include $this->root_path.'includes/functions_display.'.$this->php_ext;
452
+		}
453
+
454
+		generate_smilies('inline', 0);
455
+		display_custom_bbcodes();
456
+		add_form_key('dir_form_comment');
457
+
458
+		$this->template->assign_vars([
459
+			'S_AUTH_COMM'        => $this->auth->acl_get('u_comment_dir'),
460
+
461
+			'BBCODE_STATUS'        => ($this->config['dir_allow_bbcode']) ? $this->user->lang('BBCODE_IS_ON', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>') : $this->user->lang('BBCODE_IS_OFF', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>'),
462
+			'IMG_STATUS'           => ($this->config['dir_allow_bbcode']) ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'],
463
+			'SMILIES_STATUS'       => ($this->config['dir_allow_smilies']) ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'],
464
+			'URL_STATUS'           => ($this->config['dir_allow_links']) ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'],
465
+			'FLASH_STATUS'         => ($this->config['dir_allow_bbcode'] && $this->config['dir_allow_flash']) ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'],
466
+
467
+			'L_DIR_REPLY_EXP'    => $this->user->lang('DIR_REPLY_EXP', $this->config['dir_length_comments']),
468
+
469
+			'S_COMMENT'        => isset($this->s_comment) ? $this->s_comment : '',
470
+
471
+			'S_BBCODE_ALLOWED'    => (bool) $this->config['dir_allow_bbcode'],
472
+			'S_BBCODE_IMG'        => (bool) $this->config['dir_allow_bbcode'],
473
+			'S_BBCODE_FLASH'      => ($this->config['dir_allow_bbcode'] && $this->config['dir_allow_flash']) ? true : false,
474
+			'S_BBCODE_QUOTE'      => true,
475
+			'S_LINKS_ALLOWED'     => (bool) $this->config['dir_allow_links'],
476
+			'S_SMILIES_ALLOWED'   => (bool) $this->config['dir_allow_smilies'],
477
+
478
+			'S_HIDDEN_FIELDS'      => build_hidden_fields($this->s_hidden_fields),
479
+			'S_BUTTON_NAME'        => ($mode == 'edit') ? 'update_comment' : 'submit_comment',
480
+			'S_POST_ACTION'        => ($mode == 'edit') ? '' : $this->helper->route('ernadoo_phpbbdirectory_comment_new_controller', ['link_id' => (int) $link_id]),
481
+		]);
482
+	}
483 483
 }
Please login to merge, or discard this patch.
Braces   +57 added lines, -26 removed lines patch added patch discarded remove patch
@@ -95,7 +95,8 @@  discard block
 block discarded – undo
95 95
         ]);
96 96
 
97 97
         // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
98
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
98
+        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'])
99
+        {
99 100
             $this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
100 101
             $this->captcha->init(CONFIRM_POST);
101 102
         }
@@ -115,7 +116,8 @@  discard block
 block discarded – undo
115 116
     {
116 117
         $this->_check_comments_enable($link_id);
117 118
 
118
-        if ($this->request->is_set_post('cancel')) {
119
+        if ($this->request->is_set_post('cancel'))
120
+        {
119 121
             $redirect = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
120 122
             redirect($redirect);
121 123
         }
@@ -126,11 +128,13 @@  discard block
 block discarded – undo
126 128
         $result = $this->db->sql_query($sql);
127 129
         $value = $this->db->sql_fetchrow($result);
128 130
 
129
-        if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_delete_comment_dir') && (!$this->auth->acl_get('u_delete_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id'])) {
131
+        if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_delete_comment_dir') && (!$this->auth->acl_get('u_delete_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id']))
132
+        {
130 133
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
131 134
         }
132 135
 
133
-        if (confirm_box(true)) {
136
+        if (confirm_box(true))
137
+        {
134 138
             $this->comment->del($link_id, $comment_id);
135 139
 
136 140
             $meta_info = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
@@ -139,7 +143,9 @@  discard block
 block discarded – undo
139 143
             $message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_COMMENT', '<a href="'.$meta_info.'">', '</a>');
140 144
 
141 145
             return $this->helper->message($message);
142
-        } else {
146
+        }
147
+        else
148
+        {
143 149
             confirm_box(false, 'DIR_COMMENT_DELETE');
144 150
         }
145 151
     }
@@ -164,7 +170,8 @@  discard block
 block discarded – undo
164 170
         $result = $this->db->sql_query($sql);
165 171
         $value = $this->db->sql_fetchrow($result);
166 172
 
167
-        if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_edit_comment_dir') && (!$this->auth->acl_get('u_edit_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id'])) {
173
+        if (!$this->user->data['is_registered'] || !$this->auth->acl_get('m_edit_comment_dir') && (!$this->auth->acl_get('u_edit_comment_dir') || $this->user->data['user_id'] != $value['comment_user_id']))
174
+        {
168 175
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
169 176
         }
170 177
 
@@ -174,7 +181,8 @@  discard block
 block discarded – undo
174 181
         $submit = $this->request->is_set_post('update_comment') ? true : false;
175 182
 
176 183
         // If form is done
177
-        if ($submit) {
184
+        if ($submit)
185
+        {
178 186
             return $this->_data_processing($link_id, $comment_id, 'edit');
179 187
         }
180 188
 
@@ -194,7 +202,8 @@  discard block
 block discarded – undo
194 202
     {
195 203
         $this->_check_comments_enable($link_id);
196 204
 
197
-        if (!$this->auth->acl_get('u_comment_dir')) {
205
+        if (!$this->auth->acl_get('u_comment_dir'))
206
+        {
198 207
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
199 208
         }
200 209
 
@@ -202,9 +211,12 @@  discard block
 block discarded – undo
202 211
         $refresh = $this->request->is_set_post('refresh_vc') ? true : false;
203 212
 
204 213
         // If form is done
205
-        if ($submit || $refresh) {
214
+        if ($submit || $refresh)
215
+        {
206 216
             return $this->_data_processing($link_id);
207
-        } else {
217
+        }
218
+        else
219
+        {
208 220
             $redirect = $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $link_id]);
209 221
             redirect($redirect);
210 222
         }
@@ -264,7 +276,8 @@  discard block
 block discarded – undo
264 276
 
265 277
         $have_result = false;
266 278
 
267
-        while ($comments = $this->db->sql_fetchrow($result)) {
279
+        while ($comments = $this->db->sql_fetchrow($result))
280
+        {
268 281
             $have_result = true;
269 282
 
270 283
             $edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_comment_dir') || (
@@ -322,13 +335,15 @@  discard block
 block discarded – undo
322 335
      */
323 336
     private function _data_processing($link_id, $comment_id = 0, $mode = 'new')
324 337
     {
325
-        if (!check_form_key('dir_form_comment')) {
338
+        if (!check_form_key('dir_form_comment'))
339
+        {
326 340
             return $this->helper->message('FORM_INVALID');
327 341
         }
328 342
 
329 343
         $this->s_comment = $this->request->variable('message', '', true);
330 344
 
331
-        if (!function_exists('validate_data')) {
345
+        if (!function_exists('validate_data'))
346
+        {
332 347
             include $this->root_path.'includes/functions_user.'.$this->php_ext;
333 348
         }
334 349
 
@@ -344,18 +359,22 @@  discard block
 block discarded – undo
344 359
 
345 360
         $error = array_map([$this->user, 'lang'], $error);
346 361
 
347
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
362
+        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'])
363
+        {
348 364
             $vc_response = $this->captcha->validate();
349
-            if ($vc_response !== false) {
365
+            if ($vc_response !== false)
366
+            {
350 367
                 $error[] = $vc_response;
351 368
             }
352 369
 
353
-            if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
370
+            if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts'])
371
+            {
354 372
                 $error[] = $this->user->lang['TOO_MANY_ADDS'];
355 373
             }
356 374
         }
357 375
 
358
-        if (!$error) {
376
+        if (!$error)
377
+        {
359 378
             $uid = $bitfield = $flags = '';
360 379
             generate_text_for_storage($this->s_comment, $uid, $bitfield, $flags, (bool) $this->config['dir_allow_bbcode'], (bool) $this->config['dir_allow_links'], (bool) $this->config['dir_allow_smilies']);
361 380
 
@@ -366,9 +385,12 @@  discard block
 block discarded – undo
366 385
                 'comment_bitfield'     => $bitfield,
367 386
             ];
368 387
 
369
-            if ($mode == 'edit') {
388
+            if ($mode == 'edit')
389
+            {
370 390
                 $this->comment->edit($data_edit, $comment_id);
371
-            } else {
391
+            }
392
+            else
393
+            {
372 394
                 $data_add = [
373 395
                     'comment_link_id'     => (int) $link_id,
374 396
                     'comment_date'        => time(),
@@ -387,7 +409,9 @@  discard block
 block discarded – undo
387 409
             $message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_COMMENT', '<a href="'.$meta_info.'">', '</a>');
388 410
 
389 411
             return $this->helper->message($message);
390
-        } else {
412
+        }
413
+        else
414
+        {
391 415
             $this->template->assign_vars([
392 416
                 'ERROR'    => (count($error)) ? implode('<br />', $error) : '',
393 417
             ]);
@@ -414,13 +438,17 @@  discard block
 block discarded – undo
414 438
         $cat_id = (int) $this->db->sql_fetchfield('link_cat');
415 439
         $this->db->sql_freeresult($result);
416 440
 
417
-        if ($cat_id) {
441
+        if ($cat_id)
442
+        {
418 443
             $this->categorie->get($cat_id);
419 444
 
420
-            if (!$this->categorie->data['cat_allow_comments']) {
445
+            if (!$this->categorie->data['cat_allow_comments'])
446
+            {
421 447
                 throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
422 448
             }
423
-        } else {
449
+        }
450
+        else
451
+        {
424 452
             throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
425 453
         }
426 454
     }
@@ -435,7 +463,8 @@  discard block
 block discarded – undo
435 463
      */
436 464
     private function _populate_form($link_id, $mode)
437 465
     {
438
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode != 'edit') {
466
+        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode != 'edit')
467
+        {
439 468
             $this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
440 469
 
441 470
             $this->template->assign_vars([
@@ -444,10 +473,12 @@  discard block
 block discarded – undo
444 473
             ]);
445 474
         }
446 475
 
447
-        if (!function_exists('generate_smilies')) {
476
+        if (!function_exists('generate_smilies'))
477
+        {
448 478
             include $this->root_path.'includes/functions_posting.'.$this->php_ext;
449 479
         }
450
-        if (!function_exists('display_custom_bbcodes')) {
480
+        if (!function_exists('display_custom_bbcodes'))
481
+        {
451 482
             include $this->root_path.'includes/functions_display.'.$this->php_ext;
452 483
         }
453 484
 
Please login to merge, or discard this patch.
ext.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@
 block discarded – undo
142 142
      * @license GNU General Public License, version 2 (GPL-2.0)
143 143
      *
144 144
      * @param string $step               The step (enable, disable, purge)
145
-     * @param array  $notification_types The notification type names
145
+     * @param string[]  $notification_types The notification type names
146 146
      *
147 147
      * @return string Return notifications as temporary state
148 148
      */
Please login to merge, or discard this patch.
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -14,146 +14,146 @@
 block discarded – undo
14 14
 
15 15
 class ext extends \phpbb\extension\base
16 16
 {
17
-    /**
18
-     * Enable extension if requirements are met.
19
-     *
20
-     * @return bool
21
-     * @aceess public
22
-     */
23
-    public function is_enableable()
24
-    {
25
-        $config = $this->container->get('config');
26
-
27
-        // Check phpbb version
28
-        if (!version_compare($config['version'], '3.1.3', '>=')) {
29
-            return false;
30
-        }
31
-
32
-        // Check for getimagesize
33
-        if (!@function_exists('getimagesize')) {
34
-            return false;
35
-        }
36
-
37
-        // Check for url_fopen
38
-        return (bool) @ini_get('allow_url_fopen');
39
-    }
40
-
41
-    /**
42
-     * Single enable step that installs any included migrations.
43
-     *
44
-     * @param mixed $old_state State returned by previous call of this method
45
-     *
46
-     * @return mixed Returns false after last step, otherwise temporary state
47
-     */
48
-    public function enable_step($old_state)
49
-    {
50
-        switch ($old_state) {
51
-            case '': // Empty means nothing has run yet
52
-
53
-                // Enable notifications
54
-                return $this->notification_handler('enable', [
55
-                    'ernadoo.phpbbdirectory.notification.type.directory_website',
56
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_approved',
57
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved',
58
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron',
59
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
60
-                ]);
61
-
62
-            break;
63
-
64
-            default:
65
-
66
-                // Run parent enable step method
67
-                return parent::enable_step($old_state);
68
-
69
-            break;
70
-        }
71
-    }
72
-
73
-    /**
74
-     * Single disable step that does nothing.
75
-     *
76
-     * @param mixed $old_state State returned by previous call of this method
77
-     *
78
-     * @return mixed Returns false after last step, otherwise temporary state
79
-     */
80
-    public function disable_step($old_state)
81
-    {
82
-        switch ($old_state) {
83
-            case '': // Empty means nothing has run yet
84
-
85
-                // Disable notifications
86
-                return $this->notification_handler('disable', [
87
-                    'ernadoo.phpbbdirectory.notification.type.directory_website',
88
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_approved',
89
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved',
90
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron',
91
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
92
-                ]);
93
-
94
-            break;
95
-
96
-            default:
97
-
98
-                // Run parent disable step method
99
-                return parent::disable_step($old_state);
100
-
101
-            break;
102
-        }
103
-    }
104
-
105
-    /**
106
-     * Single purge step that reverts any included and installed migrations.
107
-     *
108
-     * @param mixed $old_state State returned by previous call of this method
109
-     *
110
-     * @return mixed Returns false after last step, otherwise temporary state
111
-     */
112
-    public function purge_step($old_state)
113
-    {
114
-        switch ($old_state) {
115
-            case '': // Empty means nothing has run yet
116
-
117
-                // Purge notifications
118
-                return $this->notification_handler('purge', [
119
-                    'ernadoo.phpbbdirectory.notification.type.directory_website',
120
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_approved',
121
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved',
122
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron',
123
-                    'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
124
-                ]);
125
-
126
-            break;
127
-
128
-            default:
129
-
130
-                // Run parent purge step method
131
-                return parent::purge_step($old_state);
132
-
133
-            break;
134
-        }
135
-    }
136
-
137
-    /**
138
-     * Notification handler to call notification enable/disable/purge steps.
139
-     *
140
-     * @author VSEphpbb (Matt Friedman)
141
-     * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
142
-     * @license GNU General Public License, version 2 (GPL-2.0)
143
-     *
144
-     * @param string $step               The step (enable, disable, purge)
145
-     * @param array  $notification_types The notification type names
146
-     *
147
-     * @return string Return notifications as temporary state
148
-     */
149
-    protected function notification_handler($step, $notification_types)
150
-    {
151
-        $phpbb_notifications = $this->container->get('notification_manager');
152
-
153
-        foreach ($notification_types as $notification_type) {
154
-            call_user_func([$phpbb_notifications, $step.'_notifications'], $notification_type);
155
-        }
156
-
157
-        return 'notifications';
158
-    }
17
+	/**
18
+	 * Enable extension if requirements are met.
19
+	 *
20
+	 * @return bool
21
+	 * @aceess public
22
+	 */
23
+	public function is_enableable()
24
+	{
25
+		$config = $this->container->get('config');
26
+
27
+		// Check phpbb version
28
+		if (!version_compare($config['version'], '3.1.3', '>=')) {
29
+			return false;
30
+		}
31
+
32
+		// Check for getimagesize
33
+		if (!@function_exists('getimagesize')) {
34
+			return false;
35
+		}
36
+
37
+		// Check for url_fopen
38
+		return (bool) @ini_get('allow_url_fopen');
39
+	}
40
+
41
+	/**
42
+	 * Single enable step that installs any included migrations.
43
+	 *
44
+	 * @param mixed $old_state State returned by previous call of this method
45
+	 *
46
+	 * @return mixed Returns false after last step, otherwise temporary state
47
+	 */
48
+	public function enable_step($old_state)
49
+	{
50
+		switch ($old_state) {
51
+			case '': // Empty means nothing has run yet
52
+
53
+				// Enable notifications
54
+				return $this->notification_handler('enable', [
55
+					'ernadoo.phpbbdirectory.notification.type.directory_website',
56
+					'ernadoo.phpbbdirectory.notification.type.directory_website_approved',
57
+					'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved',
58
+					'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron',
59
+					'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
60
+				]);
61
+
62
+			break;
63
+
64
+			default:
65
+
66
+				// Run parent enable step method
67
+				return parent::enable_step($old_state);
68
+
69
+			break;
70
+		}
71
+	}
72
+
73
+	/**
74
+	 * Single disable step that does nothing.
75
+	 *
76
+	 * @param mixed $old_state State returned by previous call of this method
77
+	 *
78
+	 * @return mixed Returns false after last step, otherwise temporary state
79
+	 */
80
+	public function disable_step($old_state)
81
+	{
82
+		switch ($old_state) {
83
+			case '': // Empty means nothing has run yet
84
+
85
+				// Disable notifications
86
+				return $this->notification_handler('disable', [
87
+					'ernadoo.phpbbdirectory.notification.type.directory_website',
88
+					'ernadoo.phpbbdirectory.notification.type.directory_website_approved',
89
+					'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved',
90
+					'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron',
91
+					'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
92
+				]);
93
+
94
+			break;
95
+
96
+			default:
97
+
98
+				// Run parent disable step method
99
+				return parent::disable_step($old_state);
100
+
101
+			break;
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * Single purge step that reverts any included and installed migrations.
107
+	 *
108
+	 * @param mixed $old_state State returned by previous call of this method
109
+	 *
110
+	 * @return mixed Returns false after last step, otherwise temporary state
111
+	 */
112
+	public function purge_step($old_state)
113
+	{
114
+		switch ($old_state) {
115
+			case '': // Empty means nothing has run yet
116
+
117
+				// Purge notifications
118
+				return $this->notification_handler('purge', [
119
+					'ernadoo.phpbbdirectory.notification.type.directory_website',
120
+					'ernadoo.phpbbdirectory.notification.type.directory_website_approved',
121
+					'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved',
122
+					'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron',
123
+					'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
124
+				]);
125
+
126
+			break;
127
+
128
+			default:
129
+
130
+				// Run parent purge step method
131
+				return parent::purge_step($old_state);
132
+
133
+			break;
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * Notification handler to call notification enable/disable/purge steps.
139
+	 *
140
+	 * @author VSEphpbb (Matt Friedman)
141
+	 * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
142
+	 * @license GNU General Public License, version 2 (GPL-2.0)
143
+	 *
144
+	 * @param string $step               The step (enable, disable, purge)
145
+	 * @param array  $notification_types The notification type names
146
+	 *
147
+	 * @return string Return notifications as temporary state
148
+	 */
149
+	protected function notification_handler($step, $notification_types)
150
+	{
151
+		$phpbb_notifications = $this->container->get('notification_manager');
152
+
153
+		foreach ($notification_types as $notification_type) {
154
+			call_user_func([$phpbb_notifications, $step.'_notifications'], $notification_type);
155
+		}
156
+
157
+		return 'notifications';
158
+	}
159 159
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,12 +25,14 @@  discard block
 block discarded – undo
25 25
         $config = $this->container->get('config');
26 26
 
27 27
         // Check phpbb version
28
-        if (!version_compare($config['version'], '3.1.3', '>=')) {
28
+        if (!version_compare($config['version'], '3.1.3', '>='))
29
+        {
29 30
             return false;
30 31
         }
31 32
 
32 33
         // Check for getimagesize
33
-        if (!@function_exists('getimagesize')) {
34
+        if (!@function_exists('getimagesize'))
35
+        {
34 36
             return false;
35 37
         }
36 38
 
@@ -47,7 +49,8 @@  discard block
 block discarded – undo
47 49
      */
48 50
     public function enable_step($old_state)
49 51
     {
50
-        switch ($old_state) {
52
+        switch ($old_state)
53
+        {
51 54
             case '': // Empty means nothing has run yet
52 55
 
53 56
                 // Enable notifications
@@ -79,7 +82,8 @@  discard block
 block discarded – undo
79 82
      */
80 83
     public function disable_step($old_state)
81 84
     {
82
-        switch ($old_state) {
85
+        switch ($old_state)
86
+        {
83 87
             case '': // Empty means nothing has run yet
84 88
 
85 89
                 // Disable notifications
@@ -111,7 +115,8 @@  discard block
 block discarded – undo
111 115
      */
112 116
     public function purge_step($old_state)
113 117
     {
114
-        switch ($old_state) {
118
+        switch ($old_state)
119
+        {
115 120
             case '': // Empty means nothing has run yet
116 121
 
117 122
                 // Purge notifications
@@ -150,7 +155,8 @@  discard block
 block discarded – undo
150 155
     {
151 156
         $phpbb_notifications = $this->container->get('notification_manager');
152 157
 
153
-        foreach ($notification_types as $notification_type) {
158
+        foreach ($notification_types as $notification_type)
159
+        {
154 160
             call_user_func([$phpbb_notifications, $step.'_notifications'], $notification_type);
155 161
         }
156 162
 
Please login to merge, or discard this patch.
controller/categories.php 2 patches
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -9,354 +9,354 @@
 block discarded – undo
9 9
 
10 10
 class categories
11 11
 {
12
-    /** @var \phpbb\db\driver\driver_interface */
13
-    protected $db;
14
-
15
-    /** @var \phpbb\config\config */
16
-    protected $config;
17
-
18
-    /** @var \phpbb\template\template */
19
-    protected $template;
20
-
21
-    /** @var \phpbb\user */
22
-    protected $user;
23
-
24
-    /** @var \phpbb\controller\helper */
25
-    protected $helper;
26
-
27
-    /** @var \phpbb\request\request */
28
-    protected $request;
29
-
30
-    /** @var \phpbb\auth\auth */
31
-    protected $auth;
32
-
33
-    /** @var \phpbb\pagination */
34
-    protected $pagination;
35
-
36
-    /** @var \ernadoo\phpbbdirectory\core\categorie */
37
-    protected $categorie;
38
-
39
-    /** @var \ernadoo\phpbbdirectory\core\link */
40
-    protected $link;
41
-
42
-    /**
43
-     * Constructor.
44
-     *
45
-     * @param \phpbb\db\driver\driver_interface      $db         Database object
46
-     * @param \phpbb\config\config                   $config     Config object
47
-     * @param \phpbb\template\template               $template   Template object
48
-     * @param \phpbb\user                            $user       User object
49
-     * @param \phpbb\controller\helper               $helper     Controller helper object
50
-     * @param \phpbb\request\request                 $request    Request object
51
-     * @param \phpbb\auth\auth                       $auth       Auth object
52
-     * @param \phpbb\pagination                      $pagination Pagination object
53
-     * @param \ernadoo\phpbbdirectory\core\categorie $categorie  PhpBB Directory extension categorie object
54
-     * @param \ernadoo\phpbbdirectory\core\link      $link       PhpBB Directory extension link object
55
-     */
56
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link)
57
-    {
58
-        $this->db = $db;
59
-        $this->config = $config;
60
-        $this->template = $template;
61
-        $this->user = $user;
62
-        $this->helper = $helper;
63
-        $this->request = $request;
64
-        $this->auth = $auth;
65
-        $this->pagination = $pagination;
66
-        $this->categorie = $categorie;
67
-        $this->link = $link;
68
-
69
-        $this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory');
70
-
71
-        $this->template->assign_vars([
72
-            'S_PHPBB_DIRECTORY'                => true,
73
-            'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
74
-        ]);
75
-    }
76
-
77
-    /**
78
-     * Base controller to be accessed with the URL /directory.
79
-     *
80
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
81
-     */
82
-    public function base()
83
-    {
84
-        $this->categorie->display();
85
-        $this->link->recents();
86
-
87
-        return $this->helper->render('body.html', $this->user->lang['DIRECTORY']);
88
-    }
89
-
90
-    /**
91
-     * View controller for display a category.
92
-     *
93
-     * @param int    $cat_id    The category ID
94
-     * @param int    $page      Page number taken from the URL
95
-     * @param int    $sort_days Specifies the maximum amount of days a link may be old
96
-     * @param string $sort_key  is the key of $sort_by_sql for the selected sorting: a|t|r|s|v|p
97
-     * @param string $sort_dir  is either a or d representing ASC and DESC (ascending|descending)
98
-     * @param string $mode      watch|unwatch
99
-     *
100
-     * @throws \phpbb\exception\http_exception
101
-     *
102
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
103
-     */
104
-    public function view($cat_id, $page, $sort_days, $sort_key, $sort_dir, $mode = '')
105
-    {
106
-        if (false === $this->categorie->get($cat_id)) {
107
-            throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_CATS');
108
-        }
109
-
110
-        $start = ($page - 1) * $this->config['dir_show'];
111
-
112
-        $default_sort_days = 0;
113
-        $default_sort_key = (string) substr($this->config['dir_default_order'], 0, 1);
114
-        $default_sort_dir = (string) substr($this->config['dir_default_order'], 2);
115
-
116
-        $sort_days = (!$sort_days) ? $this->request->variable('st', $default_sort_days) : $sort_days;
117
-        $sort_key = (!$sort_key) ? $this->request->variable('sk', $default_sort_key) : $sort_key;
118
-        $sort_dir = (!$sort_dir) ? $this->request->variable('sd', $default_sort_dir) : $sort_dir;
119
-        $link_list = $rowset = [];
120
-
121
-        // Categorie ordering options
122
-        $limit_days = [0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']];
123
-        $sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' =>  $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']];
124
-        $sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id'], 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'];
125
-
126
-        if ($this->config['dir_activ_pagerank']) {
127
-            $sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
128
-            $sort_by_sql['p'] = 'l.link_pagerank';
129
-        }
130
-
131
-        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
132
-        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
133
-
134
-        $u_sort_param = ($sort_days === $default_sort_days && $sort_key == $default_sort_key && $sort_dir == $default_sort_dir) ? [] : ['sort_days' => $sort_days, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir];
135
-
136
-        // Are we watching this categorie?
137
-        $s_watching_categorie = [
138
-            'link'             => '',
139
-            'link_toggle'      => '',
140
-            'title'            => '',
141
-            'title_toggle'     => '',
142
-            'is_watching'      => false,
143
-        ];
144
-
145
-        if ($this->config['email_enable'] && $this->user->data['is_registered']) {
146
-            $notify_status = (isset($this->categorie->data['notify_status'])) ? $this->categorie->data['notify_status'] : null;
147
-
148
-            if (($message = $this->categorie->watch_categorie($mode, $s_watching_categorie, $this->user->data['user_id'], $cat_id, $notify_status))) {
149
-                return $this->helper->message($message);
150
-            }
151
-        }
152
-
153
-        // A deadline has been selected
154
-        if ($sort_days) {
155
-            $min_post_time = time() - ($sort_days * 86400);
156
-
157
-            $sql = 'SELECT COUNT(link_id) AS nb_links
12
+	/** @var \phpbb\db\driver\driver_interface */
13
+	protected $db;
14
+
15
+	/** @var \phpbb\config\config */
16
+	protected $config;
17
+
18
+	/** @var \phpbb\template\template */
19
+	protected $template;
20
+
21
+	/** @var \phpbb\user */
22
+	protected $user;
23
+
24
+	/** @var \phpbb\controller\helper */
25
+	protected $helper;
26
+
27
+	/** @var \phpbb\request\request */
28
+	protected $request;
29
+
30
+	/** @var \phpbb\auth\auth */
31
+	protected $auth;
32
+
33
+	/** @var \phpbb\pagination */
34
+	protected $pagination;
35
+
36
+	/** @var \ernadoo\phpbbdirectory\core\categorie */
37
+	protected $categorie;
38
+
39
+	/** @var \ernadoo\phpbbdirectory\core\link */
40
+	protected $link;
41
+
42
+	/**
43
+	 * Constructor.
44
+	 *
45
+	 * @param \phpbb\db\driver\driver_interface      $db         Database object
46
+	 * @param \phpbb\config\config                   $config     Config object
47
+	 * @param \phpbb\template\template               $template   Template object
48
+	 * @param \phpbb\user                            $user       User object
49
+	 * @param \phpbb\controller\helper               $helper     Controller helper object
50
+	 * @param \phpbb\request\request                 $request    Request object
51
+	 * @param \phpbb\auth\auth                       $auth       Auth object
52
+	 * @param \phpbb\pagination                      $pagination Pagination object
53
+	 * @param \ernadoo\phpbbdirectory\core\categorie $categorie  PhpBB Directory extension categorie object
54
+	 * @param \ernadoo\phpbbdirectory\core\link      $link       PhpBB Directory extension link object
55
+	 */
56
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link)
57
+	{
58
+		$this->db = $db;
59
+		$this->config = $config;
60
+		$this->template = $template;
61
+		$this->user = $user;
62
+		$this->helper = $helper;
63
+		$this->request = $request;
64
+		$this->auth = $auth;
65
+		$this->pagination = $pagination;
66
+		$this->categorie = $categorie;
67
+		$this->link = $link;
68
+
69
+		$this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory');
70
+
71
+		$this->template->assign_vars([
72
+			'S_PHPBB_DIRECTORY'                => true,
73
+			'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
74
+		]);
75
+	}
76
+
77
+	/**
78
+	 * Base controller to be accessed with the URL /directory.
79
+	 *
80
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
81
+	 */
82
+	public function base()
83
+	{
84
+		$this->categorie->display();
85
+		$this->link->recents();
86
+
87
+		return $this->helper->render('body.html', $this->user->lang['DIRECTORY']);
88
+	}
89
+
90
+	/**
91
+	 * View controller for display a category.
92
+	 *
93
+	 * @param int    $cat_id    The category ID
94
+	 * @param int    $page      Page number taken from the URL
95
+	 * @param int    $sort_days Specifies the maximum amount of days a link may be old
96
+	 * @param string $sort_key  is the key of $sort_by_sql for the selected sorting: a|t|r|s|v|p
97
+	 * @param string $sort_dir  is either a or d representing ASC and DESC (ascending|descending)
98
+	 * @param string $mode      watch|unwatch
99
+	 *
100
+	 * @throws \phpbb\exception\http_exception
101
+	 *
102
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
103
+	 */
104
+	public function view($cat_id, $page, $sort_days, $sort_key, $sort_dir, $mode = '')
105
+	{
106
+		if (false === $this->categorie->get($cat_id)) {
107
+			throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_CATS');
108
+		}
109
+
110
+		$start = ($page - 1) * $this->config['dir_show'];
111
+
112
+		$default_sort_days = 0;
113
+		$default_sort_key = (string) substr($this->config['dir_default_order'], 0, 1);
114
+		$default_sort_dir = (string) substr($this->config['dir_default_order'], 2);
115
+
116
+		$sort_days = (!$sort_days) ? $this->request->variable('st', $default_sort_days) : $sort_days;
117
+		$sort_key = (!$sort_key) ? $this->request->variable('sk', $default_sort_key) : $sort_key;
118
+		$sort_dir = (!$sort_dir) ? $this->request->variable('sd', $default_sort_dir) : $sort_dir;
119
+		$link_list = $rowset = [];
120
+
121
+		// Categorie ordering options
122
+		$limit_days = [0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']];
123
+		$sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' =>  $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']];
124
+		$sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id'], 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'];
125
+
126
+		if ($this->config['dir_activ_pagerank']) {
127
+			$sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
128
+			$sort_by_sql['p'] = 'l.link_pagerank';
129
+		}
130
+
131
+		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
132
+		gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
133
+
134
+		$u_sort_param = ($sort_days === $default_sort_days && $sort_key == $default_sort_key && $sort_dir == $default_sort_dir) ? [] : ['sort_days' => $sort_days, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir];
135
+
136
+		// Are we watching this categorie?
137
+		$s_watching_categorie = [
138
+			'link'             => '',
139
+			'link_toggle'      => '',
140
+			'title'            => '',
141
+			'title_toggle'     => '',
142
+			'is_watching'      => false,
143
+		];
144
+
145
+		if ($this->config['email_enable'] && $this->user->data['is_registered']) {
146
+			$notify_status = (isset($this->categorie->data['notify_status'])) ? $this->categorie->data['notify_status'] : null;
147
+
148
+			if (($message = $this->categorie->watch_categorie($mode, $s_watching_categorie, $this->user->data['user_id'], $cat_id, $notify_status))) {
149
+				return $this->helper->message($message);
150
+			}
151
+		}
152
+
153
+		// A deadline has been selected
154
+		if ($sort_days) {
155
+			$min_post_time = time() - ($sort_days * 86400);
156
+
157
+			$sql = 'SELECT COUNT(link_id) AS nb_links
158 158
 				FROM '.DIR_LINK_TABLE.'
159 159
 				WHERE link_cat = '.(int) $cat_id.'
160 160
 					AND link_time >= '.$min_post_time;
161
-            $result = $this->db->sql_query($sql);
162
-            $nb_links = (int) $this->db->sql_fetchfield('nb_links');
163
-            $this->db->sql_freeresult($result);
164
-
165
-            if ($this->request->is_set_post('sort')) {
166
-                $start = 0;
167
-            }
168
-            $sql_limit_time = " AND l.link_time >= $min_post_time";
169
-        } else {
170
-            $sql_limit_time = '';
171
-            $nb_links = (int) $this->categorie->data['cat_links'];
172
-        }
173
-
174
-        // Make sure $start is set to the last page if it exceeds the amount
175
-        $start = $this->pagination->validate_start($start, $this->config['dir_show'], $nb_links);
176
-
177
-        // Build navigation links
178
-        $this->categorie->generate_dir_nav($this->categorie->data);
179
-
180
-        // Jumpbox
181
-        $this->categorie->make_cat_jumpbox();
182
-
183
-        $base_url = [
184
-            'routes'    => 'ernadoo_phpbbdirectory_page_controller',
185
-            'params'    => array_merge(['cat_id' => $cat_id], $u_sort_param),
186
-        ];
187
-
188
-        $this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_links, $this->config['dir_show'], $start);
189
-
190
-        $this->template->assign_vars([
191
-            'S_SELECT_SORT_DIR'        => $s_sort_dir,
192
-            'S_SELECT_SORT_KEY'        => $s_sort_key,
193
-            'S_SELECT_SORT_DAYS'       => $s_limit_days,
194
-            'S_CATLIST'                => $this->categorie->make_cat_select($cat_id),
195
-            'S_PAGE_ACTION'            => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => $cat_id, 'page' => $page]),
196
-            'S_CAT_ID'                 => $cat_id,
197
-
198
-            'TOTAL_LINKS'            => $this->user->lang('DIR_NB_LINKS', (int) $nb_links),
199
-
200
-            'U_NEW_SITE'            => $this->helper->route('ernadoo_phpbbdirectory_new_controller', ['cat_id' => $cat_id]),
201
-
202
-            'U_WATCH_CAT'              => $s_watching_categorie['link'],
203
-            'U_WATCH_CAT_TOGGLE'       => $s_watching_categorie['link_toggle'],
204
-            'S_WATCH_CAT_TITLE'        => $s_watching_categorie['title'],
205
-            'S_WATCH_CAT_TOGGLE'       => $s_watching_categorie['title_toggle'],
206
-            'S_WATCHING_CAT'           => $s_watching_categorie['is_watching'],
207
-        ]);
208
-
209
-        // If the user is trying to reach late pages, start searching from the end
210
-        $store_reverse = false;
211
-        $sql_limit = $this->config['dir_show'];
212
-        if ($start > $nb_links / 2) {
213
-            $store_reverse = true;
214
-
215
-            // Select the sort order
216
-            $direction = (($sort_dir == 'd') ? 'ASC' : 'DESC');
217
-
218
-            $sql_limit = $this->pagination->reverse_limit($start, $sql_limit, $nb_links);
219
-            $sql_start = $this->pagination->reverse_start($start, $sql_limit, $nb_links);
220
-        } else {
221
-            // Select the sort order
222
-            $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
223
-            $sql_start = $start;
224
-        }
225
-
226
-        if (is_array($sort_by_sql[$sort_key])) {
227
-            $sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
228
-        } else {
229
-            $sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
230
-        }
231
-
232
-        // Grab just the sorted link ids
233
-        $sql_array = [
234
-            'SELECT'      => 'l.link_id',
235
-            'FROM'        => [
236
-                    DIR_LINK_TABLE    => 'l', ],
237
-            'LEFT_JOIN'    => [
238
-                    [
239
-                        'FROM'    => [USERS_TABLE    => 'u'],
240
-                        'ON'      => 'l.link_user_id = u.user_id',
241
-                    ],
242
-            ],
243
-            'WHERE'        => "l.link_cat = $cat_id
161
+			$result = $this->db->sql_query($sql);
162
+			$nb_links = (int) $this->db->sql_fetchfield('nb_links');
163
+			$this->db->sql_freeresult($result);
164
+
165
+			if ($this->request->is_set_post('sort')) {
166
+				$start = 0;
167
+			}
168
+			$sql_limit_time = " AND l.link_time >= $min_post_time";
169
+		} else {
170
+			$sql_limit_time = '';
171
+			$nb_links = (int) $this->categorie->data['cat_links'];
172
+		}
173
+
174
+		// Make sure $start is set to the last page if it exceeds the amount
175
+		$start = $this->pagination->validate_start($start, $this->config['dir_show'], $nb_links);
176
+
177
+		// Build navigation links
178
+		$this->categorie->generate_dir_nav($this->categorie->data);
179
+
180
+		// Jumpbox
181
+		$this->categorie->make_cat_jumpbox();
182
+
183
+		$base_url = [
184
+			'routes'    => 'ernadoo_phpbbdirectory_page_controller',
185
+			'params'    => array_merge(['cat_id' => $cat_id], $u_sort_param),
186
+		];
187
+
188
+		$this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_links, $this->config['dir_show'], $start);
189
+
190
+		$this->template->assign_vars([
191
+			'S_SELECT_SORT_DIR'        => $s_sort_dir,
192
+			'S_SELECT_SORT_KEY'        => $s_sort_key,
193
+			'S_SELECT_SORT_DAYS'       => $s_limit_days,
194
+			'S_CATLIST'                => $this->categorie->make_cat_select($cat_id),
195
+			'S_PAGE_ACTION'            => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => $cat_id, 'page' => $page]),
196
+			'S_CAT_ID'                 => $cat_id,
197
+
198
+			'TOTAL_LINKS'            => $this->user->lang('DIR_NB_LINKS', (int) $nb_links),
199
+
200
+			'U_NEW_SITE'            => $this->helper->route('ernadoo_phpbbdirectory_new_controller', ['cat_id' => $cat_id]),
201
+
202
+			'U_WATCH_CAT'              => $s_watching_categorie['link'],
203
+			'U_WATCH_CAT_TOGGLE'       => $s_watching_categorie['link_toggle'],
204
+			'S_WATCH_CAT_TITLE'        => $s_watching_categorie['title'],
205
+			'S_WATCH_CAT_TOGGLE'       => $s_watching_categorie['title_toggle'],
206
+			'S_WATCHING_CAT'           => $s_watching_categorie['is_watching'],
207
+		]);
208
+
209
+		// If the user is trying to reach late pages, start searching from the end
210
+		$store_reverse = false;
211
+		$sql_limit = $this->config['dir_show'];
212
+		if ($start > $nb_links / 2) {
213
+			$store_reverse = true;
214
+
215
+			// Select the sort order
216
+			$direction = (($sort_dir == 'd') ? 'ASC' : 'DESC');
217
+
218
+			$sql_limit = $this->pagination->reverse_limit($start, $sql_limit, $nb_links);
219
+			$sql_start = $this->pagination->reverse_start($start, $sql_limit, $nb_links);
220
+		} else {
221
+			// Select the sort order
222
+			$direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
223
+			$sql_start = $start;
224
+		}
225
+
226
+		if (is_array($sort_by_sql[$sort_key])) {
227
+			$sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
228
+		} else {
229
+			$sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
230
+		}
231
+
232
+		// Grab just the sorted link ids
233
+		$sql_array = [
234
+			'SELECT'      => 'l.link_id',
235
+			'FROM'        => [
236
+					DIR_LINK_TABLE    => 'l', ],
237
+			'LEFT_JOIN'    => [
238
+					[
239
+						'FROM'    => [USERS_TABLE    => 'u'],
240
+						'ON'      => 'l.link_user_id = u.user_id',
241
+					],
242
+			],
243
+			'WHERE'        => "l.link_cat = $cat_id
244 244
 				AND l.link_active = 1
245 245
 					$sql_limit_time",
246
-            'ORDER_BY'    => $sql_sort_order,
247
-        ];
248
-
249
-        $sql = $this->db->sql_build_query('SELECT', $sql_array);
250
-        $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
251
-
252
-        while ($row = $this->db->sql_fetchrow($result)) {
253
-            $link_list[] = (int) $row['link_id'];
254
-        }
255
-        $this->db->sql_freeresult($result);
256
-
257
-        if (count($link_list)) {
258
-            // We get links, informations about poster, votes and number of comments
259
-            $sql_array = [
260
-                'SELECT'      => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_banner, l.link_rss, l. link_uid, l.link_bitfield, l.link_flags, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_flag, l.link_pagerank, l.link_thumb, u.user_id, u.username, u.user_colour, v.vote_user_id',
261
-                'FROM'        => [
262
-                        DIR_LINK_TABLE    => 'l', ],
263
-                'LEFT_JOIN'    => [
264
-                        [
265
-                            'FROM'    => [USERS_TABLE    => 'u'],
266
-                            'ON'      => 'l.link_user_id = u.user_id',
267
-                        ],
268
-                        [
269
-                            'FROM'    => [DIR_VOTE_TABLE => 'v'],
270
-                            'ON'      => 'l.link_id = v.vote_link_id AND v.vote_user_id = '.$this->user->data['user_id'],
271
-                        ],
272
-                ],
273
-                'WHERE'        => $this->db->sql_in_set('l.link_id', $link_list),
274
-            ];
275
-
276
-            $sql = $this->db->sql_build_query('SELECT', $sql_array);
277
-            $result = $this->db->sql_query($sql);
278
-
279
-            while ($site = $this->db->sql_fetchrow($result)) {
280
-                $rowset[$site['link_id']] = $site;
281
-            }
282
-            $this->db->sql_freeresult($result);
283
-
284
-            $link_list = ($store_reverse) ? array_reverse($link_list) : $link_list;
285
-
286
-            $votes_status = ($this->categorie->data['cat_allow_votes']) ? true : false;
287
-            $comments_status = ($this->categorie->data['cat_allow_comments']) ? true : false;
288
-
289
-            foreach ($link_list as $link_id) {
290
-                $site = &$rowset[$link_id];
291
-
292
-                $s_flag = $this->link->display_flag($site);
293
-                $s_note = $this->link->display_note($site['link_note'], $site['link_vote'], $votes_status);
294
-                $s_thumb = $this->link->display_thumb($site);
295
-                $s_vote = $this->link->display_vote($site);
296
-                $s_banner = $this->link->display_bann($site);
297
-                $s_pr = $this->link->display_pagerank($site);
298
-                $s_rss = $this->link->display_rss($site);
299
-
300
-                $edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_edit_dir'))));
301
-                $delete_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_delete_dir'))));
302
-
303
-                $this->template->assign_block_vars('site', [
304
-                    'BANNER'           => $s_banner,
305
-                    'COUNT'            => $this->user->lang('DIR_NB_CLICKS', (int) $site['link_view']),
306
-                    'DESCRIPTION'      => generate_text_for_display($site['link_description'], $site['link_uid'], $site['link_bitfield'], $site['link_flags']),
307
-                    'LINK_ID'          => $site['link_id'],
308
-                    'NAME'             => $site['link_name'],
309
-                    'NB_COMMENT'       => ($comments_status) ? $this->user->lang('DIR_NB_COMMS', (int) $site['link_comment']) : '',
310
-                    'NB_VOTE'          => $this->user->lang('DIR_NB_VOTES', (int) $site['link_vote']),
311
-                    'NOTE'             => $s_note,
312
-                    'PAGERANK'         => $s_pr,
313
-                    'RSS'              => $s_rss,
314
-                    'TIME'             => ($site['link_time']) ? $this->user->format_date($site['link_time']) : '',
315
-                    'USER'             => get_username_string('full', $site['link_user_id'], $site['username'], $site['user_colour']),
316
-                    'VOTE_LIST'        => ($votes_status) ? $s_vote : '',
317
-
318
-                    'IMG_FLAG'        => $s_flag,
319
-                    'ON_CLICK'        => "onclick=\"window.open('".$this->helper->route('ernadoo_phpbbdirectory_view_controller', ['link_id' => (int) $site['link_id']])."'); return false;\"",
320
-
321
-                    'S_NEW_LINK'    => (((time() - $site['link_time']) / 86400) <= $this->config['dir_new_time']) ? true : false,
322
-
323
-                    'U_COMMENT'        => ($comments_status) ? $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $site['link_id']]) : '',
324
-                    'U_DELETE'         => $delete_allowed ? $this->helper->route('ernadoo_phpbbdirectory_delete_controller', ['cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id'], '_referer' => $this->helper->get_current_url()]) : '',
325
-                    'U_EDIT'           => $edit_allowed ? $this->helper->route('ernadoo_phpbbdirectory_edit_controller', ['cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id']]) : '',
326
-                    'U_FORM_VOTE'      => ($votes_status) ? $this->helper->route('ernadoo_phpbbdirectory_vote_controller', ['cat_id' => (int) $site['link_cat'], 'link_id' => (int) $site['link_id']]) : '',
327
-                    'U_LINK'           => $site['link_url'],
328
-                    'U_THUMB'          => $s_thumb,
329
-                ]);
330
-            }
331
-        } else {
332
-            $this->template->assign_block_vars('no_draw_link', []);
333
-        }
334
-
335
-        $page_title = $this->user->lang['DIRECTORY'].' - '.$this->categorie->data['cat_name'];
336
-
337
-        $this->categorie->display();
338
-
339
-        return $this->helper->render('view_cat.html', $page_title);
340
-    }
341
-
342
-    /**
343
-     * date controller for return a date.
344
-     *
345
-     * @throws \phpbb\exception\http_exception
346
-     *
347
-     * @return \phpbb\json_response A Json Response
348
-     */
349
-    public function return_date()
350
-    {
351
-        if (!$this->request->is_ajax()) {
352
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
353
-        }
354
-
355
-        $timestamp = $this->request->variable('timestamp', 0);
356
-        $json_response = new \phpbb\json_response();
357
-        $json_response->send([
358
-            'success'     => true,
359
-            'DATE'        => $this->user->format_date((int) $timestamp),
360
-        ]);
361
-    }
246
+			'ORDER_BY'    => $sql_sort_order,
247
+		];
248
+
249
+		$sql = $this->db->sql_build_query('SELECT', $sql_array);
250
+		$result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
251
+
252
+		while ($row = $this->db->sql_fetchrow($result)) {
253
+			$link_list[] = (int) $row['link_id'];
254
+		}
255
+		$this->db->sql_freeresult($result);
256
+
257
+		if (count($link_list)) {
258
+			// We get links, informations about poster, votes and number of comments
259
+			$sql_array = [
260
+				'SELECT'      => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_banner, l.link_rss, l. link_uid, l.link_bitfield, l.link_flags, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_flag, l.link_pagerank, l.link_thumb, u.user_id, u.username, u.user_colour, v.vote_user_id',
261
+				'FROM'        => [
262
+						DIR_LINK_TABLE    => 'l', ],
263
+				'LEFT_JOIN'    => [
264
+						[
265
+							'FROM'    => [USERS_TABLE    => 'u'],
266
+							'ON'      => 'l.link_user_id = u.user_id',
267
+						],
268
+						[
269
+							'FROM'    => [DIR_VOTE_TABLE => 'v'],
270
+							'ON'      => 'l.link_id = v.vote_link_id AND v.vote_user_id = '.$this->user->data['user_id'],
271
+						],
272
+				],
273
+				'WHERE'        => $this->db->sql_in_set('l.link_id', $link_list),
274
+			];
275
+
276
+			$sql = $this->db->sql_build_query('SELECT', $sql_array);
277
+			$result = $this->db->sql_query($sql);
278
+
279
+			while ($site = $this->db->sql_fetchrow($result)) {
280
+				$rowset[$site['link_id']] = $site;
281
+			}
282
+			$this->db->sql_freeresult($result);
283
+
284
+			$link_list = ($store_reverse) ? array_reverse($link_list) : $link_list;
285
+
286
+			$votes_status = ($this->categorie->data['cat_allow_votes']) ? true : false;
287
+			$comments_status = ($this->categorie->data['cat_allow_comments']) ? true : false;
288
+
289
+			foreach ($link_list as $link_id) {
290
+				$site = &$rowset[$link_id];
291
+
292
+				$s_flag = $this->link->display_flag($site);
293
+				$s_note = $this->link->display_note($site['link_note'], $site['link_vote'], $votes_status);
294
+				$s_thumb = $this->link->display_thumb($site);
295
+				$s_vote = $this->link->display_vote($site);
296
+				$s_banner = $this->link->display_bann($site);
297
+				$s_pr = $this->link->display_pagerank($site);
298
+				$s_rss = $this->link->display_rss($site);
299
+
300
+				$edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_edit_dir'))));
301
+				$delete_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_delete_dir'))));
302
+
303
+				$this->template->assign_block_vars('site', [
304
+					'BANNER'           => $s_banner,
305
+					'COUNT'            => $this->user->lang('DIR_NB_CLICKS', (int) $site['link_view']),
306
+					'DESCRIPTION'      => generate_text_for_display($site['link_description'], $site['link_uid'], $site['link_bitfield'], $site['link_flags']),
307
+					'LINK_ID'          => $site['link_id'],
308
+					'NAME'             => $site['link_name'],
309
+					'NB_COMMENT'       => ($comments_status) ? $this->user->lang('DIR_NB_COMMS', (int) $site['link_comment']) : '',
310
+					'NB_VOTE'          => $this->user->lang('DIR_NB_VOTES', (int) $site['link_vote']),
311
+					'NOTE'             => $s_note,
312
+					'PAGERANK'         => $s_pr,
313
+					'RSS'              => $s_rss,
314
+					'TIME'             => ($site['link_time']) ? $this->user->format_date($site['link_time']) : '',
315
+					'USER'             => get_username_string('full', $site['link_user_id'], $site['username'], $site['user_colour']),
316
+					'VOTE_LIST'        => ($votes_status) ? $s_vote : '',
317
+
318
+					'IMG_FLAG'        => $s_flag,
319
+					'ON_CLICK'        => "onclick=\"window.open('".$this->helper->route('ernadoo_phpbbdirectory_view_controller', ['link_id' => (int) $site['link_id']])."'); return false;\"",
320
+
321
+					'S_NEW_LINK'    => (((time() - $site['link_time']) / 86400) <= $this->config['dir_new_time']) ? true : false,
322
+
323
+					'U_COMMENT'        => ($comments_status) ? $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $site['link_id']]) : '',
324
+					'U_DELETE'         => $delete_allowed ? $this->helper->route('ernadoo_phpbbdirectory_delete_controller', ['cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id'], '_referer' => $this->helper->get_current_url()]) : '',
325
+					'U_EDIT'           => $edit_allowed ? $this->helper->route('ernadoo_phpbbdirectory_edit_controller', ['cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id']]) : '',
326
+					'U_FORM_VOTE'      => ($votes_status) ? $this->helper->route('ernadoo_phpbbdirectory_vote_controller', ['cat_id' => (int) $site['link_cat'], 'link_id' => (int) $site['link_id']]) : '',
327
+					'U_LINK'           => $site['link_url'],
328
+					'U_THUMB'          => $s_thumb,
329
+				]);
330
+			}
331
+		} else {
332
+			$this->template->assign_block_vars('no_draw_link', []);
333
+		}
334
+
335
+		$page_title = $this->user->lang['DIRECTORY'].' - '.$this->categorie->data['cat_name'];
336
+
337
+		$this->categorie->display();
338
+
339
+		return $this->helper->render('view_cat.html', $page_title);
340
+	}
341
+
342
+	/**
343
+	 * date controller for return a date.
344
+	 *
345
+	 * @throws \phpbb\exception\http_exception
346
+	 *
347
+	 * @return \phpbb\json_response A Json Response
348
+	 */
349
+	public function return_date()
350
+	{
351
+		if (!$this->request->is_ajax()) {
352
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
353
+		}
354
+
355
+		$timestamp = $this->request->variable('timestamp', 0);
356
+		$json_response = new \phpbb\json_response();
357
+		$json_response->send([
358
+			'success'     => true,
359
+			'DATE'        => $this->user->format_date((int) $timestamp),
360
+		]);
361
+	}
362 362
 }
Please login to merge, or discard this patch.
Braces   +38 added lines, -17 removed lines patch added patch discarded remove patch
@@ -103,7 +103,8 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function view($cat_id, $page, $sort_days, $sort_key, $sort_dir, $mode = '')
105 105
     {
106
-        if (false === $this->categorie->get($cat_id)) {
106
+        if (false === $this->categorie->get($cat_id))
107
+        {
107 108
             throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_CATS');
108 109
         }
109 110
 
@@ -123,7 +124,8 @@  discard block
 block discarded – undo
123 124
         $sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' =>  $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']];
124 125
         $sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id'], 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'];
125 126
 
126
-        if ($this->config['dir_activ_pagerank']) {
127
+        if ($this->config['dir_activ_pagerank'])
128
+        {
127 129
             $sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
128 130
             $sort_by_sql['p'] = 'l.link_pagerank';
129 131
         }
@@ -142,16 +144,19 @@  discard block
 block discarded – undo
142 144
             'is_watching'      => false,
143 145
         ];
144 146
 
145
-        if ($this->config['email_enable'] && $this->user->data['is_registered']) {
147
+        if ($this->config['email_enable'] && $this->user->data['is_registered'])
148
+        {
146 149
             $notify_status = (isset($this->categorie->data['notify_status'])) ? $this->categorie->data['notify_status'] : null;
147 150
 
148
-            if (($message = $this->categorie->watch_categorie($mode, $s_watching_categorie, $this->user->data['user_id'], $cat_id, $notify_status))) {
151
+            if (($message = $this->categorie->watch_categorie($mode, $s_watching_categorie, $this->user->data['user_id'], $cat_id, $notify_status)))
152
+            {
149 153
                 return $this->helper->message($message);
150 154
             }
151 155
         }
152 156
 
153 157
         // A deadline has been selected
154
-        if ($sort_days) {
158
+        if ($sort_days)
159
+        {
155 160
             $min_post_time = time() - ($sort_days * 86400);
156 161
 
157 162
             $sql = 'SELECT COUNT(link_id) AS nb_links
@@ -162,11 +167,14 @@  discard block
 block discarded – undo
162 167
             $nb_links = (int) $this->db->sql_fetchfield('nb_links');
163 168
             $this->db->sql_freeresult($result);
164 169
 
165
-            if ($this->request->is_set_post('sort')) {
170
+            if ($this->request->is_set_post('sort'))
171
+            {
166 172
                 $start = 0;
167 173
             }
168 174
             $sql_limit_time = " AND l.link_time >= $min_post_time";
169
-        } else {
175
+        }
176
+        else
177
+        {
170 178
             $sql_limit_time = '';
171 179
             $nb_links = (int) $this->categorie->data['cat_links'];
172 180
         }
@@ -209,7 +217,8 @@  discard block
 block discarded – undo
209 217
         // If the user is trying to reach late pages, start searching from the end
210 218
         $store_reverse = false;
211 219
         $sql_limit = $this->config['dir_show'];
212
-        if ($start > $nb_links / 2) {
220
+        if ($start > $nb_links / 2)
221
+        {
213 222
             $store_reverse = true;
214 223
 
215 224
             // Select the sort order
@@ -217,15 +226,20 @@  discard block
 block discarded – undo
217 226
 
218 227
             $sql_limit = $this->pagination->reverse_limit($start, $sql_limit, $nb_links);
219 228
             $sql_start = $this->pagination->reverse_start($start, $sql_limit, $nb_links);
220
-        } else {
229
+        }
230
+        else
231
+        {
221 232
             // Select the sort order
222 233
             $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
223 234
             $sql_start = $start;
224 235
         }
225 236
 
226
-        if (is_array($sort_by_sql[$sort_key])) {
237
+        if (is_array($sort_by_sql[$sort_key]))
238
+        {
227 239
             $sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
228
-        } else {
240
+        }
241
+        else
242
+        {
229 243
             $sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
230 244
         }
231 245
 
@@ -249,12 +263,14 @@  discard block
 block discarded – undo
249 263
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
250 264
         $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
251 265
 
252
-        while ($row = $this->db->sql_fetchrow($result)) {
266
+        while ($row = $this->db->sql_fetchrow($result))
267
+        {
253 268
             $link_list[] = (int) $row['link_id'];
254 269
         }
255 270
         $this->db->sql_freeresult($result);
256 271
 
257
-        if (count($link_list)) {
272
+        if (count($link_list))
273
+        {
258 274
             // We get links, informations about poster, votes and number of comments
259 275
             $sql_array = [
260 276
                 'SELECT'      => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_banner, l.link_rss, l. link_uid, l.link_bitfield, l.link_flags, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_flag, l.link_pagerank, l.link_thumb, u.user_id, u.username, u.user_colour, v.vote_user_id',
@@ -276,7 +292,8 @@  discard block
 block discarded – undo
276 292
             $sql = $this->db->sql_build_query('SELECT', $sql_array);
277 293
             $result = $this->db->sql_query($sql);
278 294
 
279
-            while ($site = $this->db->sql_fetchrow($result)) {
295
+            while ($site = $this->db->sql_fetchrow($result))
296
+            {
280 297
                 $rowset[$site['link_id']] = $site;
281 298
             }
282 299
             $this->db->sql_freeresult($result);
@@ -286,7 +303,8 @@  discard block
 block discarded – undo
286 303
             $votes_status = ($this->categorie->data['cat_allow_votes']) ? true : false;
287 304
             $comments_status = ($this->categorie->data['cat_allow_comments']) ? true : false;
288 305
 
289
-            foreach ($link_list as $link_id) {
306
+            foreach ($link_list as $link_id)
307
+            {
290 308
                 $site = &$rowset[$link_id];
291 309
 
292 310
                 $s_flag = $this->link->display_flag($site);
@@ -328,7 +346,9 @@  discard block
 block discarded – undo
328 346
                     'U_THUMB'          => $s_thumb,
329 347
                 ]);
330 348
             }
331
-        } else {
349
+        }
350
+        else
351
+        {
332 352
             $this->template->assign_block_vars('no_draw_link', []);
333 353
         }
334 354
 
@@ -348,7 +368,8 @@  discard block
 block discarded – undo
348 368
      */
349 369
     public function return_date()
350 370
     {
351
-        if (!$this->request->is_ajax()) {
371
+        if (!$this->request->is_ajax())
372
+        {
352 373
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
353 374
         }
354 375
 
Please login to merge, or discard this patch.
controller/acp/cat.php 2 patches
Indentation   +962 added lines, -962 removed lines patch added patch discarded remove patch
@@ -9,1025 +9,1025 @@
 block discarded – undo
9 9
 
10 10
 class cat
11 11
 {
12
-    /** @var \phpbb\cache\service */
13
-    protected $cache;
14
-
15
-    /** @var \phpbb\db\driver\driver_interface */
16
-    protected $db;
17
-
18
-    /** @var \phpbb\controller\helper */
19
-    protected $helper;
20
-
21
-    /** @var \phpbb\log\log */
22
-    protected $phpbb_log;
23
-
24
-    /** @var \phpbb\request\request */
25
-    protected $request;
26
-
27
-    /** @var \phpbb\template\template */
28
-    protected $template;
29
-
30
-    /** @var \phpbb\user */
31
-    protected $user;
32
-
33
-    /** @var \ernadoo\phpbbdirectory\core\categorie */
34
-    protected $categorie;
35
-
36
-    /** @var \ernadoo\phpbbdirectory\core\helper */
37
-    protected $dir_helper;
38
-
39
-    /** @var \ernadoo\phpbbdirectory\core\nestedset_category */
40
-    protected $nestedset_category;
41
-
42
-    /** @var string Custom form action */
43
-    protected $u_action;
44
-
45
-    /** @var string */
46
-    private $action;
47
-
48
-    /** @var array */
49
-    private $cat_data = [];
50
-
51
-    /** @var int */
52
-    private $cat_id;
53
-
54
-    /** @var array */
55
-    private $errors;
56
-
57
-    /** @var string */
58
-    private $form_key;
59
-
60
-    /** @var int */
61
-    private $parent_id;
62
-
63
-    /** @var bool */
64
-    private $update;
65
-
66
-    /**
67
-     * Constructor.
68
-     *
69
-     * @param \phpbb\cache\service                            $cache              Cache object
70
-     * @param \phpbb\db\driver\driver_interface               $db                 Database object
71
-     * @param \phpbb\controller\helper                        $helper             Helper object
72
-     * @param \phpbb\log\log                                  $log                Log object
73
-     * @param \phpbb\request\request                          $request            Request object
74
-     * @param \phpbb\template\template                        $template           Template object
75
-     * @param \phpbb\user                                     $user               User object
76
-     * @param \ernadoo\phpbbdirectory\core\categorie          $categorie          PhpBB Directory extension categorie object
77
-     * @param \ernadoo\phpbbdirectory\core\helper             $dir_helper         PhpBB Directory extension helper object
78
-     * @param \ernadoo\phpbbdirectory\core\nestedset_category $nestedset_category PhpBB Directory extension nestedset object
79
-     */
80
-    public function __construct(\phpbb\cache\service $cache, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\log\log $log, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\helper $dir_helper, \ernadoo\phpbbdirectory\core\nestedset_category $nestedset_category)
81
-    {
82
-        $this->cache = $cache;
83
-        $this->db = $db;
84
-        $this->helper = $helper;
85
-        $this->phpbb_log = $log;
86
-        $this->request = $request;
87
-        $this->template = $template;
88
-        $this->user = $user;
89
-        $this->categorie = $categorie;
90
-        $this->dir_helper = $dir_helper;
91
-        $this->nestedset_category = $nestedset_category;
92
-
93
-        $this->form_key = 'acp_dir_cat';
94
-        add_form_key($this->form_key);
95
-
96
-        $this->action = $this->request->variable('action', '');
97
-        $this->cat_id = $request->variable('c', 0);
98
-        $this->parent_id = $request->variable('parent_id', 0);
99
-        $this->update = ($this->request->is_set_post('update')) ? true : false;
100
-    }
101
-
102
-    /**
103
-     * Initialize defaults data for add page.
104
-     *
105
-     * @return null
106
-     */
107
-    public function action_add()
108
-    {
109
-        $this->cat_id = $this->parent_id;
110
-        $parents_list = $this->categorie->make_cat_select($this->parent_id);
111
-
112
-        // Fill categorie data with default values
113
-        if (!$this->update) {
114
-            $this->cat_data = [
115
-                'parent_id'                => $this->parent_id,
116
-                'cat_name'                 => $this->request->variable('cat_name', '', true),
117
-                'cat_desc'                 => '',
118
-                'cat_icon'                 => '',
119
-                'cat_allow_comments'       => true,
120
-                'cat_allow_votes'          => true,
121
-                'cat_must_describe'        => true,
122
-                'cat_count_all'            => false,
123
-                'cat_validate'             => false,
124
-                'enable_icons'             => false,
125
-
126
-                'display_subcat_list'    => true,
127
-
128
-                'cat_link_back'            => false,
129
-                'cat_cron_enable'          => false,
130
-                'cat_cron_freq'            => 7,
131
-                'cat_cron_nb_check'        => 1,
132
-            ];
133
-        }
134
-
135
-        $this->_display_cat_form($parents_list);
136
-    }
137
-
138
-    /**
139
-     * Display deleting page.
140
-     *
141
-     * @return null
142
-     */
143
-    public function action_delete()
144
-    {
145
-        if (!$this->cat_id) {
146
-            trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
147
-        }
148
-
149
-        $this->cat_data = $this->_get_cat_info($this->cat_id);
150
-
151
-        $subcats_id = [];
152
-        $subcats = $this->nestedset_category->get_subtree_data($this->cat_id);
153
-
154
-        foreach ($subcats as $row) {
155
-            $subcats_id[] = $row['cat_id'];
156
-        }
157
-
158
-        $cat_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id);
159
-
160
-        $sql = 'SELECT cat_id
12
+	/** @var \phpbb\cache\service */
13
+	protected $cache;
14
+
15
+	/** @var \phpbb\db\driver\driver_interface */
16
+	protected $db;
17
+
18
+	/** @var \phpbb\controller\helper */
19
+	protected $helper;
20
+
21
+	/** @var \phpbb\log\log */
22
+	protected $phpbb_log;
23
+
24
+	/** @var \phpbb\request\request */
25
+	protected $request;
26
+
27
+	/** @var \phpbb\template\template */
28
+	protected $template;
29
+
30
+	/** @var \phpbb\user */
31
+	protected $user;
32
+
33
+	/** @var \ernadoo\phpbbdirectory\core\categorie */
34
+	protected $categorie;
35
+
36
+	/** @var \ernadoo\phpbbdirectory\core\helper */
37
+	protected $dir_helper;
38
+
39
+	/** @var \ernadoo\phpbbdirectory\core\nestedset_category */
40
+	protected $nestedset_category;
41
+
42
+	/** @var string Custom form action */
43
+	protected $u_action;
44
+
45
+	/** @var string */
46
+	private $action;
47
+
48
+	/** @var array */
49
+	private $cat_data = [];
50
+
51
+	/** @var int */
52
+	private $cat_id;
53
+
54
+	/** @var array */
55
+	private $errors;
56
+
57
+	/** @var string */
58
+	private $form_key;
59
+
60
+	/** @var int */
61
+	private $parent_id;
62
+
63
+	/** @var bool */
64
+	private $update;
65
+
66
+	/**
67
+	 * Constructor.
68
+	 *
69
+	 * @param \phpbb\cache\service                            $cache              Cache object
70
+	 * @param \phpbb\db\driver\driver_interface               $db                 Database object
71
+	 * @param \phpbb\controller\helper                        $helper             Helper object
72
+	 * @param \phpbb\log\log                                  $log                Log object
73
+	 * @param \phpbb\request\request                          $request            Request object
74
+	 * @param \phpbb\template\template                        $template           Template object
75
+	 * @param \phpbb\user                                     $user               User object
76
+	 * @param \ernadoo\phpbbdirectory\core\categorie          $categorie          PhpBB Directory extension categorie object
77
+	 * @param \ernadoo\phpbbdirectory\core\helper             $dir_helper         PhpBB Directory extension helper object
78
+	 * @param \ernadoo\phpbbdirectory\core\nestedset_category $nestedset_category PhpBB Directory extension nestedset object
79
+	 */
80
+	public function __construct(\phpbb\cache\service $cache, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\log\log $log, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\helper $dir_helper, \ernadoo\phpbbdirectory\core\nestedset_category $nestedset_category)
81
+	{
82
+		$this->cache = $cache;
83
+		$this->db = $db;
84
+		$this->helper = $helper;
85
+		$this->phpbb_log = $log;
86
+		$this->request = $request;
87
+		$this->template = $template;
88
+		$this->user = $user;
89
+		$this->categorie = $categorie;
90
+		$this->dir_helper = $dir_helper;
91
+		$this->nestedset_category = $nestedset_category;
92
+
93
+		$this->form_key = 'acp_dir_cat';
94
+		add_form_key($this->form_key);
95
+
96
+		$this->action = $this->request->variable('action', '');
97
+		$this->cat_id = $request->variable('c', 0);
98
+		$this->parent_id = $request->variable('parent_id', 0);
99
+		$this->update = ($this->request->is_set_post('update')) ? true : false;
100
+	}
101
+
102
+	/**
103
+	 * Initialize defaults data for add page.
104
+	 *
105
+	 * @return null
106
+	 */
107
+	public function action_add()
108
+	{
109
+		$this->cat_id = $this->parent_id;
110
+		$parents_list = $this->categorie->make_cat_select($this->parent_id);
111
+
112
+		// Fill categorie data with default values
113
+		if (!$this->update) {
114
+			$this->cat_data = [
115
+				'parent_id'                => $this->parent_id,
116
+				'cat_name'                 => $this->request->variable('cat_name', '', true),
117
+				'cat_desc'                 => '',
118
+				'cat_icon'                 => '',
119
+				'cat_allow_comments'       => true,
120
+				'cat_allow_votes'          => true,
121
+				'cat_must_describe'        => true,
122
+				'cat_count_all'            => false,
123
+				'cat_validate'             => false,
124
+				'enable_icons'             => false,
125
+
126
+				'display_subcat_list'    => true,
127
+
128
+				'cat_link_back'            => false,
129
+				'cat_cron_enable'          => false,
130
+				'cat_cron_freq'            => 7,
131
+				'cat_cron_nb_check'        => 1,
132
+			];
133
+		}
134
+
135
+		$this->_display_cat_form($parents_list);
136
+	}
137
+
138
+	/**
139
+	 * Display deleting page.
140
+	 *
141
+	 * @return null
142
+	 */
143
+	public function action_delete()
144
+	{
145
+		if (!$this->cat_id) {
146
+			trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
147
+		}
148
+
149
+		$this->cat_data = $this->_get_cat_info($this->cat_id);
150
+
151
+		$subcats_id = [];
152
+		$subcats = $this->nestedset_category->get_subtree_data($this->cat_id);
153
+
154
+		foreach ($subcats as $row) {
155
+			$subcats_id[] = $row['cat_id'];
156
+		}
157
+
158
+		$cat_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id);
159
+
160
+		$sql = 'SELECT cat_id
161 161
 			FROM '.DIR_CAT_TABLE.'
162 162
 			WHERE cat_id <> '.(int) $this->cat_id;
163
-        $result = $this->db->sql_query_limit($sql, 1);
164
-
165
-        if ($this->db->sql_fetchrow($result)) {
166
-            $this->template->assign_vars([
167
-                'S_MOVE_DIR_CAT_OPTIONS'    => $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id), ]
168
-            );
169
-        }
170
-        $this->db->sql_freeresult($result);
171
-
172
-        $parent_id = ($this->parent_id == $this->cat_id) ? 0 : $this->parent_id;
173
-
174
-        $this->template->assign_vars([
175
-            'S_DELETE_DIR_CAT'        => true,
176
-            'U_ACTION'                => $this->u_action."&amp;parent_id={$parent_id}&amp;action=delete&amp;c=$this->cat_id",
177
-            'U_BACK'                  => $this->u_action.'&amp;parent_id='.$this->parent_id,
178
-
179
-            'DIR_CAT_NAME'             => $this->cat_data['cat_name'],
180
-            'S_HAS_SUBCATS'            => ($this->cat_data['right_id'] - $this->cat_data['left_id'] > 1) ? true : false,
181
-            'S_CATS_LIST'              => $cat_list,
182
-            'S_ERROR'                  => (count($this->errors)) ? true : false,
183
-            'ERROR_MSG'                => (count($this->errors)) ? implode('<br />', $this->errors) : '', ]
184
-        );
185
-    }
186
-
187
-    /**
188
-     * Initialize data for edit page.
189
-     *
190
-     * @return null
191
-     */
192
-    public function action_edit()
193
-    {
194
-        $row = $this->_get_cat_info($this->cat_id);
195
-
196
-        if (!$this->update) {
197
-            $this->cat_data = $row;
198
-        } else {
199
-            $this->cat_data['left_id'] = $row['left_id'];
200
-            $this->cat_data['right_id'] = $row['right_id'];
201
-        }
202
-
203
-        // Make sure no direct child categories are able to be selected as parents.
204
-        $exclude_cats = [];
205
-        foreach ($this->nestedset_category->get_subtree_data($this->cat_id) as $row2) {
206
-            $exclude_cats[] = $row2['cat_id'];
207
-        }
208
-        $parents_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $exclude_cats);
209
-
210
-        $this->_display_cat_form($parents_list);
211
-    }
212
-
213
-    /**
214
-     * Move order categories.
215
-     *
216
-     * @return null
217
-     */
218
-    public function action_move()
219
-    {
220
-        if (!$this->cat_id) {
221
-            trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
222
-        }
223
-
224
-        $sql = 'SELECT cat_id, cat_name, parent_id, left_id, right_id
163
+		$result = $this->db->sql_query_limit($sql, 1);
164
+
165
+		if ($this->db->sql_fetchrow($result)) {
166
+			$this->template->assign_vars([
167
+				'S_MOVE_DIR_CAT_OPTIONS'    => $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id), ]
168
+			);
169
+		}
170
+		$this->db->sql_freeresult($result);
171
+
172
+		$parent_id = ($this->parent_id == $this->cat_id) ? 0 : $this->parent_id;
173
+
174
+		$this->template->assign_vars([
175
+			'S_DELETE_DIR_CAT'        => true,
176
+			'U_ACTION'                => $this->u_action."&amp;parent_id={$parent_id}&amp;action=delete&amp;c=$this->cat_id",
177
+			'U_BACK'                  => $this->u_action.'&amp;parent_id='.$this->parent_id,
178
+
179
+			'DIR_CAT_NAME'             => $this->cat_data['cat_name'],
180
+			'S_HAS_SUBCATS'            => ($this->cat_data['right_id'] - $this->cat_data['left_id'] > 1) ? true : false,
181
+			'S_CATS_LIST'              => $cat_list,
182
+			'S_ERROR'                  => (count($this->errors)) ? true : false,
183
+			'ERROR_MSG'                => (count($this->errors)) ? implode('<br />', $this->errors) : '', ]
184
+		);
185
+	}
186
+
187
+	/**
188
+	 * Initialize data for edit page.
189
+	 *
190
+	 * @return null
191
+	 */
192
+	public function action_edit()
193
+	{
194
+		$row = $this->_get_cat_info($this->cat_id);
195
+
196
+		if (!$this->update) {
197
+			$this->cat_data = $row;
198
+		} else {
199
+			$this->cat_data['left_id'] = $row['left_id'];
200
+			$this->cat_data['right_id'] = $row['right_id'];
201
+		}
202
+
203
+		// Make sure no direct child categories are able to be selected as parents.
204
+		$exclude_cats = [];
205
+		foreach ($this->nestedset_category->get_subtree_data($this->cat_id) as $row2) {
206
+			$exclude_cats[] = $row2['cat_id'];
207
+		}
208
+		$parents_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $exclude_cats);
209
+
210
+		$this->_display_cat_form($parents_list);
211
+	}
212
+
213
+	/**
214
+	 * Move order categories.
215
+	 *
216
+	 * @return null
217
+	 */
218
+	public function action_move()
219
+	{
220
+		if (!$this->cat_id) {
221
+			trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
222
+		}
223
+
224
+		$sql = 'SELECT cat_id, cat_name, parent_id, left_id, right_id
225 225
 			FROM '.DIR_CAT_TABLE.'
226 226
 			WHERE cat_id = '.(int) $this->cat_id;
227
-        $result = $this->db->sql_query($sql);
228
-        $row = $this->db->sql_fetchrow($result);
229
-        $this->db->sql_freeresult($result);
230
-
231
-        if (!$row) {
232
-            trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
233
-        }
234
-
235
-        try {
236
-            $move_cat_name = $this->nestedset_category->{$this->action}($this->cat_id);
237
-        } catch (\Exception $e) {
238
-            trigger_error($e->getMessage(), E_USER_WARNING);
239
-        }
240
-
241
-        if ($move_cat_name !== false) {
242
-            $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_'.strtoupper($this->action), time(), [$row['cat_name'], $move_cat_name]);
243
-            $this->cache->destroy('sql', DIR_CAT_TABLE);
244
-        }
245
-
246
-        if ($this->request->is_ajax()) {
247
-            $json_response = new \phpbb\json_response();
248
-            $json_response->send(['success' => ($move_cat_name !== false)]);
249
-        }
250
-    }
251
-
252
-    /**
253
-     * Display progress bar for syncinc categories.
254
-     *
255
-     * @return null
256
-     */
257
-    public function action_progress_bar()
258
-    {
259
-        $start = $this->request->variable('start', 0);
260
-        $total = $this->request->variable('total', 0);
261
-
262
-        adm_page_header($this->user->lang['SYNC_IN_PROGRESS']);
263
-
264
-        $this->template->set_filenames([
265
-            'body'    => 'progress_bar.html', ]
266
-        );
267
-
268
-        $this->template->assign_vars([
269
-            'L_PROGRESS'            => $this->user->lang['SYNC_IN_PROGRESS'],
270
-            'L_PROGRESS_EXPLAIN'    => ($start && $total) ? $this->user->lang('SYNC_IN_PROGRESS_EXPLAIN', $start, $total) : $this->user->lang['SYNC_IN_PROGRESS'], ]
271
-        );
272
-
273
-        adm_page_footer();
274
-    }
275
-
276
-    /**
277
-     * Get link's ID interval for _sync_dir_links().
278
-     *
279
-     * @return null
280
-     */
281
-    public function action_sync()
282
-    {
283
-        if (!$this->cat_id) {
284
-            trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
285
-        }
286
-
287
-        @set_time_limit(0);
288
-
289
-        $sql = 'SELECT cat_name, cat_links
227
+		$result = $this->db->sql_query($sql);
228
+		$row = $this->db->sql_fetchrow($result);
229
+		$this->db->sql_freeresult($result);
230
+
231
+		if (!$row) {
232
+			trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
233
+		}
234
+
235
+		try {
236
+			$move_cat_name = $this->nestedset_category->{$this->action}($this->cat_id);
237
+		} catch (\Exception $e) {
238
+			trigger_error($e->getMessage(), E_USER_WARNING);
239
+		}
240
+
241
+		if ($move_cat_name !== false) {
242
+			$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_'.strtoupper($this->action), time(), [$row['cat_name'], $move_cat_name]);
243
+			$this->cache->destroy('sql', DIR_CAT_TABLE);
244
+		}
245
+
246
+		if ($this->request->is_ajax()) {
247
+			$json_response = new \phpbb\json_response();
248
+			$json_response->send(['success' => ($move_cat_name !== false)]);
249
+		}
250
+	}
251
+
252
+	/**
253
+	 * Display progress bar for syncinc categories.
254
+	 *
255
+	 * @return null
256
+	 */
257
+	public function action_progress_bar()
258
+	{
259
+		$start = $this->request->variable('start', 0);
260
+		$total = $this->request->variable('total', 0);
261
+
262
+		adm_page_header($this->user->lang['SYNC_IN_PROGRESS']);
263
+
264
+		$this->template->set_filenames([
265
+			'body'    => 'progress_bar.html', ]
266
+		);
267
+
268
+		$this->template->assign_vars([
269
+			'L_PROGRESS'            => $this->user->lang['SYNC_IN_PROGRESS'],
270
+			'L_PROGRESS_EXPLAIN'    => ($start && $total) ? $this->user->lang('SYNC_IN_PROGRESS_EXPLAIN', $start, $total) : $this->user->lang['SYNC_IN_PROGRESS'], ]
271
+		);
272
+
273
+		adm_page_footer();
274
+	}
275
+
276
+	/**
277
+	 * Get link's ID interval for _sync_dir_links().
278
+	 *
279
+	 * @return null
280
+	 */
281
+	public function action_sync()
282
+	{
283
+		if (!$this->cat_id) {
284
+			trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
285
+		}
286
+
287
+		@set_time_limit(0);
288
+
289
+		$sql = 'SELECT cat_name, cat_links
290 290
 			FROM '.DIR_CAT_TABLE.'
291 291
 			WHERE cat_id = '.(int) $this->cat_id;
292
-        $result = $this->db->sql_query($sql);
293
-        $row = $this->db->sql_fetchrow($result);
294
-        $this->db->sql_freeresult($result);
292
+		$result = $this->db->sql_query($sql);
293
+		$row = $this->db->sql_fetchrow($result);
294
+		$this->db->sql_freeresult($result);
295 295
 
296
-        if (!$row) {
297
-            trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
298
-        }
296
+		if (!$row) {
297
+			trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
298
+		}
299 299
 
300
-        $sql = 'SELECT MIN(link_id) as min_link_id, MAX(link_id) as max_link_id
300
+		$sql = 'SELECT MIN(link_id) as min_link_id, MAX(link_id) as max_link_id
301 301
 			FROM '.DIR_LINK_TABLE.'
302 302
 			WHERE link_cat = '.(int) $this->cat_id.'
303 303
 				AND link_active = 1';
304
-        $result = $this->db->sql_query($sql);
305
-        $row2 = $this->db->sql_fetchrow($result);
306
-        $this->db->sql_freeresult($result);
304
+		$result = $this->db->sql_query($sql);
305
+		$row2 = $this->db->sql_fetchrow($result);
306
+		$this->db->sql_freeresult($result);
307 307
 
308
-        // Typecast to int if there is no data available
309
-        $row2['min_link_id'] = (int) $row2['min_link_id'];
310
-        $row2['max_link_id'] = (int) $row2['max_link_id'];
308
+		// Typecast to int if there is no data available
309
+		$row2['min_link_id'] = (int) $row2['min_link_id'];
310
+		$row2['max_link_id'] = (int) $row2['max_link_id'];
311 311
 
312
-        $start = $this->request->variable('start', $row2['min_link_id']);
312
+		$start = $this->request->variable('start', $row2['min_link_id']);
313 313
 
314
-        $batch_size = 200;
315
-        $end = $start + $batch_size;
314
+		$batch_size = 200;
315
+		$end = $start + $batch_size;
316 316
 
317
-        // Sync all links in batch mode...
318
-        $this->_sync_dir_links($start, $end);
317
+		// Sync all links in batch mode...
318
+		$this->_sync_dir_links($start, $end);
319 319
 
320
-        if ($end < $row2['max_link_id']) {
321
-            // We really need to find a way of showing statistics... no progress here
322
-            $sql = 'SELECT COUNT(link_id) as num_links
320
+		if ($end < $row2['max_link_id']) {
321
+			// We really need to find a way of showing statistics... no progress here
322
+			$sql = 'SELECT COUNT(link_id) as num_links
323 323
 				FROM '.DIR_LINK_TABLE.'
324 324
 				WHERE link_cat = '.(int) $this->cat_id.'
325 325
 						AND link_active = 1
326 326
 						AND link_id BETWEEN '.$start.' AND '.$end;
327
-            $result = $this->db->sql_query($sql);
328
-            $links_done = $this->request->variable('links_done', 0) + (int) $this->db->sql_fetchfield('num_links');
329
-            $this->db->sql_freeresult($result);
330
-
331
-            $start += $batch_size;
332
-
333
-            $url = $this->u_action."&amp;parent_id={$this->parent_id}&amp;c=$this->cat_id&amp;action=sync&amp;start=$start&amp;links_done=$links_done&amp;total={$row['cat_links']}";
334
-
335
-            meta_refresh(0, $url);
336
-
337
-            $this->template->assign_vars([
338
-                'U_PROGRESS_BAR'         => $this->u_action."&amp;action=progress_bar&amp;start=$links_done&amp;total={$row['cat_links']}",
339
-                'UA_PROGRESS_BAR'        => addslashes($this->u_action."&amp;action=progress_bar&amp;start=$links_done&amp;total={$row['cat_links']}"),
340
-                'S_CONTINUE_SYNC'        => true,
341
-                'L_PROGRESS_EXPLAIN'     => $this->user->lang('SYNC_IN_PROGRESS_EXPLAIN', $links_done, $row['cat_links']), ]
342
-            );
343
-
344
-            return;
345
-        }
346
-
347
-        $url = $this->u_action."&amp;parent_id={$this->parent_id}&amp;c=$this->cat_id&amp;action=sync_cat";
348
-        meta_refresh(0, $url);
349
-
350
-        $this->template->assign_vars([
351
-            'U_PROGRESS_BAR'         => $this->u_action.'&amp;action=progress_bar',
352
-            'UA_PROGRESS_BAR'        => addslashes($this->u_action.'&amp;action=progress_bar'),
353
-            'S_CONTINUE_SYNC'        => true,
354
-            'L_PROGRESS_EXPLAIN'     => $this->user->lang('SYNC_IN_PROGRESS_EXPLAIN', 0, $row['cat_links']), ]
355
-        );
356
-    }
357
-
358
-    /**
359
-     * Sync category data.
360
-     *
361
-     * @return null
362
-     */
363
-    public function action_sync_cat()
364
-    {
365
-        $sql = 'SELECT cat_name
327
+			$result = $this->db->sql_query($sql);
328
+			$links_done = $this->request->variable('links_done', 0) + (int) $this->db->sql_fetchfield('num_links');
329
+			$this->db->sql_freeresult($result);
330
+
331
+			$start += $batch_size;
332
+
333
+			$url = $this->u_action."&amp;parent_id={$this->parent_id}&amp;c=$this->cat_id&amp;action=sync&amp;start=$start&amp;links_done=$links_done&amp;total={$row['cat_links']}";
334
+
335
+			meta_refresh(0, $url);
336
+
337
+			$this->template->assign_vars([
338
+				'U_PROGRESS_BAR'         => $this->u_action."&amp;action=progress_bar&amp;start=$links_done&amp;total={$row['cat_links']}",
339
+				'UA_PROGRESS_BAR'        => addslashes($this->u_action."&amp;action=progress_bar&amp;start=$links_done&amp;total={$row['cat_links']}"),
340
+				'S_CONTINUE_SYNC'        => true,
341
+				'L_PROGRESS_EXPLAIN'     => $this->user->lang('SYNC_IN_PROGRESS_EXPLAIN', $links_done, $row['cat_links']), ]
342
+			);
343
+
344
+			return;
345
+		}
346
+
347
+		$url = $this->u_action."&amp;parent_id={$this->parent_id}&amp;c=$this->cat_id&amp;action=sync_cat";
348
+		meta_refresh(0, $url);
349
+
350
+		$this->template->assign_vars([
351
+			'U_PROGRESS_BAR'         => $this->u_action.'&amp;action=progress_bar',
352
+			'UA_PROGRESS_BAR'        => addslashes($this->u_action.'&amp;action=progress_bar'),
353
+			'S_CONTINUE_SYNC'        => true,
354
+			'L_PROGRESS_EXPLAIN'     => $this->user->lang('SYNC_IN_PROGRESS_EXPLAIN', 0, $row['cat_links']), ]
355
+		);
356
+	}
357
+
358
+	/**
359
+	 * Sync category data.
360
+	 *
361
+	 * @return null
362
+	 */
363
+	public function action_sync_cat()
364
+	{
365
+		$sql = 'SELECT cat_name
366 366
 			FROM '.DIR_CAT_TABLE.'
367 367
 			WHERE cat_id = '.(int) $this->cat_id;
368
-        $result = $this->db->sql_query($sql);
369
-        $row = $this->db->sql_fetchrow($result);
370
-        $this->db->sql_freeresult($result);
371
-
372
-        if (!$row) {
373
-            trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
374
-        }
375
-
376
-        $this->_sync_dir_cat($this->cat_id);
377
-
378
-        $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_SYNC', time(), [$row['cat_name']]);
379
-        $this->cache->destroy('sql', DIR_CAT_TABLE);
380
-
381
-        $this->template->assign_var('L_DIR_CAT_RESYNCED', $this->user->lang('DIR_CAT_RESYNCED', $row['cat_name']));
382
-    }
383
-
384
-    /**
385
-     * Display categories page.
386
-     *
387
-     * @return null
388
-     */
389
-    public function display_cats()
390
-    {
391
-        // Default management page
392
-        if (!$this->parent_id) {
393
-            $navigation = $this->user->lang['DIR_INDEX'];
394
-        } else {
395
-            $navigation = '<a href="'.$this->u_action.'">'.$this->user->lang['DIR_INDEX'].'</a>';
396
-
397
-            $cats_nav = $this->nestedset_category->get_path_data($this->parent_id);
398
-
399
-            foreach ($cats_nav as $row) {
400
-                if ($row['cat_id'] == $this->parent_id) {
401
-                    $navigation .= ' -&gt; '.$row['cat_name'];
402
-                } else {
403
-                    $navigation .= ' -&gt; <a href="'.$this->u_action.'&amp;parent_id='.$row['cat_id'].'">'.$row['cat_name'].'</a>';
404
-                }
405
-            }
406
-        }
407
-
408
-        // Jumpbox
409
-        $cat_box = $this->categorie->make_cat_select($this->parent_id);
410
-
411
-        if ($this->action == 'sync' || $this->action == 'sync_cat') {
412
-            $this->template->assign_var('S_RESYNCED', true);
413
-        }
414
-
415
-        $sql = 'SELECT cat_id, parent_id, right_id, left_id, cat_name, cat_icon, cat_desc_uid, cat_desc_bitfield, cat_desc, cat_desc_options, cat_links
368
+		$result = $this->db->sql_query($sql);
369
+		$row = $this->db->sql_fetchrow($result);
370
+		$this->db->sql_freeresult($result);
371
+
372
+		if (!$row) {
373
+			trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
374
+		}
375
+
376
+		$this->_sync_dir_cat($this->cat_id);
377
+
378
+		$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_SYNC', time(), [$row['cat_name']]);
379
+		$this->cache->destroy('sql', DIR_CAT_TABLE);
380
+
381
+		$this->template->assign_var('L_DIR_CAT_RESYNCED', $this->user->lang('DIR_CAT_RESYNCED', $row['cat_name']));
382
+	}
383
+
384
+	/**
385
+	 * Display categories page.
386
+	 *
387
+	 * @return null
388
+	 */
389
+	public function display_cats()
390
+	{
391
+		// Default management page
392
+		if (!$this->parent_id) {
393
+			$navigation = $this->user->lang['DIR_INDEX'];
394
+		} else {
395
+			$navigation = '<a href="'.$this->u_action.'">'.$this->user->lang['DIR_INDEX'].'</a>';
396
+
397
+			$cats_nav = $this->nestedset_category->get_path_data($this->parent_id);
398
+
399
+			foreach ($cats_nav as $row) {
400
+				if ($row['cat_id'] == $this->parent_id) {
401
+					$navigation .= ' -&gt; '.$row['cat_name'];
402
+				} else {
403
+					$navigation .= ' -&gt; <a href="'.$this->u_action.'&amp;parent_id='.$row['cat_id'].'">'.$row['cat_name'].'</a>';
404
+				}
405
+			}
406
+		}
407
+
408
+		// Jumpbox
409
+		$cat_box = $this->categorie->make_cat_select($this->parent_id);
410
+
411
+		if ($this->action == 'sync' || $this->action == 'sync_cat') {
412
+			$this->template->assign_var('S_RESYNCED', true);
413
+		}
414
+
415
+		$sql = 'SELECT cat_id, parent_id, right_id, left_id, cat_name, cat_icon, cat_desc_uid, cat_desc_bitfield, cat_desc, cat_desc_options, cat_links
416 416
 			FROM '.DIR_CAT_TABLE.'
417 417
 			WHERE parent_id = '.(int) $this->parent_id.'
418 418
 			ORDER BY left_id';
419
-        $result = $this->db->sql_query($sql);
420
-
421
-        if ($row = $this->db->sql_fetchrow($result)) {
422
-            do {
423
-                $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="'.$this->user->lang['DIR_SUBCAT'].'" />' : '<img src="images/icon_folder.gif" alt="'.$this->user->lang['FOLDER'].'" />';
424
-
425
-                $url = $this->u_action."&amp;parent_id=$this->parent_id&amp;c={$row['cat_id']}";
426
-
427
-                $this->template->assign_block_vars('cats', [
428
-                    'FOLDER_IMAGE'         => $folder_image,
429
-                    'CAT_IMAGE'            => ($row['cat_icon']) ? '<img src="'.$this->dir_helper->get_img_path('icons', $row['cat_icon']).'" alt="" />' : '',
430
-                    'CAT_NAME'             => $row['cat_name'],
431
-                    'CAT_DESCRIPTION'      => generate_text_for_display($row['cat_desc'], $row['cat_desc_uid'], $row['cat_desc_bitfield'], $row['cat_desc_options']),
432
-                    'CAT_LINKS'            => $row['cat_links'],
433
-
434
-                    'U_CAT'                => $this->u_action.'&amp;parent_id='.$row['cat_id'],
435
-                    'U_MOVE_UP'            => $url.'&amp;action=move_up',
436
-                    'U_MOVE_DOWN'          => $url.'&amp;action=move_down',
437
-                    'U_EDIT'               => $url.'&amp;action=edit',
438
-                    'U_DELETE'             => $url.'&amp;action=delete',
439
-                    'U_SYNC'               => $url.'&amp;action=sync', ]
440
-                );
441
-            } while ($row = $this->db->sql_fetchrow($result));
442
-        } elseif ($this->parent_id) {
443
-            $row = $this->_get_cat_info($this->parent_id);
444
-
445
-            $url = $this->u_action.'&amp;parent_id='.$this->parent_id.'&amp;c='.$row['cat_id'];
446
-
447
-            $this->template->assign_vars([
448
-                'S_NO_CATS'            => true,
449
-
450
-                'U_EDIT'              => $url.'&amp;action=edit',
451
-                'U_DELETE'            => $url.'&amp;action=delete',
452
-                'U_SYNC'              => $url.'&amp;action=sync', ]
453
-            );
454
-        }
455
-        $this->db->sql_freeresult($result);
456
-
457
-        $this->template->assign_vars([
458
-            'ERROR_MSG'        => (count($this->errors)) ? implode('<br />', $this->errors) : '',
459
-            'NAVIGATION'       => $navigation,
460
-            'CAT_BOX'          => $cat_box,
461
-            'U_SEL_ACTION'     => $this->u_action,
462
-            'U_ACTION'         => $this->u_action.'&amp;parent_id='.$this->parent_id,
463
-
464
-            'U_PROGRESS_BAR'     => $this->u_action.'&amp;action=progress_bar',
465
-            'UA_PROGRESS_BAR'    => addslashes($this->u_action.'&amp;action=progress_bar'),
466
-        ]);
467
-    }
468
-
469
-    /**
470
-     * Set page url.
471
-     *
472
-     * @param string $u_action Custom form action
473
-     *
474
-     * @return null
475
-     */
476
-    public function set_page_url($u_action)
477
-    {
478
-        $this->u_action = $u_action;
479
-    }
480
-
481
-    /**
482
-     * Update cat table.
483
-     *
484
-     * @return null
485
-     */
486
-    public function update()
487
-    {
488
-        if (!check_form_key($this->form_key)) {
489
-            $this->update = false;
490
-            $this->errors[] = $this->user->lang['FORM_INVALID'];
491
-        }
492
-
493
-        switch ($this->action) {
494
-            case 'delete':
495
-                $action_subcats = $this->request->variable('action_subcats', '');
496
-                $subcats_to_id = $this->request->variable('subcats_to_id', 0);
497
-                $action_links = $this->request->variable('action_links', '');
498
-                $links_to_id = $this->request->variable('links_to_id', 0);
499
-
500
-                try {
501
-                    $this->errors = $this->_delete_cat($action_links, $action_subcats, $links_to_id, $subcats_to_id);
502
-                } catch (\Exception $e) {
503
-                    trigger_error($e->getMessage(), E_USER_WARNING);
504
-                }
505
-
506
-                if (count($this->errors)) {
507
-                    break;
508
-                }
509
-
510
-                $this->cache->destroy('sql', DIR_CAT_TABLE);
511
-
512
-                trigger_error($this->user->lang['DIR_CAT_DELETED'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id));
513
-
514
-                break;
515
-
516
-            case 'edit':
517
-                $this->cat_data = [
518
-                    'cat_id'        => $this->cat_id,
519
-                ];
520
-                // No break here
521
-            case 'add':
522
-
523
-                $this->cat_data += [
524
-                    'parent_id'                => $this->request->variable('cat_parent_id', (int) $this->parent_id),
525
-                    'cat_parents'              => '',
526
-                    'cat_name'                 => $this->request->variable('cat_name', '', true),
527
-                    'cat_desc'                 => $this->request->variable('cat_desc', '', true),
528
-                    'cat_desc_uid'             => '',
529
-                    'cat_desc_options'         => 7,
530
-                    'cat_desc_bitfield'        => '',
531
-                    'cat_icon'                 => $this->request->variable('cat_icon', ''),
532
-                    'display_subcat_list'      => $this->request->variable('display_on_index', false),
533
-                    'cat_allow_comments'       => $this->request->variable('allow_comments', 1),
534
-                    'cat_allow_votes'          => $this->request->variable('allow_votes', 1),
535
-                    'cat_must_describe'        => $this->request->variable('must_describe', 1),
536
-                    'cat_count_all'            => $this->request->variable('count_all', 0),
537
-                    'cat_validate'             => $this->request->variable('validate', 0),
538
-                    'cat_link_back'            => $this->request->variable('link_back', 0),
539
-                    'cat_cron_enable'          => $this->request->variable('cron_enable', 0),
540
-                    'cat_cron_freq'            => $this->request->variable('cron_every', 7),
541
-                    'cat_cron_nb_check'        => $this->request->variable('nb_check', 1),
542
-                ];
543
-
544
-                // Get data for cat description if specified
545
-                if ($this->cat_data['cat_desc']) {
546
-                    generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_parse_bbcode', false), $this->request->variable('desc_parse_urls', false), $this->request->variable('desc_parse_smilies', false));
547
-                }
548
-
549
-                try {
550
-                    $this->errors = $this->_update_cat_data();
551
-                } catch (\Exception $e) {
552
-                    trigger_error($e->getMessage(), E_USER_WARNING);
553
-                }
554
-
555
-                if (!count($this->errors)) {
556
-                    $this->cache->destroy('sql', DIR_CAT_TABLE);
557
-
558
-                    $message = ($this->action == 'add') ? $this->user->lang['DIR_CAT_CREATED'] : $this->user->lang['DIR_CAT_UPDATED'];
559
-
560
-                    trigger_error($message.adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id));
561
-                }
562
-
563
-            break;
564
-        }
565
-    }
566
-
567
-    /**
568
-     * Display form.
569
-     *
570
-     * @param string $parents_list Drop-down list
571
-     *
572
-     * @return null
573
-     */
574
-    private function _display_cat_form($parents_list)
575
-    {
576
-        $dir_cat_desc_data = [
577
-            'text'             => $this->cat_data['cat_desc'],
578
-            'allow_bbcode'     => true,
579
-            'allow_smilies'    => true,
580
-            'allow_urls'       => true,
581
-        ];
582
-
583
-        // Parse desciption if specified
584
-        if ($this->cat_data['cat_desc']) {
585
-            if (!isset($this->cat_data['cat_desc_uid'])) {
586
-                // Before we are able to display the preview and plane text, we need to parse our $request->variable()'d value...
587
-                $this->cat_data['cat_desc_uid'] = '';
588
-                $this->cat_data['cat_desc_bitfield'] = '';
589
-                $this->cat_data['cat_desc_options'] = 0;
590
-
591
-                generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_allow_bbcode', false), $this->request->variable('desc_allow_urls', false), $this->request->variable('desc_allow_smilies', false));
592
-            }
593
-
594
-            // decode...
595
-            $dir_cat_desc_data = generate_text_for_edit($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_options']);
596
-        }
597
-
598
-        $this->template->assign_vars([
599
-            'S_EDIT_CAT'          => true,
600
-            'S_ERROR'             => (count($this->errors)) ? true : false,
601
-            'S_CAT_PARENT_ID'     => $this->cat_data['parent_id'],
602
-            'S_ADD_ACTION'        => ($this->action == 'add') ? true : false,
603
-
604
-            'U_BACK'               => $this->u_action.'&amp;parent_id='.$this->parent_id,
605
-            'U_EDIT_ACTION'        => $this->u_action."&amp;parent_id={$this->parent_id}&amp;action=$this->action&amp;c=$this->cat_id",
606
-
607
-            'L_TITLE'                      => $this->user->lang['DIR_'.strtoupper($this->action).'_CAT'],
608
-            'ERROR_MSG'                    => (count($this->errors)) ? implode('<br />', $this->errors) : '',
609
-            'ICON_IMAGE'                   => ($this->cat_data['cat_icon']) ? $this->dir_helper->get_img_path('icons', $this->cat_data['cat_icon']) : 'images/spacer.gif',
610
-
611
-            'DIR_ICON_PATH'                => $this->dir_helper->get_img_path('icons'),
612
-            'DIR_CAT_NAME'                 => $this->cat_data['cat_name'],
613
-            'DIR_CAT_DESC'                 => $dir_cat_desc_data['text'],
614
-
615
-            'S_DESC_BBCODE_CHECKED'        => ($dir_cat_desc_data['allow_bbcode']) ? true : false,
616
-            'S_DESC_SMILIES_CHECKED'       => ($dir_cat_desc_data['allow_smilies']) ? true : false,
617
-            'S_DESC_URLS_CHECKED'          => ($dir_cat_desc_data['allow_urls']) ? true : false,
618
-            'S_DISPLAY_SUBCAT_LIST'        => ($this->cat_data['display_subcat_list']) ? true : false,
619
-            'S_PARENT_OPTIONS'             => $parents_list,
620
-            'S_ICON_OPTIONS'               => $this->_get_dir_icon_list($this->dir_helper->get_img_path('icons'), $this->cat_data['cat_icon']),
621
-            'S_ALLOW_COMMENTS'             => ($this->cat_data['cat_allow_comments']) ? true : false,
622
-            'S_ALLOW_VOTES'                => ($this->cat_data['cat_allow_votes']) ? true : false,
623
-            'S_MUST_DESCRIBE'              => ($this->cat_data['cat_must_describe']) ? true : false,
624
-            'S_COUNT_ALL'                  => ($this->cat_data['cat_count_all']) ? true : false,
625
-            'S_VALIDATE'                   => ($this->cat_data['cat_validate']) ? true : false,
626
-
627
-            'DIR_CRON_EVERY'               => $this->cat_data['cat_cron_freq'],
628
-            'DIR_NEXT_CRON_ACTION'         => !empty($this->cat_data['cat_cron_next']) ? $this->user->format_date($this->cat_data['cat_cron_next']) : '-',
629
-            'DIR_CRON_NB_CHECK'            => $this->cat_data['cat_cron_nb_check'],
630
-
631
-            'S_LINK_BACK'                  => ($this->cat_data['cat_link_back']) ? true : false,
632
-            'S_CRON_ENABLE'                => ($this->cat_data['cat_cron_enable']) ? true : false,
633
-
634
-            'U_DATE'                    => $this->helper->route('ernadoo_phpbbdirectory_ajax_controller'),
635
-        ]);
636
-    }
637
-
638
-    /**
639
-     * Get category details.
640
-     *
641
-     * @param int $cat_id The category ID
642
-     *
643
-     * @return array
644
-     */
645
-    private function _get_cat_info($cat_id)
646
-    {
647
-        $sql = 'SELECT cat_id, parent_id, right_id, left_id, cat_desc, cat_desc_uid, cat_desc_options, cat_icon, cat_name, display_subcat_list, cat_allow_comments, cat_allow_votes, cat_must_describe, cat_count_all, cat_validate, cat_cron_freq, cat_cron_nb_check, cat_link_back, cat_cron_enable, cat_cron_next
419
+		$result = $this->db->sql_query($sql);
420
+
421
+		if ($row = $this->db->sql_fetchrow($result)) {
422
+			do {
423
+				$folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="'.$this->user->lang['DIR_SUBCAT'].'" />' : '<img src="images/icon_folder.gif" alt="'.$this->user->lang['FOLDER'].'" />';
424
+
425
+				$url = $this->u_action."&amp;parent_id=$this->parent_id&amp;c={$row['cat_id']}";
426
+
427
+				$this->template->assign_block_vars('cats', [
428
+					'FOLDER_IMAGE'         => $folder_image,
429
+					'CAT_IMAGE'            => ($row['cat_icon']) ? '<img src="'.$this->dir_helper->get_img_path('icons', $row['cat_icon']).'" alt="" />' : '',
430
+					'CAT_NAME'             => $row['cat_name'],
431
+					'CAT_DESCRIPTION'      => generate_text_for_display($row['cat_desc'], $row['cat_desc_uid'], $row['cat_desc_bitfield'], $row['cat_desc_options']),
432
+					'CAT_LINKS'            => $row['cat_links'],
433
+
434
+					'U_CAT'                => $this->u_action.'&amp;parent_id='.$row['cat_id'],
435
+					'U_MOVE_UP'            => $url.'&amp;action=move_up',
436
+					'U_MOVE_DOWN'          => $url.'&amp;action=move_down',
437
+					'U_EDIT'               => $url.'&amp;action=edit',
438
+					'U_DELETE'             => $url.'&amp;action=delete',
439
+					'U_SYNC'               => $url.'&amp;action=sync', ]
440
+				);
441
+			} while ($row = $this->db->sql_fetchrow($result));
442
+		} elseif ($this->parent_id) {
443
+			$row = $this->_get_cat_info($this->parent_id);
444
+
445
+			$url = $this->u_action.'&amp;parent_id='.$this->parent_id.'&amp;c='.$row['cat_id'];
446
+
447
+			$this->template->assign_vars([
448
+				'S_NO_CATS'            => true,
449
+
450
+				'U_EDIT'              => $url.'&amp;action=edit',
451
+				'U_DELETE'            => $url.'&amp;action=delete',
452
+				'U_SYNC'              => $url.'&amp;action=sync', ]
453
+			);
454
+		}
455
+		$this->db->sql_freeresult($result);
456
+
457
+		$this->template->assign_vars([
458
+			'ERROR_MSG'        => (count($this->errors)) ? implode('<br />', $this->errors) : '',
459
+			'NAVIGATION'       => $navigation,
460
+			'CAT_BOX'          => $cat_box,
461
+			'U_SEL_ACTION'     => $this->u_action,
462
+			'U_ACTION'         => $this->u_action.'&amp;parent_id='.$this->parent_id,
463
+
464
+			'U_PROGRESS_BAR'     => $this->u_action.'&amp;action=progress_bar',
465
+			'UA_PROGRESS_BAR'    => addslashes($this->u_action.'&amp;action=progress_bar'),
466
+		]);
467
+	}
468
+
469
+	/**
470
+	 * Set page url.
471
+	 *
472
+	 * @param string $u_action Custom form action
473
+	 *
474
+	 * @return null
475
+	 */
476
+	public function set_page_url($u_action)
477
+	{
478
+		$this->u_action = $u_action;
479
+	}
480
+
481
+	/**
482
+	 * Update cat table.
483
+	 *
484
+	 * @return null
485
+	 */
486
+	public function update()
487
+	{
488
+		if (!check_form_key($this->form_key)) {
489
+			$this->update = false;
490
+			$this->errors[] = $this->user->lang['FORM_INVALID'];
491
+		}
492
+
493
+		switch ($this->action) {
494
+			case 'delete':
495
+				$action_subcats = $this->request->variable('action_subcats', '');
496
+				$subcats_to_id = $this->request->variable('subcats_to_id', 0);
497
+				$action_links = $this->request->variable('action_links', '');
498
+				$links_to_id = $this->request->variable('links_to_id', 0);
499
+
500
+				try {
501
+					$this->errors = $this->_delete_cat($action_links, $action_subcats, $links_to_id, $subcats_to_id);
502
+				} catch (\Exception $e) {
503
+					trigger_error($e->getMessage(), E_USER_WARNING);
504
+				}
505
+
506
+				if (count($this->errors)) {
507
+					break;
508
+				}
509
+
510
+				$this->cache->destroy('sql', DIR_CAT_TABLE);
511
+
512
+				trigger_error($this->user->lang['DIR_CAT_DELETED'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id));
513
+
514
+				break;
515
+
516
+			case 'edit':
517
+				$this->cat_data = [
518
+					'cat_id'        => $this->cat_id,
519
+				];
520
+				// No break here
521
+			case 'add':
522
+
523
+				$this->cat_data += [
524
+					'parent_id'                => $this->request->variable('cat_parent_id', (int) $this->parent_id),
525
+					'cat_parents'              => '',
526
+					'cat_name'                 => $this->request->variable('cat_name', '', true),
527
+					'cat_desc'                 => $this->request->variable('cat_desc', '', true),
528
+					'cat_desc_uid'             => '',
529
+					'cat_desc_options'         => 7,
530
+					'cat_desc_bitfield'        => '',
531
+					'cat_icon'                 => $this->request->variable('cat_icon', ''),
532
+					'display_subcat_list'      => $this->request->variable('display_on_index', false),
533
+					'cat_allow_comments'       => $this->request->variable('allow_comments', 1),
534
+					'cat_allow_votes'          => $this->request->variable('allow_votes', 1),
535
+					'cat_must_describe'        => $this->request->variable('must_describe', 1),
536
+					'cat_count_all'            => $this->request->variable('count_all', 0),
537
+					'cat_validate'             => $this->request->variable('validate', 0),
538
+					'cat_link_back'            => $this->request->variable('link_back', 0),
539
+					'cat_cron_enable'          => $this->request->variable('cron_enable', 0),
540
+					'cat_cron_freq'            => $this->request->variable('cron_every', 7),
541
+					'cat_cron_nb_check'        => $this->request->variable('nb_check', 1),
542
+				];
543
+
544
+				// Get data for cat description if specified
545
+				if ($this->cat_data['cat_desc']) {
546
+					generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_parse_bbcode', false), $this->request->variable('desc_parse_urls', false), $this->request->variable('desc_parse_smilies', false));
547
+				}
548
+
549
+				try {
550
+					$this->errors = $this->_update_cat_data();
551
+				} catch (\Exception $e) {
552
+					trigger_error($e->getMessage(), E_USER_WARNING);
553
+				}
554
+
555
+				if (!count($this->errors)) {
556
+					$this->cache->destroy('sql', DIR_CAT_TABLE);
557
+
558
+					$message = ($this->action == 'add') ? $this->user->lang['DIR_CAT_CREATED'] : $this->user->lang['DIR_CAT_UPDATED'];
559
+
560
+					trigger_error($message.adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id));
561
+				}
562
+
563
+			break;
564
+		}
565
+	}
566
+
567
+	/**
568
+	 * Display form.
569
+	 *
570
+	 * @param string $parents_list Drop-down list
571
+	 *
572
+	 * @return null
573
+	 */
574
+	private function _display_cat_form($parents_list)
575
+	{
576
+		$dir_cat_desc_data = [
577
+			'text'             => $this->cat_data['cat_desc'],
578
+			'allow_bbcode'     => true,
579
+			'allow_smilies'    => true,
580
+			'allow_urls'       => true,
581
+		];
582
+
583
+		// Parse desciption if specified
584
+		if ($this->cat_data['cat_desc']) {
585
+			if (!isset($this->cat_data['cat_desc_uid'])) {
586
+				// Before we are able to display the preview and plane text, we need to parse our $request->variable()'d value...
587
+				$this->cat_data['cat_desc_uid'] = '';
588
+				$this->cat_data['cat_desc_bitfield'] = '';
589
+				$this->cat_data['cat_desc_options'] = 0;
590
+
591
+				generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_allow_bbcode', false), $this->request->variable('desc_allow_urls', false), $this->request->variable('desc_allow_smilies', false));
592
+			}
593
+
594
+			// decode...
595
+			$dir_cat_desc_data = generate_text_for_edit($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_options']);
596
+		}
597
+
598
+		$this->template->assign_vars([
599
+			'S_EDIT_CAT'          => true,
600
+			'S_ERROR'             => (count($this->errors)) ? true : false,
601
+			'S_CAT_PARENT_ID'     => $this->cat_data['parent_id'],
602
+			'S_ADD_ACTION'        => ($this->action == 'add') ? true : false,
603
+
604
+			'U_BACK'               => $this->u_action.'&amp;parent_id='.$this->parent_id,
605
+			'U_EDIT_ACTION'        => $this->u_action."&amp;parent_id={$this->parent_id}&amp;action=$this->action&amp;c=$this->cat_id",
606
+
607
+			'L_TITLE'                      => $this->user->lang['DIR_'.strtoupper($this->action).'_CAT'],
608
+			'ERROR_MSG'                    => (count($this->errors)) ? implode('<br />', $this->errors) : '',
609
+			'ICON_IMAGE'                   => ($this->cat_data['cat_icon']) ? $this->dir_helper->get_img_path('icons', $this->cat_data['cat_icon']) : 'images/spacer.gif',
610
+
611
+			'DIR_ICON_PATH'                => $this->dir_helper->get_img_path('icons'),
612
+			'DIR_CAT_NAME'                 => $this->cat_data['cat_name'],
613
+			'DIR_CAT_DESC'                 => $dir_cat_desc_data['text'],
614
+
615
+			'S_DESC_BBCODE_CHECKED'        => ($dir_cat_desc_data['allow_bbcode']) ? true : false,
616
+			'S_DESC_SMILIES_CHECKED'       => ($dir_cat_desc_data['allow_smilies']) ? true : false,
617
+			'S_DESC_URLS_CHECKED'          => ($dir_cat_desc_data['allow_urls']) ? true : false,
618
+			'S_DISPLAY_SUBCAT_LIST'        => ($this->cat_data['display_subcat_list']) ? true : false,
619
+			'S_PARENT_OPTIONS'             => $parents_list,
620
+			'S_ICON_OPTIONS'               => $this->_get_dir_icon_list($this->dir_helper->get_img_path('icons'), $this->cat_data['cat_icon']),
621
+			'S_ALLOW_COMMENTS'             => ($this->cat_data['cat_allow_comments']) ? true : false,
622
+			'S_ALLOW_VOTES'                => ($this->cat_data['cat_allow_votes']) ? true : false,
623
+			'S_MUST_DESCRIBE'              => ($this->cat_data['cat_must_describe']) ? true : false,
624
+			'S_COUNT_ALL'                  => ($this->cat_data['cat_count_all']) ? true : false,
625
+			'S_VALIDATE'                   => ($this->cat_data['cat_validate']) ? true : false,
626
+
627
+			'DIR_CRON_EVERY'               => $this->cat_data['cat_cron_freq'],
628
+			'DIR_NEXT_CRON_ACTION'         => !empty($this->cat_data['cat_cron_next']) ? $this->user->format_date($this->cat_data['cat_cron_next']) : '-',
629
+			'DIR_CRON_NB_CHECK'            => $this->cat_data['cat_cron_nb_check'],
630
+
631
+			'S_LINK_BACK'                  => ($this->cat_data['cat_link_back']) ? true : false,
632
+			'S_CRON_ENABLE'                => ($this->cat_data['cat_cron_enable']) ? true : false,
633
+
634
+			'U_DATE'                    => $this->helper->route('ernadoo_phpbbdirectory_ajax_controller'),
635
+		]);
636
+	}
637
+
638
+	/**
639
+	 * Get category details.
640
+	 *
641
+	 * @param int $cat_id The category ID
642
+	 *
643
+	 * @return array
644
+	 */
645
+	private function _get_cat_info($cat_id)
646
+	{
647
+		$sql = 'SELECT cat_id, parent_id, right_id, left_id, cat_desc, cat_desc_uid, cat_desc_options, cat_icon, cat_name, display_subcat_list, cat_allow_comments, cat_allow_votes, cat_must_describe, cat_count_all, cat_validate, cat_cron_freq, cat_cron_nb_check, cat_link_back, cat_cron_enable, cat_cron_next
648 648
 			FROM '.DIR_CAT_TABLE.'
649 649
 			WHERE cat_id = '.(int) $cat_id;
650
-        $result = $this->db->sql_query($sql);
651
-        $row = $this->db->sql_fetchrow($result);
652
-        $this->db->sql_freeresult($result);
653
-
654
-        if (!$row) {
655
-            trigger_error('DIR_ERROR_NO_CATS', E_USER_ERROR);
656
-        }
657
-
658
-        return $row;
659
-    }
660
-
661
-    /**
662
-     * Update category data.
663
-     *
664
-     * @return array
665
-     */
666
-    private function _update_cat_data()
667
-    {
668
-        if (!$this->cat_data['cat_name']) {
669
-            $this->errors[] = $this->user->lang['DIR_CAT_NAME_EMPTY'];
670
-        }
671
-
672
-        if (utf8_strlen($this->cat_data['cat_desc']) > 4000) {
673
-            $this->errors[] = $this->user->lang['DIR_CAT_DESC_TOO_LONG'];
674
-        }
675
-
676
-        if (($this->cat_data['cat_cron_enable'] && $this->cat_data['cat_cron_freq'] <= 0) || $this->cat_data['cat_cron_nb_check'] < 0) {
677
-            $this->errors[] = $this->user->lang['DIR_CAT_DATA_NEGATIVE'];
678
-        }
679
-
680
-        // Unset data that are not database fields
681
-        $cat_data_sql = $this->cat_data;
682
-
683
-        // What are we going to do tonight Brain? The same thing we do everynight,
684
-        // try to take over the world ... or decide whether to continue update
685
-        // and if so, whether it's a new cat/link or an existing one
686
-        if (count($this->errors)) {
687
-            return $this->errors;
688
-        }
689
-
690
-        if (!$cat_data_sql['cat_link_back']) {
691
-            $cat_data_sql['cat_cron_enable'] = 0;
692
-            $cat_data_sql['cat_cron_next'] = 0;
693
-        }
694
-
695
-        if (!$cat_data_sql['parent_id']) {
696
-            $cat_data_sql['display_subcat_list'] = 0;
697
-        }
698
-
699
-        // no cat_id means we're creating a new categorie
700
-        if (!isset($cat_data_sql['cat_id'])) {
701
-            if ($cat_data_sql['cat_cron_enable']) {
702
-                $cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq'] * 86400;
703
-            }
704
-
705
-            $this->cat_data = $this->nestedset_category->insert($cat_data_sql);
706
-
707
-            if ($cat_data_sql['parent_id']) {
708
-                $this->nestedset_category->change_parent($this->cat_data['cat_id'], $cat_data_sql['parent_id']);
709
-            }
710
-
711
-            $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_ADD', time(), [$this->cat_data['cat_name']]);
712
-        } else {
713
-            $row = $this->_get_cat_info($cat_data_sql['cat_id']);
714
-
715
-            if ($row['parent_id'] != $cat_data_sql['parent_id']) {
716
-                $this->nestedset_category->change_parent($cat_data_sql['cat_id'], $cat_data_sql['parent_id']);
717
-            }
718
-
719
-            if ($cat_data_sql['cat_cron_enable'] && ($row['cat_cron_freq'] != $cat_data_sql['cat_cron_freq'] || !$row['cat_cron_enable'])) {
720
-                $cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq'] * 86400;
721
-            }
722
-
723
-            if ($row['cat_name'] != $cat_data_sql['cat_name']) {
724
-                // the cat name has changed, clear the parents list of all categories (for safety)
725
-                $sql = 'UPDATE '.DIR_CAT_TABLE."
650
+		$result = $this->db->sql_query($sql);
651
+		$row = $this->db->sql_fetchrow($result);
652
+		$this->db->sql_freeresult($result);
653
+
654
+		if (!$row) {
655
+			trigger_error('DIR_ERROR_NO_CATS', E_USER_ERROR);
656
+		}
657
+
658
+		return $row;
659
+	}
660
+
661
+	/**
662
+	 * Update category data.
663
+	 *
664
+	 * @return array
665
+	 */
666
+	private function _update_cat_data()
667
+	{
668
+		if (!$this->cat_data['cat_name']) {
669
+			$this->errors[] = $this->user->lang['DIR_CAT_NAME_EMPTY'];
670
+		}
671
+
672
+		if (utf8_strlen($this->cat_data['cat_desc']) > 4000) {
673
+			$this->errors[] = $this->user->lang['DIR_CAT_DESC_TOO_LONG'];
674
+		}
675
+
676
+		if (($this->cat_data['cat_cron_enable'] && $this->cat_data['cat_cron_freq'] <= 0) || $this->cat_data['cat_cron_nb_check'] < 0) {
677
+			$this->errors[] = $this->user->lang['DIR_CAT_DATA_NEGATIVE'];
678
+		}
679
+
680
+		// Unset data that are not database fields
681
+		$cat_data_sql = $this->cat_data;
682
+
683
+		// What are we going to do tonight Brain? The same thing we do everynight,
684
+		// try to take over the world ... or decide whether to continue update
685
+		// and if so, whether it's a new cat/link or an existing one
686
+		if (count($this->errors)) {
687
+			return $this->errors;
688
+		}
689
+
690
+		if (!$cat_data_sql['cat_link_back']) {
691
+			$cat_data_sql['cat_cron_enable'] = 0;
692
+			$cat_data_sql['cat_cron_next'] = 0;
693
+		}
694
+
695
+		if (!$cat_data_sql['parent_id']) {
696
+			$cat_data_sql['display_subcat_list'] = 0;
697
+		}
698
+
699
+		// no cat_id means we're creating a new categorie
700
+		if (!isset($cat_data_sql['cat_id'])) {
701
+			if ($cat_data_sql['cat_cron_enable']) {
702
+				$cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq'] * 86400;
703
+			}
704
+
705
+			$this->cat_data = $this->nestedset_category->insert($cat_data_sql);
706
+
707
+			if ($cat_data_sql['parent_id']) {
708
+				$this->nestedset_category->change_parent($this->cat_data['cat_id'], $cat_data_sql['parent_id']);
709
+			}
710
+
711
+			$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_ADD', time(), [$this->cat_data['cat_name']]);
712
+		} else {
713
+			$row = $this->_get_cat_info($cat_data_sql['cat_id']);
714
+
715
+			if ($row['parent_id'] != $cat_data_sql['parent_id']) {
716
+				$this->nestedset_category->change_parent($cat_data_sql['cat_id'], $cat_data_sql['parent_id']);
717
+			}
718
+
719
+			if ($cat_data_sql['cat_cron_enable'] && ($row['cat_cron_freq'] != $cat_data_sql['cat_cron_freq'] || !$row['cat_cron_enable'])) {
720
+				$cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq'] * 86400;
721
+			}
722
+
723
+			if ($row['cat_name'] != $cat_data_sql['cat_name']) {
724
+				// the cat name has changed, clear the parents list of all categories (for safety)
725
+				$sql = 'UPDATE '.DIR_CAT_TABLE."
726 726
 					SET cat_parents = ''";
727
-                $this->db->sql_query($sql);
728
-            }
727
+				$this->db->sql_query($sql);
728
+			}
729 729
 
730
-            // Setting the cat id to the categorie id is not really received well by some dbs. ;)
731
-            unset($cat_data_sql['cat_id']);
730
+			// Setting the cat id to the categorie id is not really received well by some dbs. ;)
731
+			unset($cat_data_sql['cat_id']);
732 732
 
733
-            $sql = 'UPDATE '.DIR_CAT_TABLE.'
733
+			$sql = 'UPDATE '.DIR_CAT_TABLE.'
734 734
 				SET '.$this->db->sql_build_array('UPDATE', $cat_data_sql).'
735 735
 				WHERE cat_id = '.(int) $this->cat_id;
736
-            $this->db->sql_query($sql);
737
-
738
-            $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_EDIT', time(), [$this->cat_data['cat_name']]);
739
-        }
740
-
741
-        return $this->errors;
742
-    }
743
-
744
-    /**
745
-     * Remove complete category.
746
-     *
747
-     * @param string $action_links   Action for categories links
748
-     * @param string $action_subcats Action for sub-categories
749
-     * @param int    $links_to_id    New category ID for links
750
-     * @param int    $subcats_to_id  New category ID for sub-categories
751
-     *
752
-     * @return array
753
-     */
754
-    private function _delete_cat($action_links = 'delete', $action_subcats = 'delete', $links_to_id = 0, $subcats_to_id = 0)
755
-    {
756
-        $this->cat_data = $this->_get_cat_info($this->cat_id);
757
-
758
-        $log_action_links = $log_action_cats = $links_to_name = $subcats_to_name = '';
759
-
760
-        if ($action_links == 'delete') {
761
-            $log_action_links = 'LINKS';
762
-            $this->errors = array_merge($this->errors, $this->_delete_cat_content());
763
-        } elseif ($action_links == 'move') {
764
-            if (!$links_to_id) {
765
-                $this->errors[] = $this->user->lang['DIR_NO_DESTINATION_CAT'];
766
-            } else {
767
-                $log_action_links = 'MOVE_LINKS';
768
-
769
-                $sql = 'SELECT cat_name
736
+			$this->db->sql_query($sql);
737
+
738
+			$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_EDIT', time(), [$this->cat_data['cat_name']]);
739
+		}
740
+
741
+		return $this->errors;
742
+	}
743
+
744
+	/**
745
+	 * Remove complete category.
746
+	 *
747
+	 * @param string $action_links   Action for categories links
748
+	 * @param string $action_subcats Action for sub-categories
749
+	 * @param int    $links_to_id    New category ID for links
750
+	 * @param int    $subcats_to_id  New category ID for sub-categories
751
+	 *
752
+	 * @return array
753
+	 */
754
+	private function _delete_cat($action_links = 'delete', $action_subcats = 'delete', $links_to_id = 0, $subcats_to_id = 0)
755
+	{
756
+		$this->cat_data = $this->_get_cat_info($this->cat_id);
757
+
758
+		$log_action_links = $log_action_cats = $links_to_name = $subcats_to_name = '';
759
+
760
+		if ($action_links == 'delete') {
761
+			$log_action_links = 'LINKS';
762
+			$this->errors = array_merge($this->errors, $this->_delete_cat_content());
763
+		} elseif ($action_links == 'move') {
764
+			if (!$links_to_id) {
765
+				$this->errors[] = $this->user->lang['DIR_NO_DESTINATION_CAT'];
766
+			} else {
767
+				$log_action_links = 'MOVE_LINKS';
768
+
769
+				$sql = 'SELECT cat_name
770 770
 					FROM '.DIR_CAT_TABLE.'
771 771
 					WHERE cat_id = '.(int) $links_to_id;
772
-                $result = $this->db->sql_query($sql);
773
-                $row = $this->db->sql_fetchrow($result);
774
-                $this->db->sql_freeresult($result);
775
-
776
-                if (!$row) {
777
-                    throw new \OutOfBoundsException('DIR_NO_CAT');
778
-                } else {
779
-                    $links_to_name = $row['cat_name'];
780
-                    $this->_move_cat_content($this->cat_id, $links_to_id);
781
-                }
782
-            }
783
-        }
784
-
785
-        if (count($this->errors)) {
786
-            return $this->errors;
787
-        }
788
-
789
-        if ($action_subcats == 'delete') {
790
-            $log_action_cats = 'CATS';
791
-        } elseif ($action_subcats == 'move') {
792
-            if (!$subcats_to_id) {
793
-                $this->errors[] = $this->user->lang['DIR_NO_DESTINATION_CAT'];
794
-            } else {
795
-                $log_action_cats = 'MOVE_CATS';
796
-
797
-                $subcats_to_name = $row['cat_name'];
798
-                $this->nestedset_category->move_children($this->cat_id, $subcats_to_id);
799
-            }
800
-        }
801
-
802
-        if (count($this->errors)) {
803
-            return $this->errors;
804
-        }
805
-
806
-        $this->nestedset_category->delete($this->cat_id);
807
-
808
-        $log_action = implode('_', [$log_action_links, $log_action_cats]);
809
-
810
-        switch ($log_action) {
811
-            case 'MOVE_LINKS_MOVE_CATS':
812
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS_MOVE_CATS', time(), [$links_to_name, $subcats_to_name, $this->cat_data['cat_name']]);
813
-            break;
814
-
815
-            case 'MOVE_LINKS_CATS':
816
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS_CATS', time(), [$links_to_name, $this->cat_data['cat_name']]);
817
-            break;
818
-
819
-            case 'LINKS_MOVE_CATS':
820
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_LINKS_MOVE_CATS', time(), [$subcats_to_name, $this->cat_data['cat_name']]);
821
-            break;
822
-
823
-            case '_MOVE_CATS':
824
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_CATS', time(), [$subcats_to_name, $this->cat_data['cat_name']]);
825
-            break;
826
-
827
-            case 'MOVE_LINKS_':
828
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS', time(), [$links_to_name, $this->cat_data['cat_name']]);
829
-            break;
830
-
831
-            case 'LINKS_CATS':
832
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_LINKS_CATS', time(), [$this->cat_data['cat_name']]);
833
-            break;
834
-
835
-            case '_CATS':
836
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_CATS', time(), [$this->cat_data['cat_name']]);
837
-            break;
838
-
839
-            case 'LINKS_':
840
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_LINKS', time(), [$this->cat_data['cat_name']]);
841
-            break;
842
-
843
-            default:
844
-                $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_CAT', time(), [$this->cat_data['cat_name']]);
845
-            break;
846
-        }
847
-
848
-        return $this->errors;
849
-    }
850
-
851
-    /**
852
-     * Move category content from one to another forum.
853
-     *
854
-     * @param int $from_id
855
-     * @param int $to_id
856
-     *
857
-     * @return null
858
-     */
859
-    private function _move_cat_content($from_id, $to_id)
860
-    {
861
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
772
+				$result = $this->db->sql_query($sql);
773
+				$row = $this->db->sql_fetchrow($result);
774
+				$this->db->sql_freeresult($result);
775
+
776
+				if (!$row) {
777
+					throw new \OutOfBoundsException('DIR_NO_CAT');
778
+				} else {
779
+					$links_to_name = $row['cat_name'];
780
+					$this->_move_cat_content($this->cat_id, $links_to_id);
781
+				}
782
+			}
783
+		}
784
+
785
+		if (count($this->errors)) {
786
+			return $this->errors;
787
+		}
788
+
789
+		if ($action_subcats == 'delete') {
790
+			$log_action_cats = 'CATS';
791
+		} elseif ($action_subcats == 'move') {
792
+			if (!$subcats_to_id) {
793
+				$this->errors[] = $this->user->lang['DIR_NO_DESTINATION_CAT'];
794
+			} else {
795
+				$log_action_cats = 'MOVE_CATS';
796
+
797
+				$subcats_to_name = $row['cat_name'];
798
+				$this->nestedset_category->move_children($this->cat_id, $subcats_to_id);
799
+			}
800
+		}
801
+
802
+		if (count($this->errors)) {
803
+			return $this->errors;
804
+		}
805
+
806
+		$this->nestedset_category->delete($this->cat_id);
807
+
808
+		$log_action = implode('_', [$log_action_links, $log_action_cats]);
809
+
810
+		switch ($log_action) {
811
+			case 'MOVE_LINKS_MOVE_CATS':
812
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS_MOVE_CATS', time(), [$links_to_name, $subcats_to_name, $this->cat_data['cat_name']]);
813
+			break;
814
+
815
+			case 'MOVE_LINKS_CATS':
816
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS_CATS', time(), [$links_to_name, $this->cat_data['cat_name']]);
817
+			break;
818
+
819
+			case 'LINKS_MOVE_CATS':
820
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_LINKS_MOVE_CATS', time(), [$subcats_to_name, $this->cat_data['cat_name']]);
821
+			break;
822
+
823
+			case '_MOVE_CATS':
824
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_CATS', time(), [$subcats_to_name, $this->cat_data['cat_name']]);
825
+			break;
826
+
827
+			case 'MOVE_LINKS_':
828
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS', time(), [$links_to_name, $this->cat_data['cat_name']]);
829
+			break;
830
+
831
+			case 'LINKS_CATS':
832
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_LINKS_CATS', time(), [$this->cat_data['cat_name']]);
833
+			break;
834
+
835
+			case '_CATS':
836
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_CATS', time(), [$this->cat_data['cat_name']]);
837
+			break;
838
+
839
+			case 'LINKS_':
840
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_LINKS', time(), [$this->cat_data['cat_name']]);
841
+			break;
842
+
843
+			default:
844
+				$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_CAT', time(), [$this->cat_data['cat_name']]);
845
+			break;
846
+		}
847
+
848
+		return $this->errors;
849
+	}
850
+
851
+	/**
852
+	 * Move category content from one to another forum.
853
+	 *
854
+	 * @param int $from_id
855
+	 * @param int $to_id
856
+	 *
857
+	 * @return null
858
+	 */
859
+	private function _move_cat_content($from_id, $to_id)
860
+	{
861
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
862 862
 			SET link_cat = '.(int) $to_id.'
863 863
 			WHERE link_cat = '.(int) $from_id;
864
-        $this->db->sql_query($sql);
864
+		$this->db->sql_query($sql);
865 865
 
866
-        $sql = 'DELETE FROM '.DIR_WATCH_TABLE.'
866
+		$sql = 'DELETE FROM '.DIR_WATCH_TABLE.'
867 867
 			WHERE cat_id = '.(int) $from_id;
868
-        $this->db->sql_query($sql);
869
-
870
-        $this->_sync_dir_cat($to_id);
871
-    }
872
-
873
-    /**
874
-     * Delete category content.
875
-     *
876
-     * @return array
877
-     */
878
-    private function _delete_cat_content()
879
-    {
880
-        $this->db->sql_transaction('begin');
881
-
882
-        // Before we remove anything we make sure we are able to adjust the post counts later. ;)
883
-        $sql = 'SELECT link_id, link_banner
868
+		$this->db->sql_query($sql);
869
+
870
+		$this->_sync_dir_cat($to_id);
871
+	}
872
+
873
+	/**
874
+	 * Delete category content.
875
+	 *
876
+	 * @return array
877
+	 */
878
+	private function _delete_cat_content()
879
+	{
880
+		$this->db->sql_transaction('begin');
881
+
882
+		// Before we remove anything we make sure we are able to adjust the post counts later. ;)
883
+		$sql = 'SELECT link_id, link_banner
884 884
 			FROM '.DIR_LINK_TABLE.'
885 885
 			WHERE link_cat = '.(int) $this->cat_id;
886
-        $result = $this->db->sql_query($sql);
887
-
888
-        $link_ids = [];
889
-        while ($row = $this->db->sql_fetchrow($result)) {
890
-            $link_ids[] = $row['link_id'];
891
-
892
-            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
893
-                $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
894
-
895
-                if (file_exists($banner_img)) {
896
-                    @unlink($banner_img);
897
-                }
898
-            }
899
-        }
900
-        $this->db->sql_freeresult($result);
901
-
902
-        if (count($link_ids)) {
903
-            // Delete links datas
904
-            $link_datas_ary = [
905
-                DIR_COMMENT_TABLE     => 'comment_link_id',
906
-                DIR_VOTE_TABLE        => 'vote_link_id',
907
-            ];
908
-
909
-            foreach ($link_datas_ary as $table => $field) {
910
-                $this->db->sql_query("DELETE FROM $table WHERE ".$this->db->sql_in_set($field, $link_ids));
911
-            }
912
-        }
913
-
914
-        // Delete cats datas
915
-        $cat_datas_ary = [
916
-            DIR_LINK_TABLE     => 'link_cat',
917
-            DIR_WATCH_TABLE    => 'cat_id',
918
-        ];
919
-
920
-        foreach ($cat_datas_ary as $table => $field) {
921
-            $this->db->sql_query("DELETE FROM $table WHERE $field = ".(int) $this->cat_id);
922
-        }
923
-
924
-        $this->db->sql_transaction('commit');
925
-
926
-        return [];
927
-    }
928
-
929
-    /**
930
-     * Update links counter.
931
-     *
932
-     * @param int $cat_id The category ID
933
-     *
934
-     * @return null
935
-     */
936
-    private function _sync_dir_cat($cat_id)
937
-    {
938
-        $sql = 'SELECT COUNT(link_id) AS num_links
886
+		$result = $this->db->sql_query($sql);
887
+
888
+		$link_ids = [];
889
+		while ($row = $this->db->sql_fetchrow($result)) {
890
+			$link_ids[] = $row['link_id'];
891
+
892
+			if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
893
+				$banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
894
+
895
+				if (file_exists($banner_img)) {
896
+					@unlink($banner_img);
897
+				}
898
+			}
899
+		}
900
+		$this->db->sql_freeresult($result);
901
+
902
+		if (count($link_ids)) {
903
+			// Delete links datas
904
+			$link_datas_ary = [
905
+				DIR_COMMENT_TABLE     => 'comment_link_id',
906
+				DIR_VOTE_TABLE        => 'vote_link_id',
907
+			];
908
+
909
+			foreach ($link_datas_ary as $table => $field) {
910
+				$this->db->sql_query("DELETE FROM $table WHERE ".$this->db->sql_in_set($field, $link_ids));
911
+			}
912
+		}
913
+
914
+		// Delete cats datas
915
+		$cat_datas_ary = [
916
+			DIR_LINK_TABLE     => 'link_cat',
917
+			DIR_WATCH_TABLE    => 'cat_id',
918
+		];
919
+
920
+		foreach ($cat_datas_ary as $table => $field) {
921
+			$this->db->sql_query("DELETE FROM $table WHERE $field = ".(int) $this->cat_id);
922
+		}
923
+
924
+		$this->db->sql_transaction('commit');
925
+
926
+		return [];
927
+	}
928
+
929
+	/**
930
+	 * Update links counter.
931
+	 *
932
+	 * @param int $cat_id The category ID
933
+	 *
934
+	 * @return null
935
+	 */
936
+	private function _sync_dir_cat($cat_id)
937
+	{
938
+		$sql = 'SELECT COUNT(link_id) AS num_links
939 939
 			FROM '.DIR_LINK_TABLE.'
940 940
 			WHERE link_cat = '.(int) $cat_id.'
941 941
 				AND link_active = 1';
942
-        $result = $this->db->sql_query($sql);
943
-        $total_links = (int) $this->db->sql_fetchfield('num_links');
944
-        $this->db->sql_freeresult($result);
942
+		$result = $this->db->sql_query($sql);
943
+		$total_links = (int) $this->db->sql_fetchfield('num_links');
944
+		$this->db->sql_freeresult($result);
945 945
 
946
-        $sql = 'UPDATE '.DIR_CAT_TABLE.'
946
+		$sql = 'UPDATE '.DIR_CAT_TABLE.'
947 947
 			SET cat_links = '.$total_links.'
948 948
 			WHERE cat_id = '.(int) $cat_id;
949
-        $this->db->sql_query($sql);
950
-    }
951
-
952
-    /**
953
-     * Update link data (note, vote, comment).
954
-     *
955
-     * @param int $start
956
-     * @param int $stop
957
-     *
958
-     * @return null
959
-     */
960
-    private function _sync_dir_links($start, $stop)
961
-    {
962
-        $sql_ary = [
963
-            'link_comment'     => 0,
964
-            'link_note'        => 0,
965
-            'link_vote'        => 0,
966
-        ];
967
-
968
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
949
+		$this->db->sql_query($sql);
950
+	}
951
+
952
+	/**
953
+	 * Update link data (note, vote, comment).
954
+	 *
955
+	 * @param int $start
956
+	 * @param int $stop
957
+	 *
958
+	 * @return null
959
+	 */
960
+	private function _sync_dir_links($start, $stop)
961
+	{
962
+		$sql_ary = [
963
+			'link_comment'     => 0,
964
+			'link_note'        => 0,
965
+			'link_vote'        => 0,
966
+		];
967
+
968
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
969 969
 			SET '.$this->db->sql_build_array('UPDATE', $sql_ary).'
970 970
 			WHERE link_id BETWEEN '.(int) $start.' AND '.(int) $stop;
971
-        $this->db->sql_query($sql);
971
+		$this->db->sql_query($sql);
972 972
 
973
-        $sql = 'SELECT vote_link_id, COUNT(vote_note) AS nb_vote, SUM(vote_note) AS total FROM '.DIR_VOTE_TABLE.'
973
+		$sql = 'SELECT vote_link_id, COUNT(vote_note) AS nb_vote, SUM(vote_note) AS total FROM '.DIR_VOTE_TABLE.'
974 974
 			WHERE vote_link_id BETWEEN '.(int) $start.' AND '.(int) $stop.'
975 975
 			GROUP BY vote_link_id';
976
-        $result = $this->db->sql_query($sql);
977
-        while ($tmp = $this->db->sql_fetchrow($result)) {
978
-            $sql = 'UPDATE '.DIR_LINK_TABLE.'
976
+		$result = $this->db->sql_query($sql);
977
+		while ($tmp = $this->db->sql_fetchrow($result)) {
978
+			$sql = 'UPDATE '.DIR_LINK_TABLE.'
979 979
 				SET link_note = '.(int) $tmp['total'].', link_vote = '.(int) $tmp['nb_vote'].'
980 980
 				WHERE link_id = '.(int) $tmp['vote_link_id'];
981
-            $this->db->sql_query($sql);
982
-        }
983
-        $this->db->sql_freeresult($result);
981
+			$this->db->sql_query($sql);
982
+		}
983
+		$this->db->sql_freeresult($result);
984 984
 
985
-        $sql = 'SELECT 	comment_link_id, COUNT(comment_id) AS nb_comment
985
+		$sql = 'SELECT 	comment_link_id, COUNT(comment_id) AS nb_comment
986 986
 			FROM '.DIR_COMMENT_TABLE.'
987 987
 			WHERE comment_link_id BETWEEN '.(int) $start.' AND '.(int) $stop.'
988 988
 			GROUP BY comment_link_id';
989
-        $result = $this->db->sql_query($sql);
990
-        while ($tmp = $this->db->sql_fetchrow($result)) {
991
-            $sql = 'UPDATE '.DIR_LINK_TABLE.'
989
+		$result = $this->db->sql_query($sql);
990
+		while ($tmp = $this->db->sql_fetchrow($result)) {
991
+			$sql = 'UPDATE '.DIR_LINK_TABLE.'
992 992
 				SET link_comment = '.(int) $tmp['nb_comment'].'
993 993
 				WHERE link_id = '.(int) $tmp['comment_link_id'];
994
-            $this->db->sql_query($sql);
995
-        }
996
-        $this->db->sql_freeresult($result);
997
-    }
998
-
999
-    /**
1000
-     * Display icons drop-down list.
1001
-     *
1002
-     * @param string $icons_path
1003
-     * @param string $img_selected
1004
-     *
1005
-     * @return string
1006
-     */
1007
-    private function _get_dir_icon_list($icons_path, $img_selected)
1008
-    {
1009
-        $imglist = filelist($icons_path, '');
1010
-        $filename_list = '<option value="">----------</option>';
1011
-
1012
-        foreach ($imglist as $path => $img_ary) {
1013
-            sort($img_ary);
1014
-
1015
-            foreach ($img_ary as $img) {
1016
-                $img = $path.$img;
1017
-                $selected = '';
1018
-
1019
-                if (strlen($img) > 255) {
1020
-                    continue;
1021
-                }
1022
-
1023
-                if ($img == $img_selected) {
1024
-                    $selected = ' selected="selected"';
1025
-                }
1026
-
1027
-                $filename_list .= '<option value="'.htmlspecialchars($img).'"'.$selected.'>'.$img.'</option>';
1028
-            }
1029
-        }
1030
-
1031
-        return $filename_list;
1032
-    }
994
+			$this->db->sql_query($sql);
995
+		}
996
+		$this->db->sql_freeresult($result);
997
+	}
998
+
999
+	/**
1000
+	 * Display icons drop-down list.
1001
+	 *
1002
+	 * @param string $icons_path
1003
+	 * @param string $img_selected
1004
+	 *
1005
+	 * @return string
1006
+	 */
1007
+	private function _get_dir_icon_list($icons_path, $img_selected)
1008
+	{
1009
+		$imglist = filelist($icons_path, '');
1010
+		$filename_list = '<option value="">----------</option>';
1011
+
1012
+		foreach ($imglist as $path => $img_ary) {
1013
+			sort($img_ary);
1014
+
1015
+			foreach ($img_ary as $img) {
1016
+				$img = $path.$img;
1017
+				$selected = '';
1018
+
1019
+				if (strlen($img) > 255) {
1020
+					continue;
1021
+				}
1022
+
1023
+				if ($img == $img_selected) {
1024
+					$selected = ' selected="selected"';
1025
+				}
1026
+
1027
+				$filename_list .= '<option value="'.htmlspecialchars($img).'"'.$selected.'>'.$img.'</option>';
1028
+			}
1029
+		}
1030
+
1031
+		return $filename_list;
1032
+	}
1033 1033
 }
Please login to merge, or discard this patch.
Braces   +165 added lines, -76 removed lines patch added patch discarded remove patch
@@ -110,7 +110,8 @@  discard block
 block discarded – undo
110 110
         $parents_list = $this->categorie->make_cat_select($this->parent_id);
111 111
 
112 112
         // Fill categorie data with default values
113
-        if (!$this->update) {
113
+        if (!$this->update)
114
+        {
114 115
             $this->cat_data = [
115 116
                 'parent_id'                => $this->parent_id,
116 117
                 'cat_name'                 => $this->request->variable('cat_name', '', true),
@@ -142,7 +143,8 @@  discard block
 block discarded – undo
142 143
      */
143 144
     public function action_delete()
144 145
     {
145
-        if (!$this->cat_id) {
146
+        if (!$this->cat_id)
147
+        {
146 148
             trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
147 149
         }
148 150
 
@@ -151,7 +153,8 @@  discard block
 block discarded – undo
151 153
         $subcats_id = [];
152 154
         $subcats = $this->nestedset_category->get_subtree_data($this->cat_id);
153 155
 
154
-        foreach ($subcats as $row) {
156
+        foreach ($subcats as $row)
157
+        {
155 158
             $subcats_id[] = $row['cat_id'];
156 159
         }
157 160
 
@@ -162,7 +165,8 @@  discard block
 block discarded – undo
162 165
 			WHERE cat_id <> '.(int) $this->cat_id;
163 166
         $result = $this->db->sql_query_limit($sql, 1);
164 167
 
165
-        if ($this->db->sql_fetchrow($result)) {
168
+        if ($this->db->sql_fetchrow($result))
169
+        {
166 170
             $this->template->assign_vars([
167 171
                 'S_MOVE_DIR_CAT_OPTIONS'    => $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id), ]
168 172
             );
@@ -193,16 +197,20 @@  discard block
 block discarded – undo
193 197
     {
194 198
         $row = $this->_get_cat_info($this->cat_id);
195 199
 
196
-        if (!$this->update) {
200
+        if (!$this->update)
201
+        {
197 202
             $this->cat_data = $row;
198
-        } else {
203
+        }
204
+        else
205
+        {
199 206
             $this->cat_data['left_id'] = $row['left_id'];
200 207
             $this->cat_data['right_id'] = $row['right_id'];
201 208
         }
202 209
 
203 210
         // Make sure no direct child categories are able to be selected as parents.
204 211
         $exclude_cats = [];
205
-        foreach ($this->nestedset_category->get_subtree_data($this->cat_id) as $row2) {
212
+        foreach ($this->nestedset_category->get_subtree_data($this->cat_id) as $row2)
213
+        {
206 214
             $exclude_cats[] = $row2['cat_id'];
207 215
         }
208 216
         $parents_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $exclude_cats);
@@ -217,7 +225,8 @@  discard block
 block discarded – undo
217 225
      */
218 226
     public function action_move()
219 227
     {
220
-        if (!$this->cat_id) {
228
+        if (!$this->cat_id)
229
+        {
221 230
             trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
222 231
         }
223 232
 
@@ -228,22 +237,28 @@  discard block
 block discarded – undo
228 237
         $row = $this->db->sql_fetchrow($result);
229 238
         $this->db->sql_freeresult($result);
230 239
 
231
-        if (!$row) {
240
+        if (!$row)
241
+        {
232 242
             trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
233 243
         }
234 244
 
235
-        try {
245
+        try
246
+        {
236 247
             $move_cat_name = $this->nestedset_category->{$this->action}($this->cat_id);
237
-        } catch (\Exception $e) {
248
+        }
249
+        catch (\Exception $e)
250
+        {
238 251
             trigger_error($e->getMessage(), E_USER_WARNING);
239 252
         }
240 253
 
241
-        if ($move_cat_name !== false) {
254
+        if ($move_cat_name !== false)
255
+        {
242 256
             $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_'.strtoupper($this->action), time(), [$row['cat_name'], $move_cat_name]);
243 257
             $this->cache->destroy('sql', DIR_CAT_TABLE);
244 258
         }
245 259
 
246
-        if ($this->request->is_ajax()) {
260
+        if ($this->request->is_ajax())
261
+        {
247 262
             $json_response = new \phpbb\json_response();
248 263
             $json_response->send(['success' => ($move_cat_name !== false)]);
249 264
         }
@@ -280,7 +295,8 @@  discard block
 block discarded – undo
280 295
      */
281 296
     public function action_sync()
282 297
     {
283
-        if (!$this->cat_id) {
298
+        if (!$this->cat_id)
299
+        {
284 300
             trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
285 301
         }
286 302
 
@@ -293,7 +309,8 @@  discard block
 block discarded – undo
293 309
         $row = $this->db->sql_fetchrow($result);
294 310
         $this->db->sql_freeresult($result);
295 311
 
296
-        if (!$row) {
312
+        if (!$row)
313
+        {
297 314
             trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
298 315
         }
299 316
 
@@ -317,7 +334,8 @@  discard block
 block discarded – undo
317 334
         // Sync all links in batch mode...
318 335
         $this->_sync_dir_links($start, $end);
319 336
 
320
-        if ($end < $row2['max_link_id']) {
337
+        if ($end < $row2['max_link_id'])
338
+        {
321 339
             // We really need to find a way of showing statistics... no progress here
322 340
             $sql = 'SELECT COUNT(link_id) as num_links
323 341
 				FROM '.DIR_LINK_TABLE.'
@@ -369,7 +387,8 @@  discard block
 block discarded – undo
369 387
         $row = $this->db->sql_fetchrow($result);
370 388
         $this->db->sql_freeresult($result);
371 389
 
372
-        if (!$row) {
390
+        if (!$row)
391
+        {
373 392
             trigger_error($this->user->lang['DIR_NO_CAT'].adm_back_link($this->u_action.'&amp;parent_id='.$this->parent_id), E_USER_WARNING);
374 393
         }
375 394
 
@@ -389,17 +408,24 @@  discard block
 block discarded – undo
389 408
     public function display_cats()
390 409
     {
391 410
         // Default management page
392
-        if (!$this->parent_id) {
411
+        if (!$this->parent_id)
412
+        {
393 413
             $navigation = $this->user->lang['DIR_INDEX'];
394
-        } else {
414
+        }
415
+        else
416
+        {
395 417
             $navigation = '<a href="'.$this->u_action.'">'.$this->user->lang['DIR_INDEX'].'</a>';
396 418
 
397 419
             $cats_nav = $this->nestedset_category->get_path_data($this->parent_id);
398 420
 
399
-            foreach ($cats_nav as $row) {
400
-                if ($row['cat_id'] == $this->parent_id) {
421
+            foreach ($cats_nav as $row)
422
+            {
423
+                if ($row['cat_id'] == $this->parent_id)
424
+                {
401 425
                     $navigation .= ' -&gt; '.$row['cat_name'];
402
-                } else {
426
+                }
427
+                else
428
+                {
403 429
                     $navigation .= ' -&gt; <a href="'.$this->u_action.'&amp;parent_id='.$row['cat_id'].'">'.$row['cat_name'].'</a>';
404 430
                 }
405 431
             }
@@ -408,7 +434,8 @@  discard block
 block discarded – undo
408 434
         // Jumpbox
409 435
         $cat_box = $this->categorie->make_cat_select($this->parent_id);
410 436
 
411
-        if ($this->action == 'sync' || $this->action == 'sync_cat') {
437
+        if ($this->action == 'sync' || $this->action == 'sync_cat')
438
+        {
412 439
             $this->template->assign_var('S_RESYNCED', true);
413 440
         }
414 441
 
@@ -418,8 +445,10 @@  discard block
 block discarded – undo
418 445
 			ORDER BY left_id';
419 446
         $result = $this->db->sql_query($sql);
420 447
 
421
-        if ($row = $this->db->sql_fetchrow($result)) {
422
-            do {
448
+        if ($row = $this->db->sql_fetchrow($result))
449
+        {
450
+            do
451
+            {
423 452
                 $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="'.$this->user->lang['DIR_SUBCAT'].'" />' : '<img src="images/icon_folder.gif" alt="'.$this->user->lang['FOLDER'].'" />';
424 453
 
425 454
                 $url = $this->u_action."&amp;parent_id=$this->parent_id&amp;c={$row['cat_id']}";
@@ -439,7 +468,9 @@  discard block
 block discarded – undo
439 468
                     'U_SYNC'               => $url.'&amp;action=sync', ]
440 469
                 );
441 470
             } while ($row = $this->db->sql_fetchrow($result));
442
-        } elseif ($this->parent_id) {
471
+        }
472
+        elseif ($this->parent_id)
473
+        {
443 474
             $row = $this->_get_cat_info($this->parent_id);
444 475
 
445 476
             $url = $this->u_action.'&amp;parent_id='.$this->parent_id.'&amp;c='.$row['cat_id'];
@@ -485,25 +516,31 @@  discard block
 block discarded – undo
485 516
      */
486 517
     public function update()
487 518
     {
488
-        if (!check_form_key($this->form_key)) {
519
+        if (!check_form_key($this->form_key))
520
+        {
489 521
             $this->update = false;
490 522
             $this->errors[] = $this->user->lang['FORM_INVALID'];
491 523
         }
492 524
 
493
-        switch ($this->action) {
525
+        switch ($this->action)
526
+        {
494 527
             case 'delete':
495 528
                 $action_subcats = $this->request->variable('action_subcats', '');
496 529
                 $subcats_to_id = $this->request->variable('subcats_to_id', 0);
497 530
                 $action_links = $this->request->variable('action_links', '');
498 531
                 $links_to_id = $this->request->variable('links_to_id', 0);
499 532
 
500
-                try {
533
+                try
534
+                {
501 535
                     $this->errors = $this->_delete_cat($action_links, $action_subcats, $links_to_id, $subcats_to_id);
502
-                } catch (\Exception $e) {
536
+                }
537
+                catch (\Exception $e)
538
+                {
503 539
                     trigger_error($e->getMessage(), E_USER_WARNING);
504 540
                 }
505 541
 
506
-                if (count($this->errors)) {
542
+                if (count($this->errors))
543
+                {
507 544
                     break;
508 545
                 }
509 546
 
@@ -542,17 +579,22 @@  discard block
 block discarded – undo
542 579
                 ];
543 580
 
544 581
                 // Get data for cat description if specified
545
-                if ($this->cat_data['cat_desc']) {
582
+                if ($this->cat_data['cat_desc'])
583
+                {
546 584
                     generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_parse_bbcode', false), $this->request->variable('desc_parse_urls', false), $this->request->variable('desc_parse_smilies', false));
547 585
                 }
548 586
 
549
-                try {
587
+                try
588
+                {
550 589
                     $this->errors = $this->_update_cat_data();
551
-                } catch (\Exception $e) {
590
+                }
591
+                catch (\Exception $e)
592
+                {
552 593
                     trigger_error($e->getMessage(), E_USER_WARNING);
553 594
                 }
554 595
 
555
-                if (!count($this->errors)) {
596
+                if (!count($this->errors))
597
+                {
556 598
                     $this->cache->destroy('sql', DIR_CAT_TABLE);
557 599
 
558 600
                     $message = ($this->action == 'add') ? $this->user->lang['DIR_CAT_CREATED'] : $this->user->lang['DIR_CAT_UPDATED'];
@@ -581,8 +623,10 @@  discard block
 block discarded – undo
581 623
         ];
582 624
 
583 625
         // Parse desciption if specified
584
-        if ($this->cat_data['cat_desc']) {
585
-            if (!isset($this->cat_data['cat_desc_uid'])) {
626
+        if ($this->cat_data['cat_desc'])
627
+        {
628
+            if (!isset($this->cat_data['cat_desc_uid']))
629
+            {
586 630
                 // Before we are able to display the preview and plane text, we need to parse our $request->variable()'d value...
587 631
                 $this->cat_data['cat_desc_uid'] = '';
588 632
                 $this->cat_data['cat_desc_bitfield'] = '';
@@ -651,7 +695,8 @@  discard block
 block discarded – undo
651 695
         $row = $this->db->sql_fetchrow($result);
652 696
         $this->db->sql_freeresult($result);
653 697
 
654
-        if (!$row) {
698
+        if (!$row)
699
+        {
655 700
             trigger_error('DIR_ERROR_NO_CATS', E_USER_ERROR);
656 701
         }
657 702
 
@@ -665,15 +710,18 @@  discard block
 block discarded – undo
665 710
      */
666 711
     private function _update_cat_data()
667 712
     {
668
-        if (!$this->cat_data['cat_name']) {
713
+        if (!$this->cat_data['cat_name'])
714
+        {
669 715
             $this->errors[] = $this->user->lang['DIR_CAT_NAME_EMPTY'];
670 716
         }
671 717
 
672
-        if (utf8_strlen($this->cat_data['cat_desc']) > 4000) {
718
+        if (utf8_strlen($this->cat_data['cat_desc']) > 4000)
719
+        {
673 720
             $this->errors[] = $this->user->lang['DIR_CAT_DESC_TOO_LONG'];
674 721
         }
675 722
 
676
-        if (($this->cat_data['cat_cron_enable'] && $this->cat_data['cat_cron_freq'] <= 0) || $this->cat_data['cat_cron_nb_check'] < 0) {
723
+        if (($this->cat_data['cat_cron_enable'] && $this->cat_data['cat_cron_freq'] <= 0) || $this->cat_data['cat_cron_nb_check'] < 0)
724
+        {
677 725
             $this->errors[] = $this->user->lang['DIR_CAT_DATA_NEGATIVE'];
678 726
         }
679 727
 
@@ -683,44 +731,55 @@  discard block
 block discarded – undo
683 731
         // What are we going to do tonight Brain? The same thing we do everynight,
684 732
         // try to take over the world ... or decide whether to continue update
685 733
         // and if so, whether it's a new cat/link or an existing one
686
-        if (count($this->errors)) {
734
+        if (count($this->errors))
735
+        {
687 736
             return $this->errors;
688 737
         }
689 738
 
690
-        if (!$cat_data_sql['cat_link_back']) {
739
+        if (!$cat_data_sql['cat_link_back'])
740
+        {
691 741
             $cat_data_sql['cat_cron_enable'] = 0;
692 742
             $cat_data_sql['cat_cron_next'] = 0;
693 743
         }
694 744
 
695
-        if (!$cat_data_sql['parent_id']) {
745
+        if (!$cat_data_sql['parent_id'])
746
+        {
696 747
             $cat_data_sql['display_subcat_list'] = 0;
697 748
         }
698 749
 
699 750
         // no cat_id means we're creating a new categorie
700
-        if (!isset($cat_data_sql['cat_id'])) {
701
-            if ($cat_data_sql['cat_cron_enable']) {
751
+        if (!isset($cat_data_sql['cat_id']))
752
+        {
753
+            if ($cat_data_sql['cat_cron_enable'])
754
+            {
702 755
                 $cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq'] * 86400;
703 756
             }
704 757
 
705 758
             $this->cat_data = $this->nestedset_category->insert($cat_data_sql);
706 759
 
707
-            if ($cat_data_sql['parent_id']) {
760
+            if ($cat_data_sql['parent_id'])
761
+            {
708 762
                 $this->nestedset_category->change_parent($this->cat_data['cat_id'], $cat_data_sql['parent_id']);
709 763
             }
710 764
 
711 765
             $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_ADD', time(), [$this->cat_data['cat_name']]);
712
-        } else {
766
+        }
767
+        else
768
+        {
713 769
             $row = $this->_get_cat_info($cat_data_sql['cat_id']);
714 770
 
715
-            if ($row['parent_id'] != $cat_data_sql['parent_id']) {
771
+            if ($row['parent_id'] != $cat_data_sql['parent_id'])
772
+            {
716 773
                 $this->nestedset_category->change_parent($cat_data_sql['cat_id'], $cat_data_sql['parent_id']);
717 774
             }
718 775
 
719
-            if ($cat_data_sql['cat_cron_enable'] && ($row['cat_cron_freq'] != $cat_data_sql['cat_cron_freq'] || !$row['cat_cron_enable'])) {
776
+            if ($cat_data_sql['cat_cron_enable'] && ($row['cat_cron_freq'] != $cat_data_sql['cat_cron_freq'] || !$row['cat_cron_enable']))
777
+            {
720 778
                 $cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq'] * 86400;
721 779
             }
722 780
 
723
-            if ($row['cat_name'] != $cat_data_sql['cat_name']) {
781
+            if ($row['cat_name'] != $cat_data_sql['cat_name'])
782
+            {
724 783
                 // the cat name has changed, clear the parents list of all categories (for safety)
725 784
                 $sql = 'UPDATE '.DIR_CAT_TABLE."
726 785
 					SET cat_parents = ''";
@@ -757,13 +816,19 @@  discard block
 block discarded – undo
757 816
 
758 817
         $log_action_links = $log_action_cats = $links_to_name = $subcats_to_name = '';
759 818
 
760
-        if ($action_links == 'delete') {
819
+        if ($action_links == 'delete')
820
+        {
761 821
             $log_action_links = 'LINKS';
762 822
             $this->errors = array_merge($this->errors, $this->_delete_cat_content());
763
-        } elseif ($action_links == 'move') {
764
-            if (!$links_to_id) {
823
+        }
824
+        elseif ($action_links == 'move')
825
+        {
826
+            if (!$links_to_id)
827
+            {
765 828
                 $this->errors[] = $this->user->lang['DIR_NO_DESTINATION_CAT'];
766
-            } else {
829
+            }
830
+            else
831
+            {
767 832
                 $log_action_links = 'MOVE_LINKS';
768 833
 
769 834
                 $sql = 'SELECT cat_name
@@ -773,25 +838,35 @@  discard block
 block discarded – undo
773 838
                 $row = $this->db->sql_fetchrow($result);
774 839
                 $this->db->sql_freeresult($result);
775 840
 
776
-                if (!$row) {
841
+                if (!$row)
842
+                {
777 843
                     throw new \OutOfBoundsException('DIR_NO_CAT');
778
-                } else {
844
+                }
845
+                else
846
+                {
779 847
                     $links_to_name = $row['cat_name'];
780 848
                     $this->_move_cat_content($this->cat_id, $links_to_id);
781 849
                 }
782 850
             }
783 851
         }
784 852
 
785
-        if (count($this->errors)) {
853
+        if (count($this->errors))
854
+        {
786 855
             return $this->errors;
787 856
         }
788 857
 
789
-        if ($action_subcats == 'delete') {
858
+        if ($action_subcats == 'delete')
859
+        {
790 860
             $log_action_cats = 'CATS';
791
-        } elseif ($action_subcats == 'move') {
792
-            if (!$subcats_to_id) {
861
+        }
862
+        elseif ($action_subcats == 'move')
863
+        {
864
+            if (!$subcats_to_id)
865
+            {
793 866
                 $this->errors[] = $this->user->lang['DIR_NO_DESTINATION_CAT'];
794
-            } else {
867
+            }
868
+            else
869
+            {
795 870
                 $log_action_cats = 'MOVE_CATS';
796 871
 
797 872
                 $subcats_to_name = $row['cat_name'];
@@ -799,7 +874,8 @@  discard block
 block discarded – undo
799 874
             }
800 875
         }
801 876
 
802
-        if (count($this->errors)) {
877
+        if (count($this->errors))
878
+        {
803 879
             return $this->errors;
804 880
         }
805 881
 
@@ -807,7 +883,8 @@  discard block
 block discarded – undo
807 883
 
808 884
         $log_action = implode('_', [$log_action_links, $log_action_cats]);
809 885
 
810
-        switch ($log_action) {
886
+        switch ($log_action)
887
+        {
811 888
             case 'MOVE_LINKS_MOVE_CATS':
812 889
                 $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_DEL_MOVE_LINKS_MOVE_CATS', time(), [$links_to_name, $subcats_to_name, $this->cat_data['cat_name']]);
813 890
             break;
@@ -886,27 +963,32 @@  discard block
 block discarded – undo
886 963
         $result = $this->db->sql_query($sql);
887 964
 
888 965
         $link_ids = [];
889
-        while ($row = $this->db->sql_fetchrow($result)) {
966
+        while ($row = $this->db->sql_fetchrow($result))
967
+        {
890 968
             $link_ids[] = $row['link_id'];
891 969
 
892
-            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
970
+            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner']))
971
+            {
893 972
                 $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
894 973
 
895
-                if (file_exists($banner_img)) {
974
+                if (file_exists($banner_img))
975
+                {
896 976
                     @unlink($banner_img);
897 977
                 }
898 978
             }
899 979
         }
900 980
         $this->db->sql_freeresult($result);
901 981
 
902
-        if (count($link_ids)) {
982
+        if (count($link_ids))
983
+        {
903 984
             // Delete links datas
904 985
             $link_datas_ary = [
905 986
                 DIR_COMMENT_TABLE     => 'comment_link_id',
906 987
                 DIR_VOTE_TABLE        => 'vote_link_id',
907 988
             ];
908 989
 
909
-            foreach ($link_datas_ary as $table => $field) {
990
+            foreach ($link_datas_ary as $table => $field)
991
+            {
910 992
                 $this->db->sql_query("DELETE FROM $table WHERE ".$this->db->sql_in_set($field, $link_ids));
911 993
             }
912 994
         }
@@ -917,7 +999,8 @@  discard block
 block discarded – undo
917 999
             DIR_WATCH_TABLE    => 'cat_id',
918 1000
         ];
919 1001
 
920
-        foreach ($cat_datas_ary as $table => $field) {
1002
+        foreach ($cat_datas_ary as $table => $field)
1003
+        {
921 1004
             $this->db->sql_query("DELETE FROM $table WHERE $field = ".(int) $this->cat_id);
922 1005
         }
923 1006
 
@@ -974,7 +1057,8 @@  discard block
 block discarded – undo
974 1057
 			WHERE vote_link_id BETWEEN '.(int) $start.' AND '.(int) $stop.'
975 1058
 			GROUP BY vote_link_id';
976 1059
         $result = $this->db->sql_query($sql);
977
-        while ($tmp = $this->db->sql_fetchrow($result)) {
1060
+        while ($tmp = $this->db->sql_fetchrow($result))
1061
+        {
978 1062
             $sql = 'UPDATE '.DIR_LINK_TABLE.'
979 1063
 				SET link_note = '.(int) $tmp['total'].', link_vote = '.(int) $tmp['nb_vote'].'
980 1064
 				WHERE link_id = '.(int) $tmp['vote_link_id'];
@@ -987,7 +1071,8 @@  discard block
 block discarded – undo
987 1071
 			WHERE comment_link_id BETWEEN '.(int) $start.' AND '.(int) $stop.'
988 1072
 			GROUP BY comment_link_id';
989 1073
         $result = $this->db->sql_query($sql);
990
-        while ($tmp = $this->db->sql_fetchrow($result)) {
1074
+        while ($tmp = $this->db->sql_fetchrow($result))
1075
+        {
991 1076
             $sql = 'UPDATE '.DIR_LINK_TABLE.'
992 1077
 				SET link_comment = '.(int) $tmp['nb_comment'].'
993 1078
 				WHERE link_id = '.(int) $tmp['comment_link_id'];
@@ -1009,18 +1094,22 @@  discard block
 block discarded – undo
1009 1094
         $imglist = filelist($icons_path, '');
1010 1095
         $filename_list = '<option value="">----------</option>';
1011 1096
 
1012
-        foreach ($imglist as $path => $img_ary) {
1097
+        foreach ($imglist as $path => $img_ary)
1098
+        {
1013 1099
             sort($img_ary);
1014 1100
 
1015
-            foreach ($img_ary as $img) {
1101
+            foreach ($img_ary as $img)
1102
+            {
1016 1103
                 $img = $path.$img;
1017 1104
                 $selected = '';
1018 1105
 
1019
-                if (strlen($img) > 255) {
1106
+                if (strlen($img) > 255)
1107
+                {
1020 1108
                     continue;
1021 1109
                 }
1022 1110
 
1023
-                if ($img == $img_selected) {
1111
+                if ($img == $img_selected)
1112
+                {
1024 1113
                     $selected = ' selected="selected"';
1025 1114
                 }
1026 1115
 
Please login to merge, or discard this patch.
controller/acp/main.php 2 patches
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -9,294 +9,294 @@
 block discarded – undo
9 9
 
10 10
 class main
11 11
 {
12
-    /** @var \phpbb\db\driver\driver_interface */
13
-    protected $db;
14
-
15
-    /** @var \phpbb\request\request */
16
-    protected $request;
17
-
18
-    /** @var \phpbb\template\template */
19
-    protected $template;
20
-
21
-    /** @var \phpbb\user */
22
-    protected $user;
23
-
24
-    /** @var \ernadoo\phpbbdirectory\core\helper */
25
-    protected $dir_helper;
26
-
27
-    /** @var string Custom form action */
28
-    protected $u_action;
29
-
30
-    /**
31
-     * Constructor.
32
-     *
33
-     * @param \phpbb\db\driver\driver_interface   $db         Database object
34
-     * @param \phpbb\request\request              $request    Request object
35
-     * @param \phpbb\template\template            $template   Template object
36
-     * @param \phpbb\user                         $user       User object
37
-     * @param \ernadoo\phpbbdirectory\core\helper $dir_helper PhpBB Directory extension helper object
38
-     */
39
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\helper $dir_helper)
40
-    {
41
-        $this->db = $db;
42
-        $this->template = $template;
43
-        $this->user = $user;
44
-        $this->request = $request;
45
-        $this->dir_helper = $dir_helper;
46
-    }
47
-
48
-    /**
49
-     * Display confirm box.
50
-     *
51
-     * @param string $action Requested action
52
-     *
53
-     * @return null
54
-     */
55
-    public function display_confirm($action)
56
-    {
57
-        switch ($action) {
58
-            case 'votes':
59
-                $confirm = true;
60
-                $confirm_lang = 'DIR_RESET_VOTES_CONFIRM';
61
-                break;
62
-
63
-            case 'comments':
64
-                $confirm = true;
65
-                $confirm_lang = 'DIR_RESET_COMMENTS_CONFIRM';
66
-                break;
67
-
68
-            case 'clicks':
69
-                $confirm = true;
70
-                $confirm_lang = 'DIR_RESET_CLICKS_CONFIRM';
71
-                break;
72
-
73
-            case 'orphans':
74
-                $confirm = true;
75
-                $confirm_lang = 'DIR_DELETE_ORPHANS';
76
-                break;
77
-
78
-            default:
79
-                $confirm = false;
80
-        }
81
-
82
-        if ($confirm) {
83
-            confirm_box(false, $this->user->lang[$confirm_lang], build_hidden_fields([
84
-                'action'    => $action,
85
-            ]));
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Display phpBB Directory statistics.
91
-     *
92
-     * @return null
93
-     */
94
-    public function display_stats()
95
-    {
96
-        // Count number of categories
97
-        $sql = 'SELECT COUNT(cat_id) AS nb_cats
12
+	/** @var \phpbb\db\driver\driver_interface */
13
+	protected $db;
14
+
15
+	/** @var \phpbb\request\request */
16
+	protected $request;
17
+
18
+	/** @var \phpbb\template\template */
19
+	protected $template;
20
+
21
+	/** @var \phpbb\user */
22
+	protected $user;
23
+
24
+	/** @var \ernadoo\phpbbdirectory\core\helper */
25
+	protected $dir_helper;
26
+
27
+	/** @var string Custom form action */
28
+	protected $u_action;
29
+
30
+	/**
31
+	 * Constructor.
32
+	 *
33
+	 * @param \phpbb\db\driver\driver_interface   $db         Database object
34
+	 * @param \phpbb\request\request              $request    Request object
35
+	 * @param \phpbb\template\template            $template   Template object
36
+	 * @param \phpbb\user                         $user       User object
37
+	 * @param \ernadoo\phpbbdirectory\core\helper $dir_helper PhpBB Directory extension helper object
38
+	 */
39
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\helper $dir_helper)
40
+	{
41
+		$this->db = $db;
42
+		$this->template = $template;
43
+		$this->user = $user;
44
+		$this->request = $request;
45
+		$this->dir_helper = $dir_helper;
46
+	}
47
+
48
+	/**
49
+	 * Display confirm box.
50
+	 *
51
+	 * @param string $action Requested action
52
+	 *
53
+	 * @return null
54
+	 */
55
+	public function display_confirm($action)
56
+	{
57
+		switch ($action) {
58
+			case 'votes':
59
+				$confirm = true;
60
+				$confirm_lang = 'DIR_RESET_VOTES_CONFIRM';
61
+				break;
62
+
63
+			case 'comments':
64
+				$confirm = true;
65
+				$confirm_lang = 'DIR_RESET_COMMENTS_CONFIRM';
66
+				break;
67
+
68
+			case 'clicks':
69
+				$confirm = true;
70
+				$confirm_lang = 'DIR_RESET_CLICKS_CONFIRM';
71
+				break;
72
+
73
+			case 'orphans':
74
+				$confirm = true;
75
+				$confirm_lang = 'DIR_DELETE_ORPHANS';
76
+				break;
77
+
78
+			default:
79
+				$confirm = false;
80
+		}
81
+
82
+		if ($confirm) {
83
+			confirm_box(false, $this->user->lang[$confirm_lang], build_hidden_fields([
84
+				'action'    => $action,
85
+			]));
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * Display phpBB Directory statistics.
91
+	 *
92
+	 * @return null
93
+	 */
94
+	public function display_stats()
95
+	{
96
+		// Count number of categories
97
+		$sql = 'SELECT COUNT(cat_id) AS nb_cats
98 98
 			FROM '.DIR_CAT_TABLE;
99
-        $result = $this->db->sql_query($sql);
100
-        $total_cats = (int) $this->db->sql_fetchfield('nb_cats');
101
-        $this->db->sql_freeresult($result);
99
+		$result = $this->db->sql_query($sql);
100
+		$total_cats = (int) $this->db->sql_fetchfield('nb_cats');
101
+		$this->db->sql_freeresult($result);
102 102
 
103
-        // Cont number of links
104
-        $sql = 'SELECT link_id, link_active
103
+		// Cont number of links
104
+		$sql = 'SELECT link_id, link_active
105 105
 			FROM '.DIR_LINK_TABLE;
106
-        $result = $this->db->sql_query($sql);
107
-        $total_links = $waiting_links = 0;
108
-        while ($row = $this->db->sql_fetchrow($result)) {
109
-            $total_links++;
110
-
111
-            if (!$row['link_active']) {
112
-                $waiting_links++;
113
-            }
114
-        }
115
-        $this->db->sql_freeresult($result);
116
-
117
-        // Comments number calculating
118
-        $sql = 'SELECT COUNT(comment_id) AS nb_comments
106
+		$result = $this->db->sql_query($sql);
107
+		$total_links = $waiting_links = 0;
108
+		while ($row = $this->db->sql_fetchrow($result)) {
109
+			$total_links++;
110
+
111
+			if (!$row['link_active']) {
112
+				$waiting_links++;
113
+			}
114
+		}
115
+		$this->db->sql_freeresult($result);
116
+
117
+		// Comments number calculating
118
+		$sql = 'SELECT COUNT(comment_id) AS nb_comments
119 119
 			FROM '.DIR_COMMENT_TABLE;
120
-        $result = $this->db->sql_query($sql);
121
-        $total_comments = (int) $this->db->sql_fetchfield('nb_comments');
122
-        $this->db->sql_freeresult($result);
120
+		$result = $this->db->sql_query($sql);
121
+		$total_comments = (int) $this->db->sql_fetchfield('nb_comments');
122
+		$this->db->sql_freeresult($result);
123 123
 
124
-        // Votes number calculating
125
-        $sql = 'SELECT COUNT(vote_id) AS nb_votes
124
+		// Votes number calculating
125
+		$sql = 'SELECT COUNT(vote_id) AS nb_votes
126 126
 			FROM '.DIR_VOTE_TABLE;
127
-        $result = $this->db->sql_query($sql);
128
-        $total_votes = (int) $this->db->sql_fetchfield('nb_votes');
129
-        $this->db->sql_freeresult($result);
127
+		$result = $this->db->sql_query($sql);
128
+		$total_votes = (int) $this->db->sql_fetchfield('nb_votes');
129
+		$this->db->sql_freeresult($result);
130 130
 
131
-        // Click number calculating
132
-        $sql = 'SELECT SUM(link_view) AS nb_clicks
131
+		// Click number calculating
132
+		$sql = 'SELECT SUM(link_view) AS nb_clicks
133 133
 			FROM '.DIR_LINK_TABLE;
134
-        $result = $this->db->sql_query($sql);
135
-        $total_clicks = (int) $this->db->sql_fetchfield('nb_clicks');
136
-        $this->db->sql_freeresult($result);
137
-
138
-        $banners_dir_size = 0;
139
-
140
-        $banners_path = $this->dir_helper->get_banner_path();
141
-
142
-        if ($banners_dir = @opendir($banners_path)) {
143
-            while (($file = readdir($banners_dir)) !== false) {
144
-                if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false) {
145
-                    $banners_dir_size += filesize($banners_path.$file);
146
-                }
147
-            }
148
-            closedir($banners_dir);
149
-
150
-            $banners_dir_size = get_formatted_filesize($banners_dir_size);
151
-        } else {
152
-            // Couldn't open banners dir.
153
-            $banners_dir_size = $this->user->lang['NOT_AVAILABLE'];
154
-        }
155
-
156
-        $total_orphan = $this->_orphan_files();
157
-
158
-        $this->template->assign_vars([
159
-            'U_ACTION'            => $this->u_action,
160
-
161
-            'TOTAL_CATS'           => $total_cats,
162
-            'TOTAL_LINKS'          => $total_links - $waiting_links,
163
-            'WAITING_LINKS'        => $waiting_links,
164
-            'TOTAL_COMMENTS'       => $total_comments,
165
-            'TOTAL_VOTES'          => $total_votes,
166
-            'TOTAL_CLICKS'         => $total_clicks,
167
-            'TOTAL_ORPHANS'        => $total_orphan,
168
-            'BANNERS_DIR_SIZE'     => $banners_dir_size,
169
-        ]);
170
-    }
171
-
172
-    /**
173
-     * Execute action requested.
174
-     *
175
-     * @param string $action Requested action
176
-     *
177
-     * @return null
178
-     */
179
-    public function exec_action($action)
180
-    {
181
-        switch ($action) {
182
-            case 'votes':
183
-                switch ($this->db->get_sql_layer()) {
184
-                    case 'sqlite':
185
-                    case 'firebird':
186
-                        $this->db->sql_query('DELETE FROM '.DIR_VOTE_TABLE);
187
-                    break;
188
-
189
-                    default:
190
-                        $this->db->sql_query('TRUNCATE TABLE '.DIR_VOTE_TABLE);
191
-                    break;
192
-                }
193
-
194
-                $sql = 'UPDATE '.DIR_LINK_TABLE.'
134
+		$result = $this->db->sql_query($sql);
135
+		$total_clicks = (int) $this->db->sql_fetchfield('nb_clicks');
136
+		$this->db->sql_freeresult($result);
137
+
138
+		$banners_dir_size = 0;
139
+
140
+		$banners_path = $this->dir_helper->get_banner_path();
141
+
142
+		if ($banners_dir = @opendir($banners_path)) {
143
+			while (($file = readdir($banners_dir)) !== false) {
144
+				if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false) {
145
+					$banners_dir_size += filesize($banners_path.$file);
146
+				}
147
+			}
148
+			closedir($banners_dir);
149
+
150
+			$banners_dir_size = get_formatted_filesize($banners_dir_size);
151
+		} else {
152
+			// Couldn't open banners dir.
153
+			$banners_dir_size = $this->user->lang['NOT_AVAILABLE'];
154
+		}
155
+
156
+		$total_orphan = $this->_orphan_files();
157
+
158
+		$this->template->assign_vars([
159
+			'U_ACTION'            => $this->u_action,
160
+
161
+			'TOTAL_CATS'           => $total_cats,
162
+			'TOTAL_LINKS'          => $total_links - $waiting_links,
163
+			'WAITING_LINKS'        => $waiting_links,
164
+			'TOTAL_COMMENTS'       => $total_comments,
165
+			'TOTAL_VOTES'          => $total_votes,
166
+			'TOTAL_CLICKS'         => $total_clicks,
167
+			'TOTAL_ORPHANS'        => $total_orphan,
168
+			'BANNERS_DIR_SIZE'     => $banners_dir_size,
169
+		]);
170
+	}
171
+
172
+	/**
173
+	 * Execute action requested.
174
+	 *
175
+	 * @param string $action Requested action
176
+	 *
177
+	 * @return null
178
+	 */
179
+	public function exec_action($action)
180
+	{
181
+		switch ($action) {
182
+			case 'votes':
183
+				switch ($this->db->get_sql_layer()) {
184
+					case 'sqlite':
185
+					case 'firebird':
186
+						$this->db->sql_query('DELETE FROM '.DIR_VOTE_TABLE);
187
+					break;
188
+
189
+					default:
190
+						$this->db->sql_query('TRUNCATE TABLE '.DIR_VOTE_TABLE);
191
+					break;
192
+				}
193
+
194
+				$sql = 'UPDATE '.DIR_LINK_TABLE.'
195 195
 					SET link_vote = 0, link_note = 0';
196
-                $this->db->sql_query($sql);
197
-
198
-                if ($this->request->is_ajax()) {
199
-                    trigger_error('DIR_RESET_VOTES_SUCCESS');
200
-                }
201
-            break;
202
-
203
-            case 'comments':
204
-                switch ($this->db->get_sql_layer()) {
205
-                    case 'sqlite':
206
-                    case 'firebird':
207
-                        $this->db->sql_query('DELETE FROM '.DIR_COMMENT_TABLE);
208
-                    break;
209
-
210
-                    default:
211
-                        $this->db->sql_query('TRUNCATE TABLE '.DIR_COMMENT_TABLE);
212
-                    break;
213
-                }
214
-
215
-                $sql = 'UPDATE '.DIR_LINK_TABLE.'
196
+				$this->db->sql_query($sql);
197
+
198
+				if ($this->request->is_ajax()) {
199
+					trigger_error('DIR_RESET_VOTES_SUCCESS');
200
+				}
201
+			break;
202
+
203
+			case 'comments':
204
+				switch ($this->db->get_sql_layer()) {
205
+					case 'sqlite':
206
+					case 'firebird':
207
+						$this->db->sql_query('DELETE FROM '.DIR_COMMENT_TABLE);
208
+					break;
209
+
210
+					default:
211
+						$this->db->sql_query('TRUNCATE TABLE '.DIR_COMMENT_TABLE);
212
+					break;
213
+				}
214
+
215
+				$sql = 'UPDATE '.DIR_LINK_TABLE.'
216 216
 					SET link_comment = 0';
217
-                $this->db->sql_query($sql);
217
+				$this->db->sql_query($sql);
218 218
 
219
-                if ($this->request->is_ajax()) {
220
-                    trigger_error('DIR_RESET_COMMENTS_SUCCESS');
221
-                }
219
+				if ($this->request->is_ajax()) {
220
+					trigger_error('DIR_RESET_COMMENTS_SUCCESS');
221
+				}
222 222
 
223
-                break;
223
+				break;
224 224
 
225
-            case 'clicks':
226
-                $sql = 'UPDATE '.DIR_LINK_TABLE.'
225
+			case 'clicks':
226
+				$sql = 'UPDATE '.DIR_LINK_TABLE.'
227 227
 					SET link_view = 0';
228
-                $this->db->sql_query($sql);
229
-
230
-                if ($this->request->is_ajax()) {
231
-                    trigger_error('DIR_RESET_CLICKS_SUCCESS');
232
-                }
233
-            break;
234
-
235
-            case 'orphans':
236
-                $this->_orphan_files(true);
237
-
238
-                if ($this->request->is_ajax()) {
239
-                    trigger_error('DIR_DELETE_ORPHANS_SUCCESS');
240
-                }
241
-            break;
242
-        }
243
-    }
244
-
245
-    /**
246
-     * Set page url.
247
-     *
248
-     * @param string $u_action Custom form action
249
-     *
250
-     * @return null
251
-     */
252
-    public function set_page_url($u_action)
253
-    {
254
-        $this->u_action = $u_action;
255
-    }
256
-
257
-    /**
258
-     * Get orphan banners.
259
-     *
260
-     * @param bool $delete True if we want to delete banners, else false
261
-     *
262
-     * @return null|int Number of orphan files, else null
263
-     */
264
-    private function _orphan_files($delete = false)
265
-    {
266
-        $banner_path = $this->dir_helper->get_banner_path();
267
-        $imglist = filelist($banner_path);
268
-        $physical_files = $logical_files = $orphan_files = [];
269
-
270
-        if (!empty($imglist[''])) {
271
-            $imglist = array_values($imglist);
272
-            $imglist = $imglist[0];
273
-
274
-            foreach ($imglist as $img) {
275
-                $physical_files[] = $img;
276
-            }
277
-            $sql = 'SELECT link_banner FROM '.DIR_LINK_TABLE.'
228
+				$this->db->sql_query($sql);
229
+
230
+				if ($this->request->is_ajax()) {
231
+					trigger_error('DIR_RESET_CLICKS_SUCCESS');
232
+				}
233
+			break;
234
+
235
+			case 'orphans':
236
+				$this->_orphan_files(true);
237
+
238
+				if ($this->request->is_ajax()) {
239
+					trigger_error('DIR_DELETE_ORPHANS_SUCCESS');
240
+				}
241
+			break;
242
+		}
243
+	}
244
+
245
+	/**
246
+	 * Set page url.
247
+	 *
248
+	 * @param string $u_action Custom form action
249
+	 *
250
+	 * @return null
251
+	 */
252
+	public function set_page_url($u_action)
253
+	{
254
+		$this->u_action = $u_action;
255
+	}
256
+
257
+	/**
258
+	 * Get orphan banners.
259
+	 *
260
+	 * @param bool $delete True if we want to delete banners, else false
261
+	 *
262
+	 * @return null|int Number of orphan files, else null
263
+	 */
264
+	private function _orphan_files($delete = false)
265
+	{
266
+		$banner_path = $this->dir_helper->get_banner_path();
267
+		$imglist = filelist($banner_path);
268
+		$physical_files = $logical_files = $orphan_files = [];
269
+
270
+		if (!empty($imglist[''])) {
271
+			$imglist = array_values($imglist);
272
+			$imglist = $imglist[0];
273
+
274
+			foreach ($imglist as $img) {
275
+				$physical_files[] = $img;
276
+			}
277
+			$sql = 'SELECT link_banner FROM '.DIR_LINK_TABLE.'
278 278
 				WHERE link_banner <> \'\'';
279
-            $result = $this->db->sql_query($sql);
280
-
281
-            while ($row = $this->db->sql_fetchrow($result)) {
282
-                if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
283
-                    $logical_files[] = basename($row['link_banner']);
284
-                }
285
-            }
286
-            $this->db->sql_freeresult($result);
287
-
288
-            $orphan_files = array_diff($physical_files, $logical_files);
289
-        }
290
-
291
-        if (!$delete) {
292
-            return count($orphan_files);
293
-        }
294
-
295
-        $dh = @opendir($banner_path);
296
-        while (($file = readdir($dh)) !== false) {
297
-            if (in_array($file, $orphan_files)) {
298
-                @unlink($this->dir_helper->get_banner_path($file));
299
-            }
300
-        }
301
-    }
279
+			$result = $this->db->sql_query($sql);
280
+
281
+			while ($row = $this->db->sql_fetchrow($result)) {
282
+				if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
283
+					$logical_files[] = basename($row['link_banner']);
284
+				}
285
+			}
286
+			$this->db->sql_freeresult($result);
287
+
288
+			$orphan_files = array_diff($physical_files, $logical_files);
289
+		}
290
+
291
+		if (!$delete) {
292
+			return count($orphan_files);
293
+		}
294
+
295
+		$dh = @opendir($banner_path);
296
+		while (($file = readdir($dh)) !== false) {
297
+			if (in_array($file, $orphan_files)) {
298
+				@unlink($this->dir_helper->get_banner_path($file));
299
+			}
300
+		}
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Braces   +45 added lines, -22 removed lines patch added patch discarded remove patch
@@ -54,7 +54,8 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function display_confirm($action)
56 56
     {
57
-        switch ($action) {
57
+        switch ($action)
58
+        {
58 59
             case 'votes':
59 60
                 $confirm = true;
60 61
                 $confirm_lang = 'DIR_RESET_VOTES_CONFIRM';
@@ -79,7 +80,8 @@  discard block
 block discarded – undo
79 80
                 $confirm = false;
80 81
         }
81 82
 
82
-        if ($confirm) {
83
+        if ($confirm)
84
+        {
83 85
             confirm_box(false, $this->user->lang[$confirm_lang], build_hidden_fields([
84 86
                 'action'    => $action,
85 87
             ]));
@@ -105,10 +107,12 @@  discard block
 block discarded – undo
105 107
 			FROM '.DIR_LINK_TABLE;
106 108
         $result = $this->db->sql_query($sql);
107 109
         $total_links = $waiting_links = 0;
108
-        while ($row = $this->db->sql_fetchrow($result)) {
110
+        while ($row = $this->db->sql_fetchrow($result))
111
+        {
109 112
             $total_links++;
110 113
 
111
-            if (!$row['link_active']) {
114
+            if (!$row['link_active'])
115
+            {
112 116
                 $waiting_links++;
113 117
             }
114 118
         }
@@ -139,16 +143,21 @@  discard block
 block discarded – undo
139 143
 
140 144
         $banners_path = $this->dir_helper->get_banner_path();
141 145
 
142
-        if ($banners_dir = @opendir($banners_path)) {
143
-            while (($file = readdir($banners_dir)) !== false) {
144
-                if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false) {
146
+        if ($banners_dir = @opendir($banners_path))
147
+        {
148
+            while (($file = readdir($banners_dir)) !== false)
149
+            {
150
+                if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false)
151
+                {
145 152
                     $banners_dir_size += filesize($banners_path.$file);
146 153
                 }
147 154
             }
148 155
             closedir($banners_dir);
149 156
 
150 157
             $banners_dir_size = get_formatted_filesize($banners_dir_size);
151
-        } else {
158
+        }
159
+        else
160
+        {
152 161
             // Couldn't open banners dir.
153 162
             $banners_dir_size = $this->user->lang['NOT_AVAILABLE'];
154 163
         }
@@ -178,9 +187,11 @@  discard block
 block discarded – undo
178 187
      */
179 188
     public function exec_action($action)
180 189
     {
181
-        switch ($action) {
190
+        switch ($action)
191
+        {
182 192
             case 'votes':
183
-                switch ($this->db->get_sql_layer()) {
193
+                switch ($this->db->get_sql_layer())
194
+                {
184 195
                     case 'sqlite':
185 196
                     case 'firebird':
186 197
                         $this->db->sql_query('DELETE FROM '.DIR_VOTE_TABLE);
@@ -195,13 +206,15 @@  discard block
 block discarded – undo
195 206
 					SET link_vote = 0, link_note = 0';
196 207
                 $this->db->sql_query($sql);
197 208
 
198
-                if ($this->request->is_ajax()) {
209
+                if ($this->request->is_ajax())
210
+                {
199 211
                     trigger_error('DIR_RESET_VOTES_SUCCESS');
200 212
                 }
201 213
             break;
202 214
 
203 215
             case 'comments':
204
-                switch ($this->db->get_sql_layer()) {
216
+                switch ($this->db->get_sql_layer())
217
+                {
205 218
                     case 'sqlite':
206 219
                     case 'firebird':
207 220
                         $this->db->sql_query('DELETE FROM '.DIR_COMMENT_TABLE);
@@ -216,7 +229,8 @@  discard block
 block discarded – undo
216 229
 					SET link_comment = 0';
217 230
                 $this->db->sql_query($sql);
218 231
 
219
-                if ($this->request->is_ajax()) {
232
+                if ($this->request->is_ajax())
233
+                {
220 234
                     trigger_error('DIR_RESET_COMMENTS_SUCCESS');
221 235
                 }
222 236
 
@@ -227,7 +241,8 @@  discard block
 block discarded – undo
227 241
 					SET link_view = 0';
228 242
                 $this->db->sql_query($sql);
229 243
 
230
-                if ($this->request->is_ajax()) {
244
+                if ($this->request->is_ajax())
245
+                {
231 246
                     trigger_error('DIR_RESET_CLICKS_SUCCESS');
232 247
                 }
233 248
             break;
@@ -235,7 +250,8 @@  discard block
 block discarded – undo
235 250
             case 'orphans':
236 251
                 $this->_orphan_files(true);
237 252
 
238
-                if ($this->request->is_ajax()) {
253
+                if ($this->request->is_ajax())
254
+                {
239 255
                     trigger_error('DIR_DELETE_ORPHANS_SUCCESS');
240 256
                 }
241 257
             break;
@@ -267,19 +283,23 @@  discard block
 block discarded – undo
267 283
         $imglist = filelist($banner_path);
268 284
         $physical_files = $logical_files = $orphan_files = [];
269 285
 
270
-        if (!empty($imglist[''])) {
286
+        if (!empty($imglist['']))
287
+        {
271 288
             $imglist = array_values($imglist);
272 289
             $imglist = $imglist[0];
273 290
 
274
-            foreach ($imglist as $img) {
291
+            foreach ($imglist as $img)
292
+            {
275 293
                 $physical_files[] = $img;
276 294
             }
277 295
             $sql = 'SELECT link_banner FROM '.DIR_LINK_TABLE.'
278 296
 				WHERE link_banner <> \'\'';
279 297
             $result = $this->db->sql_query($sql);
280 298
 
281
-            while ($row = $this->db->sql_fetchrow($result)) {
282
-                if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
299
+            while ($row = $this->db->sql_fetchrow($result))
300
+            {
301
+                if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner']))
302
+                {
283 303
                     $logical_files[] = basename($row['link_banner']);
284 304
                 }
285 305
             }
@@ -288,13 +308,16 @@  discard block
 block discarded – undo
288 308
             $orphan_files = array_diff($physical_files, $logical_files);
289 309
         }
290 310
 
291
-        if (!$delete) {
311
+        if (!$delete)
312
+        {
292 313
             return count($orphan_files);
293 314
         }
294 315
 
295 316
         $dh = @opendir($banner_path);
296
-        while (($file = readdir($dh)) !== false) {
297
-            if (in_array($file, $orphan_files)) {
317
+        while (($file = readdir($dh)) !== false)
318
+        {
319
+            if (in_array($file, $orphan_files))
320
+            {
298 321
                 @unlink($this->dir_helper->get_banner_path($file));
299 322
             }
300 323
         }
Please login to merge, or discard this patch.
controller/acp/settings.php 3 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -9,216 +9,216 @@
 block discarded – undo
9 9
 
10 10
 class settings
11 11
 {
12
-    /** @var \phpbb\config\config */
13
-    protected $config;
14
-
15
-    /** @var \phpbb\log\log */
16
-    protected $log;
17
-
18
-    /** @var \phpbb\request\request */
19
-    protected $request;
20
-
21
-    /** @var \phpbb\template\template */
22
-    protected $template;
23
-
24
-    /** @var \phpbb\user */
25
-    protected $user;
26
-
27
-    /** @var string Custom form action */
28
-    protected $u_action;
29
-
30
-    /** @var array */
31
-    private $new_config;
32
-
33
-    /** @var array */
34
-    private $display_vars;
35
-
36
-    /**
37
-     * Constructor.
38
-     *
39
-     * @param \phpbb\config\config     $config   Config object
40
-     * @param \phpbb\log\log           $log      Log object
41
-     * @param \phpbb\request\request   $request  Request object
42
-     * @param \phpbb\template\template $template Template object
43
-     * @param \phpbb\user              $user     User object
44
-     */
45
-    public function __construct(\phpbb\config\config $config, \phpbb\log\log $log, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
46
-    {
47
-        $this->config = $config;
48
-        $this->log = $log;
49
-        $this->template = $template;
50
-        $this->user = $user;
51
-        $this->request = $request;
52
-
53
-        $this->_generate_config();
54
-    }
55
-
56
-    /**
57
-     * Display config page.
58
-     *
59
-     * @return null
60
-     */
61
-    public function display_config()
62
-    {
63
-        // Output relevant page
64
-        foreach ($this->display_vars['vars'] as $config_key => $vars) {
65
-            if (!is_array($vars) && strpos($config_key, 'legend') === false) {
66
-                continue;
67
-            }
68
-
69
-            if (strpos($config_key, 'legend') !== false) {
70
-                $this->template->assign_block_vars('options', [
71
-                    'S_LEGEND'    => true,
72
-                    'LEGEND'      => (isset($this->user->lang[$vars])) ? $this->user->lang[$vars] : $vars, ]
73
-                );
74
-
75
-                continue;
76
-            }
77
-
78
-            $type = explode(':', $vars['type']);
79
-
80
-            $l_explain = '';
81
-            if ($vars['explain'] && isset($vars['lang_explain'])) {
82
-                $l_explain = (isset($this->user->lang[$vars['lang_explain']])) ? $this->user->lang[$vars['lang_explain']] : $vars['lang_explain'];
83
-            } elseif ($vars['explain']) {
84
-                $l_explain = (isset($this->user->lang[$vars['lang'].'_EXPLAIN'])) ? $this->user->lang[$vars['lang'].'_EXPLAIN'] : '';
85
-            }
86
-
87
-            $this->template->assign_block_vars('options', [
88
-                'KEY'              => $config_key,
89
-                'TITLE'            => (isset($this->user->lang[$vars['lang']])) ? $this->user->lang[$vars['lang']] : $vars['lang'],
90
-                'S_EXPLAIN'        => $vars['explain'],
91
-                'TITLE_EXPLAIN'    => $l_explain,
92
-                'CONTENT'          => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
93
-            ]);
94
-
95
-            unset($this->display_vars['vars'][$config_key]);
96
-        }
97
-    }
98
-
99
-    /**
100
-     * Validate config vars and update config table if needed.
101
-     *
102
-     * @return null
103
-     */
104
-    public function process()
105
-    {
106
-        $submit = ($this->request->is_set_post('submit')) ? true : false;
107
-
108
-        $this->new_config = $this->config;
109
-        $cfg_array = ($this->request->is_set('config')) ? $this->request->variable('config', ['' => ''], true) : $this->new_config;
110
-        $error = [];
111
-
112
-        // We validate the complete config if whished
113
-        validate_config_vars($this->display_vars['vars'], $cfg_array, $error);
114
-
115
-        // Do not write values if there is an error
116
-        if (count($error)) {
117
-            $submit = false;
118
-        }
119
-
120
-        // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
121
-        foreach ($this->display_vars['vars'] as $config_name => $null) {
122
-            if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
123
-                continue;
124
-            }
125
-
126
-            $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
127
-
128
-            if ($config_name == 'dir_banner_filesize') {
129
-                $size_var = $this->request->variable($config_name, '');
130
-                $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
131
-            }
132
-
133
-            if ($submit) {
134
-                $this->config->set($config_name, $config_value);
135
-            }
136
-        }
137
-
138
-        if ($submit) {
139
-            $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'DIR_CONFIG_SETTINGS');
140
-
141
-            trigger_error($this->user->lang['CONFIG_UPDATED'].adm_back_link($this->u_action));
142
-        }
143
-
144
-        $this->template->assign_vars([
145
-            'L_TITLE'            => $this->user->lang[$this->display_vars['title']],
146
-            'L_TITLE_EXPLAIN'    => $this->user->lang[$this->display_vars['title'].'_EXPLAIN'],
147
-
148
-            'S_ERROR'              => (count($error)) ? true : false,
149
-            'ERROR_MSG'            => implode('<br />', $error),
150
-
151
-            'U_ACTION'            => $this->u_action, ]
152
-        );
153
-    }
154
-
155
-    /**
156
-     * Set page url.
157
-     *
158
-     * @param string $u_action Custom form action
159
-     *
160
-     * @return null
161
-     */
162
-    public function set_page_url($u_action)
163
-    {
164
-        $this->u_action = $u_action;
165
-    }
166
-
167
-    /**
168
-     * Build config matrice.
169
-     *
170
-     * @return null
171
-     */
172
-    private function _generate_config()
173
-    {
174
-        $this->display_vars = [
175
-            'title'    => 'ACP_DIRECTORY_SETTINGS',
176
-            'vars'     => [
177
-                'legend1' => 'DIR_PARAM',
178
-
179
-                'dir_banner_width'                     => '',
180
-                'dir_banner_height'                    => '',
181
-
182
-                'dir_mail'                             => ['lang' => 'DIR_MAIL_VALIDATION',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
183
-                'dir_activ_checkurl'                   => ['lang' => 'DIR_ACTIVE_CHECK',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
184
-                'dir_activ_flag'                       => ['lang' => 'DIR_ACTIV_FLAG',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
185
-                'dir_activ_rss'                        => ['lang' => 'DIR_ACTIV_RSS',            'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
186
-                'dir_activ_pagerank'                   => ['lang' => 'DIR_ACTIV_PAGERANK',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
187
-                'dir_show'                             => ['lang' => 'DIR_SHOW',                'validate' => 'int:1:9999', 'type' => 'number:1:9999',    'explain' => false],
188
-                'dir_length_describe'                  => ['lang' => 'DIR_MAX_DESC',            'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
189
-                'dir_new_time'                         => ['lang' => 'DIR_NEW_TIME',            'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => true],
190
-                'dir_default_order'                    => ['lang' => 'DIR_DEFAULT_ORDER',        'validate' => 'string',    'type' => 'select',            'explain' => true, 'method' => 'get_order_list', 'params' => ['{CONFIG_VALUE}']],
191
-
192
-                'legend2'                             => 'DIR_RECENT_GUEST',
193
-                'dir_recent_block'                    => ['lang' => 'DIR_RECENT_ENABLE',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
194
-                'dir_recent_rows'                     => ['lang' => 'DIR_RECENT_ROWS',        'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
195
-                'dir_recent_columns'                  => ['lang' => 'DIR_RECENT_COLUMNS',    'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
196
-                'dir_recent_exclude'                  => ['lang' => 'DIR_RECENT_EXCLUDE',    'validate' => 'string',        'type' => 'text:6:99',        'explain' => true],
197
-
198
-                'legend3'                            => 'DIR_ADD_GUEST',
199
-                'dir_visual_confirm'                 => ['lang' => 'DIR_VISUAL_CONFIRM',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
200
-                'dir_visual_confirm_max_attempts'    => ['lang' => 'DIR_MAX_ADD_ATTEMPTS',    'validate' => 'int:0:9999',    'type' => 'number:0:9999',    'explain' => true],
201
-
202
-                'legend4'                              => 'DIR_THUMB_PARAM',
203
-                'dir_activ_thumb'                      => ['lang' => 'DIR_ACTIVE_THUMB',            'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => false],
204
-                'dir_activ_thumb_remote'               => ['lang' => 'DIR_ACTIVE_THUMB_REMOTE',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
205
-                'dir_thumb_service'                    => ['lang' => 'DIR_THUMB_SERVICE',            'validate' => 'string', 'type' => 'select',            'explain' => true, 'method' => 'get_thumb_service_list', 'params' => ['{CONFIG_VALUE}']],
206
-                'dir_thumb_service_reverse'            => ['lang' => 'DIR_THUMB_SERVICE_REVERSE',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
207
-
208
-                'legend5'                              => 'DIR_COMM_PARAM',
209
-                'dir_allow_bbcode'                     => ['lang' => 'DIR_ALLOW_BBCODE',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
210
-                'dir_allow_flash'                      => ['lang' => 'DIR_ALLOW_FLASH',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
211
-                'dir_allow_links'                      => ['lang' => 'DIR_ALLOW_LINKS',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
212
-                'dir_allow_smilies'                    => ['lang' => 'DIR_ALLOW_SMILIES',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
213
-                'dir_length_comments'                  => ['lang' => 'DIR_LENGTH_COMMENTS',    'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => true],
214
-                'dir_comments_per_page'                => ['lang' => 'DIR_COMM_PER_PAGE',        'validate' => 'int:1:9999',    'type' => 'number:1:9999',    'explain' => false],
215
-
216
-                'legend6'                             => 'DIR_BANN_PARAM',
217
-                'dir_activ_banner'                    => ['lang' => 'DIR_ACTIV_BANNER',        'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => false],
218
-                'dir_banner'                          => ['lang' => 'DIR_MAX_BANN',            'validate' => 'int:0',    'type' => 'dimension:0',    'explain' => true, 'append' => ' '.$this->user->lang['PIXEL']],
219
-                'dir_banner_filesize'                 => ['lang' => 'DIR_MAX_SIZE',            'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true],
220
-                'dir_storage_banner'                  => ['lang' => 'DIR_STORAGE_BANNER',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
221
-            ],
222
-        ];
223
-    }
12
+	/** @var \phpbb\config\config */
13
+	protected $config;
14
+
15
+	/** @var \phpbb\log\log */
16
+	protected $log;
17
+
18
+	/** @var \phpbb\request\request */
19
+	protected $request;
20
+
21
+	/** @var \phpbb\template\template */
22
+	protected $template;
23
+
24
+	/** @var \phpbb\user */
25
+	protected $user;
26
+
27
+	/** @var string Custom form action */
28
+	protected $u_action;
29
+
30
+	/** @var array */
31
+	private $new_config;
32
+
33
+	/** @var array */
34
+	private $display_vars;
35
+
36
+	/**
37
+	 * Constructor.
38
+	 *
39
+	 * @param \phpbb\config\config     $config   Config object
40
+	 * @param \phpbb\log\log           $log      Log object
41
+	 * @param \phpbb\request\request   $request  Request object
42
+	 * @param \phpbb\template\template $template Template object
43
+	 * @param \phpbb\user              $user     User object
44
+	 */
45
+	public function __construct(\phpbb\config\config $config, \phpbb\log\log $log, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
46
+	{
47
+		$this->config = $config;
48
+		$this->log = $log;
49
+		$this->template = $template;
50
+		$this->user = $user;
51
+		$this->request = $request;
52
+
53
+		$this->_generate_config();
54
+	}
55
+
56
+	/**
57
+	 * Display config page.
58
+	 *
59
+	 * @return null
60
+	 */
61
+	public function display_config()
62
+	{
63
+		// Output relevant page
64
+		foreach ($this->display_vars['vars'] as $config_key => $vars) {
65
+			if (!is_array($vars) && strpos($config_key, 'legend') === false) {
66
+				continue;
67
+			}
68
+
69
+			if (strpos($config_key, 'legend') !== false) {
70
+				$this->template->assign_block_vars('options', [
71
+					'S_LEGEND'    => true,
72
+					'LEGEND'      => (isset($this->user->lang[$vars])) ? $this->user->lang[$vars] : $vars, ]
73
+				);
74
+
75
+				continue;
76
+			}
77
+
78
+			$type = explode(':', $vars['type']);
79
+
80
+			$l_explain = '';
81
+			if ($vars['explain'] && isset($vars['lang_explain'])) {
82
+				$l_explain = (isset($this->user->lang[$vars['lang_explain']])) ? $this->user->lang[$vars['lang_explain']] : $vars['lang_explain'];
83
+			} elseif ($vars['explain']) {
84
+				$l_explain = (isset($this->user->lang[$vars['lang'].'_EXPLAIN'])) ? $this->user->lang[$vars['lang'].'_EXPLAIN'] : '';
85
+			}
86
+
87
+			$this->template->assign_block_vars('options', [
88
+				'KEY'              => $config_key,
89
+				'TITLE'            => (isset($this->user->lang[$vars['lang']])) ? $this->user->lang[$vars['lang']] : $vars['lang'],
90
+				'S_EXPLAIN'        => $vars['explain'],
91
+				'TITLE_EXPLAIN'    => $l_explain,
92
+				'CONTENT'          => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
93
+			]);
94
+
95
+			unset($this->display_vars['vars'][$config_key]);
96
+		}
97
+	}
98
+
99
+	/**
100
+	 * Validate config vars and update config table if needed.
101
+	 *
102
+	 * @return null
103
+	 */
104
+	public function process()
105
+	{
106
+		$submit = ($this->request->is_set_post('submit')) ? true : false;
107
+
108
+		$this->new_config = $this->config;
109
+		$cfg_array = ($this->request->is_set('config')) ? $this->request->variable('config', ['' => ''], true) : $this->new_config;
110
+		$error = [];
111
+
112
+		// We validate the complete config if whished
113
+		validate_config_vars($this->display_vars['vars'], $cfg_array, $error);
114
+
115
+		// Do not write values if there is an error
116
+		if (count($error)) {
117
+			$submit = false;
118
+		}
119
+
120
+		// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
121
+		foreach ($this->display_vars['vars'] as $config_name => $null) {
122
+			if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
123
+				continue;
124
+			}
125
+
126
+			$this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
127
+
128
+			if ($config_name == 'dir_banner_filesize') {
129
+				$size_var = $this->request->variable($config_name, '');
130
+				$this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
131
+			}
132
+
133
+			if ($submit) {
134
+				$this->config->set($config_name, $config_value);
135
+			}
136
+		}
137
+
138
+		if ($submit) {
139
+			$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'DIR_CONFIG_SETTINGS');
140
+
141
+			trigger_error($this->user->lang['CONFIG_UPDATED'].adm_back_link($this->u_action));
142
+		}
143
+
144
+		$this->template->assign_vars([
145
+			'L_TITLE'            => $this->user->lang[$this->display_vars['title']],
146
+			'L_TITLE_EXPLAIN'    => $this->user->lang[$this->display_vars['title'].'_EXPLAIN'],
147
+
148
+			'S_ERROR'              => (count($error)) ? true : false,
149
+			'ERROR_MSG'            => implode('<br />', $error),
150
+
151
+			'U_ACTION'            => $this->u_action, ]
152
+		);
153
+	}
154
+
155
+	/**
156
+	 * Set page url.
157
+	 *
158
+	 * @param string $u_action Custom form action
159
+	 *
160
+	 * @return null
161
+	 */
162
+	public function set_page_url($u_action)
163
+	{
164
+		$this->u_action = $u_action;
165
+	}
166
+
167
+	/**
168
+	 * Build config matrice.
169
+	 *
170
+	 * @return null
171
+	 */
172
+	private function _generate_config()
173
+	{
174
+		$this->display_vars = [
175
+			'title'    => 'ACP_DIRECTORY_SETTINGS',
176
+			'vars'     => [
177
+				'legend1' => 'DIR_PARAM',
178
+
179
+				'dir_banner_width'                     => '',
180
+				'dir_banner_height'                    => '',
181
+
182
+				'dir_mail'                             => ['lang' => 'DIR_MAIL_VALIDATION',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
183
+				'dir_activ_checkurl'                   => ['lang' => 'DIR_ACTIVE_CHECK',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
184
+				'dir_activ_flag'                       => ['lang' => 'DIR_ACTIV_FLAG',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
185
+				'dir_activ_rss'                        => ['lang' => 'DIR_ACTIV_RSS',            'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
186
+				'dir_activ_pagerank'                   => ['lang' => 'DIR_ACTIV_PAGERANK',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
187
+				'dir_show'                             => ['lang' => 'DIR_SHOW',                'validate' => 'int:1:9999', 'type' => 'number:1:9999',    'explain' => false],
188
+				'dir_length_describe'                  => ['lang' => 'DIR_MAX_DESC',            'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
189
+				'dir_new_time'                         => ['lang' => 'DIR_NEW_TIME',            'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => true],
190
+				'dir_default_order'                    => ['lang' => 'DIR_DEFAULT_ORDER',        'validate' => 'string',    'type' => 'select',            'explain' => true, 'method' => 'get_order_list', 'params' => ['{CONFIG_VALUE}']],
191
+
192
+				'legend2'                             => 'DIR_RECENT_GUEST',
193
+				'dir_recent_block'                    => ['lang' => 'DIR_RECENT_ENABLE',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
194
+				'dir_recent_rows'                     => ['lang' => 'DIR_RECENT_ROWS',        'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
195
+				'dir_recent_columns'                  => ['lang' => 'DIR_RECENT_COLUMNS',    'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
196
+				'dir_recent_exclude'                  => ['lang' => 'DIR_RECENT_EXCLUDE',    'validate' => 'string',        'type' => 'text:6:99',        'explain' => true],
197
+
198
+				'legend3'                            => 'DIR_ADD_GUEST',
199
+				'dir_visual_confirm'                 => ['lang' => 'DIR_VISUAL_CONFIRM',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
200
+				'dir_visual_confirm_max_attempts'    => ['lang' => 'DIR_MAX_ADD_ATTEMPTS',    'validate' => 'int:0:9999',    'type' => 'number:0:9999',    'explain' => true],
201
+
202
+				'legend4'                              => 'DIR_THUMB_PARAM',
203
+				'dir_activ_thumb'                      => ['lang' => 'DIR_ACTIVE_THUMB',            'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => false],
204
+				'dir_activ_thumb_remote'               => ['lang' => 'DIR_ACTIVE_THUMB_REMOTE',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
205
+				'dir_thumb_service'                    => ['lang' => 'DIR_THUMB_SERVICE',            'validate' => 'string', 'type' => 'select',            'explain' => true, 'method' => 'get_thumb_service_list', 'params' => ['{CONFIG_VALUE}']],
206
+				'dir_thumb_service_reverse'            => ['lang' => 'DIR_THUMB_SERVICE_REVERSE',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
207
+
208
+				'legend5'                              => 'DIR_COMM_PARAM',
209
+				'dir_allow_bbcode'                     => ['lang' => 'DIR_ALLOW_BBCODE',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
210
+				'dir_allow_flash'                      => ['lang' => 'DIR_ALLOW_FLASH',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
211
+				'dir_allow_links'                      => ['lang' => 'DIR_ALLOW_LINKS',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
212
+				'dir_allow_smilies'                    => ['lang' => 'DIR_ALLOW_SMILIES',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
213
+				'dir_length_comments'                  => ['lang' => 'DIR_LENGTH_COMMENTS',    'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => true],
214
+				'dir_comments_per_page'                => ['lang' => 'DIR_COMM_PER_PAGE',        'validate' => 'int:1:9999',    'type' => 'number:1:9999',    'explain' => false],
215
+
216
+				'legend6'                             => 'DIR_BANN_PARAM',
217
+				'dir_activ_banner'                    => ['lang' => 'DIR_ACTIV_BANNER',        'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => false],
218
+				'dir_banner'                          => ['lang' => 'DIR_MAX_BANN',            'validate' => 'int:0',    'type' => 'dimension:0',    'explain' => true, 'append' => ' '.$this->user->lang['PIXEL']],
219
+				'dir_banner_filesize'                 => ['lang' => 'DIR_MAX_SIZE',            'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true],
220
+				'dir_storage_banner'                  => ['lang' => 'DIR_STORAGE_BANNER',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
221
+			],
222
+		];
223
+	}
224 224
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -179,45 +179,45 @@
 block discarded – undo
179 179
                 'dir_banner_width'                     => '',
180 180
                 'dir_banner_height'                    => '',
181 181
 
182
-                'dir_mail'                             => ['lang' => 'DIR_MAIL_VALIDATION',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
183
-                'dir_activ_checkurl'                   => ['lang' => 'DIR_ACTIVE_CHECK',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
184
-                'dir_activ_flag'                       => ['lang' => 'DIR_ACTIV_FLAG',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
185
-                'dir_activ_rss'                        => ['lang' => 'DIR_ACTIV_RSS',            'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
186
-                'dir_activ_pagerank'                   => ['lang' => 'DIR_ACTIV_PAGERANK',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
187
-                'dir_show'                             => ['lang' => 'DIR_SHOW',                'validate' => 'int:1:9999', 'type' => 'number:1:9999',    'explain' => false],
188
-                'dir_length_describe'                  => ['lang' => 'DIR_MAX_DESC',            'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
189
-                'dir_new_time'                         => ['lang' => 'DIR_NEW_TIME',            'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => true],
190
-                'dir_default_order'                    => ['lang' => 'DIR_DEFAULT_ORDER',        'validate' => 'string',    'type' => 'select',            'explain' => true, 'method' => 'get_order_list', 'params' => ['{CONFIG_VALUE}']],
182
+                'dir_mail'                             => ['lang' => 'DIR_MAIL_VALIDATION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
183
+                'dir_activ_checkurl'                   => ['lang' => 'DIR_ACTIVE_CHECK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
184
+                'dir_activ_flag'                       => ['lang' => 'DIR_ACTIV_FLAG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
185
+                'dir_activ_rss'                        => ['lang' => 'DIR_ACTIV_RSS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
186
+                'dir_activ_pagerank'                   => ['lang' => 'DIR_ACTIV_PAGERANK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
187
+                'dir_show'                             => ['lang' => 'DIR_SHOW', 'validate' => 'int:1:9999', 'type' => 'number:1:9999', 'explain' => false],
188
+                'dir_length_describe'                  => ['lang' => 'DIR_MAX_DESC', 'validate' => 'int:1:999', 'type' => 'number:1:999', 'explain' => false],
189
+                'dir_new_time'                         => ['lang' => 'DIR_NEW_TIME', 'validate' => 'int:1:999', 'type' => 'number:1:999', 'explain' => true],
190
+                'dir_default_order'                    => ['lang' => 'DIR_DEFAULT_ORDER', 'validate' => 'string', 'type' => 'select', 'explain' => true, 'method' => 'get_order_list', 'params' => ['{CONFIG_VALUE}']],
191 191
 
192 192
                 'legend2'                             => 'DIR_RECENT_GUEST',
193
-                'dir_recent_block'                    => ['lang' => 'DIR_RECENT_ENABLE',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
194
-                'dir_recent_rows'                     => ['lang' => 'DIR_RECENT_ROWS',        'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
195
-                'dir_recent_columns'                  => ['lang' => 'DIR_RECENT_COLUMNS',    'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => false],
196
-                'dir_recent_exclude'                  => ['lang' => 'DIR_RECENT_EXCLUDE',    'validate' => 'string',        'type' => 'text:6:99',        'explain' => true],
193
+                'dir_recent_block'                    => ['lang' => 'DIR_RECENT_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
194
+                'dir_recent_rows'                     => ['lang' => 'DIR_RECENT_ROWS', 'validate' => 'int:1:999', 'type' => 'number:1:999', 'explain' => false],
195
+                'dir_recent_columns'                  => ['lang' => 'DIR_RECENT_COLUMNS', 'validate' => 'int:1:999', 'type' => 'number:1:999', 'explain' => false],
196
+                'dir_recent_exclude'                  => ['lang' => 'DIR_RECENT_EXCLUDE', 'validate' => 'string', 'type' => 'text:6:99', 'explain' => true],
197 197
 
198 198
                 'legend3'                            => 'DIR_ADD_GUEST',
199
-                'dir_visual_confirm'                 => ['lang' => 'DIR_VISUAL_CONFIRM',    'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => true],
200
-                'dir_visual_confirm_max_attempts'    => ['lang' => 'DIR_MAX_ADD_ATTEMPTS',    'validate' => 'int:0:9999',    'type' => 'number:0:9999',    'explain' => true],
199
+                'dir_visual_confirm'                 => ['lang' => 'DIR_VISUAL_CONFIRM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
200
+                'dir_visual_confirm_max_attempts'    => ['lang' => 'DIR_MAX_ADD_ATTEMPTS', 'validate' => 'int:0:9999', 'type' => 'number:0:9999', 'explain' => true],
201 201
 
202 202
                 'legend4'                              => 'DIR_THUMB_PARAM',
203
-                'dir_activ_thumb'                      => ['lang' => 'DIR_ACTIVE_THUMB',            'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => false],
204
-                'dir_activ_thumb_remote'               => ['lang' => 'DIR_ACTIVE_THUMB_REMOTE',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
205
-                'dir_thumb_service'                    => ['lang' => 'DIR_THUMB_SERVICE',            'validate' => 'string', 'type' => 'select',            'explain' => true, 'method' => 'get_thumb_service_list', 'params' => ['{CONFIG_VALUE}']],
206
-                'dir_thumb_service_reverse'            => ['lang' => 'DIR_THUMB_SERVICE_REVERSE',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
203
+                'dir_activ_thumb'                      => ['lang' => 'DIR_ACTIVE_THUMB', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
204
+                'dir_activ_thumb_remote'               => ['lang' => 'DIR_ACTIVE_THUMB_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
205
+                'dir_thumb_service'                    => ['lang' => 'DIR_THUMB_SERVICE', 'validate' => 'string', 'type' => 'select', 'explain' => true, 'method' => 'get_thumb_service_list', 'params' => ['{CONFIG_VALUE}']],
206
+                'dir_thumb_service_reverse'            => ['lang' => 'DIR_THUMB_SERVICE_REVERSE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
207 207
 
208 208
                 'legend5'                              => 'DIR_COMM_PARAM',
209
-                'dir_allow_bbcode'                     => ['lang' => 'DIR_ALLOW_BBCODE',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
210
-                'dir_allow_flash'                      => ['lang' => 'DIR_ALLOW_FLASH',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
211
-                'dir_allow_links'                      => ['lang' => 'DIR_ALLOW_LINKS',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
212
-                'dir_allow_smilies'                    => ['lang' => 'DIR_ALLOW_SMILIES',        'validate' => 'bool',        'type' => 'radio:yes_no',    'explain' => false],
213
-                'dir_length_comments'                  => ['lang' => 'DIR_LENGTH_COMMENTS',    'validate' => 'int:1:999',    'type' => 'number:1:999',    'explain' => true],
214
-                'dir_comments_per_page'                => ['lang' => 'DIR_COMM_PER_PAGE',        'validate' => 'int:1:9999',    'type' => 'number:1:9999',    'explain' => false],
209
+                'dir_allow_bbcode'                     => ['lang' => 'DIR_ALLOW_BBCODE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
210
+                'dir_allow_flash'                      => ['lang' => 'DIR_ALLOW_FLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
211
+                'dir_allow_links'                      => ['lang' => 'DIR_ALLOW_LINKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
212
+                'dir_allow_smilies'                    => ['lang' => 'DIR_ALLOW_SMILIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
213
+                'dir_length_comments'                  => ['lang' => 'DIR_LENGTH_COMMENTS', 'validate' => 'int:1:999', 'type' => 'number:1:999', 'explain' => true],
214
+                'dir_comments_per_page'                => ['lang' => 'DIR_COMM_PER_PAGE', 'validate' => 'int:1:9999', 'type' => 'number:1:9999', 'explain' => false],
215 215
 
216 216
                 'legend6'                             => 'DIR_BANN_PARAM',
217
-                'dir_activ_banner'                    => ['lang' => 'DIR_ACTIV_BANNER',        'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => false],
218
-                'dir_banner'                          => ['lang' => 'DIR_MAX_BANN',            'validate' => 'int:0',    'type' => 'dimension:0',    'explain' => true, 'append' => ' '.$this->user->lang['PIXEL']],
219
-                'dir_banner_filesize'                 => ['lang' => 'DIR_MAX_SIZE',            'validate' => 'string',    'type' => 'custom', 'method' => 'max_filesize', 'explain' => true],
220
-                'dir_storage_banner'                  => ['lang' => 'DIR_STORAGE_BANNER',    'validate' => 'bool',    'type' => 'radio:yes_no',    'explain' => true],
217
+                'dir_activ_banner'                    => ['lang' => 'DIR_ACTIV_BANNER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false],
218
+                'dir_banner'                          => ['lang' => 'DIR_MAX_BANN', 'validate' => 'int:0', 'type' => 'dimension:0', 'explain' => true, 'append' => ' '.$this->user->lang['PIXEL']],
219
+                'dir_banner_filesize'                 => ['lang' => 'DIR_MAX_SIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true],
220
+                'dir_storage_banner'                  => ['lang' => 'DIR_STORAGE_BANNER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
221 221
             ],
222 222
         ];
223 223
     }
Please login to merge, or discard this patch.
Braces   +23 added lines, -11 removed lines patch added patch discarded remove patch
@@ -61,12 +61,15 @@  discard block
 block discarded – undo
61 61
     public function display_config()
62 62
     {
63 63
         // Output relevant page
64
-        foreach ($this->display_vars['vars'] as $config_key => $vars) {
65
-            if (!is_array($vars) && strpos($config_key, 'legend') === false) {
64
+        foreach ($this->display_vars['vars'] as $config_key => $vars)
65
+        {
66
+            if (!is_array($vars) && strpos($config_key, 'legend') === false)
67
+            {
66 68
                 continue;
67 69
             }
68 70
 
69
-            if (strpos($config_key, 'legend') !== false) {
71
+            if (strpos($config_key, 'legend') !== false)
72
+            {
70 73
                 $this->template->assign_block_vars('options', [
71 74
                     'S_LEGEND'    => true,
72 75
                     'LEGEND'      => (isset($this->user->lang[$vars])) ? $this->user->lang[$vars] : $vars, ]
@@ -78,9 +81,12 @@  discard block
 block discarded – undo
78 81
             $type = explode(':', $vars['type']);
79 82
 
80 83
             $l_explain = '';
81
-            if ($vars['explain'] && isset($vars['lang_explain'])) {
84
+            if ($vars['explain'] && isset($vars['lang_explain']))
85
+            {
82 86
                 $l_explain = (isset($this->user->lang[$vars['lang_explain']])) ? $this->user->lang[$vars['lang_explain']] : $vars['lang_explain'];
83
-            } elseif ($vars['explain']) {
87
+            }
88
+            elseif ($vars['explain'])
89
+            {
84 90
                 $l_explain = (isset($this->user->lang[$vars['lang'].'_EXPLAIN'])) ? $this->user->lang[$vars['lang'].'_EXPLAIN'] : '';
85 91
             }
86 92
 
@@ -113,29 +119,35 @@  discard block
 block discarded – undo
113 119
         validate_config_vars($this->display_vars['vars'], $cfg_array, $error);
114 120
 
115 121
         // Do not write values if there is an error
116
-        if (count($error)) {
122
+        if (count($error))
123
+        {
117 124
             $submit = false;
118 125
         }
119 126
 
120 127
         // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
121
-        foreach ($this->display_vars['vars'] as $config_name => $null) {
122
-            if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
128
+        foreach ($this->display_vars['vars'] as $config_name => $null)
129
+        {
130
+            if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
131
+            {
123 132
                 continue;
124 133
             }
125 134
 
126 135
             $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
127 136
 
128
-            if ($config_name == 'dir_banner_filesize') {
137
+            if ($config_name == 'dir_banner_filesize')
138
+            {
129 139
                 $size_var = $this->request->variable($config_name, '');
130 140
                 $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
131 141
             }
132 142
 
133
-            if ($submit) {
143
+            if ($submit)
144
+            {
134 145
                 $this->config->set($config_name, $config_value);
135 146
             }
136 147
         }
137 148
 
138
-        if ($submit) {
149
+        if ($submit)
150
+        {
139 151
             $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'DIR_CONFIG_SETTINGS');
140 152
 
141 153
             trigger_error($this->user->lang['CONFIG_UPDATED'].adm_back_link($this->u_action));
Please login to merge, or discard this patch.
controller/acp/validation.php 2 patches
Indentation   +395 added lines, -395 removed lines patch added patch discarded remove patch
@@ -9,406 +9,406 @@
 block discarded – undo
9 9
 
10 10
 class validation
11 11
 {
12
-    /** @var \phpbb\config\config */
13
-    protected $config;
14
-
15
-    /** @var \phpbb\db\driver\driver_interface */
16
-    protected $db;
17
-
18
-    /** @var \phpbb\pagination */
19
-    protected $pagination;
20
-
21
-    /** @var \phpbb\log\log */
22
-    protected $phpbb_log;
23
-
24
-    /** @var \phpbb\notification\manager */
25
-    protected $notification;
26
-
27
-    /** @var \phpbb\request\request */
28
-    protected $request;
29
-
30
-    /** @var \phpbb\template\template */
31
-    protected $template;
32
-
33
-    /** @var \phpbb\user */
34
-    protected $user;
35
-
36
-    /** @var \ernadoo\phpbbdirectory\core\categorie */
37
-    protected $categorie;
38
-
39
-    /** @var \ernadoo\phpbbdirectory\core\helper */
40
-    protected $dir_helper;
41
-
42
-    /** @var \ernadoo\phpbbdirectory\core\link */
43
-    protected $link;
44
-
45
-    /** @var string phpBB root path */
46
-    protected $root_path;
47
-
48
-    /** @var string phpEx */
49
-    protected $php_ext;
50
-
51
-    /** @var string Custom form action */
52
-    protected $u_action;
53
-
54
-    /** @var string */
55
-    private $action;
56
-
57
-    /** @var array */
58
-    private $affected_link_name = [];
59
-
60
-    /** @var array */
61
-    private $cat_data = [];
62
-
63
-    /** @var array */
64
-    private $links_data;
65
-
66
-    /**
67
-     * Constructor.
68
-     *
69
-     * @param \phpbb\config\config                   $config       Config object
70
-     * @param \phpbb\db\driver\driver_interface      $db           Database object
71
-     * @param \phpbb\pagination                      $pagination   Pagination object
72
-     * @param \phpbb\log\log                         $log          Log object
73
-     * @param \phpbb\notification\manager            $notification Notification object
74
-     * @param \phpbb\request\request                 $request      Request object
75
-     * @param \phpbb\template\template               $template     Template object
76
-     * @param \phpbb\user                            $user         User object
77
-     * @param \ernadoo\phpbbdirectory\core\categorie $categorie    PhpBB Directory extension categorie object
78
-     * @param \ernadoo\phpbbdirectory\core\helper    $dir_helper   PhpBB Directory extension helper object
79
-     * @param \ernadoo\phpbbdirectory\core\link      $link         PhpBB Directory extension link object
80
-     * @param string                                 $root_path    phpBB root path
81
-     * @param string                                 $php_ext      phpEx
82
-     */
83
-    public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\pagination $pagination, \phpbb\log\log $log, \phpbb\notification\manager $notification, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\helper $dir_helper, \ernadoo\phpbbdirectory\core\link $link, $root_path, $php_ext)
84
-    {
85
-        $this->config = $config;
86
-        $this->db = $db;
87
-        $this->pagination = $pagination;
88
-        $this->phpbb_log = $log;
89
-        $this->notification = $notification;
90
-        $this->request = $request;
91
-        $this->template = $template;
92
-        $this->user = $user;
93
-        $this->categorie = $categorie;
94
-        $this->dir_helper = $dir_helper;
95
-        $this->link = $link;
96
-        $this->root_path = $root_path;
97
-        $this->php_ext = $php_ext;
98
-
99
-        $this->action = $this->request->variable('action', '');
100
-    }
101
-
102
-    /**
103
-     * Display confirm box.
104
-     *
105
-     * @param array $mark Website selected for (dis)approval
106
-     *
107
-     * @return null
108
-     */
109
-    public function display_confirm($mark)
110
-    {
111
-        $s_hidden_fields = [
112
-            'action'           => $this->action,
113
-            'link_id'          => $mark,
114
-            'start'            => $this->request->variable('start', 0),
115
-        ];
116
-        confirm_box(false, $this->user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
117
-    }
118
-
119
-    /**
120
-     * Display website list for (dis)approval.
121
-     *
122
-     * @return null
123
-     */
124
-    public function display_websites()
125
-    {
126
-        global $phpbb_admin_path;
127
-
128
-        // Sort keys
129
-        $sort_days = $this->request->variable('st', 0);
130
-        $sort_key = $this->request->variable('sk', 't');
131
-        $sort_dir = $this->request->variable('sd', 'd');
132
-
133
-        // Number of entries to display
134
-        $per_page = $this->request->variable('links_per_page', (int) $this->config['dir_show']);
135
-
136
-        $start = $this->request->variable('start', 0);
137
-
138
-        // Categorie ordering options
139
-        $limit_days = [0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']];
140
-        $sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME']];
141
-        $sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id']];
142
-
143
-        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
144
-        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
145
-
146
-        // Define where and sort sql for use in displaying logs
147
-        $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
148
-        $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
149
-
150
-        if (is_array($sort_by_sql[$sort_key])) {
151
-            $sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
152
-        } else {
153
-            $sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
154
-        }
155
-
156
-        $sql = 'SELECT COUNT(1) AS total_links
12
+	/** @var \phpbb\config\config */
13
+	protected $config;
14
+
15
+	/** @var \phpbb\db\driver\driver_interface */
16
+	protected $db;
17
+
18
+	/** @var \phpbb\pagination */
19
+	protected $pagination;
20
+
21
+	/** @var \phpbb\log\log */
22
+	protected $phpbb_log;
23
+
24
+	/** @var \phpbb\notification\manager */
25
+	protected $notification;
26
+
27
+	/** @var \phpbb\request\request */
28
+	protected $request;
29
+
30
+	/** @var \phpbb\template\template */
31
+	protected $template;
32
+
33
+	/** @var \phpbb\user */
34
+	protected $user;
35
+
36
+	/** @var \ernadoo\phpbbdirectory\core\categorie */
37
+	protected $categorie;
38
+
39
+	/** @var \ernadoo\phpbbdirectory\core\helper */
40
+	protected $dir_helper;
41
+
42
+	/** @var \ernadoo\phpbbdirectory\core\link */
43
+	protected $link;
44
+
45
+	/** @var string phpBB root path */
46
+	protected $root_path;
47
+
48
+	/** @var string phpEx */
49
+	protected $php_ext;
50
+
51
+	/** @var string Custom form action */
52
+	protected $u_action;
53
+
54
+	/** @var string */
55
+	private $action;
56
+
57
+	/** @var array */
58
+	private $affected_link_name = [];
59
+
60
+	/** @var array */
61
+	private $cat_data = [];
62
+
63
+	/** @var array */
64
+	private $links_data;
65
+
66
+	/**
67
+	 * Constructor.
68
+	 *
69
+	 * @param \phpbb\config\config                   $config       Config object
70
+	 * @param \phpbb\db\driver\driver_interface      $db           Database object
71
+	 * @param \phpbb\pagination                      $pagination   Pagination object
72
+	 * @param \phpbb\log\log                         $log          Log object
73
+	 * @param \phpbb\notification\manager            $notification Notification object
74
+	 * @param \phpbb\request\request                 $request      Request object
75
+	 * @param \phpbb\template\template               $template     Template object
76
+	 * @param \phpbb\user                            $user         User object
77
+	 * @param \ernadoo\phpbbdirectory\core\categorie $categorie    PhpBB Directory extension categorie object
78
+	 * @param \ernadoo\phpbbdirectory\core\helper    $dir_helper   PhpBB Directory extension helper object
79
+	 * @param \ernadoo\phpbbdirectory\core\link      $link         PhpBB Directory extension link object
80
+	 * @param string                                 $root_path    phpBB root path
81
+	 * @param string                                 $php_ext      phpEx
82
+	 */
83
+	public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\pagination $pagination, \phpbb\log\log $log, \phpbb\notification\manager $notification, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\helper $dir_helper, \ernadoo\phpbbdirectory\core\link $link, $root_path, $php_ext)
84
+	{
85
+		$this->config = $config;
86
+		$this->db = $db;
87
+		$this->pagination = $pagination;
88
+		$this->phpbb_log = $log;
89
+		$this->notification = $notification;
90
+		$this->request = $request;
91
+		$this->template = $template;
92
+		$this->user = $user;
93
+		$this->categorie = $categorie;
94
+		$this->dir_helper = $dir_helper;
95
+		$this->link = $link;
96
+		$this->root_path = $root_path;
97
+		$this->php_ext = $php_ext;
98
+
99
+		$this->action = $this->request->variable('action', '');
100
+	}
101
+
102
+	/**
103
+	 * Display confirm box.
104
+	 *
105
+	 * @param array $mark Website selected for (dis)approval
106
+	 *
107
+	 * @return null
108
+	 */
109
+	public function display_confirm($mark)
110
+	{
111
+		$s_hidden_fields = [
112
+			'action'           => $this->action,
113
+			'link_id'          => $mark,
114
+			'start'            => $this->request->variable('start', 0),
115
+		];
116
+		confirm_box(false, $this->user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
117
+	}
118
+
119
+	/**
120
+	 * Display website list for (dis)approval.
121
+	 *
122
+	 * @return null
123
+	 */
124
+	public function display_websites()
125
+	{
126
+		global $phpbb_admin_path;
127
+
128
+		// Sort keys
129
+		$sort_days = $this->request->variable('st', 0);
130
+		$sort_key = $this->request->variable('sk', 't');
131
+		$sort_dir = $this->request->variable('sd', 'd');
132
+
133
+		// Number of entries to display
134
+		$per_page = $this->request->variable('links_per_page', (int) $this->config['dir_show']);
135
+
136
+		$start = $this->request->variable('start', 0);
137
+
138
+		// Categorie ordering options
139
+		$limit_days = [0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']];
140
+		$sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME']];
141
+		$sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id']];
142
+
143
+		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
144
+		gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
145
+
146
+		// Define where and sort sql for use in displaying logs
147
+		$sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
148
+		$direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
149
+
150
+		if (is_array($sort_by_sql[$sort_key])) {
151
+			$sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
152
+		} else {
153
+			$sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
154
+		}
155
+
156
+		$sql = 'SELECT COUNT(1) AS total_links
157 157
 			FROM '.DIR_LINK_TABLE.'
158 158
 			WHERE link_active = 0'.
159
-                (($sql_where) ? " AND link_time >= $sql_where" : '');
160
-        $result = $this->db->sql_query($sql);
161
-        $total_links = (int) $this->db->sql_fetchfield('total_links');
162
-        $this->db->sql_freeresult($result);
163
-
164
-        // Make sure $start is set to the last page if it exceeds the amount
165
-        $start = $this->pagination->validate_start($start, $per_page, $total_links);
166
-
167
-        $sql_array = [
168
-            'SELECT'      => 'l.link_id, l.link_name, l.link_url, l.link_description, l.link_cat, l.link_user_id, l.link_guest_email, l.link_uid, l.link_bitfield, l.link_flags, l.link_banner, l.link_time, c.cat_name, u.user_id, u.username, u.user_colour',
169
-            'FROM'        => [
170
-                DIR_LINK_TABLE    => 'l', ],
171
-            'LEFT_JOIN'    => [
172
-                [
173
-                    'FROM'    => [DIR_CAT_TABLE => 'c'],
174
-                    'ON'      => 'c.cat_id = l.link_cat',
175
-                ],
176
-                [
177
-                    'FROM'    => [USERS_TABLE => 'u'],
178
-                    'ON'      => 'u.user_id = l.link_user_id',
179
-                ],
180
-            ],
181
-            'WHERE'        => 'l.link_active = 0'.(($sql_where) ? " AND l.link_time >= $sql_where" : ''),
182
-            'ORDER_BY'     => $sql_sort_order, ];
183
-
184
-        $sql = $this->db->sql_build_query('SELECT', $sql_array);
185
-        $result = $this->db->sql_query_limit($sql, $per_page, $start);
186
-
187
-        while ($row = $this->db->sql_fetchrow($result)) {
188
-            $s_banner = $this->link->display_bann($row);
189
-
190
-            $username = ($row['link_user_id'] == ANONYMOUS) ? $row['link_guest_email'] : $row['username'];
191
-
192
-            $link_row = [
193
-                'LINK_URL'             => $row['link_url'],
194
-                'LINK_NAME'            => $row['link_name'],
195
-                'LINK_DESC'            => generate_text_for_display($row['link_description'], $row['link_uid'], $row['link_bitfield'], $row['link_flags']),
196
-                'L_DIR_USER_PROP'      => $this->user->lang('DIR_USER_PROP', get_username_string('full', $row['link_user_id'], $username, $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$this->php_ext", 'i=users&amp;mode=overview')), '<select name=c'.$row['link_id'].'>'.$this->categorie->make_cat_select((int) $row['link_cat']).'</select>', $this->user->format_date($row['link_time'])),
197
-                'BANNER'               => $s_banner,
198
-                'LINK_ID'              => $row['link_id'],
199
-
200
-            ];
201
-            $this->template->assign_block_vars('linkrow', $link_row);
202
-        }
203
-        $this->db->sql_freeresult($result);
204
-
205
-        $option_ary = ['approved' => 'DIR_LINK_ACTIVATE', 'disapproved' => 'DIR_LINK_DELETE'];
206
-
207
-        $base_url = $this->u_action."&amp;$u_sort_param&amp;links_per_page=$per_page";
208
-        $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_links, $per_page, $start);
209
-
210
-        $this->template->assign_vars([
211
-            'S_LINKS_OPTIONS'    => build_select($option_ary),
212
-
213
-            'S_LIMIT_DAYS'        => $s_limit_days,
214
-            'S_SORT_KEY'          => $s_sort_key,
215
-            'S_SORT_DIR'          => $s_sort_dir,
216
-            'LINKS_PER_PAGE'      => $per_page,
217
-
218
-            'U_ACTION'            => $this->u_action."&amp;$u_sort_param&amp;links_per_page=$per_page&amp;start=$start",
219
-        ]);
220
-    }
221
-
222
-    /**
223
-     * Get link's information and call appropriate action.
224
-     *
225
-     * @param array $mark Website selected for (dis)approval
226
-     *
227
-     * @return null
228
-     */
229
-    public function exec_action($mark)
230
-    {
231
-        $this->_get_infos_links($mark);
232
-
233
-        switch ($this->action) {
234
-            case 'approved':
235
-                $this->_action_approved();
236
-                break;
237
-
238
-            case 'disapproved':
239
-                $this->_action_disapproved();
240
-                break;
241
-
242
-            default:
243
-                return;
244
-        }
245
-
246
-        $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_LINK_'.strtoupper($this->action), time(), [implode(', ', $this->affected_link_name)]);
247
-    }
248
-
249
-    /**
250
-     * Notify users which had submitted their websites.
251
-     *
252
-     * @return null
253
-     */
254
-    public function notifiy_submiters()
255
-    {
256
-        if (!class_exists('messenger')) {
257
-            include $this->root_path.'includes/functions_messenger.'.$this->php_ext;
258
-        }
259
-        $messenger = new \messenger(false);
260
-
261
-        foreach ($this->links_data as $row) {
262
-            $this->notification->mark_notifications_read('ernadoo.phpbbdirectory.notification.type.directory_website_in_queue', (int) $row['link_id'], false);
263
-
264
-            // New notification system can't send mail to an anonymous user with an email adress storage in another table than phpbb_users
265
-            if ($row['link_user_id'] == ANONYMOUS) {
266
-                $username = $email = $row['link_guest_email'];
267
-
268
-                $messenger->template('@ernadoo_phpbbdirectory/directory_website_'.$this->action, $row['user_lang']);
269
-                $messenger->to($email, $username);
270
-
271
-                $messenger->assign_vars([
272
-                    'USERNAME'     => htmlspecialchars_decode($username),
273
-                    'LINK_NAME'    => $row['link_name'],
274
-                ]);
275
-
276
-                $messenger->send(NOTIFY_EMAIL);
277
-            } else {
278
-                $notification_data = [
279
-                    'user_from'            => (int) $row['link_user_id'],
280
-                    'link_id'              => (int) $row['link_id'],
281
-                    'link_name'            => $row['link_name'],
282
-                    'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $row['link_cat']),
283
-                    'cat_id'               => (int) $row['link_cat'],
284
-                ];
285
-
286
-                $this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_'.$this->action, $notification_data);
287
-            }
288
-        }
289
-    }
290
-
291
-    /**
292
-     * Set page url.
293
-     *
294
-     * @param string $u_action Custom form action
295
-     *
296
-     * @return null
297
-     */
298
-    public function set_page_url($u_action)
299
-    {
300
-        $this->u_action = $u_action;
301
-    }
302
-
303
-    /**
304
-     * Approve action.
305
-     *
306
-     * @return null
307
-     */
308
-    private function _action_approved()
309
-    {
310
-        foreach ($this->links_data as $row) {
311
-            $this->_notify_suscribers($row);
312
-
313
-            $sql_ary = [
314
-                'link_active'      => 1,
315
-                'link_time'        => time(),
316
-                'link_cat'         => (int) $row['link_cat'],
317
-            ];
318
-
319
-            $sql = 'UPDATE '.DIR_LINK_TABLE.'
159
+				(($sql_where) ? " AND link_time >= $sql_where" : '');
160
+		$result = $this->db->sql_query($sql);
161
+		$total_links = (int) $this->db->sql_fetchfield('total_links');
162
+		$this->db->sql_freeresult($result);
163
+
164
+		// Make sure $start is set to the last page if it exceeds the amount
165
+		$start = $this->pagination->validate_start($start, $per_page, $total_links);
166
+
167
+		$sql_array = [
168
+			'SELECT'      => 'l.link_id, l.link_name, l.link_url, l.link_description, l.link_cat, l.link_user_id, l.link_guest_email, l.link_uid, l.link_bitfield, l.link_flags, l.link_banner, l.link_time, c.cat_name, u.user_id, u.username, u.user_colour',
169
+			'FROM'        => [
170
+				DIR_LINK_TABLE    => 'l', ],
171
+			'LEFT_JOIN'    => [
172
+				[
173
+					'FROM'    => [DIR_CAT_TABLE => 'c'],
174
+					'ON'      => 'c.cat_id = l.link_cat',
175
+				],
176
+				[
177
+					'FROM'    => [USERS_TABLE => 'u'],
178
+					'ON'      => 'u.user_id = l.link_user_id',
179
+				],
180
+			],
181
+			'WHERE'        => 'l.link_active = 0'.(($sql_where) ? " AND l.link_time >= $sql_where" : ''),
182
+			'ORDER_BY'     => $sql_sort_order, ];
183
+
184
+		$sql = $this->db->sql_build_query('SELECT', $sql_array);
185
+		$result = $this->db->sql_query_limit($sql, $per_page, $start);
186
+
187
+		while ($row = $this->db->sql_fetchrow($result)) {
188
+			$s_banner = $this->link->display_bann($row);
189
+
190
+			$username = ($row['link_user_id'] == ANONYMOUS) ? $row['link_guest_email'] : $row['username'];
191
+
192
+			$link_row = [
193
+				'LINK_URL'             => $row['link_url'],
194
+				'LINK_NAME'            => $row['link_name'],
195
+				'LINK_DESC'            => generate_text_for_display($row['link_description'], $row['link_uid'], $row['link_bitfield'], $row['link_flags']),
196
+				'L_DIR_USER_PROP'      => $this->user->lang('DIR_USER_PROP', get_username_string('full', $row['link_user_id'], $username, $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$this->php_ext", 'i=users&amp;mode=overview')), '<select name=c'.$row['link_id'].'>'.$this->categorie->make_cat_select((int) $row['link_cat']).'</select>', $this->user->format_date($row['link_time'])),
197
+				'BANNER'               => $s_banner,
198
+				'LINK_ID'              => $row['link_id'],
199
+
200
+			];
201
+			$this->template->assign_block_vars('linkrow', $link_row);
202
+		}
203
+		$this->db->sql_freeresult($result);
204
+
205
+		$option_ary = ['approved' => 'DIR_LINK_ACTIVATE', 'disapproved' => 'DIR_LINK_DELETE'];
206
+
207
+		$base_url = $this->u_action."&amp;$u_sort_param&amp;links_per_page=$per_page";
208
+		$this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_links, $per_page, $start);
209
+
210
+		$this->template->assign_vars([
211
+			'S_LINKS_OPTIONS'    => build_select($option_ary),
212
+
213
+			'S_LIMIT_DAYS'        => $s_limit_days,
214
+			'S_SORT_KEY'          => $s_sort_key,
215
+			'S_SORT_DIR'          => $s_sort_dir,
216
+			'LINKS_PER_PAGE'      => $per_page,
217
+
218
+			'U_ACTION'            => $this->u_action."&amp;$u_sort_param&amp;links_per_page=$per_page&amp;start=$start",
219
+		]);
220
+	}
221
+
222
+	/**
223
+	 * Get link's information and call appropriate action.
224
+	 *
225
+	 * @param array $mark Website selected for (dis)approval
226
+	 *
227
+	 * @return null
228
+	 */
229
+	public function exec_action($mark)
230
+	{
231
+		$this->_get_infos_links($mark);
232
+
233
+		switch ($this->action) {
234
+			case 'approved':
235
+				$this->_action_approved();
236
+				break;
237
+
238
+			case 'disapproved':
239
+				$this->_action_disapproved();
240
+				break;
241
+
242
+			default:
243
+				return;
244
+		}
245
+
246
+		$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_LINK_'.strtoupper($this->action), time(), [implode(', ', $this->affected_link_name)]);
247
+	}
248
+
249
+	/**
250
+	 * Notify users which had submitted their websites.
251
+	 *
252
+	 * @return null
253
+	 */
254
+	public function notifiy_submiters()
255
+	{
256
+		if (!class_exists('messenger')) {
257
+			include $this->root_path.'includes/functions_messenger.'.$this->php_ext;
258
+		}
259
+		$messenger = new \messenger(false);
260
+
261
+		foreach ($this->links_data as $row) {
262
+			$this->notification->mark_notifications_read('ernadoo.phpbbdirectory.notification.type.directory_website_in_queue', (int) $row['link_id'], false);
263
+
264
+			// New notification system can't send mail to an anonymous user with an email adress storage in another table than phpbb_users
265
+			if ($row['link_user_id'] == ANONYMOUS) {
266
+				$username = $email = $row['link_guest_email'];
267
+
268
+				$messenger->template('@ernadoo_phpbbdirectory/directory_website_'.$this->action, $row['user_lang']);
269
+				$messenger->to($email, $username);
270
+
271
+				$messenger->assign_vars([
272
+					'USERNAME'     => htmlspecialchars_decode($username),
273
+					'LINK_NAME'    => $row['link_name'],
274
+				]);
275
+
276
+				$messenger->send(NOTIFY_EMAIL);
277
+			} else {
278
+				$notification_data = [
279
+					'user_from'            => (int) $row['link_user_id'],
280
+					'link_id'              => (int) $row['link_id'],
281
+					'link_name'            => $row['link_name'],
282
+					'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $row['link_cat']),
283
+					'cat_id'               => (int) $row['link_cat'],
284
+				];
285
+
286
+				$this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_'.$this->action, $notification_data);
287
+			}
288
+		}
289
+	}
290
+
291
+	/**
292
+	 * Set page url.
293
+	 *
294
+	 * @param string $u_action Custom form action
295
+	 *
296
+	 * @return null
297
+	 */
298
+	public function set_page_url($u_action)
299
+	{
300
+		$this->u_action = $u_action;
301
+	}
302
+
303
+	/**
304
+	 * Approve action.
305
+	 *
306
+	 * @return null
307
+	 */
308
+	private function _action_approved()
309
+	{
310
+		foreach ($this->links_data as $row) {
311
+			$this->_notify_suscribers($row);
312
+
313
+			$sql_ary = [
314
+				'link_active'      => 1,
315
+				'link_time'        => time(),
316
+				'link_cat'         => (int) $row['link_cat'],
317
+			];
318
+
319
+			$sql = 'UPDATE '.DIR_LINK_TABLE.'
320 320
 							SET '.$this->db->sql_build_array('UPDATE', $sql_ary).'
321 321
 							WHERE link_id = '.(int) $row['link_id'];
322
-            $this->db->sql_query($sql);
323
-        }
322
+			$this->db->sql_query($sql);
323
+		}
324 324
 
325
-        foreach ($this->cat_data as $cat_id => $count) {
326
-            $sql = 'UPDATE '.DIR_CAT_TABLE.'
325
+		foreach ($this->cat_data as $cat_id => $count) {
326
+			$sql = 'UPDATE '.DIR_CAT_TABLE.'
327 327
 							SET cat_links = cat_links + '.$count.'
328 328
 							WHERE cat_id = '.(int) $cat_id;
329
-            $this->db->sql_query($sql);
330
-        }
331
-    }
332
-
333
-    /**
334
-     * Disapprove action.
335
-     *
336
-     * @return null
337
-     */
338
-    private function _action_disapproved()
339
-    {
340
-        foreach ($this->links_data as $row) {
341
-            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
342
-                $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
343
-
344
-                if (file_exists($banner_img)) {
345
-                    @unlink($banner_img);
346
-                }
347
-            }
348
-
349
-            $sql = 'DELETE FROM '.DIR_LINK_TABLE.' WHERE link_id = '.(int) $row['link_id'];
350
-            $this->db->sql_query($sql);
351
-        }
352
-    }
353
-
354
-    /**
355
-     * Get informations about links selected.
356
-     *
357
-     * @param	$mark Website selected for (dis)approval
358
-     *
359
-     * @return null
360
-     */
361
-    private function _get_infos_links($mark)
362
-    {
363
-        $sql_array = [
364
-            'SELECT'      => 'a.link_id, a.link_name, a.link_url, a.link_description, a.link_banner, a.link_user_id, a.link_guest_email, u.username, u.user_email, u.user_lang, u.user_notify_type, c.cat_id, c.cat_name',
365
-            'FROM'        => [
366
-                DIR_LINK_TABLE    => 'a', ],
367
-            'LEFT_JOIN'    => [
368
-                [
369
-                    'FROM'    => [USERS_TABLE => 'u'],
370
-                    'ON'      => 'u.user_id = a.link_user_id',
371
-                ],
372
-                [
373
-                    'FROM'    => [DIR_CAT_TABLE => 'c'],
374
-                    'ON'      => 'a.link_cat = c.cat_id',
375
-                ],
376
-            ],
377
-            'WHERE'        => $this->db->sql_in_set('a.link_id', $mark), ];
378
-
379
-        $sql = $this->db->sql_build_query('SELECT', $sql_array);
380
-        $result = $this->db->sql_query($sql);
381
-
382
-        while ($row = $this->db->sql_fetchrow($result)) {
383
-            $row['link_cat'] = $this->request->variable('c'.$row['link_id'], (int) $row['cat_id']);
384
-
385
-            $this->links_data[] = $row;
386
-
387
-            $this->affected_link_name[] = $row['link_name'];
388
-
389
-            $this->cat_data[$row['link_cat']] = isset($this->cat_data[$row['link_cat']]) ? $this->cat_data[$row['link_cat']] + 1 : 1;
390
-        }
391
-    }
392
-
393
-    /**
394
-     * Notify users which watch categories.
395
-     *
396
-     * @param	$row Informations about website
397
-     *
398
-     * @return null
399
-     */
400
-    private function _notify_suscribers($row)
401
-    {
402
-        $notification_data = [
403
-            'user_from'            => (int) $row['link_user_id'],
404
-            'link_id'              => (int) $row['link_id'],
405
-            'link_name'            => $row['link_name'],
406
-            'link_url'             => $row['link_url'],
407
-            'link_description'     => preg_replace('/(\[.*?\])(.*?)(\[\/.*?\])/si', '\\1', $row['link_description']),
408
-            'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $row['link_cat']),
409
-            'cat_id'               => (int) $row['link_cat'],
410
-        ];
411
-
412
-        $this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website', $notification_data);
413
-    }
329
+			$this->db->sql_query($sql);
330
+		}
331
+	}
332
+
333
+	/**
334
+	 * Disapprove action.
335
+	 *
336
+	 * @return null
337
+	 */
338
+	private function _action_disapproved()
339
+	{
340
+		foreach ($this->links_data as $row) {
341
+			if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
342
+				$banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
343
+
344
+				if (file_exists($banner_img)) {
345
+					@unlink($banner_img);
346
+				}
347
+			}
348
+
349
+			$sql = 'DELETE FROM '.DIR_LINK_TABLE.' WHERE link_id = '.(int) $row['link_id'];
350
+			$this->db->sql_query($sql);
351
+		}
352
+	}
353
+
354
+	/**
355
+	 * Get informations about links selected.
356
+	 *
357
+	 * @param	$mark Website selected for (dis)approval
358
+	 *
359
+	 * @return null
360
+	 */
361
+	private function _get_infos_links($mark)
362
+	{
363
+		$sql_array = [
364
+			'SELECT'      => 'a.link_id, a.link_name, a.link_url, a.link_description, a.link_banner, a.link_user_id, a.link_guest_email, u.username, u.user_email, u.user_lang, u.user_notify_type, c.cat_id, c.cat_name',
365
+			'FROM'        => [
366
+				DIR_LINK_TABLE    => 'a', ],
367
+			'LEFT_JOIN'    => [
368
+				[
369
+					'FROM'    => [USERS_TABLE => 'u'],
370
+					'ON'      => 'u.user_id = a.link_user_id',
371
+				],
372
+				[
373
+					'FROM'    => [DIR_CAT_TABLE => 'c'],
374
+					'ON'      => 'a.link_cat = c.cat_id',
375
+				],
376
+			],
377
+			'WHERE'        => $this->db->sql_in_set('a.link_id', $mark), ];
378
+
379
+		$sql = $this->db->sql_build_query('SELECT', $sql_array);
380
+		$result = $this->db->sql_query($sql);
381
+
382
+		while ($row = $this->db->sql_fetchrow($result)) {
383
+			$row['link_cat'] = $this->request->variable('c'.$row['link_id'], (int) $row['cat_id']);
384
+
385
+			$this->links_data[] = $row;
386
+
387
+			$this->affected_link_name[] = $row['link_name'];
388
+
389
+			$this->cat_data[$row['link_cat']] = isset($this->cat_data[$row['link_cat']]) ? $this->cat_data[$row['link_cat']] + 1 : 1;
390
+		}
391
+	}
392
+
393
+	/**
394
+	 * Notify users which watch categories.
395
+	 *
396
+	 * @param	$row Informations about website
397
+	 *
398
+	 * @return null
399
+	 */
400
+	private function _notify_suscribers($row)
401
+	{
402
+		$notification_data = [
403
+			'user_from'            => (int) $row['link_user_id'],
404
+			'link_id'              => (int) $row['link_id'],
405
+			'link_name'            => $row['link_name'],
406
+			'link_url'             => $row['link_url'],
407
+			'link_description'     => preg_replace('/(\[.*?\])(.*?)(\[\/.*?\])/si', '\\1', $row['link_description']),
408
+			'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $row['link_cat']),
409
+			'cat_id'               => (int) $row['link_cat'],
410
+		];
411
+
412
+		$this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website', $notification_data);
413
+	}
414 414
 }
Please login to merge, or discard this patch.
Braces   +30 added lines, -14 removed lines patch added patch discarded remove patch
@@ -147,9 +147,12 @@  discard block
 block discarded – undo
147 147
         $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
148 148
         $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
149 149
 
150
-        if (is_array($sort_by_sql[$sort_key])) {
150
+        if (is_array($sort_by_sql[$sort_key]))
151
+        {
151 152
             $sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
152
-        } else {
153
+        }
154
+        else
155
+        {
153 156
             $sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
154 157
         }
155 158
 
@@ -184,7 +187,8 @@  discard block
 block discarded – undo
184 187
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
185 188
         $result = $this->db->sql_query_limit($sql, $per_page, $start);
186 189
 
187
-        while ($row = $this->db->sql_fetchrow($result)) {
190
+        while ($row = $this->db->sql_fetchrow($result))
191
+        {
188 192
             $s_banner = $this->link->display_bann($row);
189 193
 
190 194
             $username = ($row['link_user_id'] == ANONYMOUS) ? $row['link_guest_email'] : $row['username'];
@@ -230,7 +234,8 @@  discard block
 block discarded – undo
230 234
     {
231 235
         $this->_get_infos_links($mark);
232 236
 
233
-        switch ($this->action) {
237
+        switch ($this->action)
238
+        {
234 239
             case 'approved':
235 240
                 $this->_action_approved();
236 241
                 break;
@@ -253,16 +258,19 @@  discard block
 block discarded – undo
253 258
      */
254 259
     public function notifiy_submiters()
255 260
     {
256
-        if (!class_exists('messenger')) {
261
+        if (!class_exists('messenger'))
262
+        {
257 263
             include $this->root_path.'includes/functions_messenger.'.$this->php_ext;
258 264
         }
259 265
         $messenger = new \messenger(false);
260 266
 
261
-        foreach ($this->links_data as $row) {
267
+        foreach ($this->links_data as $row)
268
+        {
262 269
             $this->notification->mark_notifications_read('ernadoo.phpbbdirectory.notification.type.directory_website_in_queue', (int) $row['link_id'], false);
263 270
 
264 271
             // New notification system can't send mail to an anonymous user with an email adress storage in another table than phpbb_users
265
-            if ($row['link_user_id'] == ANONYMOUS) {
272
+            if ($row['link_user_id'] == ANONYMOUS)
273
+            {
266 274
                 $username = $email = $row['link_guest_email'];
267 275
 
268 276
                 $messenger->template('@ernadoo_phpbbdirectory/directory_website_'.$this->action, $row['user_lang']);
@@ -274,7 +282,9 @@  discard block
 block discarded – undo
274 282
                 ]);
275 283
 
276 284
                 $messenger->send(NOTIFY_EMAIL);
277
-            } else {
285
+            }
286
+            else
287
+            {
278 288
                 $notification_data = [
279 289
                     'user_from'            => (int) $row['link_user_id'],
280 290
                     'link_id'              => (int) $row['link_id'],
@@ -307,7 +317,8 @@  discard block
 block discarded – undo
307 317
      */
308 318
     private function _action_approved()
309 319
     {
310
-        foreach ($this->links_data as $row) {
320
+        foreach ($this->links_data as $row)
321
+        {
311 322
             $this->_notify_suscribers($row);
312 323
 
313 324
             $sql_ary = [
@@ -322,7 +333,8 @@  discard block
 block discarded – undo
322 333
             $this->db->sql_query($sql);
323 334
         }
324 335
 
325
-        foreach ($this->cat_data as $cat_id => $count) {
336
+        foreach ($this->cat_data as $cat_id => $count)
337
+        {
326 338
             $sql = 'UPDATE '.DIR_CAT_TABLE.'
327 339
 							SET cat_links = cat_links + '.$count.'
328 340
 							WHERE cat_id = '.(int) $cat_id;
@@ -337,11 +349,14 @@  discard block
 block discarded – undo
337 349
      */
338 350
     private function _action_disapproved()
339 351
     {
340
-        foreach ($this->links_data as $row) {
341
-            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
352
+        foreach ($this->links_data as $row)
353
+        {
354
+            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner']))
355
+            {
342 356
                 $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
343 357
 
344
-                if (file_exists($banner_img)) {
358
+                if (file_exists($banner_img))
359
+                {
345 360
                     @unlink($banner_img);
346 361
                 }
347 362
             }
@@ -379,7 +394,8 @@  discard block
 block discarded – undo
379 394
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
380 395
         $result = $this->db->sql_query($sql);
381 396
 
382
-        while ($row = $this->db->sql_fetchrow($result)) {
397
+        while ($row = $this->db->sql_fetchrow($result))
398
+        {
383 399
             $row['link_cat'] = $this->request->variable('c'.$row['link_id'], (int) $row['cat_id']);
384 400
 
385 401
             $this->links_data[] = $row;
Please login to merge, or discard this patch.
controller/search.php 2 patches
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -9,330 +9,330 @@
 block discarded – undo
9 9
 
10 10
 class search
11 11
 {
12
-    /** @var \phpbb\db\driver\driver_interface */
13
-    protected $db;
14
-
15
-    /** @var \phpbb\config\config */
16
-    protected $config;
17
-
18
-    /** @var \phpbb\template\template */
19
-    protected $template;
20
-
21
-    /** @var \phpbb\user */
22
-    protected $user;
23
-
24
-    /** @var \phpbb\controller\helper */
25
-    protected $helper;
26
-
27
-    /** @var \phpbb\request\request */
28
-    protected $request;
29
-
30
-    /** @var \phpbb\auth\auth */
31
-    protected $auth;
32
-
33
-    /** @var \phpbb\pagination */
34
-    protected $pagination;
35
-
36
-    /** @var \ernadoo\phpbbdirectory\search\fulltext_directory */
37
-    protected $search;
38
-
39
-    /** @var \ernadoo\phpbbdirectory\core\categorie */
40
-    protected $categorie;
41
-
42
-    /** @var \ernadoo\phpbbdirectory\core\link */
43
-    protected $link;
44
-
45
-    /**
46
-     * Constructor.
47
-     *
48
-     * @param \phpbb\db\driver\driver_interface                 $db         Database object
49
-     * @param \phpbb\config\config                              $config     Config object
50
-     * @param \phpbb\template\template                          $template   Template object
51
-     * @param \phpbb\user                                       $user       User object
52
-     * @param \phpbb\controller\helper                          $helper     Controller helper object
53
-     * @param \phpbb\request\request                            $request    Request object
54
-     * @param \phpbb\auth\auth                                  $auth       Auth object
55
-     * @param \phpbb\pagination                                 $pagination Pagination object
56
-     * @param \ernadoo\phpbbdirectory\search\fulltext_directory $search     PhpBB Directory extension search object
57
-     * @param \ernadoo\phpbbdirectory\core\categorie            $categorie  PhpBB Directory extension categorie object
58
-     * @param \ernadoo\phpbbdirectory\core\link                 $link       PhpBB Directory extension link object
59
-     */
60
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \ernadoo\phpbbdirectory\search\fulltext_directory $search, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link)
61
-    {
62
-        $this->db = $db;
63
-        $this->config = $config;
64
-        $this->template = $template;
65
-        $this->user = $user;
66
-        $this->helper = $helper;
67
-        $this->request = $request;
68
-        $this->auth = $auth;
69
-        $this->pagination = $pagination;
70
-        $this->search = $search;
71
-        $this->categorie = $categorie;
72
-        $this->link = $link;
73
-
74
-        $this->user->add_lang_ext('ernadoo/phpbbdirectory', ['directory']);
75
-        $this->user->add_lang('search');
76
-
77
-        $this->template->assign_vars([
78
-            'S_PHPBB_DIRECTORY'                => true,
79
-            'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
80
-        ]);
81
-    }
82
-
83
-    /**
84
-     * Search controller.
85
-     *
86
-     * @param int $page Page number taken from the URL
87
-     *
88
-     * @throws \phpbb\exception\http_exception
89
-     *
90
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
91
-     */
92
-    public function main($page)
93
-    {
94
-        if (!$this->auth->acl_get('u_search_dir')) {
95
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
96
-        }
97
-
98
-        $cat_id = $this->request->variable('cat_id', 0);
99
-        $keywords = $this->request->variable('keywords', '', true);
100
-        $search_terms = $this->request->variable('terms', 'all');
101
-        $search_category = $this->request->variable('cid', [0]);
102
-        $search_fields = $this->request->variable('sf', 'all');
103
-        $search_child = $this->request->variable('sc', true);
104
-        $sort_days = $this->request->variable('st', 0);
105
-        $sort_key = $this->request->variable('sk', 't');
106
-        $sort_dir = $this->request->variable('sd', 'd');
107
-        $start = ($page - 1) * (int) $this->config['dir_show'];
108
-
109
-        $default_sort_days = 0;
110
-        $default_sort_key = (string) substr($this->config['dir_default_order'], 0, 1);
111
-        $default_sort_dir = (string) substr($this->config['dir_default_order'], 2);
112
-
113
-        // Categorie ordering options
114
-        $limit_days = [0 => $this->user->lang['ALL_RESULTS'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']];
115
-        $sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' =>  $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']];
116
-        $sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id'], 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'];
117
-
118
-        if ($this->config['dir_activ_pagerank']) {
119
-            $sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
120
-            $sort_by_sql['p'] = 'l.link_pagerank';
121
-        }
122
-
123
-        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
124
-        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
125
-
126
-        $u_sort_param = ($sort_days === $default_sort_days && $sort_key == $default_sort_key && $sort_dir == $default_sort_dir) ? [] : ['sort_days' => $sort_days, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir];
127
-
128
-        /*
12
+	/** @var \phpbb\db\driver\driver_interface */
13
+	protected $db;
14
+
15
+	/** @var \phpbb\config\config */
16
+	protected $config;
17
+
18
+	/** @var \phpbb\template\template */
19
+	protected $template;
20
+
21
+	/** @var \phpbb\user */
22
+	protected $user;
23
+
24
+	/** @var \phpbb\controller\helper */
25
+	protected $helper;
26
+
27
+	/** @var \phpbb\request\request */
28
+	protected $request;
29
+
30
+	/** @var \phpbb\auth\auth */
31
+	protected $auth;
32
+
33
+	/** @var \phpbb\pagination */
34
+	protected $pagination;
35
+
36
+	/** @var \ernadoo\phpbbdirectory\search\fulltext_directory */
37
+	protected $search;
38
+
39
+	/** @var \ernadoo\phpbbdirectory\core\categorie */
40
+	protected $categorie;
41
+
42
+	/** @var \ernadoo\phpbbdirectory\core\link */
43
+	protected $link;
44
+
45
+	/**
46
+	 * Constructor.
47
+	 *
48
+	 * @param \phpbb\db\driver\driver_interface                 $db         Database object
49
+	 * @param \phpbb\config\config                              $config     Config object
50
+	 * @param \phpbb\template\template                          $template   Template object
51
+	 * @param \phpbb\user                                       $user       User object
52
+	 * @param \phpbb\controller\helper                          $helper     Controller helper object
53
+	 * @param \phpbb\request\request                            $request    Request object
54
+	 * @param \phpbb\auth\auth                                  $auth       Auth object
55
+	 * @param \phpbb\pagination                                 $pagination Pagination object
56
+	 * @param \ernadoo\phpbbdirectory\search\fulltext_directory $search     PhpBB Directory extension search object
57
+	 * @param \ernadoo\phpbbdirectory\core\categorie            $categorie  PhpBB Directory extension categorie object
58
+	 * @param \ernadoo\phpbbdirectory\core\link                 $link       PhpBB Directory extension link object
59
+	 */
60
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \ernadoo\phpbbdirectory\search\fulltext_directory $search, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link)
61
+	{
62
+		$this->db = $db;
63
+		$this->config = $config;
64
+		$this->template = $template;
65
+		$this->user = $user;
66
+		$this->helper = $helper;
67
+		$this->request = $request;
68
+		$this->auth = $auth;
69
+		$this->pagination = $pagination;
70
+		$this->search = $search;
71
+		$this->categorie = $categorie;
72
+		$this->link = $link;
73
+
74
+		$this->user->add_lang_ext('ernadoo/phpbbdirectory', ['directory']);
75
+		$this->user->add_lang('search');
76
+
77
+		$this->template->assign_vars([
78
+			'S_PHPBB_DIRECTORY'                => true,
79
+			'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
80
+		]);
81
+	}
82
+
83
+	/**
84
+	 * Search controller.
85
+	 *
86
+	 * @param int $page Page number taken from the URL
87
+	 *
88
+	 * @throws \phpbb\exception\http_exception
89
+	 *
90
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
91
+	 */
92
+	public function main($page)
93
+	{
94
+		if (!$this->auth->acl_get('u_search_dir')) {
95
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
96
+		}
97
+
98
+		$cat_id = $this->request->variable('cat_id', 0);
99
+		$keywords = $this->request->variable('keywords', '', true);
100
+		$search_terms = $this->request->variable('terms', 'all');
101
+		$search_category = $this->request->variable('cid', [0]);
102
+		$search_fields = $this->request->variable('sf', 'all');
103
+		$search_child = $this->request->variable('sc', true);
104
+		$sort_days = $this->request->variable('st', 0);
105
+		$sort_key = $this->request->variable('sk', 't');
106
+		$sort_dir = $this->request->variable('sd', 'd');
107
+		$start = ($page - 1) * (int) $this->config['dir_show'];
108
+
109
+		$default_sort_days = 0;
110
+		$default_sort_key = (string) substr($this->config['dir_default_order'], 0, 1);
111
+		$default_sort_dir = (string) substr($this->config['dir_default_order'], 2);
112
+
113
+		// Categorie ordering options
114
+		$limit_days = [0 => $this->user->lang['ALL_RESULTS'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']];
115
+		$sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' =>  $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']];
116
+		$sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id'], 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'];
117
+
118
+		if ($this->config['dir_activ_pagerank']) {
119
+			$sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
120
+			$sort_by_sql['p'] = 'l.link_pagerank';
121
+		}
122
+
123
+		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
124
+		gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
125
+
126
+		$u_sort_param = ($sort_days === $default_sort_days && $sort_key == $default_sort_key && $sort_dir == $default_sort_dir) ? [] : ['sort_days' => $sort_days, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir];
127
+
128
+		/*
129 129
         ** search form submited
130 130
         */
131
-        if ($this->request->is_set_post('submit') || $keywords) {
132
-            // clear arrays
133
-            $id_ary = $u_search = [];
134
-            $keywords_ary = ($keywords) ? explode(' ', $keywords) : [];
135
-
136
-            if (!count($keywords_ary)) {
137
-                return $this->helper->message('DIR_ERROR_KEYWORD');
138
-            }
139
-
140
-            $ex_cid_ary = $this->_get_exclude_categories($search_category, $search_child);
141
-
142
-            $total_match_count = $this->search->keyword_search($keywords_ary, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_cid_ary, $cat_id, $id_ary, $start, $this->config['dir_show']);
143
-
144
-            $l_search_matches = $this->user->lang('FOUND_SEARCH_MATCHES', (int) $total_match_count);
145
-
146
-            if (count($id_ary)) {
147
-                $sql_where = $this->db->sql_in_set('l.link_id', $id_ary);
148
-            } else {
149
-                return $this->helper->message('DIR_SEARCH_NO_RESULT');
150
-            }
151
-
152
-            // A single wildcard will make the search results look ugly
153
-            $hilit = phpbb_clean_search_string(str_replace(['+', '-', '|', '(', ')', '&quot;'], ' ', $keywords));
154
-            $hilit = str_replace(' ', '|', $hilit);
155
-
156
-            $u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
157
-
158
-            ($u_hilit) ? $u_search['keywords'] = urlencode(htmlspecialchars_decode($keywords)) : '';
159
-            ($search_terms != 'all') ? $u_search['terms'] = $search_terms : '';
160
-            ($cat_id) ? $u_search['cat_id'] = $cat_id : '';
161
-            ($search_category) ? $u_search['cid'] = $search_category : '';
162
-            (!$search_child) ? $u_search['sc'] = 0 : '';
163
-            ($search_fields != 'all') ? $u_search['sf'] = $search_fields : '';
164
-
165
-            $base_url = [
166
-                'routes'    => 'ernadoo_phpbbdirectory_search_controller',
167
-                'params'    => array_merge($u_search, $u_sort_param),
168
-            ];
169
-
170
-            $u_search = $this->helper->route('ernadoo_phpbbdirectory_search_controller', array_merge($u_search, $u_sort_param));
171
-
172
-            $this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $total_match_count, $this->config['dir_show'], $start);
173
-
174
-            $this->template->assign_vars([
175
-                'SEARCH_MATCHES'      => $l_search_matches,
176
-                'SEARCH_WORDS'        => $keywords,
177
-
178
-                'TOTAL_MATCHES'        => $total_match_count,
179
-
180
-                'S_SELECT_SORT_DIR'        => $s_sort_dir,
181
-                'S_SELECT_SORT_KEY'        => $s_sort_key,
182
-                'S_SELECT_SORT_DAYS'       => $s_limit_days,
183
-                'S_SEARCH_ACTION'          => $u_search,
184
-
185
-                'U_DIR_SEARCH'            => $this->helper->route('ernadoo_phpbbdirectory_search_controller'),
186
-                'U_SEARCH_WORDS'          => $u_search,
187
-            ]);
188
-
189
-            if ($cat_id) {
190
-                $this->template->assign_vars([
191
-                    'SEARCH_CATEGORY'      => $this->user->lang('RETURN_TO', \ernadoo\phpbbdirectory\core\categorie::getname((int) $cat_id)),
192
-                    'U_SEARCH_CATEGORY'    => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]),
193
-                ]);
194
-            }
195
-
196
-            if ($sql_where) {
197
-                $sql_array = [
198
-                    'SELECT'      => 'l.link_name, l.link_description, l.link_url, l.link_uid, l.link_bitfield, l.link_flags, l.link_view, l.link_user_id, l.link_time, l.link_comment, l.link_flag, l.link_id, l.link_thumb, l.link_banner, c.cat_name, u.user_id, u.username, u.user_colour',
199
-                    'FROM'        => [
200
-                            DIR_LINK_TABLE    => 'l', ],
201
-                    'LEFT_JOIN'    => [
202
-                            [
203
-                                'FROM'    => [DIR_CAT_TABLE => 'c'],
204
-                                'ON'      => 'l.link_cat = c.cat_id',
205
-                            ],
206
-                            [
207
-                                'FROM'    => [USERS_TABLE => 'u'],
208
-                                'ON'      => 'u.user_id = l.link_user_id',
209
-                            ],
210
-                    ],
211
-                    'WHERE'        => $sql_where, ];
212
-
213
-                $sql = $this->db->sql_build_query('SELECT', $sql_array);
214
-                $result = $this->db->sql_query($sql);
215
-
216
-                $rowset = $this->db->sql_fetchrowset($result);
217
-
218
-                if (count($rowset)) {
219
-                    if ($hilit) {
220
-                        // Remove bad highlights
221
-                        $hilit_array = array_filter(explode('|', $hilit), 'strlen');
222
-                        foreach ($hilit_array as $key => $value) {
223
-                            $hilit_array[$key] = phpbb_clean_search_string($value);
224
-                            $hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($hilit_array[$key], '#'));
225
-                            $hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
226
-                        }
227
-                        $hilit = implode('|', $hilit_array);
228
-                    }
229
-
230
-                    foreach ($rowset as $data) {
231
-                        $s_banner = $this->link->display_bann($data);
232
-                        $s_thumb = $this->link->display_thumb($data);
233
-                        $s_flag = $this->link->display_flag($data);
234
-
235
-                        $data['link_description'] = generate_text_for_display($data['link_description'], $data['link_uid'], $data['link_bitfield'], $data['link_flags']);
236
-
237
-                        if ($hilit) {
238
-                            $data['link_name'] = preg_replace('#(?!<.*)(?<!\w)('.$hilit.')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $data['link_name']);
239
-                            $data['link_description'] = preg_replace('#(?!<.*)(?<!\w)('.$hilit.')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $data['link_description']);
240
-                        }
241
-
242
-                        $this->template->assign_block_vars('results', [
243
-                            'S_SITE'           => $data['link_name'],
244
-                            'S_DESCRIPTION'    => $data['link_description'],
245
-                            'S_COUNT'          => $data['link_view'],
246
-                            'S_CAT'            => $data['cat_name'],
247
-                            'S_USER'           => get_username_string('full', $data['link_user_id'], $data['username'], $data['user_colour']),
248
-                            'S_TIME'           => ($data['link_time'] != 0) ? $this->user->format_date($data['link_time']) : '',
249
-                            'S_COMMENT'        => $data['link_comment'],
250
-
251
-                            'THUMB'            => '<img src="'.$s_thumb.'" alt="'.$this->user->lang['DIR_THUMB'].'" title="'.$data['link_name'].'"/>',
252
-                            'IMG_BANNER'       => $s_banner,
253
-                            'IMG_FLAG'         => $s_flag,
254
-                            'ON_CLICK'         => "onclick=\"window.open('".$this->helper->route('ernadoo_phpbbdirectory_view_controller', ['link_id' => (int) $data['link_id']])."'); return false;\"",
255
-
256
-                            'L_DIR_SEARCH_NB_CLICKS'       => $this->user->lang('DIR_SEARCH_NB_CLICKS', (int) $data['link_view']),
257
-                            'L_DIR_SEARCH_NB_COMMS'        => $this->user->lang('DIR_SEARCH_NB_COMMS', (int) $data['link_comment']),
258
-
259
-                            'U_COMMENT'        => $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $data['link_id']]),
260
-                            'U_SITE'           => $data['link_url'],
261
-                            'LINK_ID'          => $data['link_id'],
262
-                        ]);
263
-
264
-                        if ($s_banner) {
265
-                            $this->template->assign_block_vars('results.banner', []);
266
-                        }
267
-
268
-                        if ($this->config['dir_activ_flag']) {
269
-                            $this->template->assign_block_vars('results.switch_dir_flag', []);
270
-                        }
271
-                    }
272
-                    unset($rowset);
273
-
274
-                    return $this->helper->render('search_results.html', $this->user->lang['DIR_MAKE_SEARCH']);
275
-                }
276
-            }
277
-        }
278
-
279
-        $s_catlist = $this->categorie->make_cat_select();
280
-
281
-        if (!$s_catlist) {
282
-            return $this->helper->message('NO_SEARCH');
283
-        }
284
-
285
-        $this->template->assign_vars([
286
-            'S_POST_ACTION'            => build_url(true),
287
-            'S_KEYWORD'                => $keywords,
288
-            'S_CATLIST'                => $s_catlist,
289
-            'S_SELECT_SORT_DIR'        => $s_sort_dir,
290
-            'S_SELECT_SORT_KEY'        => $s_sort_key,
291
-            'S_SELECT_SORT_DAYS'       => $s_limit_days,
292
-        ]);
293
-
294
-        return $this->helper->render('search_body.html', $this->user->lang['DIR_MAKE_SEARCH']);
295
-    }
296
-
297
-    /**
298
-     * @param array $search_category
299
-     * @param bool  $search_child
300
-     *
301
-     * @return array Categories to exclude from search
302
-     */
303
-    private function _get_exclude_categories(&$search_category, $search_child)
304
-    {
305
-        $sql = 'SELECT cat_id, parent_id, right_id
131
+		if ($this->request->is_set_post('submit') || $keywords) {
132
+			// clear arrays
133
+			$id_ary = $u_search = [];
134
+			$keywords_ary = ($keywords) ? explode(' ', $keywords) : [];
135
+
136
+			if (!count($keywords_ary)) {
137
+				return $this->helper->message('DIR_ERROR_KEYWORD');
138
+			}
139
+
140
+			$ex_cid_ary = $this->_get_exclude_categories($search_category, $search_child);
141
+
142
+			$total_match_count = $this->search->keyword_search($keywords_ary, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_cid_ary, $cat_id, $id_ary, $start, $this->config['dir_show']);
143
+
144
+			$l_search_matches = $this->user->lang('FOUND_SEARCH_MATCHES', (int) $total_match_count);
145
+
146
+			if (count($id_ary)) {
147
+				$sql_where = $this->db->sql_in_set('l.link_id', $id_ary);
148
+			} else {
149
+				return $this->helper->message('DIR_SEARCH_NO_RESULT');
150
+			}
151
+
152
+			// A single wildcard will make the search results look ugly
153
+			$hilit = phpbb_clean_search_string(str_replace(['+', '-', '|', '(', ')', '&quot;'], ' ', $keywords));
154
+			$hilit = str_replace(' ', '|', $hilit);
155
+
156
+			$u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
157
+
158
+			($u_hilit) ? $u_search['keywords'] = urlencode(htmlspecialchars_decode($keywords)) : '';
159
+			($search_terms != 'all') ? $u_search['terms'] = $search_terms : '';
160
+			($cat_id) ? $u_search['cat_id'] = $cat_id : '';
161
+			($search_category) ? $u_search['cid'] = $search_category : '';
162
+			(!$search_child) ? $u_search['sc'] = 0 : '';
163
+			($search_fields != 'all') ? $u_search['sf'] = $search_fields : '';
164
+
165
+			$base_url = [
166
+				'routes'    => 'ernadoo_phpbbdirectory_search_controller',
167
+				'params'    => array_merge($u_search, $u_sort_param),
168
+			];
169
+
170
+			$u_search = $this->helper->route('ernadoo_phpbbdirectory_search_controller', array_merge($u_search, $u_sort_param));
171
+
172
+			$this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $total_match_count, $this->config['dir_show'], $start);
173
+
174
+			$this->template->assign_vars([
175
+				'SEARCH_MATCHES'      => $l_search_matches,
176
+				'SEARCH_WORDS'        => $keywords,
177
+
178
+				'TOTAL_MATCHES'        => $total_match_count,
179
+
180
+				'S_SELECT_SORT_DIR'        => $s_sort_dir,
181
+				'S_SELECT_SORT_KEY'        => $s_sort_key,
182
+				'S_SELECT_SORT_DAYS'       => $s_limit_days,
183
+				'S_SEARCH_ACTION'          => $u_search,
184
+
185
+				'U_DIR_SEARCH'            => $this->helper->route('ernadoo_phpbbdirectory_search_controller'),
186
+				'U_SEARCH_WORDS'          => $u_search,
187
+			]);
188
+
189
+			if ($cat_id) {
190
+				$this->template->assign_vars([
191
+					'SEARCH_CATEGORY'      => $this->user->lang('RETURN_TO', \ernadoo\phpbbdirectory\core\categorie::getname((int) $cat_id)),
192
+					'U_SEARCH_CATEGORY'    => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]),
193
+				]);
194
+			}
195
+
196
+			if ($sql_where) {
197
+				$sql_array = [
198
+					'SELECT'      => 'l.link_name, l.link_description, l.link_url, l.link_uid, l.link_bitfield, l.link_flags, l.link_view, l.link_user_id, l.link_time, l.link_comment, l.link_flag, l.link_id, l.link_thumb, l.link_banner, c.cat_name, u.user_id, u.username, u.user_colour',
199
+					'FROM'        => [
200
+							DIR_LINK_TABLE    => 'l', ],
201
+					'LEFT_JOIN'    => [
202
+							[
203
+								'FROM'    => [DIR_CAT_TABLE => 'c'],
204
+								'ON'      => 'l.link_cat = c.cat_id',
205
+							],
206
+							[
207
+								'FROM'    => [USERS_TABLE => 'u'],
208
+								'ON'      => 'u.user_id = l.link_user_id',
209
+							],
210
+					],
211
+					'WHERE'        => $sql_where, ];
212
+
213
+				$sql = $this->db->sql_build_query('SELECT', $sql_array);
214
+				$result = $this->db->sql_query($sql);
215
+
216
+				$rowset = $this->db->sql_fetchrowset($result);
217
+
218
+				if (count($rowset)) {
219
+					if ($hilit) {
220
+						// Remove bad highlights
221
+						$hilit_array = array_filter(explode('|', $hilit), 'strlen');
222
+						foreach ($hilit_array as $key => $value) {
223
+							$hilit_array[$key] = phpbb_clean_search_string($value);
224
+							$hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($hilit_array[$key], '#'));
225
+							$hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
226
+						}
227
+						$hilit = implode('|', $hilit_array);
228
+					}
229
+
230
+					foreach ($rowset as $data) {
231
+						$s_banner = $this->link->display_bann($data);
232
+						$s_thumb = $this->link->display_thumb($data);
233
+						$s_flag = $this->link->display_flag($data);
234
+
235
+						$data['link_description'] = generate_text_for_display($data['link_description'], $data['link_uid'], $data['link_bitfield'], $data['link_flags']);
236
+
237
+						if ($hilit) {
238
+							$data['link_name'] = preg_replace('#(?!<.*)(?<!\w)('.$hilit.')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $data['link_name']);
239
+							$data['link_description'] = preg_replace('#(?!<.*)(?<!\w)('.$hilit.')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $data['link_description']);
240
+						}
241
+
242
+						$this->template->assign_block_vars('results', [
243
+							'S_SITE'           => $data['link_name'],
244
+							'S_DESCRIPTION'    => $data['link_description'],
245
+							'S_COUNT'          => $data['link_view'],
246
+							'S_CAT'            => $data['cat_name'],
247
+							'S_USER'           => get_username_string('full', $data['link_user_id'], $data['username'], $data['user_colour']),
248
+							'S_TIME'           => ($data['link_time'] != 0) ? $this->user->format_date($data['link_time']) : '',
249
+							'S_COMMENT'        => $data['link_comment'],
250
+
251
+							'THUMB'            => '<img src="'.$s_thumb.'" alt="'.$this->user->lang['DIR_THUMB'].'" title="'.$data['link_name'].'"/>',
252
+							'IMG_BANNER'       => $s_banner,
253
+							'IMG_FLAG'         => $s_flag,
254
+							'ON_CLICK'         => "onclick=\"window.open('".$this->helper->route('ernadoo_phpbbdirectory_view_controller', ['link_id' => (int) $data['link_id']])."'); return false;\"",
255
+
256
+							'L_DIR_SEARCH_NB_CLICKS'       => $this->user->lang('DIR_SEARCH_NB_CLICKS', (int) $data['link_view']),
257
+							'L_DIR_SEARCH_NB_COMMS'        => $this->user->lang('DIR_SEARCH_NB_COMMS', (int) $data['link_comment']),
258
+
259
+							'U_COMMENT'        => $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $data['link_id']]),
260
+							'U_SITE'           => $data['link_url'],
261
+							'LINK_ID'          => $data['link_id'],
262
+						]);
263
+
264
+						if ($s_banner) {
265
+							$this->template->assign_block_vars('results.banner', []);
266
+						}
267
+
268
+						if ($this->config['dir_activ_flag']) {
269
+							$this->template->assign_block_vars('results.switch_dir_flag', []);
270
+						}
271
+					}
272
+					unset($rowset);
273
+
274
+					return $this->helper->render('search_results.html', $this->user->lang['DIR_MAKE_SEARCH']);
275
+				}
276
+			}
277
+		}
278
+
279
+		$s_catlist = $this->categorie->make_cat_select();
280
+
281
+		if (!$s_catlist) {
282
+			return $this->helper->message('NO_SEARCH');
283
+		}
284
+
285
+		$this->template->assign_vars([
286
+			'S_POST_ACTION'            => build_url(true),
287
+			'S_KEYWORD'                => $keywords,
288
+			'S_CATLIST'                => $s_catlist,
289
+			'S_SELECT_SORT_DIR'        => $s_sort_dir,
290
+			'S_SELECT_SORT_KEY'        => $s_sort_key,
291
+			'S_SELECT_SORT_DAYS'       => $s_limit_days,
292
+		]);
293
+
294
+		return $this->helper->render('search_body.html', $this->user->lang['DIR_MAKE_SEARCH']);
295
+	}
296
+
297
+	/**
298
+	 * @param array $search_category
299
+	 * @param bool  $search_child
300
+	 *
301
+	 * @return array Categories to exclude from search
302
+	 */
303
+	private function _get_exclude_categories(&$search_category, $search_child)
304
+	{
305
+		$sql = 'SELECT cat_id, parent_id, right_id
306 306
 				FROM '.DIR_CAT_TABLE.'
307 307
 				ORDER BY left_id';
308
-        $result = $this->db->sql_query($sql);
309
-
310
-        $right_id = 0;
311
-        $reset_search_category = true;
312
-        $ex_cid_ary = [];
313
-
314
-        while ($row = $this->db->sql_fetchrow($result)) {
315
-            if (count($search_category)) {
316
-                if ($search_child) {
317
-                    if (in_array($row['cat_id'], $search_category) && $row['right_id'] > $right_id) {
318
-                        $right_id = (int) $row['right_id'];
319
-                    } elseif ($row['right_id'] < $right_id) {
320
-                        continue;
321
-                    }
322
-                }
323
-
324
-                if (!in_array($row['cat_id'], $search_category)) {
325
-                    $ex_cid_ary[] = (int) $row['cat_id'];
326
-                    $reset_search_category = false;
327
-                }
328
-            }
329
-        }
330
-        $this->db->sql_freeresult($result);
331
-
332
-        if ($reset_search_category) {
333
-            $search_category = [];
334
-        }
335
-
336
-        return $ex_cid_ary;
337
-    }
308
+		$result = $this->db->sql_query($sql);
309
+
310
+		$right_id = 0;
311
+		$reset_search_category = true;
312
+		$ex_cid_ary = [];
313
+
314
+		while ($row = $this->db->sql_fetchrow($result)) {
315
+			if (count($search_category)) {
316
+				if ($search_child) {
317
+					if (in_array($row['cat_id'], $search_category) && $row['right_id'] > $right_id) {
318
+						$right_id = (int) $row['right_id'];
319
+					} elseif ($row['right_id'] < $right_id) {
320
+						continue;
321
+					}
322
+				}
323
+
324
+				if (!in_array($row['cat_id'], $search_category)) {
325
+					$ex_cid_ary[] = (int) $row['cat_id'];
326
+					$reset_search_category = false;
327
+				}
328
+			}
329
+		}
330
+		$this->db->sql_freeresult($result);
331
+
332
+		if ($reset_search_category) {
333
+			$search_category = [];
334
+		}
335
+
336
+		return $ex_cid_ary;
337
+	}
338 338
 }
Please login to merge, or discard this patch.
Braces   +48 added lines, -23 removed lines patch added patch discarded remove patch
@@ -91,7 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function main($page)
93 93
     {
94
-        if (!$this->auth->acl_get('u_search_dir')) {
94
+        if (!$this->auth->acl_get('u_search_dir'))
95
+        {
95 96
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
96 97
         }
97 98
 
@@ -115,7 +116,8 @@  discard block
 block discarded – undo
115 116
         $sort_by_text = ['a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' =>  $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']];
116 117
         $sort_by_sql = ['a' => 'u.username_clean', 't' => ['l.link_time', 'l.link_id'], 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'];
117 118
 
118
-        if ($this->config['dir_activ_pagerank']) {
119
+        if ($this->config['dir_activ_pagerank'])
120
+        {
119 121
             $sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
120 122
             $sort_by_sql['p'] = 'l.link_pagerank';
121 123
         }
@@ -128,12 +130,14 @@  discard block
 block discarded – undo
128 130
         /*
129 131
         ** search form submited
130 132
         */
131
-        if ($this->request->is_set_post('submit') || $keywords) {
133
+        if ($this->request->is_set_post('submit') || $keywords)
134
+        {
132 135
             // clear arrays
133 136
             $id_ary = $u_search = [];
134 137
             $keywords_ary = ($keywords) ? explode(' ', $keywords) : [];
135 138
 
136
-            if (!count($keywords_ary)) {
139
+            if (!count($keywords_ary))
140
+            {
137 141
                 return $this->helper->message('DIR_ERROR_KEYWORD');
138 142
             }
139 143
 
@@ -143,9 +147,12 @@  discard block
 block discarded – undo
143 147
 
144 148
             $l_search_matches = $this->user->lang('FOUND_SEARCH_MATCHES', (int) $total_match_count);
145 149
 
146
-            if (count($id_ary)) {
150
+            if (count($id_ary))
151
+            {
147 152
                 $sql_where = $this->db->sql_in_set('l.link_id', $id_ary);
148
-            } else {
153
+            }
154
+            else
155
+            {
149 156
                 return $this->helper->message('DIR_SEARCH_NO_RESULT');
150 157
             }
151 158
 
@@ -186,14 +193,16 @@  discard block
 block discarded – undo
186 193
                 'U_SEARCH_WORDS'          => $u_search,
187 194
             ]);
188 195
 
189
-            if ($cat_id) {
196
+            if ($cat_id)
197
+            {
190 198
                 $this->template->assign_vars([
191 199
                     'SEARCH_CATEGORY'      => $this->user->lang('RETURN_TO', \ernadoo\phpbbdirectory\core\categorie::getname((int) $cat_id)),
192 200
                     'U_SEARCH_CATEGORY'    => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]),
193 201
                 ]);
194 202
             }
195 203
 
196
-            if ($sql_where) {
204
+            if ($sql_where)
205
+            {
197 206
                 $sql_array = [
198 207
                     'SELECT'      => 'l.link_name, l.link_description, l.link_url, l.link_uid, l.link_bitfield, l.link_flags, l.link_view, l.link_user_id, l.link_time, l.link_comment, l.link_flag, l.link_id, l.link_thumb, l.link_banner, c.cat_name, u.user_id, u.username, u.user_colour',
199 208
                     'FROM'        => [
@@ -215,11 +224,14 @@  discard block
 block discarded – undo
215 224
 
216 225
                 $rowset = $this->db->sql_fetchrowset($result);
217 226
 
218
-                if (count($rowset)) {
219
-                    if ($hilit) {
227
+                if (count($rowset))
228
+                {
229
+                    if ($hilit)
230
+                    {
220 231
                         // Remove bad highlights
221 232
                         $hilit_array = array_filter(explode('|', $hilit), 'strlen');
222
-                        foreach ($hilit_array as $key => $value) {
233
+                        foreach ($hilit_array as $key => $value)
234
+                        {
223 235
                             $hilit_array[$key] = phpbb_clean_search_string($value);
224 236
                             $hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($hilit_array[$key], '#'));
225 237
                             $hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
@@ -227,14 +239,16 @@  discard block
 block discarded – undo
227 239
                         $hilit = implode('|', $hilit_array);
228 240
                     }
229 241
 
230
-                    foreach ($rowset as $data) {
242
+                    foreach ($rowset as $data)
243
+                    {
231 244
                         $s_banner = $this->link->display_bann($data);
232 245
                         $s_thumb = $this->link->display_thumb($data);
233 246
                         $s_flag = $this->link->display_flag($data);
234 247
 
235 248
                         $data['link_description'] = generate_text_for_display($data['link_description'], $data['link_uid'], $data['link_bitfield'], $data['link_flags']);
236 249
 
237
-                        if ($hilit) {
250
+                        if ($hilit)
251
+                        {
238 252
                             $data['link_name'] = preg_replace('#(?!<.*)(?<!\w)('.$hilit.')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $data['link_name']);
239 253
                             $data['link_description'] = preg_replace('#(?!<.*)(?<!\w)('.$hilit.')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $data['link_description']);
240 254
                         }
@@ -261,11 +275,13 @@  discard block
 block discarded – undo
261 275
                             'LINK_ID'          => $data['link_id'],
262 276
                         ]);
263 277
 
264
-                        if ($s_banner) {
278
+                        if ($s_banner)
279
+                        {
265 280
                             $this->template->assign_block_vars('results.banner', []);
266 281
                         }
267 282
 
268
-                        if ($this->config['dir_activ_flag']) {
283
+                        if ($this->config['dir_activ_flag'])
284
+                        {
269 285
                             $this->template->assign_block_vars('results.switch_dir_flag', []);
270 286
                         }
271 287
                     }
@@ -278,7 +294,8 @@  discard block
 block discarded – undo
278 294
 
279 295
         $s_catlist = $this->categorie->make_cat_select();
280 296
 
281
-        if (!$s_catlist) {
297
+        if (!$s_catlist)
298
+        {
282 299
             return $this->helper->message('NO_SEARCH');
283 300
         }
284 301
 
@@ -311,17 +328,24 @@  discard block
 block discarded – undo
311 328
         $reset_search_category = true;
312 329
         $ex_cid_ary = [];
313 330
 
314
-        while ($row = $this->db->sql_fetchrow($result)) {
315
-            if (count($search_category)) {
316
-                if ($search_child) {
317
-                    if (in_array($row['cat_id'], $search_category) && $row['right_id'] > $right_id) {
331
+        while ($row = $this->db->sql_fetchrow($result))
332
+        {
333
+            if (count($search_category))
334
+            {
335
+                if ($search_child)
336
+                {
337
+                    if (in_array($row['cat_id'], $search_category) && $row['right_id'] > $right_id)
338
+                    {
318 339
                         $right_id = (int) $row['right_id'];
319
-                    } elseif ($row['right_id'] < $right_id) {
340
+                    }
341
+                    elseif ($row['right_id'] < $right_id)
342
+                    {
320 343
                         continue;
321 344
                     }
322 345
                 }
323 346
 
324
-                if (!in_array($row['cat_id'], $search_category)) {
347
+                if (!in_array($row['cat_id'], $search_category))
348
+                {
325 349
                     $ex_cid_ary[] = (int) $row['cat_id'];
326 350
                     $reset_search_category = false;
327 351
                 }
@@ -329,7 +353,8 @@  discard block
 block discarded – undo
329 353
         }
330 354
         $this->db->sql_freeresult($result);
331 355
 
332
-        if ($reset_search_category) {
356
+        if ($reset_search_category)
357
+        {
333 358
             $search_category = [];
334 359
         }
335 360
 
Please login to merge, or discard this patch.
controller/links.php 3 patches
Indentation   +587 added lines, -587 removed lines patch added patch discarded remove patch
@@ -12,602 +12,602 @@
 block discarded – undo
12 12
 
13 13
 class links
14 14
 {
15
-    private $link_user_id;
16
-    private $site_name;
17
-    private $url;
18
-    private $description;
19
-    private $guest_email;
20
-    private $rss;
21
-    private $banner;
22
-    private $back;
23
-    private $flag;
24
-
25
-    private $captcha;
26
-    private $s_hidden_fields = [];
27
-
28
-    /** @var \phpbb\db\driver\driver_interface */
29
-    protected $db;
30
-
31
-    /** @var \phpbb\config\config */
32
-    protected $config;
33
-
34
-    /** @var \phpbb\template\template */
35
-    protected $template;
36
-
37
-    /** @var \phpbb\user */
38
-    protected $user;
39
-
40
-    /** @var \phpbb\controller\helper */
41
-    protected $helper;
42
-
43
-    /** @var \phpbb\request\request */
44
-    protected $request;
45
-
46
-    /** @var \phpbb\auth\auth */
47
-    protected $auth;
48
-
49
-    /** @var \phpbb\captcha\factory */
50
-    protected $captcha_factory;
51
-
52
-    /** @var \ernadoo\phpbbdirectory\core\categorie */
53
-    protected $categorie;
54
-
55
-    /** @var \ernadoo\phpbbdirectory\core\link */
56
-    protected $link;
57
-
58
-    /** @var \ernadoo\phpbbdirectory\core\helper */
59
-    protected $dir_helper;
60
-
61
-    /** @var string phpBB root path */
62
-    protected $root_path;
63
-
64
-    /** @var string phpEx */
65
-    protected $php_ext;
66
-
67
-    /**
68
-     * Constructor.
69
-     *
70
-     * @param \phpbb\db\driver\driver_interface      $db              Database object
71
-     * @param \phpbb\config\config                   $config          Config object
72
-     * @param \phpbb\template\template               $template        Template object
73
-     * @param \phpbb\user                            $user            User object
74
-     * @param \phpbb\controller\helper               $helper          Controller helper object
75
-     * @param \phpbb\request\request                 $request         Request object
76
-     * @param \phpbb\auth\auth                       $auth            Auth object
77
-     * @param \phpbb\captcha\factory                 $captcha_factory Captcha object
78
-     * @param \ernadoo\phpbbdirectory\core\categorie $categorie       PhpBB Directory extension categorie object
79
-     * @param \ernadoo\phpbbdirectory\core\link      $link            PhpBB Directory extension link object
80
-     * @param \ernadoo\phpbbdirectory\core\helper    $dir_helper      PhpBB Directory extension helper object
81
-     * @param string                                 $root_path       phpBB root path
82
-     * @param string                                 $php_ext         phpEx
83
-     */
84
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\captcha\factory $captcha_factory, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link, \ernadoo\phpbbdirectory\core\helper $dir_helper, $root_path, $php_ext)
85
-    {
86
-        $this->db = $db;
87
-        $this->config = $config;
88
-        $this->template = $template;
89
-        $this->user = $user;
90
-        $this->helper = $helper;
91
-        $this->request = $request;
92
-        $this->auth = $auth;
93
-        $this->captcha_factory = $captcha_factory;
94
-        $this->categorie = $categorie;
95
-        $this->link = $link;
96
-        $this->dir_helper = $dir_helper;
97
-        $this->root_path = $root_path;
98
-        $this->php_ext = $php_ext;
99
-
100
-        $this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory');
101
-
102
-        $this->template->assign_vars([
103
-            'S_PHPBB_DIRECTORY'                => true,
104
-            'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
105
-        ]);
106
-    }
107
-
108
-    /**
109
-     * Delete a link.
110
-     *
111
-     * @param int $cat_id  The category ID
112
-     * @param int $link_id The link ID
113
-     *
114
-     * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
115
-     */
116
-    public function delete_link($cat_id, $link_id)
117
-    {
118
-        if ($this->request->is_set_post('cancel')) {
119
-            $redirect = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
120
-            redirect($redirect);
121
-        }
122
-
123
-        $sql = 'SELECT link_user_id
15
+	private $link_user_id;
16
+	private $site_name;
17
+	private $url;
18
+	private $description;
19
+	private $guest_email;
20
+	private $rss;
21
+	private $banner;
22
+	private $back;
23
+	private $flag;
24
+
25
+	private $captcha;
26
+	private $s_hidden_fields = [];
27
+
28
+	/** @var \phpbb\db\driver\driver_interface */
29
+	protected $db;
30
+
31
+	/** @var \phpbb\config\config */
32
+	protected $config;
33
+
34
+	/** @var \phpbb\template\template */
35
+	protected $template;
36
+
37
+	/** @var \phpbb\user */
38
+	protected $user;
39
+
40
+	/** @var \phpbb\controller\helper */
41
+	protected $helper;
42
+
43
+	/** @var \phpbb\request\request */
44
+	protected $request;
45
+
46
+	/** @var \phpbb\auth\auth */
47
+	protected $auth;
48
+
49
+	/** @var \phpbb\captcha\factory */
50
+	protected $captcha_factory;
51
+
52
+	/** @var \ernadoo\phpbbdirectory\core\categorie */
53
+	protected $categorie;
54
+
55
+	/** @var \ernadoo\phpbbdirectory\core\link */
56
+	protected $link;
57
+
58
+	/** @var \ernadoo\phpbbdirectory\core\helper */
59
+	protected $dir_helper;
60
+
61
+	/** @var string phpBB root path */
62
+	protected $root_path;
63
+
64
+	/** @var string phpEx */
65
+	protected $php_ext;
66
+
67
+	/**
68
+	 * Constructor.
69
+	 *
70
+	 * @param \phpbb\db\driver\driver_interface      $db              Database object
71
+	 * @param \phpbb\config\config                   $config          Config object
72
+	 * @param \phpbb\template\template               $template        Template object
73
+	 * @param \phpbb\user                            $user            User object
74
+	 * @param \phpbb\controller\helper               $helper          Controller helper object
75
+	 * @param \phpbb\request\request                 $request         Request object
76
+	 * @param \phpbb\auth\auth                       $auth            Auth object
77
+	 * @param \phpbb\captcha\factory                 $captcha_factory Captcha object
78
+	 * @param \ernadoo\phpbbdirectory\core\categorie $categorie       PhpBB Directory extension categorie object
79
+	 * @param \ernadoo\phpbbdirectory\core\link      $link            PhpBB Directory extension link object
80
+	 * @param \ernadoo\phpbbdirectory\core\helper    $dir_helper      PhpBB Directory extension helper object
81
+	 * @param string                                 $root_path       phpBB root path
82
+	 * @param string                                 $php_ext         phpEx
83
+	 */
84
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\captcha\factory $captcha_factory, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link, \ernadoo\phpbbdirectory\core\helper $dir_helper, $root_path, $php_ext)
85
+	{
86
+		$this->db = $db;
87
+		$this->config = $config;
88
+		$this->template = $template;
89
+		$this->user = $user;
90
+		$this->helper = $helper;
91
+		$this->request = $request;
92
+		$this->auth = $auth;
93
+		$this->captcha_factory = $captcha_factory;
94
+		$this->categorie = $categorie;
95
+		$this->link = $link;
96
+		$this->dir_helper = $dir_helper;
97
+		$this->root_path = $root_path;
98
+		$this->php_ext = $php_ext;
99
+
100
+		$this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory');
101
+
102
+		$this->template->assign_vars([
103
+			'S_PHPBB_DIRECTORY'                => true,
104
+			'DIRECTORY_TRANSLATION_INFO'       => (!empty($user->lang['DIRECTORY_TRANSLATION_INFO'])) ? $user->lang['DIRECTORY_TRANSLATION_INFO'] : '',
105
+		]);
106
+	}
107
+
108
+	/**
109
+	 * Delete a link.
110
+	 *
111
+	 * @param int $cat_id  The category ID
112
+	 * @param int $link_id The link ID
113
+	 *
114
+	 * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
115
+	 */
116
+	public function delete_link($cat_id, $link_id)
117
+	{
118
+		if ($this->request->is_set_post('cancel')) {
119
+			$redirect = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
120
+			redirect($redirect);
121
+		}
122
+
123
+		$sql = 'SELECT link_user_id
124 124
 			FROM '.DIR_LINK_TABLE.'
125 125
 			WHERE link_id = '.(int) $link_id;
126
-        $result = $this->db->sql_query($sql);
127
-        $link_data = $this->db->sql_fetchrow($result);
128
-
129
-        if (empty($link_data)) {
130
-            throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
131
-        }
132
-
133
-        $delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $link_data['link_user_id'] && $this->auth->acl_get('u_delete_dir')));
134
-
135
-        if (!$delete_allowed) {
136
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
137
-        }
138
-
139
-        if (confirm_box(true)) {
140
-            $this->link->del($cat_id, $link_id);
141
-
142
-            $meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
143
-            meta_refresh(3, $meta_info);
144
-            $message = $this->user->lang['DIR_DELETE_OK'].'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_base_controller').'">', '</a>').'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]).'">', '</a>');
145
-
146
-            return $this->helper->message($message);
147
-        } else {
148
-            confirm_box(false, 'DIR_DELETE_SITE');
149
-        }
150
-    }
151
-
152
-    /**
153
-     * Edit a link.
154
-     *
155
-     * @param int $cat_id  The category ID
156
-     * @param int $link_id The link ID
157
-     *
158
-     * @throws \phpbb\exception\http_exception
159
-     *
160
-     * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
161
-     */
162
-    public function edit_link($cat_id, $link_id)
163
-    {
164
-        $sql = 'SELECT link_user_id
126
+		$result = $this->db->sql_query($sql);
127
+		$link_data = $this->db->sql_fetchrow($result);
128
+
129
+		if (empty($link_data)) {
130
+			throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
131
+		}
132
+
133
+		$delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $link_data['link_user_id'] && $this->auth->acl_get('u_delete_dir')));
134
+
135
+		if (!$delete_allowed) {
136
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
137
+		}
138
+
139
+		if (confirm_box(true)) {
140
+			$this->link->del($cat_id, $link_id);
141
+
142
+			$meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
143
+			meta_refresh(3, $meta_info);
144
+			$message = $this->user->lang['DIR_DELETE_OK'].'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_base_controller').'">', '</a>').'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]).'">', '</a>');
145
+
146
+			return $this->helper->message($message);
147
+		} else {
148
+			confirm_box(false, 'DIR_DELETE_SITE');
149
+		}
150
+	}
151
+
152
+	/**
153
+	 * Edit a link.
154
+	 *
155
+	 * @param int $cat_id  The category ID
156
+	 * @param int $link_id The link ID
157
+	 *
158
+	 * @throws \phpbb\exception\http_exception
159
+	 *
160
+	 * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
161
+	 */
162
+	public function edit_link($cat_id, $link_id)
163
+	{
164
+		$sql = 'SELECT link_user_id
165 165
 			FROM '.DIR_LINK_TABLE.'
166 166
 			WHERE link_id = '.(int) $link_id;
167
-        $result = $this->db->sql_query($sql);
168
-        $link_data = $this->db->sql_fetchrow($result);
169
-        $this->link_user_id = (int) $link_data['link_user_id'];
170
-
171
-        $edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == (int) $link_data['link_user_id'] && $this->auth->acl_get('u_edit_dir'))));
172
-
173
-        if (!$edit_allowed) {
174
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
175
-        }
176
-
177
-        $cat_id = $this->request->variable('id', $cat_id);
178
-        $submit = $this->request->is_set_post('submit') ? true : false;
179
-        $refresh = $this->request->is_set_post('refresh_vc') ? true : false;
180
-        $title = $this->user->lang['DIR_EDIT_SITE'];
181
-
182
-        $this->template->assign_block_vars('dir_navlinks', [
183
-            'FORUM_NAME'      => $title,
184
-            'U_VIEW_FORUM'    => $this->helper->route('ernadoo_phpbbdirectory_edit_controller', ['cat_id' => (int) $cat_id, 'link_id' => $link_id]),
185
-        ]);
186
-
187
-        $this->categorie->get($cat_id);
188
-
189
-        // If form is done
190
-        if ($submit || $refresh) {
191
-            if (false != ($result = $this->_data_processing($cat_id, $link_id, 'edit'))) {
192
-                return $result;
193
-            }
194
-        } else {
195
-            $sql = 'SELECT link_id, link_uid, link_flags, link_bitfield, link_cat, link_url, link_description, link_guest_email, link_name, link_rss, link_back, link_banner, link_flag, link_cat, link_time
167
+		$result = $this->db->sql_query($sql);
168
+		$link_data = $this->db->sql_fetchrow($result);
169
+		$this->link_user_id = (int) $link_data['link_user_id'];
170
+
171
+		$edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == (int) $link_data['link_user_id'] && $this->auth->acl_get('u_edit_dir'))));
172
+
173
+		if (!$edit_allowed) {
174
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
175
+		}
176
+
177
+		$cat_id = $this->request->variable('id', $cat_id);
178
+		$submit = $this->request->is_set_post('submit') ? true : false;
179
+		$refresh = $this->request->is_set_post('refresh_vc') ? true : false;
180
+		$title = $this->user->lang['DIR_EDIT_SITE'];
181
+
182
+		$this->template->assign_block_vars('dir_navlinks', [
183
+			'FORUM_NAME'      => $title,
184
+			'U_VIEW_FORUM'    => $this->helper->route('ernadoo_phpbbdirectory_edit_controller', ['cat_id' => (int) $cat_id, 'link_id' => $link_id]),
185
+		]);
186
+
187
+		$this->categorie->get($cat_id);
188
+
189
+		// If form is done
190
+		if ($submit || $refresh) {
191
+			if (false != ($result = $this->_data_processing($cat_id, $link_id, 'edit'))) {
192
+				return $result;
193
+			}
194
+		} else {
195
+			$sql = 'SELECT link_id, link_uid, link_flags, link_bitfield, link_cat, link_url, link_description, link_guest_email, link_name, link_rss, link_back, link_banner, link_flag, link_cat, link_time
196 196
 				FROM '.DIR_LINK_TABLE.'
197 197
 				WHERE link_id = '.(int) $link_id;
198
-            $result = $this->db->sql_query($sql);
199
-
200
-            $site = $this->db->sql_fetchrow($result);
201
-
202
-            if (empty($site['link_id'])) {
203
-                throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
204
-            }
205
-
206
-            $this->s_hidden_fields = [
207
-                'old_cat_id'    => $site['link_cat'],
208
-                'old_banner'    => $site['link_banner'],
209
-            ];
210
-
211
-            $site_description = generate_text_for_edit($site['link_description'], $site['link_uid'], $site['link_flags']);
212
-            $site['link_banner'] = (preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $site['link_banner'])) ? $site['link_banner'] : '';
213
-
214
-            $this->url = $site['link_url'];
215
-            $this->site_name = $site['link_name'];
216
-            $this->description = $site_description['text'];
217
-            $this->guest_email = $site['link_guest_email'];
218
-            $this->rss = $site['link_rss'];
219
-            $this->banner = $site['link_banner'];
220
-            $this->back = $site['link_back'];
221
-            $this->flag = $site['link_flag'];
222
-        }
223
-
224
-        $this->_populate_form($cat_id, 'edit', $title);
225
-
226
-        return $this->helper->render('add_site.html', $title);
227
-    }
228
-
229
-    /**
230
-     * Display add form.
231
-     *
232
-     * @param int $cat_id The category ID
233
-     *
234
-     * @throws \phpbb\exception\http_exception
235
-     *
236
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
237
-     */
238
-    public function new_link($cat_id)
239
-    {
240
-        if (!$this->auth->acl_get('u_submit_dir')) {
241
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
242
-        }
243
-
244
-        $cat_id = $this->request->variable('id', $cat_id);
245
-        $submit = $this->request->is_set_post('submit') ? true : false;
246
-        $refresh = $this->request->is_set_post('refresh_vc') ? true : false;
247
-        $title = $this->user->lang['DIR_NEW_SITE'];
248
-
249
-        $this->template->assign_block_vars('dir_navlinks', [
250
-            'FORUM_NAME'      => $title,
251
-            'U_VIEW_FORUM'    => $this->helper->route('ernadoo_phpbbdirectory_new_controller', ['cat_id' => (int) $cat_id]),
252
-        ]);
253
-
254
-        $this->categorie->get($cat_id);
255
-
256
-        // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
257
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
258
-            $this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
259
-            $this->captcha->init(CONFIRM_POST);
260
-        }
261
-
262
-        // If form is done
263
-        if ($submit || $refresh) {
264
-            if (false != ($result = $this->_data_processing($cat_id))) {
265
-                return $result;
266
-            }
267
-        }
268
-
269
-        $this->_populate_form($cat_id, 'new', $title);
270
-
271
-        return $this->helper->render('add_site.html', $title);
272
-    }
273
-
274
-    /**
275
-     * View link controller.
276
-     *
277
-     * @param int $link_id The link ID
278
-     *
279
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
280
-     */
281
-    public function view_link($link_id)
282
-    {
283
-        return $this->link->view($link_id);
284
-    }
285
-
286
-    /**
287
-     * Vote for a link.
288
-     *
289
-     * @param int $cat_id  The category ID
290
-     * @param int $link_id The link ID
291
-     *
292
-     * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
293
-     */
294
-    public function vote_link($cat_id, $link_id)
295
-    {
296
-        $this->categorie->get($cat_id);
297
-
298
-        if (!$this->auth->acl_get('u_vote_dir') || !$this->categorie->data['cat_allow_votes']) {
299
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
300
-        }
301
-
302
-        $data = [
303
-            'vote_link_id'        => (int) $link_id,
304
-            'vote_user_id'        => (int) $this->user->data['user_id'],
305
-        ];
306
-
307
-        // We check if user had already vot for this website.
308
-        $sql = 'SELECT vote_link_id
198
+			$result = $this->db->sql_query($sql);
199
+
200
+			$site = $this->db->sql_fetchrow($result);
201
+
202
+			if (empty($site['link_id'])) {
203
+				throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
204
+			}
205
+
206
+			$this->s_hidden_fields = [
207
+				'old_cat_id'    => $site['link_cat'],
208
+				'old_banner'    => $site['link_banner'],
209
+			];
210
+
211
+			$site_description = generate_text_for_edit($site['link_description'], $site['link_uid'], $site['link_flags']);
212
+			$site['link_banner'] = (preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $site['link_banner'])) ? $site['link_banner'] : '';
213
+
214
+			$this->url = $site['link_url'];
215
+			$this->site_name = $site['link_name'];
216
+			$this->description = $site_description['text'];
217
+			$this->guest_email = $site['link_guest_email'];
218
+			$this->rss = $site['link_rss'];
219
+			$this->banner = $site['link_banner'];
220
+			$this->back = $site['link_back'];
221
+			$this->flag = $site['link_flag'];
222
+		}
223
+
224
+		$this->_populate_form($cat_id, 'edit', $title);
225
+
226
+		return $this->helper->render('add_site.html', $title);
227
+	}
228
+
229
+	/**
230
+	 * Display add form.
231
+	 *
232
+	 * @param int $cat_id The category ID
233
+	 *
234
+	 * @throws \phpbb\exception\http_exception
235
+	 *
236
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
237
+	 */
238
+	public function new_link($cat_id)
239
+	{
240
+		if (!$this->auth->acl_get('u_submit_dir')) {
241
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
242
+		}
243
+
244
+		$cat_id = $this->request->variable('id', $cat_id);
245
+		$submit = $this->request->is_set_post('submit') ? true : false;
246
+		$refresh = $this->request->is_set_post('refresh_vc') ? true : false;
247
+		$title = $this->user->lang['DIR_NEW_SITE'];
248
+
249
+		$this->template->assign_block_vars('dir_navlinks', [
250
+			'FORUM_NAME'      => $title,
251
+			'U_VIEW_FORUM'    => $this->helper->route('ernadoo_phpbbdirectory_new_controller', ['cat_id' => (int) $cat_id]),
252
+		]);
253
+
254
+		$this->categorie->get($cat_id);
255
+
256
+		// The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
257
+		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
258
+			$this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
259
+			$this->captcha->init(CONFIRM_POST);
260
+		}
261
+
262
+		// If form is done
263
+		if ($submit || $refresh) {
264
+			if (false != ($result = $this->_data_processing($cat_id))) {
265
+				return $result;
266
+			}
267
+		}
268
+
269
+		$this->_populate_form($cat_id, 'new', $title);
270
+
271
+		return $this->helper->render('add_site.html', $title);
272
+	}
273
+
274
+	/**
275
+	 * View link controller.
276
+	 *
277
+	 * @param int $link_id The link ID
278
+	 *
279
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
280
+	 */
281
+	public function view_link($link_id)
282
+	{
283
+		return $this->link->view($link_id);
284
+	}
285
+
286
+	/**
287
+	 * Vote for a link.
288
+	 *
289
+	 * @param int $cat_id  The category ID
290
+	 * @param int $link_id The link ID
291
+	 *
292
+	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
293
+	 */
294
+	public function vote_link($cat_id, $link_id)
295
+	{
296
+		$this->categorie->get($cat_id);
297
+
298
+		if (!$this->auth->acl_get('u_vote_dir') || !$this->categorie->data['cat_allow_votes']) {
299
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
300
+		}
301
+
302
+		$data = [
303
+			'vote_link_id'        => (int) $link_id,
304
+			'vote_user_id'        => (int) $this->user->data['user_id'],
305
+		];
306
+
307
+		// We check if user had already vot for this website.
308
+		$sql = 'SELECT vote_link_id
309 309
 			FROM '.DIR_VOTE_TABLE.'
310 310
 			WHERE '.$this->db->sql_build_array('SELECT', $data);
311
-        $result = $this->db->sql_query($sql);
312
-        $data = $this->db->sql_fetchrow($result);
313
-
314
-        if (!empty($data['vote_link_id'])) {
315
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_VOTE');
316
-        }
317
-
318
-        $this->link->add_vote($link_id);
319
-
320
-        $meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
321
-        meta_refresh(3, $meta_info);
322
-        $message = $this->user->lang['DIR_VOTE_OK'].'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$meta_info.'">', '</a>');
323
-
324
-        return $this->helper->message($message);
325
-    }
326
-
327
-    /**
328
-     * Routine.
329
-     *
330
-     * @param int    $cat_id  The category ID
331
-     * @param int    $link_id The link ID
332
-     * @param string $mode    add|edit
333
-     *
334
-     * @throws \phpbb\exception\http_exception
335
-     *
336
-     * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
337
-     */
338
-    private function _data_processing($cat_id, $link_id = 0, $mode = 'new')
339
-    {
340
-        if (($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir')) || ($mode == 'new' && !$this->auth->acl_get('u_submit_dir'))) {
341
-            throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
342
-        }
343
-
344
-        if (!check_form_key('dir_form')) {
345
-            return $this->helper->message('FORM_INVALID');
346
-        }
347
-
348
-        $this->url = $this->request->variable('url', '');
349
-        $this->site_name = $this->request->variable('site_name', '', true);
350
-        $this->description = $this->request->variable('description', '', true);
351
-        $this->guest_email = $this->request->variable('guest_email', '');
352
-        $this->rss = $this->request->variable('rss', '');
353
-        $this->banner = $this->request->variable('banner', '');
354
-        $this->back = $this->request->variable('back', '');
355
-        $this->flag = $this->request->variable('flag', '');
356
-
357
-        if (!function_exists('validate_data')) {
358
-            include $this->root_path.'includes/functions_user.'.$this->php_ext;
359
-        }
360
-
361
-        // We define variables to check
362
-        $data = [
363
-            'email'            => $this->guest_email,
364
-            'site_name'        => $this->site_name,
365
-            'website'          => $this->url,
366
-            'description'      => $this->description,
367
-            'rss'              => $this->rss,
368
-            'banner'           => $this->banner,
369
-            'back'             => $this->back,
370
-            'cat'              => (int) $cat_id,
371
-        ];
372
-
373
-        // We define verification type for each variable
374
-        $data2 = [
375
-            'email'            => [
376
-                ['string', $this->user->data['is_registered'], 6, 60],
377
-                ['user_email', ''], ],
378
-            'site_name' => [
379
-                ['string', false, 1, 100], ],
380
-            'website'        => [
381
-                ['string',    false, 12, 255],
382
-                ['match',    true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
383
-            'description'    => [
384
-                ['string', !$this->categorie->data['cat_must_describe'], 1, $this->config['dir_length_describe']], ],
385
-            'rss'            => [
386
-                ['string', true, 12, 255],
387
-                ['match',    empty($this->rss), '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
388
-            'banner'        => [
389
-                ['string', true, 5, 255], ],
390
-            'back'            => [
391
-                ['string',    !$this->categorie->data['cat_link_back'], 12, 255],
392
-                [[$this->link, 'link_back'], true], ],
393
-            'cat'            => [
394
-                ['num', '', 1], ],
395
-        ];
396
-
397
-        $this->user->add_lang('ucp');
398
-        $error = validate_data($data, $data2);
399
-        $error = array_map([$this->user, 'lang'], $error);
400
-
401
-        // We check that url have good format
402
-        if (preg_match('/^(http|https):\/\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url)) {
403
-            $error[] = $this->user->lang['DIR_ERROR_CHECK_URL'];
404
-        }
405
-
406
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
407
-            $vc_response = $this->captcha->validate($data);
408
-            if ($vc_response !== false) {
409
-                $error[] = $vc_response;
410
-            }
411
-
412
-            if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
413
-                $error[] = $this->user->lang['TOO_MANY_ADDS'];
414
-            }
415
-        }
416
-
417
-        if (!$error) {
418
-            /*
311
+		$result = $this->db->sql_query($sql);
312
+		$data = $this->db->sql_fetchrow($result);
313
+
314
+		if (!empty($data['vote_link_id'])) {
315
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_VOTE');
316
+		}
317
+
318
+		$this->link->add_vote($link_id);
319
+
320
+		$meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
321
+		meta_refresh(3, $meta_info);
322
+		$message = $this->user->lang['DIR_VOTE_OK'].'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$meta_info.'">', '</a>');
323
+
324
+		return $this->helper->message($message);
325
+	}
326
+
327
+	/**
328
+	 * Routine.
329
+	 *
330
+	 * @param int    $cat_id  The category ID
331
+	 * @param int    $link_id The link ID
332
+	 * @param string $mode    add|edit
333
+	 *
334
+	 * @throws \phpbb\exception\http_exception
335
+	 *
336
+	 * @return null|\Symfony\Component\HttpFoundation\Response A Symfony Response object
337
+	 */
338
+	private function _data_processing($cat_id, $link_id = 0, $mode = 'new')
339
+	{
340
+		if (($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir')) || ($mode == 'new' && !$this->auth->acl_get('u_submit_dir'))) {
341
+			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
342
+		}
343
+
344
+		if (!check_form_key('dir_form')) {
345
+			return $this->helper->message('FORM_INVALID');
346
+		}
347
+
348
+		$this->url = $this->request->variable('url', '');
349
+		$this->site_name = $this->request->variable('site_name', '', true);
350
+		$this->description = $this->request->variable('description', '', true);
351
+		$this->guest_email = $this->request->variable('guest_email', '');
352
+		$this->rss = $this->request->variable('rss', '');
353
+		$this->banner = $this->request->variable('banner', '');
354
+		$this->back = $this->request->variable('back', '');
355
+		$this->flag = $this->request->variable('flag', '');
356
+
357
+		if (!function_exists('validate_data')) {
358
+			include $this->root_path.'includes/functions_user.'.$this->php_ext;
359
+		}
360
+
361
+		// We define variables to check
362
+		$data = [
363
+			'email'            => $this->guest_email,
364
+			'site_name'        => $this->site_name,
365
+			'website'          => $this->url,
366
+			'description'      => $this->description,
367
+			'rss'              => $this->rss,
368
+			'banner'           => $this->banner,
369
+			'back'             => $this->back,
370
+			'cat'              => (int) $cat_id,
371
+		];
372
+
373
+		// We define verification type for each variable
374
+		$data2 = [
375
+			'email'            => [
376
+				['string', $this->user->data['is_registered'], 6, 60],
377
+				['user_email', ''], ],
378
+			'site_name' => [
379
+				['string', false, 1, 100], ],
380
+			'website'        => [
381
+				['string',    false, 12, 255],
382
+				['match',    true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
383
+			'description'    => [
384
+				['string', !$this->categorie->data['cat_must_describe'], 1, $this->config['dir_length_describe']], ],
385
+			'rss'            => [
386
+				['string', true, 12, 255],
387
+				['match',    empty($this->rss), '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
388
+			'banner'        => [
389
+				['string', true, 5, 255], ],
390
+			'back'            => [
391
+				['string',    !$this->categorie->data['cat_link_back'], 12, 255],
392
+				[[$this->link, 'link_back'], true], ],
393
+			'cat'            => [
394
+				['num', '', 1], ],
395
+		];
396
+
397
+		$this->user->add_lang('ucp');
398
+		$error = validate_data($data, $data2);
399
+		$error = array_map([$this->user, 'lang'], $error);
400
+
401
+		// We check that url have good format
402
+		if (preg_match('/^(http|https):\/\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url)) {
403
+			$error[] = $this->user->lang['DIR_ERROR_CHECK_URL'];
404
+		}
405
+
406
+		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
407
+			$vc_response = $this->captcha->validate($data);
408
+			if ($vc_response !== false) {
409
+				$error[] = $vc_response;
410
+			}
411
+
412
+			if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
413
+				$error[] = $this->user->lang['TOO_MANY_ADDS'];
414
+			}
415
+		}
416
+
417
+		if (!$error) {
418
+			/*
419 419
             * No errrors, we execute heavy tasks wich need a valid url
420 420
             */
421 421
 
422
-            // Banner
423
-            $this->link->banner_process($this->banner, $error);
424
-
425
-            // PageRank
426
-            $pagerank = $this->link->pagerank_process($this->url);
427
-
428
-            // Thumb ;)
429
-            $thumb = $this->link->thumb_process($this->url);
430
-        }
431
-
432
-        // Still no errors?? So let's go!
433
-        if (!$error) {
434
-            $this->banner = (!$this->banner && !$this->request->is_set_post('delete_banner')) ? $this->request->variable('old_banner', '') : $this->banner;
435
-            $this->url = $this->link->clean_url($this->url);
436
-
437
-            $data_edit = [
438
-                'link_user_id'         => $this->link_user_id,
439
-                'link_guest_email'     => $this->guest_email,
440
-                'link_name'            => $this->site_name,
441
-                'link_url'             => $this->url,
442
-                'link_description'     => $this->description,
443
-                'link_cat'             => (int) $cat_id,
444
-                'link_rss'             => $this->rss,
445
-                'link_banner'          => $this->banner,
446
-                'link_back'            => $this->back,
447
-                'link_uid'             => '',
448
-                'link_flags'           => 7,
449
-                'link_flag'            => $this->flag,
450
-                'link_bitfield'        => '',
451
-                'link_pagerank'        => (int) $pagerank,
452
-                'link_thumb'           => $thumb,
453
-            ];
454
-
455
-            if ($this->description) {
456
-                generate_text_for_storage($this->description, $data_edit['link_uid'], $data_edit['link_bitfield'], $data_edit['link_flags'], (bool) $this->config['allow_bbcode'], (bool) $this->config['allow_post_links'], (bool) $this->config['allow_smilies']);
457
-            }
458
-
459
-            $need_approval = ($this->categorie->need_approval() && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_')) ? true : false;
460
-
461
-            if ($mode == 'edit') {
462
-                $data_edit['link_cat_old'] = $this->request->variable('old_cat_id', 0);
463
-                $this->link->edit($data_edit, $link_id, $need_approval);
464
-            } else {
465
-                $data_add = [
466
-                    'link_time'            => time(),
467
-                    'link_view'            => 0,
468
-                    'link_active'          => $need_approval ? false : true,
469
-                    'link_user_id'         => $this->user->data['user_id'],
470
-                ];
471
-
472
-                $data_add = array_merge($data_edit, $data_add);
473
-
474
-                $this->link->add($data_add, $need_approval);
475
-            }
476
-
477
-            $meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
478
-            meta_refresh(3, $meta_info);
479
-            $message = ($need_approval) ? $this->user->lang['DIR_'.strtoupper($mode).'_SITE_ACTIVE'] : $this->user->lang['DIR_'.strtoupper($mode).'_SITE_OK'];
480
-            $message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_base_controller').'">', '</a>').'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]).'">', '</a>');
481
-
482
-            return $this->helper->message($message);
483
-        } else {
484
-            if ($mode == 'edit') {
485
-                $this->s_hidden_fields = [
486
-                    'old_cat_id'    => $this->request->variable('old_cat_id', 0),
487
-                    'old_banner'    => $this->request->variable('old_banner', ''),
488
-                ];
489
-            }
490
-
491
-            $this->template->assign_vars([
492
-                'ERROR'    => (isset($error)) ? implode('<br />', $error) : '',
493
-            ]);
494
-        }
495
-    }
496
-
497
-    /**
498
-     * Display a banner.
499
-     *
500
-     * @param string $banner_img Path to banner file
501
-     *
502
-     * @return Response object
503
-     */
504
-    public function return_banner($banner_img)
505
-    {
506
-        if (!function_exists('file_gc')) {
507
-            include $this->root_path.'includes/functions_download.'.$this->php_ext;
508
-        }
509
-
510
-        $file_path = $this->dir_helper->get_banner_path($banner_img);
511
-
512
-        if ((@file_exists($file_path) && @is_readable($file_path))) {
513
-            $response = new BinaryFileResponse($file_path);
514
-            $response->setContentDisposition('inline', $banner_img);
515
-
516
-            // Without fileinfo extension, Symfony is unable to guess the mime type
517
-            if (!extension_loaded('fileinfo')) {
518
-                $image_data = @getimagesize($file_path);
519
-                $response->headers->set('Content-Type', image_type_to_mime_type($image_data[2]));
520
-            }
521
-        } else {
522
-            $response = new Response();
523
-            $response->setStatusCode(404);
524
-        }
525
-        file_gc(false);
526
-
527
-        return $response;
528
-    }
529
-
530
-    /**
531
-     * Populate form when an error occurred.
532
-     *
533
-     * @param int    $cat_id The category ID
534
-     * @param string $mode   add|edit
535
-     * @param string $title  Page title (depends of $mode)
536
-     *
537
-     * @return null
538
-     */
539
-    private function _populate_form($cat_id, $mode, $title)
540
-    {
541
-        global $phpbb_extension_manager;
542
-
543
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new') {
544
-            $this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
545
-
546
-            $this->user->add_lang('ucp');
547
-
548
-            $this->template->assign_vars([
549
-                'CAPTCHA_TEMPLATE'        => $this->captcha->get_template(),
550
-            ]);
551
-        }
552
-
553
-        $this->user->add_lang('posting');
554
-
555
-        if (!function_exists('display_custom_bbcodes')) {
556
-            include $this->root_path.'includes/functions_display.'.$this->php_ext;
557
-        }
558
-        display_custom_bbcodes();
559
-        add_form_key('dir_form');
560
-
561
-        $ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false);
562
-        $flag_path = $ext_path.'images/flags/';
563
-
564
-        $s_guest = (!$this->user->data['is_registered'] || !empty($this->guest_email));
565
-        $s_rss = $this->config['dir_activ_rss'];
566
-        $s_banner = $this->config['dir_activ_banner'];
567
-        $s_back = $this->categorie->data['cat_link_back'];
568
-        $s_flag = $this->config['dir_activ_flag'];
569
-
570
-        $this->template->assign_vars([
571
-            'BBCODE_STATUS'            => ($this->config['allow_bbcode']) ? $this->user->lang('BBCODE_IS_ON', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>') : $this->user->lang('BBCODE_IS_OFF', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>'),
572
-            'IMG_STATUS'               => ($this->config['allow_bbcode']) ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'],
573
-            'SMILIES_STATUS'           => ($this->config['allow_smilies']) ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'],
574
-            'URL_STATUS'               => ($this->config['allow_post_links']) ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'],
575
-            'FLASH_STATUS'             => ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'],
576
-
577
-            'L_TITLE'                  => $title,
578
-            'L_DIR_DESCRIPTION_EXP'    => $this->user->lang('DIR_DESCRIPTION_EXP', $this->config['dir_length_describe']),
579
-            'L_DIR_SUBMIT_TYPE'        => $this->categorie->dir_submit_type($this->categorie->need_approval()),
580
-            'L_DIR_SITE_BANN_EXP'      => $this->user->lang('DIR_SITE_BANN_EXP', $this->config['dir_banner_width'], $this->config['dir_banner_height']),
581
-
582
-            'S_GUEST'                  => $s_guest ? true : false,
583
-            'S_RSS'                    => $s_rss ? true : false,
584
-            'S_BANNER'                 => $s_banner ? true : false,
585
-            'S_BACK'                   => $s_back ? true : false,
586
-            'S_FLAG'                   => $s_flag ? true : false,
587
-            'S_BBCODE_ALLOWED'         => (bool) $this->config['allow_bbcode'],
588
-            'S_BBCODE_IMG'             => (bool) $this->config['allow_bbcode'],
589
-            'S_BBCODE_FLASH'           => ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? true : false,
590
-            'S_BBCODE_QUOTE'           => true,
591
-            'S_LINKS_ALLOWED'          => (bool) $this->config['allow_post_links'],
592
-
593
-            'DIR_FLAG_PATH'            => $flag_path,
594
-            'DIR_FLAG_IMAGE'           => $this->flag ? $this->dir_helper->get_img_path('flags', $this->flag) : '',
595
-
596
-            'EDIT_MODE'                => ($mode == 'edit') ? true : false,
597
-
598
-            'SITE_NAME'                => isset($this->site_name) ? $this->site_name : '',
599
-            'SITE_URL'                 => isset($this->url) ? $this->url : '',
600
-            'DESCRIPTION'              => isset($this->description) ? $this->description : '',
601
-            'GUEST_EMAIL'              => isset($this->guest_email) ? $this->guest_email : '',
602
-            'RSS'                      => isset($this->rss) ? $this->rss : '',
603
-            'BANNER'                   => isset($this->banner) ? $this->banner : '',
604
-            'BACK'                     => isset($this->back) ? $this->back : '',
605
-            'S_POST_ACTION'            => '',
606
-            'S_CATLIST'                => $this->categorie->make_cat_select($cat_id),
607
-            'S_LIST_FLAG'              => $this->link->get_dir_flag_list($flag_path, $this->flag),
608
-            'S_DESC_STAR'              => (@$this->categorie->data['cat_must_describe']) ? '*' : '',
609
-            'S_ROOT'                   => $cat_id,
610
-            'S_HIDDEN_FIELDS'          => build_hidden_fields($this->s_hidden_fields),
611
-        ]);
612
-    }
422
+			// Banner
423
+			$this->link->banner_process($this->banner, $error);
424
+
425
+			// PageRank
426
+			$pagerank = $this->link->pagerank_process($this->url);
427
+
428
+			// Thumb ;)
429
+			$thumb = $this->link->thumb_process($this->url);
430
+		}
431
+
432
+		// Still no errors?? So let's go!
433
+		if (!$error) {
434
+			$this->banner = (!$this->banner && !$this->request->is_set_post('delete_banner')) ? $this->request->variable('old_banner', '') : $this->banner;
435
+			$this->url = $this->link->clean_url($this->url);
436
+
437
+			$data_edit = [
438
+				'link_user_id'         => $this->link_user_id,
439
+				'link_guest_email'     => $this->guest_email,
440
+				'link_name'            => $this->site_name,
441
+				'link_url'             => $this->url,
442
+				'link_description'     => $this->description,
443
+				'link_cat'             => (int) $cat_id,
444
+				'link_rss'             => $this->rss,
445
+				'link_banner'          => $this->banner,
446
+				'link_back'            => $this->back,
447
+				'link_uid'             => '',
448
+				'link_flags'           => 7,
449
+				'link_flag'            => $this->flag,
450
+				'link_bitfield'        => '',
451
+				'link_pagerank'        => (int) $pagerank,
452
+				'link_thumb'           => $thumb,
453
+			];
454
+
455
+			if ($this->description) {
456
+				generate_text_for_storage($this->description, $data_edit['link_uid'], $data_edit['link_bitfield'], $data_edit['link_flags'], (bool) $this->config['allow_bbcode'], (bool) $this->config['allow_post_links'], (bool) $this->config['allow_smilies']);
457
+			}
458
+
459
+			$need_approval = ($this->categorie->need_approval() && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_')) ? true : false;
460
+
461
+			if ($mode == 'edit') {
462
+				$data_edit['link_cat_old'] = $this->request->variable('old_cat_id', 0);
463
+				$this->link->edit($data_edit, $link_id, $need_approval);
464
+			} else {
465
+				$data_add = [
466
+					'link_time'            => time(),
467
+					'link_view'            => 0,
468
+					'link_active'          => $need_approval ? false : true,
469
+					'link_user_id'         => $this->user->data['user_id'],
470
+				];
471
+
472
+				$data_add = array_merge($data_edit, $data_add);
473
+
474
+				$this->link->add($data_add, $need_approval);
475
+			}
476
+
477
+			$meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
478
+			meta_refresh(3, $meta_info);
479
+			$message = ($need_approval) ? $this->user->lang['DIR_'.strtoupper($mode).'_SITE_ACTIVE'] : $this->user->lang['DIR_'.strtoupper($mode).'_SITE_OK'];
480
+			$message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_base_controller').'">', '</a>').'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]).'">', '</a>');
481
+
482
+			return $this->helper->message($message);
483
+		} else {
484
+			if ($mode == 'edit') {
485
+				$this->s_hidden_fields = [
486
+					'old_cat_id'    => $this->request->variable('old_cat_id', 0),
487
+					'old_banner'    => $this->request->variable('old_banner', ''),
488
+				];
489
+			}
490
+
491
+			$this->template->assign_vars([
492
+				'ERROR'    => (isset($error)) ? implode('<br />', $error) : '',
493
+			]);
494
+		}
495
+	}
496
+
497
+	/**
498
+	 * Display a banner.
499
+	 *
500
+	 * @param string $banner_img Path to banner file
501
+	 *
502
+	 * @return Response object
503
+	 */
504
+	public function return_banner($banner_img)
505
+	{
506
+		if (!function_exists('file_gc')) {
507
+			include $this->root_path.'includes/functions_download.'.$this->php_ext;
508
+		}
509
+
510
+		$file_path = $this->dir_helper->get_banner_path($banner_img);
511
+
512
+		if ((@file_exists($file_path) && @is_readable($file_path))) {
513
+			$response = new BinaryFileResponse($file_path);
514
+			$response->setContentDisposition('inline', $banner_img);
515
+
516
+			// Without fileinfo extension, Symfony is unable to guess the mime type
517
+			if (!extension_loaded('fileinfo')) {
518
+				$image_data = @getimagesize($file_path);
519
+				$response->headers->set('Content-Type', image_type_to_mime_type($image_data[2]));
520
+			}
521
+		} else {
522
+			$response = new Response();
523
+			$response->setStatusCode(404);
524
+		}
525
+		file_gc(false);
526
+
527
+		return $response;
528
+	}
529
+
530
+	/**
531
+	 * Populate form when an error occurred.
532
+	 *
533
+	 * @param int    $cat_id The category ID
534
+	 * @param string $mode   add|edit
535
+	 * @param string $title  Page title (depends of $mode)
536
+	 *
537
+	 * @return null
538
+	 */
539
+	private function _populate_form($cat_id, $mode, $title)
540
+	{
541
+		global $phpbb_extension_manager;
542
+
543
+		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new') {
544
+			$this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
545
+
546
+			$this->user->add_lang('ucp');
547
+
548
+			$this->template->assign_vars([
549
+				'CAPTCHA_TEMPLATE'        => $this->captcha->get_template(),
550
+			]);
551
+		}
552
+
553
+		$this->user->add_lang('posting');
554
+
555
+		if (!function_exists('display_custom_bbcodes')) {
556
+			include $this->root_path.'includes/functions_display.'.$this->php_ext;
557
+		}
558
+		display_custom_bbcodes();
559
+		add_form_key('dir_form');
560
+
561
+		$ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false);
562
+		$flag_path = $ext_path.'images/flags/';
563
+
564
+		$s_guest = (!$this->user->data['is_registered'] || !empty($this->guest_email));
565
+		$s_rss = $this->config['dir_activ_rss'];
566
+		$s_banner = $this->config['dir_activ_banner'];
567
+		$s_back = $this->categorie->data['cat_link_back'];
568
+		$s_flag = $this->config['dir_activ_flag'];
569
+
570
+		$this->template->assign_vars([
571
+			'BBCODE_STATUS'            => ($this->config['allow_bbcode']) ? $this->user->lang('BBCODE_IS_ON', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>') : $this->user->lang('BBCODE_IS_OFF', '<a href="'.append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode').'">', '</a>'),
572
+			'IMG_STATUS'               => ($this->config['allow_bbcode']) ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'],
573
+			'SMILIES_STATUS'           => ($this->config['allow_smilies']) ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'],
574
+			'URL_STATUS'               => ($this->config['allow_post_links']) ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'],
575
+			'FLASH_STATUS'             => ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'],
576
+
577
+			'L_TITLE'                  => $title,
578
+			'L_DIR_DESCRIPTION_EXP'    => $this->user->lang('DIR_DESCRIPTION_EXP', $this->config['dir_length_describe']),
579
+			'L_DIR_SUBMIT_TYPE'        => $this->categorie->dir_submit_type($this->categorie->need_approval()),
580
+			'L_DIR_SITE_BANN_EXP'      => $this->user->lang('DIR_SITE_BANN_EXP', $this->config['dir_banner_width'], $this->config['dir_banner_height']),
581
+
582
+			'S_GUEST'                  => $s_guest ? true : false,
583
+			'S_RSS'                    => $s_rss ? true : false,
584
+			'S_BANNER'                 => $s_banner ? true : false,
585
+			'S_BACK'                   => $s_back ? true : false,
586
+			'S_FLAG'                   => $s_flag ? true : false,
587
+			'S_BBCODE_ALLOWED'         => (bool) $this->config['allow_bbcode'],
588
+			'S_BBCODE_IMG'             => (bool) $this->config['allow_bbcode'],
589
+			'S_BBCODE_FLASH'           => ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? true : false,
590
+			'S_BBCODE_QUOTE'           => true,
591
+			'S_LINKS_ALLOWED'          => (bool) $this->config['allow_post_links'],
592
+
593
+			'DIR_FLAG_PATH'            => $flag_path,
594
+			'DIR_FLAG_IMAGE'           => $this->flag ? $this->dir_helper->get_img_path('flags', $this->flag) : '',
595
+
596
+			'EDIT_MODE'                => ($mode == 'edit') ? true : false,
597
+
598
+			'SITE_NAME'                => isset($this->site_name) ? $this->site_name : '',
599
+			'SITE_URL'                 => isset($this->url) ? $this->url : '',
600
+			'DESCRIPTION'              => isset($this->description) ? $this->description : '',
601
+			'GUEST_EMAIL'              => isset($this->guest_email) ? $this->guest_email : '',
602
+			'RSS'                      => isset($this->rss) ? $this->rss : '',
603
+			'BANNER'                   => isset($this->banner) ? $this->banner : '',
604
+			'BACK'                     => isset($this->back) ? $this->back : '',
605
+			'S_POST_ACTION'            => '',
606
+			'S_CATLIST'                => $this->categorie->make_cat_select($cat_id),
607
+			'S_LIST_FLAG'              => $this->link->get_dir_flag_list($flag_path, $this->flag),
608
+			'S_DESC_STAR'              => (@$this->categorie->data['cat_must_describe']) ? '*' : '',
609
+			'S_ROOT'                   => $cat_id,
610
+			'S_HIDDEN_FIELDS'          => build_hidden_fields($this->s_hidden_fields),
611
+		]);
612
+	}
613 613
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -378,17 +378,17 @@
 block discarded – undo
378 378
             'site_name' => [
379 379
                 ['string', false, 1, 100], ],
380 380
             'website'        => [
381
-                ['string',    false, 12, 255],
382
-                ['match',    true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
381
+                ['string', false, 12, 255],
382
+                ['match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
383 383
             'description'    => [
384 384
                 ['string', !$this->categorie->data['cat_must_describe'], 1, $this->config['dir_length_describe']], ],
385 385
             'rss'            => [
386 386
                 ['string', true, 12, 255],
387
-                ['match',    empty($this->rss), '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
387
+                ['match', empty($this->rss), '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i'], ],
388 388
             'banner'        => [
389 389
                 ['string', true, 5, 255], ],
390 390
             'back'            => [
391
-                ['string',    !$this->categorie->data['cat_link_back'], 12, 255],
391
+                ['string', !$this->categorie->data['cat_link_back'], 12, 255],
392 392
                 [[$this->link, 'link_back'], true], ],
393 393
             'cat'            => [
394 394
                 ['num', '', 1], ],
Please login to merge, or discard this patch.
Braces   +77 added lines, -36 removed lines patch added patch discarded remove patch
@@ -115,7 +115,8 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function delete_link($cat_id, $link_id)
117 117
     {
118
-        if ($this->request->is_set_post('cancel')) {
118
+        if ($this->request->is_set_post('cancel'))
119
+        {
119 120
             $redirect = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
120 121
             redirect($redirect);
121 122
         }
@@ -126,17 +127,20 @@  discard block
 block discarded – undo
126 127
         $result = $this->db->sql_query($sql);
127 128
         $link_data = $this->db->sql_fetchrow($result);
128 129
 
129
-        if (empty($link_data)) {
130
+        if (empty($link_data))
131
+        {
130 132
             throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
131 133
         }
132 134
 
133 135
         $delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $link_data['link_user_id'] && $this->auth->acl_get('u_delete_dir')));
134 136
 
135
-        if (!$delete_allowed) {
137
+        if (!$delete_allowed)
138
+        {
136 139
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
137 140
         }
138 141
 
139
-        if (confirm_box(true)) {
142
+        if (confirm_box(true))
143
+        {
140 144
             $this->link->del($cat_id, $link_id);
141 145
 
142 146
             $meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]);
@@ -144,7 +148,9 @@  discard block
 block discarded – undo
144 148
             $message = $this->user->lang['DIR_DELETE_OK'].'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_base_controller').'">', '</a>').'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]).'">', '</a>');
145 149
 
146 150
             return $this->helper->message($message);
147
-        } else {
151
+        }
152
+        else
153
+        {
148 154
             confirm_box(false, 'DIR_DELETE_SITE');
149 155
         }
150 156
     }
@@ -170,7 +176,8 @@  discard block
 block discarded – undo
170 176
 
171 177
         $edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == (int) $link_data['link_user_id'] && $this->auth->acl_get('u_edit_dir'))));
172 178
 
173
-        if (!$edit_allowed) {
179
+        if (!$edit_allowed)
180
+        {
174 181
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
175 182
         }
176 183
 
@@ -187,11 +194,15 @@  discard block
 block discarded – undo
187 194
         $this->categorie->get($cat_id);
188 195
 
189 196
         // If form is done
190
-        if ($submit || $refresh) {
191
-            if (false != ($result = $this->_data_processing($cat_id, $link_id, 'edit'))) {
197
+        if ($submit || $refresh)
198
+        {
199
+            if (false != ($result = $this->_data_processing($cat_id, $link_id, 'edit')))
200
+            {
192 201
                 return $result;
193 202
             }
194
-        } else {
203
+        }
204
+        else
205
+        {
195 206
             $sql = 'SELECT link_id, link_uid, link_flags, link_bitfield, link_cat, link_url, link_description, link_guest_email, link_name, link_rss, link_back, link_banner, link_flag, link_cat, link_time
196 207
 				FROM '.DIR_LINK_TABLE.'
197 208
 				WHERE link_id = '.(int) $link_id;
@@ -199,7 +210,8 @@  discard block
 block discarded – undo
199 210
 
200 211
             $site = $this->db->sql_fetchrow($result);
201 212
 
202
-            if (empty($site['link_id'])) {
213
+            if (empty($site['link_id']))
214
+            {
203 215
                 throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
204 216
             }
205 217
 
@@ -237,7 +249,8 @@  discard block
 block discarded – undo
237 249
      */
238 250
     public function new_link($cat_id)
239 251
     {
240
-        if (!$this->auth->acl_get('u_submit_dir')) {
252
+        if (!$this->auth->acl_get('u_submit_dir'))
253
+        {
241 254
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
242 255
         }
243 256
 
@@ -254,14 +267,17 @@  discard block
 block discarded – undo
254 267
         $this->categorie->get($cat_id);
255 268
 
256 269
         // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
257
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
270
+        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'])
271
+        {
258 272
             $this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
259 273
             $this->captcha->init(CONFIRM_POST);
260 274
         }
261 275
 
262 276
         // If form is done
263
-        if ($submit || $refresh) {
264
-            if (false != ($result = $this->_data_processing($cat_id))) {
277
+        if ($submit || $refresh)
278
+        {
279
+            if (false != ($result = $this->_data_processing($cat_id)))
280
+            {
265 281
                 return $result;
266 282
             }
267 283
         }
@@ -295,7 +311,8 @@  discard block
 block discarded – undo
295 311
     {
296 312
         $this->categorie->get($cat_id);
297 313
 
298
-        if (!$this->auth->acl_get('u_vote_dir') || !$this->categorie->data['cat_allow_votes']) {
314
+        if (!$this->auth->acl_get('u_vote_dir') || !$this->categorie->data['cat_allow_votes'])
315
+        {
299 316
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
300 317
         }
301 318
 
@@ -311,7 +328,8 @@  discard block
 block discarded – undo
311 328
         $result = $this->db->sql_query($sql);
312 329
         $data = $this->db->sql_fetchrow($result);
313 330
 
314
-        if (!empty($data['vote_link_id'])) {
331
+        if (!empty($data['vote_link_id']))
332
+        {
315 333
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_VOTE');
316 334
         }
317 335
 
@@ -337,11 +355,13 @@  discard block
 block discarded – undo
337 355
      */
338 356
     private function _data_processing($cat_id, $link_id = 0, $mode = 'new')
339 357
     {
340
-        if (($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir')) || ($mode == 'new' && !$this->auth->acl_get('u_submit_dir'))) {
358
+        if (($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir')) || ($mode == 'new' && !$this->auth->acl_get('u_submit_dir')))
359
+        {
341 360
             throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
342 361
         }
343 362
 
344
-        if (!check_form_key('dir_form')) {
363
+        if (!check_form_key('dir_form'))
364
+        {
345 365
             return $this->helper->message('FORM_INVALID');
346 366
         }
347 367
 
@@ -354,7 +374,8 @@  discard block
 block discarded – undo
354 374
         $this->back = $this->request->variable('back', '');
355 375
         $this->flag = $this->request->variable('flag', '');
356 376
 
357
-        if (!function_exists('validate_data')) {
377
+        if (!function_exists('validate_data'))
378
+        {
358 379
             include $this->root_path.'includes/functions_user.'.$this->php_ext;
359 380
         }
360 381
 
@@ -399,22 +420,27 @@  discard block
 block discarded – undo
399 420
         $error = array_map([$this->user, 'lang'], $error);
400 421
 
401 422
         // We check that url have good format
402
-        if (preg_match('/^(http|https):\/\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url)) {
423
+        if (preg_match('/^(http|https):\/\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url))
424
+        {
403 425
             $error[] = $this->user->lang['DIR_ERROR_CHECK_URL'];
404 426
         }
405 427
 
406
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
428
+        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'])
429
+        {
407 430
             $vc_response = $this->captcha->validate($data);
408
-            if ($vc_response !== false) {
431
+            if ($vc_response !== false)
432
+            {
409 433
                 $error[] = $vc_response;
410 434
             }
411 435
 
412
-            if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
436
+            if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts'])
437
+            {
413 438
                 $error[] = $this->user->lang['TOO_MANY_ADDS'];
414 439
             }
415 440
         }
416 441
 
417
-        if (!$error) {
442
+        if (!$error)
443
+        {
418 444
             /*
419 445
             * No errrors, we execute heavy tasks wich need a valid url
420 446
             */
@@ -430,7 +456,8 @@  discard block
 block discarded – undo
430 456
         }
431 457
 
432 458
         // Still no errors?? So let's go!
433
-        if (!$error) {
459
+        if (!$error)
460
+        {
434 461
             $this->banner = (!$this->banner && !$this->request->is_set_post('delete_banner')) ? $this->request->variable('old_banner', '') : $this->banner;
435 462
             $this->url = $this->link->clean_url($this->url);
436 463
 
@@ -452,16 +479,20 @@  discard block
 block discarded – undo
452 479
                 'link_thumb'           => $thumb,
453 480
             ];
454 481
 
455
-            if ($this->description) {
482
+            if ($this->description)
483
+            {
456 484
                 generate_text_for_storage($this->description, $data_edit['link_uid'], $data_edit['link_bitfield'], $data_edit['link_flags'], (bool) $this->config['allow_bbcode'], (bool) $this->config['allow_post_links'], (bool) $this->config['allow_smilies']);
457 485
             }
458 486
 
459 487
             $need_approval = ($this->categorie->need_approval() && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_')) ? true : false;
460 488
 
461
-            if ($mode == 'edit') {
489
+            if ($mode == 'edit')
490
+            {
462 491
                 $data_edit['link_cat_old'] = $this->request->variable('old_cat_id', 0);
463 492
                 $this->link->edit($data_edit, $link_id, $need_approval);
464
-            } else {
493
+            }
494
+            else
495
+            {
465 496
                 $data_add = [
466 497
                     'link_time'            => time(),
467 498
                     'link_view'            => 0,
@@ -480,8 +511,11 @@  discard block
 block discarded – undo
480 511
             $message = $message.'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_base_controller').'">', '</a>').'<br /><br />'.$this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="'.$this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $cat_id]).'">', '</a>');
481 512
 
482 513
             return $this->helper->message($message);
483
-        } else {
484
-            if ($mode == 'edit') {
514
+        }
515
+        else
516
+        {
517
+            if ($mode == 'edit')
518
+            {
485 519
                 $this->s_hidden_fields = [
486 520
                     'old_cat_id'    => $this->request->variable('old_cat_id', 0),
487 521
                     'old_banner'    => $this->request->variable('old_banner', ''),
@@ -503,22 +537,27 @@  discard block
 block discarded – undo
503 537
      */
504 538
     public function return_banner($banner_img)
505 539
     {
506
-        if (!function_exists('file_gc')) {
540
+        if (!function_exists('file_gc'))
541
+        {
507 542
             include $this->root_path.'includes/functions_download.'.$this->php_ext;
508 543
         }
509 544
 
510 545
         $file_path = $this->dir_helper->get_banner_path($banner_img);
511 546
 
512
-        if ((@file_exists($file_path) && @is_readable($file_path))) {
547
+        if ((@file_exists($file_path) && @is_readable($file_path)))
548
+        {
513 549
             $response = new BinaryFileResponse($file_path);
514 550
             $response->setContentDisposition('inline', $banner_img);
515 551
 
516 552
             // Without fileinfo extension, Symfony is unable to guess the mime type
517
-            if (!extension_loaded('fileinfo')) {
553
+            if (!extension_loaded('fileinfo'))
554
+            {
518 555
                 $image_data = @getimagesize($file_path);
519 556
                 $response->headers->set('Content-Type', image_type_to_mime_type($image_data[2]));
520 557
             }
521
-        } else {
558
+        }
559
+        else
560
+        {
522 561
             $response = new Response();
523 562
             $response->setStatusCode(404);
524 563
         }
@@ -540,7 +579,8 @@  discard block
 block discarded – undo
540 579
     {
541 580
         global $phpbb_extension_manager;
542 581
 
543
-        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new') {
582
+        if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new')
583
+        {
544 584
             $this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
545 585
 
546 586
             $this->user->add_lang('ucp');
@@ -552,7 +592,8 @@  discard block
 block discarded – undo
552 592
 
553 593
         $this->user->add_lang('posting');
554 594
 
555
-        if (!function_exists('display_custom_bbcodes')) {
595
+        if (!function_exists('display_custom_bbcodes'))
596
+        {
556 597
             include $this->root_path.'includes/functions_display.'.$this->php_ext;
557 598
         }
558 599
         display_custom_bbcodes();
Please login to merge, or discard this patch.