diff --git a/htroot/Blog.html b/htroot/Blog.html index e60d016f4..3db7dca9f 100644 --- a/htroot/Blog.html +++ b/htroot/Blog.html @@ -13,7 +13,7 @@

#[subject]#

#[page]#

- #[date]# | by #[author]# + #[date]# | by #[author]# #(commentsactive)#::| #[comments]# Comments#(/commentsactive)# #(admin)#::| edit - delete#(/admin)#

@@ -43,6 +43,13 @@ You can use Yacy-Wiki Code here.

+
+
+ +
@@ -79,6 +86,13 @@ You can use Yacy-Wiki Code here.

+
+
+ +
diff --git a/htroot/Blog.java b/htroot/Blog.java index aca29e9be..b173ecc58 100644 --- a/htroot/Blog.java +++ b/htroot/Blog.java @@ -49,6 +49,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -122,6 +123,11 @@ public class Blog { } if(hasRights && post.containsKey("delete") && post.get("delete").equals("sure")) { + page = switchboard.blogDB.read(pagename); + Iterator i = page.comments().iterator(); + while(i.hasNext()) { + switchboard.blogCommentDB.delete((String) i.next()); + } switchboard.blogDB.delete(pagename); pagename = "blog_default"; } @@ -136,15 +142,17 @@ public class Blog { } Date date = null; + ArrayList comments = null; //set name for new entry or date for old entry if(pagename.equals("blog_default")) pagename = String.valueOf(System.currentTimeMillis()); else { page = switchboard.blogDB.read(pagename); + comments = page.comments(); date = page.date(); } - + String commentMode = post.get("commentMode", "1"); String StrSubject = post.get("subject", ""); byte[] subject; try { @@ -153,7 +161,7 @@ public class Blog { subject = StrSubject.getBytes(); } - switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, subject, author, ip, date, content)); + switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, subject, author, ip, date, content, comments, commentMode)); // create a news message HashMap map = new HashMap(); @@ -169,7 +177,8 @@ public class Blog { //edit an entry if(hasRights) { try { - prop.put("mode", 1); //edit + prop.put("mode", 1); //edit + prop.put("mode_commentMode", page.getCommentMode()); prop.put("mode_author", new String(page.author(),"UTF-8")); prop.put("mode_pageid", page.key()); prop.put("mode_subject", new String(page.subject(), "UTF-8")); @@ -184,6 +193,7 @@ public class Blog { //preview the page if(hasRights) { prop.put("mode", 2);//preview + prop.put("mode_commentMode", Integer.parseInt(post.get("commentMode", "1"))); prop.put("mode_pageid", pagename); try { prop.put("mode_author", new String(author, "UTF-8")); @@ -259,7 +269,7 @@ public class Blog { } else { prop.put("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); - prop.put("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); + prop.put("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); prop.putASIS("mode_entries_"+count+"_page", entry.page()); prop.put("mode_entries_"+count+"_timestamp", entry.timestamp()); } @@ -270,6 +280,13 @@ public class Blog { prop.put("mode_entries_"+count+"_admin_pageid",entry.key()); } else prop.put("mode_entries_"+count+"_admin", 0); + if(entry.getCommentMode() != 0) { + prop.put("mode_entries_"+count+"_commentsactive", 1); + prop.put("mode_entries_"+count+"_commentsactive_pageid",entry.key()); + prop.put("mode_entries_"+count+"_commentsactive_comments", new String(entry.commentsSize(),"UTF-8")); + } + else prop.put("mode_entries_"+count+"_commentsactive", 0); + ++count; } prop.put("mode_entries",count); @@ -297,6 +314,12 @@ public class Blog { } catch (UnsupportedEncodingException e) { prop.put("mode_entries_0_author", new String(page.author())); } + try { + prop.put("mode_entries_0_comments", new String(page.commentsSize(),"UTF-8")); + } catch (UnsupportedEncodingException e) { + prop.put("mode_entries_0_comments", new String(page.commentsSize())); + } + prop.put("mode_entries_0_date", dateString(page.date())); prop.putWiki("mode_entries_0_page", page.page()); if(hasRights) { diff --git a/htroot/env/base.css b/htroot/env/base.css index f798c3aec..d7413cf1b 100644 --- a/htroot/env/base.css +++ b/htroot/env/base.css @@ -148,6 +148,13 @@ tt, *.tt { margin-bottom:10px; } +.BlogCommentPost { + padding:10px; + padding-left:50px; + padding-right:50px; + margin-bottom:10px; +} + .PostSubject { padding:5px; margin:0; diff --git a/source/de/anomic/data/blogBoard.java b/source/de/anomic/data/blogBoard.java index 392dd11ed..97db40be4 100644 --- a/source/de/anomic/data/blogBoard.java +++ b/source/de/anomic/data/blogBoard.java @@ -49,6 +49,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; @@ -133,8 +134,8 @@ public class blogBoard { return wikiBoard.guessAuthor(ip); } - public entry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page) { - return new entry(normalize(key), subject, author, ip, date, page); + public entry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList comments, String commentMode) { + return new entry(normalize(key), subject, author, ip, date, page, comments, commentMode); } public class entry { @@ -142,7 +143,7 @@ public class blogBoard { String key; Map record; - public entry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page) { + public entry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList comments, String commentMode) { record = new HashMap(); key = nkey; if (key.length() > keyLength) key = key.substring(0, keyLength); @@ -154,8 +155,12 @@ public class blogBoard { else record.put("author", kelondroBase64Order.enhancedCoder.encode(author)); if ((ip == null) || (ip.length() == 0)) ip = ""; record.put("ip", ip); - if (page == null) record.put("page", ""); - else record.put("page", kelondroBase64Order.enhancedCoder.encode(page)); + if (page == null) record.put("page", ""); + else record.put("page", kelondroBase64Order.enhancedCoder.encode(page)); + if (comments == null) record.put("comments", listManager.arraylist2string(new ArrayList())); + else record.put("comments", listManager.arraylist2string(comments)); + if (commentMode == null) record.put("commentMode", "1"); + else record.put("commentMode", commentMode); wikiBoard.setAuthor(ip, new String(author)); //System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString()); @@ -164,6 +169,8 @@ public class blogBoard { private entry(String key, Map record) { this.key = key; this.record = record; + if (this.record.get("comments")==null) this.record.put("comments", listManager.arraylist2string(new ArrayList())); + if (this.record.get("commentMode")==null || this.record.get("commentMode").equals("")) this.record.put("commentMode", "1"); } public String key() { @@ -200,14 +207,28 @@ public class blogBoard { return c; } - public byte[] author() { - String m = (String) record.get("author"); - if (m == null) return new byte[0]; - byte[] b = kelondroBase64Order.enhancedCoder.decode(m); - if (b == null) return "".getBytes(); - return b; - } - + public byte[] author() { + String m = (String) record.get("author"); + if (m == null) return new byte[0]; + byte[] b = kelondroBase64Order.enhancedCoder.decode(m); + if (b == null) return "".getBytes(); + return b; + } + + public byte[] commentsSize() { + ArrayList m = listManager.string2arraylist((String) record.get("comments")); + if (m == null) return new byte[0]; + byte[] b = Integer.toString(m.size()).getBytes(); + if (b == null) return "".getBytes(); + return b; + } + + public ArrayList comments() { + ArrayList m = listManager.string2arraylist((String) record.get("comments")); + if (m == null) return new ArrayList(); + return m; + } + public String ip() { String a = (String) record.get("ip"); if (a == null) return "127.0.0.1"; @@ -222,6 +243,22 @@ public class blogBoard { return b; } + public void addComment(String commentID) { + ArrayList comments = listManager.string2arraylist((String) record.get("comments")); + comments.add(commentID); + record.put("comments", listManager.arraylist2string(comments)); + } + + public boolean removeComment(String commentID) { + ArrayList comments = listManager.string2arraylist((String) record.get("comments")); + boolean success = comments.remove(commentID); + record.put("comments", listManager.arraylist2string(comments)); + return success; + } + + public int getCommentMode(){ + return Integer.parseInt((String) record.get("commentMode")); + } } public String write(entry page) { @@ -242,7 +279,7 @@ public class blogBoard { key = normalize(key); if (key.length() > keyLength) key = key.substring(0, keyLength); Map record = base.getMap(key); - if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes()); + if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes(), null, null); return new entry(key, record); } @@ -318,7 +355,7 @@ public class blogBoard { page = StrPage.getBytes(); } - write (newEntry(key, subject, author, ip, date, page)); + write (newEntry(key, subject, author, ip, date, page, null, null)); } return true; } diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index 7e2d76eca..0608614e6 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -121,6 +121,7 @@ import java.util.Set; import java.util.TreeSet; import de.anomic.data.blogBoard; +import de.anomic.data.blogBoardComments; import de.anomic.data.bookmarksDB; import de.anomic.data.listManager; import de.anomic.data.messageBoard; @@ -216,6 +217,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser public messageBoard messageDB; public wikiBoard wikiDB; public blogBoard blogDB; + public blogBoardComments blogCommentDB; public static plasmaCrawlRobotsTxt robots; public plasmaCrawlProfile profiles; public plasmaCrawlProfile.entry defaultProxyProfile; @@ -784,6 +786,13 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser * @see plasmaSwitchboard#WORK_PATH for the folder this file lies in */ public static final String DBFILE_BLOG = "blog.db"; + /** + *

public static final String DBFILE_BLOGCOMMENTS = "blogComment.db"

+ *

Name of the file containing the database holding all blogComment-entries available on this peer

+ * + * @see plasmaSwitchboard#WORK_PATH for the folder this file lies in + */ + public static final String DBFILE_BLOGCOMMENTS = "blogComment.db"; /** *

public static final String DBFILE_BOOKMARKS = "bookmarks.db"

*

Name of the file containing the database holding all bookmarks available on this peer

@@ -1290,6 +1299,12 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser this.log.logConfig("Loaded Blog DB from file " + blogDbFile.getName() + ", " + this.blogDB.size() + " entries" + ", " + ppRamString(blogDbFile.length()/1024)); + + File blogCommentDbFile = new File(workPath, DBFILE_BLOGCOMMENTS); + this.blogCommentDB = new blogBoardComments(blogCommentDbFile, ramBlog, ramBlog_time); + this.log.logConfig("Loaded Blog-Comment DB from file " + blogCommentDbFile.getName() + + ", " + this.blogCommentDB.size() + " entries" + + ", " + ppRamString(blogCommentDbFile.length()/1024)); } public void initBookmarks(){ this.log.logConfig("Loading Bookmarks DB"); @@ -1575,6 +1590,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser cacheLoader.close(); wikiDB.close(); blogDB.close(); + blogCommentDB.close(); userDB.close(); bookmarksDB.close(); messageDB.close(); @@ -3013,12 +3029,12 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser dhtTransferChunk.incTransferFailedCounter(); int maxChunkFails = (int) getConfigLong(INDEX_DIST_CHUNK_FAILS_MAX, 1); if (dhtTransferChunk.getTransferFailedCounter() >= maxChunkFails) { - System.out.println("DEBUG: " + dhtTransferChunk.getTransferFailedCounter() + " of " + maxChunkFails + " sendings failed for this chunk, aborting!"); + //System.out.println("DEBUG: " + dhtTransferChunk.getTransferFailedCounter() + " of " + maxChunkFails + " sendings failed for this chunk, aborting!"); dhtTransferChunk.setStatus(plasmaDHTChunk.chunkStatus_FAILED); log.logFine("DHT distribution: transfer FAILED"); } else { - System.out.println("DEBUG: " + dhtTransferChunk.getTransferFailedCounter() + " of " + maxChunkFails + " sendings failed for this chunk, retrying!"); + //System.out.println("DEBUG: " + dhtTransferChunk.getTransferFailedCounter() + " of " + maxChunkFails + " sendings failed for this chunk, retrying!"); log.logFine("DHT distribution: transfer FAILED, sending this chunk again"); } return false; @@ -3032,7 +3048,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser // find a list of DHT-peers ArrayList seeds = yacyCore.dhtAgent.getDHTTargets(log, peerCount, 10, dhtChunk.firstContainer().getWordHash(), dhtChunk.lastContainer().getWordHash(), 0.4); if (seeds.size() < peerCount) { - log.logWarning("found not enough (" + seeds.size() + ") peers for distribution"); + log.logWarning("found not enough (" + seeds.size() + ") peers for distribution for dhtchunk [" + dhtChunk.firstContainer().getWordHash() + " .. " + dhtChunk.lastContainer().getWordHash() + "]"); return false; } diff --git a/source/de/anomic/yacy/yacyNewsPool.java b/source/de/anomic/yacy/yacyNewsPool.java index c7a604100..56bc2a389 100644 --- a/source/de/anomic/yacy/yacyNewsPool.java +++ b/source/de/anomic/yacy/yacyNewsPool.java @@ -305,18 +305,18 @@ public class yacyNewsPool { // called if a published news shall be removed yacyNewsRecord record = fromqueue.remove(id); if (record == null) { - System.out.println("DEBUG: record == null"); + //System.out.println("DEBUG: record == null"); return false; } if (toqueue != null) toqueue.push(record); else if ((incomingNews.get(id) == null) && (processedNews.get(id) == null) && (outgoingNews.get(id) == null) && (publishedNews.get(id) == null)){ newsDB.remove(id); - System.out.println("DEBUG: News-ID " + id + " deleted"); + //System.out.println("DEBUG: News-ID " + id + " deleted"); } - if (incomingNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in incomingNews"); - if (processedNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in processedNews"); - if (outgoingNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in outgoingNews"); - if (publishedNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in publishedNews"); + //if (incomingNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in incomingNews"); + //if (processedNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in processedNews"); + //if (outgoingNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in outgoingNews"); + //if (publishedNews.get(id) != null) System.out.println("DEBUG: News-ID " + id + " in publishedNews"); return true; }