Ticket #2212: HomeHelper.diff
File HomeHelper.diff, 10.4 KB (added by , 3 years ago) |
---|
-
apps/routerconsole/java/src/net/i2p/router/web/helpers/HomeHelper.java
# # old_revision [e2b980ab057561d5b60da27fec1fafba568eeea1] # # patch "apps/routerconsole/java/src/net/i2p/router/web/helpers/HomeHelper.java" # from [3e0b492c3ef2d4338464a05a022f18ee319b2c61] # to [b38b203797ffb82fe12c6fcdbc26da5ceaf0346d] # ============================================================
import net.i2p.util.PortMapper; 18 18 import net.i2p.router.web.WebAppStarter; 19 19 import net.i2p.util.PortMapper; 20 20 21 import net.i2p.router.web.CSSHelper; 22 23 21 24 /** 22 25 * For /home and /confighome 23 26 * … … public class HomeHelper extends HelperBa 31 34 static final String PROP_FAVORITES = "routerconsole.favorites"; 32 35 static final String PROP_OLDHOME = "routerconsole.oldHomePage"; 33 36 private static final String PROP_SEARCH = "routerconsole.showSearch"; 37 static final String PROP_NEWTAB = "routerconsole.homeExtLinksToNewTab"; 34 38 35 39 // No commas allowed in text strings! 36 40 static final String DEFAULT_SERVICES = … … public class HomeHelper extends HelperBa 40 44 _x("Configure UI") + S + _x("Select console theme & language & set optional console password").replace("&", "&") + S + "/configui" + S + I + "info/ui.png" + S + 41 45 _x("Customize Home Page") + S + _x("I2P Home Page Configuration") + S + "/confighome" + S + I + "home_page.png" + S + 42 46 _x("Customize Sidebar") + S + _x("Customize the sidebar by adding or removing or repositioning elements") + S + "/configsidebar" + S + I + "info/sidebar.png" + S + 43 _x(" Email") + S + _x("Anonymous webmail client") + S + "/webmail" + S + I + "email.png" + S +47 _x("I2PMail") + S + _x("Anonymous webmail client") + S + "/webmail" + S + I + "email.png" + S + 44 48 _x("Help") + S + _x("I2P Router Help") + S + "/help" + S + I + "support.png" + S + 45 49 _x("Manage Plugins") + S + _x("Install and configure I2P plugins") + S + "/configplugins" + S + I + "plugin.png" + S + 46 50 _x("Router Console") + S + _x("I2P Router Console") + S + "/console" + S + I + "info/console.png" + S + … … public class HomeHelper extends HelperBa 117 121 return getChecked(PROP_OLDHOME); 118 122 } 119 123 124 public boolean homeExtLinksToNewTab() { 125 return _context.getBooleanProperty(PROP_NEWTAB); 126 } 127 120 128 public String getProxyStatus() { 121 129 int port = _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY); 122 130 if (port <= 0) 123 131 return _t("The HTTP proxy is not up"); 124 132 return "<img src=\"http://console.i2p/onepixel.png?" + _context.random().nextInt() + "\"" + 125 " alt=\"" + _t("Your browser is not properly configured to use the HTTP proxy at {0}",126 127 "\">";133 " alt=\"" + _t("Your browser is not properly configured to use the HTTP proxy at {0}", 134 _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST) + ':' + port) + 135 "\">"; 128 136 } 129 137 130 138 private String homeTable(String prop, String dflt, Collection<App> toAdd) { … … public class HomeHelper extends HelperBa 187 195 private String renderApps(Collection<App> apps) { 188 196 String website = _t("Web Server"); 189 197 StringBuilder buf = new StringBuilder(1024); 198 boolean embedApps = _context.getBooleanProperty(CSSHelper.PROP_EMBED_APPS); 190 199 buf.append("<div class=\"appgroup\">"); 191 200 PortMapper pm = _context.portMapper(); 192 201 for (App app : apps) { … … public class HomeHelper extends HelperBa 198 207 continue; 199 208 // fixup eepsite link 200 209 if (sslPort > 0) { 201 url = "https://" + pm.getActualHost(PortMapper.SVC_HTTPS_EEPSITE, "127.0.0.1") + 202 ':' + sslPort + '/'; 210 if (homeExtLinksToNewTab()) { 211 url = "https://" + pm.getActualHost(PortMapper.SVC_HTTPS_EEPSITE, "127.0.0.1") + 212 ':' + sslPort + "/\" target=\"_blank\" class=\"extlink"; 213 } else { 214 url = "https://" + pm.getActualHost(PortMapper.SVC_HTTPS_EEPSITE, "127.0.0.1") + 215 ':' + sslPort + "/"; 216 } 203 217 } else { 204 url = "http://" + pm.getActualHost(PortMapper.SVC_EEPSITE, "127.0.0.1") + 205 ':' + port + '/'; 218 if (homeExtLinksToNewTab()) { 219 url = "http://" + pm.getActualHost(PortMapper.SVC_EEPSITE, "127.0.0.1") + 220 ':' + port + "/\" target=\"_blank\" class=\"extlink"; 221 } else { 222 url = "http://" + pm.getActualHost(PortMapper.SVC_EEPSITE, "127.0.0.1") + 223 ':' + port + "/"; 224 } 206 225 } 207 } else { 208 url = app.url; 209 // check for disabled webapps and other things 210 if (url.equals("/dns")) { 211 if (pm.getPort("susidns") <= 0) 212 continue; 213 } else if (url.equals("/webmail")) { 214 if (pm.getPort("susimail") <= 0) 215 continue; 216 } else if (url.equals("/torrents")) { 217 if (pm.getPort("i2psnark") <= 0) 218 continue; 219 } else if (url.equals("/configplugins")) { 220 if (!PluginStarter.pluginsEnabled(_context)) 221 continue; 226 // if external links set to open in new tab, add class so we can indicate external links with overlay on homepage 227 // plugins need to be manually added 228 } else if (((app.url.contains("webmail") || (app.url.contains("torrents"))) && (!embedApps) && (homeExtLinksToNewTab())) 229 || ((app.url.contains("bote") || (app.url.contains("orchid") || (app.url.contains("BwSchedule")))) && (homeExtLinksToNewTab())) 230 || ((app.url.contains(".i2p")) && (homeExtLinksToNewTab()))) { 231 url = app.url + "\" target=\"_blank\" class=\"extlink"; 232 } else { 233 url = app.url; 234 // check for disabled webapps and other things 235 if (url.equals("/dns")) { 236 if (pm.getPort("susidns") <= 0) 237 continue; 238 } else if (url.equals("/webmail")) { 239 if (pm.getPort("susimail") <= 0) 240 continue; 241 } else if (url.equals("/torrents")) { 242 if (pm.getPort("i2psnark") <= 0) 243 continue; 244 } else if (url.equals("/configplugins")) { 245 if (!PluginStarter.pluginsEnabled(_context)) 246 continue; 247 } 222 248 } 249 buf.append("\n<div class=\"app\" style=\"display: inline-block; text-align: center;\">\n" + 250 "<div class=\"appimg\">" + 251 // usability: add tabindex -1 so we avoid 2 tabs per app 252 "<a href=\"").append(url).append("\" tabindex=\"-1\">" + 253 "<img alt=\"\" title=\"").append(app.desc).append("\" src=\"") 254 .append(app.icon).append("\" style=\"max-width: 32px; max-height: 32px;\"></a>" + 255 "</div>\n" + 256 "<table><tr><td>" + 257 "<div class=\"applabel\">" + 258 "<a href=\"").append(url).append("\" title=\"").append(app.desc).append("\">").append(app.name).append("</a>" + 259 "</div>" + 260 "</td></tr></table>\n" + 261 "</div>"); 223 262 } 224 buf.append("\n<div class=\"app\">\n" + 225 "<div class=\"appimg\">" + 226 // usability: add tabindex -1 so we avoid 2 tabs per app 227 "<a href=\"").append(url).append("\" tabindex=\"-1\">" + 228 "<img alt=\"\" title=\"").append(app.desc).append("\" src=\"").append(app.icon).append("\"></a>" + 229 "</div>\n" + 230 "<table><tr><td>" + 231 "<div class=\"applabel\">" + 232 "<a href=\"").append(url).append("\" title=\"").append(app.desc).append("\">").append(app.name).append("</a>" + 233 "</div>" + 234 "</td></tr></table>\n" + 235 "</div>"); 263 buf.append("</div>\n"); 264 return buf.toString(); 236 265 } 237 buf.append("</div>\n");238 return buf.toString();239 }240 266 241 267 private String renderConfig(Collection<App> apps) { 242 268 StringBuilder buf = new StringBuilder(1024); … … public class HomeHelper extends HelperBa 254 280 .append(app.name) 255 281 .append("\" id=\"") 256 282 .append(app.name) 257 .append("\"></td> <td align=\"center\">");283 .append("\"></td>"); 258 284 if (app.icon != null) { 259 buf.append("<img height=\"16\" alt=\"\" src=\"").append(app.icon).append("\">"); 285 buf.append("<td align=\"center\"><img height=\"16\" alt=\"\" src=\"").append(app.icon).append("\">"); 286 } else { 287 buf.append("<td align=\"center\" class=\"noicon\">"); 260 288 } 261 289 buf.append("</td><td align=\"left\"><label for=\"") 262 290 .append(app.name) … … public class HomeHelper extends HelperBa 267 295 buf.append(url) 268 296 .append("\">"); 269 297 // truncate before escaping 270 if (app.url.length() > 50)271 buf.append(DataHelper.escapeHTML(app.url.substring(0, 48))).append("…");298 if (app.url.length() > 72) 299 buf.append(DataHelper.escapeHTML(app.url.substring(0, 70))).append("…"); 272 300 else 273 301 buf.append(url); 274 302 buf.append("</a></td></tr>\n");