diff --git a/htroot/Blog.java b/htroot/Blog.java index 3def31d93..31d35951c 100644 --- a/htroot/Blog.java +++ b/htroot/Blog.java @@ -72,6 +72,7 @@ public class Blog { public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { plasmaSwitchboard switchboard = (plasmaSwitchboard) env; serverObjects prop = new serverObjects(); + blogBoard.entry page = null; boolean hasRights = switchboard.verifyAuthentication(header, true); @@ -120,16 +121,22 @@ public class Blog { content = post.get("content", "").getBytes(); } - //set name for new entry + Date date = 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); //must I read it again after submitting? + date = page.date(); + } try { - switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, post.get("subject",""), author, ip, content)); + switchboard.blogDB.write(switchboard.blogDB.newEntry(pagename, post.get("subject",""), author, ip, date, content)); } catch (IOException e) {} } - blogBoard.entry page = switchboard.blogDB.read(pagename); + page = switchboard.blogDB.read(pagename); //maybe "if(page == null)" if (post.containsKey("edit")) { //edit an entry diff --git a/source/de/anomic/data/blogBoard.java b/source/de/anomic/data/blogBoard.java index deb9e050f..c777ae3d5 100644 --- a/source/de/anomic/data/blogBoard.java +++ b/source/de/anomic/data/blogBoard.java @@ -96,10 +96,6 @@ public class blogBoard { public void close() { try {datbase.close();} catch (IOException e) {} } - - private static String dateString() { - return dateString(new GregorianCalendar(GMTTimeZone).getTime()); - } private static String dateString(Date date) { return SimpleFormatter.format(date); @@ -123,8 +119,8 @@ public class blogBoard { return wikiBoard.guessAuthor(ip); } - public entry newEntry(String key, String subject, String author, String ip, byte[] page) throws IOException { - return new entry(normalize(key), subject, author, ip, page); + public entry newEntry(String key, String subject, String author, String ip, Date date, byte[] page) throws IOException { + return new entry(normalize(key), subject, author, ip, date, page); } public class entry { @@ -132,11 +128,12 @@ public class blogBoard { String key; Map record; - public entry(String nkey, String subject, String author, String ip, byte[] page) throws IOException { + public entry(String nkey, String subject, String author, String ip, Date date, byte[] page) throws IOException { record = new HashMap(); key = nkey; if (key.length() > keyLength) key = key.substring(0, keyLength); - record.put("date", dateString()); + if(date == null) date = new GregorianCalendar(GMTTimeZone).getTime(); + record.put("date", dateString(date)); if ((subject == null) || (subject.length() == 0)) subject = ""; record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject.getBytes("UTF-8"))); if ((author == null) || (author.length() == 0)) author = "anonymous"; @@ -215,7 +212,7 @@ public class blogBoard { key = normalize(key); if (key.length() > keyLength) key = key.substring(0, keyLength); Map record = base.get(key); - if (record == null) return newEntry(key, "", "anonymous", "127.0.0.1", "".getBytes()); + if (record == null) return newEntry(key, "", "anonymous", "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes()); return new entry(key, record); } catch (IOException e) { return null;