Passed
Branch development (176841)
by Elk
07:58
created

Load.php ➔ loadAssetFile()   F

Complexity

Conditions 29
Paths 1761

Size

Total Lines 102

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 73.3496

Importance

Changes 0
Metric Value
cc 29
nc 1761
nop 3
dl 0
loc 102
rs 0
c 0
b 0
f 0
ccs 30
cts 48
cp 0.625
crap 73.3496

How to fix   Long Method    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
 * This file has the hefty job of loading information for the forum.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * This file contains code covered by:
11
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
12
 *
13
 * @version 2.0 dev
14
 *
15
 */
16
17
use ElkArte\User;
18
19
/**
20
 * Load the $modSettings array and many necessary forum settings.
21
 *
22
 * What it does:
23
 *
24
 * - load the settings from cache if available, otherwise from the database.
25
 * - sets the timezone
26
 * - checks the load average settings if available.
27
 * - check whether post moderation is enabled.
28
 * - calls add_integration_function
29
 * - calls integrate_pre_include, integrate_pre_load,
30
 *
31
 * @event integrate_load_average is called if load average is enabled
32
 * @event integrate_pre_include to allow including files at startup
33
 * @event integrate_pre_load to call any pre load integration functions.
34
 *
35
 * @global array $modSettings is a giant array of all of the forum-wide settings and statistics.
36
 */
37
function reloadSettings()
38
{
39 1
	global $modSettings;
40
41 1
	$db = database();
42 1
	$cache = \ElkArte\Cache\Cache::instance();
43 1
	$hooks = \ElkArte\Hooks::instance();
44
45
	// Try to load it from the cache first; it'll never get cached if the setting is off.
46 1
	if (!$cache->getVar($modSettings, 'modSettings', 90))
47
	{
48 1
		$request = $db->query('', '
49
			SELECT variable, value
50
			FROM {db_prefix}settings',
51
			array(
52 1
			)
53
		);
54 1
		$modSettings = array();
55 1
		if (!$request)
56
			\ElkArte\Errors\Errors::instance()->display_db_error();
57 1
		while ($row = $request->fetch_row())
0 ignored issues
show
Bug introduced by
The method fetch_row cannot be called on $request (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
58 1
			$modSettings[$row[0]] = $row[1];
59 1
		$request->free_result();
0 ignored issues
show
Bug introduced by
The method free_result cannot be called on $request (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
60
61
		// Do a few things to protect against missing settings or settings with invalid values...
62 1
		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
63
			$modSettings['defaultMaxTopics'] = 20;
64 1
		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
65
			$modSettings['defaultMaxMessages'] = 15;
66 1
		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
67
			$modSettings['defaultMaxMembers'] = 30;
68 1
		if (empty($modSettings['subject_length']))
69 1
			$modSettings['subject_length'] = 24;
70
71 1
		$modSettings['warning_enable'] = $modSettings['warning_settings'][0];
72
73 1
		$cache->put('modSettings', $modSettings, 90);
74
	}
75
76 1
	$hooks->loadIntegrations();
77
78
	// Setting the timezone is a requirement for some functions in PHP >= 5.1.
79 1
	if (isset($modSettings['default_timezone']))
80 1
		date_default_timezone_set($modSettings['default_timezone']);
81
82
	// Check the load averages?
83 1
	if (!empty($modSettings['loadavg_enable']))
84
	{
85
		if (!$cache->getVar($modSettings['load_average'], 'loadavg', 90))
86
		{
87
			require_once(SUBSDIR . '/Server.subs.php');
88
			$modSettings['load_average'] = detectServerLoad();
89
90
			$cache->put('loadavg', $modSettings['load_average'], 90);
91
		}
92
93
		if ($modSettings['load_average'] !== false)
94
			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
95
96
		// Let's have at least a zero
97
		if (empty($modSettings['loadavg_forum']) || $modSettings['load_average'] === false)
98
			$modSettings['current_load'] = 0;
99
		else
100
			$modSettings['current_load'] = $modSettings['load_average'];
101
102
		if (!empty($modSettings['loadavg_forum']) && $modSettings['current_load'] >= $modSettings['loadavg_forum'])
103
			\ElkArte\Errors\Errors::instance()->display_loadavg_error();
104
	}
105
	else
106 1
		$modSettings['current_load'] = 0;
107
108
	// Is post moderation alive and well?
109 1
	$modSettings['postmod_active'] = isset($modSettings['admin_features']) ? in_array('pm', explode(',', $modSettings['admin_features'])) : true;
110
111 1
	if (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off')
112
	{
113 1
		$modSettings['secureCookies'] = 0;
114
	}
115
116
	// Here to justify the name of this function. :P
117
	// It should be added to the install and upgrade scripts.
118
	// But since the converters need to be updated also. This is easier.
119 1
	if (empty($modSettings['currentAttachmentUploadDir']))
120
	{
121
		updateSettings(array(
122
			'attachmentUploadDir' => serialize(array(1 => $modSettings['attachmentUploadDir'])),
123
			'currentAttachmentUploadDir' => 1,
124
		));
125
	}
126
127
	// Integration is cool.
128 1
	if (defined('ELK_INTEGRATION_SETTINGS'))
129
	{
130
		$integration_settings = \ElkArte\Util::unserialize(ELK_INTEGRATION_SETTINGS);
131
		foreach ($integration_settings as $hook => $function)
132
			add_integration_function($hook, $function);
133
	}
134
135
	// Any files to pre include?
136 1
	call_integration_include_hook('integrate_pre_include');
137
138
	// Call pre load integration functions.
139 1
	call_integration_hook('integrate_pre_load');
140 1
}
141
142
/**
143
 * Load all the important user information.
144
 *
145
 * What it does:
146
 *
147
 * - sets up the $user_info array
148
 * - assigns $user_info['query_wanna_see_board'] for what boards the user can see.
149
 * - first checks for cookie or integration validation.
150
 * - uses the current session if no integration function or cookie is found.
151
 * - checks password length, if member is activated and the login span isn't over.
152
 * - if validation fails for the user, $id_member is set to 0.
153
 * - updates the last visit time when needed.
154
 *
155
 * @event integrate_verify_user allow for integration to verify a user
156
 * @event integrate_user_info to allow for adding to $user_info array
157
 * @deprecated kept until any trace of $user_info has been completely removed
158
 */
159
function loadUserSettings()
160
{
161 1
	\ElkArte\User::load(true);
162 1
}
163
164
/**
165
 * Check for moderators and see if they have access to the board.
166
 *
167
 * What it does:
168
 *
169
 * - sets up the $board_info array for current board information.
170
 * - if cache is enabled, the $board_info array is stored in cache.
171
 * - redirects to appropriate post if only message id is requested.
172
 * - is only used when inside a topic or board.
173
 * - determines the local moderators for the board.
174
 * - adds group id 3 if the user is a local moderator for the board they are in.
175
 * - prevents access if user is not in proper group nor a local moderator of the board.
176
 *
177
 * @event integrate_load_board_query allows to add tables and columns to the query, used
178
 * to add to the $board_info array
179
 * @event integrate_loaded_board called after board_info is populated, allows to add
180
 * directly to $board_info
181
 *
182
 */
183
function loadBoard()
184
{
185 3
	global $txt, $scripturl, $context, $modSettings;
186 3
	global $board_info, $board, $topic;
187
188 3
	$db = database();
189 3
	$cache = \ElkArte\Cache\Cache::instance();
190
191
	// Assume they are not a moderator.
192 3
	User::$info->is_mod = false;
0 ignored issues
show
Documentation introduced by
The property is_mod does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
193
	// @since 1.0.5 - is_mod takes into account only local (board) moderators,
194
	// and not global moderators, is_moderator is meant to take into account both.
195 3
	User::$info->is_moderator = false;
0 ignored issues
show
Documentation introduced by
The property is_moderator does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
196
197
	// Start the linktree off empty..
198 3
	$context['linktree'] = array();
199
200
	// Have they by chance specified a message id but nothing else?
201 3
	if (empty($_REQUEST['action']) && empty($topic) && empty($board) && !empty($_REQUEST['msg']))
202
	{
203
		// Make sure the message id is really an int.
204
		$_REQUEST['msg'] = (int) $_REQUEST['msg'];
205
206
		// Looking through the message table can be slow, so try using the cache first.
207
		if (!$cache->getVar($topic, 'msg_topic-' . $_REQUEST['msg'], 120))
208
		{
209
			require_once(SUBSDIR . '/Messages.subs.php');
210
			$topic = associatedTopic($_REQUEST['msg']);
211
212
			// So did it find anything?
213
			if ($topic !== false)
214
			{
215
				// Save save save.
216
				$cache->put('msg_topic-' . $_REQUEST['msg'], $topic, 120);
217
			}
218
		}
219
220
		// Remember redirection is the key to avoiding fallout from your bosses.
221
		if (!empty($topic))
222
			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
223
		else
224
		{
225
			loadPermissions();
226
			new ElkArte\Themes\ThemeLoader();
227
			throw new \ElkArte\Exceptions\Exception('topic_gone', false);
228
		}
229
	}
230
231
	// Load this board only if it is specified.
232 3
	if (empty($board) && empty($topic))
233
	{
234 1
		$board_info = array('moderators' => array());
235 1
		return;
236
	}
237
238 2
	if ($cache->isEnabled() && (empty($topic) || $cache->levelHigherThan(2)))
239
	{
240
		// @todo SLOW?
241
		if (!empty($topic))
242
			$temp = $cache->get('topic_board-' . $topic, 120);
243
		else
244
			$temp = $cache->get('board-' . $board, 120);
245
246
		if (!empty($temp))
247
		{
248
			$board_info = $temp;
249
			$board = (int) $board_info['id'];
250
		}
251
	}
252
253 2
	if (empty($temp))
254
	{
255 2
		$select_columns = array();
256 2
		$select_tables = array();
257
		// Wanna grab something more from the boards table or another table at all?
258 2
		call_integration_hook('integrate_load_board_query', array(&$select_columns, &$select_tables));
259
260 2
		$request = $db->query('', '
261
			SELECT
262
				c.id_cat, b.name AS bname, b.description, b.num_topics, b.member_groups, b.deny_member_groups,
263
				b.id_parent, c.name AS cname, COALESCE(mem.id_member, 0) AS id_moderator,
264 2
				mem.real_name' . (!empty($topic) ? ', b.id_board' : '') . ', b.child_level,
265
				b.id_theme, b.override_theme, b.count_posts, b.id_profile, b.redirect,
266 2
				b.unapproved_topics, b.unapproved_posts' . (!empty($topic) ? ', t.approved, t.id_member_started' : '') . (!empty($select_columns) ? ', ' . implode(', ', $select_columns) : '') . '
267 2
			FROM {db_prefix}boards AS b' . (!empty($topic) ? '
268 2
				INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})' : '') . (!empty($select_tables) ? '
269 2
				' . implode("\n\t\t\t\t", $select_tables) : '') . '
270
				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
271
				LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = {raw:board_link})
272
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
273
			WHERE b.id_board = {raw:board_link}',
274
			array(
275 2
				'current_topic' => $topic,
276 2
				'board_link' => empty($topic) ? $db->quote('{int:current_board}', array('current_board' => $board)) : 't.id_board',
277
			)
278
		);
279
		// If there aren't any, skip.
280 2
		if ($db->num_rows($request) > 0)
281
		{
282 2
			$row = $db->fetch_assoc($request);
283
284
			// Set the current board.
285 2
			if (!empty($row['id_board']))
286
				$board = (int) $row['id_board'];
287
288
			// Basic operating information. (globals... :/)
289
			$board_info = array(
290 2
				'id' => $board,
291
				'moderators' => array(),
292
				'cat' => array(
293 2
					'id' => $row['id_cat'],
294 2
					'name' => $row['cname']
295
				),
296 2
				'name' => $row['bname'],
297 2
				'raw_description' => $row['description'],
298 2
				'description' => $row['description'],
299 2
				'num_topics' => $row['num_topics'],
300 2
				'unapproved_topics' => $row['unapproved_topics'],
301 2
				'unapproved_posts' => $row['unapproved_posts'],
302 2
				'unapproved_user_topics' => 0,
303 2
				'parent_boards' => getBoardParents($row['id_parent']),
304 2
				'parent' => $row['id_parent'],
305 2
				'child_level' => $row['child_level'],
306 2
				'theme' => $row['id_theme'],
307 2
				'override_theme' => !empty($row['override_theme']),
308 2
				'profile' => $row['id_profile'],
309 2
				'redirect' => $row['redirect'],
310 2
				'posts_count' => empty($row['count_posts']),
311 2
				'cur_topic_approved' => empty($topic) || $row['approved'],
312 2
				'cur_topic_starter' => empty($topic) ? 0 : $row['id_member_started'],
313
			);
314
315
			// Load the membergroups allowed, and check permissions.
316 2
			$board_info['groups'] = $row['member_groups'] == '' ? array() : explode(',', $row['member_groups']);
317 2
			$board_info['deny_groups'] = $row['deny_member_groups'] == '' ? array() : explode(',', $row['deny_member_groups']);
318
319 2
			call_integration_hook('integrate_loaded_board', array(&$board_info, &$row));
320
321
			do
322
			{
323 2
				if (!empty($row['id_moderator']))
324
					$board_info['moderators'][$row['id_moderator']] = array(
325
						'id' => $row['id_moderator'],
326
						'name' => $row['real_name'],
327
						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
328
						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
329
					);
330
			}
331 2
			while ($row = $db->fetch_assoc($request));
332
333
			// If the board only contains unapproved posts and the user can't approve then they can't see any topics.
334
			// If that is the case do an additional check to see if they have any topics waiting to be approved.
335 2
			if ($board_info['num_topics'] == 0 && $modSettings['postmod_active'] && !allowedTo('approve_posts'))
336
			{
337
				// Free the previous result
338
				$db->free_result($request);
339
340
				// @todo why is this using id_topic?
341
				// @todo Can this get cached?
342
				$request = $db->query('', '
343
					SELECT COUNT(id_topic)
344
					FROM {db_prefix}topics
345
					WHERE id_member_started={int:id_member}
346
						AND approved = {int:unapproved}
347
						AND id_board = {int:board}',
348
					array(
349
						'id_member' => User::$info->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
350
						'unapproved' => 0,
351
						'board' => $board,
352
					)
353
				);
354
355
				list ($board_info['unapproved_user_topics']) = $db->fetch_row($request);
356
			}
357
358 2
			if ($cache->isEnabled() && (empty($topic) || $cache->levelHigherThan(2)))
359
			{
360
				// @todo SLOW?
361
				if (!empty($topic))
362
					$cache->put('topic_board-' . $topic, $board_info, 120);
363 2
				$cache->put('board-' . $board, $board_info, 120);
364
			}
365
		}
366
		else
367
		{
368
			// Otherwise the topic is invalid, there are no moderators, etc.
369
			$board_info = array(
370
				'moderators' => array(),
371
				'error' => 'exist'
372
			);
373
			$topic = null;
374
			$board = 0;
375
		}
376 2
		$db->free_result($request);
377
	}
378
379 2
	if (!empty($topic))
380
		$_GET['board'] = (int) $board;
381
382 2
	if (!empty($board))
383
	{
384
		// Now check if the user is a moderator.
385 2
		User::$info->is_mod = isset($board_info['moderators'][User::$info->id]);
0 ignored issues
show
Documentation introduced by
The property is_mod does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property id does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
386
387 2
		if (count(array_intersect(User::$info->groups, $board_info['groups'])) == 0 && User::$info->is_admin === false)
0 ignored issues
show
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property is_admin does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
388
		{
389
			$board_info['error'] = 'access';
390
		}
391 2
		if (!empty($modSettings['deny_boards_access']) && count(array_intersect(User::$info->groups, $board_info['deny_groups'])) != 0 && User::$info->is_admin === false)
0 ignored issues
show
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property is_admin does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
392
		{
393
			$board_info['error'] = 'access';
394
		}
395
396
		// Build up the linktree.
397 2
		$context['linktree'] = array_merge(
398 2
			$context['linktree'],
399
			array(array(
400 2
				'url' => getUrl('action', $modSettings['default_forum_action']) . '#c' . $board_info['cat']['id'],
401 2
				'name' => $board_info['cat']['name']
402
			)),
403 2
			array_reverse($board_info['parent_boards']),
404
			array(array(
405 2
				'url' => $scripturl . '?board=' . $board . '.0',
406 2
				'name' => $board_info['name']
407
			))
408
		);
409
	}
410
411
	// Set the template contextual information.
412 2
	$context['user']['is_mod'] = User::$info->is_mod;
0 ignored issues
show
Documentation introduced by
The property is_mod does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
413 2
	$context['user']['is_moderator'] = User::$info->is_moderator;
0 ignored issues
show
Documentation introduced by
The property is_moderator does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
414 2
	$context['current_topic'] = $topic;
415 2
	$context['current_board'] = $board;
416
417
	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
418 2
	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || User::$info->is_moderator === false))
0 ignored issues
show
Documentation introduced by
The property is_moderator does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
419
	{
420
		// The permissions and theme need loading, just to make sure everything goes smoothly.
421
		loadPermissions();
422
		new ElkArte\Themes\ThemeLoader();
423
424
		$_GET['board'] = '';
425
		$_GET['topic'] = '';
426
427
		// The linktree should not give the game away mate!
428
		$context['linktree'] = array(
429
			array(
430
				'url' => $scripturl,
431
				'name' => $context['forum_name_html_safe']
432
			)
433
		);
434
435
		// If it's a prefetching agent, stop it
436
		stop_prefetching();
437
438
		// If we're requesting an attachment.
439
		if (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'dlattach')
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $_REQUEST['action'] (integer) and 'dlattach' (string) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
440
		{
441
			ob_end_clean();
442
			header('HTTP/1.1 403 Forbidden');
443
			exit;
444
		}
445
		elseif (User::$info->is_guest)
0 ignored issues
show
Documentation introduced by
The property is_guest does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
446
		{
447
			theme()->getTemplates()->loadLanguageFile('Errors');
448
			is_not_guest($txt['topic_gone']);
449
		}
450
		else
451
			throw new \ElkArte\Exceptions\Exception('topic_gone', false);
452
	}
453
454 2
	if (User::$info->is_mod)
0 ignored issues
show
Documentation introduced by
The property is_mod does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
455
	{
456
		User::$info->groups = array_merge(User::$info->groups, [3]);
0 ignored issues
show
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
457
	}
458 2
}
459
460
/**
461
 * Load this user's permissions.
462
 *
463
 * What it does:
464
 *
465
 * - If the user is an admin, validate that they have not been banned.
466
 * - Attempt to load permissions from cache for cache level > 2
467
 * - See if the user is possibly a robot and apply added permissions as needed
468
 * - Load permissions from the general permissions table.
469
 * - If inside a board load the necessary board permissions.
470
 * - If the user is not a guest, identify what other boards they have access to.
471
 */
472
function loadPermissions()
473
{
474 1
	global $board, $board_info, $modSettings;
475
476 1
	$db = database();
477
478 1
	if (User::$info->is_admin)
0 ignored issues
show
Documentation introduced by
The property is_admin does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
479
	{
480
		banPermissions();
481
		return;
482
	}
483
484 1
	$removals = array();
485
486 1
	$cache = \ElkArte\Cache\Cache::instance();
487
488 1
	if ($cache->isEnabled())
489
	{
490
		$cache_groups = User::$info->groups;
0 ignored issues
show
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
491
		asort($cache_groups);
492
		$cache_groups = implode(',', $cache_groups);
493
494
		// If it's a spider then cache it different.
495
		if (User::$info->possibly_robot)
0 ignored issues
show
Documentation introduced by
The property possibly_robot does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
496
		{
497
			$cache_groups .= '-spider';
498
		}
499
		$cache_key = 'permissions:' . $cache_groups;
500
		$cache_board_key = 'permissions:' . $cache_groups . ':' . $board;
501
502
		$temp = array();
503
		if ($cache->levelHigherThan(1) && !empty($board) && $cache->getVar($temp, $cache_board_key, 240) && time() - 240 > $modSettings['settings_updated'])
504
		{
505
			list (User::$info->permissions) = $temp;
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
506
			banPermissions();
507
508
			return;
509
		}
510
		elseif ($cache->getVar($temp, $cache_key, 240) && time() - 240 > $modSettings['settings_updated'])
511
		{
512
			if (is_array($temp))
513
			{
514
				list (User::$info->permissions, $removals) = $temp;
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
515
			}
516
		}
517
	}
518
519
	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
520 1
	$spider_restrict = User::$info->possibly_robot && !empty($modSettings['spider_group']) ? ' OR (id_group = {int:spider_group} AND add_deny = 0)' : '';
0 ignored issues
show
Documentation introduced by
The property possibly_robot does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
521
522 1
	if (empty(User::$info->permissions))
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
523
	{
524 1
		$permissions = [];
525
		// Get the general permissions.
526 1
		$request = $db->query('', '
527
			SELECT
528
				permission, add_deny
529
			FROM {db_prefix}permissions
530
			WHERE id_group IN ({array_int:member_groups})
531 1
				' . $spider_restrict,
532
			array(
533 1
				'member_groups' => User::$info->groups,
0 ignored issues
show
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
534 1
				'spider_group' => !empty($modSettings['spider_group']) && $modSettings['spider_group'] != 1 ? $modSettings['spider_group'] : 0,
535
			)
536
		);
537 1
		while ($row = $db->fetch_assoc($request))
538
		{
539 1
			if (empty($row['add_deny']))
540
				$removals[] = $row['permission'];
541
			else
542 1
				$permissions[] = $row['permission'];
543
		}
544 1
		User::$info->permissions = $permissions;
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
545 1
		$db->free_result($request);
546
547 1
		if (isset($cache_key))
548
		{
549
			$cache->put($cache_key, array((array) User::$info->permissions, !empty($removals) ? $removals : array()), 2);
550
		}
551
	}
552
553
	// Get the board permissions.
554 1
	if (!empty($board))
555
	{
556
		// Make sure the board (if any) has been loaded by loadBoard().
557
		if (!isset($board_info['profile']))
558
		{
559
			throw new \ElkArte\Exceptions\Exception('no_board');
560
		}
561
562
		$permissions = [];
563
		$request = $db->query('', '
564
			SELECT
565
				permission, add_deny
566
			FROM {db_prefix}board_permissions
567
			WHERE (id_group IN ({array_int:member_groups})
568
				' . $spider_restrict . ')
569
				AND id_profile = {int:id_profile}',
570
			array(
571
				'member_groups' => User::$info->groups,
0 ignored issues
show
Documentation introduced by
The property groups does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
572
				'id_profile' => $board_info['profile'],
573
				'spider_group' => !empty($modSettings['spider_group']) && $modSettings['spider_group'] != 1 ? $modSettings['spider_group'] : 0,
574
			)
575
		);
576
		while ($row = $db->fetch_assoc($request))
577
		{
578
			if (empty($row['add_deny']))
579
				$removals[] = $row['permission'];
580
			else
581
				$permissions[] = $row['permission'];
582
		}
583
		User::$info->permissions = $permissions;
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
584
		$db->free_result($request);
585
	}
586
587
	// Remove all the permissions they shouldn't have ;).
588 1
	if (!empty($modSettings['permission_enable_deny']))
589
	{
590
		User::$info->permissions = array_diff(User::$info->permissions, $removals);
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
591
	}
592
593 1
	if (isset($cache_board_key) && !empty($board) && $cache->levelHigherThan(1))
594
	{
595
		$cache->put($cache_board_key, array(User::$info->permissions, null), 240);
0 ignored issues
show
Documentation introduced by
The property permissions does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
596
	}
597
598
	// Banned?  Watch, don't touch..
599 1
	banPermissions();
600
601
	// Load the mod cache so we can know what additional boards they should see, but no sense in doing it for guests
602 1
	if (User::$info->is_guest === false)
0 ignored issues
show
Documentation introduced by
The property is_guest does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
603
	{
604
		User::$info->is_moderator = User::$info->is_mod || allowedTo('moderate_board');
0 ignored issues
show
Documentation introduced by
The property is_moderator does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property is_mod does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
605
		if (!isset($_SESSION['mc']) || $_SESSION['mc']['time'] <= $modSettings['settings_updated'])
606
		{
607
			require_once(SUBSDIR . '/Auth.subs.php');
608
			rebuildModCache();
609
		}
610
		else
611
		{
612
			User::$info->mod_cache = $_SESSION['mc'];
0 ignored issues
show
Documentation introduced by
The property mod_cache does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
613
		}
614
	}
615 1
}
616
617
/**
618
 * Loads information about what browser the user is viewing with and places it in $context
619
 *
620
 * @uses ElkArte\Http\BrowserDetector class
621
 */
622
function detectBrowser()
623
{
624 15
	global $context;
625
626
	// Load the current user's browser of choice
627 15
	$detector = new ElkArte\Http\BrowserDetector;
628 15
	$context['browser'] = $detector->detectBrowser();
629 15
	$context['browser_body_id'] = $detector->browserBodyId();
630 15
}
631
632
/**
633
 * Load a theme, by ID.
634
 *
635
 * What it does:
636
 *
637
 * - identify the theme to be loaded.
638
 * - validate that the theme is valid and that the user has permission to use it
639
 * - load the users theme settings and site settings into $options.
640
 * - prepares the list of folders to search for template loading.
641
 * - identify what smiley set to use.
642
 * - sets up $context['user']
643
 * - detects the users browser and sets a mobile friendly environment if needed
644
 * - loads default JS variables for use in every theme
645
 * - loads default JS scripts for use in every theme
646
 *
647
 * @deprecated since 2.0; use the theme object
648
 *
649
 * @param int $id_theme = 0
650
 * @param bool $initialize = true
651
 */
652
function loadTheme($id_theme = 0, $initialize = true)
653
{
654
	\ElkArte\Errors\Errors::instance()->log_deprecated('loadTheme()', '\\ElkArte\\Themes\\ThemeLoader');
655
	new ElkArte\Themes\ThemeLoader($id_theme, $initialize);
656
}
657
658
/**
659
 * Loads basic user information in to $context['user']
660
 */
661
function loadUserContext()
662
{
663 15
	global $context, $txt, $modSettings;
664
665
	// Set up the contextual user array.
666 15
	$context['user'] = array(
667 15
		'id' => User::$info->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
668 15
		'is_logged' => User::$info->is_guest === false,
0 ignored issues
show
Documentation introduced by
The property is_guest does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
669 15
		'is_guest' => User::$info->is_guest,
0 ignored issues
show
Documentation introduced by
The property is_guest does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
670 15
		'is_admin' => User::$info->is_admin,
0 ignored issues
show
Documentation introduced by
The property is_admin does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
671 15
		'is_mod' => User::$info->is_mod,
0 ignored issues
show
Documentation introduced by
The property is_mod does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
672 15
		'is_moderator' => User::$info->is_moderator,
0 ignored issues
show
Documentation introduced by
The property is_moderator does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
673
		// A user can mod if they have permission to see the mod center, or they are a board/group/approval moderator.
674 15
		'can_mod' => User::$info->canMod($modSettings['postmod_active']),
0 ignored issues
show
Documentation Bug introduced by
The method canMod does not exist on object<ElkArte\ValuesContainer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
675 15
		'username' => User::$info->username,
0 ignored issues
show
Documentation introduced by
The property username does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
676 15
		'language' => User::$info->language,
0 ignored issues
show
Documentation introduced by
The property language does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
677 15
		'email' => User::$info->email,
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
678 15
		'ignoreusers' => User::$info->ignoreusers,
0 ignored issues
show
Documentation introduced by
The property ignoreusers does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
679
	);
680
681
	// Something for the guests
682 15
	if (!$context['user']['is_guest'])
683
	{
684
		$context['user']['name'] = User::$info->name;
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<ElkArte\ValuesContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
685
	}
686 15
	elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
687
	{
688 14
		$context['user']['name'] = $txt['guest_title'];
689
	}
690
691 15
	$context['user']['smiley_set'] = determineSmileySet(User::$info->smiley_set, $modSettings['smiley_sets_known']);
0 ignored issues
show
Documentation introduced by
The property smiley_set does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
692 15
	$context['smiley_enabled'] = User::$info->smiley_set !== 'none';
0 ignored issues
show
Documentation introduced by
The property smiley_set does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
693 15
	$context['user']['smiley_path'] = $modSettings['smileys_url'] . '/' . $context['user']['smiley_set'] . '/';
694 15
}
695
696
/**
697
 * Determine the current user's smiley set
698
 *
699
 * @param mixed[] $user_smiley_set
700
 * @param mixed[] $known_smiley_sets
701
 *
702
 * @return mixed
703
 */
704
function determineSmileySet($user_smiley_set, $known_smiley_sets)
705
{
706 17
	global $modSettings, $settings;
707
708 17
	if ((!in_array($user_smiley_set, explode(',', $known_smiley_sets)) && $user_smiley_set !== 'none') || empty($modSettings['smiley_sets_enable']))
709
	{
710 17
		$set = !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'];
711
	}
712
	else
713
	{
714
		$set = $user_smiley_set;
715
	}
716
717 17
	return $set;
718
}
719
720
/**
721
 * This loads the bare minimum data.
722
 *
723
 * @deprecated since 2.0; use the theme object
724
 *
725
 * - Needed by scheduled tasks,
726
 * - Needed by any other code that needs language files before the forum (the theme) is loaded.
727
 */
728
function loadEssentialThemeData()
729
{
730
	\ElkArte\Errors\Errors::instance()->log_deprecated('loadEssentialThemeData()', 'theme()->getTemplates()->loadEssentialThemeData()');
731
	return theme()->getTemplates()->loadEssentialThemeData();
732
}
733
734
/**
735
 * Load a template - if the theme doesn't include it, use the default.
736
 *
737
 * What it does:
738
 *
739
 * - loads a template file with the name template_name from the current, default, or base theme.
740
 * - detects a wrong default theme directory and tries to work around it.
741
 * - can be used to only load style sheets by using false as the template name
742
 *   loading of style sheets with this function is deprecated, use loadCSSFile instead
743
 * - if $settings['template_dirs'] is empty, it delays the loading of the template
744
 *
745
 * @deprecated since 2.0; use the theme object
746
 *
747
 * @uses the requireTemplate() function to actually load the file.
748
 *
749
 * @param string|false $template_name
750
 * @param string[]|string $style_sheets any style sheets to load with the template
751
 * @param bool $fatal = true if fatal is true, dies with an error message if the template cannot be found
752
 *
753
 * @return boolean|null
754
 */
755
function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
756
{
757
	\ElkArte\Errors\Errors::instance()->log_deprecated('loadTemplate()', 'theme()->getTemplates()->load()');
758
	return theme()->getTemplates()->load($template_name, $style_sheets, $fatal);
759
}
760
761
/**
762
 * Load a sub-template.
763
 *
764
 * What it does:
765
 *
766
 * - loads the sub template specified by sub_template_name, which must be in an already-loaded template.
767
 * - if ?debug is in the query string, shows administrators a marker after every sub template
768
 * for debugging purposes.
769
 *
770
 * @deprecated since 2.0; use the theme object
771
 *
772
 * @param string $sub_template_name
773
 * @param bool|string $fatal = false
774
 * - $fatal = true is for templates that shouldn't get a 'pretty' error screen
775
 * - $fatal = 'ignore' to skip
776
 *
777
 * @return bool
778
 */
779
function loadSubTemplate($sub_template_name, $fatal = false)
780
{
781
	\ElkArte\Errors\Errors::instance()->log_deprecated('loadSubTemplate()', 'theme()->getTemplates()->loadSubTemplate()');
782
	theme()->getTemplates()->loadSubTemplate($sub_template_name, $fatal);
783
784
	return true;
785
}
786
787
/**
788
 * Add a CSS file for output later
789
 *
790
 * @param string[]|string $filenames string or array of filenames to work on
791
 * @param mixed[] $params = array()
792
 * Keys are the following:
793
 * - ['local'] (true/false): define if the file is local
794
 * - ['fallback'] (true/false): if false  will attempt to load the file
795
 *   from the default theme if not found in the current theme
796
 * - ['stale'] (true/false/string): if true or null, use cache stale,
797
 *   false do not, or used a supplied string
798
 * @param string $id optional id to use in html id=""
799
 */
800
function loadCSSFile($filenames, $params = array(), $id = '')
801
{
802 15
	global $context;
803
804 15
	if (empty($filenames))
805
		return;
806
807 15
	if (!is_array($filenames))
808 15
		$filenames = array($filenames);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $filenames. This often makes code more readable.
Loading history...
809
810 15
	if (in_array('admin.css', $filenames))
811
		$filenames[] = $context['theme_variant'] . '/admin' . $context['theme_variant'] . '.css';
812
813 15
	$params['subdir'] = 'css';
814 15
	$params['extension'] = 'css';
815 15
	$params['index_name'] = 'css_files';
816 15
	$params['debug_index'] = 'sheets';
817
818 15
	loadAssetFile($filenames, $params, $id);
819 15
}
820
821
/**
822
 * Add a Javascript file for output later
823
 *
824
 * What it does:
825
 *
826
 * - Can be passed an array of filenames, all which will have the same
827
 *   parameters applied,
828
 * - if you need specific parameters on a per file basis, call it multiple times
829
 *
830
 * @param string[]|string $filenames string or array of filenames to work on
831
 * @param mixed[] $params = array()
832
 * Keys are the following:
833
 * - ['local'] (true/false): define if the file is local, if file does not
834
 *     start with http its assumed local
835
 * - ['defer'] (true/false): define if the file should load in <head> or before
836
 *     the closing <html> tag
837
 * - ['fallback'] (true/false): if true will attempt to load the file from the
838
 *     default theme if not found in the current this is the default behavior
839
 *     if this is not supplied
840
 * - ['async'] (true/false): if the script should be loaded asynchronously (HTML5)
841
 * - ['stale'] (true/false/string): if true or null, use cache stale, false do
842
 *     not, or used a supplied string
843
 * @param string $id = '' optional id to use in html id=""
844
 */
845
function loadJavascriptFile($filenames, $params = array(), $id = '')
846
{
847 15
	if (empty($filenames))
848
		return;
849
850 15
	$params['subdir'] = 'scripts';
851 15
	$params['extension'] = 'js';
852 15
	$params['index_name'] = 'js_files';
853 15
	$params['debug_index'] = 'javascript';
854
855 15
	loadAssetFile($filenames, $params, $id);
856 15
}
857
858
/**
859
 * Add an asset (css, js or other) file for output later
860
 *
861
 * What it does:
862
 *
863
 * - Can be passed an array of filenames, all which will have the same
864
 *   parameters applied,
865
 * - If you need specific parameters on a per file basis, call it multiple times
866
 *
867
 * @param string[]|string $filenames string or array of filenames to work on
868
 * @param mixed[] $params = array()
869
 * Keys are the following:
870
 * - ['subdir'] (string): the subdirectory of the theme dir the file is in
871
 * - ['extension'] (string): the extension of the file (e.g. css)
872
 * - ['index_name'] (string): the $context index that holds the array of loaded
873
 *     files
874
 * - ['debug_index'] (string): the index that holds the array of loaded
875
 *     files for debugging debug
876
 * - ['local'] (true/false): define if the file is local, if file does not
877
 *     start with http or // (schema-less URLs) its assumed local.
878
 *     The parameter is in fact useful only for files whose name starts with
879
 *     http, in any other case (e.g. passing a local URL) the parameter would
880
 *     fail in properly adding the file to the list.
881
 * - ['defer'] (true/false): define if the file should load in <head> or before
882
 *     the closing <html> tag
883
 * - ['fallback'] (true/false): if true will attempt to load the file from the
884
 *     default theme if not found in the current this is the default behavior
885
 *     if this is not supplied
886
 * - ['async'] (true/false): if the script should be loaded asynchronously (HTML5)
887
 * - ['stale'] (true/false/string): if true or null, use cache stale, false do
888
 *     not, or used a supplied string
889
 * @param string $id = '' optional id to use in html id=""
890
 */
891
function loadAssetFile($filenames, $params = array(), $id = '')
892
{
893 15
	global $settings, $context, $db_show_debug;
894
895 15
	if (empty($filenames))
896
		return;
897
898 15
	$cache = \ElkArte\Cache\Cache::instance();
899
900 15
	if (!is_array($filenames))
901 15
		$filenames = array($filenames);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $filenames. This often makes code more readable.
Loading history...
902
903
	// Static values for all these settings
904 15
	if (!isset($params['stale']) || $params['stale'] === true)
905 15
		$staler_string = CACHE_STALE;
906
	elseif (is_string($params['stale']))
907
		$staler_string = ($params['stale'][0] === '?' ? $params['stale'] : '?' . $params['stale']);
908
	else
909
		$staler_string = '';
910
911 15
	$fallback = (!empty($params['fallback']) && ($params['fallback'] === false)) ? false : true;
912 15
	$dir = '/' . $params['subdir'] . '/';
913
914
	// Whoa ... we've done this before yes?
915 15
	$cache_name = 'load_' . $params['extension'] . '_' . hash('md5', $settings['theme_dir'] . implode('_', $filenames));
916 15
	$temp = array();
917 15
	if ($cache->getVar($temp, $cache_name, 600))
918
	{
919
		if (empty($context[$params['index_name']]))
920
			$context[$params['index_name']] = array();
921
922
		$context[$params['index_name']] += $temp;
923
924
		if ($db_show_debug === true)
925
		{
926
			foreach ($temp as $temp_params)
927
			{
928
				\ElkArte\Debug::instance()->add($params['debug_index'], $temp_params['options']['basename'] . '(' . (!empty($temp_params['options']['local']) ? (!empty($temp_params['options']['url']) ? basename($temp_params['options']['url']) : basename($temp_params['options']['dir'])) : '') . ')');
929
			}
930
		}
931
	}
932
	else
933
	{
934 15
		$this_build = array();
935
936
		// All the files in this group use the above parameters
937 15
		foreach ($filenames as $filename)
938
		{
939
			// Account for shorthand like admin.ext?xyz11 filenames
940 15
			$has_cache_staler = strpos($filename, '.' . $params['extension'] . '?');
941 15
			if ($has_cache_staler)
942
			{
943
				$cache_staler = $staler_string;
944
				$params['basename'] = substr($filename, 0, $has_cache_staler + strlen($params['extension']) + 1);
945
			}
946
			else
947
			{
948 15
				$cache_staler = $staler_string;
949 15
				$params['basename'] = $filename;
950
			}
951 15
			$this_id = empty($id) ? strtr(basename($filename), '?', '_') : $id;
952
953
			// Is this a local file?
954 15
			if (!empty($params['local']) || (substr($filename, 0, 4) !== 'http' && substr($filename, 0, 2) !== '//'))
955
			{
956 15
				$params['local'] = true;
957 15
				$params['dir'] = $settings['theme_dir'] . $dir;
958 15
				$params['url'] = $settings['theme_url'];
959
960
				// Fallback if we are not already in the default theme
961 15
				if ($fallback && ($settings['theme_dir'] !== $settings['default_theme_dir']) && !file_exists($settings['theme_dir'] . $dir . $params['basename']))
962
				{
963
					// Can't find it in this theme, how about the default?
964
					if (file_exists($settings['default_theme_dir'] . $dir . $params['basename']))
965
					{
966
						$filename = $settings['default_theme_url'] . $dir . $params['basename'] . $cache_staler;
967
						$params['dir'] = $settings['default_theme_dir'] . $dir;
968
						$params['url'] = $settings['default_theme_url'];
969
					}
970
					else
971
						$filename = false;
972
				}
973
				else
974 15
					$filename = $settings['theme_url'] . $dir . $params['basename'] . $cache_staler;
975
			}
976
977
			// Add it to the array for use in the template
978 15
			if (!empty($filename))
979
			{
980 15
				$this_build[$this_id] = $context[$params['index_name']][$this_id] = array('filename' => $filename, 'options' => $params);
981
982 15
				if ($db_show_debug === true)
983
				{
984
					\ElkArte\Debug::instance()->add($params['debug_index'], $params['basename'] . '(' . (!empty($params['local']) ? (!empty($params['url']) ? basename($params['url']) : basename($params['dir'])) : '') . ')');
985
				}
986
			}
987
988
			// Save it so we don't have to build this so often
989 15
			$cache->put($cache_name, $this_build, 600);
990
		}
991
	}
992 15
}
993
994
/**
995
 * Add a Javascript variable for output later (for feeding text strings and similar to JS)
996
 *
997
 * @deprecated since 2.0; use the theme object
998
 *
999
 * @param mixed[] $vars array of vars to include in the output done as 'varname' => 'var value'
1000
 * @param bool $escape = false, whether or not to escape the value
1001
 */
1002
function addJavascriptVar($vars, $escape = false)
1003
{
1004
	\ElkArte\Errors\Errors::instance()->log_deprecated('addJavascriptVar()', 'theme()->getTemplates()->addJavascriptVar()');
1005
	theme()->addJavascriptVar($vars, $escape);
1006
}
1007
1008
/**
1009
 * Add a block of inline Javascript code to be executed later
1010
 *
1011
 * What it does:
1012
 *
1013
 * - only use this if you have to, generally external JS files are better, but for very small scripts
1014
 *   or for scripts that require help from PHP/whatever, this can be useful.
1015
 * - all code added with this function is added to the same <script> tag so do make sure your JS is clean!
1016
 *
1017
 * @deprecated since 2.0; use the theme object
1018
 *
1019
 * @param string $javascript
1020
 * @param bool $defer = false, define if the script should load in <head> or before the closing <html> tag
1021
 */
1022
function addInlineJavascript($javascript, $defer = false)
1023
{
1024
	\ElkArte\Errors\Errors::instance()->log_deprecated('addInlineJavascript()', 'theme()->addInlineJavascript()');
1025
	theme()->addInlineJavascript($javascript, $defer);
1026
}
1027
1028
/**
1029
 * Load a language file.
1030
 *
1031
 * - Tries the current and default themes as well as the user and global languages.
1032
 *
1033
 * @deprecated since 2.0; use the theme object
1034
 *
1035
 * @param string $template_name
1036
 * @param string $lang = ''
1037
 * @param bool $fatal = true
1038
 * @param bool $force_reload = false
1039
 * @return string The language actually loaded.
1040
 */
1041
function loadLanguage($template_name, $lang = '', $fatal = true, $force_reload = false)
1042
{
1043
	\ElkArte\Errors\Errors::instance()->log_deprecated('loadLanguage()', 'theme()->getTemplates()->loadLanguageFile()');
1044
	return theme()->getTemplates()->loadLanguageFile($template_name, $lang, $fatal, $force_reload);
1045
}
1046
1047
/**
1048
 * Loads / Sets arrays for use in date display
1049
 * This is here and not in a language file for two reasons:
1050
 *  1. the structure is required by the code, so better be sure
1051
 *     to have it the way we are supposed to have it
1052
 *  2. Transifex (that we use for translating the strings) doesn't
1053
 *     support array of arrays, so if we move this to a language file
1054
 *     we'd need to move away from Tx.
1055
 */
1056
function fix_calendar_text()
1057
{
1058 1
	global $txt;
1059
1060 1
	$txt['days'] = array(
1061 1
		$txt['sunday'],
1062 1
		$txt['monday'],
1063 1
		$txt['tuesday'],
1064 1
		$txt['wednesday'],
1065 1
		$txt['thursday'],
1066 1
		$txt['friday'],
1067 1
		$txt['saturday'],
1068
	);
1069 1
	$txt['days_short'] = array(
1070 1
		$txt['sunday_short'],
1071 1
		$txt['monday_short'],
1072 1
		$txt['tuesday_short'],
1073 1
		$txt['wednesday_short'],
1074 1
		$txt['thursday_short'],
1075 1
		$txt['friday_short'],
1076 1
		$txt['saturday_short'],
1077
	);
1078 1
	$txt['months'] = array(
1079 1
		1 => $txt['january'],
1080 1
		$txt['february'],
1081 1
		$txt['march'],
1082 1
		$txt['april'],
1083 1
		$txt['may'],
1084 1
		$txt['june'],
1085 1
		$txt['july'],
1086 1
		$txt['august'],
1087 1
		$txt['september'],
1088 1
		$txt['october'],
1089 1
		$txt['november'],
1090 1
		$txt['december'],
1091
	);
1092 1
	$txt['months_titles'] = array(
1093 1
		1 => $txt['january_titles'],
1094 1
		$txt['february_titles'],
1095 1
		$txt['march_titles'],
1096 1
		$txt['april_titles'],
1097 1
		$txt['may_titles'],
1098 1
		$txt['june_titles'],
1099 1
		$txt['july_titles'],
1100 1
		$txt['august_titles'],
1101 1
		$txt['september_titles'],
1102 1
		$txt['october_titles'],
1103 1
		$txt['november_titles'],
1104 1
		$txt['december_titles'],
1105
	);
1106 1
	$txt['months_short'] = array(
1107 1
		1 => $txt['january_short'],
1108 1
		$txt['february_short'],
1109 1
		$txt['march_short'],
1110 1
		$txt['april_short'],
1111 1
		$txt['may_short'],
1112 1
		$txt['june_short'],
1113 1
		$txt['july_short'],
1114 1
		$txt['august_short'],
1115 1
		$txt['september_short'],
1116 1
		$txt['october_short'],
1117 1
		$txt['november_short'],
1118 1
		$txt['december_short'],
1119
	);
1120 1
}
1121
1122
/**
1123
 * Get all parent boards (requires first parent as parameter)
1124
 *
1125
 * What it does:
1126
 *
1127
 * - It finds all the parents of id_parent, and that board itself.
1128
 * - Additionally, it detects the moderators of said boards.
1129
 * - Returns an array of information about the boards found.
1130
 *
1131
 * @param int $id_parent
1132
 *
1133
 * @return array
1134
 * @throws \ElkArte\Exceptions\Exception parent_not_found
1135
 */
1136
function getBoardParents($id_parent)
1137
{
1138 24
	global $scripturl;
1139
1140 24
	$db = database();
1141 24
	$cache = \ElkArte\Cache\Cache::instance();
1142 24
	$boards = array();
1143
1144
	// First check if we have this cached already.
1145 24
	if (!$cache->getVar($boards, 'board_parents-' . $id_parent, 480))
1146
	{
1147 24
		$boards = array();
1148 24
		$original_parent = $id_parent;
1149
1150
		// Loop while the parent is non-zero.
1151 24
		while ($id_parent != 0)
1152
		{
1153 22
			$result = $db->query('', '
1154
				SELECT
1155
					b.id_parent, b.name, {int:board_parent} AS id_board, COALESCE(mem.id_member, 0) AS id_moderator,
1156
					mem.real_name, b.child_level
1157
				FROM {db_prefix}boards AS b
1158
					LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board)
1159
					LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
1160
				WHERE b.id_board = {int:board_parent}',
1161
				array(
1162 22
					'board_parent' => $id_parent,
1163
				)
1164
			);
1165
			// In the EXTREMELY unlikely event this happens, give an error message.
1166 22
			if ($db->num_rows($result) == 0)
1167
			{
1168
				throw new \ElkArte\Exceptions\Exception('parent_not_found', 'critical');
1169
			}
1170 22
			while ($row = $db->fetch_assoc($result))
1171
			{
1172 22
				if (!isset($boards[$row['id_board']]))
1173
				{
1174 22
					$id_parent = $row['id_parent'];
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $id_parent. This often makes code more readable.
Loading history...
1175 22
					$boards[$row['id_board']] = array(
1176 22
						'url' => $scripturl . '?board=' . $row['id_board'] . '.0',
1177 22
						'name' => $row['name'],
1178 22
						'level' => $row['child_level'],
1179
						'moderators' => array()
1180
					);
1181
				}
1182
1183
				// If a moderator exists for this board, add that moderator for all children too.
1184 22
				if (!empty($row['id_moderator']))
1185
					foreach ($boards as $id => $dummy)
1186
					{
1187
						$boards[$id]['moderators'][$row['id_moderator']] = array(
1188
							'id' => $row['id_moderator'],
1189
							'name' => $row['real_name'],
1190
							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
1191
							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
1192
						);
1193
					}
1194
			}
1195 22
			$db->free_result($result);
1196
		}
1197
1198 24
		$cache->put('board_parents-' . $original_parent, $boards, 480);
1199
	}
1200
1201 24
	return $boards;
1202
}
1203
1204
/**
1205
 * Attempt to reload our known languages.
1206
 *
1207
 * @param bool $use_cache = true
1208
 *
1209
 * @return array
1210
 */
1211
function getLanguages($use_cache = true)
1212
{
1213 2
	global $settings;
1214
1215 2
	$cache = \ElkArte\Cache\Cache::instance();
1216
1217
	// Either we don't use the cache, or its expired.
1218 2
	$languages = array();
1219
1220 2
	if (!$use_cache || !$cache->getVar($languages, 'known_languages', $cache->levelLowerThan(2) ? 86400 : 3600))
1221
	{
1222
		// If we don't have our theme information yet, lets get it.
1223 2
		if (empty($settings['default_theme_dir']))
1224
			new ElkArte\Themes\ThemeLoader(0, false);
1225
1226
		// Default language directories to try.
1227
		$language_directories = array(
1228 2
			$settings['default_theme_dir'] . '/languages',
1229 2
			$settings['actual_theme_dir'] . '/languages',
1230
		);
1231
1232
		// We possibly have a base theme directory.
1233 2
		if (!empty($settings['base_theme_dir']))
1234
			$language_directories[] = $settings['base_theme_dir'] . '/languages';
1235
1236
		// Remove any duplicates.
1237 2
		$language_directories = array_unique($language_directories);
1238
1239 2
		foreach ($language_directories as $language_dir)
1240
		{
1241
			// Can't look in here... doesn't exist!
1242 2
			if (!file_exists($language_dir))
1243
				continue;
1244
1245 2
			$dir = dir($language_dir);
1246 2
			while ($entry = $dir->read())
1247
			{
1248
				// Only directories are interesting
1249 2
				if ($entry == '..' || !is_dir($dir->path . '/' . $entry))
0 ignored issues
show
Bug introduced by
The property path does not seem to exist in Directory.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1250 2
					continue;
1251
1252
				// @todo at some point we may want to simplify that stuff (I mean scanning all the files just for index)
1253 2
				$file_dir = dir($dir->path . '/' . $entry);
1254 2
				while ($file_entry = $file_dir->read())
1255
				{
1256
					// Look for the index language file....
1257 2
					if (!preg_match('~^index\.(.+)\.php$~', $file_entry, $matches))
1258 2
						continue;
1259
1260 2
					$languages[$matches[1]] = array(
1261 2
						'name' => \ElkArte\Util::ucwords(strtr($matches[1], array('_' => ' '))),
1262
						'selected' => false,
1263 2
						'filename' => $matches[1],
1264 2
						'location' => $language_dir . '/' . $entry . '/index.' . $matches[1] . '.php',
1265
					);
1266
				}
1267 2
				$file_dir->close();
1268
			}
1269 2
			$dir->close();
1270
		}
1271
1272
		// Lets cash in on this deal.
1273 2
		$cache->put('known_languages', $languages, $cache->isEnabled() && $cache->levelLowerThan(1) ? 86400 : 3600);
1274
	}
1275
1276 2
	return $languages;
1277
}
1278
1279
/**
1280
 * Initialize a database connection.
1281
 */
1282
function loadDatabase()
1283
{
1284 1
	global $db_prefix, $db_name;
1285
1286
	// Database stuffs
1287 1
	require_once(SOURCEDIR . '/database/Database.subs.php');
1288
1289
	// Safe guard here, if there isn't a valid connection lets put a stop to it.
1290
	try
1291
	{
1292 1
		$db = database(false);
1293
	}
1294
	catch (\Exception $e)
1295
	{
1296
		\ElkArte\Errors\Errors::instance()->display_db_error();
1297
	}
1298
1299
	// If in SSI mode fix up the prefix.
1300 1
	if (ELK === 'SSI')
1301
	{
1302
		$db_prefix = $db->fix_prefix($db_prefix, $db_name);
1303
	}
1304
1305
	// Case sensitive database? Let's define a constant.
1306
	// @NOTE: I think it is already taken care by the abstraction, it should be possible to remove
1307 1
	if ($db->case_sensitive() && !defined('DB_CASE_SENSITIVE'))
1308
	{
1309
		DEFINE('DB_CASE_SENSITIVE', '1');
1310
	}
1311 1
}
1312
1313
/**
1314
 * Determine the user's avatar type and return the information as an array
1315
 *
1316
 * @todo this function seems more useful than expected, it should be improved. :P
1317
 *
1318
 * @event integrate_avatar allows access to $avatar array before it is returned
1319
 * @param mixed[] $profile array containing the users profile data
1320
 *
1321
 * @return mixed[] $avatar
1322
 */
1323
function determineAvatar($profile)
1324
{
1325 7
	global $modSettings, $scripturl, $settings;
1326
1327 7
	if (empty($profile))
1328
		return array();
1329
1330 7
	$avatar_protocol = substr(strtolower($profile['avatar']), 0, 7);
1331
1332
	// uploaded avatar?
1333 7
	if ($profile['id_attach'] > 0 && empty($profile['avatar']))
1334
	{
1335
		// where are those pesky avatars?
1336
		$avatar_url = empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1337
1338
		$avatar = array(
1339
			'name' => $profile['avatar'],
1340
			'image' => '<img class="avatar avatarresize" src="' . $avatar_url . '" alt="" />',
1341
			'href' => $avatar_url,
1342
			'url' => '',
1343
		);
1344
	}
1345
	// remote avatar?
1346 7
	elseif ($avatar_protocol === 'http://' || $avatar_protocol === 'https:/')
1347
	{
1348
		$avatar = array(
1349
			'name' => $profile['avatar'],
1350
			'image' => '<img class="avatar avatarresize" src="' . $profile['avatar'] . '" alt="" />',
1351
			'href' => $profile['avatar'],
1352
			'url' => $profile['avatar'],
1353
		);
1354
	}
1355
	// Gravatar instead?
1356 7
	elseif (!empty($profile['avatar']) && $profile['avatar'] === 'gravatar')
1357
	{
1358
		// Gravatars URL.
1359
		$gravatar_url = '//www.gravatar.com/avatar/' . hash('md5', strtolower($profile['email_address'])) . '?s=' . $modSettings['avatar_max_height'] . (!empty($modSettings['gravatar_rating']) ? ('&amp;r=' . $modSettings['gravatar_rating']) : '');
1360
1361
		$avatar = array(
1362
			'name' => $profile['avatar'],
1363
			'image' => '<img class="avatar avatarresize" src="' . $gravatar_url . '" alt="" />',
1364
			'href' => $gravatar_url,
1365
			'url' => $gravatar_url,
1366
		);
1367
	}
1368
	// an avatar from the gallery?
1369 7
	elseif (!empty($profile['avatar']) && !($avatar_protocol === 'http://' || $avatar_protocol === 'https:/'))
1370
	{
1371
		$avatar = array(
1372
			'name' => $profile['avatar'],
1373
			'image' => '<img class="avatar avatarresize" src="' . $modSettings['avatar_url'] . '/' . $profile['avatar'] . '" alt="" />',
1374
			'href' => $modSettings['avatar_url'] . '/' . $profile['avatar'],
1375
			'url' => $modSettings['avatar_url'] . '/' . $profile['avatar'],
1376
		);
1377
	}
1378
	// no custom avatar found yet, maybe a default avatar?
1379 7
	elseif (!empty($modSettings['avatar_default']) && empty($profile['avatar']) && empty($profile['filename']))
1380
	{
1381
		// $settings not initialized? We can't do anything further..
1382
		if (!empty($settings))
1383
		{
1384
			// Let's proceed with the default avatar.
1385
			// TODO: This should be incorporated into the theme.
1386
			$avatar = array(
1387
				'name' => '',
1388
				'image' => '<img class="avatar avatarresize" src="' . $settings['images_url'] . '/default_avatar.png" alt="" />',
1389
				'href' => $settings['images_url'] . '/default_avatar.png',
1390
				'url' => 'http://',
1391
			);
1392
		}
1393
		else
1394
		{
1395
			$avatar = array();
1396
		}
1397
	}
1398
	// finally ...
1399
	else
1400
		$avatar = array(
1401 7
			'name' => '',
1402
			'image' => '',
1403
			'href' => '',
1404
			'url' => ''
1405
		);
1406
1407
	// Make sure there's a preview for gravatars available.
1408 7
	$avatar['gravatar_preview'] = '//www.gravatar.com/avatar/' . hash('md5', strtolower($profile['email_address'])) . '?s=' . $modSettings['avatar_max_height'] . (!empty($modSettings['gravatar_rating']) ? ('&amp;r=' . $modSettings['gravatar_rating']) : '');
1409
1410 7
	call_integration_hook('integrate_avatar', array(&$avatar, $profile));
1411
1412 7
	return $avatar;
1413
}
1414
1415
/**
1416
 * Get information about the server
1417
 */
1418
function detectServer()
1419
{
1420 32
	global $context;
1421 32
	static $server = null;
1422
1423 32
	if ($server === null)
1424
	{
1425 1
		$server = new ElkArte\Server($_SERVER);
1426 1
		$servers = array('iis', 'apache', 'litespeed', 'lighttpd', 'nginx', 'cgi', 'windows');
1427 1
		$context['server'] = array();
1428 1
		foreach ($servers as $name)
1429
		{
1430 1
			$context['server']['is_' . $name] = $server->is($name);
1431
		}
1432
1433 1
		$context['server']['iso_case_folding'] = $server->is('iso_case_folding');
1434
		// A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
1435 1
		$context['server']['needs_login_fix'] = $server->is('needs_login_fix');
1436
	}
1437
1438 32
	return $server;
1439
}
1440
1441
/**
1442
 * Returns if a webserver is of type server (apache, nginx, etc)
1443
 *
1444
 * @param $server
1445
 *
1446
 * @return bool
1447
 */
1448
function serverIs($server)
1449
{
1450
	return detectServer()->is($server);
1451
}
1452
1453
/**
1454
 * Do some important security checks:
1455
 *
1456
 * What it does:
1457
 *
1458
 * - Checks the existence of critical files e.g. install.php
1459
 * - Checks for an active admin session.
1460
 * - Checks cache directory is writable.
1461
 * - Calls secureDirectory to protect attachments & cache.
1462
 * - Checks if the forum is in maintenance mode.
1463
 */
1464
function doSecurityChecks()
1465
{
1466
	global $modSettings, $context, $maintenance, $txt, $scripturl, $options;
1467
1468
	$show_warnings = false;
1469
1470
	$cache = \ElkArte\Cache\Cache::instance();
1471
1472
	if (allowedTo('admin_forum') && User::$info->is_guest === false)
0 ignored issues
show
Documentation introduced by
The property is_guest does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1473
	{
1474
		// If agreement is enabled, at least the english version shall exists
1475
		if ($modSettings['requireAgreement'] && !file_exists(BOARDDIR . '/agreement.txt'))
1476
		{
1477
			$context['security_controls_files']['title'] = $txt['generic_warning'];
1478
			$context['security_controls_files']['errors']['agreement'] = $txt['agreement_missing'];
1479
			$show_warnings = true;
1480
		}
1481
1482
		// Cache directory writable?
1483
		if ($cache->isEnabled() && !is_writable(CACHEDIR))
1484
		{
1485
			$context['security_controls_files']['title'] = $txt['generic_warning'];
1486
			$context['security_controls_files']['errors']['cache'] = $txt['cache_writable'];
1487
			$show_warnings = true;
1488
		}
1489
1490
		if (checkSecurityFiles())
1491
			$show_warnings = true;
1492
1493
		// We are already checking so many files...just few more doesn't make any difference! :P
1494
		require_once(SUBSDIR . '/Attachments.subs.php');
1495
		$path = getAttachmentPath();
1496
		secureDirectory($path, true);
1497
		secureDirectory(CACHEDIR, false, '"\.(js|css)$"');
1498
1499
		// Active admin session?
1500
		if (isAdminSessionActive())
1501
			$context['warning_controls']['admin_session'] = sprintf($txt['admin_session_active'], ($scripturl . '?action=admin;area=adminlogoff;redir;' . $context['session_var'] . '=' . $context['session_id']));
1502
1503
		// Maintenance mode enabled?
1504
		if (!empty($maintenance))
1505
			$context['warning_controls']['maintenance'] = sprintf($txt['admin_maintenance_active'], ($scripturl . '?action=admin;area=serversettings;' . $context['session_var'] . '=' . $context['session_id']));
1506
1507
		// New updates
1508
		if (defined('FORUM_VERSION'))
1509
		{
1510
			$index = 'new_in_' . str_replace(array('ElkArte ', '.'), array('', '_'), FORUM_VERSION);
1511
			if (!empty($modSettings[$index]) && empty($options['dismissed_' . $index]))
1512
			{
1513
				$show_warnings = true;
1514
				$context['new_version_updates'] = array(
1515
					'title' => $txt['new_version_updates'],
1516
					'errors' => array(replaceBasicActionUrl($txt['new_version_updates_text'])),
1517
				);
1518
			}
1519
		}
1520
	}
1521
1522
	// Check for database errors.
1523
	if (!empty($_SESSION['query_command_denied']))
1524
	{
1525
		if (User::$info->is_admin)
0 ignored issues
show
Documentation introduced by
The property is_admin does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1526
		{
1527
			$context['security_controls_query']['title'] = $txt['query_command_denied'];
1528
			$show_warnings = true;
1529
			foreach ($_SESSION['query_command_denied'] as $command => $error)
1530
				$context['security_controls_query']['errors'][$command] = '<pre>' . \ElkArte\Util::htmlspecialchars($error) . '</pre>';
1531
		}
1532
		else
1533
		{
1534
			$context['security_controls_query']['title'] = $txt['query_command_denied_guests'];
1535
			foreach ($_SESSION['query_command_denied'] as $command => $error)
1536
				$context['security_controls_query']['errors'][$command] = '<pre>' . sprintf($txt['query_command_denied_guests_msg'], \ElkArte\Util::htmlspecialchars($command)) . '</pre>';
1537
		}
1538
	}
1539
1540
	// Are there any members waiting for approval?
1541
	if (allowedTo('moderate_forum') && ((!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2) || !empty($modSettings['approveAccountDeletion'])) && !empty($modSettings['unapprovedMembers']))
1542
		$context['warning_controls']['unapproved_members'] = sprintf($txt[$modSettings['unapprovedMembers'] == 1 ? 'approve_one_member_waiting' : 'approve_many_members_waiting'], $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve', $modSettings['unapprovedMembers']);
1543
1544
	if (!empty($context['open_mod_reports']) && (empty(\ElkArte\User::$settings['mod_prefs']) || \ElkArte\User::$settings['mod_prefs'][0] == 1))
1545
	{
1546
		$context['warning_controls']['open_mod_reports'] = '<a href="' . $scripturl . '?action=moderate;area=reports">' . sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']) . '</a>';
1547
	}
1548
1549
	if (!empty($context['open_pm_reports']) && allowedTo('admin_forum'))
1550
	{
1551
		$context['warning_controls']['open_pm_reports'] = '<a href="' . $scripturl . '?action=moderate;area=pm_reports">' . sprintf($txt['pm_reports_waiting'], $context['open_pm_reports']) . '</a>';
1552
	}
1553
1554
	if (isset($_SESSION['ban']['cannot_post']))
1555
	{
1556
		// An admin cannot be banned (technically he could), and if it is better he knows.
1557
		$context['security_controls_ban']['title'] = sprintf($txt['you_are_post_banned'], User::$info->is_guest ? $txt['guest_title'] : User::$info->name);
0 ignored issues
show
Documentation introduced by
The property is_guest does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property name does not exist on object<ElkArte\ValuesContainer>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1558
		$show_warnings = true;
1559
1560
		$context['security_controls_ban']['errors']['reason'] = '';
1561
1562
		if (!empty($_SESSION['ban']['cannot_post']['reason']))
1563
			$context['security_controls_ban']['errors']['reason'] = $_SESSION['ban']['cannot_post']['reason'];
1564
1565
		if (!empty($_SESSION['ban']['expire_time']))
1566
			$context['security_controls_ban']['errors']['reason'] .= '<span class="smalltext">' . sprintf($txt['your_ban_expires'], standardTime($_SESSION['ban']['expire_time'], false)) . '</span>';
1567
		else
1568
			$context['security_controls_ban']['errors']['reason'] .= '<span class="smalltext">' . $txt['your_ban_expires_never'] . '</span>';
1569
	}
1570
1571
	// Finally, let's show the layer.
1572
	if ($show_warnings || !empty($context['warning_controls']))
1573
		\theme()->getLayers()->addAfter('admin_warning', 'body');
1574
}
1575
1576
/**
1577
 * Load everything necessary for the BBC parsers
1578
 */
1579
function loadBBCParsers()
1580
{
1581
	global $modSettings;
1582
1583
	// Set the default disabled BBC
1584
	if (!empty($modSettings['disabledBBC']))
1585
	{
1586
		if (!is_array($modSettings['disabledBBC']))
1587
			$disabledBBC = explode(',', $modSettings['disabledBBC']);
1588
		else
1589
			$disabledBBC = $modSettings['disabledBBC'];
1590
		\BBC\ParserWrapper::instance()->setDisabled(empty($disabledBBC) ? array() : (array) $disabledBBC);
1591
	}
1592
1593
	return 1;
1594
}
1595
1596
/**
1597
 * This is necessary to support data stored in the pre-1.0.8 way (i.e. serialized)
1598
 *
1599
 * @param string $variable The string to convert
1600
 * @param null|callable $save_callback The function that will save the data to the db
1601
 * @return mixed[] the array
1602
 */
1603
function serializeToJson($variable, $save_callback = null)
1604
{
1605
	$array_form = json_decode($variable, true);
1606
1607
	// decoding failed, let's try with unserialize
1608
	if (!is_array($array_form))
1609
	{
1610
		try
1611
		{
1612
			$array_form = \ElkArte\Util::unserialize($variable);
1613
		}
1614
		catch (\Exception $e)
1615
		{
1616
			$array_form = false;
1617
		}
1618
1619
		// If unserialize fails as well, let's just store an empty array
1620
		if ($array_form === false)
1621
		{
1622
			$array_form = array(0, '', 0);
1623
		}
1624
1625
		// Time to update the value if necessary
1626
		if ($save_callback !== null)
1627
		{
1628
			$save_callback($array_form);
1629
		}
1630
	}
1631
1632
	return $array_form;
1633
}
1634