New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boardindex & Messageindex templates Consistency #5148

Open
SychO9 opened this Issue Nov 17, 2018 · 5 comments

Comments

Projects
None yet
5 participants
@SychO9
Contributor

SychO9 commented Nov 17, 2018

Looking at the Boardindex template and the Messageindex template, you can see that the code outputting the boards list is different.

The first organizes code in functions whereas the second just outputs, perhaps we should group the whole code into a function that outputs the list, load Boardindex template in Messageindex source file and use the same function in its template.

Boardindex

foreach ($category['boards'] as $board)
			{
				echo '
				<div id="board_', $board['id'], '" class="up_contain ', (!empty($board['css_class']) ? $board['css_class'] : ''), '">
					<div class="board_icon">', function_exists('template_bi_' . $board['type'] . '_icon') ? call_user_func('template_bi_' . $board['type'] . '_icon', $board) : template_bi_board_icon($board), '
					</div>
					<div class="info">', function_exists('template_bi_' . $board['type'] . '_info') ? call_user_func('template_bi_' . $board['type'] . '_info', $board) : template_bi_board_info($board);

				// Show some basic information about the number of posts, etc.
				echo '
					</div>
					<div class="board_stats">', function_exists('template_bi_' . $board['type'] . '_stats') ? call_user_func('template_bi_' . $board['type'] . '_stats', $board) : template_bi_board_stats($board), '
					</div>
					<div class="lastpost ',!empty($board['last_post']['id']) ? 'lpr_border' : 'hidden', '">', function_exists('template_bi_' . $board['type'] . '_lastpost') ? call_user_func('template_bi_' . $board['type'] . '_lastpost', $board) : template_bi_board_lastpost($board), '
					</div>';

				// Won't somebody think of the children!
				if (function_exists('template_bi_' . $board['type'] . '_children'))
					call_user_func('template_bi_' . $board['type'] . '_children', $board);
				else
					template_bi_board_children($board);

				echo '
				</div><!-- #board_[id] -->';
			}

Messageindex

foreach ($context['boards'] as $board)
		{
			echo '
		<div id="board_', $board['id'], '" class="up_contain">
			<div class="board_icon">
				<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '" class="board_', $board['board_class'], '"', !empty($board['board_tooltip']) ? ' title="' . $board['board_tooltip'] . '"' : '', '></a>
			</div>
			<div class="info">
				<a class="subject mobile_subject" href="', $board['href'], '" id="b', $board['id'], '">
					', $board['name'], '
					<p class="board_description mobile_display">', $board['description'], '</p>
				</a>';

			// Has it outstanding posts for approval?
			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
				echo '
				<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';

			echo '
				<p class="board_description">', $board['description'], '</p>';

			// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
			if (!empty($board['moderators']) || !empty($board['moderator_groups']))
				echo '
				<p class="moderators">', count($board['link_moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';

			// Show some basic information about the number of posts, etc.
			echo '
			</div><!-- .info -->
			<div class="board_stats centertext">
				<p>', $board['is_redirect'] ? $txt['redirects'] : $txt['posts'], ': ', comma_format($board['posts']), '<br>', $board['is_redirect'] ? '' : $txt['board_topics'] . ': ' . comma_format($board['topics']), '
				</p>
			</div>
			<div class="lastpost ', !empty($board['last_post']['id']) ? 'lpr_border' : 'hidden', '">';

			if (!empty($board['last_post']['id']))
				echo '
				<p>', $board['last_post']['last_post_message'], '</p>';

			echo '
			</div>';

			// Show the "Child Boards: ". (there's a link_children but we're going to bold the new ones...)
			if (!empty($board['children']))
			{
				// Sort the links into an array with new boards bold so it can be imploded.
				$children = array();
				/* Each child in each board's children has:
					id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
				foreach ($board['children'] as $child)
				{
					if (!$child['is_redirect'])
						$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')" class="new_posts">' . $txt['new'] . '</a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
					else
						$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';

					// Has it posts awaiting approval?
					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics']))
						$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';

					$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
				}

			echo '
			<div id="board_', $board['id'], '_children" class="children">
				<p><strong id="child_list_', $board['id'], '">', $txt['sub_boards'], '</strong>', implode($children), '</p>
			</div>';
			}

			echo '
		</div><!-- #board_[id] -->';
		}

If there are no objections I'll make a PR

@SychO9 SychO9 changed the title from Boardindex & Messageindex Consistency to Boardindex & Messageindex templates Consistency Nov 17, 2018

@wintstar

This comment has been minimized.

wintstar commented Nov 17, 2018

The same could be done with the author information in Display.template.php and PersonalMessage.template.php. They are also almost identical. @SychO9 ,please have a look if it's possible too.

@SychO9

This comment has been minimized.

Contributor

SychO9 commented Nov 17, 2018

Hmmmm, actually I'm just gonna have to copy them, forgot I couldn't possibly load two templates because they both use template _main

@Antes

This comment has been minimized.

Contributor

Antes commented Nov 18, 2018

@jdarwood007 can give you proper info. This was made I think for "fake boards" support or something.

@jdarwood007

This comment has been minimized.

Member

jdarwood007 commented Nov 18, 2018

I didn't think of implanting support for it in MessageIndex. But the BoardIndex template was changed to handle things like redirect boards better. It also made it so things like SimpleDesk or portals could inject fake boards or other stuff to change parts of the displays without needing to hack up the templates.

@SychO9

This comment has been minimized.

Contributor

SychO9 commented Nov 19, 2018

Yes that's better indeed, I was just thinking it'd be better to have the codes be the same in both templates, and I thought I could just load the board index template and use the same functions instead of redeclaring them, but I can't so I'm just gonna redeclare them.

@SychO9 SychO9 referenced a pull request that will close this issue Nov 20, 2018

Open

Tidy up Boardindex & Messageindex templates #5155

@live627 live627 added this to the RC 2 milestone Nov 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment