<%
/**
 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
%>

<c:if test="<%= BlogsEntryPermission.contains(permissionChecker, entry, ActionKeys.VIEW) %>">
	<div class="entry-content">

		<%
		PortletURL showBlogEntryURL = renderResponse.createRenderURL();

		showBlogEntryURL.setParameter("struts_action", "/blogs_aggregator/view_entry");
		showBlogEntryURL.setParameter("entryId", String.valueOf(entry.getEntryId()));

		StringBuilder sb = new StringBuilder();

		sb.append(themeDisplay.getPathMain());
		sb.append("/blogs/find_entry?redirect=");
		sb.append(HttpUtil.encodeURL(currentURL));
		sb.append("&noSuchEntryRedirect=");
		sb.append(HttpUtil.encodeURL(showBlogEntryURL.toString()));
		sb.append("&entryId=");
		sb.append(entry.getEntryId());

		String viewEntryURL = sb.toString();

		sb.append("&showAllEntries=1");

		String viewAllEntriesURL = sb.toString();

		User user2 = UserLocalServiceUtil.getUserById(entry.getUserId());
		%>

		<c:if test='<%= !displayStyle.endsWith("-without-title") %>'>
			<div class="entry-title">
				<a href="<%= viewEntryURL %>"><%= entry.getTitle() %></a>
			</div>

			<div class="entry-author">
				<liferay-ui:message key="written-by" /> <a href="<%= viewAllEntriesURL %>"><%= PortalUtil.getUserName(entry.getUserId(), entry.getUserName()) %></a>, <liferay-ui:message key="on-date" /> <%= dateFormatDateTime.format(entry.getDisplayDate()) %>
			</div>
		</c:if>

		<liferay-ui:tags-summary
			className="<%= BlogsEntry.class.getName() %>"
			classPK="<%= entry.getEntryId() %>"
		/>
	</div>

	<c:if test='<%= !displayStyle.equals("title") %>'>
		<div class="abstract">
			<c:if test='<%= displayStyle.endsWith("-image") %>'>
				<a href="<%= viewAllEntriesURL %>"><img align="left" border="0" hspace="0" src="<%= themeDisplay.getPathImage() %>/user_<%= user2.isFemale() ? "female" : "male" %>_portrait?img_id=<%= user2.getPortraitId() %>&t=<%= ImageServletTokenUtil.getToken(user2.getPortraitId()) %>" width="65" /></a>
			</c:if>
			<c:choose>
				<c:when test='<%= displayStyle.startsWith("abstract") %>'>
					<%= StringUtil.shorten(HtmlUtil.stripHtml(entry.getContent()), 200, StringPool.BLANK) %>
				</c:when>
				<c:when test='<%= displayStyle.startsWith("quote") %>'>
					<span class="quote">
						<a href="<%= viewAllEntriesURL %>">
							&quot;<%= StringUtil.shorten(StringUtil.trim(HtmlUtil.stripHtml(entry.getContent())), 100, StringPool.BLANK) %> ...&quot;

							<span class="nobreak"><liferay-ui:message key="read-more" /> &raquo;</span>
						</a>
					</span>
				</c:when>
				<c:otherwise>
					<%= entry.getContent() %>
				</c:otherwise>
			</c:choose>
		</div>

		<div class="comments">
			<c:choose>
				<c:when test='<%= displayStyle.startsWith("abstract") %>'>
					<a href="<%= viewEntryURL %>"><liferay-ui:message key="read-more" /> &raquo;</a>
				</c:when>
				<c:when test='<%= !displayStyle.startsWith("quote") %>'>

					<%
					long classNameId = PortalUtil.getClassNameId(BlogsEntry.class.getName());

					int messagesCount = MBMessageLocalServiceUtil.getDiscussionMessagesCount(classNameId, entry.getEntryId());
					%>

					<a href="<%= viewEntryURL %>#<portlet:namespace />messageScroll0"><%= messagesCount %> <liferay-ui:message key="comments" /></a>
				</c:when>
			</c:choose>
		</div>
	</c:if>
</c:if>