<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%
boolean showAddEntryButton = BlogsPermission.contains(permissionChecker, scopeGroupId, ActionKeys.ADD_ENTRY);
boolean showPermissionsButton = GroupPermissionUtil.contains(permissionChecker, scopeGroupId, ActionKeys.PERMISSIONS);
boolean showSubscribeButton = BlogsPermission.contains(permissionChecker, scopeGroupId, ActionKeys.SUBSCRIBE);
showSearch = showSearch && !results.isEmpty();
%>

<c:if test="<%= showAddEntryButton || showPermissionsButton || showSearch %>">
	<div class="portlet-toolbar search-form">
		<c:if test="<%= showSearch %>">
			<span class="aui-search-bar">
				<aui:input inlineField="<%= true %>" label="" name="keywords" size="30" title="search-entries" type="text" />

				<aui:button type="submit" value="search" />
			</span>
		</c:if>

		<c:if test="<%= showAddEntryButton %>">
			<portlet:renderURL var="editEntryURL">
				<portlet:param name="struts_action" value="/blogs/edit_entry" />
				<portlet:param name="redirect" value="<%= currentURL %>" />
			</portlet:renderURL>

			<aui:button name="addEntryButton" value="add-blog-entry" onClick="<%= editEntryURL %>" />
		</c:if>

		<c:if test="<%= showPermissionsButton %>">
			<liferay-security:permissionsURL
				modelResource="com.liferay.portlet.blogs"
				modelResourceDescription="<%= HtmlUtil.escape(themeDisplay.getScopeGroupName()) %>"
				resourcePrimKey="<%= String.valueOf(scopeGroupId) %>"
				var="permissionsURL"
			/>

			<aui:button onClick="<%= permissionsURL %>" value="permissions" />
		</c:if>
	</div>
</c:if>

<c:if test="<%= Validator.isNotNull(categoryName) %>">
	<h1 class="entry-title">
		<%= LanguageUtil.format(pageContext, "entries-with-x-x", new String[] {vocabularyName, categoryName}) %>
	</h1>

	<%
	AssetUtil.addPortletBreadcrumbEntries(categoryId, request, portletURL);
	%>

</c:if>

<c:if test="<%= Validator.isNotNull(tagName) %>">
	<h1 class="entry-title">
		<%= HtmlUtil.escape(LanguageUtil.format(pageContext, "entries-with-tag-x", tagName)) %>
	</h1>

	<%
	PortalUtil.addPortletBreadcrumbEntry(request, tagName, currentURL);
	%>

</c:if>

<%
for (Object result : results) {
	BlogsEntry entry = null;

	AssetEntry assetEntry = null;

	if (result instanceof AssetEntry) {
		assetEntry = (AssetEntry)result;

		entry = BlogsEntryLocalServiceUtil.getEntry(assetEntry.getClassPK());

		AssetUtil.addLayoutTags(request, assetEntry.getTags());
	}
	else {
		entry = (BlogsEntry)result;
	}

	request.setAttribute("view_entry_content.jsp-redirect", redirect);

	request.setAttribute("view_entry_content.jsp-searchContainer", searchContainer);

	request.setAttribute("view_entry_content.jsp-entry", entry);

	request.setAttribute("view_entry_content.jsp-assetEntry", assetEntry);
%>

	<liferay-util:include page="/html/portlet/blogs/view_entry_content.jsp" />

<%
}

String rssURL = PortalUtil.getLayoutURL(layout, themeDisplay) + Portal.FRIENDLY_URL_SEPARATOR + "blogs/rss";

if (rssURLParams.length() > 0) {
	rssURL += "?" + rssURLParams.substring(1);
}
%>

<div class="subscribe">
	<liferay-ui:icon
		image="rss"
		label="<%= true %>"
		method="get"
		target="_blank"
		url="<%= rssURL %>"
	/>

	<c:if test="<%= showSubscribeButton %>">
		<c:choose>
			<c:when test="<%= SubscriptionLocalServiceUtil.isSubscribed(company.getCompanyId(), user.getUserId(), BlogsEntry.class.getName(), scopeGroupId) %>">
				<portlet:actionURL var="unsubscribeURL">
					<portlet:param name="struts_action" value="/blogs/edit_entry" />
					<portlet:param name="<%= Constants.CMD %>" value="<%= Constants.UNSUBSCRIBE %>" />
					<portlet:param name="redirect" value="<%= currentURL %>" />
				</portlet:actionURL>

				<liferay-ui:icon
					image="unsubscribe"
					label="<%= true %>"
					url="<%= unsubscribeURL %>"
				/>
			</c:when>
			<c:otherwise>
				<portlet:actionURL var="subscribeURL">
					<portlet:param name="struts_action" value="/blogs/edit_entry" />
					<portlet:param name="<%= Constants.CMD %>" value="<%= Constants.SUBSCRIBE %>" />
					<portlet:param name="redirect" value="<%= currentURL %>" />
				</portlet:actionURL>

				<liferay-ui:icon
					image="subscribe"
					label="<%= true %>"
					url="<%= subscribeURL %>"
				/>
			</c:otherwise>
		</c:choose>
	</c:if>
</div>

<liferay-util:html-top>
	<link href="<%= rssURL %>" rel="alternate" title="RSS" type="application/rss+xml" />
</liferay-util:html-top>

<liferay-ui:search-paginator searchContainer="<%= searchContainer %>" />