G2 Gallery Spam

f’ing spammers, well hopefully with the disabling of the comments things should be a bit more secure. That said, gee it runs better without 20k with of spam comments…

See teh rest of the post for the Comments Blaster script, just change the 500 limit to whatever ya want and it makes removing spam a piece of cake..mmm cheesecake….gotta go..

<?php
/**
* This script will delete all the comments in your Gallery2, in chunks of 500.
* Use it very carefully!  It’s intended to be starting off point if you intend
* to blast comments in bulk (which is something that we do periodically for
* the demo Gallery2 on the Gallery website).  To use it, just copy this script
* into your Gallery2 directory and then open it up in your web browser.
*
* Note that as a safety measure, it won’t do anything until you edit the following
* line and set:
*  $DRY_RUN = false;
*/
$DRY_RUN = true;

require(’embed.php’);
GalleryEmbed::init();

/* Uncomment the next line if you’d like more verbose debug output */
// $gallery->setDebug(‘immediate’);

GalleryCoreApi::requireOnce(‘modules/comment/classes/GalleryCommentHelper.class’);

$ret = blastAll();
if ($ret) {
print $ret->getAsHtml();
}

$ret = GalleryEmbed::done();
if ($ret) {
print $ret->getAsHtml();
}

function blastAll() {
list ($ret, $count) = getCount();
if ($ret) {
return $ret->wrap(__FILE__, __LINE__);
}

flushprint(“There are $count comments”);

$ret = blast(500);
if ($ret) {
return $ret->wrap(__FILE__, __LINE__);
}

return null;
}

function flushprint($msg) {
print “$msg\n”;
flush();
}

function getCount() {
global $gallery;

$query = ‘SELECT COUNT([GalleryComment::id]) FROM [GalleryComment]’;
$storage =& $gallery->getStorage();
list ($ret, $results) = $storage->search($query);
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}

$result = $results->nextResult();
$count = $result[0];
return array(null, $count);
}

function blast($max) {
global $gallery;

$query = ‘SELECT [GalleryComment::id] FROM [GalleryComment]’;
$storage =& $gallery->getStorage();
list ($ret, $results) = $storage->search(
$query, array(), array(‘limit’ => array(‘count’ => $max)));
if ($ret) {
return $ret->wrap(__FILE__, __LINE__);
}

while ($result = $results->nextResult()) {
$id = $result[0];
if (!$GLOBALS[‘DRY_RUN’]) {
$ret = GalleryCoreApi::deleteEntityById($id);
if ($ret) {
return $ret->wrap(__FILE__, __LINE__);
}
}
flushprint(“$id…”);
}

return null;
}
?>

Email this to someoneTweet about this on TwitterShare on FacebookPin on PinterestShare on LinkedIn

Leave a Reply

Your email address will not be published.