Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added supporter page; personal home pages are removed from the surftips, they appear now separately on the supporter page, but only if the peer is also online
orbiter506a5a44de69
diff --git a/htroot/ConfigProfile_p.html b/htroot/ConfigProfile_p.htmlindex bba9ecaff..194088184 100644--- a/htroot/ConfigProfile_p.html+++ b/htroot/ConfigProfile_p.html@@ -25,7 +25,7 @@<dd><input type="text" name="nickname" id="nickname" size="40" maxlength="1000" value="#[nickname]#" /></dd>- <dt><label for="homepage">Homepage</label></dt>+ <dt><label for="homepage">Homepage (appears on every <a href="/Supporter.html">Supporter Page</a> as long as your peer is online)</label></dt><dd><input type="text" name="homepage" id="homepage" size="40" maxlength="1000" value="#[homepage]#" /></dd>@@ -62,8 +62,14 @@<textarea name="comment" id="comment" cols="40" rows="10">#[comment]#</textarea><p class="help">You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.</p></dd>+ </dl>+ <dl>+ <dt> </dt>+ <dd>+ <input type="submit" name="set" value="Save" />+ </dd></dl>- <input type="submit" name="set" value="Save" />+</fieldset></form>#%env/templates/footer.template%#diff --git a/htroot/Supporter.html b/htroot/Supporter.htmlnew file mode 100644index 000000000..bf4005763--- /dev/null+++ b/htroot/Supporter.html@@ -0,0 +1,65 @@+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">+<html xmlns="http://www.w3.org/1999/xhtml">+ <head>+ <title>YaCy '#[clientname]#': Supporter</title>+ <meta name="keywords" content="YaCy P2P peer-to-peer Supporter Social Bookmarking Link Voting" />+ <meta name="description" content="Supporter provided by the YaCy peer-to-peer network using public bookmarks, link votes and crawl start points" />+ <link rel="alternate" type="application/rss+xml" title="YaCy Supporter" href="Supporter.rss" />+ #%env/templates/metas.template%#+ <script type="text/javascript">+ //<![CDATA[+ function pcomment(link) {+ var c = window.prompt("Please enter a comment to your link recommendation. (Your Vote is also considered without a comment.)", "");+ return link + "&comment=" + c;+ }+ //]]>+ </script>+ <script type="text/javascript" src="/js/yacysearch.js"></script>+ </head>+ <body id="Supporter">+ #(display)#+ #%env/templates/simpleheader.template%#+ ::+ #%env/templates/header.template%#+ #(/display)#++ <h2 class="yacy">Supporter</h2>++ #(supporter)#+ Supporter are switched off for users without authorization+ ::+ #{results}#+ <!-- link begin -->+ <div class="searchresults">+ #(authorized)#::+ <div class="urlactions">+ <a href="/Bookmarks.html?edit=#[urlhash]#" class="bookmarklink" title="bookmark"><img src="/env/grafics/empty.gif" title="bookmark" alt="Add to bookmarks" class="bookmarkIcon" /></a>+ #(recommend)#+ <img src="/env/grafics/empty.gif" title="" alt="" class="recommendIcon" />+ <img src="/env/grafics/empty.gif" title="" alt="" class="deleteIcon" />+ ::+ <a href="/Supporter.html?votePositive=#[urlhash]#&refid=#[refid]#&url=#[url]#&title=#[title]#&description=#[description]#&display=#[display]##(showScore)#::&score=true#(/showScore)#" title="positive vote" class="recommendlink" onclick="pcomment(this.href);void(0);"><img src="/env/grafics/empty.gif" title="positive vote" alt="Give positive vote" class="recommendIcon" /></a>+ <a href="/Supporter.html?voteNegative=#[urlhash]#&refid=#[refid]#&display=#[display]##(showScore)#::&score=true#(/showScore)#" title="negative vote" class="deletelink" ><img src="/env/grafics/empty.gif" title="negative vote" alt="Give negative vote" class="deleteIcon" /></a>+ #(/recommend)#+ </div>+ #(/authorized)#+ <h4 class="linktitle"><a href="#[url]#">#[title]#</a></h4>+ <p class="snippet">#[description]#</p>+ </div>+ <!-- link end -->+ #{/results}#+ <p class="afterSupporter">+ ...provided by YaCy peers with an URL in their profile. This shows only URLs from peers that are currently online.<br />+ </p>+ <script type="text/javascript">+ addHover();+ </script>+ #(/supporter)#++ #(display)#+ #%env/templates/simplefooter.template%#+ ::+ #%env/templates/footer.template%#+ #(/display)#+ </body>+</html>diff --git a/htroot/Supporter.java b/htroot/Supporter.javanew file mode 100644index 000000000..bcef7e6c7--- /dev/null+++ b/htroot/Supporter.java@@ -0,0 +1,272 @@+// Supporter.java+// (C) 2007 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// first published 13.6.2007 on http://yacy.net+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $+// $LastChangedRevision: 1986 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+++import java.io.IOException;+import java.net.MalformedURLException;+import java.util.Date;+import java.util.HashMap;+import java.util.Iterator;++import de.anomic.http.httpHeader;+import de.anomic.net.URL;+import de.anomic.plasma.plasmaURL;+import de.anomic.kelondro.kelondroMScoreCluster;+import de.anomic.kelondro.kelondroRow;+import de.anomic.kelondro.kelondroNaturalOrder;+import de.anomic.plasma.plasmaSwitchboard;+import de.anomic.plasma.urlPattern.plasmaURLPattern;+import de.anomic.server.serverObjects;+import de.anomic.server.serverSwitch;+import de.anomic.tools.crypt;+import de.anomic.tools.nxTools;+import de.anomic.yacy.yacyCore;+import de.anomic.yacy.yacyNewsPool;+import de.anomic.yacy.yacyNewsRecord;+import de.anomic.yacy.yacySeed;++public class Supporter {++ public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {+ final plasmaSwitchboard sb = (plasmaSwitchboard) env;+ final serverObjects prop = new serverObjects();++ boolean authenticated = sb.adminAuthenticated(header) >= 2;+ int display = ((post == null) || (!authenticated)) ? 0 : post.getInt("display", 0);+ prop.put("display", display);++ boolean showScore = ((post != null) && (post.containsKey("score")));++ // access control+ boolean publicPage = sb.getConfigBool("publicSurftips", true);+ boolean authorizedAccess = sb.verifyAuthentication(header, false);++ if ((publicPage) || (authorizedAccess)) {++ // read voting+ String hash;+ if ((post != null) && ((hash = post.get("voteNegative", null)) != null)) {+ if (!sb.verifyAuthentication(header, false)) {+ prop.put("AUTHENTICATE", "admin log-in"); // force log-in+ return prop;+ }+ // make new news message with voting+ HashMap map = new HashMap();+ map.put("urlhash", hash);+ map.put("vote", "negative");+ map.put("refid", post.get("refid", ""));+ yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));+ }+ if ((post != null) && ((hash = post.get("votePositive", null)) != null)) {+ if (!sb.verifyAuthentication(header, false)) {+ prop.put("AUTHENTICATE", "admin log-in"); // force log-in+ return prop;+ }+ // make new news message with voting+ HashMap map = new HashMap();+ map.put("urlhash", hash);+ map.put("url", crypt.simpleDecode(post.get("url", ""), null));+ map.put("title", crypt.simpleDecode(post.get("title", ""), null));+ map.put("description", crypt.simpleDecode(post.get("description", ""), null));+ map.put("vote", "positive");+ map.put("refid", post.get("refid", ""));+ map.put("comment", post.get("comment", ""));+ yacyCore.newsPool.publishMyNews(new yacyNewsRecord(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map));+ }++ // create Supporter+ HashMap negativeHashes = new HashMap(); // a mapping from an url hash to Integer (count of votes)+ HashMap positiveHashes = new HashMap(); // a mapping from an url hash to Integer (count of votes)+ accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);+ //accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);+ //accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);+ kelondroMScoreCluster ranking = new kelondroMScoreCluster(); // score cluster for url hashes+ kelondroRow rowdef = new kelondroRow("String url-255, String title-120, String description-120, String refid-" + (yacyCore.universalDateShortPattern.length() + 12), kelondroNaturalOrder.naturalOrder, 0);+ HashMap Supporter = new HashMap(); // a mapping from an url hash to a kelondroRow.Entry with display properties+ accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);+ //accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);+ //accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);++ // read out surftipp array and create property entries+ Iterator k = ranking.scores(false);+ int i = 0;+ kelondroRow.Entry row;+ String url, urlhash, refid, title, description;+ boolean voted;+ while (k.hasNext()) {+ urlhash = (String) k.next();+ if (urlhash == null) continue;++ row = (kelondroRow.Entry) Supporter.get(urlhash);+ if (row == null) continue;++ url = row.getColString(0, null);+ try{+ if(plasmaSwitchboard.urlBlacklist.isListed(plasmaURLPattern.BLACKLIST_SURFTIPS ,new URL(url)))+ continue;+ }catch(MalformedURLException e){continue;};+ title = row.getColString(1,"UTF-8");+ description = row.getColString(2,"UTF-8");+ if ((url == null) || (title == null) || (description == null)) continue;+ refid = row.getColString(3, null);+ voted = false;+ try {+ voted = (yacyCore.newsPool.getSpecific(yacyNewsPool.OUTGOING_DB, yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, "refid", refid) != null) ||+ (yacyCore.newsPool.getSpecific(yacyNewsPool.PUBLISHED_DB, yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, "refid", refid) != null);+ } catch (IOException e) {+ e.printStackTrace();+ }+ prop.put("supporter_results_" + i + "_authorized", (authenticated) ? 1 : 0);+ prop.put("supporter_results_" + i + "_authorized_recommend", (voted) ? 0 : 1);++ prop.put("supporter_results_" + i + "_authorized_recommend_urlhash", urlhash);+ prop.put("supporter_results_" + i + "_authorized_recommend_refid", refid);+ prop.putASIS("supporter_results_" + i + "_authorized_recommend_url", crypt.simpleEncode(url, null, 'b'));+ prop.putASIS("supporter_results_" + i + "_authorized_recommend_title", crypt.simpleEncode(title, null, 'b'));+ prop.putASIS("supporter_results_" + i + "_authorized_recommend_description", crypt.simpleEncode(description, null, 'b'));+ prop.put("supporter_results_" + i + "_authorized_recommend_display", display);+ prop.put("supporter_results_" + i + "_authorized_recommend_showScore", (showScore ? 1 : 0));++ prop.put("supporter_results_" + i + "_authorized_urlhash", urlhash);+ prop.put("supporter_results_" + i + "_url", de.anomic.data.htmlTools.replaceXMLEntities(url));+ prop.put("supporter_results_" + i + "_urlname", nxTools.shortenURLString(url, 60));+ prop.put("supporter_results_" + i + "_urlhash", urlhash);+ prop.put("supporter_results_" + i + "_title", (showScore) ? ("(" + ranking.getScore(urlhash) + ") " + title) : title);+ prop.put("supporter_results_" + i + "_description", description);+ i++;++ if (i >= 50) break;+ }+ prop.put("supporter_results", i);+ prop.put("supporter", 1);+ } else {+ prop.put("supporter", 0);+ }++ return prop;+ }++ private static int timeFactor(Date created) {+ return (int) Math.max(0, 10 - ((System.currentTimeMillis() - created.getTime()) / 24 / 60 / 60 / 1000));+ }++ private static void accumulateVotes(HashMap negativeHashes, HashMap positiveHashes, int dbtype) {+ int maxCount = Math.min(1000, yacyCore.newsPool.size(dbtype));+ yacyNewsRecord record;++ for (int j = 0; j < maxCount; j++) try {+ record = yacyCore.newsPool.get(dbtype, j);+ if (record == null) continue;++ if (record.category().equals(yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD)) {+ String urlhash = record.attribute("urlhash", "");+ String vote = record.attribute("vote", "");+ int factor = ((dbtype == yacyNewsPool.OUTGOING_DB) || (dbtype == yacyNewsPool.PUBLISHED_DB)) ? 2 : 1;+ if (vote.equals("negative")) {+ Integer i = (Integer) negativeHashes.get(urlhash);+ if (i == null) negativeHashes.put(urlhash, new Integer(factor));+ else negativeHashes.put(urlhash, new Integer(i.intValue() + factor));+ }+ if (vote.equals("positive")) {+ Integer i = (Integer) positiveHashes.get(urlhash);+ if (i == null) positiveHashes.put(urlhash, new Integer(factor));+ else positiveHashes.put(urlhash, new Integer(i.intValue() + factor));+ }+ }+ } catch (IOException e) {e.printStackTrace();}+ }++ private static void accumulateSupporter(+ HashMap Supporter, kelondroMScoreCluster ranking, kelondroRow rowdef,+ HashMap negativeHashes, HashMap positiveHashes, int dbtype) {+ int maxCount = Math.min(1000, yacyCore.newsPool.size(dbtype));+ yacyNewsRecord record;+ String url = "", urlhash;+ kelondroRow.Entry entry;+ int score = 0;+ Integer vote;+ yacySeed seed;+ for (int j = 0; j < maxCount; j++) try {+ record = yacyCore.newsPool.get(dbtype, j);+ if (record == null) continue;++ entry = null;+ if ((record.category().equals(yacyNewsPool.CATEGORY_PROFILE_UPDATE)) &&+ ((seed = yacyCore.seedDB.getConnected(record.originator())) != null)) {+ url = record.attribute("homepage", "");+ if (url.length() < 12) continue;+ entry = rowdef.newEntry(new byte[][]{+ url.getBytes(),+ url.getBytes(),+ ("Home Page of " + seed.getName()).getBytes("UTF-8"),+ record.id().getBytes()+ });+ score = 1 + timeFactor(record.created());+ }++ if ((record.category().equals(yacyNewsPool.CATEGORY_PROFILE_BROADCAST)) &&+ ((seed = yacyCore.seedDB.getConnected(record.originator())) != null)) {+ url = record.attribute("homepage", "");+ if (url.length() < 12) continue;+ entry = rowdef.newEntry(new byte[][]{+ url.getBytes(),+ url.getBytes(),+ ("Home Page of " + seed.getName()).getBytes("UTF-8"),+ record.id().getBytes()+ });+ score = 1 + timeFactor(record.created());+ }++ // add/subtract votes and write record+ if (entry != null) {+ urlhash = plasmaURL.urlHash(url);+ if (urlhash == null)+ urlhash=plasmaURL.urlHash("http://"+url);+ if(urlhash==null){+ System.out.println("Supporter: bad url '" + url + "' from news record " + record.toString());+ continue;+ }+ if ((vote = (Integer) negativeHashes.get(urlhash)) != null) {+ score = Math.max(0, score - vote.intValue()); // do not go below zero+ }+ if ((vote = (Integer) positiveHashes.get(urlhash)) != null) {+ score += 2 * vote.intValue();+ }+ // consider double-entries+ if (Supporter.containsKey(urlhash)) {+ ranking.addScore(urlhash, score);+ } else {+ ranking.setScore(urlhash, score);+ Supporter.put(urlhash, entry);+ }+ }++ } catch (IOException e) {e.printStackTrace();}++ }+++}diff --git a/htroot/Surftips.html b/htroot/Surftips.htmlindex 7c45d4c4a..51e866712 100644--- a/htroot/Surftips.html+++ b/htroot/Surftips.html@@ -48,6 +48,12 @@</div><!-- link end -->#{/results}#+ <!-- supporter page (appears like surf tip) -->+ <div class="searchresults">+ <h4 class="linktitle"><a href="/Supporter.html">YaCy Supporters</a></h4>+ <p class="snippet">a list of home pages of yacy users</p>+ </div>+ <!-- supporter page --><p class="aftersurftips">...provided by YaCy peers using public bookmarks, link votes and crawl start points<br />diff --git a/htroot/Surftips.java b/htroot/Surftips.javaindex d9934f468..ab72cbcb3 100644--- a/htroot/Surftips.java+++ b/htroot/Surftips.java@@ -234,18 +234,6 @@ public class Surftips {score = 2 + Math.min(10, intention.length() / 4) + timeFactor(record.created());}- if (record.category().equals(yacyNewsPool.CATEGORY_PROFILE_UPDATE)) {- url = record.attribute("homepage", "");- if (url.length() < 12) continue;- entry = rowdef.newEntry(new byte[][]{- url.getBytes(),- ("Home Page of " + record.attribute("nickname", "")).getBytes("UTF-8"),- ("Profile Update").getBytes("UTF-8"),- record.id().getBytes()- });- score = 1 + timeFactor(record.created());- }-if (record.category().equals(yacyNewsPool.CATEGORY_BOOKMARK_ADD)) {url = record.attribute("url", "");if (url.length() < 12) continue;