(a little test for later merges)
[phpbb.git] / phpBB / includes / functions_display.php
blobcec1becb6e558040981de43e5e35cf7df8a35ccd
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * Display Forums
22 function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
24 global $db, $auth, $user, $template;
25 global $phpbb_root_path, $phpEx, $config;
27 $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
28 $parent_id = $visible_forums = 0;
29 $sql_from = '';
31 // Mark forums read?
32 $mark_read = request_var('mark', '');
34 if ($mark_read == 'all')
36 $mark_read = '';
39 if (!$root_data)
41 if ($mark_read == 'forums')
43 $mark_read = 'all';
46 $root_data = array('forum_id' => 0);
47 $sql_where = '';
49 else
51 $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
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;
57 $sql_array = array(
58 'SELECT' => 'f.*',
59 'FROM' => array(
60 FORUMS_TABLE => 'f'
62 'LEFT_JOIN' => array(),
65 if ($config['load_db_lastread'] && $user->data['is_registered'])
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';
70 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
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();
75 if (!$user->data['is_registered'])
77 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
81 if ($show_active)
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) . "'"
88 $sql_array['SELECT'] .= ', fa.user_id';
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'],
96 'WHERE' => $sql_where,
98 'ORDER_BY' => 'f.left_id',
99 ));
101 $result = $db->sql_query($sql);
103 $forum_tracking_info = array();
104 $branch_root_id = $root_data['forum_id'];
106 // Check for unread global announcements (index page only)
107 $ga_unread = false;
108 if ($root_data['forum_id'] == 0)
110 $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
112 if (!empty($unread_ga_list))
114 $ga_unread = true;
118 while ($row = $db->sql_fetchrow($result))
120 $forum_id = $row['forum_id'];
122 // Mark forums read?
123 if ($mark_read == 'forums' || $mark_read == 'all')
125 if ($auth->acl_get('f_list', $forum_id))
127 $forum_ids[] = $forum_id;
128 continue;
132 // Category with no members
133 if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
135 continue;
138 // Skip branch
139 if (isset($right_id))
141 if ($row['left_id'] < $right_id)
143 continue;
145 unset($right_id);
148 if (!$auth->acl_get('f_list', $forum_id))
150 // if the user does not have permissions to list this forum, skip everything until next branch
151 $right_id = $row['right_id'];
152 continue;
155 $forum_ids[] = $forum_id;
157 if ($config['load_db_lastread'] && $user->data['is_registered'])
159 $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
161 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
163 if (!$user->data['is_registered'])
165 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
167 $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'];
170 // Count the difference of real to public topics, so we can display an information to moderators
171 $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
172 $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
174 // Display active topics from this forum?
175 if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
177 if (!isset($active_forum_ary['forum_topics']))
179 $active_forum_ary['forum_topics'] = 0;
182 if (!isset($active_forum_ary['forum_posts']))
184 $active_forum_ary['forum_posts'] = 0;
187 $active_forum_ary['forum_id'][] = $forum_id;
188 $active_forum_ary['enable_icons'][] = $row['enable_icons'];
189 $active_forum_ary['forum_topics'] += $row['forum_topics'];
190 $active_forum_ary['forum_posts'] += $row['forum_posts'];
192 // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
193 if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
195 $active_forum_ary['exclude_forum_id'][] = $forum_id;
200 if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
202 if ($row['forum_type'] != FORUM_CAT)
204 $forum_ids_moderator[] = (int) $forum_id;
207 // Direct child of current branch
208 $parent_id = $forum_id;
209 $forum_rows[$forum_id] = $row;
211 if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
213 $branch_root_id = $forum_id;
215 $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
216 $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
218 else if ($row['forum_type'] != FORUM_CAT)
220 $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
221 $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
222 $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
223 $subforums[$parent_id][$forum_id]['children'] = array();
225 if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
227 $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
230 if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
232 $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
235 $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
237 // Do not list redirects in LINK Forums as Posts.
238 if ($row['forum_type'] != FORUM_LINK)
240 $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
243 if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
245 $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
246 $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
247 $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
248 $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
249 $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
250 $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
251 $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
255 $db->sql_freeresult($result);
257 // Handle marking posts
258 if ($mark_read == 'forums' || $mark_read == 'all')
260 $redirect = build_url(array('mark', 'hash'));
261 $token = request_var('hash', '');
262 if (check_link_hash($token, 'global'))
264 if ($mark_read == 'all')
266 markread('all');
267 $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
269 else
271 // Add 0 to forums array to mark global announcements correctly
272 $forum_ids[] = 0;
273 markread('topics', $forum_ids);
274 $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
276 meta_refresh(3, $redirect);
277 trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
279 else
281 $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
282 meta_refresh(3, $redirect);
283 trigger_error($message);
288 // Grab moderators ... if necessary
289 if ($display_moderators)
291 if ($return_moderators)
293 $forum_ids_moderator[] = $root_data['forum_id'];
295 get_moderators($forum_moderators, $forum_ids_moderator);
298 // Used to tell whatever we have to create a dummy category or not.
299 $last_catless = true;
300 foreach ($forum_rows as $row)
302 // Empty category
303 if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
305 $template->assign_block_vars('forumrow', array(
306 'S_IS_CAT' => true,
307 'FORUM_ID' => $row['forum_id'],
308 'FORUM_NAME' => $row['forum_name'],
309 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
310 'FORUM_FOLDER_IMG' => '',
311 'FORUM_FOLDER_IMG_SRC' => '',
312 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
313 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
314 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
317 continue;
320 $visible_forums++;
321 $forum_id = $row['forum_id'];
323 $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
325 // Mark the first visible forum on index as unread if there's any unread global announcement
326 if (($forum_id == $forum_ids_moderator[0]) && ($root_data['forum_id'] == 0) && $ga_unread)
328 $forum_unread = true;
331 $folder_image = $folder_alt = $l_subforums = '';
332 $subforums_list = array();
334 // Generate list of subforums if we need to
335 if (isset($subforums[$forum_id]))
337 foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
339 $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
341 if (!$subforum_unread && !empty($subforum_row['children']))
343 foreach ($subforum_row['children'] as $child_id)
345 if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
347 // Once we found an unread child forum, we can drop out of this loop
348 $subforum_unread = true;
349 break;
354 if ($subforum_row['display'] && $subforum_row['name'])
356 $subforums_list[] = array(
357 'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
358 'name' => $subforum_row['name'],
359 'unread' => $subforum_unread,
362 else
364 unset($subforums[$forum_id][$subforum_id]);
367 // If one subforum is unread the forum gets unread too...
368 if ($subforum_unread)
370 $forum_unread = true;
374 $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
375 $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
377 else
379 switch ($row['forum_type'])
381 case FORUM_POST:
382 $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
383 break;
385 case FORUM_LINK:
386 $folder_image = 'forum_link';
387 break;
391 // Which folder should we display?
392 if ($row['forum_status'] == ITEM_LOCKED)
394 $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
395 $folder_alt = 'FORUM_LOCKED';
397 else
399 $folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
402 // Create last post link information, if appropriate
403 if ($row['forum_last_post_id'])
405 $last_post_subject = $row['forum_last_post_subject'];
406 $last_post_time = $user->format_date($row['forum_last_post_time']);
407 $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'];
409 else
411 $last_post_subject = $last_post_time = $last_post_url = '';
414 // Output moderator listing ... if applicable
415 $l_moderator = $moderators_list = '';
416 if ($display_moderators && !empty($forum_moderators[$forum_id]))
418 $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
419 $moderators_list = implode(', ', $forum_moderators[$forum_id]);
422 $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
423 $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
425 $s_subforums_list = array();
426 foreach ($subforums_list as $subforum)
428 $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['NEW_POSTS'] : $user->lang['NO_NEW_POSTS']) . '">' . $subforum['name'] . '</a>';
430 $s_subforums_list = (string) implode(', ', $s_subforums_list);
431 $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
433 if ($row['forum_type'] != FORUM_LINK)
435 $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
437 else
439 // If the forum is a link and we count redirects we need to visit it
440 // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
441 if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
443 $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
445 else
447 $u_viewforum = $row['forum_link'];
451 $template->assign_block_vars('forumrow', array(
452 'S_IS_CAT' => false,
453 'S_NO_CAT' => $catless && !$last_catless,
454 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
455 'S_UNREAD_FORUM' => $forum_unread,
456 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
457 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false,
458 'S_SUBFORUMS' => (sizeof($subforums_list)) ? true : false,
459 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options'])) ? true : false,
461 'FORUM_ID' => $row['forum_id'],
462 'FORUM_NAME' => $row['forum_name'],
463 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
464 'TOPICS' => $row['forum_topics'],
465 $l_post_click_count => $post_click_count,
466 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
467 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
468 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
469 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
470 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
471 'LAST_POST_SUBJECT' => censor_text($last_post_subject),
472 'LAST_POST_TIME' => $last_post_time,
473 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
474 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
475 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
476 'MODERATORS' => $moderators_list,
477 'SUBFORUMS' => $s_subforums_list,
479 'L_SUBFORUM_STR' => $l_subforums,
480 'L_FORUM_FOLDER_ALT' => $folder_alt,
481 'L_MODERATOR_STR' => $l_moderator,
483 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
484 'U_VIEWFORUM' => $u_viewforum,
485 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
486 'U_LAST_POST' => $last_post_url)
489 // Assign subforums loop for style authors
490 foreach ($subforums_list as $subforum)
492 $template->assign_block_vars('forumrow.subforum', array(
493 'U_SUBFORUM' => $subforum['link'],
494 'SUBFORUM_NAME' => $subforum['name'],
495 'S_UNREAD' => $subforum['unread'])
499 $last_catless = $catless;
502 $template->assign_vars(array(
503 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums') : '',
504 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
505 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
506 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
507 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
510 if ($return_moderators)
512 return array($active_forum_ary, $forum_moderators);
515 return array($active_forum_ary, array());
519 * Create forum rules for given forum
521 function generate_forum_rules(&$forum_data)
523 if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
525 return;
528 global $template, $phpbb_root_path, $phpEx;
530 if ($forum_data['forum_rules'])
532 $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']);
535 $template->assign_vars(array(
536 'S_FORUM_RULES' => true,
537 'U_FORUM_RULES' => $forum_data['forum_rules_link'],
538 'FORUM_RULES' => $forum_data['forum_rules'])
543 * Create forum navigation links for given forum, create parent
544 * list if currently null, assign basic forum info to template
546 function generate_forum_nav(&$forum_data)
548 global $db, $user, $template, $auth, $config;
549 global $phpEx, $phpbb_root_path;
551 if (!$auth->acl_get('f_list', $forum_data['forum_id']))
553 return;
556 // Get forum parents
557 $forum_parents = get_forum_parents($forum_data);
559 // Build navigation links
560 if (!empty($forum_parents))
562 foreach ($forum_parents as $parent_forum_id => $parent_data)
564 list($parent_name, $parent_type) = array_values($parent_data);
566 // Skip this parent if the user does not have the permission to view it
567 if (!$auth->acl_get('f_list', $parent_forum_id))
569 continue;
572 $template->assign_block_vars('navlinks', array(
573 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
574 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
575 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
576 'FORUM_NAME' => $parent_name,
577 'FORUM_ID' => $parent_forum_id,
578 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
583 $template->assign_block_vars('navlinks', array(
584 'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
585 'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
586 'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
587 'FORUM_NAME' => $forum_data['forum_name'],
588 'FORUM_ID' => $forum_data['forum_id'],
589 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
592 $template->assign_vars(array(
593 'FORUM_ID' => $forum_data['forum_id'],
594 'FORUM_NAME' => $forum_data['forum_name'],
595 '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']),
597 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false,
600 return;
604 * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
606 function get_forum_parents(&$forum_data)
608 global $db;
610 $forum_parents = array();
612 if ($forum_data['parent_id'] > 0)
614 if ($forum_data['forum_parents'] == '')
616 $sql = 'SELECT forum_id, forum_name, forum_type
617 FROM ' . FORUMS_TABLE . '
618 WHERE left_id < ' . $forum_data['left_id'] . '
619 AND right_id > ' . $forum_data['right_id'] . '
620 ORDER BY left_id ASC';
621 $result = $db->sql_query($sql);
623 while ($row = $db->sql_fetchrow($result))
625 $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
627 $db->sql_freeresult($result);
629 $forum_data['forum_parents'] = serialize($forum_parents);
631 $sql = 'UPDATE ' . FORUMS_TABLE . "
632 SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
633 WHERE parent_id = " . $forum_data['parent_id'];
634 $db->sql_query($sql);
636 else
638 $forum_parents = unserialize($forum_data['forum_parents']);
642 return $forum_parents;
646 * Generate topic pagination
648 function topic_generate_pagination($replies, $url)
650 global $config, $user;
652 // Make sure $per_page is a valid value
653 $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
655 if (($replies + 1) > $per_page)
657 $total_pages = ceil(($replies + 1) / $per_page);
658 $pagination = '';
660 $times = 1;
661 for ($j = 0; $j < $replies + 1; $j += $per_page)
663 $pagination .= '<a href="' . $url . '&amp;start=' . $j . '">' . $times . '</a>';
664 if ($times == 1 && $total_pages > 5)
666 $pagination .= ' ... ';
668 // Display the last three pages
669 $times = $total_pages - 3;
670 $j += ($total_pages - 4) * $per_page;
672 else if ($times < $total_pages)
674 $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
676 $times++;
679 else
681 $pagination = '';
684 return $pagination;
688 * Obtain list of moderators of each forum
690 function get_moderators(&$forum_moderators, $forum_id = false)
692 global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
694 $forum_id_ary = array();
696 if ($forum_id !== false)
698 if (!is_array($forum_id))
700 $forum_id = array($forum_id);
703 // Exchange key/value pair to be able to faster check for the forum id existence
704 $forum_id_ary = array_flip($forum_id);
707 $sql_array = array(
708 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
710 'FROM' => array(
711 MODERATOR_CACHE_TABLE => 'm',
714 'LEFT_JOIN' => array(
715 array(
716 'FROM' => array(USERS_TABLE => 'u'),
717 'ON' => 'm.user_id = u.user_id',
719 array(
720 'FROM' => array(GROUPS_TABLE => 'g'),
721 'ON' => 'm.group_id = g.group_id',
725 'WHERE' => 'm.display_on_index = 1',
728 // We query every forum here because for caching we should not have any parameter.
729 $sql = $db->sql_build_query('SELECT', $sql_array);
730 $result = $db->sql_query($sql, 3600);
732 while ($row = $db->sql_fetchrow($result))
734 $f_id = (int) $row['forum_id'];
736 if (!isset($forum_id_ary[$f_id]))
738 continue;
741 if (!empty($row['user_id']))
743 $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
745 else
747 $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
749 if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
751 $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
753 else
755 $forum_moderators[$f_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']) . '">' . $group_name . '</a>';
759 $db->sql_freeresult($result);
761 return;
765 * User authorisation levels output
767 * @param string $mode Can be forum or topic. Not in use at the moment.
768 * @param int $forum_id The current forum the user is in.
769 * @param int $forum_status The forums status bit.
771 function gen_forum_auth_level($mode, $forum_id, $forum_status)
773 global $template, $auth, $user, $config;
775 $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
777 $rules = array(
778 ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
779 ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
780 ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
781 ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
784 if ($config['allow_attachments'])
786 $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
789 foreach ($rules as $rule)
791 $template->assign_block_vars('rules', array('RULE' => $rule));
794 return;
798 * Generate topic status
800 function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
802 global $user, $config;
804 $folder = $folder_new = '';
806 if ($topic_row['topic_status'] == ITEM_MOVED)
808 $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
809 $folder_img = 'topic_moved';
810 $folder_alt = 'TOPIC_MOVED';
812 else
814 switch ($topic_row['topic_type'])
816 case POST_GLOBAL:
817 $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
818 $folder = 'global_read';
819 $folder_new = 'global_unread';
820 break;
822 case POST_ANNOUNCE:
823 $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
824 $folder = 'announce_read';
825 $folder_new = 'announce_unread';
826 break;
828 case POST_STICKY:
829 $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
830 $folder = 'sticky_read';
831 $folder_new = 'sticky_unread';
832 break;
834 default:
835 $topic_type = '';
836 $folder = 'topic_read';
837 $folder_new = 'topic_unread';
839 // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
840 if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
842 $folder .= '_hot';
843 $folder_new .= '_hot';
845 break;
848 if ($topic_row['topic_status'] == ITEM_LOCKED)
850 $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
851 $folder .= '_locked';
852 $folder_new .= '_locked';
856 $folder_img = ($unread_topic) ? $folder_new : $folder;
857 $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
859 // Posted image?
860 if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
862 $folder_img .= '_mine';
866 if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
868 $topic_type = $user->lang['VIEW_TOPIC_POLL'];
873 * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
874 * The custom bbcodes buttons will be placed within the template block 'custom_codes'
876 function display_custom_bbcodes()
878 global $db, $template, $user;
880 // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
881 $num_predefined_bbcodes = 22;
883 $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
884 FROM ' . BBCODES_TABLE . '
885 WHERE display_on_posting = 1
886 ORDER BY bbcode_tag';
887 $result = $db->sql_query($sql);
889 $i = 0;
890 while ($row = $db->sql_fetchrow($result))
892 // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
893 if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
895 $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
898 $template->assign_block_vars('custom_tags', array(
899 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
900 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
901 'BBCODE_TAG' => $row['bbcode_tag'],
902 'BBCODE_HELPLINE' => $row['bbcode_helpline'],
903 'A_BBCODE_HELPLINE' => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
906 $i++;
908 $db->sql_freeresult($result);
912 * Display reasons
914 function display_reasons($reason_id = 0)
916 global $db, $user, $template;
918 $sql = 'SELECT *
919 FROM ' . REPORTS_REASONS_TABLE . '
920 ORDER BY reason_order ASC';
921 $result = $db->sql_query($sql);
923 while ($row = $db->sql_fetchrow($result))
925 // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
926 if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
928 $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
929 $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
932 $template->assign_block_vars('reason', array(
933 'ID' => $row['reason_id'],
934 'TITLE' => $row['reason_title'],
935 'DESCRIPTION' => $row['reason_description'],
936 'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
939 $db->sql_freeresult($result);
943 * Display user activity (action forum/topic)
945 function display_user_activity(&$userdata)
947 global $auth, $template, $db, $user;
948 global $phpbb_root_path, $phpEx;
950 // Do not display user activity for users having more than 5000 posts...
951 if ($userdata['user_posts'] > 5000)
953 return;
956 $forum_ary = array();
958 // Do not include those forums the user is not having read access to...
959 $forum_read_ary = $auth->acl_getf('!f_read');
961 foreach ($forum_read_ary as $forum_id => $not_allowed)
963 if ($not_allowed['f_read'])
965 $forum_ary[] = (int) $forum_id;
969 $forum_ary = array_unique($forum_ary);
970 $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
972 // Obtain active forum
973 $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
974 FROM ' . POSTS_TABLE . '
975 WHERE poster_id = ' . $userdata['user_id'] . "
976 AND post_postcount = 1
977 $forum_sql
978 GROUP BY forum_id
979 ORDER BY num_posts DESC";
980 $result = $db->sql_query_limit($sql, 1);
981 $active_f_row = $db->sql_fetchrow($result);
982 $db->sql_freeresult($result);
984 if (!empty($active_f_row))
986 $sql = 'SELECT forum_name
987 FROM ' . FORUMS_TABLE . '
988 WHERE forum_id = ' . $active_f_row['forum_id'];
989 $result = $db->sql_query($sql, 3600);
990 $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
991 $db->sql_freeresult($result);
994 // Obtain active topic
995 $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
996 FROM ' . POSTS_TABLE . '
997 WHERE poster_id = ' . $userdata['user_id'] . "
998 AND post_postcount = 1
999 $forum_sql
1000 GROUP BY topic_id
1001 ORDER BY num_posts DESC";
1002 $result = $db->sql_query_limit($sql, 1);
1003 $active_t_row = $db->sql_fetchrow($result);
1004 $db->sql_freeresult($result);
1006 if (!empty($active_t_row))
1008 $sql = 'SELECT topic_title
1009 FROM ' . TOPICS_TABLE . '
1010 WHERE topic_id = ' . $active_t_row['topic_id'];
1011 $result = $db->sql_query($sql);
1012 $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
1013 $db->sql_freeresult($result);
1016 $userdata['active_t_row'] = $active_t_row;
1017 $userdata['active_f_row'] = $active_f_row;
1019 $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
1020 if (!empty($active_f_row['num_posts']))
1022 $active_f_name = $active_f_row['forum_name'];
1023 $active_f_id = $active_f_row['forum_id'];
1024 $active_f_count = $active_f_row['num_posts'];
1025 $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
1028 $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
1029 if (!empty($active_t_row['num_posts']))
1031 $active_t_name = $active_t_row['topic_title'];
1032 $active_t_id = $active_t_row['topic_id'];
1033 $active_t_count = $active_t_row['num_posts'];
1034 $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
1037 $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'];
1039 $template->assign_vars(array(
1040 'ACTIVE_FORUM' => $active_f_name,
1041 'ACTIVE_FORUM_POSTS' => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
1042 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
1043 'ACTIVE_TOPIC' => censor_text($active_t_name),
1044 'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
1045 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
1046 'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
1047 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
1048 'S_SHOW_ACTIVITY' => true)
1053 * Topic and forum watching common code
1055 function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
1057 global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
1059 $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
1060 $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
1061 $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
1062 $u_url = "uid={$user->data['user_id']}";
1063 $u_url .= ($mode == 'forum') ? '&amp;f' : '&amp;f=' . $forum_id . '&amp;t';
1065 // Is user watching this thread?
1066 if ($user_id != ANONYMOUS)
1068 $can_watch = true;
1070 if ($notify_status == 'unset')
1072 $sql = "SELECT notify_status
1073 FROM $table_sql
1074 WHERE $where_sql = $match_id
1075 AND user_id = $user_id";
1076 $result = $db->sql_query($sql);
1078 $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1079 $db->sql_freeresult($result);
1082 if (!is_null($notify_status) && $notify_status !== '')
1085 if (isset($_GET['unwatch']))
1087 $uid = request_var('uid', 0);
1088 if ($uid != $user_id)
1090 $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1091 $message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1092 trigger_error($message);
1094 if ($_GET['unwatch'] == $mode)
1096 $is_watching = 0;
1098 $sql = 'DELETE FROM ' . $table_sql . "
1099 WHERE $where_sql = $match_id
1100 AND user_id = $user_id";
1101 $db->sql_query($sql);
1104 $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1106 meta_refresh(3, $redirect_url);
1108 $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1109 trigger_error($message);
1111 else
1113 $is_watching = true;
1115 if ($notify_status)
1117 $sql = 'UPDATE ' . $table_sql . "
1118 SET notify_status = 0
1119 WHERE $where_sql = $match_id
1120 AND user_id = $user_id";
1121 $db->sql_query($sql);
1125 else
1127 if (isset($_GET['watch']))
1129 $token = request_var('hash', '');
1130 $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1132 if ($_GET['watch'] == $mode && check_link_hash($token, "{$mode}_$match_id"))
1134 $is_watching = true;
1136 $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1137 VALUES ($user_id, $match_id, 0)";
1138 $db->sql_query($sql);
1139 $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1141 else
1143 $message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1146 meta_refresh(3, $redirect_url);
1148 trigger_error($message);
1150 else
1152 $is_watching = 0;
1156 else
1158 if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
1160 login_box();
1162 else
1164 $can_watch = 0;
1165 $is_watching = 0;
1169 if ($can_watch)
1171 $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start&amp;hash=" . generate_link_hash("{$mode}_$match_id"));
1172 $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1173 $s_watching['is_watching'] = $is_watching;
1176 return;
1180 * Get user rank title and image
1182 * @param int $user_rank the current stored users rank id
1183 * @param int $user_posts the users number of posts
1184 * @param string &$rank_title the rank title will be stored here after execution
1185 * @param string &$rank_img the rank image as full img tag is stored here after execution
1186 * @param string &$rank_img_src the rank image source is stored here after execution
1188 * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
1190 function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1192 global $ranks, $config, $phpbb_root_path;
1194 if (empty($ranks))
1196 global $cache;
1197 $ranks = $cache->obtain_ranks();
1200 if (!empty($user_rank))
1202 $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1203 $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
1204 $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1206 else if ($user_posts !== false)
1208 if (!empty($ranks['normal']))
1210 foreach ($ranks['normal'] as $rank)
1212 if ($user_posts >= $rank['rank_min'])
1214 $rank_title = $rank['rank_title'];
1215 $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1216 $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
1217 break;
1225 * Get user avatar
1227 * @param string $avatar Users assigned avatar name
1228 * @param int $avatar_type Type of avatar
1229 * @param string $avatar_width Width of users avatar
1230 * @param string $avatar_height Height of users avatar
1231 * @param string $alt Optional language string for alt tag within image, can be a language key or text
1232 * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
1234 * @return string Avatar image
1236 function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
1238 global $user, $config, $phpbb_root_path, $phpEx;
1240 if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
1242 return '';
1245 $avatar_img = '';
1247 switch ($avatar_type)
1249 case AVATAR_UPLOAD:
1250 if (!$config['allow_avatar_upload'] && !$ignore_config)
1252 return '';
1254 $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
1255 break;
1257 case AVATAR_GALLERY:
1258 if (!$config['allow_avatar_local'] && !$ignore_config)
1260 return '';
1262 $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
1263 break;
1265 case AVATAR_REMOTE:
1266 if (!$config['allow_avatar_remote'] && !$ignore_config)
1268 return '';
1270 break;
1273 $avatar_img .= $avatar;
1274 return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';