- 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
pull/1/head
lulabad 17 years ago
parent f890b039ee
commit 00f5f917de

@ -113,6 +113,7 @@
<input type="submit" name="view" value="Discard" /> <input type="submit" name="view" value="Discard" />
</fieldset> </fieldset>
</form> </form>
#(/mode)# #(/mode)#
#%env/templates/footer.template%# #%env/templates/footer.template%#

@ -223,14 +223,12 @@ public class BlogComments {
prop.put("mode_date", dateString(new Date())); prop.put("mode_date", dateString(new Date()));
prop.putWiki("mode_page", post.get("content", "")); prop.putWiki("mode_page", post.get("content", ""));
prop.put("mode_page-code", post.get("content", "")); prop.put("mode_page-code", post.get("content", ""));
} } else {
else {
// show blog-entry/entries // show blog-entry/entries
prop.put("mode", "0"); //viewing prop.put("mode", "0"); //viewing
if(pagename.equals("blog_default")) { if(pagename.equals("blog_default")) {
prop.put("LOCATION","Blog.html"); prop.put("LOCATION","Blog.html");
} } else {
else {
//show 1 blog entry //show 1 blog entry
prop.put("mode_pageid", page.getKey()); prop.put("mode_pageid", page.getKey());
prop.put("mode_allow_pageid", pagename); prop.put("mode_allow_pageid", pagename);
@ -287,25 +285,25 @@ public class BlogComments {
continue; continue;
prop.put("mode", "0"); prop.put("mode", "0");
prop.put("mode_entries_"+count+"_pageid", entry.key()); prop.put("mode_entries_"+count+"_pageid", entry.getKey());
if(!xml) { if(!xml) {
prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_subject", new String(entry.getSubject(),"UTF-8"));
prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_author", new String(entry.getAuthor(),"UTF-8"));
prop.putWiki("mode_entries_"+count+"_page", entry.page()); prop.putWiki("mode_entries_"+count+"_page", entry.getPage());
} }
else { else {
prop.putHTML("mode_entries_"+count+"_subject", new String(entry.subject(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_subject", new String(entry.getSubject(),"UTF-8"));
prop.putHTML("mode_entries_"+count+"_author", new String(entry.author(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_author", new String(entry.getAuthor(),"UTF-8"));
prop.put("mode_entries_"+count+"_page", entry.page()); prop.put("mode_entries_"+count+"_page", entry.getPage());
prop.put("mode_entries_"+count+"_timestamp", entry.timestamp()); prop.put("mode_entries_"+count+"_timestamp", entry.getTimestamp());
} }
prop.put("mode_entries_"+count+"_date", dateString(entry.date())); prop.put("mode_entries_"+count+"_date", dateString(entry.getDate()));
prop.put("mode_entries_"+count+"_ip", entry.ip()); prop.put("mode_entries_"+count+"_ip", entry.getIp());
if(hasRights) { if(hasRights) {
prop.put("mode_entries_"+count+"_admin", "1"); prop.put("mode_entries_"+count+"_admin", "1");
prop.put("mode_entries_"+count+"_admin_pageid", page.getKey()); prop.put("mode_entries_"+count+"_admin_pageid", page.getKey());
prop.put("mode_entries_"+count+"_admin_commentid", pageid); 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", "1");
prop.put("mode_entries_"+count+"_admin_moderate_pageid", page.getKey()); prop.put("mode_entries_"+count+"_admin_moderate_pageid", page.getKey());
prop.put("mode_entries_"+count+"_admin_moderate_commentid", pageid); prop.put("mode_entries_"+count+"_admin_moderate_commentid", pageid);

@ -107,6 +107,18 @@ public class blogBoard {
public String guessAuthor(String ip) { public String guessAuthor(String ip) {
return wikiBoard.guessAuthor(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<String> comments, String commentMode) { public BlogEntry newEntry(String key, byte[] subject, byte[] author, String ip, Date date, byte[] page, ArrayList<String> comments, String commentMode) {
return new BlogEntry(normalize(key), subject, author, ip, date, page, comments, commentMode); return new BlogEntry(normalize(key), subject, author, ip, date, page, comments, commentMode);
} }

@ -82,21 +82,21 @@ public class blogBoardComments {
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
} }
private kelondroMapObjects datbase = null; private kelondroMapObjects database = null;
public blogBoardComments(File actpath, long preloadTime) { public blogBoardComments(File actpath, long preloadTime) {
new File(actpath.getParent()).mkdir(); new File(actpath.getParent()).mkdir();
if (datbase == null) { if (database == null) {
datbase = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, false, false, false), 500); database = new kelondroMapObjects(new kelondroDyn(actpath, true, true, preloadTime, keyLength, recordSize, '_', kelondroNaturalOrder.naturalOrder, false, false, false), 500);
} }
} }
public int size() { public int size() {
return datbase.size(); return database.size();
} }
public void close() { public void close() {
datbase.close(); database.close();
} }
private static String dateString(Date date) { 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) { public CommentEntry(String nkey, byte[] subject, byte[] author, String ip, Date date, byte[] page) {
record = new HashMap<String, String>(); record = new HashMap<String, String>();
key = nkey;
if (key.length() > keyLength) key = key.substring(0, keyLength); setKey(nkey);
if(date == null) date = new Date(); setDate(date);
record.put("date", dateString(date)); setSubject(subject);
if (subject == null) record.put("subject",""); setAuthor(author);
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject)); setIp(ip);
if (author == null) record.put("author",""); setPage(page);
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));
wikiBoard.setAuthor(ip, new String(author)); wikiBoard.setAuthor(ip, new String(author));
//System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString());
} }
private CommentEntry(String key, HashMap<String, String> record) { private CommentEntry(String key, HashMap<String, String> record) {
@ -157,70 +151,99 @@ public class blogBoardComments {
if (this.record.get("comments")==null) this.record.put("comments", listManager.collection2string(new ArrayList<String>())); if (this.record.get("comments")==null) this.record.put("comments", listManager.collection2string(new ArrayList<String>()));
} }
public String key() { public String getKey() {
return key; return key;
} }
private void setKey(String var) {
public byte[] subject() { key = var;
String m = (String) record.get("subject"); if (key.length() > keyLength)
if (m == null) return new byte[0]; key = var.substring(0, keyLength);
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoardComments.subject()"); }
if (b == null) return "".getBytes(); private void setSubject(byte[] subject) {
return b; 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() {
public Date date() {
try { try {
String c = (String) record.get("date"); String date = (String) record.get("date");
if (c == null) { if (date == null) {
serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard"); serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard");
//System.out.println("DEBUG - ERROR: date field missing in blogBoard");
return new Date(); return new Date();
} }
synchronized (SimpleFormatter) { synchronized (SimpleFormatter) {
return SimpleFormatter.parse(c); return SimpleFormatter.parse(date);
} }
} catch (ParseException e) { } catch (ParseException e) {
return new Date(); return new Date();
} }
} }
public String timestamp() { public String getTimestamp() {
String c = (String) record.get("date"); String timestamp = (String) record.get("date");
if (c == null) { if (timestamp == null) {
serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard"); serverLog.logFinest("Blog", "ERROR: date field missing in blogBoard");
//System.out.println("DEBUG - ERROR: date field missing in blogBoard");
return dateString(new Date()); return dateString(new Date());
} }
return c; return timestamp;
} }
private void setAuthor(byte[] author) {
public byte[] author() { if (author == null)
String m = (String) record.get("author"); record.put("author","");
if (m == null) return new byte[0]; else
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoardComments.author()"); record.put("author", kelondroBase64Order.enhancedCoder.encode(author));
if (b == null) return "".getBytes(); }
return b; public byte[] getAuthor() {
} String author = (String) record.get("author");
if (author == null)
public String ip() { return new byte[0];
String a = (String) record.get("ip"); byte[] author_byte = kelondroBase64Order.enhancedCoder.decode(author, "de.anomic.data.blogBoardComments.author()");
if (a == null) return "127.0.0.1"; if (author_byte == null)
return a; return "".getBytes();
return author_byte;
}
private void setIp(String ip) {
if ((ip == null) || (ip.length() == 0))
ip = "";
record.put("ip", ip);
} }
public String getIp() {
public byte[] page() { String ip = (String) record.get("ip");
String m = (String) record.get("page"); if (ip == null)
if (m == null) return new byte[0]; return "127.0.0.1";
byte[] b = kelondroBase64Order.enhancedCoder.decode(m, "de.anomic.data.blogBoardComments.page()"); return ip;
if (b == null) return "".getBytes(); }
return b; 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() { public boolean isAllowed() {
return (record.get("moderated") != null) && record.get("moderated").equals("true"); return (record.get("moderated") != null) && record.get("moderated").equals("true");
} }
public void allow() { public void allow() {
record.put("moderated", "true"); record.put("moderated", "true");
} }
@ -230,7 +253,7 @@ public class blogBoardComments {
public String write(CommentEntry page) { public String write(CommentEntry page) {
// writes a new page and returns key // writes a new page and returns key
try { try {
datbase.set(page.key, page.record); database.set(page.key, page.record);
return page.key; return page.key;
} catch (IOException e) { } catch (IOException e) {
return null; return null;
@ -239,7 +262,7 @@ public class blogBoardComments {
public CommentEntry read(String key) { public CommentEntry read(String key) {
//System.out.println("DEBUG: read from blogBoardComments"); //System.out.println("DEBUG: read from blogBoardComments");
return read(key, datbase); return read(key, database);
} }
private CommentEntry read(String key, kelondroMapObjects base) { private CommentEntry read(String key, kelondroMapObjects base) {
@ -343,12 +366,12 @@ public class blogBoardComments {
public void delete(String key) { public void delete(String key) {
key = normalize(key); key = normalize(key);
try { try {
datbase.remove(key); database.remove(key);
} catch (IOException e) { } } catch (IOException e) { }
} }
public Iterator<String> keys(boolean up) throws IOException { public Iterator<String> keys(boolean up) throws IOException {
return datbase.keys(up, false); return database.keys(up, false);
} }
} }

Loading…
Cancel
Save