Skip to content

Commit

Permalink
refs #1703 : added - automatic comment cleaner with IP.
Browse files Browse the repository at this point in the history
 - TODO: trackback and guestbook
 - TODO: UI improvement
  • Loading branch information
inureyes committed Dec 9, 2014
1 parent 5249218 commit d39a1ec
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
10 changes: 9 additions & 1 deletion interface/owner/communication/comment/delete/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
$IV = array(
'POST' => array(
'targets' => array('list', 'default' => '', 'mandatory' => false),
'ip' => array('ip', 'default' => '', 'mandatory' => false)
'ip' => array('ip', 'default' => '', 'mandatory' => false),
'targetIPs' => array('string', 'default' => '', 'mandatory' => false)
)
);
require ROOT . '/library/preprocessor.php';
Expand All @@ -23,6 +24,13 @@
foreach(explode(',', $_POST['targets']) as $target)
trashCommentInOwner($blogid, $target);
}
if(!empty($_POST['targetIPs'])) {
$targetIPs = array_unique(explode(',', $_POST['targetIPs']));
foreach($targetIPs as $target) {
if (Validator::ip($target))
trashCommentInOwnerByIP($blogid, $target);
}
}
if(!empty($_POST['ip'])) {
trashCommentInOwnerByIP($blogid, $_POST['ip']);
}
Expand Down
78 changes: 46 additions & 32 deletions interface/owner/communication/comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'withSearch' => array(array('on'), 'mandatory' => false),
'status' => array('string', 'mandatory' => false)
)
);
);
require ROOT . '/library/preprocessor.php';
requireModel("blog.comment");
requireModel("blog.entry");
Expand All @@ -51,7 +51,7 @@
$tabsClass['postfix'] .= isset($_POST['name']) ? '&name='.$_POST['name'] : '';
$tabsClass['postfix'] .= isset($_POST['ip']) ? '&ip='.$_POST['ip'] : '';
$tabsClass['postfix'] .= isset($_POST['search']) ? '&search='.$_POST['search'] : '';
if(!empty($tabsClass['postfix'])) $tabsClass['postfix'] = ltrim($tabsClass['postfix'],'/');
if(!empty($tabsClass['postfix'])) $tabsClass['postfix'] = ltrim($tabsClass['postfix'],'/');

if (isset($_POST['status'])) {
if($_POST['status']=='comment') {
Expand Down Expand Up @@ -92,26 +92,38 @@
PM.addRequest(request, "<?php echo (isset($tabsClass['guestbook']) ? _t('방명록을 삭제하고 있습니다.') : _t('댓글을 삭제하고 있습니다.'));?>");
request.send();
};

deleteComments = function() {
if (!confirm("<?php echo (isset($tabsClass['guestbook']) ? _t('선택된 방명록을 삭제합니다. 계속 하시겠습니까?') : _t('선택된 댓글을 삭제합니다. 계속 하시겠습니까?'));?>"))
return false;

var oElement;
var alsoDeleteWithSameIP = document.getElementById('deleteCommentsFromSameIP').checked;
var targets = new Array();
var targetIPs = new Array();

for (i = 0; document.getElementById('list-form').elements[i]; i ++) {
oElement = document.getElementById('list-form').elements[i];
if ((oElement.name == "entry") && oElement.checked)
if ((oElement.name == "entry") && oElement.checked) {
targets[targets.length] = oElement.value;
if (alsoDeleteWithSameIP == true) {
targetIPs[targetIPs.length] = oElement.getAttribute('ip');
}
}
}

var request = new HTTPRequest("POST", "<?php echo $context->getProperty('uri.blog');?>/owner/communication/comment/delete/");
request.onSuccess = function() {
document.getElementById('list-form').submit();
}
request.send("targets=" + targets.join(","));
param = "targets=" + targets.join(",");
if (alsoDeleteWithSameIP == true) {
param = param + "&targetIPs=" + targetIPs.join(",");
}
alert(param);
request.send(param);
};

changeState = function(caller, value, no, mode) {
try {
if (caller.className == 'block-icon bullet') {
Expand All @@ -124,13 +136,13 @@
param += '&mode=' + mode;
param += '&command=' + command;
param += '&id=' + no;

var request = new HTTPRequest("GET", "<?php echo $blogURL;?>/owner/communication/filter/change/" + param);

request.onSuccess = function() {
if (mode == 'ip' && command == 'block' && confirm(value+" <?php echo (isset($tabsClass['guestbook']) ? _t('IP에서 작성한 모든 방명록을 삭제하시겠습니까?') : _t('IP에서 작성한 모든 댓글을 삭제하시겠습니까?'));?>")) {
var wipe = new HTTPRequest("POST", "<?php echo $blogURL;?>/owner/communication/comment/delete/");

wipe.onSuccess = function() {
PM.removeRequest(this);
document.getElementById('list-form').submit();
Expand All @@ -151,9 +163,9 @@
alert(e.message);
}
};

changeStateItems = function(value, mode, command, name) {
var iconList = document.getElementsByTagName("a");
var iconList = document.getElementsByTagName("a");
for (var i = 0; i < iconList.length; i++) {
icon = iconList[i];
if(icon.id == null || icon.id.replace(/\-[0-9]+$/, '') != name) {
Expand Down Expand Up @@ -190,7 +202,7 @@ function toggleThisTr(tr, isActive) {

$(document).ready(function() {
$('#allChecked').removeAttr('disabled');
<?php
<?php
if(!isset($tabsClass['guestbook'])){
?>
removeItselfById('category-move-button');
Expand All @@ -215,7 +227,7 @@ function toggleThisTr(tr, isActive) {
})(jQuery);
//]]>
</script>

<div id="part-post-comment" class="part">
<h2 class="caption">
<span class="main-text"><?php echo (isset($tabsClass['guestbook']) ? _t('등록된 방명록 목록입니다') : _t('등록된 댓글 목록입니다'));?></span>
Expand All @@ -226,7 +238,7 @@ function toggleThisTr(tr, isActive) {
<span class="filter-codition"><?php echo htmlspecialchars($name);?></span>
<?php
}

if (strlen($ip) > 0) {
?>
<span class="filter-codition"><?php echo htmlspecialchars($ip);?></span>
Expand Down Expand Up @@ -280,6 +292,8 @@ function toggleThisTr(tr, isActive) {
<div id="delete-section-top" class="section">
<span class="label"><?php echo _t('선택한 댓글을');?></span>
<input type="button" class="delete-button input-button" value="<?php echo _t('삭제');?>" onclick="deleteComments();" />
<span class="label"><?php echo _t('선택한 댓글을 삭제할 때 해당 댓글과 동일한 IP에서 발송된 댓글들도 함께 삭제합니다');?></span>
<input type="checkbox" id="deleteCommentsFromSameIP" class="checkbox" />
</div>

<table class="data-inbox" cellspacing="0" cellpadding="0">
Expand All @@ -300,38 +314,38 @@ function toggleThisTr(tr, isActive) {
$ipNumber = array();
for ($i=0; $i<sizeof($comments); $i++) {
$comment = $comments[$i];

$filter = new Filter();
if (Filter::isFiltered('name', $comment['name']))
$isNameFiltered = true;
else
$isNameFiltered = false;

if (Filter::isFiltered('ip', $comment['ip']))
$isIpFiltered = true;
else
$isIpFiltered = false;

if (!isset($nameNumber[$comment['name']])) {
$nameNumber[$comment['name']] = $i;
$currentNumber = $i;
} else {
$currentNumber = $nameNumber[$comment['name']];
}

if (!isset($ipNumber[$comment['ip']])) {
$ipNumber[$comment['ip']] = $i;
$currentIP = $i;
} else {
$currentIP = $ipNumber[$comment['ip']];
}

$className = ($i % 2) == 1 ? 'even-line' : 'odd-line';
$className .= $comment['parent'] ? ' reply-line' : null;
$className .= ($i == sizeof($comments) - 1) ? ' last-line' : '';
?>
<tr class="<?php echo $className;?> inactive-class" onmouseover="rolloverClass(this, 'over');return false;" onmouseout="rolloverClass(this, 'out');return false">
<td class="selection"><input type="checkbox" class="checkbox" name="entry" value="<?php echo $comment['id'];?>"/></td>
<td class="selection"><input type="checkbox" class="checkbox" name="entry" value="<?php echo $comment['id'];?>" ip="<?php echo $comment['ip'];?>"/></td>
<td class="date"><?php echo Timestamp::formatDate($comment['written']);?></td>
<td class="name">
<?php
Expand Down Expand Up @@ -359,10 +373,10 @@ function toggleThisTr(tr, isActive) {
echo '<span class="divider"> | </span>';
}
}
if(empty($comment['parent']))

if(empty($comment['parent']))
echo '<span class="explain">' . (isset($tabsClass['guestbook']) ? _f('%1 님의 방명록',$comment['name']) : _f('%1 님의 댓글',$comment['name'])) . '</span>';
else
else
echo '<span class="explain">' . (isset($tabsClass['guestbook']) ? _f('%1 님의 방명록에 대한 댓글',$comment['parentName']) : _f('%1 님의 댓글에 대한 댓글',$comment['parentName'])) . '</span>';
echo "</a>";

Expand Down Expand Up @@ -402,19 +416,19 @@ function toggleThisTr(tr, isActive) {
if (sizeof($comments) > 0) echo " </tbody>";
?>
</table>

<hr class="hidden" />

<div class="data-subbox">
<input type="hidden" name="page" value="<?php echo $suri['page'];?>" />
<input type="hidden" name="name" value="" />
<input type="hidden" name="ip" value="" />

<div id="delete-section" class="section">
<span class="label"><?php echo _t('선택한 댓글을');?></span>
<input type="button" class="delete-button input-button" value="<?php echo _t('삭제');?>" onclick="deleteComments();" />
</div>

<div id="page-section" class="section">
<div id="page-navigation">
<span id="page-list">
Expand All @@ -431,8 +445,8 @@ function toggleThisTr(tr, isActive) {
</div>
<div class="page-count">
<?php echo getArrayValue(explode('%1', _t('한 페이지에 글 %1건 표시')), 0);?>
<select name="perPage" onchange="document.getElementById('list-form').page.value=1; document.getElementById('list-form').submit()">

<select name="perPage" onchange="document.getElementById('list-form').page.value=1; document.getElementById('list-form').submit()">
<?php
for ($i = 10; $i <= 30; $i += 5) {
if ($i == $perPage) {
Expand All @@ -450,7 +464,7 @@ function toggleThisTr(tr, isActive) {
<?php echo getArrayValue(explode('%1', _t('한 페이지에 글 %1건 표시')), 1);?>
</div>
</div>

<div id="data-description" class="section">
<h2><?php echo _t('기능 설명');?></h2>
<dl class="ban-description">
Expand All @@ -464,12 +478,12 @@ function toggleThisTr(tr, isActive) {
</div>
</div>
</form>

<hr class="hidden" />

<form id="search-form" class="data-subbox" method="post" action="<?php echo $context->getProperty('uri.blog');?>/owner/communication/comment">
<h2><?php echo _t('검색');?></h2>

<div class="section">
<label for="search"><?php echo _t('제목');?>, <?php echo _t('내용');?></label>
<input type="text" id="search" class="input-text" name="search" value="<?php echo htmlspecialchars($search);?>" onkeydown="if (event.keyCode == '13') { document.getElementById('search-form').withSearch.value = 'on'; document.getElementById('search-form').submit(); }" />
Expand Down

0 comments on commit d39a1ec

Please sign in to comment.