Skip to content

Commit

Permalink
- View for batch submission of spam
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberwolf committed Sep 3, 2007
1 parent 2b0fe19 commit f343814
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
55 changes: 55 additions & 0 deletions classes/ezcontentobjectakismet.php
Expand Up @@ -51,6 +51,61 @@ function getInfoExtractor( $contentObjectVersion )
return false;
}
}

/*!
\static
Returns an array of class identifiers for which a content object akismet
information extractor is available.
*/
function getExtractableClassList()
{
include_once( 'lib/ezutils/classes/ezini.php' );
$ini = eZINI::instance( 'akismet.ini' );
$infoExtractors = $ini->variable( 'InformationExtractorSettings', 'ClassMap' );

return array_keys( $infoExtractors );
}

/*
\static
Returns an array of nodes for which a content object akismet
information extractor is available.
*/
function getExtractableNodes( $limit = false, $offset = false )
{
$classList = eZContentObjectAkismet::getExtractableClassList();

include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
$params = array(
'ClassFilterType' => 'include',
'ClassFilterArray' => $classList,
'SortBy' => array( array( 'published', false ) ),
'Limit' => $limit,
'Offset' => $offset
);

$nodes = eZContentObjectTreeNode::subTree( $params, 1 );
return $nodes;
}

/*
\static
Returns the number of nodes for which a content object akismet
information extractor is available.
*/
function getExtractableNodesCount()
{
$classList = eZContentObjectAkismet::getExtractableClassList();

include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
$params = array(
'ClassFilterType' => 'include',
'ClassFilterArray' => $classList
);

$nodeCount = eZContentObjectTreeNode::subTreeCount( $params, 1 );
return $nodeCount;
}
}

?>
30 changes: 30 additions & 0 deletions design/standard/templates/akismet/submit.tpl
@@ -0,0 +1,30 @@
<form action={'akismet/submit'|ezurl} method="post">
<table class="list" cellspacing="0">
<tr>
<th></th>
<th>Name</th>
<th>Published</th>
</tr>
{foreach $nodes as $node sequence array('bglight','bgdark') as $sequence}
<tr class="{$sequence}">
<td><input type="checkbox" name="ObjectIDList[]" value="{$node.contentobject_id}" /></td>
<td><a href={$node.url_alias|ezurl}>{$node.name|wash}</a></td>
<td>{$node.object.published|l10n( shortdatetime )}</td>
</tr>
{/foreach}
</table>

<div class="button-block">
<input type="submit" value="Report as spam" name="SpamSubmitButton" />
</div>

</form>

<div class="context-toolbar">
{include name=navigator
uri='design:navigator/google.tpl'
page_uri='akismet/submit'
item_count=$nodes_count
view_parameters=$view_parameters
item_limit=$limit}
</div>
6 changes: 6 additions & 0 deletions modules/akismet/module.php
Expand Up @@ -3,6 +3,12 @@
$Module = array( 'name' => 'Akismet', 'variable_params' => false, 'ui_component_match' => 'module' );

$ViewList = array();
$ViewList['submit'] = array(
'script' => 'submit.php',
'functions' => array( 'submit' ),
'single_post_actions' => array( 'SpamSubmitButton' => 'Submit' ),
'post_action_parameters' => array( 'Submit' => array( 'ObjectIDList' => 'ObjectIDList' ) )
);

$FunctionList = array();
$FunctionList['submit'] = array();
Expand Down
65 changes: 65 additions & 0 deletions modules/akismet/submit.php
@@ -0,0 +1,65 @@
<?php

$Module =& $Params['Module'];

$limit = 20;
$offset = 0;

include_once( 'extension/akismet/classes/ezcontentobjectakismet.php' );

$extractableNodes = eZContentObjectAkismet::getExtractableNodes( $limit, $offset );
$extractableNodesCount = eZContentObjectAkismet::getExtractableNodesCount();

if ( $Module->isCurrentAction( 'Submit' ) && $Module->hasActionParameter( 'ObjectIDList' ) )
{
$objectIDList = $Module->actionParameter( 'ObjectIDList' );

foreach ( $objectIDList as $objectID )
{
$object = eZContentObject::fetch( $objectID );
$version = $object->attribute( 'current' );

include_once( 'extension/akismet/classes/ezcontentobjectakismet.php' );
$infoExtractor = eZContentObjectAkismet::getInfoExtractor( $version );
if ( $infoExtractor )
{
$comment = $infoExtractor->getCommentArray();

eZDebug::writeDebug( $comment );

include_once( 'extension/akismet/classes/ezakismet.php' );
$akismet = new eZAkismet( $comment );

if ( !$akismet->errorsExist() )
{
$response = $akismet->submitSpam();
eZDebug::writeNotice( $response, 'Akismet web service response' );
}
else
{
eZDebug::writeWarning( 'An error has occured, unable to submit spam to Akismet.' );
}

}
else
{
eZDebug::writeDebug( 'Unable to find Akismet info extractor' );
}
}
}

include_once( 'kernel/common/template.php' );
$tpl =& templateInit();

$tpl->setVariable( 'nodes', $extractableNodes );
$tpl->setVariable( 'nodes_count', $extractableNodesCount );
$tpl->setVariable( 'limit', $limit );

$Result = array();
$Result['content'] = $tpl->fetch( 'design:akismet/submit.tpl' );
$Result['path'] = array(
array( 'url' => false, 'text' => 'Akismet' ),
array( 'url' => false, 'text' => 'Submit spam' )
);

?>

0 comments on commit f343814

Please sign in to comment.