@ -60,6 +60,7 @@ import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard ;
import de.anomic.plasma.plasmaSwitchboard ;
import de.anomic.server.serverObjects ;
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
import de.anomic.server.serverSwitch ;
import de.anomic.server.logging.serverLog ;
import de.anomic.yacy.yacyCore ;
import de.anomic.yacy.yacyCore ;
import de.anomic.yacy.yacyNewsRecord ;
import de.anomic.yacy.yacyNewsRecord ;
@ -75,8 +76,8 @@ public class Blog {
}
}
public static serverObjects respond ( httpHeader header , serverObjects post , serverSwitch env ) {
public static serverObjects respond ( httpHeader header , serverObjects post , serverSwitch env ) {
plasmaSwitchboard switchboard = ( plasmaSwitchboard ) env ;
final plasmaSwitchboard switchboard = ( plasmaSwitchboard ) env ;
serverObjects prop = new serverObjects ( ) ;
final serverObjects prop = new serverObjects ( ) ;
blogBoard . entry page = null ;
blogBoard . entry page = null ;
boolean hasRights = switchboard . verifyAuthentication ( header , true ) ;
boolean hasRights = switchboard . verifyAuthentication ( header , true ) ;
@ -99,7 +100,7 @@ public class Blog {
final int num = post . getInt ( "num" , 20 ) ; //indicates how many entries should be shown
final int num = post . getInt ( "num" , 20 ) ; //indicates how many entries should be shown
if ( ! hasRights ) {
if ( ! hasRights ) {
userDB . Entry userentry = switchboard . userDB . proxyAuth ( ( String ) header . get ( "Authorization" , "xxxxxx" ) ) ;
final userDB . Entry userentry = switchboard . userDB . proxyAuth ( ( String ) header . get ( "Authorization" , "xxxxxx" ) ) ;
if ( userentry ! = null & & userentry . hasBlogRight ( ) ) {
if ( userentry ! = null & & userentry . hasBlogRight ( ) ) {
hasRights = true ;
hasRights = true ;
} else if ( post . containsKey ( "login" ) ) {
} else if ( post . containsKey ( "login" ) ) {
@ -109,7 +110,7 @@ public class Blog {
}
}
String pagename = post . get ( "page" , DEFAULT_PAGE ) ;
String pagename = post . get ( "page" , DEFAULT_PAGE ) ;
final String ip = post . get ( "CLIENTIP" , "127.0.0.1" ) ;
final String ip = ( String ) header . get ( httpHeader . CONNECTION_PROP_CLIENTIP , "127.0.0.1" ) ;
String StrAuthor = post . get ( "author" , "" ) ;
String StrAuthor = post . get ( "author" , "" ) ;
@ -134,7 +135,7 @@ public class Blog {
if ( hasRights & & post . containsKey ( "delete" ) & & post . get ( "delete" ) . equals ( "sure" ) ) {
if ( hasRights & & post . containsKey ( "delete" ) & & post . get ( "delete" ) . equals ( "sure" ) ) {
page = switchboard . blogDB . read ( pagename ) ;
page = switchboard . blogDB . read ( pagename ) ;
Iterator i = page . comments ( ) . iterator ( ) ;
final Iterator i = page . comments ( ) . iterator ( ) ;
while ( i . hasNext ( ) ) {
while ( i . hasNext ( ) ) {
switchboard . blogCommentDB . delete ( ( String ) i . next ( ) ) ;
switchboard . blogCommentDB . delete ( ( String ) i . next ( ) ) ;
}
}
@ -165,8 +166,8 @@ public class Blog {
comments = page . comments ( ) ;
comments = page . comments ( ) ;
date = page . date ( ) ;
date = page . date ( ) ;
}
}
String commentMode = post . get ( "commentMode" , "1" ) ;
final String commentMode = post . get ( "commentMode" , "1" ) ;
String StrSubject = post . get ( "subject" , "" ) ;
final String StrSubject = post . get ( "subject" , "" ) ;
byte [ ] subject ;
byte [ ] subject ;
try {
try {
subject = StrSubject . getBytes ( "UTF-8" ) ;
subject = StrSubject . getBytes ( "UTF-8" ) ;
@ -177,11 +178,11 @@ public class Blog {
switchboard . blogDB . write ( switchboard . blogDB . newEntry ( pagename , subject , author , ip , date , content , comments , commentMode ) ) ;
switchboard . blogDB . write ( switchboard . blogDB . newEntry ( pagename , subject , author , ip , date , content , comments , commentMode ) ) ;
// create a news message
// create a news message
HashMap map = new HashMap ( ) ;
final HashMap map = new HashMap ( ) ;
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 ( ',' , ' ' ) ) ;
yacyCore . newsPool . publishMyNews ( new yacyNewsRecord ( "blog_add" , map ) ) ;
yacyCore . newsPool . publishMyNews ( new yacyNewsRecord ( "blog_add" , map ) ) ;
}
}
page = switchboard . blogDB . read ( pagename ) ; //maybe "if(page == null)"
page = switchboard . blogDB . read ( pagename ) ; //maybe "if(page == null)"
@ -264,7 +265,7 @@ public class Blog {
else {
else {
//only show 1 entry
//only show 1 entry
prop . put ( "mode_entries" , 1 ) ;
prop . put ( "mode_entries" , 1 ) ;
putBlogEntry ( prop , page , address , 0 , xml, hasRights) ;
putBlogEntry ( prop , page , address , 0 , hasRights, xml ) ;
}
}
}
}
@ -273,28 +274,29 @@ public class Blog {
}
}
private static serverObjects putBlogDefault (
private static serverObjects putBlogDefault (
serverObjects prop ,
final serverObjects prop ,
plasmaSwitchboard switchboard ,
final plasmaSwitchboard switchboard ,
String address ,
final String address ,
int start ,
int start ,
int num ,
int num ,
boolean hasRights ,
final boolean hasRights ,
boolean xml ) {
final boolean xml ) {
try {
try {
Iterator i = switchboard . blogDB . keys ( false ) ;
final Iterator i = switchboard . blogDB . keys ( false ) ;
String pageid ;
String pageid ;
blogBoard . entry entry ;
int count = 0 ; //counts how many entries are shown to the user
int count = 0 ; //counts how many entries are shown to the user
if ( xml ) num = 0 ;
if ( xml ) num = 0 ;
int nextstart = start + num ; //indicates the starting offset for next results
final int nextstart = start + num ; //indicates the starting offset for next results
while ( i . hasNext ( ) ) {
while ( i . hasNext ( ) & & ( num = = 0 | | num > count ) ) {
if ( count > = num & & num > 0 )
break ;
pageid = ( String ) i . next ( ) ;
pageid = ( String ) i . next ( ) ;
if ( 0 < start - - )
if ( 0 < start - - ) continue ;
continue ;
putBlogEntry (
entry = switchboard . blogDB . read ( pageid ) ;
prop ,
putBlogEntry ( prop , entry , address , count + + , xml , hasRights ) ;
switchboard . blogDB . read ( pageid ) ,
address ,
count + + ,
hasRights ,
xml ) ;
}
}
prop . put ( "mode_entries" , count ) ;
prop . put ( "mode_entries" , count ) ;
@ -305,7 +307,7 @@ public class Blog {
} else {
} else {
prop . put ( "moreentries" , 0 ) ;
prop . put ( "moreentries" , 0 ) ;
}
}
} catch ( IOException e ) { }
} catch ( IOException e ) { serverLog . logSevere ( "BLOG" , "Error reading blog-DB" , e ) ; }
return prop ;
return prop ;
}
}
@ -314,8 +316,8 @@ public class Blog {
final blogBoard . entry entry ,
final blogBoard . entry entry ,
final String address ,
final String address ,
final int number ,
final int number ,
final boolean xml ,
final boolean hasRights ,
final boolean hasRights ) {
final boolean xml ) {
// subject
// subject
try {
try {
@ -332,7 +334,9 @@ public class Blog {
}
}
// comments
// comments
if ( entry . getCommentMode ( ) ! = 0 ) {
if ( entry . getCommentMode ( ) = = 0 ) {
prop . put ( "mode_entries_" + number + "_commentsactive" , 0 ) ;
} else {
prop . put ( "mode_entries_" + number + "_commentsactive" , 1 ) ;
prop . put ( "mode_entries_" + number + "_commentsactive" , 1 ) ;
prop . put ( "mode_entries_" + number + "_commentsactive_pageid" , entry . key ( ) ) ;
prop . put ( "mode_entries_" + number + "_commentsactive_pageid" , entry . key ( ) ) ;
prop . put ( "mode_entries_" + number + "_commentsactive_address" , address ) ;
prop . put ( "mode_entries_" + number + "_commentsactive_address" , address ) ;
@ -341,14 +345,12 @@ public class Blog {
} catch ( UnsupportedEncodingException e ) {
} catch ( UnsupportedEncodingException e ) {
prop . put ( "mode_entries_" + number + "_commentsactive_comments" , new String ( entry . commentsSize ( ) ) ) ;
prop . put ( "mode_entries_" + number + "_commentsactive_comments" , new String ( entry . commentsSize ( ) ) ) ;
}
}
} else {
prop . put ( "mode_entries_" + number + "_commentsactive" , 0 ) ;
}
}
prop . put ( "mode_entries_" + number + "_date" , dateString ( entry . date ( ) ) ) ;
prop . put ( "mode_entries_" + number + "_date" , dateString ( entry . date ( ) ) ) ;
prop . put ( "mode_entries_" + number + "_pageid" , entry . key ( ) ) ;
prop . put ( "mode_entries_" + number + "_pageid" , entry . key ( ) ) ;
prop . put ( "mode_entries_" + number + "_address" , address ) ;
prop . put ( "mode_entries_" + number + "_address" , address ) ;
prop . put ( "mode_entries_" + number + " _ip", entry . ip ( ) ) ;
prop . put ( "mode_entries_" + number + " _ip", entry . ip ( ) ) ;
if ( xml ) {
if ( xml ) {
prop . putASIS ( "mode_entries_" + number + "_page" , entry . page ( ) ) ;
prop . putASIS ( "mode_entries_" + number + "_page" , entry . page ( ) ) ;