*) a peer-message are now created when a blog-comment is written

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3480 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
hydrox 18 years ago
parent 581db87237
commit 9b5fb3908d

@ -46,7 +46,9 @@
// javac -classpath .:../Classes Blacklist_p.java
// if the shell's current path is HTROOT
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -54,12 +56,16 @@ import java.util.Iterator;
import de.anomic.data.blogBoard;
import de.anomic.data.blogBoardComments;
import de.anomic.data.messageBoard;
import de.anomic.data.userDB;
import de.anomic.data.blogBoard.entry;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverFileUtils;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacyCore;
public class BlogComments {
@ -147,6 +153,36 @@ public class BlogComments {
blogEntry.addComment(commentID);
switchboard.blogDB.write(blogEntry);
switchboard.blogCommentDB.write(switchboard.blogCommentDB.newEntry(commentID, subject, author, ip, date, content));
prop.put("LOCATION","BlogComments.html?page=" + pagename);
messageBoard.entry msgEntry = null;
try {
switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry(
"blogComment",
StrAuthor,
yacyCore.seedDB.mySeed.hash,
yacyCore.seedDB.mySeed.getName(), yacyCore.seedDB.mySeed.hash,
"new blog comment: " + new String(blogEntry.subject(),"UTF-8"), content));
} catch (UnsupportedEncodingException e1) {
switchboard.messageDB.write(msgEntry = switchboard.messageDB.newEntry(
"blogComment",
StrAuthor,
yacyCore.seedDB.mySeed.hash,
yacyCore.seedDB.mySeed.getName(), yacyCore.seedDB.mySeed.hash,
"new blog comment: " + new String(blogEntry.subject()), content));
}
messageForwardingViaEmail(env, msgEntry);
// finally write notification
File notifierSource = new File(switchboard.getRootPath(), switchboard.getConfig("htRootPath","htroot") + "/env/grafics/message.gif");
File notifierDest = new File(switchboard.getConfig("htDocsPath", "DATA/HTDOCS"), "notifier.gif");
try {
serverFileUtils.copy(notifierSource, notifierDest);
} catch (IOException e) {
serverLog.logSevere("MESSAGE", "NEW MESSAGE ARRIVED! (error: " + e.getMessage() + ")");
}
}
}
@ -263,4 +299,50 @@ public class BlogComments {
// return rewrite properties
return prop;
}
private static void messageForwardingViaEmail(serverSwitch env, messageBoard.entry msgEntry) {
try {
if (!Boolean.valueOf(env.getConfig("msgForwardingEnabled","false")).booleanValue()) return;
// getting the recipient address
String sendMailTo = env.getConfig("msgForwardingTo","root@localhost").trim();
// getting the sendmail configuration
String sendMailStr = env.getConfig("msgForwardingCmd","/usr/bin/sendmail")+" "+sendMailTo;
String[] sendMail = sendMailStr.trim().split(" ");
// building the message text
StringBuffer emailTxt = new StringBuffer();
emailTxt.append("To: ")
.append(sendMailTo)
.append("\nFrom: ")
.append("yacy@")
.append(yacyCore.seedDB.mySeed.getName())
.append("\nSubject: [YaCy] ")
.append(msgEntry.subject().replace('\n', ' '))
.append("\nDate: ")
.append(msgEntry.date())
.append("\n")
.append("\nMessage from: ")
.append(msgEntry.author())
.append("/")
.append(msgEntry.authorHash())
.append("\nMessage to: ")
.append(msgEntry.recipient())
.append("/")
.append(msgEntry.recipientHash())
.append("\nCategory: ")
.append(msgEntry.category())
.append("\n===================================================================\n")
.append(new String(msgEntry.message()));
Process process=Runtime.getRuntime().exec(sendMail);
PrintWriter email = new PrintWriter(process.getOutputStream());
email.print(new String(emailTxt));
email.close();
} catch (Exception e) {
yacyCore.log.logWarning("message: message forwarding via email failed. ",e);
}
}
}

@ -132,7 +132,7 @@ public class Messages_p {
if (action.equals("list")) {
prop.put("mode", 0); //list
try {
Iterator i = switchboard.messageDB.keys("remote", true);
Iterator i = switchboard.messageDB.keys(null, true);
String key;
boolean dark = true;
@ -146,7 +146,8 @@ public class Messages_p {
prop.put("mode_messages_"+count+"_to", message.recipient());
//prop.put("mode_messages_"+count+"_subject", wikiTransformer.transform(message.subject()));
//TODO: not needed, when all templates will be cleaned via replaceHTML
prop.put("mode_messages_"+count+"_subject", wikiCode.replaceHTML(message.subject()));
prop.put("mode_messages_"+count+"_subject", message.subject());
prop.put("mode_messages_"+count+"_category", message.category());
prop.put("mode_messages_"+count+"_key", key);
prop.put("mode_messages_"+count+"_hash", message.authorHash());
@ -186,7 +187,7 @@ public class Messages_p {
prop.put("mode_date", dateString(message.date()));
//prop.put("mode_messages_subject", wikiTransformer.transform(message.subject()));
//TODO: not needed, when all templates will be cleaned via replaceHTML
prop.put("mode_subject", wikiCode.replaceHTML(message.subject()));
prop.put("mode_subject", message.subject());
String theMessage = null;
try {
theMessage = new String(message.message(), "UTF-8");

@ -13,6 +13,7 @@
<item>
<author><![CDATA[#[from]#]]></author>
<title><![CDATA[#[subject]#]]></title>
<category>#[category]#</category>
<link>http://#[peerAddress]#/Messages_p.html?action=view&amp;object=#[key]#</link>
<pubDate>#[rfc822Date]#</pubDate>
<guid>#[key]#</guid>

@ -241,7 +241,7 @@ public class messageBoard {
public void findNext() {
while (allIter.hasNext()) {
nextKey = (String) allIter.next();
if (nextKey.startsWith(this.category)) return;
if (this.category==null || nextKey.startsWith(this.category)) return;
}
nextKey = null;
}

Loading…
Cancel
Save