~azzar1/unity/add-show-desktop-key

443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
1
<?php
2
/**
3
*
4
* @package phpBB3
5
* @version $Id: functions_display.php,v 1.168 2007/10/20 10:12:54 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8
*
9
*/
10
11
/**
12
* @ignore
13
*/
14
if (!defined('IN_PHPBB'))
15
{
16
	exit;
17
}
18
19
/**
20
* Display Forums
21
*/
22
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
23
{
24
	global $db, $auth, $user, $template;
25
	global $phpbb_root_path, $phpEx, $config;
26
27
	$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
28
	$parent_id = $visible_forums = 0;
29
	$sql_from = '';
30
	
31
	// Mark forums read?
32
	$mark_read = request_var('mark', '');
33
34
	if ($mark_read == 'all')
35
	{
36
		$mark_read = '';
37
	}
38
39
	if (!$root_data)
40
	{
41
		if ($mark_read == 'forums')
42
		{
43
			$mark_read = 'all';
44
		}
45
46
		$root_data = array('forum_id' => 0);
47
		$sql_where = '';
48
	}
49
	else
50
	{
51
		$sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
52
	}
53
54
	// Display list of active topics for this category?
55
	$show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
56
57
	$sql_array = array(
58
		'SELECT'	=> 'f.*',
59
		'FROM'		=> array(
60
			FORUMS_TABLE		=> 'f'
61
		),
62
		'LEFT_JOIN'	=> array(),
63
	);
64
65
	if ($config['load_db_lastread'] && $user->data['is_registered'])
66
	{
67
		$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
68
		$sql_array['SELECT'] .= ', ft.mark_time';
69
	}
70
	else if ($config['load_anon_lastread'] || $user->data['is_registered'])
71
	{
72
		$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
73
		$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
74
75
		if (!$user->data['is_registered'])
76
		{
77
			$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
78
		}
79
	}
80
81
	if ($show_active)
82
	{
83
		$sql_array['LEFT_JOIN'][] = array(
84
			'FROM'	=> array(FORUMS_ACCESS_TABLE => 'fa'),
85
			'ON'	=> "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
86
		);
87
88
		$sql_array['SELECT'] .= ', fa.user_id';
89
	}
90
91
	$sql = $db->sql_build_query('SELECT', array(
92
		'SELECT'	=> $sql_array['SELECT'],
93
		'FROM'		=> $sql_array['FROM'],
94
		'LEFT_JOIN'	=> $sql_array['LEFT_JOIN'],
95
96
		'WHERE'		=> $sql_where,
97
98
		'ORDER_BY'	=> 'f.left_id',
99
	));
100
101
	$result = $db->sql_query($sql);
102
103
	$forum_tracking_info = array();
104
	$branch_root_id = $root_data['forum_id'];
105
	while ($row = $db->sql_fetchrow($result))
106
	{
107
		$forum_id = $row['forum_id'];
108
109
		// Mark forums read?
110
		if ($mark_read == 'forums' || $mark_read == 'all')
111
		{
112
			if ($auth->acl_get('f_list', $forum_id))
113
			{
114
				$forum_ids[] = $forum_id;
115
				continue;
116
			}
117
		}
118
119
		// Category with no members
120
		if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
121
		{
122
			continue;
123
		}
124
125
		// Skip branch
126
		if (isset($right_id))
127
		{
128
			if ($row['left_id'] < $right_id)
129
			{
130
				continue;
131
			}
132
			unset($right_id);
133
		}
134
135
		if (!$auth->acl_get('f_list', $forum_id))
136
		{
137
			// if the user does not have permissions to list this forum, skip everything until next branch
138
			$right_id = $row['right_id'];
139
			continue;
140
		}
141
142
		$forum_ids[] = $forum_id;
143
144
		if ($config['load_db_lastread'] && $user->data['is_registered'])
145
		{
146
			$forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
147
		}
148
		else if ($config['load_anon_lastread'] || $user->data['is_registered'])
149
		{
150
			if (!$user->data['is_registered'])
151
			{
152
				$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
153
			}
154
			$forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
155
		}
156
157
		$row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
158
159
		// Display active topics from this forum?
160
		if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
161
		{
162
			if (!isset($active_forum_ary['forum_topics']))
163
			{
164
				$active_forum_ary['forum_topics'] = 0;
165
			}
166
167
			if (!isset($active_forum_ary['forum_posts']))
168
			{
169
				$active_forum_ary['forum_posts'] = 0;
170
			}
171
172
			$active_forum_ary['forum_id'][]		= $forum_id;
173
			$active_forum_ary['enable_icons'][]	= $row['enable_icons'];
174
			$active_forum_ary['forum_topics']	+= $row['forum_topics'];
175
			$active_forum_ary['forum_posts']	+= $row['forum_posts'];
176
177
			// If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
178
			if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
179
			{
180
				$active_forum_ary['exclude_forum_id'][] = $forum_id;
181
			}
182
		}
183
184
		//
185
		if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
186
		{
187
			if ($row['forum_type'] != FORUM_CAT)
188
			{
189
				$forum_ids_moderator[] = (int) $forum_id;
190
			}
191
192
			// Direct child of current branch
193
			$parent_id = $forum_id;
194
			$forum_rows[$forum_id] = $row;
195
196
			if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
197
			{
198
				$branch_root_id = $forum_id;
199
			}
200
			$forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
201
			$forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
202
		}
203
		else if ($row['forum_type'] != FORUM_CAT)
204
		{
205
			$subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
206
			$subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
207
			$subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
208
209
			$forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
210
211
			// Do not list redirects in LINK Forums as Posts.
212
			if ($row['forum_type'] != FORUM_LINK)
213
			{
214
				$forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
215
			}
216
217
			if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
218
			{
219
				$forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
220
				$forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
221
				$forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
222
				$forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
223
				$forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
224
				$forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
225
				$forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
226
			}
227
		}
228
	}
229
	$db->sql_freeresult($result);
230
231
	// Handle marking posts
232
	if ($mark_read == 'forums' || $mark_read == 'all')
233
	{
234
		$redirect = build_url('mark');
235
236
		if ($mark_read == 'all')
237
		{
238
			markread('all');
239
240
			$message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
241
		}
242
		else
243
		{
244
			markread('topics', $forum_ids);
245
246
			$message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
247
		}
248
249
		meta_refresh(3, $redirect);
250
		trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
251
	}
252
253
	// Grab moderators ... if necessary
254
	if ($display_moderators)
255
	{
256
		if ($return_moderators)
257
		{
258
			$forum_ids_moderator[] = $root_data['forum_id'];
259
		}
260
		get_moderators($forum_moderators, $forum_ids_moderator);
261
	}
262
263
	// Used to tell whatever we have to create a dummy category or not.
264
	$last_catless = true;
265
	foreach ($forum_rows as $row)
266
	{
267
		// Empty category
268
		if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
269
		{
270
			$template->assign_block_vars('forumrow', array(
271
				'S_IS_CAT'				=> true,
272
				'FORUM_ID'				=> $row['forum_id'],
273
				'FORUM_NAME'			=> $row['forum_name'],
274
				'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
275
				'FORUM_FOLDER_IMG'		=> '',
276
				'FORUM_FOLDER_IMG_SRC'	=> '',
277
				'FORUM_IMAGE'			=> ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
278
				'FORUM_IMAGE_SRC'		=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
279
				'U_VIEWFORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
280
			);
281
282
			continue;
283
		}
284
285
		$visible_forums++;
286
		$forum_id = $row['forum_id'];
287
288
		$forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
289
290
		$folder_image = $folder_alt = $l_subforums = '';
291
		$subforums_list = array();
292
293
		// Generate list of subforums if we need to
294
		if (isset($subforums[$forum_id]))
295
		{
296
			foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
297
			{
298
				$subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
299
300
				if ($subforum_row['display'] && $subforum_row['name'])
301
				{
302
					$subforums_list[] = array(
303
						'link'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
304
						'name'		=> $subforum_row['name'],
305
						'unread'	=> $subforum_unread,
306
					);
307
				}
308
				else
309
				{
310
					unset($subforums[$forum_id][$subforum_id]);
311
				}
312
313
				// If one subforum is unread the forum gets unread too...
314
				if ($subforum_unread)
315
				{
316
					$forum_unread = true;
317
				}
318
			}
319
320
			$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
321
			$folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
322
		}
323
		else
324
		{
325
			switch ($row['forum_type'])
326
			{
327
				case FORUM_POST:
328
					$folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
329
				break;
330
331
				case FORUM_LINK:
332
					$folder_image = 'forum_link';
333
				break;
334
			}
335
		}
336
337
		// Which folder should we display?
338
		if ($row['forum_status'] == ITEM_LOCKED)
339
		{
340
			$folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
341
			$folder_alt = 'FORUM_LOCKED';
342
		}
343
		else
344
		{
345
			$folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
346
		}
347
348
		// Create last post link information, if appropriate
349
		if ($row['forum_last_post_id'])
350
		{
351
			$last_post_subject = $row['forum_last_post_subject'];
352
			$last_post_time = $user->format_date($row['forum_last_post_time']);
353
			$last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
354
		}
355
		else
356
		{
357
			$last_post_subject = $last_post_time = $last_post_url = '';
358
		}
359
360
		// Output moderator listing ... if applicable
361
		$l_moderator = $moderators_list = '';
362
		if ($display_moderators && !empty($forum_moderators[$forum_id]))
363
		{
364
			$l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
365
			$moderators_list = implode(', ', $forum_moderators[$forum_id]);
366
		}
367
368
		$l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
369
		$post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
370
371
		$s_subforums_list = array();
372
		foreach ($subforums_list as $subforum)
373
		{
374
			$s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '">' . $subforum['name'] . '</a>';
375
		}
376
		$s_subforums_list = (string) implode(', ', $s_subforums_list);
377
		$catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
378
379
		if ($row['forum_type'] != FORUM_LINK)
380
		{
381
			$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
382
		}
383
		else
384
		{
385
			// If the forum is a link and we count redirects we need to visit it
386
			// If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
387
			if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
388
			{
389
				$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
390
			}
391
			else
392
			{
393
				$u_viewforum = $row['forum_link'];
394
			}
395
		}
396
397
		$template->assign_block_vars('forumrow', array(
398
			'S_IS_CAT'			=> false,
399
			'S_NO_CAT'			=> $catless && !$last_catless,
400
			'S_IS_LINK'			=> ($row['forum_type'] == FORUM_LINK) ? true : false,
401
			'S_UNREAD_FORUM'	=> $forum_unread,
402
			'S_LOCKED_FORUM'	=> ($row['forum_status'] == ITEM_LOCKED) ? true : false,
403
			'S_SUBFORUMS'		=> (sizeof($subforums_list)) ? true : false,
404
405
			'FORUM_ID'				=> $row['forum_id'],
406
			'FORUM_NAME'			=> $row['forum_name'],
407
			'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
408
			'TOPICS'				=> $row['forum_topics'],
409
			$l_post_click_count		=> $post_click_count,
410
			'FORUM_FOLDER_IMG'		=> $user->img($folder_image, $folder_alt),
411
			'FORUM_FOLDER_IMG_SRC'	=> $user->img($folder_image, $folder_alt, false, '', 'src'),
412
			'FORUM_IMAGE'			=> ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
413
			'FORUM_IMAGE_SRC'		=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
414
			'LAST_POST_SUBJECT'		=> censor_text($last_post_subject),
415
			'LAST_POST_TIME'		=> $last_post_time,
416
			'LAST_POSTER'			=> get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
417
			'LAST_POSTER_COLOUR'	=> get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
418
			'LAST_POSTER_FULL'		=> get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
419
			'MODERATORS'			=> $moderators_list,
420
			'SUBFORUMS'				=> $s_subforums_list,
421
422
			'L_SUBFORUM_STR'		=> $l_subforums,
423
			'L_FORUM_FOLDER_ALT'	=> $folder_alt,
424
			'L_MODERATOR_STR'		=> $l_moderator,
425
426
			'U_VIEWFORUM'		=> $u_viewforum,
427
			'U_LAST_POSTER'		=> get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
428
			'U_LAST_POST'		=> $last_post_url)
429
		);
430
431
		// Assign subforums loop for style authors
432
		foreach ($subforums_list as $subforum)
433
		{
434
			$template->assign_block_vars('forumrow.subforum', array(
435
				'U_SUBFORUM'	=> $subforum['link'],
436
				'SUBFORUM_NAME'	=> $subforum['name'],
437
				'S_UNREAD'		=> $subforum['unread'])
438
			);
439
		}
440
		
441
		$last_catless = $catless;
442
	}
443
444
	$template->assign_vars(array(
445
		'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $root_data['forum_id'] . '&amp;mark=forums') : '',
446
		'S_HAS_SUBFORUM'	=> ($visible_forums) ? true : false,
447
		'L_SUBFORUM'		=> ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
448
		'LAST_POST_IMG'		=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'))
449
	);
450
451
	if ($return_moderators)
452
	{
453
		return array($active_forum_ary, $forum_moderators);
454
	}
455
456
	return array($active_forum_ary, array());
457
}
458
459
/**
460
* Create forum rules for given forum
461
*/
462
function generate_forum_rules(&$forum_data)
463
{
464
	if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
465
	{
466
		return;
467
	}
468
469
	global $template, $phpbb_root_path, $phpEx;
470
471
	if ($forum_data['forum_rules'])
472
	{
473
		$forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
474
	}
475
476
	$template->assign_vars(array(
477
		'S_FORUM_RULES'	=> true,
478
		'U_FORUM_RULES'	=> $forum_data['forum_rules_link'],
479
		'FORUM_RULES'	=> $forum_data['forum_rules'])
480
	);
481
}
482
483
/**
484
* Create forum navigation links for given forum, create parent
485
* list if currently null, assign basic forum info to template
486
*/
487
function generate_forum_nav(&$forum_data)
488
{
489
	global $db, $user, $template, $auth;
490
	global $phpEx, $phpbb_root_path;
491
492
	if (!$auth->acl_get('f_list', $forum_data['forum_id']))
493
	{
494
		return;
495
	}
496
497
	// Get forum parents
498
	$forum_parents = get_forum_parents($forum_data);
499
500
	// Build navigation links
501
	if (!empty($forum_parents))
502
	{
503
		foreach ($forum_parents as $parent_forum_id => $parent_data)
504
		{
505
			list($parent_name, $parent_type) = array_values($parent_data);
506
507
			// Skip this parent if the user does not have the permission to view it
508
			if (!$auth->acl_get('f_list', $parent_forum_id))
509
			{
510
				continue;
511
			}
512
513
			$template->assign_block_vars('navlinks', array(
514
				'S_IS_CAT'		=> ($parent_type == FORUM_CAT) ? true : false,
515
				'S_IS_LINK'		=> ($parent_type == FORUM_LINK) ? true : false,
516
				'S_IS_POST'		=> ($parent_type == FORUM_POST) ? true : false,
517
				'FORUM_NAME'	=> $parent_name,
518
				'FORUM_ID'		=> $parent_forum_id,
519
				'U_VIEW_FORUM'	=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
520
			);
521
		}
522
	}
523
524
	$template->assign_block_vars('navlinks', array(
525
		'S_IS_CAT'		=> ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
526
		'S_IS_LINK'		=> ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
527
		'S_IS_POST'		=> ($forum_data['forum_type'] == FORUM_POST) ? true : false,
528
		'FORUM_NAME'	=> $forum_data['forum_name'],
529
		'FORUM_ID'		=> $forum_data['forum_id'],
530
		'U_VIEW_FORUM'	=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
531
	);
532
533
	$template->assign_vars(array(
534
		'FORUM_ID' 		=> $forum_data['forum_id'],
535
		'FORUM_NAME'	=> $forum_data['forum_name'],
536
		'FORUM_DESC'	=> generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']))
537
	);
538
539
	return;
540
}
541
542
/**
543
* Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
544
*/
545
function get_forum_parents(&$forum_data)
546
{
547
	global $db;
548
549
	$forum_parents = array();
550
551
	if ($forum_data['parent_id'] > 0)
552
	{
553
		if ($forum_data['forum_parents'] == '')
554
		{
555
			$sql = 'SELECT forum_id, forum_name, forum_type
556
				FROM ' . FORUMS_TABLE . '
557
				WHERE left_id < ' . $forum_data['left_id'] . '
558
					AND right_id > ' . $forum_data['right_id'] . '
559
				ORDER BY left_id ASC';
560
			$result = $db->sql_query($sql);
561
562
			while ($row = $db->sql_fetchrow($result))
563
			{
564
				$forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
565
			}
566
			$db->sql_freeresult($result);
567
568
			$forum_data['forum_parents'] = serialize($forum_parents);
569
570
			$sql = 'UPDATE ' . FORUMS_TABLE . "
571
				SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
572
				WHERE parent_id = " . $forum_data['parent_id'];
573
			$db->sql_query($sql);
574
		}
575
		else
576
		{
577
			$forum_parents = unserialize($forum_data['forum_parents']);
578
		}
579
	}
580
581
	return $forum_parents;
582
}
583
584
/**
585
* Generate topic pagination
586
*/
587
function topic_generate_pagination($replies, $url)
588
{
589
	global $config, $user;
590
591
	// Make sure $per_page is a valid value
592
	$per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
593
594
	if (($replies + 1) > $per_page)
595
	{
596
		$total_pages = ceil(($replies + 1) / $per_page);
597
		$pagination = '';
598
599
		$times = 1;
600
		for ($j = 0; $j < $replies + 1; $j += $per_page)
601
		{
602
			$pagination .= '<a href="' . $url . '&amp;start=' . $j . '">' . $times . '</a>';
603
			if ($times == 1 && $total_pages > 5)
604
			{
605
				$pagination .= ' ... ';
606
607
				// Display the last three pages
608
				$times = $total_pages - 3;
609
				$j += ($total_pages - 4) * $per_page;
610
			}
611
			else if ($times < $total_pages)
612
			{
613
				$pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
614
			}
615
			$times++;
616
		}
617
	}
618
	else
619
	{
620
		$pagination = '';
621
	}
622
623
	return $pagination;
624
}
625
626
/**
627
* Obtain list of moderators of each forum
628
*/
629
function get_moderators(&$forum_moderators, $forum_id = false)
630
{
631
	global $config, $template, $db, $phpbb_root_path, $phpEx;
632
633
	// Have we disabled the display of moderators? If so, then return
634
	// from whence we came ...
635
	if (!$config['load_moderators'])
636
	{
637
		return;
638
	}
639
640
	$forum_sql = '';
641
642
	if ($forum_id !== false)
643
	{
644
		if (!is_array($forum_id))
645
		{
646
			$forum_id = array($forum_id);
647
		}
648
649
		// If we don't have a forum then we can't have a moderator
650
		if (!sizeof($forum_id))
651
		{
652
			return;
653
		}
654
655
		$forum_sql = 'AND m.' . $db->sql_in_set('forum_id', $forum_id);
656
	}
657
658
	$sql_array = array(
659
		'SELECT'	=> 'm.*, u.user_colour, g.group_colour, g.group_type',
660
661
		'FROM'		=> array(
662
			MODERATOR_CACHE_TABLE	=> 'm',
663
		),
664
665
		'LEFT_JOIN'	=> array(
666
			array(
667
				'FROM'	=> array(USERS_TABLE => 'u'),
668
				'ON'	=> 'm.user_id = u.user_id',
669
			),
670
			array(
671
				'FROM'	=> array(GROUPS_TABLE => 'g'),
672
				'ON'	=> 'm.group_id = g.group_id',
673
			),
674
		),
675
676
		'WHERE'		=> "m.display_on_index = 1 $forum_sql",
677
	);
678
679
	$sql = $db->sql_build_query('SELECT', $sql_array);
680
	$result = $db->sql_query($sql, 3600);
681
682
	while ($row = $db->sql_fetchrow($result))
683
	{
684
		if (!empty($row['user_id']))
685
		{
686
			$forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
687
		}
688
		else
689
		{
690
			$forum_moderators[$row['forum_id']][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</a>';
691
		}
692
	}
693
	$db->sql_freeresult($result);
694
695
	return;
696
}
697
698
/**
699
* User authorisation levels output
700
*
701
* @param	string	$mode			Can be forum or topic. Not in use at the moment.
702
* @param	int		$forum_id		The current forum the user is in.
703
* @param	int		$forum_status	The forums status bit.
704
*/
705
function gen_forum_auth_level($mode, $forum_id, $forum_status)
706
{
707
	global $template, $auth, $user, $config;
708
709
	$locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
710
711
	$rules = array(
712
		($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
713
		($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
714
		($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
715
		($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
716
	);
717
718
	if ($config['allow_attachments'])
719
	{
720
		$rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
721
	}
722
723
	foreach ($rules as $rule)
724
	{
725
		$template->assign_block_vars('rules', array('RULE' => $rule));
726
	}
727
728
	return;
729
}
730
731
/**
732
* Generate topic status
733
*/
734
function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
735
{
736
	global $user, $config;
737
738
	$folder = $folder_new = '';
739
740
	if ($topic_row['topic_status'] == ITEM_MOVED)
741
	{
742
		$topic_type = $user->lang['VIEW_TOPIC_MOVED'];
743
		$folder_img = 'topic_moved';
744
		$folder_alt = 'TOPIC_MOVED';
745
	}
746
	else
747
	{
748
		switch ($topic_row['topic_type'])
749
		{
750
			case POST_GLOBAL:
751
				$topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
752
				$folder = 'global_read';
753
				$folder_new = 'global_unread';
754
			break;
755
756
			case POST_ANNOUNCE:
757
				$topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
758
				$folder = 'announce_read';
759
				$folder_new = 'announce_unread';
760
			break;
761
762
			case POST_STICKY:
763
				$topic_type = $user->lang['VIEW_TOPIC_STICKY'];
764
				$folder = 'sticky_read';
765
				$folder_new = 'sticky_unread';
766
			break;
767
768
			default:
769
				$topic_type = '';
770
				$folder = 'topic_read';
771
				$folder_new = 'topic_unread';
772
773
				if ($config['hot_threshold'] && $replies >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
774
				{
775
					$folder .= '_hot';
776
					$folder_new .= '_hot';
777
				}
778
			break;
779
		}
780
781
		if ($topic_row['topic_status'] == ITEM_LOCKED)
782
		{
783
			$topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
784
			$folder .= '_locked';
785
			$folder_new .= '_locked';
786
		}
787
788
789
		$folder_img = ($unread_topic) ? $folder_new : $folder;
790
		$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
791
792
		// Posted image?
793
		if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
794
		{
795
			$folder_img .= '_mine';
796
		}
797
	}
798
799
	if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
800
	{
801
		$topic_type = $user->lang['VIEW_TOPIC_POLL'];
802
	}
803
}
804
805
/**
806
* Assign/Build custom bbcodes for display in screens supporting using of bbcodes
807
* The custom bbcodes buttons will be placed within the template block 'custom_codes'
808
*/
809
function display_custom_bbcodes()
810
{
811
	global $db, $template;
812
813
	// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
814
	$num_predefined_bbcodes = 22;
815
816
	$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
817
		FROM ' . BBCODES_TABLE . '
818
		WHERE display_on_posting = 1
819
		ORDER BY bbcode_tag';
820
	$result = $db->sql_query($sql);
821
822
	$i = 0;
823
	while ($row = $db->sql_fetchrow($result))
824
	{
825
		$template->assign_block_vars('custom_tags', array(
826
			'BBCODE_NAME'		=> "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
827
			'BBCODE_ID'			=> $num_predefined_bbcodes + ($i * 2),
828
			'BBCODE_TAG'		=> $row['bbcode_tag'],
829
			'BBCODE_HELPLINE'	=> $row['bbcode_helpline'],
830
			'A_BBCODE_HELPLINE'	=> str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
831
		));
832
833
		$i++;
834
	}
835
	$db->sql_freeresult($result);
836
}
837
838
/**
839
* Display reasons
840
*/
841
function display_reasons($reason_id = 0)
842
{
843
	global $db, $user, $template;
844
845
	$sql = 'SELECT *
846
		FROM ' . REPORTS_REASONS_TABLE . '
847
		ORDER BY reason_order ASC';
848
	$result = $db->sql_query($sql);
849
850
	while ($row = $db->sql_fetchrow($result))
851
	{
852
		// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
853
		if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
854
		{
855
			$row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
856
			$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
857
		}
858
859
		$template->assign_block_vars('reason', array(
860
			'ID'			=> $row['reason_id'],
861
			'TITLE'			=> $row['reason_title'],
862
			'DESCRIPTION'	=> $row['reason_description'],
863
			'S_SELECTED'	=> ($row['reason_id'] == $reason_id) ? true : false)
864
		);
865
	}
866
	$db->sql_freeresult($result);
867
}
868
869
/**
870
* Display user activity (action forum/topic)
871
*/
872
function display_user_activity(&$userdata)
873
{
874
	global $auth, $template, $db, $user;
875
	global $phpbb_root_path, $phpEx;
876
877
	// Do not display user activity for users having more than 5000 posts...
878
	if ($userdata['user_posts'] > 5000)
879
	{
880
		return;
881
	}
882
883
	$forum_ary = array();
884
885
	// Do not include those forums the user is not having read access to...
886
	$forum_read_ary = $auth->acl_getf('!f_read');
887
888
	foreach ($forum_read_ary as $forum_id => $not_allowed)
889
	{
890
		if ($not_allowed['f_read'])
891
		{
892
			$forum_ary[] = (int) $forum_id;
893
		}
894
	}
895
896
	$forum_ary = array_unique($forum_ary);
897
	$forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
898
899
	// Obtain active forum
900
	$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
901
		FROM ' . POSTS_TABLE . '
902
		WHERE poster_id = ' . $userdata['user_id'] . "
903
			AND post_postcount = 1
904
			$forum_sql
905
		GROUP BY forum_id
906
		ORDER BY num_posts DESC";
907
	$result = $db->sql_query_limit($sql, 1);
908
	$active_f_row = $db->sql_fetchrow($result);
909
	$db->sql_freeresult($result);
910
911
	if (!empty($active_f_row))
912
	{
913
		$sql = 'SELECT forum_name
914
			FROM ' . FORUMS_TABLE . '
915
			WHERE forum_id = ' . $active_f_row['forum_id'];
916
		$result = $db->sql_query($sql, 3600);
917
		$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
918
		$db->sql_freeresult($result);
919
	}
920
921
	// Obtain active topic
922
	$sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
923
		FROM ' . POSTS_TABLE . '
924
		WHERE poster_id = ' . $userdata['user_id'] . "
925
			AND post_postcount = 1
926
			$forum_sql
927
		GROUP BY topic_id
928
		ORDER BY num_posts DESC";
929
	$result = $db->sql_query_limit($sql, 1);
930
	$active_t_row = $db->sql_fetchrow($result);
931
	$db->sql_freeresult($result);
932
933
	if (!empty($active_t_row))
934
	{
935
		$sql = 'SELECT topic_title
936
			FROM ' . TOPICS_TABLE . '
937
			WHERE topic_id = ' . $active_t_row['topic_id'];
938
		$result = $db->sql_query($sql);
939
		$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
940
		$db->sql_freeresult($result);
941
	}
942
943
	$userdata['active_t_row'] = $active_t_row;
944
	$userdata['active_f_row'] = $active_f_row;
945
946
	$active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
947
	if (!empty($active_f_row['num_posts']))
948
	{
949
		$active_f_name = $active_f_row['forum_name'];
950
		$active_f_id = $active_f_row['forum_id'];
951
		$active_f_count = $active_f_row['num_posts'];
952
		$active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
953
	}
954
955
	$active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
956
	if (!empty($active_t_row['num_posts']))
957
	{
958
		$active_t_name = $active_t_row['topic_title'];
959
		$active_t_id = $active_t_row['topic_id'];
960
		$active_t_count = $active_t_row['num_posts'];
961
		$active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
962
	}
963
964
	$l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
965
966
	$template->assign_vars(array(
967
		'ACTIVE_FORUM'			=> $active_f_name,
968
		'ACTIVE_FORUM_POSTS'	=> ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
969
		'ACTIVE_FORUM_PCT'		=> sprintf($l_active_pct, $active_f_pct),
970
		'ACTIVE_TOPIC'			=> censor_text($active_t_name),
971
		'ACTIVE_TOPIC_POSTS'	=> ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
972
		'ACTIVE_TOPIC_PCT'		=> sprintf($l_active_pct, $active_t_pct),
973
		'U_ACTIVE_FORUM'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
974
		'U_ACTIVE_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
975
		'S_SHOW_ACTIVITY'		=> true)
976
	);
977
}
978
979
/**
980
* Topic and forum watching common code
981
*/
982
function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
983
{
984
	global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
985
986
	$table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
987
	$where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
988
	$match_id = ($mode == 'forum') ? $forum_id : $topic_id;
989
990
	$u_url = ($mode == 'forum') ? 'f' : 'f=' . $forum_id . '&amp;t';
991
992
	// Is user watching this thread?
993
	if ($user_id != ANONYMOUS)
994
	{
995
		$can_watch = true;
996
997
		if ($notify_status == 'unset')
998
		{
999
			$sql = "SELECT notify_status
1000
				FROM $table_sql
1001
				WHERE $where_sql = $match_id
1002
					AND user_id = $user_id";
1003
			$result = $db->sql_query($sql);
1004
1005
			$notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1006
			$db->sql_freeresult($result);
1007
		}
1008
1009
		if (!is_null($notify_status) && $notify_status !== '')
1010
		{
1011
			if (isset($_GET['unwatch']))
1012
			{
1013
				if ($_GET['unwatch'] == $mode)
1014
				{
1015
					$is_watching = 0;
1016
1017
					$sql = 'DELETE FROM ' . $table_sql . "
1018
						WHERE $where_sql = $match_id
1019
							AND user_id = $user_id";
1020
					$db->sql_query($sql);
1021
				}
1022
1023
				$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1024
1025
				meta_refresh(3, $redirect_url);
1026
1027
				$message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1028
				trigger_error($message);
1029
			}
1030
			else
1031
			{
1032
				$is_watching = true;
1033
1034
				if ($notify_status)
1035
				{
1036
					$sql = 'UPDATE ' . $table_sql . "
1037
						SET notify_status = 0
1038
						WHERE $where_sql = $match_id
1039
							AND user_id = $user_id";
1040
					$db->sql_query($sql);
1041
				}
1042
			}
1043
		}
1044
		else
1045
		{
1046
			if (isset($_GET['watch']))
1047
			{
1048
				if ($_GET['watch'] == $mode)
1049
				{
1050
					$is_watching = true;
1051
1052
					$sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1053
						VALUES ($user_id, $match_id, 0)";
1054
					$db->sql_query($sql);
1055
				}
1056
1057
				$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1058
				meta_refresh(3, $redirect_url);
1059
1060
				$message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1061
				trigger_error($message);
1062
			}
1063
			else
1064
			{
1065
				$is_watching = 0;
1066
			}
1067
		}
1068
	}
1069
	else
1070
	{
1071
		if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
1072
		{
1073
			login_box();
1074
		}
1075
		else
1076
		{
1077
			$can_watch = 0;
1078
			$is_watching = 0;
1079
		}
1080
	}
1081
1082
	if ($can_watch)
1083
	{
1084
		$s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start");
1085
		$s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1086
		$s_watching['is_watching'] = $is_watching;
1087
	}
1088
1089
	return;
1090
}
1091
1092
/**
1093
* Get user rank title and image
1094
*
1095
* @param int $user_rank the current stored users rank id
1096
* @param int $user_posts the users number of posts
1097
* @param string &$rank_title the rank title will be stored here after execution
1098
* @param string &$rank_img the rank image as full img tag is stored here after execution
1099
* @param string &$rank_img_src the rank image source is stored here after execution
1100
*
1101
*/
1102
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1103
{
1104
	global $ranks, $config;
1105
1106
	if (empty($ranks))
1107
	{
1108
		global $cache;
1109
		$ranks = $cache->obtain_ranks();
1110
	}
1111
1112
	if (!empty($user_rank))
1113
	{
1114
		$rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1115
		$rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
1116
		$rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1117
	}
1118
	else
1119
	{
1120
		if (!empty($ranks['normal']))
1121
		{
1122
			foreach ($ranks['normal'] as $rank)
1123
			{
1124
				if ($user_posts >= $rank['rank_min'])
1125
				{
1126
					$rank_title = $rank['rank_title'];
1127
					$rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1128
					$rank_img_src = (!empty($rank['rank_image'])) ? $config['ranks_path'] . '/' . $rank['rank_image'] : '';
1129
					break;
1130
				}
1131
			}
1132
		}
1133
	}
1134
}
1135
1136
/**
1137
* Get user avatar
1138
*
1139
* @param string $avatar Users assigned avatar name
1140
* @param int $avatar_type Type of avatar
1141
* @param string $avatar_width Width of users avatar
1142
* @param string $avatar_height Height of users avatar
1143
* @param string $alt Optional language string for alt tag within image, can be a language key or text
1144
*
1145
* @return string Avatar image
1146
*/
1147
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
1148
{
1149
	global $user, $config, $phpbb_root_path, $phpEx;
1150
1151
	if (empty($avatar) || !$avatar_type)
1152
	{
1153
		return '';
1154
	}
1155
1156
	$avatar_img = '';
1157
1158
	switch ($avatar_type)
1159
	{
1160
		case AVATAR_UPLOAD:
1161
			$avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
1162
		break;
1163
1164
		case AVATAR_GALLERY:
1165
			$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
1166
		break;
1167
	}
1168
1169
	$avatar_img .= $avatar;
1170
	return '<img src="' . $avatar_img . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
1171
}
1172
1173
?>