Completed
Pull Request — master (#25)
by Erwan
04:33
created
core/link.php 2 patches
Indentation   +1074 added lines, -1074 removed lines patch added patch discarded remove patch
@@ -9,1126 +9,1126 @@
 block discarded – undo
9 9
 
10 10
 class link
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\notification\manager */
34
-    protected $notification;
35
-
36
-    /** @var \ernadoo\phpbbdirectory\core\helper */
37
-    protected $dir_helper;
38
-
39
-    /** @var string phpBB root path */
40
-    protected $root_path;
41
-
42
-    /** @var string phpEx */
43
-    protected $php_ext;
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\notification\manager         $notification Notification object
56
-     * @param \ernadoo\phpbbdirectory\core\helper $dir_helper   PhpBB Directory extension helper object
57
-     * @param string                              $root_path    phpBB root path
58
-     * @param string                              $php_ext      phpEx
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\notification\manager $notification, \ernadoo\phpbbdirectory\core\helper $dir_helper, $root_path, $php_ext)
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->notification = $notification;
70
-        $this->dir_helper = $dir_helper;
71
-        $this->root_path = $root_path;
72
-        $this->php_ext = $php_ext;
73
-    }
74
-
75
-    /**
76
-     * Add a link into db.
77
-     *
78
-     * @param array $data          Contains all data to insert in db
79
-     * @param bool  $need_approval Links needs to be approved?
80
-     *
81
-     * @return null
82
-     */
83
-    public function add($data, $need_approval)
84
-    {
85
-        $notification_data = [];
86
-
87
-        $this->db->sql_transaction('begin');
88
-
89
-        $sql = 'INSERT INTO '.DIR_LINK_TABLE.' '.$this->db->sql_build_array('INSERT', $data);
90
-        $this->db->sql_query($sql);
91
-        $notification_data['link_id'] = $this->db->sql_nextid();
92
-
93
-        if (!$need_approval || $this->auth->acl_get('a_') || $this->auth->acl_get('m_')) {
94
-            $sql = 'UPDATE '.DIR_CAT_TABLE.'
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\notification\manager */
34
+	protected $notification;
35
+
36
+	/** @var \ernadoo\phpbbdirectory\core\helper */
37
+	protected $dir_helper;
38
+
39
+	/** @var string phpBB root path */
40
+	protected $root_path;
41
+
42
+	/** @var string phpEx */
43
+	protected $php_ext;
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\notification\manager         $notification Notification object
56
+	 * @param \ernadoo\phpbbdirectory\core\helper $dir_helper   PhpBB Directory extension helper object
57
+	 * @param string                              $root_path    phpBB root path
58
+	 * @param string                              $php_ext      phpEx
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\notification\manager $notification, \ernadoo\phpbbdirectory\core\helper $dir_helper, $root_path, $php_ext)
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->notification = $notification;
70
+		$this->dir_helper = $dir_helper;
71
+		$this->root_path = $root_path;
72
+		$this->php_ext = $php_ext;
73
+	}
74
+
75
+	/**
76
+	 * Add a link into db.
77
+	 *
78
+	 * @param array $data          Contains all data to insert in db
79
+	 * @param bool  $need_approval Links needs to be approved?
80
+	 *
81
+	 * @return null
82
+	 */
83
+	public function add($data, $need_approval)
84
+	{
85
+		$notification_data = [];
86
+
87
+		$this->db->sql_transaction('begin');
88
+
89
+		$sql = 'INSERT INTO '.DIR_LINK_TABLE.' '.$this->db->sql_build_array('INSERT', $data);
90
+		$this->db->sql_query($sql);
91
+		$notification_data['link_id'] = $this->db->sql_nextid();
92
+
93
+		if (!$need_approval || $this->auth->acl_get('a_') || $this->auth->acl_get('m_')) {
94
+			$sql = 'UPDATE '.DIR_CAT_TABLE.'
95 95
 				SET cat_links = cat_links + 1
96 96
 				WHERE cat_id = '.(int) $data['link_cat'];
97
-            $this->db->sql_query($sql);
98
-
99
-            $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website';
100
-        } elseif ($this->config['dir_mail']) {
101
-            $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
102
-        }
103
-
104
-        $this->db->sql_transaction('commit');
105
-
106
-        if (isset($notification_type)) {
107
-            $notification_data = array_merge($notification_data,
108
-                [
109
-                    'user_from'            => (int) $data['link_user_id'],
110
-                    'link_name'            => $data['link_name'],
111
-                    'link_url'             => $data['link_url'],
112
-                    'link_description'     => $data['link_description'],
113
-                    'cat_id'               => (int) $data['link_cat'],
114
-                    'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $data['link_cat']),
115
-                ]
116
-            );
117
-
118
-            $this->notification->add_notifications($notification_type, $notification_data);
119
-        }
120
-    }
121
-
122
-    /**
123
-     * Edit a link of the db.
124
-     *
125
-     * @param array $data          Contains all data to edit in db
126
-     * @param int   $link_id       is link's id, for WHERE clause
127
-     * @param bool  $need_approval Links needs to be approved?
128
-     *
129
-     * @return null
130
-     */
131
-    public function edit($data, $link_id, $need_approval)
132
-    {
133
-        $notification_data = [
134
-            'link_id'              => (int) $link_id,
135
-            'user_from'            => (int) $data['link_user_id'],
136
-            'link_name'            => $data['link_name'],
137
-            'link_description'     => $data['link_description'],
138
-            'cat_id'               => (int) $data['link_cat'],
139
-            'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $data['link_cat']),
140
-        ];
141
-
142
-        $old_cat = array_pop($data);
143
-
144
-        if ($old_cat != $data['link_cat'] || $need_approval) {
145
-            $this->notification->delete_notifications('ernadoo.phpbbdirectory.notification.type.directory_website', (int) $link_id);
146
-
147
-            $this->db->sql_transaction('begin');
148
-
149
-            $sql = 'UPDATE '.DIR_CAT_TABLE.'
97
+			$this->db->sql_query($sql);
98
+
99
+			$notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website';
100
+		} elseif ($this->config['dir_mail']) {
101
+			$notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
102
+		}
103
+
104
+		$this->db->sql_transaction('commit');
105
+
106
+		if (isset($notification_type)) {
107
+			$notification_data = array_merge($notification_data,
108
+				[
109
+					'user_from'            => (int) $data['link_user_id'],
110
+					'link_name'            => $data['link_name'],
111
+					'link_url'             => $data['link_url'],
112
+					'link_description'     => $data['link_description'],
113
+					'cat_id'               => (int) $data['link_cat'],
114
+					'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $data['link_cat']),
115
+				]
116
+			);
117
+
118
+			$this->notification->add_notifications($notification_type, $notification_data);
119
+		}
120
+	}
121
+
122
+	/**
123
+	 * Edit a link of the db.
124
+	 *
125
+	 * @param array $data          Contains all data to edit in db
126
+	 * @param int   $link_id       is link's id, for WHERE clause
127
+	 * @param bool  $need_approval Links needs to be approved?
128
+	 *
129
+	 * @return null
130
+	 */
131
+	public function edit($data, $link_id, $need_approval)
132
+	{
133
+		$notification_data = [
134
+			'link_id'              => (int) $link_id,
135
+			'user_from'            => (int) $data['link_user_id'],
136
+			'link_name'            => $data['link_name'],
137
+			'link_description'     => $data['link_description'],
138
+			'cat_id'               => (int) $data['link_cat'],
139
+			'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $data['link_cat']),
140
+		];
141
+
142
+		$old_cat = array_pop($data);
143
+
144
+		if ($old_cat != $data['link_cat'] || $need_approval) {
145
+			$this->notification->delete_notifications('ernadoo.phpbbdirectory.notification.type.directory_website', (int) $link_id);
146
+
147
+			$this->db->sql_transaction('begin');
148
+
149
+			$sql = 'UPDATE '.DIR_CAT_TABLE.'
150 150
 				SET cat_links = cat_links - 1
151 151
 				WHERE cat_id = '.(int) $old_cat;
152
-            $this->db->sql_query($sql);
152
+			$this->db->sql_query($sql);
153 153
 
154
-            if (!$need_approval) {
155
-                $sql = 'UPDATE '.DIR_CAT_TABLE.'
154
+			if (!$need_approval) {
155
+				$sql = 'UPDATE '.DIR_CAT_TABLE.'
156 156
 					SET cat_links = cat_links + 1
157 157
 					WHERE cat_id = '.(int) $data['link_cat'];
158
-                $this->db->sql_query($sql);
158
+				$this->db->sql_query($sql);
159 159
 
160
-                $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website';
161
-            } else {
162
-                $data['link_active'] = false;
163
-                $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
164
-            }
160
+				$notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website';
161
+			} else {
162
+				$data['link_active'] = false;
163
+				$notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
164
+			}
165 165
 
166
-            $this->db->sql_transaction('commit');
166
+			$this->db->sql_transaction('commit');
167 167
 
168
-            $this->notification->add_notifications($notification_type, $notification_data);
169
-        }
168
+			$this->notification->add_notifications($notification_type, $notification_data);
169
+		}
170 170
 
171
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
171
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
172 172
 			SET '.$this->db->sql_build_array('UPDATE', $data).'
173 173
 			WHERE link_id = '.(int) $link_id;
174
-        $this->db->sql_query($sql);
175
-    }
176
-
177
-    /**
178
-     * Delete a link of the db.
179
-     *
180
-     * @param int   $cat_id  The category ID
181
-     * @param mixed $link_id Link's id, for WHERE clause
182
-     *
183
-     * @return null
184
-     */
185
-    public function del($cat_id, $link_id)
186
-    {
187
-        $this->db->sql_transaction('begin');
188
-
189
-        $url_array = is_array($link_id) ? $link_id : [$link_id];
190
-
191
-        // Delete links datas
192
-        $link_datas_ary = [
193
-            DIR_LINK_TABLE        => 'link_id',
194
-            DIR_COMMENT_TABLE     => 'comment_link_id',
195
-            DIR_VOTE_TABLE        => 'vote_link_id',
196
-        ];
197
-
198
-        $sql = 'SELECT link_banner
174
+		$this->db->sql_query($sql);
175
+	}
176
+
177
+	/**
178
+	 * Delete a link of the db.
179
+	 *
180
+	 * @param int   $cat_id  The category ID
181
+	 * @param mixed $link_id Link's id, for WHERE clause
182
+	 *
183
+	 * @return null
184
+	 */
185
+	public function del($cat_id, $link_id)
186
+	{
187
+		$this->db->sql_transaction('begin');
188
+
189
+		$url_array = is_array($link_id) ? $link_id : [$link_id];
190
+
191
+		// Delete links datas
192
+		$link_datas_ary = [
193
+			DIR_LINK_TABLE        => 'link_id',
194
+			DIR_COMMENT_TABLE     => 'comment_link_id',
195
+			DIR_VOTE_TABLE        => 'vote_link_id',
196
+		];
197
+
198
+		$sql = 'SELECT link_banner
199 199
 			FROM '.DIR_LINK_TABLE.'
200 200
 			WHERE '.$this->db->sql_in_set('link_id', $url_array);
201
-        $result = $this->db->sql_query($sql);
201
+		$result = $this->db->sql_query($sql);
202 202
 
203
-        while ($row = $this->db->sql_fetchrow($result)) {
204
-            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
205
-                $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
203
+		while ($row = $this->db->sql_fetchrow($result)) {
204
+			if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
205
+				$banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
206 206
 
207
-                if (file_exists($banner_img)) {
208
-                    @unlink($banner_img);
209
-                }
210
-            }
211
-        }
207
+				if (file_exists($banner_img)) {
208
+					@unlink($banner_img);
209
+				}
210
+			}
211
+		}
212 212
 
213
-        foreach ($link_datas_ary as $table => $field) {
214
-            $this->db->sql_query("DELETE FROM $table WHERE ".$this->db->sql_in_set($field, $url_array));
215
-        }
213
+		foreach ($link_datas_ary as $table => $field) {
214
+			$this->db->sql_query("DELETE FROM $table WHERE ".$this->db->sql_in_set($field, $url_array));
215
+		}
216 216
 
217
-        $sql = 'UPDATE '.DIR_CAT_TABLE.'
217
+		$sql = 'UPDATE '.DIR_CAT_TABLE.'
218 218
 			SET cat_links = cat_links - '.count($url_array).'
219 219
 			WHERE cat_id = '.(int) $cat_id;
220
-        $this->db->sql_query($sql);
220
+		$this->db->sql_query($sql);
221 221
 
222
-        $this->db->sql_transaction('commit');
222
+		$this->db->sql_transaction('commit');
223 223
 
224
-        foreach ($url_array as $link_id) {
225
-            $this->notification->delete_notifications([
226
-                'ernadoo.phpbbdirectory.notification.type.directory_website',
227
-                'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
228
-            ], $link_id);
229
-        }
224
+		foreach ($url_array as $link_id) {
225
+			$this->notification->delete_notifications([
226
+				'ernadoo.phpbbdirectory.notification.type.directory_website',
227
+				'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
228
+			], $link_id);
229
+		}
230 230
 
231
-        if ($this->request->is_ajax()) {
232
-            $sql = 'SELECT cat_links
231
+		if ($this->request->is_ajax()) {
232
+			$sql = 'SELECT cat_links
233 233
 				FROM '.DIR_CAT_TABLE.'
234 234
 				WHERE cat_id = '.(int) $cat_id;
235
-            $result = $this->db->sql_query($sql);
236
-            $data = $this->db->sql_fetchrow($result);
237
-
238
-            $json_response = new \phpbb\json_response();
239
-            $json_response->send([
240
-                'success' => true,
241
-
242
-                'MESSAGE_TITLE'    => $this->user->lang['INFORMATION'],
243
-                'MESSAGE_TEXT'     => $this->user->lang['DIR_DELETE_OK'],
244
-                'LINK_ID'          => $link_id,
245
-                'TOTAL_LINKS'      => $this->user->lang('DIR_NB_LINKS', (int) $data['cat_links']),
246
-            ]);
247
-        }
248
-    }
249
-
250
-    /**
251
-     * Increments link view counter.
252
-     *
253
-     * @param int $link_id Link's id, for WHERE clause
254
-     *
255
-     * @throws \phpbb\exception\http_exception
256
-     *
257
-     * @return null
258
-     */
259
-    public function view($link_id)
260
-    {
261
-        $sql = 'SELECT link_id, link_url
235
+			$result = $this->db->sql_query($sql);
236
+			$data = $this->db->sql_fetchrow($result);
237
+
238
+			$json_response = new \phpbb\json_response();
239
+			$json_response->send([
240
+				'success' => true,
241
+
242
+				'MESSAGE_TITLE'    => $this->user->lang['INFORMATION'],
243
+				'MESSAGE_TEXT'     => $this->user->lang['DIR_DELETE_OK'],
244
+				'LINK_ID'          => $link_id,
245
+				'TOTAL_LINKS'      => $this->user->lang('DIR_NB_LINKS', (int) $data['cat_links']),
246
+			]);
247
+		}
248
+	}
249
+
250
+	/**
251
+	 * Increments link view counter.
252
+	 *
253
+	 * @param int $link_id Link's id, for WHERE clause
254
+	 *
255
+	 * @throws \phpbb\exception\http_exception
256
+	 *
257
+	 * @return null
258
+	 */
259
+	public function view($link_id)
260
+	{
261
+		$sql = 'SELECT link_id, link_url
262 262
 			FROM '.DIR_LINK_TABLE.'
263 263
 			WHERE link_id = '.(int) $link_id;
264
-        $result = $this->db->sql_query($sql);
265
-        $data = $this->db->sql_fetchrow($result);
264
+		$result = $this->db->sql_query($sql);
265
+		$data = $this->db->sql_fetchrow($result);
266 266
 
267
-        if (empty($data['link_id'])) {
268
-            throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
269
-        }
267
+		if (empty($data['link_id'])) {
268
+			throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
269
+		}
270 270
 
271
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
271
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
272 272
 			SET link_view = link_view + 1
273 273
 			WHERE link_id = '.(int) $link_id;
274
-        $this->db->sql_query($sql);
275
-
276
-        redirect($data['link_url'], false, true);
277
-    }
278
-
279
-    /**
280
-     * Verify that an URL exist before add into db.
281
-     *
282
-     * @param string $url The URL to check
283
-     *
284
-     * @return bool True if url is reachable, else false.
285
-     */
286
-    public function checkurl($url)
287
-    {
288
-        $details = parse_url($url);
289
-
290
-        $default_port = 80;
291
-        $hostname = $details['host'];
292
-
293
-        if ($details['scheme'] == 'https') {
294
-            $default_port = 443;
295
-            $hostname = 'tls://'.$details['host'];
296
-        }
297
-
298
-        if (!isset($details['path'])) {
299
-            $details['path'] = '/';
300
-        }
301
-
302
-        $port = (isset($details['port']) && !empty($details['port'])) ? (int) $details['port'] : $default_port;
303
-
304
-        if ($sock = @fsockopen($hostname, $port, $errno, $errstr, 1)) {
305
-            $requete = 'GET '.$details['path']." HTTP/1.1\r\n";
306
-            $requete .= 'Host: '.$details['host']."\r\n\r\n";
307
-
308
-            // Send a HTTP GET header
309
-            fwrite($sock, $requete);
310
-            // answer from server
311
-            $str = fgets($sock, 1024);
312
-            preg_match("'HTTP/1\.. (.*) (.*)'U", $str, $parts);
313
-            fclose($sock);
314
-
315
-            return !($parts[1] == '404');
316
-        }
317
-
318
-        return false;
319
-    }
320
-
321
-    /**
322
-     * Delete the final '/', if no path.
323
-     *
324
-     * @param string $url URL to clean
325
-     *
326
-     * @return string $url	The correct string.
327
-     */
328
-    public function clean_url($url)
329
-    {
330
-        $details = parse_url($url);
331
-
332
-        if (isset($details['path']) && $details['path'] == '/' && !isset($details['query'])) {
333
-            return substr($url, 0, -1);
334
-        }
335
-
336
-        return $url;
337
-    }
338
-
339
-    /**
340
-     * Display a flag.
341
-     *
342
-     * @param array $data Link's data from db
343
-     *
344
-     * @return string Flag path.
345
-     */
346
-    public function display_flag($data)
347
-    {
348
-        global $phpbb_extension_manager;
349
-
350
-        $ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false);
351
-        $flag_path = $ext_path.'images/flags/';
352
-        $img_flag = 'no_flag.png';
353
-
354
-        if ($this->config['dir_activ_flag'] && !empty($data['link_flag']) && file_exists($flag_path.$data['link_flag'])) {
355
-            $img_flag = $data['link_flag'];
356
-        }
357
-
358
-        return $this->dir_helper->get_img_path('flags', $img_flag);
359
-    }
360
-
361
-    /**
362
-     * Calculate the link's note.
363
-     *
364
-     * @param int  $total_note   Sum of all link's notes
365
-     * @param int  $nb_vote      Number of votes
366
-     * @param bool $votes_status Votes are enable in this category?
367
-     *
368
-     * @return string $note			The calculated note.
369
-     */
370
-    public function display_note($total_note, $nb_vote, $votes_status)
371
-    {
372
-        if (!$votes_status) {
373
-            return;
374
-        }
375
-
376
-        $note = ($nb_vote < 1) ? '' : $total_note / $nb_vote;
377
-        $note = (strlen($note) > 2) ? number_format($note, 1) : $note;
378
-
379
-        return ($nb_vote) ? $this->user->lang('DIR_FROM_TEN', $note) : $this->user->lang['DIR_NO_NOTE'];
380
-    }
381
-
382
-    /**
383
-     * Display the vote form for auth users.
384
-     *
385
-     * @param array $data Link's data from db
386
-     *
387
-     * @return null|string Html combo list or nothing if votes are not available.
388
-     */
389
-    public function display_vote($data)
390
-    {
391
-        if ($this->user->data['is_registered'] && $this->auth->acl_get('u_vote_dir') && empty($data['vote_user_id'])) {
392
-            $list = '<select name="vote">';
393
-            for ($i = 0; $i <= 10; $i++) {
394
-                $list .= '<option value="'.$i.'"'.(($i == 5) ? ' selected="selected"' : '').'>'.$i.'</option>';
395
-            }
396
-            $list .= '</select>';
397
-
398
-            return $list;
399
-        }
400
-    }
401
-
402
-    /**
403
-     * Display the RSS icon.
404
-     *
405
-     * @param array $data Link's data from db
406
-     *
407
-     * @return null|string RSS feed URL or nothing.
408
-     */
409
-    public function display_rss($data)
410
-    {
411
-        if ($this->config['dir_activ_rss'] && !empty($data['link_rss'])) {
412
-            return $data['link_rss'];
413
-        }
414
-    }
415
-
416
-    /**
417
-     * Display link's thumb if thumb service enabled.
418
-     * if thumb don't exists in db or if a new service was choosen in acp
419
-     * thumb is research.
420
-     *
421
-     * @param array $data Link's data from db
422
-     *
423
-     * @return string|null Thumb or null.
424
-     */
425
-    public function display_thumb($data)
426
-    {
427
-        if ($this->config['dir_activ_thumb']) {
428
-            if (!$data['link_thumb'] || ($this->config['dir_thumb_service_reverse'] && (!strstr($data['link_thumb'], 'ascreen.jpg') && (!strstr($data['link_thumb'], $this->config['dir_thumb_service']))))) {
429
-                $thumb = $this->thumb_process($data['link_url']);
430
-
431
-                $sql = 'UPDATE '.DIR_LINK_TABLE.'
274
+		$this->db->sql_query($sql);
275
+
276
+		redirect($data['link_url'], false, true);
277
+	}
278
+
279
+	/**
280
+	 * Verify that an URL exist before add into db.
281
+	 *
282
+	 * @param string $url The URL to check
283
+	 *
284
+	 * @return bool True if url is reachable, else false.
285
+	 */
286
+	public function checkurl($url)
287
+	{
288
+		$details = parse_url($url);
289
+
290
+		$default_port = 80;
291
+		$hostname = $details['host'];
292
+
293
+		if ($details['scheme'] == 'https') {
294
+			$default_port = 443;
295
+			$hostname = 'tls://'.$details['host'];
296
+		}
297
+
298
+		if (!isset($details['path'])) {
299
+			$details['path'] = '/';
300
+		}
301
+
302
+		$port = (isset($details['port']) && !empty($details['port'])) ? (int) $details['port'] : $default_port;
303
+
304
+		if ($sock = @fsockopen($hostname, $port, $errno, $errstr, 1)) {
305
+			$requete = 'GET '.$details['path']." HTTP/1.1\r\n";
306
+			$requete .= 'Host: '.$details['host']."\r\n\r\n";
307
+
308
+			// Send a HTTP GET header
309
+			fwrite($sock, $requete);
310
+			// answer from server
311
+			$str = fgets($sock, 1024);
312
+			preg_match("'HTTP/1\.. (.*) (.*)'U", $str, $parts);
313
+			fclose($sock);
314
+
315
+			return !($parts[1] == '404');
316
+		}
317
+
318
+		return false;
319
+	}
320
+
321
+	/**
322
+	 * Delete the final '/', if no path.
323
+	 *
324
+	 * @param string $url URL to clean
325
+	 *
326
+	 * @return string $url	The correct string.
327
+	 */
328
+	public function clean_url($url)
329
+	{
330
+		$details = parse_url($url);
331
+
332
+		if (isset($details['path']) && $details['path'] == '/' && !isset($details['query'])) {
333
+			return substr($url, 0, -1);
334
+		}
335
+
336
+		return $url;
337
+	}
338
+
339
+	/**
340
+	 * Display a flag.
341
+	 *
342
+	 * @param array $data Link's data from db
343
+	 *
344
+	 * @return string Flag path.
345
+	 */
346
+	public function display_flag($data)
347
+	{
348
+		global $phpbb_extension_manager;
349
+
350
+		$ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false);
351
+		$flag_path = $ext_path.'images/flags/';
352
+		$img_flag = 'no_flag.png';
353
+
354
+		if ($this->config['dir_activ_flag'] && !empty($data['link_flag']) && file_exists($flag_path.$data['link_flag'])) {
355
+			$img_flag = $data['link_flag'];
356
+		}
357
+
358
+		return $this->dir_helper->get_img_path('flags', $img_flag);
359
+	}
360
+
361
+	/**
362
+	 * Calculate the link's note.
363
+	 *
364
+	 * @param int  $total_note   Sum of all link's notes
365
+	 * @param int  $nb_vote      Number of votes
366
+	 * @param bool $votes_status Votes are enable in this category?
367
+	 *
368
+	 * @return string $note			The calculated note.
369
+	 */
370
+	public function display_note($total_note, $nb_vote, $votes_status)
371
+	{
372
+		if (!$votes_status) {
373
+			return;
374
+		}
375
+
376
+		$note = ($nb_vote < 1) ? '' : $total_note / $nb_vote;
377
+		$note = (strlen($note) > 2) ? number_format($note, 1) : $note;
378
+
379
+		return ($nb_vote) ? $this->user->lang('DIR_FROM_TEN', $note) : $this->user->lang['DIR_NO_NOTE'];
380
+	}
381
+
382
+	/**
383
+	 * Display the vote form for auth users.
384
+	 *
385
+	 * @param array $data Link's data from db
386
+	 *
387
+	 * @return null|string Html combo list or nothing if votes are not available.
388
+	 */
389
+	public function display_vote($data)
390
+	{
391
+		if ($this->user->data['is_registered'] && $this->auth->acl_get('u_vote_dir') && empty($data['vote_user_id'])) {
392
+			$list = '<select name="vote">';
393
+			for ($i = 0; $i <= 10; $i++) {
394
+				$list .= '<option value="'.$i.'"'.(($i == 5) ? ' selected="selected"' : '').'>'.$i.'</option>';
395
+			}
396
+			$list .= '</select>';
397
+
398
+			return $list;
399
+		}
400
+	}
401
+
402
+	/**
403
+	 * Display the RSS icon.
404
+	 *
405
+	 * @param array $data Link's data from db
406
+	 *
407
+	 * @return null|string RSS feed URL or nothing.
408
+	 */
409
+	public function display_rss($data)
410
+	{
411
+		if ($this->config['dir_activ_rss'] && !empty($data['link_rss'])) {
412
+			return $data['link_rss'];
413
+		}
414
+	}
415
+
416
+	/**
417
+	 * Display link's thumb if thumb service enabled.
418
+	 * if thumb don't exists in db or if a new service was choosen in acp
419
+	 * thumb is research.
420
+	 *
421
+	 * @param array $data Link's data from db
422
+	 *
423
+	 * @return string|null Thumb or null.
424
+	 */
425
+	public function display_thumb($data)
426
+	{
427
+		if ($this->config['dir_activ_thumb']) {
428
+			if (!$data['link_thumb'] || ($this->config['dir_thumb_service_reverse'] && (!strstr($data['link_thumb'], 'ascreen.jpg') && (!strstr($data['link_thumb'], $this->config['dir_thumb_service']))))) {
429
+				$thumb = $this->thumb_process($data['link_url']);
430
+
431
+				$sql = 'UPDATE '.DIR_LINK_TABLE.'
432 432
 					SET link_thumb = "'.$this->db->sql_escape($thumb).'"
433 433
 					WHERE link_id = '.(int) $data['link_id'];
434
-                $this->db->sql_query($sql);
435
-
436
-                return $thumb;
437
-            }
438
-
439
-            return $data['link_thumb'];
440
-        }
441
-    }
442
-
443
-    /**
444
-     * Display and calculate PageRank if needed.
445
-     *
446
-     * @param array $data Link's data from db
447
-     *
448
-     * @return string Pagerank, 'n/a' or false
449
-     */
450
-    public function display_pagerank($data)
451
-    {
452
-        if ($this->config['dir_activ_pagerank']) {
453
-            if ($data['link_pagerank'] == '') {
454
-                $pagerank = $this->pagerank_process($data['link_url']);
455
-
456
-                $sql = 'UPDATE '.DIR_LINK_TABLE.'
434
+				$this->db->sql_query($sql);
435
+
436
+				return $thumb;
437
+			}
438
+
439
+			return $data['link_thumb'];
440
+		}
441
+	}
442
+
443
+	/**
444
+	 * Display and calculate PageRank if needed.
445
+	 *
446
+	 * @param array $data Link's data from db
447
+	 *
448
+	 * @return string Pagerank, 'n/a' or false
449
+	 */
450
+	public function display_pagerank($data)
451
+	{
452
+		if ($this->config['dir_activ_pagerank']) {
453
+			if ($data['link_pagerank'] == '') {
454
+				$pagerank = $this->pagerank_process($data['link_url']);
455
+
456
+				$sql = 'UPDATE '.DIR_LINK_TABLE.'
457 457
 					SET link_pagerank = '.(int) $pagerank.'
458 458
 					WHERE link_id = '.(int) $data['link_id'];
459
-                $this->db->sql_query($sql);
460
-            } else {
461
-                $pagerank = (int) $data['link_pagerank'];
462
-            }
463
-
464
-            $prpos = 40 * $pagerank / 10;
465
-            $prneg = 40 - $prpos;
466
-            $html = '<img src="http://www.google.com/images/pos.gif" width="'.$prpos.'" height="4" alt="'.$pagerank.'" /><img src="http://www.google.com/images/neg.gif" width="'.$prneg.'" height="4" alt="'.$pagerank.'" /> ';
467
-
468
-            $pagerank = $pagerank == '-1' ? $this->user->lang['DIR_PAGERANK_NOT_AVAILABLE'] : $this->user->lang('DIR_FROM_TEN', $pagerank);
469
-
470
-            return $html.$pagerank;
471
-        }
472
-
473
-        return false;
474
-    }
475
-
476
-    /**
477
-     * Display and resize a banner.
478
-     *
479
-     * @param array $data link's data from db
480
-     *
481
-     * @return string $s_banner	html code.
482
-     */
483
-    public function display_bann($data)
484
-    {
485
-        $s_banner = '';
486
-
487
-        if (!empty($data['link_banner'])) {
488
-            if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $data['link_banner'])) {
489
-                $img_src = $this->helper->route('ernadoo_phpbbdirectory_banner_controller', ['banner_img' => $data['link_banner']]);
490
-                $physical_path = $this->dir_helper->get_banner_path($data['link_banner']);
491
-            } else {
492
-                $img_src = $physical_path = $data['link_banner'];
493
-            }
494
-
495
-            list($width, $height) = @getimagesize($physical_path);
496
-            if (($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height']) && $this->config['dir_banner_width'] > 0 && $this->config['dir_banner_height'] > 0) {
497
-                $coef_w = $width / $this->config['dir_banner_width'];
498
-                $coef_h = $height / $this->config['dir_banner_height'];
499
-                $coef_max = max($coef_w, $coef_h);
500
-                $width /= $coef_max;
501
-                $height /= $coef_max;
502
-            }
503
-
504
-            $s_banner = '<img src="'.$img_src.'" width="'.$width.'" height="'.$height.'" alt="'.$data['link_name'].'" title="'.$data['link_name'].'" />';
505
-        }
506
-
507
-        return $s_banner;
508
-    }
509
-
510
-    /**
511
-     * Add a vote in db, for a specifi link.
512
-     *
513
-     * @param int $link_id Link_id from db
514
-     *
515
-     * @return null
516
-     */
517
-    public function add_vote($link_id)
518
-    {
519
-        $data = [
520
-            'vote_link_id'         => (int) $link_id,
521
-            'vote_user_id'         => $this->user->data['user_id'],
522
-            'vote_note'            => $this->request->variable('vote', 0),
523
-        ];
524
-
525
-        $this->db->sql_transaction('begin');
526
-
527
-        $sql = 'INSERT INTO '.DIR_VOTE_TABLE.' '.$this->db->sql_build_array('INSERT', $data);
528
-        $this->db->sql_query($sql);
529
-
530
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
459
+				$this->db->sql_query($sql);
460
+			} else {
461
+				$pagerank = (int) $data['link_pagerank'];
462
+			}
463
+
464
+			$prpos = 40 * $pagerank / 10;
465
+			$prneg = 40 - $prpos;
466
+			$html = '<img src="http://www.google.com/images/pos.gif" width="'.$prpos.'" height="4" alt="'.$pagerank.'" /><img src="http://www.google.com/images/neg.gif" width="'.$prneg.'" height="4" alt="'.$pagerank.'" /> ';
467
+
468
+			$pagerank = $pagerank == '-1' ? $this->user->lang['DIR_PAGERANK_NOT_AVAILABLE'] : $this->user->lang('DIR_FROM_TEN', $pagerank);
469
+
470
+			return $html.$pagerank;
471
+		}
472
+
473
+		return false;
474
+	}
475
+
476
+	/**
477
+	 * Display and resize a banner.
478
+	 *
479
+	 * @param array $data link's data from db
480
+	 *
481
+	 * @return string $s_banner	html code.
482
+	 */
483
+	public function display_bann($data)
484
+	{
485
+		$s_banner = '';
486
+
487
+		if (!empty($data['link_banner'])) {
488
+			if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $data['link_banner'])) {
489
+				$img_src = $this->helper->route('ernadoo_phpbbdirectory_banner_controller', ['banner_img' => $data['link_banner']]);
490
+				$physical_path = $this->dir_helper->get_banner_path($data['link_banner']);
491
+			} else {
492
+				$img_src = $physical_path = $data['link_banner'];
493
+			}
494
+
495
+			list($width, $height) = @getimagesize($physical_path);
496
+			if (($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height']) && $this->config['dir_banner_width'] > 0 && $this->config['dir_banner_height'] > 0) {
497
+				$coef_w = $width / $this->config['dir_banner_width'];
498
+				$coef_h = $height / $this->config['dir_banner_height'];
499
+				$coef_max = max($coef_w, $coef_h);
500
+				$width /= $coef_max;
501
+				$height /= $coef_max;
502
+			}
503
+
504
+			$s_banner = '<img src="'.$img_src.'" width="'.$width.'" height="'.$height.'" alt="'.$data['link_name'].'" title="'.$data['link_name'].'" />';
505
+		}
506
+
507
+		return $s_banner;
508
+	}
509
+
510
+	/**
511
+	 * Add a vote in db, for a specifi link.
512
+	 *
513
+	 * @param int $link_id Link_id from db
514
+	 *
515
+	 * @return null
516
+	 */
517
+	public function add_vote($link_id)
518
+	{
519
+		$data = [
520
+			'vote_link_id'         => (int) $link_id,
521
+			'vote_user_id'         => $this->user->data['user_id'],
522
+			'vote_note'            => $this->request->variable('vote', 0),
523
+		];
524
+
525
+		$this->db->sql_transaction('begin');
526
+
527
+		$sql = 'INSERT INTO '.DIR_VOTE_TABLE.' '.$this->db->sql_build_array('INSERT', $data);
528
+		$this->db->sql_query($sql);
529
+
530
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
531 531
 			SET link_vote = link_vote + 1,
532 532
 			link_note = link_note + '.(int) $data['vote_note'].'
533 533
 		WHERE link_id = '.(int) $link_id;
534
-        $this->db->sql_query($sql);
535
-
536
-        $this->db->sql_transaction('commit');
537
-
538
-        if ($this->request->is_ajax()) {
539
-            $sql = 'SELECT link_vote, link_note FROM '.DIR_LINK_TABLE.' WHERE link_id = '.(int) $link_id;
540
-            $result = $this->db->sql_query($sql);
541
-            $data = $this->db->sql_fetchrow($result);
542
-
543
-            $note = $this->display_note($data['link_note'], $data['link_vote'], true);
544
-
545
-            $json_response = new \phpbb\json_response();
546
-            $json_response->send([
547
-                'success' => true,
548
-
549
-                'MESSAGE_TITLE'    => $this->user->lang['INFORMATION'],
550
-                'MESSAGE_TEXT'     => $this->user->lang['DIR_VOTE_OK'],
551
-                'NOTE'             => $note,
552
-                'NB_VOTE'          => $this->user->lang('DIR_NB_VOTES', (int) $data['link_vote']),
553
-                'LINK_ID'          => $link_id,
554
-            ]);
555
-        }
556
-    }
557
-
558
-    /**
559
-     * Search an appropriate thumb for url.
560
-     *
561
-     * @param string $url Link's url
562
-     *
563
-     * @return string The thumb url
564
-     */
565
-    public function thumb_process($url)
566
-    {
567
-        if (!$this->config['dir_activ_thumb']) {
568
-            return $this->root_path.'images/directory/nothumb.gif';
569
-        }
570
-
571
-        $details = parse_url($url);
572
-
573
-        $root_url = $details['scheme'].'://'.$details['host'];
574
-        $absolute_url = isset($details['path']) ? $root_url.$details['path'] : $root_url;
575
-
576
-        if ($this->config['dir_activ_thumb_remote'] && $this->_ascreen_exist($details['scheme'], $details['host'])) {
577
-            return $root_url.'/ascreen.jpg';
578
-        }
579
-
580
-        return $this->config['dir_thumb_service'].$absolute_url;
581
-    }
582
-
583
-    /**
584
-     * Check if ascreen thumb exists.
585
-     *
586
-     * @param string $protocol The protocol
587
-     * @param string $host     The hostname
588
-     *
589
-     * @return bool True if ascreen file exixts, else false
590
-     */
591
-    private function _ascreen_exist($protocol, $host)
592
-    {
593
-        if ($thumb_info = @getimagesize($protocol.'://'.$host.'/ascreen.jpg')) {
594
-            // Obviously this is an image, we did some additional tests
595
-            if ($thumb_info[0] == '120' && $thumb_info[1] == '90' && $thumb_info['mime'] == 'image/jpeg') {
596
-                return true;
597
-            }
598
-        }
599
-
600
-        return false;
601
-    }
602
-
603
-    /**
604
-     * Primary work on banner, can edit, copy or check a banner.
605
-     *
606
-     * @param string $banner The banner's remote url
607
-     * @param array  $error  The array error, passed by reference
608
-     *
609
-     * @return null
610
-     */
611
-    public function banner_process(&$banner, &$error)
612
-    {
613
-        $old_banner = $this->request->variable('old_banner', '');
614
-
615
-        $destination = $this->dir_helper->get_banner_path();
616
-
617
-        // Can we upload?
618
-        $can_upload = ($this->config['dir_storage_banner'] && file_exists($this->root_path.$destination) && phpbb_is_writable($this->root_path.$destination) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
619
-
620
-        if ($banner && $can_upload) {
621
-            $file = $this->_banner_upload($banner, $error);
622
-        } elseif ($banner) {
623
-            $file = $this->_banner_remote($banner, $error);
624
-        } elseif ($this->request->is_set_post('delete_banner') && $old_banner) {
625
-            $this->_banner_delete($old_banner);
626
-
627
-            return;
628
-        }
629
-
630
-        if (!count($error)) {
631
-            if ($banner && $old_banner && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $old_banner)) {
632
-                $this->_banner_delete($old_banner);
633
-            }
634
-
635
-            $banner = !empty($file) ? $file : '';
636
-        }
637
-    }
638
-
639
-    /**
640
-     * Copy a remonte banner to server.
641
-     * called by banner_process().
642
-     *
643
-     * @param string $banner The anner's remote url
644
-     * @param array  $error  The array error, passed by reference
645
-     *
646
-     * @return false|string String if no errors, else false
647
-     */
648
-    private function _banner_upload($banner, &$error)
649
-    {
650
-        // Init upload class
651
-        if (!class_exists('fileupload')) {
652
-            include $this->root_path.'includes/functions_upload.'.$this->php_ext;
653
-        }
654
-        $upload = new \fileupload('DIR_BANNER_', ['jpg', 'jpeg', 'gif', 'png'], $this->config['dir_banner_filesize']);
655
-
656
-        $file = $upload->remote_upload($banner);
657
-
658
-        $prefix = unique_id().'_';
659
-        $file->clean_filename('real', $prefix);
660
-
661
-        $destination = $this->dir_helper->get_banner_path();
662
-
663
-        // Move file and overwrite any existing image
664
-        $file->move_file($destination, true);
665
-
666
-        if (count($file->error)) {
667
-            $file->remove();
668
-            $error = array_merge($error, $file->error);
669
-
670
-            return false;
671
-        }
672
-
673
-        return $prefix.strtolower($file->uploadname);
674
-    }
675
-
676
-    /**
677
-     * Check than remote banner exists
678
-     * called by banner_process().
679
-     *
680
-     * @param string $banner The banner's remote url
681
-     * @param array  $error  The array error, passed by reference
682
-     *
683
-     * @return false|string String if no errors, else false
684
-     */
685
-    private function _banner_remote($banner, &$error)
686
-    {
687
-        if (!preg_match('#^(http|https|ftp)://#i', $banner)) {
688
-            $banner = 'http://'.$banner;
689
-        }
690
-        if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $banner)) {
691
-            $error[] = $this->user->lang['DIR_BANNER_URL_INVALID'];
692
-
693
-            return false;
694
-        }
695
-
696
-        // Make sure getimagesize works...
697
-        if (($image_data = @getimagesize($banner)) === false) {
698
-            $error[] = $this->user->lang['DIR_BANNER_UNABLE_GET_IMAGE_SIZE'];
699
-
700
-            return false;
701
-        }
702
-
703
-        if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) {
704
-            $error[] = $this->user->lang['DIR_BANNER_UNABLE_GET_IMAGE_SIZE'];
705
-
706
-            return false;
707
-        }
708
-
709
-        $width = $image_data[0];
710
-        $height = $image_data[1];
711
-
712
-        // Check image type
713
-        if (!class_exists('fileupload')) {
714
-            include $this->root_path.'includes/functions_upload.'.$this->php_ext;
715
-        }
716
-
717
-        $types = \fileupload::image_types();
718
-        $extension = strtolower(\filespec::get_extension($banner));
719
-
720
-        // Check if this is actually an image
721
-        if ($file_stream = @fopen($banner, 'r')) {
722
-            // Timeout after 1 second
723
-            stream_set_timeout($file_stream, 1);
724
-            // read some data to ensure headers are present
725
-            fread($file_stream, 1024);
726
-            $meta = stream_get_meta_data($file_stream);
727
-            if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers'])) {
728
-                $headers = $meta['wrapper_data']['headers'];
729
-            } elseif (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
730
-                $headers = $meta['wrapper_data'];
731
-            } else {
732
-                $headers = [];
733
-            }
734
-
735
-            foreach ($headers as $header) {
736
-                $header = preg_split('/ /', $header, 2);
737
-                if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type') {
738
-                    if (strpos($header[1], 'image/') !== 0) {
739
-                        $error[] = 'DIR_BANNER_URL_INVALID';
740
-                        fclose($file_stream);
741
-
742
-                        return false;
743
-                    } else {
744
-                        fclose($file_stream);
745
-                        break;
746
-                    }
747
-                }
748
-            }
749
-        } else {
750
-            $error[] = 'DIR_BANNER_URL_INVALID';
751
-
752
-            return false;
753
-        }
754
-
755
-        if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) {
756
-            if (!isset($types[$image_data[2]])) {
757
-                $error[] = $this->user->lang['UNABLE_GET_IMAGE_SIZE'];
758
-            } else {
759
-                $error[] = $this->user->lang('DIR_BANNER_IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
760
-            }
761
-
762
-            return false;
763
-        }
764
-
765
-        if (($this->config['dir_banner_width'] || $this->config['dir_banner_height']) && ($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height'])) {
766
-            $error[] = $this->user->lang('DIR_BANNER_WRONG_SIZE', $this->config['dir_banner_width'], $this->config['dir_banner_height'], $width, $height);
767
-
768
-            return false;
769
-        }
770
-
771
-        return $banner;
772
-    }
773
-
774
-    /**
775
-     * Delete a banner from server.
776
-     *
777
-     * @param string $file The file's name
778
-     *
779
-     * @return bool True if delete success, else false
780
-     */
781
-    private function _banner_delete($file)
782
-    {
783
-        if (file_exists($this->dir_helper->get_banner_path($file))) {
784
-            @unlink($this->dir_helper->get_banner_path($file));
785
-
786
-            return true;
787
-        }
788
-
789
-        return false;
790
-    }
791
-
792
-    /**
793
-     * PageRank Lookup (Based on Google Toolbar for Mozilla Firefox).
794
-     *
795
-     * @copyright 2012 HM2K <[email protected]>
796
-     *
797
-     * @link http://pagerank.phurix.net/
798
-     *
799
-     * @author James Wade <[email protected]>
800
-     *
801
-     * @version $Revision: 2.1 $
802
-     * @require PHP 4.3.0 (file_get_contents)
803
-     * @updated 06/10/11
804
-     *
805
-     * @param string $q The website URL
806
-     *
807
-     * @return string The calculated pagerank, or -1
808
-     */
809
-    public function pagerank_process($q)
810
-    {
811
-        $googleDomains = ['.com', '.com.tr', '.de', '.fr', '.be', '.ca', '.ro', '.ch'];
812
-        $seed = $this->user->lang['SEED'];
813
-        $result = 0x01020345;
814
-        $len = strlen($q);
815
-
816
-        for ($i = 0; $i < $len; $i++) {
817
-            $result ^= ord($seed[$i % strlen($seed)]) ^ ord($q[$i]);
818
-            $result = (($result >> 23) & 0x1ff) | $result << 9;
819
-        }
820
-
821
-        if (PHP_INT_MAX != 2147483647) {
822
-            $result = -(~($result & 0xFFFFFFFF) + 1);
823
-        }
824
-
825
-        $ch = sprintf('8%x', $result);
826
-        $url = 'http://%s/tbr?client=navclient-auto&ch=%s&features=Rank&q=info:%s';
827
-        $host = 'toolbarqueries.google'.$googleDomains[mt_rand(0, count($googleDomains) - 1)];
828
-
829
-        $url = sprintf($url, $host, $ch, $q);
830
-        @$pr = trim(file_get_contents($url, false));
831
-
832
-        if (is_numeric(substr(strrchr($pr, ':'), 1))) {
833
-            return substr(strrchr($pr, ':'), 1);
834
-        }
835
-
836
-        return '-1';
837
-    }
838
-
839
-    /**
840
-     * List flags.
841
-     *
842
-     * @param string $flag_path The flag directory path
843
-     * @param string $value     Selected flag
844
-     *
845
-     * @return string $list		Html code
846
-     */
847
-    public function get_dir_flag_list($flag_path, $value)
848
-    {
849
-        $list = '';
850
-
851
-        $this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory_flags');
852
-
853
-        $flags = $this->dir_helper->preg_grep_keys('/^DIR_FLAG_CODE_/i', $this->user->lang);
854
-
855
-        if (extension_loaded('intl')) {
856
-            $locale = $this->user->lang['USER_LANG'];
857
-
858
-            $col = new \Collator($locale);
859
-            $col->asort($flags);
860
-        } else {
861
-            asort($flags);
862
-        }
863
-
864
-        foreach ($flags as $file => $name) {
865
-            $img_file = strtolower(substr(strrchr($file, '_'), 1)).'.png';
866
-
867
-            if (file_exists($flag_path.$img_file)) {
868
-                $list .= '<option value="'.$img_file.'" '.(($img_file == $value) ? 'selected="selected"' : '').'>'.$name.'</option>';
869
-            }
870
-        }
871
-
872
-        return $list;
873
-    }
874
-
875
-    /**
876
-     * Display recents links added.
877
-     *
878
-     * @return null
879
-     */
880
-    public function recents()
881
-    {
882
-        if ($this->config['dir_recent_block']) {
883
-            $limit_sql = $this->config['dir_recent_rows'] * $this->config['dir_recent_columns'];
884
-            $exclude_array = explode(',', str_replace(' ', '', $this->config['dir_recent_exclude']));
885
-
886
-            $sql_array = [
887
-                'SELECT'      => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_thumb, u.user_id, u.username, u.user_colour, c.cat_name',
888
-                'FROM'        => [
889
-                        DIR_LINK_TABLE    => 'l', ],
890
-                'LEFT_JOIN'    => [
891
-                        [
892
-                            'FROM'    => [USERS_TABLE    => 'u'],
893
-                            'ON'      => 'l.link_user_id = u.user_id',
894
-                        ],
895
-                        [
896
-                            'FROM'    => [DIR_CAT_TABLE => 'c'],
897
-                            'ON'      => 'l.link_cat = c.cat_id',
898
-                        ],
899
-                ],
900
-                'WHERE'        => $this->db->sql_in_set('l.link_cat', $exclude_array, true).' AND l.link_active = 1',
901
-                'ORDER_BY'     => 'l.link_time DESC, l.link_id DESC', ];
902
-
903
-            $sql = $this->db->sql_build_query('SELECT', $sql_array);
904
-            $result = $this->db->sql_query_limit($sql, $limit_sql, 0);
905
-            $num = 0;
906
-            $rowset = [];
907
-
908
-            while ($site = $this->db->sql_fetchrow($result)) {
909
-                $rowset[$site['link_id']] = $site;
910
-            }
911
-            $this->db->sql_freeresult($result);
912
-
913
-            if (count($rowset)) {
914
-                $this->template->assign_block_vars('block', [
915
-                    'S_COL_WIDTH'            => (100 / $this->config['dir_recent_columns']).'%',
916
-                ]);
917
-
918
-                foreach ($rowset as $row) {
919
-                    if (($num % $this->config['dir_recent_columns']) == 0) {
920
-                        $this->template->assign_block_vars('block.row', []);
921
-                    }
922
-
923
-                    $this->template->assign_block_vars('block.row.col', [
924
-                        'UC_THUMBNAIL'               => '<a href="'.$row['link_url'].'" onclick="window.open(\''.$this->helper->route('ernadoo_phpbbdirectory_view_controller', ['link_id' => (int) $row['link_id']]).'\'); return false;"><img src="'.$row['link_thumb'].'" title="'.$row['link_name'].'" alt="'.$row['link_name'].'" /></a>',
925
-                        'NAME'                       => $row['link_name'],
926
-                        'USER'                       => get_username_string('full', $row['link_user_id'], $row['username'], $row['user_colour']),
927
-                        'TIME'                       => ($row['link_time']) ? $this->user->format_date($row['link_time']) : '',
928
-                        'CAT'                        => $row['cat_name'],
929
-                        'COUNT'                      => $row['link_view'],
930
-                        'COMMENT'                    => $row['link_comment'],
931
-
932
-                        'U_CAT'                   => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $row['link_cat']]),
933
-                        'U_COMMENT'               => $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $row['link_id']]),
934
-
935
-                        'L_DIR_SEARCH_NB_CLICKS'       => $this->user->lang('DIR_SEARCH_NB_CLICKS', (int) $row['link_view']),
936
-                        'L_DIR_SEARCH_NB_COMMS'        => $this->user->lang('DIR_SEARCH_NB_COMMS', (int) $row['link_comment']),
937
-                    ]);
938
-                    $num++;
939
-                }
940
-
941
-                while (($num % $this->config['dir_recent_columns']) != 0) {
942
-                    $this->template->assign_block_vars('block.row.col2', []);
943
-                    $num++;
944
-                }
945
-            }
946
-        }
947
-    }
948
-
949
-    /**
950
-     * Validate back link.
951
-     *
952
-     * @param string $remote_url Page URL contains the backlink
953
-     * @param bool   $optional   Link back is optional in this category?
954
-     * @param bool   $cron       This methos is called by con process?
955
-     *
956
-     * @return false|string Either false if validation succeeded or a string which will be used as the error message (with the variable name appended)
957
-     */
958
-    public function validate_link_back($remote_url, $optional, $cron = false)
959
-    {
960
-        if (!$cron) {
961
-            if (empty($remote_url) && $optional) {
962
-                return false;
963
-            }
964
-
965
-            if (!preg_match('#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i', $remote_url)) {
966
-                return 'DIR_ERROR_WRONG_DATA_BACK';
967
-            }
968
-        }
969
-
970
-        if (false === ($handle = @fopen($remote_url, 'r'))) {
971
-            return 'DIR_ERROR_NOT_FOUND_BACK';
972
-        }
973
-
974
-        $buff = '';
975
-
976
-        // Read by packet, faster than file_get_contents()
977
-        while (!feof($handle)) {
978
-            $buff .= fgets($handle, 256);
979
-
980
-            if (stristr($buff, $this->config['server_name'])) {
981
-                @fclose($handle);
982
-
983
-                return false;
984
-            }
985
-        }
986
-        @fclose($handle);
987
-
988
-        return 'DIR_ERROR_NO_LINK_BACK';
989
-    }
990
-
991
-    /**
992
-     * Check, for website with backlink specified, if backlink is always here.
993
-     * After $nb_check verification, website is deleted, otherwise, a notification is send to poster.
994
-     *
995
-     * @param int $cat_id     The categoryID
996
-     * @param int $nb_check   Number of check before demete a website
997
-     * @param int $next_prune Date of next auto check
998
-     *
999
-     * @return null
1000
-     */
1001
-    private function _check($cat_id, $nb_check, $next_prune)
1002
-    {
1003
-        $del_array = $update_array = [];
1004
-
1005
-        $sql_array = [
1006
-            'SELECT'      => 'link_id, link_cat, link_back, link_guest_email, link_nb_check, link_user_id, link_name, link_url, link_description, u.user_lang, u.user_dateformat',
1007
-            'FROM'        => [
1008
-                    DIR_LINK_TABLE    => 'l', ],
1009
-            'LEFT_JOIN'    => [
1010
-                    [
1011
-                        'FROM'    => [USERS_TABLE    => 'u'],
1012
-                        'ON'      => 'l.link_user_id = u.user_id',
1013
-                    ],
1014
-            ],
1015
-            'WHERE'        => 'l.link_back <> "" AND l.link_active = 1 AND l.link_cat = '.(int) $cat_id, ];
1016
-
1017
-        $sql = $this->db->sql_build_query('SELECT', $sql_array);
1018
-        $result = $this->db->sql_query($sql);
1019
-
1020
-        while ($row = $this->db->sql_fetchrow($result)) {
1021
-            if ($this->validate_link_back($row['link_back'], false, true) !== false) {
1022
-                if (!$nb_check || ($row['link_nb_check'] + 1) >= $nb_check) {
1023
-                    $del_array[] = $row['link_id'];
1024
-                } else {
1025
-                    // A first table containing links ID to update
1026
-                    $update_array[$row['link_id']] = $row;
1027
-                }
1028
-            }
1029
-        }
1030
-        $this->db->sql_freeresult($result);
1031
-
1032
-        if (count($del_array)) {
1033
-            $this->del($cat_id, $del_array);
1034
-        }
1035
-        if (count($update_array)) {
1036
-            $this->_update_check($update_array, $next_prune);
1037
-        }
1038
-    }
1039
-
1040
-    /**
1041
-     * Method called by cron task.
1042
-     *
1043
-     * @param array $cat_data Information about category, from db
1044
-     *
1045
-     * @return null
1046
-     */
1047
-    public function auto_check($cat_data)
1048
-    {
1049
-        global $phpbb_log;
1050
-
1051
-        $sql = 'SELECT cat_name
534
+		$this->db->sql_query($sql);
535
+
536
+		$this->db->sql_transaction('commit');
537
+
538
+		if ($this->request->is_ajax()) {
539
+			$sql = 'SELECT link_vote, link_note FROM '.DIR_LINK_TABLE.' WHERE link_id = '.(int) $link_id;
540
+			$result = $this->db->sql_query($sql);
541
+			$data = $this->db->sql_fetchrow($result);
542
+
543
+			$note = $this->display_note($data['link_note'], $data['link_vote'], true);
544
+
545
+			$json_response = new \phpbb\json_response();
546
+			$json_response->send([
547
+				'success' => true,
548
+
549
+				'MESSAGE_TITLE'    => $this->user->lang['INFORMATION'],
550
+				'MESSAGE_TEXT'     => $this->user->lang['DIR_VOTE_OK'],
551
+				'NOTE'             => $note,
552
+				'NB_VOTE'          => $this->user->lang('DIR_NB_VOTES', (int) $data['link_vote']),
553
+				'LINK_ID'          => $link_id,
554
+			]);
555
+		}
556
+	}
557
+
558
+	/**
559
+	 * Search an appropriate thumb for url.
560
+	 *
561
+	 * @param string $url Link's url
562
+	 *
563
+	 * @return string The thumb url
564
+	 */
565
+	public function thumb_process($url)
566
+	{
567
+		if (!$this->config['dir_activ_thumb']) {
568
+			return $this->root_path.'images/directory/nothumb.gif';
569
+		}
570
+
571
+		$details = parse_url($url);
572
+
573
+		$root_url = $details['scheme'].'://'.$details['host'];
574
+		$absolute_url = isset($details['path']) ? $root_url.$details['path'] : $root_url;
575
+
576
+		if ($this->config['dir_activ_thumb_remote'] && $this->_ascreen_exist($details['scheme'], $details['host'])) {
577
+			return $root_url.'/ascreen.jpg';
578
+		}
579
+
580
+		return $this->config['dir_thumb_service'].$absolute_url;
581
+	}
582
+
583
+	/**
584
+	 * Check if ascreen thumb exists.
585
+	 *
586
+	 * @param string $protocol The protocol
587
+	 * @param string $host     The hostname
588
+	 *
589
+	 * @return bool True if ascreen file exixts, else false
590
+	 */
591
+	private function _ascreen_exist($protocol, $host)
592
+	{
593
+		if ($thumb_info = @getimagesize($protocol.'://'.$host.'/ascreen.jpg')) {
594
+			// Obviously this is an image, we did some additional tests
595
+			if ($thumb_info[0] == '120' && $thumb_info[1] == '90' && $thumb_info['mime'] == 'image/jpeg') {
596
+				return true;
597
+			}
598
+		}
599
+
600
+		return false;
601
+	}
602
+
603
+	/**
604
+	 * Primary work on banner, can edit, copy or check a banner.
605
+	 *
606
+	 * @param string $banner The banner's remote url
607
+	 * @param array  $error  The array error, passed by reference
608
+	 *
609
+	 * @return null
610
+	 */
611
+	public function banner_process(&$banner, &$error)
612
+	{
613
+		$old_banner = $this->request->variable('old_banner', '');
614
+
615
+		$destination = $this->dir_helper->get_banner_path();
616
+
617
+		// Can we upload?
618
+		$can_upload = ($this->config['dir_storage_banner'] && file_exists($this->root_path.$destination) && phpbb_is_writable($this->root_path.$destination) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
619
+
620
+		if ($banner && $can_upload) {
621
+			$file = $this->_banner_upload($banner, $error);
622
+		} elseif ($banner) {
623
+			$file = $this->_banner_remote($banner, $error);
624
+		} elseif ($this->request->is_set_post('delete_banner') && $old_banner) {
625
+			$this->_banner_delete($old_banner);
626
+
627
+			return;
628
+		}
629
+
630
+		if (!count($error)) {
631
+			if ($banner && $old_banner && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $old_banner)) {
632
+				$this->_banner_delete($old_banner);
633
+			}
634
+
635
+			$banner = !empty($file) ? $file : '';
636
+		}
637
+	}
638
+
639
+	/**
640
+	 * Copy a remonte banner to server.
641
+	 * called by banner_process().
642
+	 *
643
+	 * @param string $banner The anner's remote url
644
+	 * @param array  $error  The array error, passed by reference
645
+	 *
646
+	 * @return false|string String if no errors, else false
647
+	 */
648
+	private function _banner_upload($banner, &$error)
649
+	{
650
+		// Init upload class
651
+		if (!class_exists('fileupload')) {
652
+			include $this->root_path.'includes/functions_upload.'.$this->php_ext;
653
+		}
654
+		$upload = new \fileupload('DIR_BANNER_', ['jpg', 'jpeg', 'gif', 'png'], $this->config['dir_banner_filesize']);
655
+
656
+		$file = $upload->remote_upload($banner);
657
+
658
+		$prefix = unique_id().'_';
659
+		$file->clean_filename('real', $prefix);
660
+
661
+		$destination = $this->dir_helper->get_banner_path();
662
+
663
+		// Move file and overwrite any existing image
664
+		$file->move_file($destination, true);
665
+
666
+		if (count($file->error)) {
667
+			$file->remove();
668
+			$error = array_merge($error, $file->error);
669
+
670
+			return false;
671
+		}
672
+
673
+		return $prefix.strtolower($file->uploadname);
674
+	}
675
+
676
+	/**
677
+	 * Check than remote banner exists
678
+	 * called by banner_process().
679
+	 *
680
+	 * @param string $banner The banner's remote url
681
+	 * @param array  $error  The array error, passed by reference
682
+	 *
683
+	 * @return false|string String if no errors, else false
684
+	 */
685
+	private function _banner_remote($banner, &$error)
686
+	{
687
+		if (!preg_match('#^(http|https|ftp)://#i', $banner)) {
688
+			$banner = 'http://'.$banner;
689
+		}
690
+		if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $banner)) {
691
+			$error[] = $this->user->lang['DIR_BANNER_URL_INVALID'];
692
+
693
+			return false;
694
+		}
695
+
696
+		// Make sure getimagesize works...
697
+		if (($image_data = @getimagesize($banner)) === false) {
698
+			$error[] = $this->user->lang['DIR_BANNER_UNABLE_GET_IMAGE_SIZE'];
699
+
700
+			return false;
701
+		}
702
+
703
+		if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) {
704
+			$error[] = $this->user->lang['DIR_BANNER_UNABLE_GET_IMAGE_SIZE'];
705
+
706
+			return false;
707
+		}
708
+
709
+		$width = $image_data[0];
710
+		$height = $image_data[1];
711
+
712
+		// Check image type
713
+		if (!class_exists('fileupload')) {
714
+			include $this->root_path.'includes/functions_upload.'.$this->php_ext;
715
+		}
716
+
717
+		$types = \fileupload::image_types();
718
+		$extension = strtolower(\filespec::get_extension($banner));
719
+
720
+		// Check if this is actually an image
721
+		if ($file_stream = @fopen($banner, 'r')) {
722
+			// Timeout after 1 second
723
+			stream_set_timeout($file_stream, 1);
724
+			// read some data to ensure headers are present
725
+			fread($file_stream, 1024);
726
+			$meta = stream_get_meta_data($file_stream);
727
+			if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers'])) {
728
+				$headers = $meta['wrapper_data']['headers'];
729
+			} elseif (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
730
+				$headers = $meta['wrapper_data'];
731
+			} else {
732
+				$headers = [];
733
+			}
734
+
735
+			foreach ($headers as $header) {
736
+				$header = preg_split('/ /', $header, 2);
737
+				if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type') {
738
+					if (strpos($header[1], 'image/') !== 0) {
739
+						$error[] = 'DIR_BANNER_URL_INVALID';
740
+						fclose($file_stream);
741
+
742
+						return false;
743
+					} else {
744
+						fclose($file_stream);
745
+						break;
746
+					}
747
+				}
748
+			}
749
+		} else {
750
+			$error[] = 'DIR_BANNER_URL_INVALID';
751
+
752
+			return false;
753
+		}
754
+
755
+		if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) {
756
+			if (!isset($types[$image_data[2]])) {
757
+				$error[] = $this->user->lang['UNABLE_GET_IMAGE_SIZE'];
758
+			} else {
759
+				$error[] = $this->user->lang('DIR_BANNER_IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
760
+			}
761
+
762
+			return false;
763
+		}
764
+
765
+		if (($this->config['dir_banner_width'] || $this->config['dir_banner_height']) && ($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height'])) {
766
+			$error[] = $this->user->lang('DIR_BANNER_WRONG_SIZE', $this->config['dir_banner_width'], $this->config['dir_banner_height'], $width, $height);
767
+
768
+			return false;
769
+		}
770
+
771
+		return $banner;
772
+	}
773
+
774
+	/**
775
+	 * Delete a banner from server.
776
+	 *
777
+	 * @param string $file The file's name
778
+	 *
779
+	 * @return bool True if delete success, else false
780
+	 */
781
+	private function _banner_delete($file)
782
+	{
783
+		if (file_exists($this->dir_helper->get_banner_path($file))) {
784
+			@unlink($this->dir_helper->get_banner_path($file));
785
+
786
+			return true;
787
+		}
788
+
789
+		return false;
790
+	}
791
+
792
+	/**
793
+	 * PageRank Lookup (Based on Google Toolbar for Mozilla Firefox).
794
+	 *
795
+	 * @copyright 2012 HM2K <[email protected]>
796
+	 *
797
+	 * @link http://pagerank.phurix.net/
798
+	 *
799
+	 * @author James Wade <[email protected]>
800
+	 *
801
+	 * @version $Revision: 2.1 $
802
+	 * @require PHP 4.3.0 (file_get_contents)
803
+	 * @updated 06/10/11
804
+	 *
805
+	 * @param string $q The website URL
806
+	 *
807
+	 * @return string The calculated pagerank, or -1
808
+	 */
809
+	public function pagerank_process($q)
810
+	{
811
+		$googleDomains = ['.com', '.com.tr', '.de', '.fr', '.be', '.ca', '.ro', '.ch'];
812
+		$seed = $this->user->lang['SEED'];
813
+		$result = 0x01020345;
814
+		$len = strlen($q);
815
+
816
+		for ($i = 0; $i < $len; $i++) {
817
+			$result ^= ord($seed[$i % strlen($seed)]) ^ ord($q[$i]);
818
+			$result = (($result >> 23) & 0x1ff) | $result << 9;
819
+		}
820
+
821
+		if (PHP_INT_MAX != 2147483647) {
822
+			$result = -(~($result & 0xFFFFFFFF) + 1);
823
+		}
824
+
825
+		$ch = sprintf('8%x', $result);
826
+		$url = 'http://%s/tbr?client=navclient-auto&ch=%s&features=Rank&q=info:%s';
827
+		$host = 'toolbarqueries.google'.$googleDomains[mt_rand(0, count($googleDomains) - 1)];
828
+
829
+		$url = sprintf($url, $host, $ch, $q);
830
+		@$pr = trim(file_get_contents($url, false));
831
+
832
+		if (is_numeric(substr(strrchr($pr, ':'), 1))) {
833
+			return substr(strrchr($pr, ':'), 1);
834
+		}
835
+
836
+		return '-1';
837
+	}
838
+
839
+	/**
840
+	 * List flags.
841
+	 *
842
+	 * @param string $flag_path The flag directory path
843
+	 * @param string $value     Selected flag
844
+	 *
845
+	 * @return string $list		Html code
846
+	 */
847
+	public function get_dir_flag_list($flag_path, $value)
848
+	{
849
+		$list = '';
850
+
851
+		$this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory_flags');
852
+
853
+		$flags = $this->dir_helper->preg_grep_keys('/^DIR_FLAG_CODE_/i', $this->user->lang);
854
+
855
+		if (extension_loaded('intl')) {
856
+			$locale = $this->user->lang['USER_LANG'];
857
+
858
+			$col = new \Collator($locale);
859
+			$col->asort($flags);
860
+		} else {
861
+			asort($flags);
862
+		}
863
+
864
+		foreach ($flags as $file => $name) {
865
+			$img_file = strtolower(substr(strrchr($file, '_'), 1)).'.png';
866
+
867
+			if (file_exists($flag_path.$img_file)) {
868
+				$list .= '<option value="'.$img_file.'" '.(($img_file == $value) ? 'selected="selected"' : '').'>'.$name.'</option>';
869
+			}
870
+		}
871
+
872
+		return $list;
873
+	}
874
+
875
+	/**
876
+	 * Display recents links added.
877
+	 *
878
+	 * @return null
879
+	 */
880
+	public function recents()
881
+	{
882
+		if ($this->config['dir_recent_block']) {
883
+			$limit_sql = $this->config['dir_recent_rows'] * $this->config['dir_recent_columns'];
884
+			$exclude_array = explode(',', str_replace(' ', '', $this->config['dir_recent_exclude']));
885
+
886
+			$sql_array = [
887
+				'SELECT'      => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_thumb, u.user_id, u.username, u.user_colour, c.cat_name',
888
+				'FROM'        => [
889
+						DIR_LINK_TABLE    => 'l', ],
890
+				'LEFT_JOIN'    => [
891
+						[
892
+							'FROM'    => [USERS_TABLE    => 'u'],
893
+							'ON'      => 'l.link_user_id = u.user_id',
894
+						],
895
+						[
896
+							'FROM'    => [DIR_CAT_TABLE => 'c'],
897
+							'ON'      => 'l.link_cat = c.cat_id',
898
+						],
899
+				],
900
+				'WHERE'        => $this->db->sql_in_set('l.link_cat', $exclude_array, true).' AND l.link_active = 1',
901
+				'ORDER_BY'     => 'l.link_time DESC, l.link_id DESC', ];
902
+
903
+			$sql = $this->db->sql_build_query('SELECT', $sql_array);
904
+			$result = $this->db->sql_query_limit($sql, $limit_sql, 0);
905
+			$num = 0;
906
+			$rowset = [];
907
+
908
+			while ($site = $this->db->sql_fetchrow($result)) {
909
+				$rowset[$site['link_id']] = $site;
910
+			}
911
+			$this->db->sql_freeresult($result);
912
+
913
+			if (count($rowset)) {
914
+				$this->template->assign_block_vars('block', [
915
+					'S_COL_WIDTH'            => (100 / $this->config['dir_recent_columns']).'%',
916
+				]);
917
+
918
+				foreach ($rowset as $row) {
919
+					if (($num % $this->config['dir_recent_columns']) == 0) {
920
+						$this->template->assign_block_vars('block.row', []);
921
+					}
922
+
923
+					$this->template->assign_block_vars('block.row.col', [
924
+						'UC_THUMBNAIL'               => '<a href="'.$row['link_url'].'" onclick="window.open(\''.$this->helper->route('ernadoo_phpbbdirectory_view_controller', ['link_id' => (int) $row['link_id']]).'\'); return false;"><img src="'.$row['link_thumb'].'" title="'.$row['link_name'].'" alt="'.$row['link_name'].'" /></a>',
925
+						'NAME'                       => $row['link_name'],
926
+						'USER'                       => get_username_string('full', $row['link_user_id'], $row['username'], $row['user_colour']),
927
+						'TIME'                       => ($row['link_time']) ? $this->user->format_date($row['link_time']) : '',
928
+						'CAT'                        => $row['cat_name'],
929
+						'COUNT'                      => $row['link_view'],
930
+						'COMMENT'                    => $row['link_comment'],
931
+
932
+						'U_CAT'                   => $this->helper->route('ernadoo_phpbbdirectory_page_controller', ['cat_id' => (int) $row['link_cat']]),
933
+						'U_COMMENT'               => $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', ['link_id' => (int) $row['link_id']]),
934
+
935
+						'L_DIR_SEARCH_NB_CLICKS'       => $this->user->lang('DIR_SEARCH_NB_CLICKS', (int) $row['link_view']),
936
+						'L_DIR_SEARCH_NB_COMMS'        => $this->user->lang('DIR_SEARCH_NB_COMMS', (int) $row['link_comment']),
937
+					]);
938
+					$num++;
939
+				}
940
+
941
+				while (($num % $this->config['dir_recent_columns']) != 0) {
942
+					$this->template->assign_block_vars('block.row.col2', []);
943
+					$num++;
944
+				}
945
+			}
946
+		}
947
+	}
948
+
949
+	/**
950
+	 * Validate back link.
951
+	 *
952
+	 * @param string $remote_url Page URL contains the backlink
953
+	 * @param bool   $optional   Link back is optional in this category?
954
+	 * @param bool   $cron       This methos is called by con process?
955
+	 *
956
+	 * @return false|string Either false if validation succeeded or a string which will be used as the error message (with the variable name appended)
957
+	 */
958
+	public function validate_link_back($remote_url, $optional, $cron = false)
959
+	{
960
+		if (!$cron) {
961
+			if (empty($remote_url) && $optional) {
962
+				return false;
963
+			}
964
+
965
+			if (!preg_match('#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i', $remote_url)) {
966
+				return 'DIR_ERROR_WRONG_DATA_BACK';
967
+			}
968
+		}
969
+
970
+		if (false === ($handle = @fopen($remote_url, 'r'))) {
971
+			return 'DIR_ERROR_NOT_FOUND_BACK';
972
+		}
973
+
974
+		$buff = '';
975
+
976
+		// Read by packet, faster than file_get_contents()
977
+		while (!feof($handle)) {
978
+			$buff .= fgets($handle, 256);
979
+
980
+			if (stristr($buff, $this->config['server_name'])) {
981
+				@fclose($handle);
982
+
983
+				return false;
984
+			}
985
+		}
986
+		@fclose($handle);
987
+
988
+		return 'DIR_ERROR_NO_LINK_BACK';
989
+	}
990
+
991
+	/**
992
+	 * Check, for website with backlink specified, if backlink is always here.
993
+	 * After $nb_check verification, website is deleted, otherwise, a notification is send to poster.
994
+	 *
995
+	 * @param int $cat_id     The categoryID
996
+	 * @param int $nb_check   Number of check before demete a website
997
+	 * @param int $next_prune Date of next auto check
998
+	 *
999
+	 * @return null
1000
+	 */
1001
+	private function _check($cat_id, $nb_check, $next_prune)
1002
+	{
1003
+		$del_array = $update_array = [];
1004
+
1005
+		$sql_array = [
1006
+			'SELECT'      => 'link_id, link_cat, link_back, link_guest_email, link_nb_check, link_user_id, link_name, link_url, link_description, u.user_lang, u.user_dateformat',
1007
+			'FROM'        => [
1008
+					DIR_LINK_TABLE    => 'l', ],
1009
+			'LEFT_JOIN'    => [
1010
+					[
1011
+						'FROM'    => [USERS_TABLE    => 'u'],
1012
+						'ON'      => 'l.link_user_id = u.user_id',
1013
+					],
1014
+			],
1015
+			'WHERE'        => 'l.link_back <> "" AND l.link_active = 1 AND l.link_cat = '.(int) $cat_id, ];
1016
+
1017
+		$sql = $this->db->sql_build_query('SELECT', $sql_array);
1018
+		$result = $this->db->sql_query($sql);
1019
+
1020
+		while ($row = $this->db->sql_fetchrow($result)) {
1021
+			if ($this->validate_link_back($row['link_back'], false, true) !== false) {
1022
+				if (!$nb_check || ($row['link_nb_check'] + 1) >= $nb_check) {
1023
+					$del_array[] = $row['link_id'];
1024
+				} else {
1025
+					// A first table containing links ID to update
1026
+					$update_array[$row['link_id']] = $row;
1027
+				}
1028
+			}
1029
+		}
1030
+		$this->db->sql_freeresult($result);
1031
+
1032
+		if (count($del_array)) {
1033
+			$this->del($cat_id, $del_array);
1034
+		}
1035
+		if (count($update_array)) {
1036
+			$this->_update_check($update_array, $next_prune);
1037
+		}
1038
+	}
1039
+
1040
+	/**
1041
+	 * Method called by cron task.
1042
+	 *
1043
+	 * @param array $cat_data Information about category, from db
1044
+	 *
1045
+	 * @return null
1046
+	 */
1047
+	public function auto_check($cat_data)
1048
+	{
1049
+		global $phpbb_log;
1050
+
1051
+		$sql = 'SELECT cat_name
1052 1052
 			FROM '.DIR_CAT_TABLE.'
1053 1053
 			WHERE cat_id = '.(int) $cat_data['cat_id'];
1054
-        $result = $this->db->sql_query($sql);
1055
-        $row = $this->db->sql_fetchrow($result);
1056
-        $this->db->sql_freeresult($result);
1054
+		$result = $this->db->sql_query($sql);
1055
+		$row = $this->db->sql_fetchrow($result);
1056
+		$this->db->sql_freeresult($result);
1057 1057
 
1058
-        if ($row) {
1059
-            $next_prune = time() + ($cat_data['cat_cron_freq'] * 86400);
1058
+		if ($row) {
1059
+			$next_prune = time() + ($cat_data['cat_cron_freq'] * 86400);
1060 1060
 
1061
-            $this->_check($cat_data['cat_id'], $cat_data['cat_cron_nb_check'], $next_prune);
1061
+			$this->_check($cat_data['cat_id'], $cat_data['cat_cron_nb_check'], $next_prune);
1062 1062
 
1063
-            $sql = 'UPDATE '.DIR_CAT_TABLE."
1063
+			$sql = 'UPDATE '.DIR_CAT_TABLE."
1064 1064
 				SET cat_cron_next = $next_prune
1065 1065
 				WHERE cat_id = ".(int) $cat_data['cat_id'];
1066
-            $this->db->sql_query($sql);
1067
-
1068
-            $phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_AUTO_PRUNE', time(), [$row['cat_name']]);
1069
-        }
1070
-    }
1071
-
1072
-    /**
1073
-     * Update website verification number after a missing backlink, and send notificaton.
1074
-     *
1075
-     * @param array $u_array    Information about website
1076
-     * @param int   $next_prune Date of next auto check
1077
-     *
1078
-     * @return null
1079
-     */
1080
-    private function _update_check($u_array, $next_prune)
1081
-    {
1082
-        if (!class_exists('messenger')) {
1083
-            include $this->root_path.'includes/functions_messenger.'.$this->php_ext;
1084
-        }
1085
-
1086
-        $messenger = new \messenger(false);
1087
-
1088
-        // cron.php don't call $user->setup(), so $this->timezone is unset.
1089
-        // We need to define it, because we use user->format_date below
1090
-        $this->user->timezone = new \DateTimeZone($this->config['board_timezone']);
1091
-
1092
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
1066
+			$this->db->sql_query($sql);
1067
+
1068
+			$phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_AUTO_PRUNE', time(), [$row['cat_name']]);
1069
+		}
1070
+	}
1071
+
1072
+	/**
1073
+	 * Update website verification number after a missing backlink, and send notificaton.
1074
+	 *
1075
+	 * @param array $u_array    Information about website
1076
+	 * @param int   $next_prune Date of next auto check
1077
+	 *
1078
+	 * @return null
1079
+	 */
1080
+	private function _update_check($u_array, $next_prune)
1081
+	{
1082
+		if (!class_exists('messenger')) {
1083
+			include $this->root_path.'includes/functions_messenger.'.$this->php_ext;
1084
+		}
1085
+
1086
+		$messenger = new \messenger(false);
1087
+
1088
+		// cron.php don't call $user->setup(), so $this->timezone is unset.
1089
+		// We need to define it, because we use user->format_date below
1090
+		$this->user->timezone = new \DateTimeZone($this->config['board_timezone']);
1091
+
1092
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
1093 1093
 			SET link_nb_check = link_nb_check + 1
1094 1094
 			WHERE '.$this->db->sql_in_set('link_id', array_keys($u_array));
1095
-        $this->db->sql_query($sql);
1096
-
1097
-        foreach ($u_array as $data) {
1098
-            strip_bbcode($data['link_description']);
1099
-
1100
-            $notification_data = [
1101
-                    'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $data['link_cat']),
1102
-                    'link_id'              => $data['link_id'],
1103
-                    'link_name'            => $data['link_name'],
1104
-                    'link_url'             => $data['link_url'],
1105
-                    'link_description'     => $data['link_description'],
1106
-                    'next_cron'            => $this->user->format_date($next_prune, $data['user_dateformat']),
1107
-            ];
1108
-
1109
-            if ($data['link_nb_check']) {
1110
-                $this->notification->delete_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', $notification_data);
1111
-            }
1112
-
1113
-            // New notification system can't send mail to an anonymous user with an email address stored in another table than phpbb_users
1114
-            if ($data['link_user_id'] == ANONYMOUS) {
1115
-                $username = $email = $data['link_guest_email'];
1116
-
1117
-                $messenger->template('@ernadoo_phpbbdirectory/directory_website_error_cron', $data['user_lang']);
1118
-                $messenger->to($email, $username);
1119
-
1120
-                $messenger->assign_vars([
1121
-                    'USERNAME'             => htmlspecialchars_decode($username),
1122
-                    'LINK_NAME'            => $data['link_name'],
1123
-                    'LINK_URL'             => $data['link_url'],
1124
-                    'LINK_DESCRIPTION'     => $data['link_description'],
1125
-                    'NEXT_CRON'            => $this->user->format_date($next_prune, $data['user_dateformat']),
1126
-                ]);
1127
-
1128
-                $messenger->send(NOTIFY_EMAIL);
1129
-            } else {
1130
-                $this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', $notification_data);
1131
-            }
1132
-        }
1133
-    }
1095
+		$this->db->sql_query($sql);
1096
+
1097
+		foreach ($u_array as $data) {
1098
+			strip_bbcode($data['link_description']);
1099
+
1100
+			$notification_data = [
1101
+					'cat_name'             => \ernadoo\phpbbdirectory\core\categorie::getname((int) $data['link_cat']),
1102
+					'link_id'              => $data['link_id'],
1103
+					'link_name'            => $data['link_name'],
1104
+					'link_url'             => $data['link_url'],
1105
+					'link_description'     => $data['link_description'],
1106
+					'next_cron'            => $this->user->format_date($next_prune, $data['user_dateformat']),
1107
+			];
1108
+
1109
+			if ($data['link_nb_check']) {
1110
+				$this->notification->delete_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', $notification_data);
1111
+			}
1112
+
1113
+			// New notification system can't send mail to an anonymous user with an email address stored in another table than phpbb_users
1114
+			if ($data['link_user_id'] == ANONYMOUS) {
1115
+				$username = $email = $data['link_guest_email'];
1116
+
1117
+				$messenger->template('@ernadoo_phpbbdirectory/directory_website_error_cron', $data['user_lang']);
1118
+				$messenger->to($email, $username);
1119
+
1120
+				$messenger->assign_vars([
1121
+					'USERNAME'             => htmlspecialchars_decode($username),
1122
+					'LINK_NAME'            => $data['link_name'],
1123
+					'LINK_URL'             => $data['link_url'],
1124
+					'LINK_DESCRIPTION'     => $data['link_description'],
1125
+					'NEXT_CRON'            => $this->user->format_date($next_prune, $data['user_dateformat']),
1126
+				]);
1127
+
1128
+				$messenger->send(NOTIFY_EMAIL);
1129
+			} else {
1130
+				$this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', $notification_data);
1131
+			}
1132
+		}
1133
+	}
1134 1134
 }
Please login to merge, or discard this patch.
Braces   +200 added lines, -93 removed lines patch added patch discarded remove patch
@@ -90,20 +90,24 @@  discard block
 block discarded – undo
90 90
         $this->db->sql_query($sql);
91 91
         $notification_data['link_id'] = $this->db->sql_nextid();
92 92
 
93
-        if (!$need_approval || $this->auth->acl_get('a_') || $this->auth->acl_get('m_')) {
93
+        if (!$need_approval || $this->auth->acl_get('a_') || $this->auth->acl_get('m_'))
94
+        {
94 95
             $sql = 'UPDATE '.DIR_CAT_TABLE.'
95 96
 				SET cat_links = cat_links + 1
96 97
 				WHERE cat_id = '.(int) $data['link_cat'];
97 98
             $this->db->sql_query($sql);
98 99
 
99 100
             $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website';
100
-        } elseif ($this->config['dir_mail']) {
101
+        }
102
+        elseif ($this->config['dir_mail'])
103
+        {
101 104
             $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
102 105
         }
103 106
 
104 107
         $this->db->sql_transaction('commit');
105 108
 
106
-        if (isset($notification_type)) {
109
+        if (isset($notification_type))
110
+        {
107 111
             $notification_data = array_merge($notification_data,
108 112
                 [
109 113
                     'user_from'            => (int) $data['link_user_id'],
@@ -141,7 +145,8 @@  discard block
 block discarded – undo
141 145
 
142 146
         $old_cat = array_pop($data);
143 147
 
144
-        if ($old_cat != $data['link_cat'] || $need_approval) {
148
+        if ($old_cat != $data['link_cat'] || $need_approval)
149
+        {
145 150
             $this->notification->delete_notifications('ernadoo.phpbbdirectory.notification.type.directory_website', (int) $link_id);
146 151
 
147 152
             $this->db->sql_transaction('begin');
@@ -151,14 +156,17 @@  discard block
 block discarded – undo
151 156
 				WHERE cat_id = '.(int) $old_cat;
152 157
             $this->db->sql_query($sql);
153 158
 
154
-            if (!$need_approval) {
159
+            if (!$need_approval)
160
+            {
155 161
                 $sql = 'UPDATE '.DIR_CAT_TABLE.'
156 162
 					SET cat_links = cat_links + 1
157 163
 					WHERE cat_id = '.(int) $data['link_cat'];
158 164
                 $this->db->sql_query($sql);
159 165
 
160 166
                 $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website';
161
-            } else {
167
+            }
168
+            else
169
+            {
162 170
                 $data['link_active'] = false;
163 171
                 $notification_type = 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
164 172
             }
@@ -200,17 +208,21 @@  discard block
 block discarded – undo
200 208
 			WHERE '.$this->db->sql_in_set('link_id', $url_array);
201 209
         $result = $this->db->sql_query($sql);
202 210
 
203
-        while ($row = $this->db->sql_fetchrow($result)) {
204
-            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) {
211
+        while ($row = $this->db->sql_fetchrow($result))
212
+        {
213
+            if ($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner']))
214
+            {
205 215
                 $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
206 216
 
207
-                if (file_exists($banner_img)) {
217
+                if (file_exists($banner_img))
218
+                {
208 219
                     @unlink($banner_img);
209 220
                 }
210 221
             }
211 222
         }
212 223
 
213
-        foreach ($link_datas_ary as $table => $field) {
224
+        foreach ($link_datas_ary as $table => $field)
225
+        {
214 226
             $this->db->sql_query("DELETE FROM $table WHERE ".$this->db->sql_in_set($field, $url_array));
215 227
         }
216 228
 
@@ -221,14 +233,16 @@  discard block
 block discarded – undo
221 233
 
222 234
         $this->db->sql_transaction('commit');
223 235
 
224
-        foreach ($url_array as $link_id) {
236
+        foreach ($url_array as $link_id)
237
+        {
225 238
             $this->notification->delete_notifications([
226 239
                 'ernadoo.phpbbdirectory.notification.type.directory_website',
227 240
                 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue',
228 241
             ], $link_id);
229 242
         }
230 243
 
231
-        if ($this->request->is_ajax()) {
244
+        if ($this->request->is_ajax())
245
+        {
232 246
             $sql = 'SELECT cat_links
233 247
 				FROM '.DIR_CAT_TABLE.'
234 248
 				WHERE cat_id = '.(int) $cat_id;
@@ -264,7 +278,8 @@  discard block
 block discarded – undo
264 278
         $result = $this->db->sql_query($sql);
265 279
         $data = $this->db->sql_fetchrow($result);
266 280
 
267
-        if (empty($data['link_id'])) {
281
+        if (empty($data['link_id']))
282
+        {
268 283
             throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
269 284
         }
270 285
 
@@ -290,18 +305,21 @@  discard block
 block discarded – undo
290 305
         $default_port = 80;
291 306
         $hostname = $details['host'];
292 307
 
293
-        if ($details['scheme'] == 'https') {
308
+        if ($details['scheme'] == 'https')
309
+        {
294 310
             $default_port = 443;
295 311
             $hostname = 'tls://'.$details['host'];
296 312
         }
297 313
 
298
-        if (!isset($details['path'])) {
314
+        if (!isset($details['path']))
315
+        {
299 316
             $details['path'] = '/';
300 317
         }
301 318
 
302 319
         $port = (isset($details['port']) && !empty($details['port'])) ? (int) $details['port'] : $default_port;
303 320
 
304
-        if ($sock = @fsockopen($hostname, $port, $errno, $errstr, 1)) {
321
+        if ($sock = @fsockopen($hostname, $port, $errno, $errstr, 1))
322
+        {
305 323
             $requete = 'GET '.$details['path']." HTTP/1.1\r\n";
306 324
             $requete .= 'Host: '.$details['host']."\r\n\r\n";
307 325
 
@@ -329,7 +347,8 @@  discard block
 block discarded – undo
329 347
     {
330 348
         $details = parse_url($url);
331 349
 
332
-        if (isset($details['path']) && $details['path'] == '/' && !isset($details['query'])) {
350
+        if (isset($details['path']) && $details['path'] == '/' && !isset($details['query']))
351
+        {
333 352
             return substr($url, 0, -1);
334 353
         }
335 354
 
@@ -351,7 +370,8 @@  discard block
 block discarded – undo
351 370
         $flag_path = $ext_path.'images/flags/';
352 371
         $img_flag = 'no_flag.png';
353 372
 
354
-        if ($this->config['dir_activ_flag'] && !empty($data['link_flag']) && file_exists($flag_path.$data['link_flag'])) {
373
+        if ($this->config['dir_activ_flag'] && !empty($data['link_flag']) && file_exists($flag_path.$data['link_flag']))
374
+        {
355 375
             $img_flag = $data['link_flag'];
356 376
         }
357 377
 
@@ -369,7 +389,8 @@  discard block
 block discarded – undo
369 389
      */
370 390
     public function display_note($total_note, $nb_vote, $votes_status)
371 391
     {
372
-        if (!$votes_status) {
392
+        if (!$votes_status)
393
+        {
373 394
             return;
374 395
         }
375 396
 
@@ -388,9 +409,11 @@  discard block
 block discarded – undo
388 409
      */
389 410
     public function display_vote($data)
390 411
     {
391
-        if ($this->user->data['is_registered'] && $this->auth->acl_get('u_vote_dir') && empty($data['vote_user_id'])) {
412
+        if ($this->user->data['is_registered'] && $this->auth->acl_get('u_vote_dir') && empty($data['vote_user_id']))
413
+        {
392 414
             $list = '<select name="vote">';
393
-            for ($i = 0; $i <= 10; $i++) {
415
+            for ($i = 0; $i <= 10; $i++)
416
+            {
394 417
                 $list .= '<option value="'.$i.'"'.(($i == 5) ? ' selected="selected"' : '').'>'.$i.'</option>';
395 418
             }
396 419
             $list .= '</select>';
@@ -408,7 +431,8 @@  discard block
 block discarded – undo
408 431
      */
409 432
     public function display_rss($data)
410 433
     {
411
-        if ($this->config['dir_activ_rss'] && !empty($data['link_rss'])) {
434
+        if ($this->config['dir_activ_rss'] && !empty($data['link_rss']))
435
+        {
412 436
             return $data['link_rss'];
413 437
         }
414 438
     }
@@ -424,8 +448,10 @@  discard block
 block discarded – undo
424 448
      */
425 449
     public function display_thumb($data)
426 450
     {
427
-        if ($this->config['dir_activ_thumb']) {
428
-            if (!$data['link_thumb'] || ($this->config['dir_thumb_service_reverse'] && (!strstr($data['link_thumb'], 'ascreen.jpg') && (!strstr($data['link_thumb'], $this->config['dir_thumb_service']))))) {
451
+        if ($this->config['dir_activ_thumb'])
452
+        {
453
+            if (!$data['link_thumb'] || ($this->config['dir_thumb_service_reverse'] && (!strstr($data['link_thumb'], 'ascreen.jpg') && (!strstr($data['link_thumb'], $this->config['dir_thumb_service'])))))
454
+            {
429 455
                 $thumb = $this->thumb_process($data['link_url']);
430 456
 
431 457
                 $sql = 'UPDATE '.DIR_LINK_TABLE.'
@@ -449,15 +475,19 @@  discard block
 block discarded – undo
449 475
      */
450 476
     public function display_pagerank($data)
451 477
     {
452
-        if ($this->config['dir_activ_pagerank']) {
453
-            if ($data['link_pagerank'] == '') {
478
+        if ($this->config['dir_activ_pagerank'])
479
+        {
480
+            if ($data['link_pagerank'] == '')
481
+            {
454 482
                 $pagerank = $this->pagerank_process($data['link_url']);
455 483
 
456 484
                 $sql = 'UPDATE '.DIR_LINK_TABLE.'
457 485
 					SET link_pagerank = '.(int) $pagerank.'
458 486
 					WHERE link_id = '.(int) $data['link_id'];
459 487
                 $this->db->sql_query($sql);
460
-            } else {
488
+            }
489
+            else
490
+            {
461 491
                 $pagerank = (int) $data['link_pagerank'];
462 492
             }
463 493
 
@@ -484,16 +514,21 @@  discard block
 block discarded – undo
484 514
     {
485 515
         $s_banner = '';
486 516
 
487
-        if (!empty($data['link_banner'])) {
488
-            if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $data['link_banner'])) {
517
+        if (!empty($data['link_banner']))
518
+        {
519
+            if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $data['link_banner']))
520
+            {
489 521
                 $img_src = $this->helper->route('ernadoo_phpbbdirectory_banner_controller', ['banner_img' => $data['link_banner']]);
490 522
                 $physical_path = $this->dir_helper->get_banner_path($data['link_banner']);
491
-            } else {
523
+            }
524
+            else
525
+            {
492 526
                 $img_src = $physical_path = $data['link_banner'];
493 527
             }
494 528
 
495 529
             list($width, $height) = @getimagesize($physical_path);
496
-            if (($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height']) && $this->config['dir_banner_width'] > 0 && $this->config['dir_banner_height'] > 0) {
530
+            if (($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height']) && $this->config['dir_banner_width'] > 0 && $this->config['dir_banner_height'] > 0)
531
+            {
497 532
                 $coef_w = $width / $this->config['dir_banner_width'];
498 533
                 $coef_h = $height / $this->config['dir_banner_height'];
499 534
                 $coef_max = max($coef_w, $coef_h);
@@ -535,7 +570,8 @@  discard block
 block discarded – undo
535 570
 
536 571
         $this->db->sql_transaction('commit');
537 572
 
538
-        if ($this->request->is_ajax()) {
573
+        if ($this->request->is_ajax())
574
+        {
539 575
             $sql = 'SELECT link_vote, link_note FROM '.DIR_LINK_TABLE.' WHERE link_id = '.(int) $link_id;
540 576
             $result = $this->db->sql_query($sql);
541 577
             $data = $this->db->sql_fetchrow($result);
@@ -564,7 +600,8 @@  discard block
 block discarded – undo
564 600
      */
565 601
     public function thumb_process($url)
566 602
     {
567
-        if (!$this->config['dir_activ_thumb']) {
603
+        if (!$this->config['dir_activ_thumb'])
604
+        {
568 605
             return $this->root_path.'images/directory/nothumb.gif';
569 606
         }
570 607
 
@@ -573,7 +610,8 @@  discard block
 block discarded – undo
573 610
         $root_url = $details['scheme'].'://'.$details['host'];
574 611
         $absolute_url = isset($details['path']) ? $root_url.$details['path'] : $root_url;
575 612
 
576
-        if ($this->config['dir_activ_thumb_remote'] && $this->_ascreen_exist($details['scheme'], $details['host'])) {
613
+        if ($this->config['dir_activ_thumb_remote'] && $this->_ascreen_exist($details['scheme'], $details['host']))
614
+        {
577 615
             return $root_url.'/ascreen.jpg';
578 616
         }
579 617
 
@@ -590,9 +628,11 @@  discard block
 block discarded – undo
590 628
      */
591 629
     private function _ascreen_exist($protocol, $host)
592 630
     {
593
-        if ($thumb_info = @getimagesize($protocol.'://'.$host.'/ascreen.jpg')) {
631
+        if ($thumb_info = @getimagesize($protocol.'://'.$host.'/ascreen.jpg'))
632
+        {
594 633
             // Obviously this is an image, we did some additional tests
595
-            if ($thumb_info[0] == '120' && $thumb_info[1] == '90' && $thumb_info['mime'] == 'image/jpeg') {
634
+            if ($thumb_info[0] == '120' && $thumb_info[1] == '90' && $thumb_info['mime'] == 'image/jpeg')
635
+            {
596 636
                 return true;
597 637
             }
598 638
         }
@@ -617,18 +657,25 @@  discard block
 block discarded – undo
617 657
         // Can we upload?
618 658
         $can_upload = ($this->config['dir_storage_banner'] && file_exists($this->root_path.$destination) && phpbb_is_writable($this->root_path.$destination) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
619 659
 
620
-        if ($banner && $can_upload) {
660
+        if ($banner && $can_upload)
661
+        {
621 662
             $file = $this->_banner_upload($banner, $error);
622
-        } elseif ($banner) {
663
+        }
664
+        elseif ($banner)
665
+        {
623 666
             $file = $this->_banner_remote($banner, $error);
624
-        } elseif ($this->request->is_set_post('delete_banner') && $old_banner) {
667
+        }
668
+        elseif ($this->request->is_set_post('delete_banner') && $old_banner)
669
+        {
625 670
             $this->_banner_delete($old_banner);
626 671
 
627 672
             return;
628 673
         }
629 674
 
630
-        if (!count($error)) {
631
-            if ($banner && $old_banner && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $old_banner)) {
675
+        if (!count($error))
676
+        {
677
+            if ($banner && $old_banner && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $old_banner))
678
+            {
632 679
                 $this->_banner_delete($old_banner);
633 680
             }
634 681
 
@@ -648,7 +695,8 @@  discard block
 block discarded – undo
648 695
     private function _banner_upload($banner, &$error)
649 696
     {
650 697
         // Init upload class
651
-        if (!class_exists('fileupload')) {
698
+        if (!class_exists('fileupload'))
699
+        {
652 700
             include $this->root_path.'includes/functions_upload.'.$this->php_ext;
653 701
         }
654 702
         $upload = new \fileupload('DIR_BANNER_', ['jpg', 'jpeg', 'gif', 'png'], $this->config['dir_banner_filesize']);
@@ -663,7 +711,8 @@  discard block
 block discarded – undo
663 711
         // Move file and overwrite any existing image
664 712
         $file->move_file($destination, true);
665 713
 
666
-        if (count($file->error)) {
714
+        if (count($file->error))
715
+        {
667 716
             $file->remove();
668 717
             $error = array_merge($error, $file->error);
669 718
 
@@ -684,23 +733,27 @@  discard block
 block discarded – undo
684 733
      */
685 734
     private function _banner_remote($banner, &$error)
686 735
     {
687
-        if (!preg_match('#^(http|https|ftp)://#i', $banner)) {
736
+        if (!preg_match('#^(http|https|ftp)://#i', $banner))
737
+        {
688 738
             $banner = 'http://'.$banner;
689 739
         }
690
-        if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $banner)) {
740
+        if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $banner))
741
+        {
691 742
             $error[] = $this->user->lang['DIR_BANNER_URL_INVALID'];
692 743
 
693 744
             return false;
694 745
         }
695 746
 
696 747
         // Make sure getimagesize works...
697
-        if (($image_data = @getimagesize($banner)) === false) {
748
+        if (($image_data = @getimagesize($banner)) === false)
749
+        {
698 750
             $error[] = $this->user->lang['DIR_BANNER_UNABLE_GET_IMAGE_SIZE'];
699 751
 
700 752
             return false;
701 753
         }
702 754
 
703
-        if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) {
755
+        if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2))
756
+        {
704 757
             $error[] = $this->user->lang['DIR_BANNER_UNABLE_GET_IMAGE_SIZE'];
705 758
 
706 759
             return false;
@@ -710,7 +763,8 @@  discard block
 block discarded – undo
710 763
         $height = $image_data[1];
711 764
 
712 765
         // Check image type
713
-        if (!class_exists('fileupload')) {
766
+        if (!class_exists('fileupload'))
767
+        {
714 768
             include $this->root_path.'includes/functions_upload.'.$this->php_ext;
715 769
         }
716 770
 
@@ -718,51 +772,69 @@  discard block
 block discarded – undo
718 772
         $extension = strtolower(\filespec::get_extension($banner));
719 773
 
720 774
         // Check if this is actually an image
721
-        if ($file_stream = @fopen($banner, 'r')) {
775
+        if ($file_stream = @fopen($banner, 'r'))
776
+        {
722 777
             // Timeout after 1 second
723 778
             stream_set_timeout($file_stream, 1);
724 779
             // read some data to ensure headers are present
725 780
             fread($file_stream, 1024);
726 781
             $meta = stream_get_meta_data($file_stream);
727
-            if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers'])) {
782
+            if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers']))
783
+            {
728 784
                 $headers = $meta['wrapper_data']['headers'];
729
-            } elseif (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
785
+            }
786
+            elseif (isset($meta['wrapper_data']) && is_array($meta['wrapper_data']))
787
+            {
730 788
                 $headers = $meta['wrapper_data'];
731
-            } else {
789
+            }
790
+            else
791
+            {
732 792
                 $headers = [];
733 793
             }
734 794
 
735
-            foreach ($headers as $header) {
795
+            foreach ($headers as $header)
796
+            {
736 797
                 $header = preg_split('/ /', $header, 2);
737
-                if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type') {
738
-                    if (strpos($header[1], 'image/') !== 0) {
798
+                if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type')
799
+                {
800
+                    if (strpos($header[1], 'image/') !== 0)
801
+                    {
739 802
                         $error[] = 'DIR_BANNER_URL_INVALID';
740 803
                         fclose($file_stream);
741 804
 
742 805
                         return false;
743
-                    } else {
806
+                    }
807
+                    else
808
+                    {
744 809
                         fclose($file_stream);
745 810
                         break;
746 811
                     }
747 812
                 }
748 813
             }
749
-        } else {
814
+        }
815
+        else
816
+        {
750 817
             $error[] = 'DIR_BANNER_URL_INVALID';
751 818
 
752 819
             return false;
753 820
         }
754 821
 
755
-        if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) {
756
-            if (!isset($types[$image_data[2]])) {
822
+        if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))
823
+        {
824
+            if (!isset($types[$image_data[2]]))
825
+            {
757 826
                 $error[] = $this->user->lang['UNABLE_GET_IMAGE_SIZE'];
758
-            } else {
827
+            }
828
+            else
829
+            {
759 830
                 $error[] = $this->user->lang('DIR_BANNER_IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
760 831
             }
761 832
 
762 833
             return false;
763 834
         }
764 835
 
765
-        if (($this->config['dir_banner_width'] || $this->config['dir_banner_height']) && ($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height'])) {
836
+        if (($this->config['dir_banner_width'] || $this->config['dir_banner_height']) && ($width > $this->config['dir_banner_width'] || $height > $this->config['dir_banner_height']))
837
+        {
766 838
             $error[] = $this->user->lang('DIR_BANNER_WRONG_SIZE', $this->config['dir_banner_width'], $this->config['dir_banner_height'], $width, $height);
767 839
 
768 840
             return false;
@@ -780,7 +852,8 @@  discard block
 block discarded – undo
780 852
      */
781 853
     private function _banner_delete($file)
782 854
     {
783
-        if (file_exists($this->dir_helper->get_banner_path($file))) {
855
+        if (file_exists($this->dir_helper->get_banner_path($file)))
856
+        {
784 857
             @unlink($this->dir_helper->get_banner_path($file));
785 858
 
786 859
             return true;
@@ -813,12 +886,14 @@  discard block
 block discarded – undo
813 886
         $result = 0x01020345;
814 887
         $len = strlen($q);
815 888
 
816
-        for ($i = 0; $i < $len; $i++) {
889
+        for ($i = 0; $i < $len; $i++)
890
+        {
817 891
             $result ^= ord($seed[$i % strlen($seed)]) ^ ord($q[$i]);
818 892
             $result = (($result >> 23) & 0x1ff) | $result << 9;
819 893
         }
820 894
 
821
-        if (PHP_INT_MAX != 2147483647) {
895
+        if (PHP_INT_MAX != 2147483647)
896
+        {
822 897
             $result = -(~($result & 0xFFFFFFFF) + 1);
823 898
         }
824 899
 
@@ -829,7 +904,8 @@  discard block
 block discarded – undo
829 904
         $url = sprintf($url, $host, $ch, $q);
830 905
         @$pr = trim(file_get_contents($url, false));
831 906
 
832
-        if (is_numeric(substr(strrchr($pr, ':'), 1))) {
907
+        if (is_numeric(substr(strrchr($pr, ':'), 1)))
908
+        {
833 909
             return substr(strrchr($pr, ':'), 1);
834 910
         }
835 911
 
@@ -852,19 +928,24 @@  discard block
 block discarded – undo
852 928
 
853 929
         $flags = $this->dir_helper->preg_grep_keys('/^DIR_FLAG_CODE_/i', $this->user->lang);
854 930
 
855
-        if (extension_loaded('intl')) {
931
+        if (extension_loaded('intl'))
932
+        {
856 933
             $locale = $this->user->lang['USER_LANG'];
857 934
 
858 935
             $col = new \Collator($locale);
859 936
             $col->asort($flags);
860
-        } else {
937
+        }
938
+        else
939
+        {
861 940
             asort($flags);
862 941
         }
863 942
 
864
-        foreach ($flags as $file => $name) {
943
+        foreach ($flags as $file => $name)
944
+        {
865 945
             $img_file = strtolower(substr(strrchr($file, '_'), 1)).'.png';
866 946
 
867
-            if (file_exists($flag_path.$img_file)) {
947
+            if (file_exists($flag_path.$img_file))
948
+            {
868 949
                 $list .= '<option value="'.$img_file.'" '.(($img_file == $value) ? 'selected="selected"' : '').'>'.$name.'</option>';
869 950
             }
870 951
         }
@@ -879,7 +960,8 @@  discard block
 block discarded – undo
879 960
      */
880 961
     public function recents()
881 962
     {
882
-        if ($this->config['dir_recent_block']) {
963
+        if ($this->config['dir_recent_block'])
964
+        {
883 965
             $limit_sql = $this->config['dir_recent_rows'] * $this->config['dir_recent_columns'];
884 966
             $exclude_array = explode(',', str_replace(' ', '', $this->config['dir_recent_exclude']));
885 967
 
@@ -905,18 +987,22 @@  discard block
 block discarded – undo
905 987
             $num = 0;
906 988
             $rowset = [];
907 989
 
908
-            while ($site = $this->db->sql_fetchrow($result)) {
990
+            while ($site = $this->db->sql_fetchrow($result))
991
+            {
909 992
                 $rowset[$site['link_id']] = $site;
910 993
             }
911 994
             $this->db->sql_freeresult($result);
912 995
 
913
-            if (count($rowset)) {
996
+            if (count($rowset))
997
+            {
914 998
                 $this->template->assign_block_vars('block', [
915 999
                     'S_COL_WIDTH'            => (100 / $this->config['dir_recent_columns']).'%',
916 1000
                 ]);
917 1001
 
918
-                foreach ($rowset as $row) {
919
-                    if (($num % $this->config['dir_recent_columns']) == 0) {
1002
+                foreach ($rowset as $row)
1003
+                {
1004
+                    if (($num % $this->config['dir_recent_columns']) == 0)
1005
+                    {
920 1006
                         $this->template->assign_block_vars('block.row', []);
921 1007
                     }
922 1008
 
@@ -938,7 +1024,8 @@  discard block
 block discarded – undo
938 1024
                     $num++;
939 1025
                 }
940 1026
 
941
-                while (($num % $this->config['dir_recent_columns']) != 0) {
1027
+                while (($num % $this->config['dir_recent_columns']) != 0)
1028
+                {
942 1029
                     $this->template->assign_block_vars('block.row.col2', []);
943 1030
                     $num++;
944 1031
                 }
@@ -957,27 +1044,33 @@  discard block
 block discarded – undo
957 1044
      */
958 1045
     public function validate_link_back($remote_url, $optional, $cron = false)
959 1046
     {
960
-        if (!$cron) {
961
-            if (empty($remote_url) && $optional) {
1047
+        if (!$cron)
1048
+        {
1049
+            if (empty($remote_url) && $optional)
1050
+            {
962 1051
                 return false;
963 1052
             }
964 1053
 
965
-            if (!preg_match('#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i', $remote_url)) {
1054
+            if (!preg_match('#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i', $remote_url))
1055
+            {
966 1056
                 return 'DIR_ERROR_WRONG_DATA_BACK';
967 1057
             }
968 1058
         }
969 1059
 
970
-        if (false === ($handle = @fopen($remote_url, 'r'))) {
1060
+        if (false === ($handle = @fopen($remote_url, 'r')))
1061
+        {
971 1062
             return 'DIR_ERROR_NOT_FOUND_BACK';
972 1063
         }
973 1064
 
974 1065
         $buff = '';
975 1066
 
976 1067
         // Read by packet, faster than file_get_contents()
977
-        while (!feof($handle)) {
1068
+        while (!feof($handle))
1069
+        {
978 1070
             $buff .= fgets($handle, 256);
979 1071
 
980
-            if (stristr($buff, $this->config['server_name'])) {
1072
+            if (stristr($buff, $this->config['server_name']))
1073
+            {
981 1074
                 @fclose($handle);
982 1075
 
983 1076
                 return false;
@@ -1017,11 +1110,16 @@  discard block
 block discarded – undo
1017 1110
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
1018 1111
         $result = $this->db->sql_query($sql);
1019 1112
 
1020
-        while ($row = $this->db->sql_fetchrow($result)) {
1021
-            if ($this->validate_link_back($row['link_back'], false, true) !== false) {
1022
-                if (!$nb_check || ($row['link_nb_check'] + 1) >= $nb_check) {
1113
+        while ($row = $this->db->sql_fetchrow($result))
1114
+        {
1115
+            if ($this->validate_link_back($row['link_back'], false, true) !== false)
1116
+            {
1117
+                if (!$nb_check || ($row['link_nb_check'] + 1) >= $nb_check)
1118
+                {
1023 1119
                     $del_array[] = $row['link_id'];
1024
-                } else {
1120
+                }
1121
+                else
1122
+                {
1025 1123
                     // A first table containing links ID to update
1026 1124
                     $update_array[$row['link_id']] = $row;
1027 1125
                 }
@@ -1029,10 +1127,12 @@  discard block
 block discarded – undo
1029 1127
         }
1030 1128
         $this->db->sql_freeresult($result);
1031 1129
 
1032
-        if (count($del_array)) {
1130
+        if (count($del_array))
1131
+        {
1033 1132
             $this->del($cat_id, $del_array);
1034 1133
         }
1035
-        if (count($update_array)) {
1134
+        if (count($update_array))
1135
+        {
1036 1136
             $this->_update_check($update_array, $next_prune);
1037 1137
         }
1038 1138
     }
@@ -1055,7 +1155,8 @@  discard block
 block discarded – undo
1055 1155
         $row = $this->db->sql_fetchrow($result);
1056 1156
         $this->db->sql_freeresult($result);
1057 1157
 
1058
-        if ($row) {
1158
+        if ($row)
1159
+        {
1059 1160
             $next_prune = time() + ($cat_data['cat_cron_freq'] * 86400);
1060 1161
 
1061 1162
             $this->_check($cat_data['cat_id'], $cat_data['cat_cron_nb_check'], $next_prune);
@@ -1079,7 +1180,8 @@  discard block
 block discarded – undo
1079 1180
      */
1080 1181
     private function _update_check($u_array, $next_prune)
1081 1182
     {
1082
-        if (!class_exists('messenger')) {
1183
+        if (!class_exists('messenger'))
1184
+        {
1083 1185
             include $this->root_path.'includes/functions_messenger.'.$this->php_ext;
1084 1186
         }
1085 1187
 
@@ -1094,7 +1196,8 @@  discard block
 block discarded – undo
1094 1196
 			WHERE '.$this->db->sql_in_set('link_id', array_keys($u_array));
1095 1197
         $this->db->sql_query($sql);
1096 1198
 
1097
-        foreach ($u_array as $data) {
1199
+        foreach ($u_array as $data)
1200
+        {
1098 1201
             strip_bbcode($data['link_description']);
1099 1202
 
1100 1203
             $notification_data = [
@@ -1106,12 +1209,14 @@  discard block
 block discarded – undo
1106 1209
                     'next_cron'            => $this->user->format_date($next_prune, $data['user_dateformat']),
1107 1210
             ];
1108 1211
 
1109
-            if ($data['link_nb_check']) {
1212
+            if ($data['link_nb_check'])
1213
+            {
1110 1214
                 $this->notification->delete_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', $notification_data);
1111 1215
             }
1112 1216
 
1113 1217
             // New notification system can't send mail to an anonymous user with an email address stored in another table than phpbb_users
1114
-            if ($data['link_user_id'] == ANONYMOUS) {
1218
+            if ($data['link_user_id'] == ANONYMOUS)
1219
+            {
1115 1220
                 $username = $email = $data['link_guest_email'];
1116 1221
 
1117 1222
                 $messenger->template('@ernadoo_phpbbdirectory/directory_website_error_cron', $data['user_lang']);
@@ -1126,7 +1231,9 @@  discard block
 block discarded – undo
1126 1231
                 ]);
1127 1232
 
1128 1233
                 $messenger->send(NOTIFY_EMAIL);
1129
-            } else {
1234
+            }
1235
+            else
1236
+            {
1130 1237
                 $this->notification->add_notifications('ernadoo.phpbbdirectory.notification.type.directory_website_error_cron', $notification_data);
1131 1238
             }
1132 1239
         }
Please login to merge, or discard this patch.
core/comment.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -12,103 +12,103 @@
 block discarded – undo
12 12
  */
13 13
 class comment
14 14
 {
15
-    /** @var \phpbb\db\driver\driver_interface $db */
16
-    protected $db;
17
-
18
-    /** @var \phpbb\user */
19
-    protected $user;
20
-
21
-    /**
22
-     * Constructor.
23
-     *
24
-     * @param \phpbb\db\driver\driver_interface $db   Database object
25
-     * @param \phpbb\user                       $user User object
26
-     */
27
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user)
28
-    {
29
-        $this->db = $db;
30
-        $this->user = $user;
31
-    }
32
-
33
-    /**
34
-     * Add a comment.
35
-     *
36
-     * @param array $data Link's data from db
37
-     *
38
-     * @return null
39
-     */
40
-    public function add($data)
41
-    {
42
-        $this->db->sql_transaction('begin');
43
-
44
-        $sql = 'INSERT INTO '.DIR_COMMENT_TABLE.' '.$this->db->sql_build_array('INSERT', $data);
45
-        $this->db->sql_query($sql);
46
-
47
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
15
+	/** @var \phpbb\db\driver\driver_interface $db */
16
+	protected $db;
17
+
18
+	/** @var \phpbb\user */
19
+	protected $user;
20
+
21
+	/**
22
+	 * Constructor.
23
+	 *
24
+	 * @param \phpbb\db\driver\driver_interface $db   Database object
25
+	 * @param \phpbb\user                       $user User object
26
+	 */
27
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user)
28
+	{
29
+		$this->db = $db;
30
+		$this->user = $user;
31
+	}
32
+
33
+	/**
34
+	 * Add a comment.
35
+	 *
36
+	 * @param array $data Link's data from db
37
+	 *
38
+	 * @return null
39
+	 */
40
+	public function add($data)
41
+	{
42
+		$this->db->sql_transaction('begin');
43
+
44
+		$sql = 'INSERT INTO '.DIR_COMMENT_TABLE.' '.$this->db->sql_build_array('INSERT', $data);
45
+		$this->db->sql_query($sql);
46
+
47
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
48 48
 			SET link_comment = link_comment + 1
49 49
 			WHERE link_id = '.(int) $data['comment_link_id'];
50
-        $this->db->sql_query($sql);
51
-
52
-        $this->db->sql_transaction('commit');
53
-    }
54
-
55
-    /**
56
-     * Edit a comment.
57
-     *
58
-     * @param array $data       Data to edit
59
-     * @param int   $comment_id The comment ID
60
-     *
61
-     * @return null
62
-     */
63
-    public function edit($data, $comment_id)
64
-    {
65
-        $sql = 'UPDATE '.DIR_COMMENT_TABLE.'
50
+		$this->db->sql_query($sql);
51
+
52
+		$this->db->sql_transaction('commit');
53
+	}
54
+
55
+	/**
56
+	 * Edit a comment.
57
+	 *
58
+	 * @param array $data       Data to edit
59
+	 * @param int   $comment_id The comment ID
60
+	 *
61
+	 * @return null
62
+	 */
63
+	public function edit($data, $comment_id)
64
+	{
65
+		$sql = 'UPDATE '.DIR_COMMENT_TABLE.'
66 66
 			SET '.$this->db->sql_build_array('UPDATE', $data).'
67 67
 			WHERE comment_id = '.(int) $comment_id;
68
-        $this->db->sql_query($sql);
69
-    }
70
-
71
-    /**
72
-     * Delete a comment.
73
-     *
74
-     * @param string $link_id    The link ID
75
-     * @param string $comment_id The comment ID
76
-     *
77
-     * @return null
78
-     */
79
-    public function del($link_id, $comment_id)
80
-    {
81
-        global $request;
82
-
83
-        $this->db->sql_transaction('begin');
84
-
85
-        $sql = 'DELETE FROM '.DIR_COMMENT_TABLE.' WHERE comment_id = '.(int) $comment_id;
86
-        $this->db->sql_query($sql);
87
-
88
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
68
+		$this->db->sql_query($sql);
69
+	}
70
+
71
+	/**
72
+	 * Delete a comment.
73
+	 *
74
+	 * @param string $link_id    The link ID
75
+	 * @param string $comment_id The comment ID
76
+	 *
77
+	 * @return null
78
+	 */
79
+	public function del($link_id, $comment_id)
80
+	{
81
+		global $request;
82
+
83
+		$this->db->sql_transaction('begin');
84
+
85
+		$sql = 'DELETE FROM '.DIR_COMMENT_TABLE.' WHERE comment_id = '.(int) $comment_id;
86
+		$this->db->sql_query($sql);
87
+
88
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
89 89
 			SET link_comment = link_comment - 1
90 90
 			WHERE link_id = '.(int) $link_id;
91
-        $this->db->sql_query($sql);
91
+		$this->db->sql_query($sql);
92 92
 
93
-        $this->db->sql_transaction('commit');
93
+		$this->db->sql_transaction('commit');
94 94
 
95
-        if ($request->is_ajax()) {
96
-            $sql = 'SELECT COUNT(comment_id) AS nb_comments
95
+		if ($request->is_ajax()) {
96
+			$sql = 'SELECT COUNT(comment_id) AS nb_comments
97 97
 				FROM '.DIR_COMMENT_TABLE.'
98 98
 				WHERE comment_link_id = '.(int) $link_id;
99
-            $result = $this->db->sql_query($sql);
100
-            $nb_comments = (int) $this->db->sql_fetchfield('nb_comments');
101
-            $this->db->sql_freeresult($result);
102
-
103
-            $json_response = new \phpbb\json_response();
104
-            $json_response->send([
105
-                'success' => true,
106
-
107
-                'MESSAGE_TITLE'        => $this->user->lang['INFORMATION'],
108
-                'MESSAGE_TEXT'         => $this->user->lang['DIR_COMMENT_DELETE_OK'],
109
-                'COMMENT_ID'           => $comment_id,
110
-                'TOTAL_COMMENTS'       => $this->user->lang('DIR_NB_COMMS', $nb_comments),
111
-            ]);
112
-        }
113
-    }
99
+			$result = $this->db->sql_query($sql);
100
+			$nb_comments = (int) $this->db->sql_fetchfield('nb_comments');
101
+			$this->db->sql_freeresult($result);
102
+
103
+			$json_response = new \phpbb\json_response();
104
+			$json_response->send([
105
+				'success' => true,
106
+
107
+				'MESSAGE_TITLE'        => $this->user->lang['INFORMATION'],
108
+				'MESSAGE_TEXT'         => $this->user->lang['DIR_COMMENT_DELETE_OK'],
109
+				'COMMENT_ID'           => $comment_id,
110
+				'TOTAL_COMMENTS'       => $this->user->lang('DIR_NB_COMMS', $nb_comments),
111
+			]);
112
+		}
113
+	}
114 114
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -92,7 +92,8 @@
 block discarded – undo
92 92
 
93 93
         $this->db->sql_transaction('commit');
94 94
 
95
-        if ($request->is_ajax()) {
95
+        if ($request->is_ajax())
96
+        {
96 97
             $sql = 'SELECT COUNT(comment_id) AS nb_comments
97 98
 				FROM '.DIR_COMMENT_TABLE.'
98 99
 				WHERE comment_link_id = '.(int) $link_id;
Please login to merge, or discard this patch.
notification/type/directory_website_error_cron.php 2 patches
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -13,184 +13,184 @@
 block discarded – undo
13 13
  */
14 14
 class directory_website_error_cron extends \phpbb\notification\type\base
15 15
 {
16
-    /**
17
-     * Get notification type name.
18
-     *
19
-     * @return string
20
-     */
21
-    public function get_type()
22
-    {
23
-        return 'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron';
24
-    }
25
-
26
-    /**
27
-     * Notification option data (for outputting to the user).
28
-     *
29
-     * @var bool|array False if the service should use it's default data
30
-     *                 Array of data (including keys 'id', 'lang', and 'group')
31
-     */
32
-    public static $notification_option = [
33
-        'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_ERROR_CHECK',
34
-        'group'    => 'NOTIFICATION_DIR_UCP',
35
-    ];
36
-
37
-    /**
38
-     * Is available.
39
-     *
40
-     * @return bool True/False whether or not this is available to the user
41
-     */
42
-    public function is_available()
43
-    {
44
-        return true;
45
-    }
46
-
47
-    /**
48
-     * Get link id.
49
-     *
50
-     * @param array $data The data from the link
51
-     *
52
-     * @return int
53
-     */
54
-    public static function get_item_id($data)
55
-    {
56
-        return (int) $data['link_id'];
57
-    }
58
-
59
-    /**
60
-     * Get parent id - it's not used.
61
-     *
62
-     * @param array $data The data from the link
63
-     */
64
-    public static function get_item_parent_id($data)
65
-    {
66
-        // No parent
67
-        return 0;
68
-    }
69
-
70
-    /**
71
-     * Find the users who want to receive notifications.
72
-     *
73
-     * @param array $data    Data from submit link
74
-     * @param array $options Options for finding users for notification
75
-     *
76
-     * @return array
77
-     */
78
-    public function find_users_for_notification($data, $options = [])
79
-    {
80
-        $users = [];
81
-
82
-        $sql = 'SELECT link_user_id
16
+	/**
17
+	 * Get notification type name.
18
+	 *
19
+	 * @return string
20
+	 */
21
+	public function get_type()
22
+	{
23
+		return 'ernadoo.phpbbdirectory.notification.type.directory_website_error_cron';
24
+	}
25
+
26
+	/**
27
+	 * Notification option data (for outputting to the user).
28
+	 *
29
+	 * @var bool|array False if the service should use it's default data
30
+	 *                 Array of data (including keys 'id', 'lang', and 'group')
31
+	 */
32
+	public static $notification_option = [
33
+		'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_ERROR_CHECK',
34
+		'group'    => 'NOTIFICATION_DIR_UCP',
35
+	];
36
+
37
+	/**
38
+	 * Is available.
39
+	 *
40
+	 * @return bool True/False whether or not this is available to the user
41
+	 */
42
+	public function is_available()
43
+	{
44
+		return true;
45
+	}
46
+
47
+	/**
48
+	 * Get link id.
49
+	 *
50
+	 * @param array $data The data from the link
51
+	 *
52
+	 * @return int
53
+	 */
54
+	public static function get_item_id($data)
55
+	{
56
+		return (int) $data['link_id'];
57
+	}
58
+
59
+	/**
60
+	 * Get parent id - it's not used.
61
+	 *
62
+	 * @param array $data The data from the link
63
+	 */
64
+	public static function get_item_parent_id($data)
65
+	{
66
+		// No parent
67
+		return 0;
68
+	}
69
+
70
+	/**
71
+	 * Find the users who want to receive notifications.
72
+	 *
73
+	 * @param array $data    Data from submit link
74
+	 * @param array $options Options for finding users for notification
75
+	 *
76
+	 * @return array
77
+	 */
78
+	public function find_users_for_notification($data, $options = [])
79
+	{
80
+		$users = [];
81
+
82
+		$sql = 'SELECT link_user_id
83 83
 			FROM '.DIR_LINK_TABLE.'
84 84
 			WHERE link_id = '.(int) $data['link_id'];
85
-        $result = $this->db->sql_query($sql);
86
-        while ($row = $this->db->sql_fetchrow($result)) {
87
-            $users[] = (int) $row['link_user_id'];
88
-        }
89
-        $this->db->sql_freeresult($result);
90
-
91
-        if (empty($users)) {
92
-            return [];
93
-        }
94
-
95
-        sort($users);
96
-
97
-        return $this->check_user_notification_options($users, $options);
98
-    }
99
-
100
-    /**
101
-     * Get the HTML formatted title of this notification.
102
-     *
103
-     * @return string
104
-     */
105
-    public function get_title()
106
-    {
107
-        $link_name = $this->get_data('link_name');
108
-        $cat_name = $this->get_data('cat_name');
109
-
110
-        return $this->user->lang('NOTIFICATION_DIR_WEBSITE_ERROR_CHECK', $link_name, $cat_name);
111
-    }
112
-
113
-    /**
114
-     * Get email template.
115
-     *
116
-     * @return string
117
-     */
118
-    public function get_email_template()
119
-    {
120
-        return '@ernadoo_phpbbdirectory/directory_website_error_cron';
121
-    }
122
-
123
-    /**
124
-     * Get email template variables.
125
-     *
126
-     * @return array
127
-     */
128
-    public function get_email_template_variables()
129
-    {
130
-        return [
131
-                'LINK_NAME'            => $this->get_data('link_name'),
132
-                'LINK_URL'             => $this->get_data('link_url'),
133
-                'LINK_DESCRIPTION'     => $this->get_data('link_description'),
134
-                'NEXT_CRON'            => $this->get_data('next_cron'),
135
-            ];
136
-    }
137
-
138
-    /**
139
-     * Get the url to this item.
140
-     *
141
-     * @return string URL
142
-     */
143
-    public function get_url()
144
-    {
145
-        return '';
146
-    }
147
-
148
-    /**
149
-     * Users needed to query before this notification can be displayed.
150
-     *
151
-     * @return array Array of user_ids
152
-     */
153
-    public function users_to_query()
154
-    {
155
-        return [];
156
-    }
157
-
158
-    /**
159
-     * Function for preparing the data for insertion in an SQL query
160
-     * (The service handles insertion).
161
-     *
162
-     * @param array $data            Data from submit link
163
-     * @param array $pre_create_data Data from pre_create_insert_array()
164
-     *
165
-     * @return array Array of data ready to be inserted into the database
166
-     */
167
-    public function create_insert_array($data, $pre_create_data = [])
168
-    {
169
-        $this->set_data('link_name', $data['link_name']);
170
-        $this->set_data('cat_name', $data['cat_name']);
171
-
172
-        $this->set_data('link_url', $data['link_url']);
173
-        $this->set_data('link_description', $data['link_description']);
174
-        $this->set_data('next_cron', $data['next_cron']);
175
-
176
-        return parent::create_insert_array($data, $pre_create_data);
177
-    }
178
-
179
-    /**
180
-     * Function for preparing the data for update in an SQL query
181
-     * (The service handles insertion).
182
-     *
183
-     * @param array $type_data Data unique to this notification type
184
-     *
185
-     * @return array Array of data ready to be updated in the database
186
-     */
187
-    public function create_update_array($type_data)
188
-    {
189
-        $data = $this->create_insert_array($type_data);
190
-
191
-        $data['notification_time'] = time();
192
-        $data['notification_read'] = 0;
193
-
194
-        return $data;
195
-    }
85
+		$result = $this->db->sql_query($sql);
86
+		while ($row = $this->db->sql_fetchrow($result)) {
87
+			$users[] = (int) $row['link_user_id'];
88
+		}
89
+		$this->db->sql_freeresult($result);
90
+
91
+		if (empty($users)) {
92
+			return [];
93
+		}
94
+
95
+		sort($users);
96
+
97
+		return $this->check_user_notification_options($users, $options);
98
+	}
99
+
100
+	/**
101
+	 * Get the HTML formatted title of this notification.
102
+	 *
103
+	 * @return string
104
+	 */
105
+	public function get_title()
106
+	{
107
+		$link_name = $this->get_data('link_name');
108
+		$cat_name = $this->get_data('cat_name');
109
+
110
+		return $this->user->lang('NOTIFICATION_DIR_WEBSITE_ERROR_CHECK', $link_name, $cat_name);
111
+	}
112
+
113
+	/**
114
+	 * Get email template.
115
+	 *
116
+	 * @return string
117
+	 */
118
+	public function get_email_template()
119
+	{
120
+		return '@ernadoo_phpbbdirectory/directory_website_error_cron';
121
+	}
122
+
123
+	/**
124
+	 * Get email template variables.
125
+	 *
126
+	 * @return array
127
+	 */
128
+	public function get_email_template_variables()
129
+	{
130
+		return [
131
+				'LINK_NAME'            => $this->get_data('link_name'),
132
+				'LINK_URL'             => $this->get_data('link_url'),
133
+				'LINK_DESCRIPTION'     => $this->get_data('link_description'),
134
+				'NEXT_CRON'            => $this->get_data('next_cron'),
135
+			];
136
+	}
137
+
138
+	/**
139
+	 * Get the url to this item.
140
+	 *
141
+	 * @return string URL
142
+	 */
143
+	public function get_url()
144
+	{
145
+		return '';
146
+	}
147
+
148
+	/**
149
+	 * Users needed to query before this notification can be displayed.
150
+	 *
151
+	 * @return array Array of user_ids
152
+	 */
153
+	public function users_to_query()
154
+	{
155
+		return [];
156
+	}
157
+
158
+	/**
159
+	 * Function for preparing the data for insertion in an SQL query
160
+	 * (The service handles insertion).
161
+	 *
162
+	 * @param array $data            Data from submit link
163
+	 * @param array $pre_create_data Data from pre_create_insert_array()
164
+	 *
165
+	 * @return array Array of data ready to be inserted into the database
166
+	 */
167
+	public function create_insert_array($data, $pre_create_data = [])
168
+	{
169
+		$this->set_data('link_name', $data['link_name']);
170
+		$this->set_data('cat_name', $data['cat_name']);
171
+
172
+		$this->set_data('link_url', $data['link_url']);
173
+		$this->set_data('link_description', $data['link_description']);
174
+		$this->set_data('next_cron', $data['next_cron']);
175
+
176
+		return parent::create_insert_array($data, $pre_create_data);
177
+	}
178
+
179
+	/**
180
+	 * Function for preparing the data for update in an SQL query
181
+	 * (The service handles insertion).
182
+	 *
183
+	 * @param array $type_data Data unique to this notification type
184
+	 *
185
+	 * @return array Array of data ready to be updated in the database
186
+	 */
187
+	public function create_update_array($type_data)
188
+	{
189
+		$data = $this->create_insert_array($type_data);
190
+
191
+		$data['notification_time'] = time();
192
+		$data['notification_read'] = 0;
193
+
194
+		return $data;
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -83,12 +83,14 @@
 block discarded – undo
83 83
 			FROM '.DIR_LINK_TABLE.'
84 84
 			WHERE link_id = '.(int) $data['link_id'];
85 85
         $result = $this->db->sql_query($sql);
86
-        while ($row = $this->db->sql_fetchrow($result)) {
86
+        while ($row = $this->db->sql_fetchrow($result))
87
+        {
87 88
             $users[] = (int) $row['link_user_id'];
88 89
         }
89 90
         $this->db->sql_freeresult($result);
90 91
 
91
-        if (empty($users)) {
92
+        if (empty($users))
93
+        {
92 94
             return [];
93 95
         }
94 96
 
Please login to merge, or discard this patch.
notification/type/directory_website_approved.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -13,161 +13,161 @@
 block discarded – undo
13 13
  */
14 14
 class directory_website_approved extends \phpbb\notification\type\base
15 15
 {
16
-    /**
17
-     * Get notification type name.
18
-     *
19
-     * @return string
20
-     */
21
-    public function get_type()
22
-    {
23
-        return 'ernadoo.phpbbdirectory.notification.type.directory_website_approved';
24
-    }
25
-
26
-    /**
27
-     * Notification option data (for outputting to the user).
28
-     *
29
-     * @var bool|array False if the service should use it's default data
30
-     *                 Array of data (including keys 'id', 'lang', and 'group')
31
-     */
32
-    public static $notification_option = [
33
-        'id'       => 'dir_moderation_queue',
34
-        'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_MODERATION_QUEUE',
35
-        'group'    => 'NOTIFICATION_DIR_UCP',
36
-    ];
37
-
38
-    /**
39
-     * Permission to check for (in find_users_for_notification).
40
-     *
41
-     * @var string Permission name
42
-     */
43
-    protected $permission = ['a_', 'm_'];
44
-
45
-    /**
46
-     * Is available.
47
-     *
48
-     * @return bool True/False whether or not this is available to the user
49
-     */
50
-    public function is_available()
51
-    {
52
-        $has_permission = $this->auth->acl_gets($this->permission, true);
53
-
54
-        return empty($has_permission);
55
-    }
56
-
57
-    /**
58
-     * Get link id.
59
-     *
60
-     * @param array $data The data from the link
61
-     *
62
-     * @return int
63
-     */
64
-    public static function get_item_id($data)
65
-    {
66
-        return (int) $data['link_id'];
67
-    }
68
-
69
-    /**
70
-     * Get parent id - it's not used.
71
-     *
72
-     * @param array $data The data from the link
73
-     */
74
-    public static function get_item_parent_id($data)
75
-    {
76
-        // No parent
77
-        return 0;
78
-    }
79
-
80
-    /**
81
-     * Find the users who want to receive notifications.
82
-     *
83
-     * @param array $data    Data from submit link
84
-     * @param array $options Options for finding users for notification
85
-     *
86
-     * @return array
87
-     */
88
-    public function find_users_for_notification($data, $options = [])
89
-    {
90
-        $options = array_merge([
91
-            'ignore_users'        => [],
92
-        ], $options);
93
-
94
-        $users = [$data['user_from']];
95
-
96
-        return $this->check_user_notification_options($users, array_merge($options, [
97
-            'item_type'        => self::$notification_option['id'],
98
-        ]));
99
-    }
100
-
101
-    /**
102
-     * Get the HTML formatted title of this notification.
103
-     *
104
-     * @return string
105
-     */
106
-    public function get_title()
107
-    {
108
-        $link_name = $this->get_data('link_name');
109
-        $cat_name = $this->get_data('cat_name');
110
-
111
-        return $this->user->lang('NOTIFICATION_DIR_WEBSITE_APPROVED', $link_name, $cat_name);
112
-    }
113
-
114
-    /**
115
-     * Get email template.
116
-     *
117
-     * @return string
118
-     */
119
-    public function get_email_template()
120
-    {
121
-        return '@ernadoo_phpbbdirectory/directory_website_approved';
122
-    }
123
-
124
-    /**
125
-     * Get email template variables.
126
-     *
127
-     * @return array
128
-     */
129
-    public function get_email_template_variables()
130
-    {
131
-        return [
132
-            'LINK_NAME'    => htmlspecialchars_decode($this->get_data('link_name')),
133
-        ];
134
-    }
135
-
136
-    /**
137
-     * Get the url to this item.
138
-     *
139
-     * @return string URL
140
-     */
141
-    public function get_url()
142
-    {
143
-        return append_sid($this->phpbb_root_path.'directory/categorie/'.(int) $this->get_data('cat_id'));
144
-    }
145
-
146
-    /**
147
-     * Users needed to query before this notification can be displayed.
148
-     *
149
-     * @return array Array of user_ids
150
-     */
151
-    public function users_to_query()
152
-    {
153
-        return [];
154
-    }
155
-
156
-    /**
157
-     * Function for preparing the data for insertion in an SQL query
158
-     * (The service handles insertion).
159
-     *
160
-     * @param array $data            Data from submit link
161
-     * @param array $pre_create_data Data from pre_create_insert_array()
162
-     *
163
-     * @return array Array of data ready to be inserted into the database
164
-     */
165
-    public function create_insert_array($data, $pre_create_data = [])
166
-    {
167
-        $this->set_data('link_name', $data['link_name']);
168
-        $this->set_data('cat_id', $data['cat_id']);
169
-        $this->set_data('cat_name', $data['cat_name']);
170
-
171
-        return parent::create_insert_array($data, $pre_create_data);
172
-    }
16
+	/**
17
+	 * Get notification type name.
18
+	 *
19
+	 * @return string
20
+	 */
21
+	public function get_type()
22
+	{
23
+		return 'ernadoo.phpbbdirectory.notification.type.directory_website_approved';
24
+	}
25
+
26
+	/**
27
+	 * Notification option data (for outputting to the user).
28
+	 *
29
+	 * @var bool|array False if the service should use it's default data
30
+	 *                 Array of data (including keys 'id', 'lang', and 'group')
31
+	 */
32
+	public static $notification_option = [
33
+		'id'       => 'dir_moderation_queue',
34
+		'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_MODERATION_QUEUE',
35
+		'group'    => 'NOTIFICATION_DIR_UCP',
36
+	];
37
+
38
+	/**
39
+	 * Permission to check for (in find_users_for_notification).
40
+	 *
41
+	 * @var string Permission name
42
+	 */
43
+	protected $permission = ['a_', 'm_'];
44
+
45
+	/**
46
+	 * Is available.
47
+	 *
48
+	 * @return bool True/False whether or not this is available to the user
49
+	 */
50
+	public function is_available()
51
+	{
52
+		$has_permission = $this->auth->acl_gets($this->permission, true);
53
+
54
+		return empty($has_permission);
55
+	}
56
+
57
+	/**
58
+	 * Get link id.
59
+	 *
60
+	 * @param array $data The data from the link
61
+	 *
62
+	 * @return int
63
+	 */
64
+	public static function get_item_id($data)
65
+	{
66
+		return (int) $data['link_id'];
67
+	}
68
+
69
+	/**
70
+	 * Get parent id - it's not used.
71
+	 *
72
+	 * @param array $data The data from the link
73
+	 */
74
+	public static function get_item_parent_id($data)
75
+	{
76
+		// No parent
77
+		return 0;
78
+	}
79
+
80
+	/**
81
+	 * Find the users who want to receive notifications.
82
+	 *
83
+	 * @param array $data    Data from submit link
84
+	 * @param array $options Options for finding users for notification
85
+	 *
86
+	 * @return array
87
+	 */
88
+	public function find_users_for_notification($data, $options = [])
89
+	{
90
+		$options = array_merge([
91
+			'ignore_users'        => [],
92
+		], $options);
93
+
94
+		$users = [$data['user_from']];
95
+
96
+		return $this->check_user_notification_options($users, array_merge($options, [
97
+			'item_type'        => self::$notification_option['id'],
98
+		]));
99
+	}
100
+
101
+	/**
102
+	 * Get the HTML formatted title of this notification.
103
+	 *
104
+	 * @return string
105
+	 */
106
+	public function get_title()
107
+	{
108
+		$link_name = $this->get_data('link_name');
109
+		$cat_name = $this->get_data('cat_name');
110
+
111
+		return $this->user->lang('NOTIFICATION_DIR_WEBSITE_APPROVED', $link_name, $cat_name);
112
+	}
113
+
114
+	/**
115
+	 * Get email template.
116
+	 *
117
+	 * @return string
118
+	 */
119
+	public function get_email_template()
120
+	{
121
+		return '@ernadoo_phpbbdirectory/directory_website_approved';
122
+	}
123
+
124
+	/**
125
+	 * Get email template variables.
126
+	 *
127
+	 * @return array
128
+	 */
129
+	public function get_email_template_variables()
130
+	{
131
+		return [
132
+			'LINK_NAME'    => htmlspecialchars_decode($this->get_data('link_name')),
133
+		];
134
+	}
135
+
136
+	/**
137
+	 * Get the url to this item.
138
+	 *
139
+	 * @return string URL
140
+	 */
141
+	public function get_url()
142
+	{
143
+		return append_sid($this->phpbb_root_path.'directory/categorie/'.(int) $this->get_data('cat_id'));
144
+	}
145
+
146
+	/**
147
+	 * Users needed to query before this notification can be displayed.
148
+	 *
149
+	 * @return array Array of user_ids
150
+	 */
151
+	public function users_to_query()
152
+	{
153
+		return [];
154
+	}
155
+
156
+	/**
157
+	 * Function for preparing the data for insertion in an SQL query
158
+	 * (The service handles insertion).
159
+	 *
160
+	 * @param array $data            Data from submit link
161
+	 * @param array $pre_create_data Data from pre_create_insert_array()
162
+	 *
163
+	 * @return array Array of data ready to be inserted into the database
164
+	 */
165
+	public function create_insert_array($data, $pre_create_data = [])
166
+	{
167
+		$this->set_data('link_name', $data['link_name']);
168
+		$this->set_data('cat_id', $data['cat_id']);
169
+		$this->set_data('cat_name', $data['cat_name']);
170
+
171
+		return parent::create_insert_array($data, $pre_create_data);
172
+	}
173 173
 }
Please login to merge, or discard this patch.
notification/type/directory_website.php 2 patches
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -13,181 +13,181 @@
 block discarded – undo
13 13
  */
14 14
 class directory_website extends \phpbb\notification\type\base
15 15
 {
16
-    /**
17
-     * Get notification type name.
18
-     *
19
-     * @return string
20
-     */
21
-    public function get_type()
22
-    {
23
-        return 'ernadoo.phpbbdirectory.notification.type.directory_website';
24
-    }
25
-
26
-    /**
27
-     * Notification option data (for outputting to the user).
28
-     *
29
-     * @var bool|array False if the service should use it's default data
30
-     *                 Array of data (including keys 'id', 'lang', and 'group')
31
-     */
32
-    public static $notification_option = [
33
-        'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_WEBSITE',
34
-        'group'    => 'NOTIFICATION_DIR_UCP',
35
-    ];
36
-
37
-    /**
38
-     * Is available.
39
-     *
40
-     * @return bool True/False whether or not this is available to the user
41
-     */
42
-    public function is_available()
43
-    {
44
-        return true;
45
-    }
46
-
47
-    /**
48
-     * Get link id.
49
-     *
50
-     * @param array $data The data from the link
51
-     *
52
-     * @return int
53
-     */
54
-    public static function get_item_id($data)
55
-    {
56
-        return (int) $data['link_id'];
57
-    }
58
-
59
-    /**
60
-     * Get parent id - it's not used.
61
-     *
62
-     * @param array $data The data from the link
63
-     */
64
-    public static function get_item_parent_id($data)
65
-    {
66
-        // No parent
67
-        return 0;
68
-    }
69
-
70
-    /**
71
-     * Find the users who want to receive notifications.
72
-     *
73
-     * @param array $data    Data from submit link
74
-     * @param array $options Options for finding users for notification
75
-     *
76
-     * @return array
77
-     */
78
-    public function find_users_for_notification($data, $options = [])
79
-    {
80
-        $options = array_merge([
81
-            'ignore_users'        => [],
82
-        ], $options);
83
-
84
-        $users = [];
85
-
86
-        $sql = 'SELECT user_id
16
+	/**
17
+	 * Get notification type name.
18
+	 *
19
+	 * @return string
20
+	 */
21
+	public function get_type()
22
+	{
23
+		return 'ernadoo.phpbbdirectory.notification.type.directory_website';
24
+	}
25
+
26
+	/**
27
+	 * Notification option data (for outputting to the user).
28
+	 *
29
+	 * @var bool|array False if the service should use it's default data
30
+	 *                 Array of data (including keys 'id', 'lang', and 'group')
31
+	 */
32
+	public static $notification_option = [
33
+		'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_WEBSITE',
34
+		'group'    => 'NOTIFICATION_DIR_UCP',
35
+	];
36
+
37
+	/**
38
+	 * Is available.
39
+	 *
40
+	 * @return bool True/False whether or not this is available to the user
41
+	 */
42
+	public function is_available()
43
+	{
44
+		return true;
45
+	}
46
+
47
+	/**
48
+	 * Get link id.
49
+	 *
50
+	 * @param array $data The data from the link
51
+	 *
52
+	 * @return int
53
+	 */
54
+	public static function get_item_id($data)
55
+	{
56
+		return (int) $data['link_id'];
57
+	}
58
+
59
+	/**
60
+	 * Get parent id - it's not used.
61
+	 *
62
+	 * @param array $data The data from the link
63
+	 */
64
+	public static function get_item_parent_id($data)
65
+	{
66
+		// No parent
67
+		return 0;
68
+	}
69
+
70
+	/**
71
+	 * Find the users who want to receive notifications.
72
+	 *
73
+	 * @param array $data    Data from submit link
74
+	 * @param array $options Options for finding users for notification
75
+	 *
76
+	 * @return array
77
+	 */
78
+	public function find_users_for_notification($data, $options = [])
79
+	{
80
+		$options = array_merge([
81
+			'ignore_users'        => [],
82
+		], $options);
83
+
84
+		$users = [];
85
+
86
+		$sql = 'SELECT user_id
87 87
 			FROM '.DIR_WATCH_TABLE.'
88 88
 			WHERE cat_id = '.(int) $data['cat_id'].'
89 89
 				AND notify_status = '.NOTIFY_YES.'
90 90
 				AND user_id <> '.(int) $data['user_from'];
91
-        $result = $this->db->sql_query($sql);
92
-        while ($row = $this->db->sql_fetchrow($result)) {
93
-            $users[] = (int) $row['user_id'];
94
-        }
95
-        $this->db->sql_freeresult($result);
96
-
97
-        if (empty($users)) {
98
-            return [];
99
-        }
100
-
101
-        sort($users);
102
-
103
-        return $this->check_user_notification_options($users, $options);
104
-    }
105
-
106
-    /**
107
-     * Get the user's avatar.
108
-     */
109
-    public function get_avatar()
110
-    {
111
-        return $this->user_loader->get_avatar($this->get_data('user_from'), false, true);
112
-    }
113
-
114
-    /**
115
-     * Get the HTML formatted title of this notification.
116
-     *
117
-     * @return string
118
-     */
119
-    public function get_title()
120
-    {
121
-        $link_name = $this->get_data('link_name');
122
-        $username = $this->user_loader->get_username($this->get_data('user_from'), 'no_profile');
123
-        $cat_name = $this->get_data('cat_name');
124
-
125
-        return $this->user->lang('NOTIFICATION_DIR_NEW', $username, $link_name, $cat_name);
126
-    }
127
-
128
-    /**
129
-     * Get email template.
130
-     *
131
-     * @return string
132
-     */
133
-    public function get_email_template()
134
-    {
135
-        return '@ernadoo_phpbbdirectory/directory_website';
136
-    }
137
-
138
-    /**
139
-     * Get email template variables.
140
-     *
141
-     * @return array
142
-     */
143
-    public function get_email_template_variables()
144
-    {
145
-        return [
146
-            'CAT_NAME'             => $this->get_data('cat_name'),
147
-            'LINK_NAME'            => htmlspecialchars_decode($this->get_data('link_name')),
148
-            'LINK_URL'             => $this->get_data('link_url'),
149
-            'LINK_DESCRIPTION'     => $this->get_data('link_description'),
150
-        ];
151
-    }
152
-
153
-    /**
154
-     * Get the url to this item.
155
-     *
156
-     * @return string URL
157
-     */
158
-    public function get_url()
159
-    {
160
-        return append_sid($this->phpbb_root_path.'directory/categorie/'.(int) $this->get_data('cat_id'));
161
-    }
162
-
163
-    /**
164
-     * Users needed to query before this notification can be displayed.
165
-     *
166
-     * @return array Array of user_ids
167
-     */
168
-    public function users_to_query()
169
-    {
170
-        return [$this->get_data('user_from')];
171
-    }
172
-
173
-    /**
174
-     * Function for preparing the data for insertion in an SQL query
175
-     * (The service handles insertion).
176
-     *
177
-     * @param array $data            Data from submit link
178
-     * @param array $pre_create_data Data from pre_create_insert_array()
179
-     *
180
-     * @return array Array of data ready to be inserted into the database
181
-     */
182
-    public function create_insert_array($data, $pre_create_data = [])
183
-    {
184
-        $this->set_data('link_name', $data['link_name']);
185
-        $this->set_data('link_url', $data['link_url']);
186
-        $this->set_data('link_description', $data['link_description']);
187
-        $this->set_data('user_from', $data['user_from']);
188
-        $this->set_data('cat_id', $data['cat_id']);
189
-        $this->set_data('cat_name', $data['cat_name']);
190
-
191
-        return parent::create_insert_array($data, $pre_create_data);
192
-    }
91
+		$result = $this->db->sql_query($sql);
92
+		while ($row = $this->db->sql_fetchrow($result)) {
93
+			$users[] = (int) $row['user_id'];
94
+		}
95
+		$this->db->sql_freeresult($result);
96
+
97
+		if (empty($users)) {
98
+			return [];
99
+		}
100
+
101
+		sort($users);
102
+
103
+		return $this->check_user_notification_options($users, $options);
104
+	}
105
+
106
+	/**
107
+	 * Get the user's avatar.
108
+	 */
109
+	public function get_avatar()
110
+	{
111
+		return $this->user_loader->get_avatar($this->get_data('user_from'), false, true);
112
+	}
113
+
114
+	/**
115
+	 * Get the HTML formatted title of this notification.
116
+	 *
117
+	 * @return string
118
+	 */
119
+	public function get_title()
120
+	{
121
+		$link_name = $this->get_data('link_name');
122
+		$username = $this->user_loader->get_username($this->get_data('user_from'), 'no_profile');
123
+		$cat_name = $this->get_data('cat_name');
124
+
125
+		return $this->user->lang('NOTIFICATION_DIR_NEW', $username, $link_name, $cat_name);
126
+	}
127
+
128
+	/**
129
+	 * Get email template.
130
+	 *
131
+	 * @return string
132
+	 */
133
+	public function get_email_template()
134
+	{
135
+		return '@ernadoo_phpbbdirectory/directory_website';
136
+	}
137
+
138
+	/**
139
+	 * Get email template variables.
140
+	 *
141
+	 * @return array
142
+	 */
143
+	public function get_email_template_variables()
144
+	{
145
+		return [
146
+			'CAT_NAME'             => $this->get_data('cat_name'),
147
+			'LINK_NAME'            => htmlspecialchars_decode($this->get_data('link_name')),
148
+			'LINK_URL'             => $this->get_data('link_url'),
149
+			'LINK_DESCRIPTION'     => $this->get_data('link_description'),
150
+		];
151
+	}
152
+
153
+	/**
154
+	 * Get the url to this item.
155
+	 *
156
+	 * @return string URL
157
+	 */
158
+	public function get_url()
159
+	{
160
+		return append_sid($this->phpbb_root_path.'directory/categorie/'.(int) $this->get_data('cat_id'));
161
+	}
162
+
163
+	/**
164
+	 * Users needed to query before this notification can be displayed.
165
+	 *
166
+	 * @return array Array of user_ids
167
+	 */
168
+	public function users_to_query()
169
+	{
170
+		return [$this->get_data('user_from')];
171
+	}
172
+
173
+	/**
174
+	 * Function for preparing the data for insertion in an SQL query
175
+	 * (The service handles insertion).
176
+	 *
177
+	 * @param array $data            Data from submit link
178
+	 * @param array $pre_create_data Data from pre_create_insert_array()
179
+	 *
180
+	 * @return array Array of data ready to be inserted into the database
181
+	 */
182
+	public function create_insert_array($data, $pre_create_data = [])
183
+	{
184
+		$this->set_data('link_name', $data['link_name']);
185
+		$this->set_data('link_url', $data['link_url']);
186
+		$this->set_data('link_description', $data['link_description']);
187
+		$this->set_data('user_from', $data['user_from']);
188
+		$this->set_data('cat_id', $data['cat_id']);
189
+		$this->set_data('cat_name', $data['cat_name']);
190
+
191
+		return parent::create_insert_array($data, $pre_create_data);
192
+	}
193 193
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,12 +89,14 @@
 block discarded – undo
89 89
 				AND notify_status = '.NOTIFY_YES.'
90 90
 				AND user_id <> '.(int) $data['user_from'];
91 91
         $result = $this->db->sql_query($sql);
92
-        while ($row = $this->db->sql_fetchrow($result)) {
92
+        while ($row = $this->db->sql_fetchrow($result))
93
+        {
93 94
             $users[] = (int) $row['user_id'];
94 95
         }
95 96
         $this->db->sql_freeresult($result);
96 97
 
97
-        if (empty($users)) {
98
+        if (empty($users))
99
+        {
98 100
             return [];
99 101
         }
100 102
 
Please login to merge, or discard this patch.
notification/type/directory_website_in_queue.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -13,173 +13,173 @@
 block discarded – undo
13 13
  */
14 14
 class directory_website_in_queue extends \phpbb\notification\type\base
15 15
 {
16
-    /**
17
-     * Get notification type name.
18
-     *
19
-     * @return string
20
-     */
21
-    public function get_type()
22
-    {
23
-        return 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
24
-    }
25
-
26
-    /**
27
-     * Notification option data (for outputting to the user).
28
-     *
29
-     * @var bool|array False if the service should use it's default data
30
-     *                 Array of data (including keys 'id', 'lang', and 'group')
31
-     */
32
-    public static $notification_option = [
33
-        'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_IN_MODERATION_QUEUE',
34
-        'group'    => 'NOTIFICATION_DIR_UCP',
35
-    ];
36
-
37
-    /**
38
-     * Permission to check for (in find_users_for_notification).
39
-     *
40
-     * @var string Permission name
41
-     */
42
-    protected $permission = 'a_';
43
-
44
-    /**
45
-     * Is available.
46
-     *
47
-     * @return bool True/False whether or not this is available to the user
48
-     */
49
-    public function is_available()
50
-    {
51
-        $has_permission = $this->auth->acl_get($this->permission, true);
52
-
53
-        return !empty($has_permission);
54
-    }
55
-
56
-    /**
57
-     * Get link id.
58
-     *
59
-     * @param array $data The data from the link
60
-     *
61
-     * @return int
62
-     */
63
-    public static function get_item_id($data)
64
-    {
65
-        return (int) $data['link_id'];
66
-    }
67
-
68
-    /**
69
-     * Get parent id - it's not used.
70
-     *
71
-     * @param array $data The data from the link
72
-     */
73
-    public static function get_item_parent_id($data)
74
-    {
75
-        // No parent
76
-        return 0;
77
-    }
78
-
79
-    /**
80
-     * Find the users who want to receive notifications.
81
-     *
82
-     * @param array $data    Data from submit link
83
-     * @param array $options Options for finding users for notification
84
-     *
85
-     * @return array
86
-     */
87
-    public function find_users_for_notification($data, $options = [])
88
-    {
89
-        $options = array_merge([
90
-            'ignore_users'        => [],
91
-        ], $options);
92
-
93
-        // 0 is for global moderator permissions
94
-        $admin_ary = $this->auth->acl_get_list(false, $this->permission);
95
-        $users = (!empty($admin_ary[0][$this->permission])) ? $admin_ary[0][$this->permission] : [];
96
-
97
-        if (empty($users)) {
98
-            return [];
99
-        }
100
-
101
-        return $this->check_user_notification_options($users, $options);
102
-    }
103
-
104
-    /**
105
-     * Get the user's avatar.
106
-     */
107
-    public function get_avatar()
108
-    {
109
-        return $this->user_loader->get_avatar($this->get_data('user_from'), false, true);
110
-    }
111
-
112
-    /**
113
-     * Get the HTML formatted title of this notification.
114
-     *
115
-     * @return string
116
-     */
117
-    public function get_title()
118
-    {
119
-        $link_name = $this->get_data('link_name');
120
-        $username = $this->user_loader->get_username($this->get_data('user_from'), 'no_profile');
121
-
122
-        return $this->user->lang('NOTIFICATION_DIR_WEBSITE_IN_QUEUE', $link_name, $username);
123
-    }
124
-
125
-    /**
126
-     * Get email template.
127
-     *
128
-     * @return string
129
-     */
130
-    public function get_email_template()
131
-    {
132
-        return '@ernadoo_phpbbdirectory/directory_website_in_queue';
133
-    }
134
-
135
-    /**
136
-     * Get email template variables.
137
-     *
138
-     * @return array
139
-     */
140
-    public function get_email_template_variables()
141
-    {
142
-        return [];
143
-    }
144
-
145
-    /**
146
-     * Get the url to this item.
147
-     *
148
-     * @return string URL
149
-     */
150
-    public function get_url()
151
-    {
152
-        global $phpbb_admin_path;
153
-
154
-        return append_sid("{$phpbb_admin_path}index.{$this->php_ext}", ['i' => '-ernadoo-phpbbdirectory-acp-phpbbdirectory_module', 'mode' => 'val'], true, $this->user->session_id);
155
-    }
156
-
157
-    /**
158
-     * Users needed to query before this notification can be displayed.
159
-     *
160
-     * @return array Array of user_ids
161
-     */
162
-    public function users_to_query()
163
-    {
164
-        return [$this->get_data('user_from')];
165
-    }
166
-
167
-    /**
168
-     * Function for preparing the data for insertion in an SQL query
169
-     * (The service handles insertion).
170
-     *
171
-     * @param array $data            Data from submit link
172
-     * @param array $pre_create_data Data from pre_create_insert_array()
173
-     *
174
-     * @return array Array of data ready to be inserted into the database
175
-     */
176
-    public function create_insert_array($data, $pre_create_data = [])
177
-    {
178
-        $this->set_data('user_from', $data['user_from']);
179
-        $this->set_data('link_name', $data['link_name']);
180
-        $this->set_data('cat_id', $data['cat_id']);
181
-        $this->set_data('cat_name', $data['cat_name']);
182
-
183
-        return parent::create_insert_array($data, $pre_create_data);
184
-    }
16
+	/**
17
+	 * Get notification type name.
18
+	 *
19
+	 * @return string
20
+	 */
21
+	public function get_type()
22
+	{
23
+		return 'ernadoo.phpbbdirectory.notification.type.directory_website_in_queue';
24
+	}
25
+
26
+	/**
27
+	 * Notification option data (for outputting to the user).
28
+	 *
29
+	 * @var bool|array False if the service should use it's default data
30
+	 *                 Array of data (including keys 'id', 'lang', and 'group')
31
+	 */
32
+	public static $notification_option = [
33
+		'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_IN_MODERATION_QUEUE',
34
+		'group'    => 'NOTIFICATION_DIR_UCP',
35
+	];
36
+
37
+	/**
38
+	 * Permission to check for (in find_users_for_notification).
39
+	 *
40
+	 * @var string Permission name
41
+	 */
42
+	protected $permission = 'a_';
43
+
44
+	/**
45
+	 * Is available.
46
+	 *
47
+	 * @return bool True/False whether or not this is available to the user
48
+	 */
49
+	public function is_available()
50
+	{
51
+		$has_permission = $this->auth->acl_get($this->permission, true);
52
+
53
+		return !empty($has_permission);
54
+	}
55
+
56
+	/**
57
+	 * Get link id.
58
+	 *
59
+	 * @param array $data The data from the link
60
+	 *
61
+	 * @return int
62
+	 */
63
+	public static function get_item_id($data)
64
+	{
65
+		return (int) $data['link_id'];
66
+	}
67
+
68
+	/**
69
+	 * Get parent id - it's not used.
70
+	 *
71
+	 * @param array $data The data from the link
72
+	 */
73
+	public static function get_item_parent_id($data)
74
+	{
75
+		// No parent
76
+		return 0;
77
+	}
78
+
79
+	/**
80
+	 * Find the users who want to receive notifications.
81
+	 *
82
+	 * @param array $data    Data from submit link
83
+	 * @param array $options Options for finding users for notification
84
+	 *
85
+	 * @return array
86
+	 */
87
+	public function find_users_for_notification($data, $options = [])
88
+	{
89
+		$options = array_merge([
90
+			'ignore_users'        => [],
91
+		], $options);
92
+
93
+		// 0 is for global moderator permissions
94
+		$admin_ary = $this->auth->acl_get_list(false, $this->permission);
95
+		$users = (!empty($admin_ary[0][$this->permission])) ? $admin_ary[0][$this->permission] : [];
96
+
97
+		if (empty($users)) {
98
+			return [];
99
+		}
100
+
101
+		return $this->check_user_notification_options($users, $options);
102
+	}
103
+
104
+	/**
105
+	 * Get the user's avatar.
106
+	 */
107
+	public function get_avatar()
108
+	{
109
+		return $this->user_loader->get_avatar($this->get_data('user_from'), false, true);
110
+	}
111
+
112
+	/**
113
+	 * Get the HTML formatted title of this notification.
114
+	 *
115
+	 * @return string
116
+	 */
117
+	public function get_title()
118
+	{
119
+		$link_name = $this->get_data('link_name');
120
+		$username = $this->user_loader->get_username($this->get_data('user_from'), 'no_profile');
121
+
122
+		return $this->user->lang('NOTIFICATION_DIR_WEBSITE_IN_QUEUE', $link_name, $username);
123
+	}
124
+
125
+	/**
126
+	 * Get email template.
127
+	 *
128
+	 * @return string
129
+	 */
130
+	public function get_email_template()
131
+	{
132
+		return '@ernadoo_phpbbdirectory/directory_website_in_queue';
133
+	}
134
+
135
+	/**
136
+	 * Get email template variables.
137
+	 *
138
+	 * @return array
139
+	 */
140
+	public function get_email_template_variables()
141
+	{
142
+		return [];
143
+	}
144
+
145
+	/**
146
+	 * Get the url to this item.
147
+	 *
148
+	 * @return string URL
149
+	 */
150
+	public function get_url()
151
+	{
152
+		global $phpbb_admin_path;
153
+
154
+		return append_sid("{$phpbb_admin_path}index.{$this->php_ext}", ['i' => '-ernadoo-phpbbdirectory-acp-phpbbdirectory_module', 'mode' => 'val'], true, $this->user->session_id);
155
+	}
156
+
157
+	/**
158
+	 * Users needed to query before this notification can be displayed.
159
+	 *
160
+	 * @return array Array of user_ids
161
+	 */
162
+	public function users_to_query()
163
+	{
164
+		return [$this->get_data('user_from')];
165
+	}
166
+
167
+	/**
168
+	 * Function for preparing the data for insertion in an SQL query
169
+	 * (The service handles insertion).
170
+	 *
171
+	 * @param array $data            Data from submit link
172
+	 * @param array $pre_create_data Data from pre_create_insert_array()
173
+	 *
174
+	 * @return array Array of data ready to be inserted into the database
175
+	 */
176
+	public function create_insert_array($data, $pre_create_data = [])
177
+	{
178
+		$this->set_data('user_from', $data['user_from']);
179
+		$this->set_data('link_name', $data['link_name']);
180
+		$this->set_data('cat_id', $data['cat_id']);
181
+		$this->set_data('cat_name', $data['cat_name']);
182
+
183
+		return parent::create_insert_array($data, $pre_create_data);
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,8 @@
 block discarded – undo
94 94
         $admin_ary = $this->auth->acl_get_list(false, $this->permission);
95 95
         $users = (!empty($admin_ary[0][$this->permission])) ? $admin_ary[0][$this->permission] : [];
96 96
 
97
-        if (empty($users)) {
97
+        if (empty($users))
98
+        {
98 99
             return [];
99 100
         }
100 101
 
Please login to merge, or discard this patch.
notification/type/directory_website_disapproved.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -13,161 +13,161 @@
 block discarded – undo
13 13
  */
14 14
 class directory_website_disapproved extends \phpbb\notification\type\base
15 15
 {
16
-    /**
17
-     * Get notification type name.
18
-     *
19
-     * @return string
20
-     */
21
-    public function get_type()
22
-    {
23
-        return 'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved';
24
-    }
25
-
26
-    /**
27
-     * Notification option data (for outputting to the user).
28
-     *
29
-     * @var bool|array False if the service should use it's default data
30
-     *                 Array of data (including keys 'id', 'lang', and 'group')
31
-     */
32
-    public static $notification_option = [
33
-        'id'       => 'dir_moderation_queue',
34
-        'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_MODERATION_QUEUE',
35
-        'group'    => 'NOTIFICATION_DIR_UCP',
36
-    ];
37
-
38
-    /**
39
-     * Permission to check for (in find_users_for_notification).
40
-     *
41
-     * @var string Permission name
42
-     */
43
-    protected $permission = ['a_', 'm_'];
44
-
45
-    /**
46
-     * Is available.
47
-     *
48
-     * @return bool True/False whether or not this is available to the user
49
-     */
50
-    public function is_available()
51
-    {
52
-        $has_permission = $this->auth->acl_gets($this->permission, true);
53
-
54
-        return empty($has_permission);
55
-    }
56
-
57
-    /**
58
-     * Get link id.
59
-     *
60
-     * @param array $data The data from the link
61
-     *
62
-     * @return int
63
-     */
64
-    public static function get_item_id($data)
65
-    {
66
-        return (int) $data['link_id'];
67
-    }
68
-
69
-    /**
70
-     * Get parent id - it's not used.
71
-     *
72
-     * @param array $data The data from the link
73
-     */
74
-    public static function get_item_parent_id($data)
75
-    {
76
-        // No parent
77
-        return 0;
78
-    }
79
-
80
-    /**
81
-     * Find the users who want to receive notifications.
82
-     *
83
-     * @param array $data    Data from submit link
84
-     * @param array $options Options for finding users for notification
85
-     *
86
-     * @return array
87
-     */
88
-    public function find_users_for_notification($data, $options = [])
89
-    {
90
-        $options = array_merge([
91
-            'ignore_users'        => [],
92
-        ], $options);
93
-
94
-        $users = [$data['user_from']];
95
-
96
-        return $this->check_user_notification_options($users, array_merge($options, [
97
-            'item_type'        => self::$notification_option['id'],
98
-        ]));
99
-    }
100
-
101
-    /**
102
-     * Get the HTML formatted title of this notification.
103
-     *
104
-     * @return string
105
-     */
106
-    public function get_title()
107
-    {
108
-        $link_name = $this->get_data('link_name');
109
-        $cat_name = $this->get_data('cat_name');
110
-
111
-        return $this->user->lang('NOTIFICATION_DIR_WEBSITE_DISAPPROVED', $link_name, $cat_name);
112
-    }
113
-
114
-    /**
115
-     * Get email template.
116
-     *
117
-     * @return string
118
-     */
119
-    public function get_email_template()
120
-    {
121
-        return '@ernadoo_phpbbdirectory/directory_website_disapproved';
122
-    }
123
-
124
-    /**
125
-     * Get email template variables.
126
-     *
127
-     * @return array
128
-     */
129
-    public function get_email_template_variables()
130
-    {
131
-        return [
132
-            'LINK_NAME'    => htmlspecialchars_decode($this->get_data('link_name')),
133
-        ];
134
-    }
135
-
136
-    /**
137
-     * Get the url to this item.
138
-     *
139
-     * @return string URL
140
-     */
141
-    public function get_url()
142
-    {
143
-        return '';
144
-    }
145
-
146
-    /**
147
-     * Users needed to query before this notification can be displayed.
148
-     *
149
-     * @return array Array of user_ids
150
-     */
151
-    public function users_to_query()
152
-    {
153
-        return [];
154
-    }
155
-
156
-    /**
157
-     * Function for preparing the data for insertion in an SQL query
158
-     * (The service handles insertion).
159
-     *
160
-     * @param array $data            Data from submit link
161
-     * @param array $pre_create_data Data from pre_create_insert_array()
162
-     *
163
-     * @return array Array of data ready to be inserted into the database
164
-     */
165
-    public function create_insert_array($data, $pre_create_data = [])
166
-    {
167
-        $this->set_data('link_name', $data['link_name']);
168
-        $this->set_data('cat_id', $data['cat_id']);
169
-        $this->set_data('cat_name', $data['cat_name']);
170
-
171
-        return parent::create_insert_array($data, $pre_create_data);
172
-    }
16
+	/**
17
+	 * Get notification type name.
18
+	 *
19
+	 * @return string
20
+	 */
21
+	public function get_type()
22
+	{
23
+		return 'ernadoo.phpbbdirectory.notification.type.directory_website_disapproved';
24
+	}
25
+
26
+	/**
27
+	 * Notification option data (for outputting to the user).
28
+	 *
29
+	 * @var bool|array False if the service should use it's default data
30
+	 *                 Array of data (including keys 'id', 'lang', and 'group')
31
+	 */
32
+	public static $notification_option = [
33
+		'id'       => 'dir_moderation_queue',
34
+		'lang'     => 'NOTIFICATION_TYPE_DIR_UCP_MODERATION_QUEUE',
35
+		'group'    => 'NOTIFICATION_DIR_UCP',
36
+	];
37
+
38
+	/**
39
+	 * Permission to check for (in find_users_for_notification).
40
+	 *
41
+	 * @var string Permission name
42
+	 */
43
+	protected $permission = ['a_', 'm_'];
44
+
45
+	/**
46
+	 * Is available.
47
+	 *
48
+	 * @return bool True/False whether or not this is available to the user
49
+	 */
50
+	public function is_available()
51
+	{
52
+		$has_permission = $this->auth->acl_gets($this->permission, true);
53
+
54
+		return empty($has_permission);
55
+	}
56
+
57
+	/**
58
+	 * Get link id.
59
+	 *
60
+	 * @param array $data The data from the link
61
+	 *
62
+	 * @return int
63
+	 */
64
+	public static function get_item_id($data)
65
+	{
66
+		return (int) $data['link_id'];
67
+	}
68
+
69
+	/**
70
+	 * Get parent id - it's not used.
71
+	 *
72
+	 * @param array $data The data from the link
73
+	 */
74
+	public static function get_item_parent_id($data)
75
+	{
76
+		// No parent
77
+		return 0;
78
+	}
79
+
80
+	/**
81
+	 * Find the users who want to receive notifications.
82
+	 *
83
+	 * @param array $data    Data from submit link
84
+	 * @param array $options Options for finding users for notification
85
+	 *
86
+	 * @return array
87
+	 */
88
+	public function find_users_for_notification($data, $options = [])
89
+	{
90
+		$options = array_merge([
91
+			'ignore_users'        => [],
92
+		], $options);
93
+
94
+		$users = [$data['user_from']];
95
+
96
+		return $this->check_user_notification_options($users, array_merge($options, [
97
+			'item_type'        => self::$notification_option['id'],
98
+		]));
99
+	}
100
+
101
+	/**
102
+	 * Get the HTML formatted title of this notification.
103
+	 *
104
+	 * @return string
105
+	 */
106
+	public function get_title()
107
+	{
108
+		$link_name = $this->get_data('link_name');
109
+		$cat_name = $this->get_data('cat_name');
110
+
111
+		return $this->user->lang('NOTIFICATION_DIR_WEBSITE_DISAPPROVED', $link_name, $cat_name);
112
+	}
113
+
114
+	/**
115
+	 * Get email template.
116
+	 *
117
+	 * @return string
118
+	 */
119
+	public function get_email_template()
120
+	{
121
+		return '@ernadoo_phpbbdirectory/directory_website_disapproved';
122
+	}
123
+
124
+	/**
125
+	 * Get email template variables.
126
+	 *
127
+	 * @return array
128
+	 */
129
+	public function get_email_template_variables()
130
+	{
131
+		return [
132
+			'LINK_NAME'    => htmlspecialchars_decode($this->get_data('link_name')),
133
+		];
134
+	}
135
+
136
+	/**
137
+	 * Get the url to this item.
138
+	 *
139
+	 * @return string URL
140
+	 */
141
+	public function get_url()
142
+	{
143
+		return '';
144
+	}
145
+
146
+	/**
147
+	 * Users needed to query before this notification can be displayed.
148
+	 *
149
+	 * @return array Array of user_ids
150
+	 */
151
+	public function users_to_query()
152
+	{
153
+		return [];
154
+	}
155
+
156
+	/**
157
+	 * Function for preparing the data for insertion in an SQL query
158
+	 * (The service handles insertion).
159
+	 *
160
+	 * @param array $data            Data from submit link
161
+	 * @param array $pre_create_data Data from pre_create_insert_array()
162
+	 *
163
+	 * @return array Array of data ready to be inserted into the database
164
+	 */
165
+	public function create_insert_array($data, $pre_create_data = [])
166
+	{
167
+		$this->set_data('link_name', $data['link_name']);
168
+		$this->set_data('cat_id', $data['cat_id']);
169
+		$this->set_data('cat_name', $data['cat_name']);
170
+
171
+		return parent::create_insert_array($data, $pre_create_data);
172
+	}
173 173
 }
Please login to merge, or discard this patch.
migrations/v10x/v1_0_0.php 2 patches
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -9,317 +9,317 @@
 block discarded – undo
9 9
 
10 10
 class v1_0_0 extends \phpbb\db\migration\migration
11 11
 {
12
-    public static function depends_on()
13
-    {
14
-        return [
15
-                '\ernadoo\phpbbdirectory\migrations\converter\convert_module',
16
-        ];
17
-    }
18
-
19
-    public function update_schema()
20
-    {
21
-        return [
22
-            'add_tables' => [
23
-                $this->table_prefix.'directory_cats' => [
24
-                    'COLUMNS' => [
25
-                        'cat_id'                   => ['UINT', null, 'auto_increment'],
26
-                        'parent_id'                => ['UINT', 0],
27
-                        'left_id'                  => ['UINT', 0],
28
-                        'right_id'                 => ['UINT', 0],
29
-                        'cat_parents'              => ['MTEXT_UNI', ''],
30
-                        'cat_name'                 => ['VCHAR', ''],
31
-                        'cat_desc'                 => ['TEXT_UNI', ''],
32
-                        'cat_desc_bitfield'        => ['VCHAR', ''],
33
-                        'cat_desc_options'         => ['TIMESTAMP', 7],
34
-                        'cat_desc_uid'             => ['VCHAR:8', ''],
35
-                        'cat_links'                => ['UINT', 0],
36
-                        'cat_icon'                 => ['VCHAR', ''],
37
-                        'display_subcat_list'      => ['BOOL', 1],
38
-                        'cat_allow_comments'       => ['BOOL', 1],
39
-                        'cat_allow_votes'          => ['BOOL', 1],
40
-                        'cat_must_describe'        => ['BOOL', 1],
41
-                        'cat_count_all'            => ['BOOL', 0],
42
-                        'cat_validate'             => ['BOOL', 1],
43
-                        'cat_link_back'            => ['BOOL', 0],
44
-                        'cat_cron_enable'          => ['BOOL', 0],
45
-                        'cat_cron_next'            => ['TIMESTAMP', 0],
46
-                        'cat_cron_freq'            => ['UINT', 7],
47
-                        'cat_cron_nb_check'        => ['UINT', 1],
48
-                    ],
49
-
50
-                    'PRIMARY_KEY'    => ['cat_id'],
51
-
52
-                    'KEYS'        => [
53
-                        'l_r_id' => ['INDEX', ['left_id', 'right_id']],
54
-                    ],
55
-                ],
56
-
57
-                $this->table_prefix.'directory_comments' => [
58
-                    'COLUMNS' => [
59
-                        'comment_id'          => ['UINT', null, 'auto_increment'],
60
-                        'comment_date'        => ['TIMESTAMP', 0],
61
-                        'comment_link_id'     => ['UINT', 0],
62
-                        'comment_user_id'     => ['UINT', 0],
63
-                        'comment_user_ip'     => ['VCHAR:40', ''],
64
-                        'comment_text'        => ['MTEXT_UNI', ''],
65
-                        'comment_uid'         => ['VCHAR:8', 0],
66
-                        'comment_flags'       => ['TIMESTAMP', 0],
67
-                        'comment_bitfield'    => ['VCHAR', ''],
68
-                    ],
69
-
70
-                    'PRIMARY_KEY'    => ['comment_id'],
71
-                ],
72
-
73
-                $this->table_prefix.'directory_links' => [
74
-                    'COLUMNS' => [
75
-                        'link_id'             => ['UINT', null, 'auto_increment'],
76
-                        'link_time'           => ['TIMESTAMP', 0],
77
-                        'link_uid'            => ['VCHAR:8', ''],
78
-                        'link_flags'          => ['TIMESTAMP', 0],
79
-                        'link_bitfield'       => ['VCHAR', ''],
80
-                        'link_url'            => ['VCHAR', ''],
81
-                        'link_description'    => ['MTEXT_UNI', ''],
82
-                        'link_view'           => ['UINT', 0],
83
-                        'link_active'         => ['BOOL', 0],
84
-                        'link_cat'            => ['UINT', 0],
85
-                        'link_user_id'        => ['UINT', 0],
86
-                        'link_name'           => ['XSTEXT_UNI', ''],
87
-                        'link_rss'            => ['VCHAR', ''],
88
-                        'link_banner'         => ['VCHAR', ''],
89
-                        'link_back'           => ['VCHAR', ''],
90
-                        'link_nb_check'       => ['TINT:3', 0],
91
-                        'link_flag'           => ['VCHAR', ''],
92
-                        'link_guest_email'    => ['XSTEXT_UNI', ''],
93
-                        'link_vote'           => ['UINT', 0],
94
-                        'link_comment'        => ['TIMESTAMP', 0],
95
-                        'link_note'           => ['UINT', 0],
96
-                        'link_pagerank'       => ['CHAR:2', ''],
97
-                        'link_thumb'          => ['VCHAR', ''],
98
-                    ],
99
-
100
-                    'PRIMARY_KEY'    => ['link_id'],
101
-
102
-                    'KEYS'        => [
103
-                        'link_id'             => ['UNIQUE', ['link_id']],
104
-                        'link_c_a'            => ['INDEX', ['link_cat', 'link_active']],
105
-                        'link_time'           => ['INDEX', ['link_time']],
106
-                        'link_u_id'           => ['INDEX', ['link_user_id']],
107
-                    ],
108
-                ],
109
-
110
-                $this->table_prefix.'directory_watch' => [
111
-                    'COLUMNS' => [
112
-                        'cat_id'           => ['UINT', 0],
113
-                        'user_id'          => ['UINT', 0],
114
-                        'notify_status'    => ['UINT', 0],
115
-                    ],
116
-
117
-                    'KEYS'        => [
118
-                        'c_id'        => ['INDEX', ['cat_id']],
119
-                        'u_id'        => ['INDEX', ['user_id']],
120
-                        'n_stat'      => ['INDEX', ['notify_status']],
121
-                    ],
122
-
123
-                ],
124
-
125
-                $this->table_prefix.'directory_votes' => [
126
-                    'COLUMNS' => [
127
-                        'vote_id'              => ['UINT', null, 'auto_increment'],
128
-                        'vote_link_id'         => ['UINT', 0],
129
-                        'vote_user_id'         => ['UINT', 0],
130
-                        'vote_note'            => ['TINT:2', 0],
131
-                    ],
132
-
133
-                    'PRIMARY_KEY'    => ['vote_id'],
134
-
135
-                    'KEYS'        => [
136
-                        'v_l_id'    => ['INDEX', ['vote_link_id']],
137
-                        'v_u_id'    => ['INDEX', ['vote_user_id']],
138
-                    ],
139
-                ],
140
-            ],
141
-        ];
142
-    }
143
-
144
-    public function revert_schema()
145
-    {
146
-        return [
147
-            'drop_tables'    => [
148
-                $this->table_prefix.'directory_cats',
149
-                $this->table_prefix.'directory_comments',
150
-                $this->table_prefix.'directory_links',
151
-                $this->table_prefix.'directory_votes',
152
-                $this->table_prefix.'directory_watch',
153
-            ],
154
-        ];
155
-    }
156
-
157
-    public function update_data()
158
-    {
159
-        return [
160
-            ['config.add', ['dir_mail', '1']],
161
-            ['config.add', ['dir_activ_flag', '1']],
162
-            ['config.add', ['dir_show', '10']],
163
-            ['config.add', ['dir_default_order', 't d']],
164
-            ['config.add', ['dir_allow_bbcode', '1']],
165
-            ['config.add', ['dir_allow_flash', '1']],
166
-            ['config.add', ['dir_allow_links', '1']],
167
-            ['config.add', ['dir_allow_smilies', '1']],
168
-            ['config.add', ['dir_length_describe', '255']],
169
-            ['config.add', ['dir_activ_banner', '1']],
170
-            ['config.add', ['dir_banner_height', '60']],
171
-            ['config.add', ['dir_banner_width', '480']],
172
-            ['config.add', ['dir_activ_checkurl', '1']],
173
-            ['config.add', ['dir_activ_pagerank', '1']],
174
-            ['config.add', ['dir_activ_thumb', '1']],
175
-            ['config.add', ['dir_activ_thumb_remote', '1']],
176
-            ['config.add', ['dir_visual_confirm', '1']],
177
-            ['config.add', ['dir_visual_confirm_max_attempts', '3']],
178
-            ['config.add', ['dir_length_comments', '256']],
179
-            ['config.add', ['dir_new_time', '7']],
180
-            ['config.add', ['dir_comments_per_page', '10']],
181
-            ['config.add', ['dir_storage_banner', '1']],
182
-            ['config.add', ['dir_banner_filesize', '30000']],
183
-            ['config.add', ['dir_thumb_service', 'http://www.apercite.fr/apercite/120x90/oui/oui/']],
184
-            ['config.add', ['dir_thumb_service_reverse', '0']],
185
-            ['config.add', ['dir_activ_rss', '1']],
186
-            ['config.add', ['dir_recent_block', '1']],
187
-            ['config.add', ['dir_recent_exclude', '1']],
188
-            ['config.add', ['dir_recent_rows', '1']],
189
-            ['config.add', ['dir_recent_columns', '5']],
190
-            ['config.add', ['dir_root_path', './']],
191
-            ['config.add', ['dir_activ_rewrite', '0']],
192
-
193
-            ['module.add', [
194
-                'acp',
195
-                'ACP_CAT_DOT_MODS',
196
-                'ACP_DIRECTORY',
197
-            ]],
198
-
199
-            ['module.add', [
200
-                'acp',
201
-                'ACP_DIRECTORY',
202
-                [
203
-                    'module_basename'      => '\ernadoo\phpbbdirectory\acp\phpbbdirectory_module',
204
-                    'modes'                => ['main', 'settings', 'cat', 'val'],
205
-                ],
206
-            ]],
207
-
208
-            ['permission.add', ['u_comment_dir']],
209
-            ['permission.add', ['u_search_dir']],
210
-            ['permission.add', ['u_submit_dir']],
211
-            ['permission.add', ['u_vote_dir']],
212
-            ['permission.add', ['u_edit_comment_dir']],
213
-            ['permission.add', ['u_delete_comment_dir']],
214
-            ['permission.add', ['u_edit_dir']],
215
-            ['permission.add', ['u_delete_dir']],
216
-            ['permission.add', ['m_edit_dir']],
217
-            ['permission.add', ['m_delete_dir']],
218
-            ['permission.add', ['m_edit_comment_dir']],
219
-            ['permission.add', ['m_delete_comment_dir']],
220
-
221
-            ['permission.permission_set',
222
-                ['ROLE_USER_FULL',
223
-                    [
224
-                        'u_comment_dir',
225
-                        'u_search_dir',
226
-                        'u_submit_dir',
227
-                        'u_vote_dir',
228
-                        'u_edit_comment_dir',
229
-                        'u_delete_comment_dir',
230
-                        'u_edit_dir',
231
-                        'u_delete_dir',
232
-                    ],
233
-                ],
234
-            ],
235
-
236
-            ['permission.permission_set',
237
-                ['ROLE_MOD_FULL',
238
-                    [
239
-                        'm_edit_dir',
240
-                        'm_delete_dir',
241
-                        'm_edit_comment_dir',
242
-                        'm_delete_comment_dir',
243
-                    ],
244
-                ],
245
-            ],
246
-
247
-            ['custom', [[&$this, 'create_directories']]],
248
-        ];
249
-    }
250
-
251
-    public function revert_data()
252
-    {
253
-        return [
254
-            ['custom', [[&$this, 'remove_directories']]],
255
-        ];
256
-    }
257
-
258
-    /**
259
-     * Create directories for banners/icons uploaded.
260
-     *
261
-     * @return null
262
-     */
263
-    public function create_directories()
264
-    {
265
-        $directories = [
266
-            'files/ext/ernadoo/phpbbdirectory/banners/',
267
-            'files/ext/ernadoo/phpbbdirectory/icons/',
268
-        ];
269
-
270
-        foreach ($directories as $dir) {
271
-            if (!file_exists($this->phpbb_root_path.$dir)) {
272
-                @mkdir($this->phpbb_root_path.$dir, 0777, true);
273
-                phpbb_chmod($this->phpbb_root_path.$dir, CHMOD_READ | CHMOD_WRITE);
274
-            }
275
-        }
276
-    }
277
-
278
-    /**
279
-     * Remove directories for banners/icons uploaded.
280
-     *
281
-     * @return null
282
-     */
283
-    public function remove_directories()
284
-    {
285
-        $dir = $this->phpbb_root_path.'files/ext/ernadoo/phpbbdirectory/';
286
-
287
-        $this->_recursive_rmdir($dir);
288
-    }
289
-
290
-    /**
291
-     * Attempts to remove recursively the directory named by dirname.
292
-     *
293
-     * @author Mehdi Kabab <http://pioupioum.fr>
294
-     * @copyright Copyright (C) 2009 Mehdi Kabab
295
-     * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
296
-     *
297
-     * @param string $dirname Path to the directory.
298
-     *
299
-     * @return null
300
-     */
301
-    private function _recursive_rmdir($dirname)
302
-    {
303
-        if (is_dir($dirname) && !is_link($dirname)) {
304
-            $iterator = new \RecursiveIteratorIterator(
305
-                new \RecursiveDirectoryIterator($dirname),
306
-                \RecursiveIteratorIterator::CHILD_FIRST
307
-            );
308
-
309
-            while ($iterator->valid()) {
310
-                if (!$iterator->isDot()) {
311
-                    if ($iterator->isFile()) {
312
-                        unlink($iterator->getPathName());
313
-                    } elseif ($iterator->isDir()) {
314
-                        rmdir($iterator->getPathName());
315
-                    }
316
-                }
317
-
318
-                $iterator->next();
319
-            }
320
-            unset($iterator); // Fix for Windows.
321
-
322
-            rmdir($dirname);
323
-        }
324
-    }
12
+	public static function depends_on()
13
+	{
14
+		return [
15
+				'\ernadoo\phpbbdirectory\migrations\converter\convert_module',
16
+		];
17
+	}
18
+
19
+	public function update_schema()
20
+	{
21
+		return [
22
+			'add_tables' => [
23
+				$this->table_prefix.'directory_cats' => [
24
+					'COLUMNS' => [
25
+						'cat_id'                   => ['UINT', null, 'auto_increment'],
26
+						'parent_id'                => ['UINT', 0],
27
+						'left_id'                  => ['UINT', 0],
28
+						'right_id'                 => ['UINT', 0],
29
+						'cat_parents'              => ['MTEXT_UNI', ''],
30
+						'cat_name'                 => ['VCHAR', ''],
31
+						'cat_desc'                 => ['TEXT_UNI', ''],
32
+						'cat_desc_bitfield'        => ['VCHAR', ''],
33
+						'cat_desc_options'         => ['TIMESTAMP', 7],
34
+						'cat_desc_uid'             => ['VCHAR:8', ''],
35
+						'cat_links'                => ['UINT', 0],
36
+						'cat_icon'                 => ['VCHAR', ''],
37
+						'display_subcat_list'      => ['BOOL', 1],
38
+						'cat_allow_comments'       => ['BOOL', 1],
39
+						'cat_allow_votes'          => ['BOOL', 1],
40
+						'cat_must_describe'        => ['BOOL', 1],
41
+						'cat_count_all'            => ['BOOL', 0],
42
+						'cat_validate'             => ['BOOL', 1],
43
+						'cat_link_back'            => ['BOOL', 0],
44
+						'cat_cron_enable'          => ['BOOL', 0],
45
+						'cat_cron_next'            => ['TIMESTAMP', 0],
46
+						'cat_cron_freq'            => ['UINT', 7],
47
+						'cat_cron_nb_check'        => ['UINT', 1],
48
+					],
49
+
50
+					'PRIMARY_KEY'    => ['cat_id'],
51
+
52
+					'KEYS'        => [
53
+						'l_r_id' => ['INDEX', ['left_id', 'right_id']],
54
+					],
55
+				],
56
+
57
+				$this->table_prefix.'directory_comments' => [
58
+					'COLUMNS' => [
59
+						'comment_id'          => ['UINT', null, 'auto_increment'],
60
+						'comment_date'        => ['TIMESTAMP', 0],
61
+						'comment_link_id'     => ['UINT', 0],
62
+						'comment_user_id'     => ['UINT', 0],
63
+						'comment_user_ip'     => ['VCHAR:40', ''],
64
+						'comment_text'        => ['MTEXT_UNI', ''],
65
+						'comment_uid'         => ['VCHAR:8', 0],
66
+						'comment_flags'       => ['TIMESTAMP', 0],
67
+						'comment_bitfield'    => ['VCHAR', ''],
68
+					],
69
+
70
+					'PRIMARY_KEY'    => ['comment_id'],
71
+				],
72
+
73
+				$this->table_prefix.'directory_links' => [
74
+					'COLUMNS' => [
75
+						'link_id'             => ['UINT', null, 'auto_increment'],
76
+						'link_time'           => ['TIMESTAMP', 0],
77
+						'link_uid'            => ['VCHAR:8', ''],
78
+						'link_flags'          => ['TIMESTAMP', 0],
79
+						'link_bitfield'       => ['VCHAR', ''],
80
+						'link_url'            => ['VCHAR', ''],
81
+						'link_description'    => ['MTEXT_UNI', ''],
82
+						'link_view'           => ['UINT', 0],
83
+						'link_active'         => ['BOOL', 0],
84
+						'link_cat'            => ['UINT', 0],
85
+						'link_user_id'        => ['UINT', 0],
86
+						'link_name'           => ['XSTEXT_UNI', ''],
87
+						'link_rss'            => ['VCHAR', ''],
88
+						'link_banner'         => ['VCHAR', ''],
89
+						'link_back'           => ['VCHAR', ''],
90
+						'link_nb_check'       => ['TINT:3', 0],
91
+						'link_flag'           => ['VCHAR', ''],
92
+						'link_guest_email'    => ['XSTEXT_UNI', ''],
93
+						'link_vote'           => ['UINT', 0],
94
+						'link_comment'        => ['TIMESTAMP', 0],
95
+						'link_note'           => ['UINT', 0],
96
+						'link_pagerank'       => ['CHAR:2', ''],
97
+						'link_thumb'          => ['VCHAR', ''],
98
+					],
99
+
100
+					'PRIMARY_KEY'    => ['link_id'],
101
+
102
+					'KEYS'        => [
103
+						'link_id'             => ['UNIQUE', ['link_id']],
104
+						'link_c_a'            => ['INDEX', ['link_cat', 'link_active']],
105
+						'link_time'           => ['INDEX', ['link_time']],
106
+						'link_u_id'           => ['INDEX', ['link_user_id']],
107
+					],
108
+				],
109
+
110
+				$this->table_prefix.'directory_watch' => [
111
+					'COLUMNS' => [
112
+						'cat_id'           => ['UINT', 0],
113
+						'user_id'          => ['UINT', 0],
114
+						'notify_status'    => ['UINT', 0],
115
+					],
116
+
117
+					'KEYS'        => [
118
+						'c_id'        => ['INDEX', ['cat_id']],
119
+						'u_id'        => ['INDEX', ['user_id']],
120
+						'n_stat'      => ['INDEX', ['notify_status']],
121
+					],
122
+
123
+				],
124
+
125
+				$this->table_prefix.'directory_votes' => [
126
+					'COLUMNS' => [
127
+						'vote_id'              => ['UINT', null, 'auto_increment'],
128
+						'vote_link_id'         => ['UINT', 0],
129
+						'vote_user_id'         => ['UINT', 0],
130
+						'vote_note'            => ['TINT:2', 0],
131
+					],
132
+
133
+					'PRIMARY_KEY'    => ['vote_id'],
134
+
135
+					'KEYS'        => [
136
+						'v_l_id'    => ['INDEX', ['vote_link_id']],
137
+						'v_u_id'    => ['INDEX', ['vote_user_id']],
138
+					],
139
+				],
140
+			],
141
+		];
142
+	}
143
+
144
+	public function revert_schema()
145
+	{
146
+		return [
147
+			'drop_tables'    => [
148
+				$this->table_prefix.'directory_cats',
149
+				$this->table_prefix.'directory_comments',
150
+				$this->table_prefix.'directory_links',
151
+				$this->table_prefix.'directory_votes',
152
+				$this->table_prefix.'directory_watch',
153
+			],
154
+		];
155
+	}
156
+
157
+	public function update_data()
158
+	{
159
+		return [
160
+			['config.add', ['dir_mail', '1']],
161
+			['config.add', ['dir_activ_flag', '1']],
162
+			['config.add', ['dir_show', '10']],
163
+			['config.add', ['dir_default_order', 't d']],
164
+			['config.add', ['dir_allow_bbcode', '1']],
165
+			['config.add', ['dir_allow_flash', '1']],
166
+			['config.add', ['dir_allow_links', '1']],
167
+			['config.add', ['dir_allow_smilies', '1']],
168
+			['config.add', ['dir_length_describe', '255']],
169
+			['config.add', ['dir_activ_banner', '1']],
170
+			['config.add', ['dir_banner_height', '60']],
171
+			['config.add', ['dir_banner_width', '480']],
172
+			['config.add', ['dir_activ_checkurl', '1']],
173
+			['config.add', ['dir_activ_pagerank', '1']],
174
+			['config.add', ['dir_activ_thumb', '1']],
175
+			['config.add', ['dir_activ_thumb_remote', '1']],
176
+			['config.add', ['dir_visual_confirm', '1']],
177
+			['config.add', ['dir_visual_confirm_max_attempts', '3']],
178
+			['config.add', ['dir_length_comments', '256']],
179
+			['config.add', ['dir_new_time', '7']],
180
+			['config.add', ['dir_comments_per_page', '10']],
181
+			['config.add', ['dir_storage_banner', '1']],
182
+			['config.add', ['dir_banner_filesize', '30000']],
183
+			['config.add', ['dir_thumb_service', 'http://www.apercite.fr/apercite/120x90/oui/oui/']],
184
+			['config.add', ['dir_thumb_service_reverse', '0']],
185
+			['config.add', ['dir_activ_rss', '1']],
186
+			['config.add', ['dir_recent_block', '1']],
187
+			['config.add', ['dir_recent_exclude', '1']],
188
+			['config.add', ['dir_recent_rows', '1']],
189
+			['config.add', ['dir_recent_columns', '5']],
190
+			['config.add', ['dir_root_path', './']],
191
+			['config.add', ['dir_activ_rewrite', '0']],
192
+
193
+			['module.add', [
194
+				'acp',
195
+				'ACP_CAT_DOT_MODS',
196
+				'ACP_DIRECTORY',
197
+			]],
198
+
199
+			['module.add', [
200
+				'acp',
201
+				'ACP_DIRECTORY',
202
+				[
203
+					'module_basename'      => '\ernadoo\phpbbdirectory\acp\phpbbdirectory_module',
204
+					'modes'                => ['main', 'settings', 'cat', 'val'],
205
+				],
206
+			]],
207
+
208
+			['permission.add', ['u_comment_dir']],
209
+			['permission.add', ['u_search_dir']],
210
+			['permission.add', ['u_submit_dir']],
211
+			['permission.add', ['u_vote_dir']],
212
+			['permission.add', ['u_edit_comment_dir']],
213
+			['permission.add', ['u_delete_comment_dir']],
214
+			['permission.add', ['u_edit_dir']],
215
+			['permission.add', ['u_delete_dir']],
216
+			['permission.add', ['m_edit_dir']],
217
+			['permission.add', ['m_delete_dir']],
218
+			['permission.add', ['m_edit_comment_dir']],
219
+			['permission.add', ['m_delete_comment_dir']],
220
+
221
+			['permission.permission_set',
222
+				['ROLE_USER_FULL',
223
+					[
224
+						'u_comment_dir',
225
+						'u_search_dir',
226
+						'u_submit_dir',
227
+						'u_vote_dir',
228
+						'u_edit_comment_dir',
229
+						'u_delete_comment_dir',
230
+						'u_edit_dir',
231
+						'u_delete_dir',
232
+					],
233
+				],
234
+			],
235
+
236
+			['permission.permission_set',
237
+				['ROLE_MOD_FULL',
238
+					[
239
+						'm_edit_dir',
240
+						'm_delete_dir',
241
+						'm_edit_comment_dir',
242
+						'm_delete_comment_dir',
243
+					],
244
+				],
245
+			],
246
+
247
+			['custom', [[&$this, 'create_directories']]],
248
+		];
249
+	}
250
+
251
+	public function revert_data()
252
+	{
253
+		return [
254
+			['custom', [[&$this, 'remove_directories']]],
255
+		];
256
+	}
257
+
258
+	/**
259
+	 * Create directories for banners/icons uploaded.
260
+	 *
261
+	 * @return null
262
+	 */
263
+	public function create_directories()
264
+	{
265
+		$directories = [
266
+			'files/ext/ernadoo/phpbbdirectory/banners/',
267
+			'files/ext/ernadoo/phpbbdirectory/icons/',
268
+		];
269
+
270
+		foreach ($directories as $dir) {
271
+			if (!file_exists($this->phpbb_root_path.$dir)) {
272
+				@mkdir($this->phpbb_root_path.$dir, 0777, true);
273
+				phpbb_chmod($this->phpbb_root_path.$dir, CHMOD_READ | CHMOD_WRITE);
274
+			}
275
+		}
276
+	}
277
+
278
+	/**
279
+	 * Remove directories for banners/icons uploaded.
280
+	 *
281
+	 * @return null
282
+	 */
283
+	public function remove_directories()
284
+	{
285
+		$dir = $this->phpbb_root_path.'files/ext/ernadoo/phpbbdirectory/';
286
+
287
+		$this->_recursive_rmdir($dir);
288
+	}
289
+
290
+	/**
291
+	 * Attempts to remove recursively the directory named by dirname.
292
+	 *
293
+	 * @author Mehdi Kabab <http://pioupioum.fr>
294
+	 * @copyright Copyright (C) 2009 Mehdi Kabab
295
+	 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
296
+	 *
297
+	 * @param string $dirname Path to the directory.
298
+	 *
299
+	 * @return null
300
+	 */
301
+	private function _recursive_rmdir($dirname)
302
+	{
303
+		if (is_dir($dirname) && !is_link($dirname)) {
304
+			$iterator = new \RecursiveIteratorIterator(
305
+				new \RecursiveDirectoryIterator($dirname),
306
+				\RecursiveIteratorIterator::CHILD_FIRST
307
+			);
308
+
309
+			while ($iterator->valid()) {
310
+				if (!$iterator->isDot()) {
311
+					if ($iterator->isFile()) {
312
+						unlink($iterator->getPathName());
313
+					} elseif ($iterator->isDir()) {
314
+						rmdir($iterator->getPathName());
315
+					}
316
+				}
317
+
318
+				$iterator->next();
319
+			}
320
+			unset($iterator); // Fix for Windows.
321
+
322
+			rmdir($dirname);
323
+		}
324
+	}
325 325
 }
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -267,8 +267,10 @@  discard block
 block discarded – undo
267 267
             'files/ext/ernadoo/phpbbdirectory/icons/',
268 268
         ];
269 269
 
270
-        foreach ($directories as $dir) {
271
-            if (!file_exists($this->phpbb_root_path.$dir)) {
270
+        foreach ($directories as $dir)
271
+        {
272
+            if (!file_exists($this->phpbb_root_path.$dir))
273
+            {
272 274
                 @mkdir($this->phpbb_root_path.$dir, 0777, true);
273 275
                 phpbb_chmod($this->phpbb_root_path.$dir, CHMOD_READ | CHMOD_WRITE);
274 276
             }
@@ -300,17 +302,23 @@  discard block
 block discarded – undo
300 302
      */
301 303
     private function _recursive_rmdir($dirname)
302 304
     {
303
-        if (is_dir($dirname) && !is_link($dirname)) {
305
+        if (is_dir($dirname) && !is_link($dirname))
306
+        {
304 307
             $iterator = new \RecursiveIteratorIterator(
305 308
                 new \RecursiveDirectoryIterator($dirname),
306 309
                 \RecursiveIteratorIterator::CHILD_FIRST
307 310
             );
308 311
 
309
-            while ($iterator->valid()) {
310
-                if (!$iterator->isDot()) {
311
-                    if ($iterator->isFile()) {
312
+            while ($iterator->valid())
313
+            {
314
+                if (!$iterator->isDot())
315
+                {
316
+                    if ($iterator->isFile())
317
+                    {
312 318
                         unlink($iterator->getPathName());
313
-                    } elseif ($iterator->isDir()) {
319
+                    }
320
+                    elseif ($iterator->isDir())
321
+                    {
314 322
                         rmdir($iterator->getPathName());
315 323
                     }
316 324
                 }
Please login to merge, or discard this patch.
migrations/converter/convert_notifications.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,56 +12,56 @@
 block discarded – undo
12 12
  */
13 13
 class convert_notifications extends \phpbb\db\migration\migration
14 14
 {
15
-    /**
16
-     * Skip this migration if phpbb_directory_notifications table does not exist.
17
-     *
18
-     * @return bool True if table does not exist
19
-     */
20
-    public function effectively_installed()
21
-    {
22
-        return !$this->db_tools->sql_table_exists($this->table_prefix.'directory_notifications');
23
-    }
15
+	/**
16
+	 * Skip this migration if phpbb_directory_notifications table does not exist.
17
+	 *
18
+	 * @return bool True if table does not exist
19
+	 */
20
+	public function effectively_installed()
21
+	{
22
+		return !$this->db_tools->sql_table_exists($this->table_prefix.'directory_notifications');
23
+	}
24 24
 
25
-    public static function depends_on()
26
-    {
27
-        return [
28
-            '\ernadoo\phpbbdirectory\migrations\v10x\v1_0_0',
29
-        ];
30
-    }
25
+	public static function depends_on()
26
+	{
27
+		return [
28
+			'\ernadoo\phpbbdirectory\migrations\v10x\v1_0_0',
29
+		];
30
+	}
31 31
 
32
-    /**
33
-     * Add or update data in the database.
34
-     *
35
-     * @return array Array of table data
36
-     */
37
-    public function update_data()
38
-    {
39
-        return [
40
-            ['custom', [[&$this, 'copy_from_notifications']]],
41
-        ];
42
-    }
32
+	/**
33
+	 * Add or update data in the database.
34
+	 *
35
+	 * @return array Array of table data
36
+	 */
37
+	public function update_data()
38
+	{
39
+		return [
40
+			['custom', [[&$this, 'copy_from_notifications']]],
41
+		];
42
+	}
43 43
 
44
-    /**
45
-     * Copy category track from 3.0.x table.
46
-     *
47
-     * @return null
48
-     */
49
-    public function copy_from_notifications()
50
-    {
51
-        $sql = 'SELECT n_user_id, n_cat_id
44
+	/**
45
+	 * Copy category track from 3.0.x table.
46
+	 *
47
+	 * @return null
48
+	 */
49
+	public function copy_from_notifications()
50
+	{
51
+		$sql = 'SELECT n_user_id, n_cat_id
52 52
 			FROM '.$this->table_prefix.'directory_notifications';
53
-        $result = $this->db->sql_query($sql);
53
+		$result = $this->db->sql_query($sql);
54 54
 
55
-        while ($row = $this->db->sql_fetchrow($result)) {
56
-            $data = [
57
-                'cat_id'           => (int) $row['n_cat_id'],
58
-                'user_id'          => (int) $row['n_user_id'],
59
-                'notify_status'    => 1,
60
-            ];
55
+		while ($row = $this->db->sql_fetchrow($result)) {
56
+			$data = [
57
+				'cat_id'           => (int) $row['n_cat_id'],
58
+				'user_id'          => (int) $row['n_user_id'],
59
+				'notify_status'    => 1,
60
+			];
61 61
 
62
-            $sql = 'INSERT INTO '.$this->table_prefix.'directory_watch '.$this->db->sql_build_array('INSERT', $data);
63
-            $this->db->sql_query($sql);
64
-        }
65
-        $this->db->sql_freeresult($result);
66
-    }
62
+			$sql = 'INSERT INTO '.$this->table_prefix.'directory_watch '.$this->db->sql_build_array('INSERT', $data);
63
+			$this->db->sql_query($sql);
64
+		}
65
+		$this->db->sql_freeresult($result);
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,8 @@
 block discarded – undo
52 52
 			FROM '.$this->table_prefix.'directory_notifications';
53 53
         $result = $this->db->sql_query($sql);
54 54
 
55
-        while ($row = $this->db->sql_fetchrow($result)) {
55
+        while ($row = $this->db->sql_fetchrow($result))
56
+        {
56 57
             $data = [
57 58
                 'cat_id'           => (int) $row['n_cat_id'],
58 59
                 'user_id'          => (int) $row['n_user_id'],
Please login to merge, or discard this patch.