[pLog-svn] r1858 - in plog/trunk: class/action/admin
class/controller class/dao class/plugin class/view/admin
templates/admin
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Sun Apr 17 20:33:16 GMT 2005
Author: oscar
Date: 2005-04-17 20:33:15 +0000 (Sun, 17 Apr 2005)
New Revision: 1858
Added:
plog/trunk/class/action/admin/adminmarktrackbackaction.class.php
Modified:
plog/trunk/class/action/admin/adminedittrackbacksaction.class.php
plog/trunk/class/controller/admincontrollermap.properties.php
plog/trunk/class/dao/commentscommon.class.php
plog/trunk/class/plugin/eventlist.properties.php
plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php
plog/trunk/templates/admin/edittrackbacks.template
Log:
It is finally possible to mark trackbacks as spam, via a similar interface used to mark comments as spam. The data is used to feed the same spam data that is used throughout plog by the bayesian filter.
Modified: plog/trunk/class/action/admin/adminedittrackbacksaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminedittrackbacksaction.class.php 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/class/action/admin/adminedittrackbacksaction.class.php 2005-04-17 20:33:15 UTC (rev 1858)
@@ -24,6 +24,7 @@
// data validation
$this->registerFieldValidator( "articleId", new IntegerValidator());
+ $this->registerFieldValidator( "showStatus", new IntegerValidator(), true );
$view = new AdminPostsListView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_fetching_trackbacks"));
$this->setValidationErrorView( $view );
@@ -39,12 +40,16 @@
$articles = new Articles();
$article = $articles->getBlogArticle( $articleId, $this->_blogInfo->getId());
+ $status = $this->_request->getValue( "showStatus" );
+ if( $status == "" ) $status = COMMENT_STATUS_ALL;
+
if( !$article ) {
$this->_view = new AdminPostsListView( $this->_blogInfo );
$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));
}
else
- $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $article ));
+ $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $article,
+ "showStatus" => $status ));
$this->setCommonData();
Added: plog/trunk/class/action/admin/adminmarktrackbackaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminmarktrackbackaction.class.php 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/class/action/admin/adminmarktrackbackaction.class.php 2005-04-17 20:33:15 UTC (rev 1858)
@@ -0,0 +1,204 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminarticletrackbackslistview.class.php" );
+
+ /**
+ * \ingroup Action
+ * @private
+ *
+ * sets the spam status for a post
+ */
+ class AdminMarkTrackbackAction extends AdminAction
+ {
+
+ var $_trackbackId;
+ var $_articleId;
+ var $_mode;
+ var $_article;
+ var $_comment;
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminMarkTrackbackAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+
+ // data validation
+ $this->registerFieldValidator( "trackbackId", new IntegerValidator());
+ $this->registerFieldValidator( "articleId", new IntegerValidator());
+ $this->registerFieldValidator( "mode", new IntegerValidator());
+ $view = new AdminPostsListView( $this->_blogInfo );
+ $view->setErrorMessage( $this->_locale->tr("error_incorrect_trackback_id"));
+ $this->setValidationErrorView( $view );
+ }
+
+ /**
+ * @private
+ * Returns true wether the comment whose status we're trying to change
+ * really belongs to this blog, just in case somebody's trying to mess
+ * around with that...
+ */
+ function _checkTrackback( $trackbackId, $articleId, $blogId )
+ {
+ $trackbacks = new Trackbacks();
+ $articles = new Articles();
+
+ // fetch the comment
+ $this->_trackback = $trackbacks->getArticleTrackback( $trackbackId, $articleId );
+ if( !$this->_trackback )
+ return false;
+
+ // fetch the article
+ $this->_article = $articles->getBlogArticle( $this->_trackback->getArticleId(), $blogId );
+ if( !$this->_article )
+ return false;
+
+ return true;
+ }
+
+ /**
+ * @private
+ */
+ function _markTrackbackAsSpam()
+ {
+ // throw the pre-event
+ $this->notifyEvent( EVENT_PRE_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $this->_trackbackId ));
+
+ $this->_view = new AdminArticleTrackbacksListview( $this->_blogInfo, Array( "article" => $this->_article ));
+
+ $trackbacks = new Trackbacks();
+ if( !$trackbacks->updateCommentStatus( $this->_trackback->getId(), COMMENT_STATUS_SPAM )) {
+ $this->_view->setErrorMessage( $this->_locale->tr("error_marking_trackback_as_spam" ));
+ $this->setCommonData();
+
+ $res = false;
+ }
+ else {
+ $this->_view->setSuccessMessage( $this->_locale->tr("trackback_marked_as_spam_ok" ));
+ $this->setCommonData();
+
+ $res = true;
+
+ // before exiting, we should get the comment and train the filter
+ // to recognize this as spam...
+ $trackback = $trackbacks->getArticleTrackback( $this->_trackbackId, $this->_articleId );
+ $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" => $this->_trackbackId ));
+ }
+
+ return $res;
+ }
+
+ /**
+ * @private
+ */
+ function _markTrackbackAsNonSpam()
+ {
+ // throw the pre-event
+ $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $this->_trackbackId ));
+
+ $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $this->_article ));
+
+ $trackbacks = new Trackbacks();
+ if( !$trackbacks->updateCommentStatus( $this->_trackbackId, COMMENT_STATUS_NONSPAM )) {
+ $this->_view->setErrorMessage( $this->_locale->tr("error_marking_trackback_as_nonspam" ));
+ $this->setCommonData();
+
+ $res = false;
+ }
+ else {
+ $this->_view->setSuccessMessage( $this->_locale->tr("trackback_marked_as_nonspam_ok" ));
+ $this->setCommonData();
+
+ $res = true;
+
+ // before exiting, we should get the comment and train the filter
+ // to recognize this as spam...
+ $trackback = $trackbacks->getArticleTrackback( $this->_trackbackId, $this->_articleId );
+ $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" => $this->_trackbackId ));
+ }
+
+ return $res;
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ // fetch the data
+
+ $this->_trackbackId = $this->_request->getValue( "trackbackId" );
+ $this->_articleId = $this->_request->getValue( "articleId" );
+ $this->_mode = $this->_request->getValue( "mode" );
+
+ // first, let's make sure that the user is trying to edit the right
+ // comment...
+ if( !$this->_checkTrackback( $this->_trackbackId, $this->_articleId, $this->_blogInfo->getId())) {
+ // if things don't match... (like trying to set the status of an article
+ // from another blog, then quit...)
+ $this->_view = new AdminPostsListView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_trackback_id"));
+ $this->setCommonData();
+ return false;
+ }
+
+ // depending on the mode, we have to do one thing or another
+ if( $this->_mode == 0 )
+ $result = $this->_markTrackbackAsNonSpam();
+ else
+ $result = $this->_markTrackbackAsSpam();
+
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+ // better to return true if everything fine
+ return $result;
+ }
+ }
+?>
Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/class/controller/admincontrollermap.properties.php 2005-04-17 20:33:15 UTC (rev 1858)
@@ -205,6 +205,7 @@
$actions["deleteResourceItems"] = "AdminDeleteGalleryItemsAction";
// mark as spam
$actions["markComment"] = "AdminMarkCommentAction";
+ $actions["markTrackback"] = "AdminMarkTrackbackAction";
// purge spam comments
$actions["purgeSpamComments"] = "AdminPurgeSpamCommentsAction";
// regenerate a preview
Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/class/dao/commentscommon.class.php 2005-04-17 20:33:15 UTC (rev 1858)
@@ -356,7 +356,7 @@
{
$query = "UPDATE ".$this->getPrefix()."articles_comments SET
status = '".Db::qstr($status)."', date = date
- WHERE id = ".Db::qstr($commentId)."'";
+ WHERE id = '".Db::qstr($commentId)."'";
if( $type != COMMENT_TYPE_ANY )
$query .= " AND type = '".Db::qstr($type)."'";
Modified: plog/trunk/class/plugin/eventlist.properties.php
===================================================================
--- plog/trunk/class/plugin/eventlist.properties.php 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/class/plugin/eventlist.properties.php 2005-04-17 20:33:15 UTC (rev 1858)
@@ -151,4 +151,9 @@
define( "EVENT_POST_REFERRER_DELETE", 109 );
define( "EVENT_PRE_REFERRER_ADD", 110 );
define( "EVENT_POST_REFERRER_ADD", 111 );
+ // before and after a trackback is marked as spam and no-spam
+ define( "EVENT_PRE_MARK_SPAM_TRACKBACK", 24 );
+ define( "EVENT_POST_MARK_SPAM_TRACKBACK", 25 );
+ define( "EVENT_PRE_MARK_NO_SPAM_TRACKBACK", 26 );
+ define( "EVENT_POST_MARK_NO_SPAM_TRACKBACK", 27 );
?>
Modified: plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php 2005-04-17 20:33:15 UTC (rev 1858)
@@ -5,6 +5,7 @@
include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
include_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
/**
* \ingroup View
@@ -14,38 +15,65 @@
*/
class AdminArticleTrackbacksListView extends AdminTemplatedView
{
- var $_articleId;
+ var $_article;
+ var $_tbStatus;
function AdminArticleTrackbacksListView( $blogInfo, $params = Array())
{
$this->AdminTemplatedView( $blogInfo, "edittrackbacks" );
+
+ $this->_setParameters( $params );
- // fetch the article id
- $this->_article = $params["article"];
-
// page
$this->_page = $this->getCurrentPageFromRequest();
}
/**
+ * @private
+ */
+ function _setParameters( $params )
+ {
+ // fetch the article id
+ $this->_article = $params["article"];
+
+ // load the status
+ $this->_tbStatus = $params["showStatus"];
+ if( !ArticleCommentStatus::isValidStatus( $this->_tbStatus ))
+ $this->_tbStatus = COMMENT_STATUS_ALL;
+ }
+
+ /**
* show the contents of the view
*/
function render()
{
$trackbacks = new Trackbacks();
// get the trackbacks
- $postTrackbacks = $trackbacks->getArticleTrackbacks( $this->_article->getId(), $this->_page, DEFAULT_ITEMS_PER_PAGE );
+
+ $postTrackbacks = $trackbacks->getArticleTrackbacks( $this->_article->getId(),
+ $this->_tbStatus,
+ $this->_page,
+ DEFAULT_ITEMS_PER_PAGE );
$this->notifyEvent( EVENT_TRACKBACKS_LOADED, Array( "trackbacks" => &$postTrackbacks ));
$this->setValue( "trackbacks", $postTrackbacks);
// and the total number of trackbacks
- $numTrackbacks = $trackbacks->getNumTrackbacksArticle( $this->_article->getId());
+ $numTrackbacks = $trackbacks->getNumTrackbacksArticle( $this->_article->getId(), $this->_tbStatus );
// create and export the pager to the view
- $pager = new Pager( "?op=editTrackbacks&articleId=".$this->_article->getId()."&page=",
+ if( $this->_tbStatus == COMMENT_STATUS_ALL )
+ $url = "?op=editTrackbacks&articleId=".$this->_article->getId()."&page=";
+ else
+ $url = "?op=editTrackbacks&articleId=".$this->_article->getId()."&showStatus=".$this->_tbStatus."&page=";
+
+ $pager = new Pager( $url,
$this->_page,
$numTrackbacks,
DEFAULT_ITEMS_PER_PAGE );
$this->setValue( "pager", $pager );
+ // get a list with all the different comment status
+ $statusList = ArticleCommentStatus::getStatusList( true );
+ $this->setValue( "commentstatus", $statusList );
+ $this->setValue( "currentstatus", $this->_tbStatus );
// pass the common data to the templates
$this->setValue( "post", $this->_article );
Modified: plog/trunk/templates/admin/edittrackbacks.template
===================================================================
--- plog/trunk/templates/admin/edittrackbacks.template 2005-04-17 19:49:52 UTC (rev 1857)
+++ plog/trunk/templates/admin/edittrackbacks.template 2005-04-17 20:33:15 UTC (rev 1858)
@@ -1,6 +1,36 @@
{include file="$admintemplatepath/header.template"}
{assign var=postTitle value=$post->getTopic()}
-{include file="$admintemplatepath/navigation.template" showOpt=editPosts title=$locale->tr("editTrackbacks")}
+{include file="$admintemplatepath/navigation.template" showOpt=editPosts title=$locale->tr("editTrackbacks")}
+ <div id="list_nav_bar">
+ <div id="list_nav_select">
+
+ <form id="showBy" action="admin.php" method="post">
+ <fieldset>
+ <legend>{$locale->tr("show_by")}</legend>
+
+ <div class="list_nav_option">
+ <label for="showStatus">{$locale->tr("status")}</label>
+ <br />
+ <select name="showStatus" id="showStatus">
+ {foreach from=$commentstatus key=name item=status}
+ <option value="{$status}" {if $currentstatus == $status} selected="selected"{/if}>{$locale->tr($name)}</option>
+ {/foreach}
+ </select>
+ </div>
+
+ <div class="list_nav_option">
+ <br />
+ <input type="hidden" name="op" value="editTrackbacks" />
+ <input type="hidden" name="articleId" value="{$post->getId()}" />
+ <input type="submit" name="show" value="{$locale->tr("show")}" class="submit" />
+ </div>
+
+ </fieldset>
+ </form>
+ </div>
+ <br style="clear:both;" />
+ </div>
+
<form id="postTrackbacks" action="admin.php" method="post">
<div id="list">
{include file="$admintemplatepath/successmessage.template"}
@@ -8,10 +38,13 @@
<table class="info">
<thead>
<tr>
- <th style="width:10px;"><input class="checkbox" type="checkbox" class="check" name="all" id="all" value="1" onclick="toggleAllChecks('postTrackbacks');" /></th>
- <th style="width:225px;">{$locale->tr("blog")}</th>
- <th style="width:330px;">{$locale->tr("excerpt")}</th>
- <th style="width:115px;">{$locale->tr("date")}</th>
+ <th style="width:10px;"><input class="checkbox" type="checkbox" class="check" name="all" id="all" value="1" onclick="toggleAllChecks('postCommentsList');" /></th>
+ <th style="width:85px;">{$locale->tr("topic")}</th>
+ <th style="width:360px;">{$locale->tr("text")}</th>
+ <th style="width:70px;">{$locale->tr("author")}</th>
+ <th stlye="width:60px;">{$locale->tr("date")}</th>
+ <th style="width:60px;">{$locale->tr("status")}</th>
+ <th style="width:45px;">IP</th>
<th style="width:95px;">{$locale->tr("actions")}</th>
</tr>
</thead>
@@ -22,18 +55,38 @@
<input class="checkbox" type="checkbox" name="trackbackIds[{$trackback->getId()}]" id="checks_1" value="{$trackback->getId()}" />
</td>
<td class="col_highlighted">
- <a href="{$trackback->getUrl()}">{$trackback->getBlogName()}</a>
+ {$trackback->getTopic()}
</td>
<td>
{$trackback->getExcerpt()|escape:html}
</td>
<td>
+ <a href="{$trackback->getUrl()}">{$trackback->getBlogName()}</a>
+ </td>
+ <td>
{assign var=date value=$trackback->getDateObject()}
{$locale->formatDate($date)}
- </td>
+ </td>
<td>
+ {foreach from=$commentstatus key=name item=status}
+ {if $trackback->getStatus() == $status}{$locale->tr($name)}{/if}
+ {/foreach}
+ </td>
+ <td style="text-align: center;">
+ {$trackback->getClientIp()}
+ </td>
+ <td>
<div class="list_action_button">
<a href="?op=deleteTrackback&articleId={$post->getId()}&trackbackId={$trackback->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete_trackback")}" /></a>
+ {if $trackback->getStatus() == 0}
+ <a href="?op=markTrackback&mode=1&articleId={$trackback->getArticleId()}&trackbackId={$trackback->getId()}">
+ <img src="imgs/admin/icon_spam-16.png" alt="{$locale->tr("mark_as_spam")}" />
+ </a>
+ {elseif $trackback->getStatus() == 1}
+ <a href="?op=markTrackback&mode=0&articleId={$trackback->getArticleId()}&trackbackId={$trackback->getId()}">
+ <img src="imgs/admin/icon_nospam-16.png" alt="{$locale->tr("mark_as_no_spam")}" />
+ </a>
+ {/if}
</div>
</td>
</tr>
More information about the pLog-svn
mailing list