Completed
Pull Request — patch_1-1-4 (#3188)
by Spuds
09:56
created

MessageTopicIcons::_loadIcons()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * General class for setting the message icon array and returning index values
5
 *
6
 * @name      ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
9
 *
10
 * @version 1.1.4
11
 *
12
 */
13
14
/**
15
 * Class MessageTopicIcons
16
 */
17
class MessageTopicIcons extends ElkArte\ValuesContainer
18
{
19
	const IMAGE_URL = 'images_url';
20
	const DEFAULT_URL = 'default_images_url';
21
22
	/**
23
	 * Whether to check if the icon exists in the expected location
24
	 * @var bool
25
	 */
26
	protected $_check = false;
27
28
	/**
29
	 * Theme directory path
30
	 * @var string
31
	 */
32
	protected $_theme_dir = '';
33
34
	/**
35
	 * Default icon code
36
	 * @var string
37
	 */
38
	protected $_default_icon = 'xx';
39
40
	/**
41
	 * Icons that are default with ElkArte
42
	 * @var array
43
	 */
44
	protected $_stable_icons = 	array();
45
46
	/**
47
	 * Icons to load in addition to the default
48
	 * @var array
49
	 */
50
	protected $_custom_icons = array();
51
52
	/**
53
	 * This simple function returns the message topic icon array.
54
	 *
55
	 * @param bool|false $icon_check
56
	 * @param string $theme_dir
57
	 * @param array topic icons to load in addition to default
58
	 * @param string $default
59
	 */
60 1
	public function __construct($icon_check = false, $theme_dir = '', $custom = array(), $default = 'xx')
61
	{
62 1
		parent::__construct();
63
64
		// Load passed parameters to the class properties
65 1
		$this->_check = $icon_check;
66 1
		$this->_theme_dir = $theme_dir;
67 1
		$this->_default_icon = $default;
68 1
		$this->_custom_icons = $custom;
69
70
		// Set default icons
71 1
		$this->_loadStableIcons();
72
73
		// Merge in additional ones
74 1
		$this->_stable_icons = array_merge($this->_stable_icons, array_column($custom, 'first_icon'));
75
76 1
		$this->_loadIcons();
77 1
	}
78
79
	/**
80
	 * Return the icon specified by idx, or the default icon for invalid names
81
	 *
82
	 * @param int|string $idx
83
	 * @return string
84
	 */
85 1
	public function __get($idx)
86
	{
87
		// Not a standard topic icon
88 1
		if (!isset($this->data[$idx]))
89 1
		{
90
			$this->_setUrl($idx);
91
		}
92
93 1
		return $this->data[$idx];
94
	}
95
96
	/**
97
	 * Load the stable icon array
98
	 */
99 1
	protected function _loadStableIcons()
100
	{
101
		// Setup the default topic icons...
102 1
		$this->_stable_icons = array(
103 1
			'xx',
104 1
			'thumbup',
105 1
			'thumbdown',
106 1
			'exclamation',
107 1
			'question',
108 1
			'lamp',
109 1
			'smiley',
110 1
			'angry',
111 1
			'cheesy',
112 1
			'grin',
113 1
			'sad',
114 1
			'wink',
115 1
			'poll',
116 1
			'moved',
117 1
			'recycled',
118 1
			'wireless',
119
			'clip'
120 1
		);
121 1
	}
122
123
	/**
124
	 * This simple function returns the message topic icon array.
125
	 */
126 1
	protected function _loadIcons()
127
	{
128
		// Allow addons to add to the message icon array
129 1
		call_integration_hook('integrate_messageindex_icons', array(&$this->_stable_icons));
130
131 1
		$this->data = array();
132 1
		foreach ($this->_stable_icons as $icon)
133
		{
134 1
			$this->_setUrl($icon);
135 1
		}
136 1
	}
137
138
	/**
139
	 * Set the icon URL location
140
	 *
141
	 * @param string $icon
142
	 */
143 1
	protected function _setUrl($icon)
144
	{
145 1
		global $settings;
146
147 1
		if ($this->_check)
148 1
		{
149
			$this->data[$icon] = $settings[file_exists($this->_theme_dir . '/images/post/' . $icon . '.png')
150
				 ? self::IMAGE_URL
151
				 : self::DEFAULT_URL] . '/post/' . $icon . '.png';
152
		}
153
		else
154
		{
155 1
			$this->data[$icon] = $settings[self::IMAGE_URL] . '/post/' . $icon . '.png';
156
		}
157
	}
158
}