Blog + BlogComments method propose() make similar + fix anonymous poster's IP resolve in Blog

this method share very much common code in both classes,
would be nice to unify
+fix some ugly code

Signed-off-by: Marek Otahal <markotahal@gmail.com>
pull/1/head
Marek Otahal 13 years ago committed by Michael Peter Christen
parent 7189a70a62
commit c1973c78a3

@ -78,11 +78,7 @@ public class Blog {
final boolean xml = (header.get(HeaderFramework.CONNECTION_PROP_PATH)).endsWith(".xml"); final boolean xml = (header.get(HeaderFramework.CONNECTION_PROP_PATH)).endsWith(".xml");
final String address = sb.peers.mySeed().getPublicAddress(); final String address = sb.peers.mySeed().getPublicAddress();
if(hasRights) { prop.put("mode_admin", hasRights ? "1" : "0");
prop.put("mode_admin", "1");
} else {
prop.put("mode_admin", "0");
}
if (post == null) { if (post == null) {
prop.putHTML("peername", sb.peers.mySeed().getName()); prop.putHTML("peername", sb.peers.mySeed().getName());
@ -106,22 +102,22 @@ public class Blog {
String pagename = post.get("page", DEFAULT_PAGE); String pagename = post.get("page", DEFAULT_PAGE);
final String ip = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "127.0.0.1"); final String ip = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "127.0.0.1");
String StrAuthor = post.get("author", ""); String strAuthor = post.get("author", "anonymous");
if ("anonymous".equals(StrAuthor)) { if ("anonymous".equals(strAuthor)) {
StrAuthor = sb.blogDB.guessAuthor(ip); strAuthor = sb.blogDB.guessAuthor(ip);
if (StrAuthor == null || StrAuthor.length() == 0) { if (strAuthor == null || strAuthor.length() == 0) {
if (sb.peers.mySeed() == null) { if (sb.peers.mySeed() == null) {
StrAuthor = "anonymous"; strAuthor = "anonymous";
} else { } else {
StrAuthor = sb.peers.mySeed().get("Name", "anonymous"); strAuthor = sb.peers.mySeed().get("Name", "anonymous");
} }
} }
} }
byte[] author; byte[] author;
author = UTF8.getBytes(StrAuthor); author = UTF8.getBytes(strAuthor);
if (hasRights && post.containsKey("delete") && "sure".equals(post.get("delete"))) { if (hasRights && post.containsKey("delete") && "sure".equals(post.get("delete"))) {
page = sb.blogDB.readBlogEntry(pagename); page = sb.blogDB.readBlogEntry(pagename);
@ -165,7 +161,7 @@ public class Blog {
final Map<String, String> map = new HashMap<String, String>(); final Map<String, String> map = new HashMap<String, String>();
map.put("page", pagename); map.put("page", pagename);
map.put("subject", StrSubject.replace(',', ' ')); map.put("subject", StrSubject.replace(',', ' '));
map.put("author", StrAuthor.replace(',', ' ')); map.put("author", strAuthor.replace(',', ' '));
sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_BLOG_ADD, map); sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_BLOG_ADD, map);
} }
} }

@ -52,6 +52,8 @@ import de.anomic.server.serverSwitch;
public class BlogComments { public class BlogComments {
private static final String DEFAULT_PAGE = "blog_default";
public static String dateString(final Date date) { public static String dateString(final Date date) {
return Blog.dateString(date); return Blog.dateString(date);
} }
@ -72,32 +74,31 @@ public class BlogComments {
final UserDB.Entry userentry = sb.userDB.proxyAuth(header.get(RequestHeader.AUTHORIZATION, "xxxxxx")); final UserDB.Entry userentry = sb.userDB.proxyAuth(header.get(RequestHeader.AUTHORIZATION, "xxxxxx"));
if (userentry != null && userentry.hasRight(UserDB.AccessRight.BLOG_RIGHT)) { if (userentry != null && userentry.hasRight(UserDB.AccessRight.BLOG_RIGHT)) {
hasRights = true; hasRights = true;
} } else if (post.containsKey("login")) {
//opens login window if login link is clicked //opens login window if login link is clicked
else if (post.containsKey("login")) {
prop.put("AUTHENTICATE","admin log-in"); prop.put("AUTHENTICATE","admin log-in");
} }
} }
final String pagename = post.get("page", "blog_default"); String pagename = post.get("page", DEFAULT_PAGE);
final String ip = post.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "127.0.0.1"); final String ip = post.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "127.0.0.1");
String StrAuthor = post.get("author", "anonymous"); String strAuthor = post.get("author", "anonymous");
if ("anonymous".equals(StrAuthor)) { if ("anonymous".equals(strAuthor)) {
StrAuthor = sb.blogDB.guessAuthor(ip); strAuthor = sb.blogDB.guessAuthor(ip);
if (StrAuthor == null || StrAuthor.length() == 0) { if (strAuthor == null || strAuthor.length() == 0) {
if (sb.peers.mySeed() == null) { if (sb.peers.mySeed() == null) {
StrAuthor = "anonymous"; strAuthor = "anonymous";
} else { } else {
StrAuthor = sb.peers.mySeed().get("Name", "anonymous"); strAuthor = sb.peers.mySeed().get("Name", "anonymous");
} }
} }
} }
byte[] author; byte[] author;
author = UTF8.getBytes(StrAuthor); author = UTF8.getBytes(strAuthor);
final BlogBoard.BlogEntry page = sb.blogDB.readBlogEntry(pagename); //maybe "if(page == null)" final BlogBoard.BlogEntry page = sb.blogDB.readBlogEntry(pagename); //maybe "if(page == null)"
final boolean pageExists = sb.blogDB.contains(pagename); final boolean pageExists = sb.blogDB.contains(pagename);
@ -127,13 +128,13 @@ public class BlogComments {
sb.blogCommentDB.write(sb.blogCommentDB.newEntry(commentID, subject, author, ip, date, content)); sb.blogCommentDB.write(sb.blogCommentDB.newEntry(commentID, subject, author, ip, date, content));
prop.putHTML("LOCATION","BlogComments.html?page=" + pagename); prop.putHTML("LOCATION","BlogComments.html?page=" + pagename);
MessageBoard.entry msgEntry = null; MessageBoard.entry msgEntry = sb.messageDB.newEntry(
sb.messageDB.write(msgEntry = sb.messageDB.newEntry(
"blogComment", "blogComment",
StrAuthor, strAuthor,
sb.peers.mySeed().hash, sb.peers.mySeed().hash,
sb.peers.mySeed().getName(), sb.peers.mySeed().hash, sb.peers.mySeed().getName(), sb.peers.mySeed().hash,
"new blog comment: " + UTF8.String(blogEntry.getSubject()), content)); "new blog comment: " + UTF8.String(blogEntry.getSubject()), content);
sb.messageDB.write(msgEntry);
messageForwardingViaEmail(sb, msgEntry); messageForwardingViaEmail(sb, msgEntry);

Loading…
Cancel
Save