blob: 158f789733e3e8565454769d549fcc772406f9ba [file] [log] [blame]
Cheng Tang697ce242014-04-27 16:18:17 +08001<%--
2/**
3 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 2.1 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 */
15--%>
16
17<%
18SyndFeed feed = null;
19
20try {
21 ObjectValuePair ovp = RSSUtil.getFeed(url);
22
23 feed = (SyndFeed)ovp.getValue();
24
25 if (Validator.isNull(title)) {
26 title = feed.getTitle();
27 }
28}
29catch (Exception e) {
30}
31%>
32
33<c:choose>
34 <c:when test="<%= (Validator.isNotNull(url)) && (feed != null) %>">
35 <div class="feed">
36
37 <%
38 String baseURL = null;
39
40 String feedLink = feed.getLink();
41
42 if (Validator.isNull(feedLink) || !HttpUtil.hasDomain(feedLink)) {
43 baseURL = HttpUtil.getProtocol(url).concat(Http.PROTOCOL_DELIMITER).concat(HttpUtil.getDomain(url));
44
45 if (Validator.isNotNull(feedLink)) {
46 feedLink = baseURL.concat(feedLink);
47 }
48 else {
49 feedLink = baseURL;
50 }
51 }
52 else {
53 baseURL = HttpUtil.getProtocol(feedLink).concat(Http.PROTOCOL_DELIMITER).concat(HttpUtil.getDomain(feedLink));
54 }
55
56 Date publishedDate = feed.getPublishedDate();
57 String description = feed.getDescription();
58
59 SyndImage feedImage = feed.getImage();
60
61 String feedImageLink = StringPool.BLANK;
62 String feedImageURL = StringPool.BLANK;
63
64 if (feedImage != null) {
65 feedImageLink = feedImage.getLink();
66
67 if (!HttpUtil.hasDomain(feedImageLink)) {
68 feedImageLink = baseURL + feedImageLink;
69 }
70
71 feedImageURL = feedImage.getUrl();
72
73 if (!HttpUtil.hasDomain(feedImageURL)) {
74 feedImageURL = baseURL + feedImageURL;
75 }
76 }
77 %>
78
79 <c:if test="<%= showFeedTitle %>">
80 <div class="feed-title">
81 <aui:a href="<%= feedLink %>" target="_new"><%= HtmlUtil.escape(title) %></aui:a>
82 </div>
83 </c:if>
84
85 <c:if test="<%= (publishedDate != null) && showFeedPublishedDate %>">
86 <div class="feed-published-date feed-date">
87 <aui:a href="<%= feedLink %>" target="_new"><%= dateFormatDateTime.format(publishedDate) %></aui:a>
88 </div>
89 </c:if>
90
91 <c:if test="<%= Validator.isNotNull(description) && showFeedDescription %>">
92 <div class="feed-description">
93 <%= HtmlUtil.escape(description) %>
94 </div>
95 </c:if>
96
97 <c:if test="<%= (feedImage != null) && showFeedImage %>">
98 <div class="feed-image-<%= feedImageAlignment %>">
99 <aui:a href="<%= feedImageLink %>" target="_new" title="<%= feedImage.getTitle() %>"><img alt="<%= feedImage.getDescription() %>" src="<%= feedImageURL %>" /></aui:a>
100 </div>
101 </c:if>
102
103 <div class="feed-entries">
104
105 <%
106 List entries = feed.getEntries();
107
108 for (int j = 0; j < entries.size(); j++) {
109 SyndEntry entry = (SyndEntry)entries.get(j);
110
111 String entryLink = entry.getLink();
112
113 if (Validator.isNotNull(entryLink) && !HttpUtil.hasDomain(entryLink)) {
114 entryLink = baseURL + entryLink;
115 }
116
117 String author = entry.getAuthor();
118
119 SyndContent content = entry.getDescription();
120
121 List contents = new ArrayList();
122
123 if (content == null) {
124 contents = entry.getContents();
125 }
126 else {
127 contents.add(content);
128 }
129
130 List<SyndEnclosure> enclosures = (List<SyndEnclosure>)entry.getEnclosures();
131
132 String enclosureLink = StringPool.BLANK;
133 String enclosureLinkTitle = entry.getTitle();
134
135 for (SyndEnclosure enclosure : enclosures) {
136 if (Validator.isNotNull(enclosure.getUrl())) {
137 enclosureLink = enclosure.getUrl();
138
139 int pos = enclosureLink.lastIndexOf(StringPool.FORWARD_SLASH);
140
141 if (pos > -1) {
142 enclosureLinkTitle = enclosureLink.substring(pos + 1);
143 }
144 else {
145 enclosureLinkTitle = enclosureLink;
146 }
147
148 break;
149 }
150 }
151 %>
152
153 <div class="feed-entry">
154 <img alt="<%= (windowState.equals(WindowState.MAXIMIZED) || (j < expandedEntriesPerFeed)) ? LanguageUtil.get(pageContext, "collapse") : LanguageUtil.get(pageContext, "expande") %>" class="<portlet:namespace />entry-expander feed-entry-expander" src='<%= themeDisplay.getPathThemeImage() %>/arrows/01_<%= (windowState.equals(WindowState.MAXIMIZED) || (j < expandedEntriesPerFeed)) ? "minus" : "plus" %>.png' />
155
156 <span class="feed-entry-title"><aui:a href="<%= entryLink %>" target="_new"><%= HtmlUtil.escape(entry.getTitle()) %></aui:a></span>
157
158 <div class="feed-entry-content <%= (windowState.equals(WindowState.MAXIMIZED) || (j < expandedEntriesPerFeed)) ? "" : "hide" %>">
159 <c:if test="<%= entry.getPublishedDate() != null %>">
160 <div class="feed-date">
161 <%= dateFormatDateTime.format(entry.getPublishedDate()) %>
162 </div>
163 </c:if>
164
165 <c:if test="<%= showFeedItemAuthor && Validator.isNotNull(author) %>">
166 <span class="feed-entry-author"><%= author %></span>
167 </c:if>
168
169 <c:if test="<%= Validator.isNotNull(enclosureLink) %>">
170 <span class="feed-entry-enclosure"><aui:a href="<%= enclosureLink %>" target="_new"><%= enclosureLinkTitle %></aui:a></span>
171 </c:if>
172
173 <%
174 for (int k = 0; k < contents.size(); k++) {
175 content = (SyndContent)contents.get(k);
176
177 if ((content != null) && Validator.isNotNull(content.getValue())) {
178 String value = StringUtil.replace(
179 content.getValue(),
180 new String[] {
181 "src=\"/",
182 "href=\"/"
183 },
184 new String[] {
185 "src=\"" + baseURL + "/",
186 "href=\"" + baseURL + "/"
187 });
188
189 String sanitizedValue = null;
190
191 try {
192 sanitizedValue = SanitizerUtil.sanitize(company.getCompanyId(), scopeGroupId, user.getUserId(), null, 0, ContentTypes.TEXT_HTML, Sanitizer.MODE_XSS, value, null);
193 }
194 catch (SanitizerException se) {
195 sanitizedValue = StringPool.BLANK;
196 }
197 %>
198
199 <%= sanitizedValue %>
200
201 <%
202 }
203 }
204 %>
205
206 </div>
207 </div>
208
209 <%
210 if ((j + 1) >= entriesPerFeed) {
211 break;
212 }
213 }
214 %>
215
216 </div>
217
218 <c:if test="<%= !last %>">
219 <div class="separator"><!-- --></div>
220 </c:if>
221 </div>
222 </c:when>
223 <c:otherwise>
224 <div class="alert alert-error">
225 <%= LanguageUtil.format(pageContext, "cannot-be-found", HtmlUtil.escape(urls[i]), false) %>
226 </div>
227 </c:otherwise>
228</c:choose>