[pLog-svn] r3358 - plog/trunk/class/action/admin
mark at devel.lifetype.net
mark at devel.lifetype.net
Mon May 8 03:08:07 GMT 2006
Author: mark
Date: 2006-05-08 03:08:05 +0000 (Mon, 08 May 2006)
New Revision: 3358
Modified:
plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php
plog/trunk/class/action/admin/adminchangetrackbacksstatusaction.class.php
Log:
I forget put the bayesian filter training stuff in the massive edit. Only change the status in previous script is not enough.
Modified: plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php 2006-05-08 02:36:25 UTC (rev 3357)
+++ plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php 2006-05-08 03:08:05 UTC (rev 3358)
@@ -60,7 +60,7 @@
$successMessage = "";
$totalOk = 0;
- if( $articleId > 0 ) {
+ if( $this->_articleId > 0 ) {
// if we can't even load the article, then forget it...
$articles = new Articles();
$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
@@ -77,7 +77,7 @@
$article = null;
}
- // loop through the comments and remove them
+ // loop through the comments and change them
foreach( $this->_commentIds as $commentId ) {
// fetch the comment
$comment = $comments->getComment( $commentId );
@@ -92,14 +92,33 @@
// check if the comment really belongs to this blog...
$article = $comment->getArticle();
if( $article->getBlogId() != $this->_blogInfo->getId()) {
- // if not, then we shouldn't be allowed to remove anything!
- $errorMessage .= $this->_locale->pr("error_deleting_comment", $comment->getTopic())."<br/>";
+ // if not, then we shouldn't be allowed to change anything!
+ $errorMessage .= $this->_locale->pr("error_updating_comment", $comment->getTopic())."<br/>";
}
- else {
+ else
+ {
+ $preCommentStatus = $comment->getStatus();
+
+ if ( $preCommentStatus == $this->_commentStatus )
+ {
+ $errorMessage .= $this->_locale->pr("error_updating_comment", $comment->getTopic())."<br/>";
+ continue;
+
+ }
+
$comment->setStatus( $this->_commentStatus );
if( !$comments->updateComment( $comment ))
$errorMessage .= $this->_locale->pr("error_updating_comment", $comment->getTopic())."<br/>";
else {
+ if( $this->_commentStatus == COMMENT_STATUS_SPAM )
+ {
+ $this->_markCommentAsSpam($comment);
+ }
+ elseif( $this->_commentStatus == COMMENT_STATUS_NONSPAM )
+ {
+ $this->_markCommentAsNonSpam($comment);
+ }
+
$totalOk++;
if( $totalOk < 2 )
$successMessage .= $this->_locale->pr("comment_updating_ok", $comment->getTopic())."<br/>";
@@ -130,5 +149,66 @@
// better to return true if everything fine
return true;
}
+
+ function _markCommentAsSpam( $comment )
+ {
+ // throw the pre-event
+ $this->notifyEvent( EVENT_PRE_MARK_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
+
+ // We should get the comment and train the filter to recognize this as spam...
+ include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
+ $bayesian = new BayesianFilterCore();
+
+ $bayesian->untrain( $this->_blogInfo->getId(),
+ $comment->getTopic(),
+ $comment->getText(),
+ $comment->getUserName(),
+ $comment->getUserEmail(),
+ $comment->getUserUrl(),
+ false );
+
+ $bayesian->train( $this->_blogInfo->getId(),
+ $comment->getTopic(),
+ $comment->getText(),
+ $comment->getUserName(),
+ $comment->getUserEmail(),
+ $comment->getUserUrl(),
+ true );
+
+ // throw the post-event if everythign went fine
+ $this->notifyEvent( EVENT_POST_MARK_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
+ }
+
+ /**
+ * @private
+ */
+ function _markCommentAsNonSpam( $comment )
+ {
+ // throw the pre-event
+ $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
+
+ // we should get the comment and train the filter
+ include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
+ $bayesian = new BayesianFilterCore();
+
+ $bayesian->untrain( $this->_blogInfo->getId(),
+ $comment->getTopic(),
+ $comment->getText(),
+ $comment->getUserName(),
+ $comment->getUserEmail(),
+ $comment->getUserUrl(),
+ true );
+
+ $bayesian->train( $this->_blogInfo->getId(),
+ $comment->getTopic(),
+ $comment->getText(),
+ $comment->getUserName(),
+ $comment->getUserEmail(),
+ $comment->getUserUrl(),
+ false );
+
+ // throw the post-event if everythign went fine
+ $this->notifyEvent( EVENT_POST_MARK_NO_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
+ }
}
?>
Modified: plog/trunk/class/action/admin/adminchangetrackbacksstatusaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangetrackbacksstatusaction.class.php 2006-05-08 02:36:25 UTC (rev 3357)
+++ plog/trunk/class/action/admin/adminchangetrackbacksstatusaction.class.php 2006-05-08 03:08:05 UTC (rev 3358)
@@ -60,7 +60,7 @@
$successMessage = "";
$totalOk = 0;
- if( $articleId > 0 ) {
+ if( $this->_articleId > 0 ) {
// if we can't even load the article, then forget it...
$articles = new Articles();
$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
@@ -95,11 +95,30 @@
// if not, then we shouldn't be allowed to remove anything!
$errorMessage .= $this->_locale->pr("error_updating_trackback", $trackback->getExcerpt())."<br/>";
}
- else {
+ else
+ {
+ $preTrackbackStatus = $trackback->getStatus();
+
+ if ( $preTrackbackStatus == $this->_trackbackStatus )
+ {
+ $errorMessage .= $this->_locale->pr("error_updating_trackback", $trackback->getExcerpt())."<br/>";
+ continue;
+
+ }
+
$trackback->setStatus( $this->_trackbackStatus );
if( !$trackbacks->updateComment( $trackback ))
$errorMessage .= $this->_locale->pr("error_updating_trackback", $trackback->getExcerpt())."<br/>";
else {
+ if( $this->_trackbackStatus == COMMENT_STATUS_SPAM )
+ {
+ $this->_markTrackbackAsSpam($trackback);
+ }
+ elseif( $this->_trackbackStatus == COMMENT_STATUS_NONSPAM )
+ {
+ $this->_markTrackbackAsNonSpam($trackback);
+ }
+
$totalOk++;
if( $totalOk < 2 )
$successMessage .= $this->_locale->pr("trackback_updated_ok", $trackback->getExcerpt());
@@ -130,5 +149,66 @@
// better to return true if everything fine
return true;
}
+
+ function _markTrackbackAsSpam( $trackback )
+ {
+ // throw the pre-event
+ $this->notifyEvent( EVENT_PRE_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() ));
+
+ // We should get the trackback and train the filter to recognize this as spam...
+ include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
+ $bayesian = new BayesianFilterCore();
+
+ $bayesian->untrain( $this->_blogInfo->getId(),
+ $trackback->getTopic(),
+ $trackback->getText(),
+ $trackback->getUserName(),
+ $trackback->getUserEmail(),
+ $trackback->getUserUrl(),
+ false );
+
+ $bayesian->train( $this->_blogInfo->getId(),
+ $trackback->getTopic(),
+ $trackback->getText(),
+ $trackback->getUserName(),
+ $trackback->getUserEmail(),
+ $trackback->getUserUrl(),
+ true );
+
+ // throw the post-event if everythign went fine
+ $this->notifyEvent( EVENT_POST_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() ));
+ }
+
+ /**
+ * @private
+ */
+ function _markTrackbackAsNonSpam( $trackback )
+ {
+ // throw the pre-event
+ $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() ));
+
+ // we should get the trackback and train the filter
+ include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
+ $bayesian = new BayesianFilterCore();
+
+ $bayesian->untrain( $this->_blogInfo->getId(),
+ $trackback->getTopic(),
+ $trackback->getText(),
+ $trackback->getUserName(),
+ $trackback->getUserEmail(),
+ $trackback->getUserUrl(),
+ true );
+
+ $bayesian->train( $this->_blogInfo->getId(),
+ $trackback->getTopic(),
+ $trackback->getText(),
+ $trackback->getUserName(),
+ $trackback->getUserEmail(),
+ $trackback->getUserUrl(),
+ false );
+
+ // throw the post-event if everythign went fine
+ $this->notifyEvent( EVENT_POST_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() ));
+ }
}
?>
\ No newline at end of file
More information about the pLog-svn
mailing list