From 00f5f917de272c4437be005d3417525f9f8238f3 Mon Sep 17 00:00:00 2001 From: lulabad Date: Tue, 12 Feb 2008 19:17:17 +0000 Subject: [PATCH] - more refactoring to blog - fixed moderate comment bug. see http://forum.yacy-websuche.de/viewtopic.php?f=9&t=860 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4478 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/BlogComments.html | 1 + htroot/BlogComments.java | 28 ++-- source/de/anomic/data/blogBoard.java | 12 ++ source/de/anomic/data/blogBoardComments.java | 147 +++++++++++-------- 4 files changed, 111 insertions(+), 77 deletions(-) diff --git a/htroot/BlogComments.html b/htroot/BlogComments.html index aa79e3283..c7934a85f 100644 --- a/htroot/BlogComments.html +++ b/htroot/BlogComments.html @@ -113,6 +113,7 @@ + #(/mode)# #%env/templates/footer.template%# diff --git a/htroot/BlogComments.java b/htroot/BlogComments.java index f15ca2aea..96b040ab2 100644 --- a/htroot/BlogComments.java +++ b/htroot/BlogComments.java @@ -223,14 +223,12 @@ public class BlogComments { prop.put("mode_date", dateString(new Date())); prop.putWiki("mode_page", post.get("content", "")); prop.put("mode_page-code", post.get("content", "")); - } - else { + } else { // show blog-entry/entries prop.put("mode", "0"); //viewing if(pagename.equals("blog_default")) { prop.put("LOCATION","Blog.html"); - } - else { + } else { //show 1 blog entry prop.put("mode_pageid", page.getKey()); prop.put("mode_allow_pageid", pagename); @@ -287,25 +285,25 @@ public class BlogComments { continue; prop.put("mode", "0"); - prop.put("mode_entries_"+count+"_pageid", entry.key()); + prop.put("mode_entries_"+count+"_pageid", entry.getKey()); if(!xml) { - prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); - prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); - prop.putWiki("mode_entries_"+count+"_page", entry.page()); + prop.putHTML("mode_entries_"+count+"_subject", new String(entry.getSubject(),"UTF-8")); + prop.putHTML("mode_entries_"+count+"_author", new String(entry.getAuthor(),"UTF-8")); + prop.putWiki("mode_entries_"+count+"_page", entry.getPage()); } else { - prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); - prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); - prop.put("mode_entries_"+count+"_page", entry.page()); - prop.put("mode_entries_"+count+"_timestamp", entry.timestamp()); + prop.putHTML("mode_entries_"+count+"_subject", new String(entry.getSubject(),"UTF-8")); + prop.putHTML("mode_entries_"+count+"_author", new String(entry.getAuthor(),"UTF-8")); + prop.put("mode_entries_"+count+"_page", entry.getPage()); + prop.put("mode_entries_"+count+"_timestamp", entry.getTimestamp()); } - prop.put("mode_entries_"+count+"_date", dateString(entry.date())); - prop.put("mode_entries_"+count+"_ip", entry.ip()); + prop.put("mode_entries_"+count+"_date", dateString(entry.getDate())); + prop.put("mode_entries_"+count+"_ip", entry.getIp()); if(hasRights) { prop.put("mode_entries_"+count+"_admin", "1"); prop.put("mode_entries_"+count+"_admin_pageid", page.getKey()); prop.put("mode_entries_"+count+"_admin_commentid", pageid); - if(!entry.isAllowed()) { + if(page.getCommentMode() == 2 && !entry.isAllowed()) { prop.put("mode_entries_"+count+"_admin_moderate", "1"); prop.put("mode_entries_"+count+"_admin_moderate_pageid", page.getKey()); prop.put("mode_entries_"+count+"_admin_moderate_commentid", pageid); diff --git a/source/de/anomic/data/blogBoard.java b/source/de/anomic/data/blogBoard.java index a413c7e18..bceed01e9 100644 --- a/source/de/anomic/data/blogBoard.java +++ b/source/de/anomic/data/blogBoard.java @@ -107,6 +107,18 @@ public class blogBoard { public String guessAuthor(String ip) { return wikiBoard.guessAuthor(ip); } + /** + * Create a new BlogEntry an return it + * @param key + * @param subject + * @param author + * @param ip + * @param date + * @param page the content of the Blogentry + * @param comments + * @param commentMode possible params are: 0 - no comments allowed, 1 - comments allowed, 2 - comments moderated + * @return BlogEntry + */ public BlogEntry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList comments, String commentMode) { return new BlogEntry(normalize(key), subject, author, ip, date, page, comments, commentMode); } diff --git a/source/de/anomic/data/blogBoardComments.java b/source/de/anomic/data/blogBoardComments.java index 98d1eb5e1..e75d1775c 100644 --- a/source/de/anomic/data/blogBoardComments.java +++ b/source/de/anomic/data/blogBoardComments.java @@ -82,21 +82,21 @@ public class blogBoardComments { SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); } - private kelondroMapObjects datbase = null; + private kelondroMapObjects database = null; public blogBoardComments(File actpath, long preloadTime) { new File(actpath.getParent()).mkdir(); - if (datbase == null) { - datbase = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, false, false, false), 500); + if (database == null) { + database = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, false, false, false), 500); } } public int size() { - return datbase.size(); + return database.size(); } public void close() { - datbase.close(); + database.close(); } private static String dateString(Date date) { @@ -134,21 +134,15 @@ public class blogBoardComments { public CommentEntry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page) { record = new HashMap(); - key = nkey; - if (key.length() > keyLength) key = key.substring(0, keyLength); - if(date == null) date = new Date(); - record.put("date", dateString(date)); - if (subject == null) record.put("subject",""); - else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject)); - if (author == null) record.put("author",""); - 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)); + + setKey(nkey); + setDate(date); + setSubject(subject); + setAuthor(author); + setIp(ip); + setPage(page); wikiBoard.setAuthor(ip, new String(author)); - //System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString()); } private CommentEntry(String key, HashMap record) { @@ -157,70 +151,99 @@ public class blogBoardComments { if (this.record.get("comments")==null) this.record.put("comments", listManager.collection2string(new ArrayList())); } - public String key() { + public String getKey() { return key; } - - public byte[] subject() { - String m = (String) record.get("subject"); - if (m == null) return new byte[0]; - byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoardComments.subject()"); - if (b == null) return "".getBytes(); - return b; + private void setKey(String var) { + key = var; + if (key.length() > keyLength) + key = var.substring(0, keyLength); } - - public Date date() { + private void setSubject(byte[] subject) { + if (subject == null) + record.put("subject",""); + else + record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject)); + } + public byte[] getSubject() { + String subject = (String) record.get("subject"); + if (subject == null) return new byte[0]; + byte[] subject_bytes = kelondroBase64Order.enhancedCoder.decode(subject, "de.anomic.data.blogBoardComments.subject()"); + if (subject_bytes == null) return "".getBytes(); + return subject_bytes; + } + private void setDate(Date date) { + if(date == null) + date = new Date(); + record.put("date", dateString(date)); + } + public Date getDate() { try { - String c = (String) record.get("date"); - if (c == null) { + String date = (String) record.get("date"); + if (date == null) { serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard"); - //System.out.println("DEBUG - ERROR: date field missing in blogBoard"); return new Date(); } synchronized (SimpleFormatter) { - return SimpleFormatter.parse(c); + return SimpleFormatter.parse(date); } } catch (ParseException e) { return new Date(); } } - public String timestamp() { - String c = (String) record.get("date"); - if (c == null) { + public String getTimestamp() { + String timestamp = (String) record.get("date"); + if (timestamp == null) { serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard"); - //System.out.println("DEBUG - ERROR: date field missing in blogBoard"); return dateString(new Date()); } - return c; + return timestamp; } - - public byte[] author() { - String m = (String) record.get("author"); - if (m == null) return new byte[0]; - byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoardComments.author()"); - if (b == null) return "".getBytes(); - return b; + private void setAuthor(byte[] author) { + if (author == null) + record.put("author",""); + else + record.put("author", kelondroBase64Order.enhancedCoder.encode(author)); + } + public byte[] getAuthor() { + String author = (String) record.get("author"); + if (author == null) + return new byte[0]; + byte[] author_byte = kelondroBase64Order.enhancedCoder.decode(author, "de.anomic.data.blogBoardComments.author()"); + if (author_byte == null) + return "".getBytes(); + return author_byte; } - - public String ip() { - String a = (String) record.get("ip"); - if (a == null) return "127.0.0.1"; - return a; + private void setIp(String ip) { + if ((ip == null) || (ip.length() == 0)) + ip = ""; + record.put("ip", ip); } - - public byte[] page() { - String m = (String) record.get("page"); - if (m == null) return new byte[0]; - byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoardComments.page()"); - if (b == null) return "".getBytes(); - return b; + public String getIp() { + String ip = (String) record.get("ip"); + if (ip == null) + return "127.0.0.1"; + return ip; + } + private void setPage(byte[] page) { + if (page == null) + record.put("page", ""); + else + record.put("page", kelondroBase64Order.enhancedCoder.encode(page)); + } + public byte[] getPage() { + String page = (String) record.get("page"); + if (page == null) + return new byte[0]; + byte[] page_byte = kelondroBase64Order.enhancedCoder.decode(page, "de.anomic.data.blogBoardComments.page()"); + if (page_byte == null) + return "".getBytes(); + return page_byte; } - public boolean isAllowed() { return (record.get("moderated") != null) && record.get("moderated").equals("true"); } - public void allow() { record.put("moderated", "true"); } @@ -230,7 +253,7 @@ public class blogBoardComments { public String write(CommentEntry page) { // writes a new page and returns key try { - datbase.set(page.key, page.record); + database.set(page.key, page.record); return page.key; } catch (IOException e) { return null; @@ -239,7 +262,7 @@ public class blogBoardComments { public CommentEntry read(String key) { //System.out.println("DEBUG: read from blogBoardComments"); - return read(key, datbase); + return read(key, database); } private CommentEntry read(String key, kelondroMapObjects base) { @@ -343,12 +366,12 @@ public class blogBoardComments { public void delete(String key) { key = normalize(key); try { - datbase.remove(key); + database.remove(key); } catch (IOException e) { } } public Iterator keys(boolean up) throws IOException { - return datbase.keys(up, false); + return database.keys(up, false); } }