Completed
Pull Request — master (#13)
by Erwan
02:10
created

qte::qte_group_select()   F

Complexity

Conditions 12
Paths 1152

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
rs 2.8641
cc 12
eloc 16
nc 1152
nop 3

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 *
4
 * @package Quick Title Edition Extension
5
 * @copyright (c) 2015 ABDev
6
 * @copyright (c) 2015 PastisD
7
 * @copyright (c) 2015 Geolim4 <http://geolim4.com>
8
 * @copyright (c) 2015 Zoddo <[email protected]>
9
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
10
 *
11
 */
12
13
namespace ernadoo\qte;
14
15
class qte
16
{
17
	const KEEP = -2;
18
	const REMOVE = -1;
19
20
	/** @var \phpbb\request\request */
21
	protected $request;
22
23
	/** @var \phpbb\cache\driver\driver_interface */
24
	protected $cache;
25
26
	/** @var \phpbb\db\driver\driver_interface */
27
	protected $db;
28
29
	/** @var \phpbb\template\template */
30
	protected $template;
31
32
	/** @var \phpbb\user */
33
	protected $user;
34
35
	/** @var \phpbb\log\log */
36
	protected $log;
37
38
	/** @var \phpbb\auth\auth */
39
	protected $auth;
40
41
	/** @var string */
42
	protected $root_path;
43
44
	/** @var string */
45
	protected $php_ext;
46
47
	/** @var string */
48
	protected $table_prefix;
49
50
	/** @var array */
51
	private $_attr;
52
53
	/** @var array */
54
	private $_name = array();
55
56
	/**
57
	* Constructor
58
	*
59
	* @param \phpbb\request\request					$request			Request object
60
	* @param \phpbb\cache\driver\driver_interface	$cache				Cache object
61
	* @param \phpbb\db\driver\driver_interface 		$db					Database object
62
	* @param \phpbb\template\template				$template			Template object
63
	* @param \phpbb\user							$user				User object
64
	* @param \phpbb\log\log							$log				Log object
65
	* @param \phpbb\auth\auth						$auth				Auth object
66
	* @param string									$root_path			phpBB root path
67
	* @param string									$php_ext   			phpEx
68
	* @param string									$table_prefix   	Prefix tables
69
	*/
70
	public function __construct(\phpbb\request\request $request, \phpbb\cache\driver\driver_interface $cache, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\log\log $log, \phpbb\auth\auth $auth, $root_path, $php_ext, $table_prefix)
71
	{
72
		$this->request		= $request;
73
		$this->cache		= $cache;
74
		$this->db			= $db;
75
		$this->template		= $template;
76
		$this->user			= $user;
77
		$this->log			= $log;
78
		$this->auth			= $auth;
79
80
		$this->root_path	= $root_path;
81
		$this->php_ext		= $php_ext;
82
		$this->table_prefix = $table_prefix;
83
84
		$this->_get_attributes();
85
		$this->user->add_lang_ext('ernadoo/qte', 'attributes');
86
	}
87
88
	/**
89
	* Get topic attributes username
90
	*
91
	* @param	array	$topic_list	Topic ids
92
	*
93
	* @return	null
94
	*/
95
	public function get_users_by_topic_id($topic_list)
96
	{
97
		if (!empty($topic_list))
98
		{
99
			$sql = 'SELECT u.user_id, u.username, u.user_colour
100
				FROM ' . USERS_TABLE . ' u
101
				LEFT JOIN ' . TOPICS_TABLE . ' t ON (u.user_id = t.topic_attr_user)
102
				WHERE ' . $this->db->sql_in_set('t.topic_id', array_map('intval', $topic_list)) . '
103
					AND t.topic_attr_user <> ' . ANONYMOUS;
104
			$result = $this->db->sql_query($sql);
105
106
			while ($row = $this->db->sql_fetchrow($result))
107
			{
108
				$this->_name[$row['user_id']] = array(
109
					'user_id'		=> (int) $row['user_id'],
110
					'username'		=> $row['username'],
111
					'user_colour'	=> $row['user_colour'],
112
				);
113
			}
114
			$this->db->sql_freeresult();
115
		}
116
	}
117
118
	/**
119
	* Get attribute name
120
	*
121
	* @param	int		$attr_id	The attribute id
122
	*
123
	* @return	string
124
	*/
125
	public function get_attr_name_by_id($attr_id)
126
	{
127
		return $this->_attr[$attr_id]['attr_name'];
128
	}
129
130
	/**
131
	* Get attribute author
132
	*
133
	* @param	int		$user_id	User id
134
	*
135
	* @return	string
136
	*/
137
	public function get_users_by_user_id($user_id)
138
	{
139
		if (!isset($this->_name[$user_id]))
140
		{
141
			$sql = 'SELECT user_id, username, user_colour
142
				FROM ' . USERS_TABLE . '
143
				WHERE user_id = ' . (int) $user_id;
144
			$result = $this->db->sql_query($sql);
145
146
			while ($row = $this->db->sql_fetchrow($result))
147
			{
148
				$this->_name[$row['user_id']] = array(
149
					'user_id'		=> (int) $row['user_id'],
150
					'username'		=> $row['username'],
151
					'user_colour'	=> $row['user_colour'],
152
				);
153
			}
154
			$this->db->sql_freeresult();
155
		}
156
	}
157
158
	/**
159
	* Generate a list of attributes based on permissions
160
	*
161
	* @param	int		$forum_id		Forum id
162
	* @param	int		$author_id		Topic author id
163
	* @param	int		$attribute_id	Current attribute id
164
	* @param	string	$viewtopic_url	Topic's url
165
	*
166
	* @return	null
167
	*/
168
	public function attr_select($forum_id, $author_id = 0, $attribute_id = 0, $viewtopic_url = '')
169
	{
170
		$show_select	= false;
171
		$current_time	= time();
172
		$can_edit		= $this->auth->acl_get('m_qte_attr_edit', $forum_id);
173
		$can_remove		= $this->auth->acl_get('m_qte_attr_del', $forum_id);
174
		$is_author		= $this->user->data['is_registered'] && $this->user->data['user_id'] == $author_id;
175
176
		// Basic auth
177
		if (!$can_remove && !$can_edit && !$is_author)
178
		{
179
			return;
180
		}
181
182
		foreach ($this->_attr as $attr)
183
		{
184
			if (!$this->auth->acl_get('f_qte_attr_'.$attr['attr_id'], $forum_id))
185
			{
186
				continue;
187
			}
188
189
			// show the selector !
190
			$show_select = true;
191
192
			// parse the attribute name
193
			$attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->data['username'], $this->user->format_date($current_time, $attr['attr_date'])), $this->user->lang($attr['attr_name']));
194
195
			$this->template->assign_block_vars('attributes', array(
196
				'QTE_ID'		=> $attr['attr_id'],
197
				'QTE_NAME'		=> $attribute_name,
198
				'QTE_DESC'		=> $this->user->lang($attr['attr_desc']),
199
				'QTE_COLOUR'	=> $this->attr_colour($attr['attr_name'], $attr['attr_colour']),
200
201
				'IS_SELECTED'	=> (!empty($attribute_id) && ($attr['attr_id'] == $attribute_id)),
202
203
				'S_QTE_DESC'	=> !empty($attr['attr_desc']) ? true : false,
204
				'U_QTE_URL'		=> !empty($viewtopic_url) ? append_sid($viewtopic_url, array('attr_id' => $attr['attr_id'])) : false,
205
			));
206
		}
207
208
		$this->template->assign_vars(array(
209
			'S_QTE_SELECT'		=> ($show_select || $can_remove && ($attribute_id || !$author_id)),
210
			'S_QTE_REMOVE'		=> $can_remove,
211
			'S_QTE_EMPTY'		=> (empty($attribute_id)),
212
			'S_QTE_SELECTED'	=> ($can_remove && ($attribute_id == self::REMOVE)),
213
			'S_QTE_KEEP'		=> !empty($attribute_id) && ($attribute_id == self::KEEP),
214
215
			'U_QTE_URL'			=> !empty($viewtopic_url) ? append_sid($viewtopic_url, array('attr_id' => self::REMOVE)) : false,
216
		));
217
	}
218
219
	/**
220
	* Generate a list of all attributes for search page
221
	*
222
	* @return	null
223
	*/
224
	public function attr_search()
225
	{
226
		foreach ($this->_attr as $attr)
227
		{
228
			// parse the attribute name
229
			$attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->lang['QTE_KEY_USERNAME'], $this->user->lang['QTE_KEY_DATE']), $this->user->lang($attr['attr_name']));
230
231
			$this->template->assign_block_vars('attributes', array(
232
				'QTE_ID'		=> $attr['attr_id'],
233
				'QTE_NAME'		=> $attribute_name,
234
				'QTE_DESC'		=> $this->user->lang($attr['attr_desc']),
235
				'QTE_COLOUR'	=> $this->attr_colour($attr['attr_name'], $attr['attr_colour']),
236
237
				'S_QTE_DESC'	=> !empty($attr['attr_desc']) ? true : false,
238
			));
239
		}
240
	}
241
242
	/**
243
	* Generate a list of attributes for viewforum page
244
	*
245
	* @param	int		$forum_id		Forum id
246
	* @param	int		$attribute_id	Current attribute id
247
	*
248
	* @return	null
249
	*/
250 View Code Duplication
	public function attr_sort($forum_id = 0, $attribute_id = 0)
251
	{
252
		foreach ($this->_attr as $attr)
253
		{
254
			$forum_allowed = $this->auth->acl_getf('f_qte_attr_'.$attr['attr_id'], true);
255
256
			if (isset($forum_allowed[$forum_id]))
257
			{
258
				// parse the attribute name
259
				$attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->lang['QTE_KEY_USERNAME'], $this->user->lang['QTE_KEY_DATE']), $this->user->lang($attr['attr_name']));
260
261
				$this->template->assign_block_vars('attributes', array(
262
					'QTE_ID'		=> $attr['attr_id'],
263
					'QTE_NAME'		=> $attribute_name,
264
					'QTE_DESC'		=> $this->user->lang($attr['attr_desc']),
265
					'QTE_COLOUR'	=> $this->attr_colour($attr['attr_name'], $attr['attr_colour']),
266
267
					'IS_SELECTED'	=> (!empty($attribute_id) && ($attr['attr_id'] == $attribute_id)) ? true : false,
268
269
					'S_QTE_DESC'	=> !empty($attr['attr_desc']) ? true : false,
270
				));
271
			}
272
		}
273
	}
274
275
	/**
276
	* Generate a default attribute list for a forum
277
	*
278
	* @param	int		$forum_id		Forum id
279
	* @param	int		$attribute_id	Current attribute id
280
	*
281
	* @return	null
282
	*/
283 View Code Duplication
	public function attr_default($forum_id = 0, $attribute_id = 0)
284
	{
285
		foreach ($this->_attr as $attr)
286
		{
287
			$forum_allowed = $this->auth->acl_getf('f_qte_attr_'.$attr['attr_id'], true);
288
289
			if (isset($forum_allowed[$forum_id]))
290
			{
291
				// parse the attribute name
292
				$attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->lang['QTE_KEY_USERNAME'], $this->user->lang['QTE_KEY_DATE']), $this->user->lang($attr['attr_name']));
293
294
				$this->template->assign_block_vars('attributes', array(
295
					'QTE_ID'		=> $attr['attr_id'],
296
					'QTE_NAME'		=> $attribute_name,
297
					'QTE_DESC'		=> $this->user->lang($attr['attr_desc']),
298
					'QTE_COLOUR'	=> $this->attr_colour($attr['attr_name'], $attr['attr_colour']),
299
300
					'IS_SELECTED'	=> (!empty($attribute_id) && ($attr['attr_id'] == $attribute_id)),
301
302
					'S_QTE_DESC'	=> !empty($attr['attr_desc']) ? true : false,
303
				));
304
			}
305
		}
306
	}
307
308
	/**
309
	* Generate attribute for topic title
310
	*
311
	* @param	int		$attribute_id	Current attribute id
312
	* @param	int		$user_id		Current attribute user id
313
	* @param	int		$timestamp		Attribute timestamp
314
	*
315
	* @return	string					Attribute html code
316
	*/
317
	public function attr_display($attribute_id = 0, $user_id = 0, $timestamp = 0)
318
	{
319
		if (empty($attribute_id) || empty($user_id) || empty($timestamp))
320
		{
321
			return false;
322
		}
323
324
		if (isset($this->_attr[$attribute_id]))
325
		{
326
			$attribute_colour = $this->attr_colour($this->_attr[$attribute_id]['attr_name'], $this->_attr[$attribute_id]['attr_colour']);
327
328
			if (isset($this->_name[$user_id]['user_id']))
329
			{
330
				$attribute_username = get_username_string(($this->_attr[$attribute_id]['attr_user_colour'] ? 'no_profile' : 'username'), $this->_name[$user_id]['user_id'], $this->_name[$user_id]['username'], $this->_name[$user_id]['user_colour']);
331
			}
332
			else
333
			{
334
				$attribute_username = $this->user->lang['GUEST'];
335
			}
336
337
			$attribute_date = $this->user->format_date($timestamp, $this->_attr[$attribute_id]['attr_date']);
338
339
			$attribute_name = str_replace(array('%mod%', '%date%'), array($attribute_username, $attribute_date), $this->user->lang($this->_attr[$attribute_id]['attr_name']));
340
341
			return !$this->_attr[$attribute_id]['attr_type'] ? '<span' . $attribute_colour . '>' . $attribute_name . '</span>' : $this->attr_img_key($this->_attr[$attribute_id]['attr_img'], $attribute_name);
342
		}
343
	}
344
345
	/**
346
	* Generate attribute for page title
347
	*
348
	* @param	int		$attribute_id	Current attribute id
349
	* @param	int		$user_id		Current attribute user id
350
	* @param	int		$timestamp		Attribute timestamp
351
	*
352
	* @return	string					attribute html code
353
	*/
354
	public function attr_title($attribute_id = 0, $user_id = 0, $timestamp = 0)
355
	{
356
		if (empty($attribute_id) || empty($user_id) || empty($timestamp))
357
		{
358
			return false;
359
		}
360
361
		if (isset($this->_attr[$attribute_id]))
362
		{
363
			if (isset($this->_name[$user_id]['user_id']))
364
			{
365
				$attribute_username = get_username_string('username', $this->_name[$user_id]['user_id'], $this->_name[$user_id]['username'], $this->_name[$user_id]['user_colour']);
366
			}
367
			else
368
			{
369
				$attribute_username = $this->user->lang['GUEST'];
370
			}
371
372
			$attribute_date = $this->user->format_date($timestamp, $this->_attr[$attribute_id]['attr_date']);
373
374
			return str_replace(array('%mod%', '%date%'), array($attribute_username, $attribute_date), $this->user->lang($this->_attr[$attribute_id]['attr_name']));
375
		}
376
	}
377
378
379
	/**
380
	* Change topic attribute
381
	*
382
	* @param	int		$attribute_id		New attribute id
383
	* @param	int		$topic_id			The id of the topic
384
	* @param	int		$forum_id			The id of the forum
385
	* @param	int		$topic_attribute	Current attribute id
386
	* @param	int		$author_id			Topic author id
387
	* @param	string	$viewtopic_url		URL to the topic page
388
	*
389
	* @return	null
390
	*/
391
	public function attr_apply($attribute_id = 0, $topic_id = 0, $forum_id = 0, $topic_attribute = 0, $author_id = 0, $viewtopic_url = '')
392
	{
393
		if (empty($topic_id) || empty($forum_id) || empty($attribute_id))
394
		{
395
			return;
396
		}
397
398
		$can_edit		= $this->auth->acl_get('m_qte_attr_edit', $forum_id) || $this->auth->acl_get('f_qte_attr_'.$attribute_id, $forum_id) && $this->user->data['is_registered'] && $this->user->data['user_id'] == $author_id;
399
		$can_remove		= $this->auth->acl_get('m_qte_attr_del', $forum_id);
400
401 View Code Duplication
		if (!$can_edit && $attribute_id != self::REMOVE || !$can_remove && $attribute_id == self::REMOVE)
402
		{
403
			return;
404
		}
405
406
		// Default values
407
		$fields = array('topic_attr_id' => 0, 'topic_attr_user'	=> 0, 'topic_attr_time'	=> 0);
408
409
		// time !
410
		$current_time = time();
411
412 View Code Duplication
		if ($attribute_id != self::REMOVE)
413
		{
414
			$fields = array(
415
				'topic_attr_id'		=> $attribute_id,
416
				'topic_attr_user'	=> $this->user->data['user_id'],
417
				'topic_attr_time'	=> $current_time,
418
			);
419
		}
420
421
		$sql = 'UPDATE ' . TOPICS_TABLE . '
422
			SET ' . $this->db->sql_build_array('UPDATE', $fields) . '
423
			WHERE topic_id = ' . (int) $topic_id;
424
		$this->db->sql_query($sql);
425
426
		$sql = 'SELECT topic_id
427
			FROM ' . TOPICS_TABLE . '
428
			WHERE topic_moved_id = ' . (int) $topic_id;
429
		$result = $this->db->sql_query($sql);
430
		$shadow_topic_id = (int) $this->db->sql_fetchfield('topic_id');
431
		$this->db->sql_freeresult($result);
432
433
		if (!empty($shadow_topic_id))
434
		{
435
			$sql = 'UPDATE ' . TOPICS_TABLE . '
436
				SET ' . $this->db->sql_build_array('UPDATE', $fields) . '
437
				WHERE topic_id = ' . $shadow_topic_id;
438
			$this->db->sql_query($sql);
439
		}
440
441
		meta_refresh(2, $viewtopic_url);
442
443
		$message = $this->user->lang['QTE_ATTRIBUTE_' . ($attribute_id == -1 ? 'REMOVED' : (empty($topic_attribute) ? 'ADDED' : 'UPDATED'))];
444
445
		if ($this->request->is_ajax())
446
		{
447
			$json_response = new \phpbb\json_response;
448
			$json_response->send(array(
449
				'success' => true,
450
451
				'MESSAGE_TITLE'	=> $this->user->lang['INFORMATION'],
452
				'MESSAGE_TEXT'	=> $message,
453
				'NEW_ATTRIBUTE'	=> $this->attr_display($attribute_id, $this->user->data['user_id'], $current_time),
454
			));
455
		}
456
457
		$message .= '<br /><br />' . $this->user->lang('RETURN_PAGE', '<a href="' . $viewtopic_url . '">', '</a>');
458
459
		trigger_error($message);
460
	}
461
462
	/**
463
	* Change topic attribute in mcp
464
	*
465
	* @param	int		$attribute_id		New attribute id
466
	* @param	int		$forum_id			The id of the forum
467
	* @param	array	$topic_ids			Topics ids
468
	*
469
	* @return	null
470
	*/
471
	public function mcp_attr_apply($attribute_id = 0, $forum_id = 0, $topic_ids = array())
472
	{
473
		$can_edit		= $this->auth->acl_get('m_qte_attr_edit', $forum_id);
474
		$can_remove		= $this->auth->acl_get('m_qte_attr_del', $forum_id);
475
476 View Code Duplication
		if (!$can_edit && $attribute_id != self::REMOVE || !$can_remove && $attribute_id == self::REMOVE)
477
		{
478
			return;
479
		}
480
481
		if (!sizeof($topic_ids))
482
		{
483
			trigger_error('NO_TOPIC_SELECTED');
484
		}
485
486
		if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id'))
487
		{
488
			return;
489
		}
490
491
		// Default values
492
		$fields = array('topic_attr_id' => 0, 'topic_attr_user'	=> 0, 'topic_attr_time'	=> 0);
493
494
		// time !
495
		$current_time = time();
496
497 View Code Duplication
		if ($attribute_id != self::REMOVE)
498
		{
499
			$fields = array(
500
				'topic_attr_id'		=> $attribute_id,
501
				'topic_attr_user'	=> $this->user->data['user_id'],
502
				'topic_attr_time'	=> $current_time,
503
			);
504
		}
505
506
		$sql = 'SELECT topic_id, forum_id, topic_title, topic_attr_id
507
			FROM ' . TOPICS_TABLE . '
508
			WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $topic_ids));
509
		$result = $this->db->sql_query($sql);
510
511
		// log this action
512
		while ($row = $this->db->sql_fetchrow($result))
513
		{
514
			$message = ($attribute_id == -1) ? 'REMOVED' : (empty($row['topic_attr_id']) ? 'ADDED' : 'UPDATED');
515
			$additional_data = array(
516
				'forum_id'	=> $row['forum_id'],
517
				'topic_id'	=> $row['topic_id'],
518
				$row['topic_title'],
519
			);
520
			$this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'MCP_ATTRIBUTE_' . $message, $current_time, $additional_data);
521
		}
522
		$this->db->sql_freeresult($result);
523
524
		$sql = 'UPDATE ' . TOPICS_TABLE . '
525
			SET ' . $this->db->sql_build_array('UPDATE', $fields) . '
526
			WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $topic_ids));
527
		$this->db->sql_query($sql);
528
529
		$sql = 'SELECT topic_id
530
			FROM ' . TOPICS_TABLE . '
531
			WHERE ' . $this->db->sql_in_set('topic_moved_id', array_map('intval', $topic_ids));
532
		$result = $this->db->sql_query($sql);
533
534
		$shadow_topic_ids = array();
535
		while ($row = $this->db->sql_fetchrow($result))
536
		{
537
			$shadow_topic_ids[] = (int) $row['topic_id'];
538
		}
539
		$this->db->sql_freeresult($result);
540
541
		if (sizeof($shadow_topic_ids))
542
		{
543
			$sql = 'UPDATE ' . TOPICS_TABLE . '
544
				SET ' . $this->db->sql_build_array('UPDATE', $fields) . '
545
				WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $shadow_topic_ids));
546
			$this->db->sql_query($sql);
547
		}
548
549
		$redirect = $this->request->variable('redirect', $this->user->data['session_page']);
550
551
		meta_refresh(3, $redirect);
552
		trigger_error($this->user->lang['QTE_TOPIC' . (sizeof($topic_ids) == 1 ? '' : 'S') . '_ATTRIBUTE_' . (isset($message) ? $message : 'ADDED')] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
553
	}
554
555
	/**
556
	* Getter...
557
	*
558
	* @return	array
559
	*/
560
	public function getAttr()
561
	{
562
		return $this->_attr;
563
	}
564
565
	// borrowed from "Categories Hierarchy" : used to check if a image key exists
566
	public function attr_img_key($key, $alt)
567
	{
568
		return empty($key) ? '' : (preg_match('#^[a-z0-9_-]+$#i', $key) ? $this->user->img($key, $alt) : '<img src="' . (preg_match('#^(ht|f)tp[s]?\://#i', $key) ? $key : $this->root_path . $key) . '" alt="' . $alt . '" title="' . $alt . '" />');
569
	}
570
571
	/**
572
	* Build class and style attribute
573
	*
574
	* @param	string	$a_name			Attribute name
575
	* @param	string	$a_colour		Attribute color
576
	* @return	string					html code
577
	*/
578
	public function attr_colour($a_name, $a_colour)
579
	{
580
		if ($a_name != $this->user->lang($a_name))
581
		{
582
			$a_class_name = preg_replace('#[^a-z0-9 _-]#', '', strtolower($a_name));
583
		}
584
585
		return ' class="qte-attr ' . (isset($a_class_name) ?  $a_class_name : '') . '"' . (!empty($a_colour) ? ' style="color:#' . $a_colour . '; font-weight:bold;"' : '');
586
	}
587
588
	/**
589
	* Get attributes from database
590
	*
591
	* @return	null
592
	*/
593
	private function _get_attributes()
594
	{
595
		if (($this->_attr = $this->cache->get('_attr')) === false)
596
		{
597
			$sql = 'SELECT *
598
				FROM ' . $this->table_prefix . 'topics_attr
599
				ORDER BY left_id ASC';
600
			$result = $this->db->sql_query($sql);
601
602
			$this->_attr = array();
603
			while ($row = $this->db->sql_fetchrow($result))
604
			{
605
				$this->_attr[$row['attr_id']] = array(
606
					'attr_id'			=> (int) $row['attr_id'],
607
					'attr_type'			=> (bool) $row['attr_type'],
608
					'attr_name'			=> $row['attr_name'],
609
					'attr_desc'			=> $row['attr_desc'],
610
					'attr_img'			=> $row['attr_img'],
611
					'attr_colour'		=> $row['attr_colour'],
612
					'attr_date'			=> $row['attr_date'],
613
					'attr_user_colour'	=> (bool) $row['attr_user_colour'],
614
				);
615
			}
616
			$this->db->sql_freeresult();
617
618
			$this->cache->put('_attr', $this->_attr);
619
		}
620
	}
621
}
622