Search in sources :

Example 1 with NewsHelper

use of net.i2p.router.web.NewsHelper in project i2p.i2p by i2p.

the class SummaryBarRenderer method renderNewsHeadingsHTML.

/**
 * @since 0.9.1
 */
public String renderNewsHeadingsHTML() {
    if (_helper == null)
        return "";
    NewsHelper newshelper = _helper.getNewsHelper();
    if (newshelper == null || newshelper.shouldShowNews())
        return "";
    StringBuilder buf = new StringBuilder(512);
    String consoleNonce = CSSHelper.getNonce();
    if (consoleNonce != null) {
        // Set up title and pre-headings stuff.
        // buf.append("<h3><a href=\"/configupdate\">")
        buf.append("<h3><a href=\"/news\">").append(_t("News &amp; Updates")).append("</a></h3><hr class=\"b\"><div class=\"sb_newsheadings\">\n");
        // Get news content.
        List<NewsEntry> entries = Collections.emptyList();
        ClientAppManager cmgr = _context.clientAppManager();
        if (cmgr != null) {
            NewsManager nmgr = (NewsManager) cmgr.getRegisteredApp(NewsManager.APP_NAME);
            if (nmgr != null)
                entries = nmgr.getEntries();
        }
        if (!entries.isEmpty()) {
            buf.append("<table>\n");
            DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
            // the router sets the JVM time zone to UTC but saves the original here so we can get it
            fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
            int i = 0;
            // show a min of 1, max of 3, none older than 60 days over min
            final int min = 1;
            final int max = 3;
            for (NewsEntry entry : entries) {
                if (i >= min && entry.updated > 0 && entry.updated < _context.clock().now() - 60 * 24 * 60 * 60 * 1000L)
                    break;
                buf.append("<tr><td><a href=\"/?news=1&amp;consoleNonce=").append(consoleNonce).append("\"");
                if (entry.updated > 0) {
                    Date date = new Date(entry.updated);
                    buf.append(" title=\"").append(_t("Published")).append(": ").append(fmt.format(date)).append("\"");
                }
                buf.append(">");
                buf.append(entry.title).append("</a></td></tr>\n");
                if (++i >= max)
                    break;
            }
            buf.append("</table>\n");
        } else {
            buf.append("<center><i>").append(_t("none")).append("</i></center>");
        }
        // Add post-headings stuff.
        // buf.append("<a href=\"/news\">")
        // .append(_t("Show all news"))
        // .append("</a>\n");
        buf.append("</div>\n");
    }
    return buf.toString();
}
Also used : NewsHelper(net.i2p.router.web.NewsHelper) DateFormat(java.text.DateFormat) NewsManager(net.i2p.router.news.NewsManager) NewsEntry(net.i2p.router.news.NewsEntry) Date(java.util.Date) ClientAppManager(net.i2p.app.ClientAppManager)

Aggregations

DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 ClientAppManager (net.i2p.app.ClientAppManager)1 NewsEntry (net.i2p.router.news.NewsEntry)1 NewsManager (net.i2p.router.news.NewsManager)1 NewsHelper (net.i2p.router.web.NewsHelper)1