Link both icon and text for tracker and magnet entries in snark torrent info

This commit is contained in:
str4d
2012-07-10 22:48:07 +00:00
parent b48014f8e6
commit 177b6e2d48

View File

@@ -1325,7 +1325,7 @@ public class I2PSnarkServlet extends DefaultServlet {
* @return string or null * @return string or null
* @since 0.8.4 * @since 0.8.4
*/ */
private String getTrackerLink(String announce, byte[] infohash) { private String getTrackerLinkUrl(String announce, byte[] infohash) {
// temporarily hardcoded for postman* and anonymity, requires bytemonsoon patch for lookup by info_hash // temporarily hardcoded for postman* and anonymity, requires bytemonsoon patch for lookup by info_hash
if (announce != null && (announce.startsWith("http://YRgrgTLG") || announce.startsWith("http://8EoJZIKr") || if (announce != null && (announce.startsWith("http://YRgrgTLG") || announce.startsWith("http://8EoJZIKr") ||
announce.startsWith("http://lnQ6yoBT") || announce.startsWith("http://tracker2.postman.i2p/") || announce.startsWith("http://lnQ6yoBT") || announce.startsWith("http://tracker2.postman.i2p/") ||
@@ -1341,15 +1341,29 @@ public class I2PSnarkServlet extends DefaultServlet {
StringBuilder buf = new StringBuilder(128); StringBuilder buf = new StringBuilder(128);
buf.append("<a href=\"").append(baseURL).append("details.php?dllist=1&amp;filelist=1&amp;info_hash=") buf.append("<a href=\"").append(baseURL).append("details.php?dllist=1&amp;filelist=1&amp;info_hash=")
.append(TrackerClient.urlencode(infohash)) .append(TrackerClient.urlencode(infohash))
.append("\" title=\"").append(_("Details at {0} tracker", name)).append("\" target=\"_blank\">" + .append("\" title=\"").append(_("Details at {0} tracker", name)).append("\" target=\"_blank\">");
"<img alt=\"").append(_("Info")).append("\" border=\"0\" src=\"")
.append(_imgPath).append("details.png\"></a>");
return buf.toString(); return buf.toString();
} }
} }
return null; return null;
} }
/**
* @return string or null
* @since 0.8.4
*/
private String getTrackerLink(String announce, byte[] infohash) {
String linkUrl = getTrackerLinkUrl(announce, infohash);
if (linkUrl != null) {
StringBuilder buf = new StringBuilder(128);
buf.append(linkUrl)
.append("<img alt=\"").append(_("Info")).append("\" border=\"0\" src=\"")
.append(_imgPath).append("details.png\"></a>");
return buf.toString();
}
return null;
}
private void writeAddForm(PrintWriter out, HttpServletRequest req) throws IOException { private void writeAddForm(PrintWriter out, HttpServletRequest req) throws IOException {
// display incoming parameter if a GET so links will work // display incoming parameter if a GET so links will work
String newURL = req.getParameter("newURL"); String newURL = req.getParameter("newURL");
@@ -2074,6 +2088,9 @@ public class I2PSnarkServlet extends DefaultServlet {
if (trackerLink != null) if (trackerLink != null)
buf.append(trackerLink).append(' '); buf.append(trackerLink).append(' ');
buf.append("<b>").append(_("Tracker")).append(":</b> "); buf.append("<b>").append(_("Tracker")).append(":</b> ");
String trackerLinkUrl = getTrackerLinkUrl(announce, snark.getInfoHash());
if (trackerLinkUrl != null)
buf.append(trackerLinkUrl);
if (announce.startsWith("http://")) if (announce.startsWith("http://"))
announce = announce.substring(7); announce = announce.substring(7);
int slsh = announce.indexOf('/'); int slsh = announce.indexOf('/');
@@ -2081,15 +2098,19 @@ public class I2PSnarkServlet extends DefaultServlet {
announce = announce.substring(0, slsh); announce = announce.substring(0, slsh);
if (announce.length() > 67) if (announce.length() > 67)
announce = announce.substring(0, 40) + "&hellip;" + announce.substring(announce.length() - 8); announce = announce.substring(0, 40) + "&hellip;" + announce.substring(announce.length() - 8);
buf.append(announce).append("</td></tr>"); buf.append(announce);
if (trackerLinkUrl != null)
buf.append("</a>");
buf.append("</td></tr>");
} }
} }
String hex = I2PSnarkUtil.toHex(snark.getInfoHash()); String hex = I2PSnarkUtil.toHex(snark.getInfoHash());
if (meta == null || !meta.isPrivate()) { if (meta == null || !meta.isPrivate()) {
buf.append("<tr><td>") buf.append("<tr><td><a href=\"")
.append(MAGNET_FULL).append(hex).append("\">")
.append(toImg("magnet", _("Magnet link"))) .append(toImg("magnet", _("Magnet link")))
.append(" <b>Magnet:</b> <a href=\"") .append("</a> <b>Magnet:</b> <a href=\"")
.append(MAGNET_FULL).append(hex).append("\">") .append(MAGNET_FULL).append(hex).append("\">")
.append(MAGNET_FULL).append(hex).append("</a>") .append(MAGNET_FULL).append(hex).append("</a>")
.append("</td></tr>\n"); .append("</td></tr>\n");