Show news headings in the /home sidebar when the main news div is hidden

Note: this now refreshes along with the rest of the sidebar, so the news.xml
file is read once every 15s - it may be better to cache the headings somewhere,
though it's debatable whether reading the cache file is better than reading the
news.xml file...
This commit is contained in:
str4d
2012-05-31 09:30:30 +00:00
parent e7c3e07626
commit ef06fc758c
5 changed files with 68 additions and 12 deletions

View File

@ -18,6 +18,45 @@ public class NewsHelper extends ContentHelper {
return super.getContent();
}
/** @since 0.9.1 */
public String getNewsHeadings() {
StringBuilder buf = new StringBuilder(512);
String consoleNonce = System.getProperty("router.consoleNonce");
if (consoleNonce != null) {
// Set up string containing <a> to show news.
String newsUrl = "<a href=\"/?news=1&amp;consoleNonce=" + consoleNonce + "\">";
// Set up title and pre-headings stuff.
buf.append("<h3><a href=\"/configupdate\">").append(_("News & Updates"))
.append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n");
// Get news content.
String newsContent = getContent();
if (newsContent != "") {
buf.append("<ul>\n");
// Parse news content for headings.
int start = newsContent.indexOf("<h3>");
while (start >= 0) {
// Add offset to start:
// 4 - gets rid of <h3>
// 16 - gets rid of the date as well (assuming form "<h3>yyyy-mm-dd: Foobarbaz...")
newsContent = newsContent.substring(start+16, newsContent.length());
int end = newsContent.indexOf("</h3>");
if (end >= 0) {
String heading = newsContent.substring(0, end);
buf.append("<li>").append(heading).append("</li>\n");
}
start = newsContent.indexOf("<h3>");
}
buf.append("</ul>\n");
buf.append(newsUrl).append(Messages.getString("Show news", _context)).append("</a>\n");
} else {
buf.append("<center><i>").append(_("none")).append("</i></center>");
}
// Add post-headings stuff.
buf.append("</div>\n");
}
return buf.toString();
}
/** @since 0.8.12 */
public boolean shouldShowNews() {
return NewsFetcher.getInstance(_context).shouldShowNews();

View File

@ -20,6 +20,11 @@
%>
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<%
java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
%>
<jsp:setProperty name="newshelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
<jsp:useBean class="net.i2p.router.web.ConfigUpdateHelper" id="updatehelper" scope="request" />
<jsp:setProperty name="updatehelper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
@ -33,14 +38,6 @@
<!-- for non-script -->
<%@include file="xhr1.jsi" %>
</div>
<%
if (!newshelper.shouldShowNews()) {
%>
<hr><h3><%=intl._("News")%></h3><hr class="b">
<jsp:getProperty name="updatehelper" property="newsStatus" />
<%
} // !shouldShowNews()
%>
</div>
</div>
@ -48,11 +45,8 @@
<%
if (newshelper.shouldShowNews()) {
java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
%>
<div class="news" id="news">
<jsp:setProperty name="newshelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
<jsp:getProperty name="newshelper" property="content" />
<hr>
<jsp:getProperty name="updatehelper" property="newsStatus" /><br>

View File

@ -17,6 +17,13 @@
<h4><a href="/confignet#help" title="<%=intl._("Help with configuring your firewall and router for optimal I2P performance")%>"><%=intl._("Network")%>:
<jsp:getProperty name="helper" property="reachability" /></a></h4>
<hr>
<%
if (!newshelper.shouldShowNews()) {
%>
<jsp:getProperty name="newshelper" property="newsHeadings" /><hr>
<%
} // !shouldShowNews()
%>
<jsp:getProperty name="helper" property="updateStatus" />
<jsp:getProperty name="helper" property="restartStatus" />
<hr>

View File

@ -11,4 +11,11 @@
%>
<jsp:useBean class="net.i2p.router.web.CSSHelper" id="intl" scope="request" />
<jsp:setProperty name="intl" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<%
java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
%>
<jsp:setProperty name="newshelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
<%@include file="xhr1.jsi" %>

View File

@ -170,6 +170,10 @@ div.routersummary h4 {
line-height: 100%;
}
div.routersummary ul {
text-align: left !important;
}
div.routersummary table {
border: 0;
text-align: center !important;
@ -227,6 +231,11 @@ div routersummary hr:last-child {
margin-bottom: -5px !important;
}
div.newsheadings {
text-align: right;
margin: 0 0 0 10px;
}
div.tunnels {
padding-top: 3px !important;
margin-left: -4px;