1
0

comments.inc enhancements

This commit is contained in:
Ian
2012-03-03 11:38:13 +01:00
parent 8bf8b28885
commit 5f6b48a9b5
2 changed files with 93 additions and 91 deletions

View File

@ -8,8 +8,9 @@ if (!serendipity_checkPermission('adminComments')) {
return; return;
} }
$codata = array();
$commentsPerPage = (int)(!empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10); $commentsPerPage = (int)(!empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10);
$codata['commentsPerPage'] = $commentsPerPage;
$summaryLength = 200; $summaryLength = 200;
$errormsg = ''; $errormsg = '';
@ -119,7 +120,7 @@ if (isset($serendipity['GET']['adminAction']) && ($serendipity['GET']['adminActi
serendipity_smarty_init(); serendipity_smarty_init();
if ($serendipity['GET']['adminAction'] == 'reply' || $serendipity['GET']['adminAction'] == 'doReply') { if ($serendipity['GET']['adminAction'] == 'reply' || $serendipity['GET']['adminAction'] == 'doReply') {
$c = serendipity_fetchComments($serendipity['GET']['entry_id'], 1, 'co.id', false, 'NORMAL', ' AND co.id=' . (int)$serendipity['GET']['id']); $c = serendipity_fetchComments($serendipity['GET']['entry_id'], 1, 'co.id', false, 'NORMAL', ' AND co.id=' . (int)$serendipity['GET']['id']);
if (isset($serendipity['POST']['preview'])) { if (isset($serendipity['POST']['preview'])) {
$c[] = array( $c[] = array(
@ -272,81 +273,85 @@ if ($commentsPerPage == COMMENTS_FILTER_ALL) {
$limit = serendipity_db_limit_sql(serendipity_db_limit(($page-1)*(int)$commentsPerPage, (int)$commentsPerPage)); $limit = serendipity_db_limit_sql(serendipity_db_limit(($page-1)*(int)$commentsPerPage, (int)$commentsPerPage));
} }
$sql = serendipity_db_query("SELECT c.*, e.title FROM {$serendipity['dbPrefix']}comments c $sql = serendipity_db_query("SELECT c.*, e.title FROM {$serendipity['dbPrefix']}comments c
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id) LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)
WHERE 1 = 1 " . ($c_type !== null ? " AND c.type = '$c_type' " : '') . $and WHERE 1 = 1 " . ($c_type !== null ? " AND c.type = '$c_type' " : '') . $and
. (!serendipity_checkPermission('adminEntriesMaintainOthers') ? 'AND e.authorid = ' . (int)$serendipity['authorid'] : '') . " . (!serendipity_checkPermission('adminEntriesMaintainOthers') ? 'AND e.authorid = ' . (int)$serendipity['authorid'] : '') . "
ORDER BY c.id DESC $limit"); ORDER BY c.id DESC $limit");
$codata['totalComments'] = $totalComments; $codata['commentsPerPage'] = $commentsPerPage;
$codata['pages'] = $pages; $codata['totalComments'] = $totalComments;
$codata['page'] = $page; $codata['pages'] = $pages;
$codata['linkPrevious'] = $linkPrevious; $codata['page'] = $page;
$codata['linkNext'] = $linkNext; $codata['linkPrevious'] = $linkPrevious;
$codata['searchString'] = $searchString; $codata['linkNext'] = $linkNext;
$codata['filter_vals'] = $filter_vals; $codata['searchString'] = $searchString;
$codata['sql'] = $sql; $codata['filter_vals'] = $filter_vals;
$codata['c_type'] = $c_type; $codata['sql'] = $sql;
$codata['c_type'] = $c_type;
$i = 0; $i = 0;
$comments = array(); $comments = array();
foreach ($sql as $rs) { if(is_array($sql)) {
$i++; foreach ($sql as $rs) {
$comment = array( $i++;
'fullBody' => $rs['body'], $comment = array(
'summary' => serendipity_mb('substr', $rs['body'], 0, $summaryLength), 'fullBody' => $rs['body'],
'status' => $rs['status'], 'summary' => serendipity_mb('substr', $rs['body'], 0, $summaryLength),
'type' => $rs['type'], 'status' => $rs['status'],
'id' => $rs['id'], 'type' => $rs['type'],
'title' => $rs['title'], 'id' => $rs['id'],
'timestamp' => $rs['timestamp'], 'title' => $rs['title'],
'pubdate' => date("c", (int)$rs['timestamp']), /* added to comment array to support HTML5 time tags in tpl */ 'timestamp' => $rs['timestamp'],
'referer' => $rs['referer'], 'pubdate' => date("c", (int)$rs['timestamp']), /* added to comment array to support HTML5 time tags in tpl */
'url' => $rs['url'], 'referer' => $rs['referer'],
'ip' => $rs['ip'], 'url' => $rs['url'],
'entry_url' => serendipity_archiveURL($rs['entry_id'], $rs['title']), 'ip' => $rs['ip'],
'email' => $rs['email'], 'entry_url' => serendipity_archiveURL($rs['entry_id'], $rs['title']),
'author' => (empty($rs['author']) ? ANONYMOUS : $rs['author']), 'email' => $rs['email'],
'entry_id' => $rs['entry_id'], 'author' => (empty($rs['author']) ? ANONYMOUS : $rs['author']),
'subscribed'=> $rs['subscribed'] 'entry_id' => $rs['entry_id'],
); 'subscribed'=> $rs['subscribed']
);
$entrylink = serendipity_archiveURL($comment['entry_id'], 'comments', 'serendipityHTTPPath', true) . '#c' . $comment['id']; $entrylink = serendipity_archiveURL($comment['entry_id'], 'comments', 'serendipityHTTPPath', true) . '#c' . $comment['id'];
if (strlen($comment['fullBody']) > strlen($comment['summary']) ) {
$comment['summary'] .= ' ...';
$comment['excerpt'] = true;
// When summary is not the full body, strip HTML tags from summary, as it might break and leave unclosed HTML. if (strlen($comment['fullBody']) > strlen($comment['summary']) ) {
$comment['fullBody'] = nl2br(htmlspecialchars($comment['fullBody'])); $comment['summary'] .= ' ...';
$comment['summary'] = nl2br(strip_tags($comment['summary'])); $comment['excerpt'] = true;
} else {
$comment['excerpt'] = false;
$comment['fullBody'] = $comment['summary'] = nl2br(htmlspecialchars($comment['fullBody'])); // When summary is not the full body, strip HTML tags from summary, as it might break and leave unclosed HTML.
$comment['fullBody'] = nl2br(htmlspecialchars($comment['fullBody']));
$comment['summary'] = nl2br(strip_tags($comment['summary']));
} else {
$comment['excerpt'] = false;
$comment['fullBody'] = $comment['summary'] = nl2br(htmlspecialchars($comment['fullBody']));
}
serendipity_plugin_api::hook_event('backend_view_comment', $comment, '&serendipity[page]='. $page . $searchString);
$class = 'serendipity_admin_list_item_' . (($i % 2 == 0 ) ? 'even' : 'uneven');
if ($comment['status'] == 'pending') {
$class .= ' serendipity_admin_comment_pending';
$header_class = 'serendipityAdminMsgNote serendipity_admin_comment_pending_header';
} elseif (strstr($comment['status'], 'confirm')) {
$class .= ' serendipity_admin_comment_pending serendipity_admin_comment_confirm';
$header_class = 'serendipityAdminMsgNote serendipity_admin_comment_pending_header serendipity_admin_comment_confirm_header';
} else {
$header_class = '';
}
$comment['class'] = $class;
$comment['header_class'] = $header_class;
if (!empty($comment['url']) && substr($comment['url'], 0, 7) != 'http://' && substr($comment['url'], 0, 8) != 'https://') {
$comment['url'] = 'http://' . $comment['url'];
}
// include all comment vars back into upper array to assign to Smarty
$comments[] = $comment;
} }
serendipity_plugin_api::hook_event('backend_view_comment', $comment, '&serendipity[page]='. $page . $searchString);
$class = 'serendipity_admin_list_item_' . (($i % 2 == 0 ) ? 'even' : 'uneven');
if ($comment['status'] == 'pending') {
$class .= ' serendipity_admin_comment_pending';
$header_class = 'serendipityAdminMsgNote serendipity_admin_comment_pending_header';
} elseif (strstr($comment['status'], 'confirm')) {
$class .= ' serendipity_admin_comment_pending serendipity_admin_comment_confirm';
$header_class = 'serendipityAdminMsgNote serendipity_admin_comment_pending_header serendipity_admin_comment_confirm_header';
} else {
$header_class = '';
}
$comment['class'] = $class;
$comment['header_class'] = $header_class;
if (!empty($comment['url']) && substr($comment['url'], 0, 7) != 'http://' &&
substr($comment['url'], 0, 8) != 'https://') {
$comment['url'] = 'http://' . $comment['url'];
}
$comments[] = $comment;
} }
/* This could be used instead, as i.e. there is no need for summary body here, as strip_tags, nl2br, etc could be done via smarty in the tpl - see dashboard PoC */ /* This could be used instead, as i.e. there is no need for summary body here, as strip_tags, nl2br, etc could be done via smarty in the tpl - see dashboard PoC */
@ -399,20 +404,17 @@ foreach ($sql as $rs) {
} }
**/ **/
$codata['comments'] = $comments;
$codata['errormsg'] = $errormsg;
$codata['urltoken'] = serendipity_setFormToken('url');
$codata['formtoken'] = serendipity_setFormToken();
$codata['getfilter'] = $serendipity['GET']['filter']; // don't trust {$smarty.get.vars} as we often change GET vars via serendipty['GET']
if (!is_object($serendipity['smarty'])) { if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init(); serendipity_smarty_init();
} }
$serendipity['smarty']->assign( $serendipity['smarty']->assign($codata); // do not use $data here, as already used above - use i.e. $codata['foo'] = $foo;
array( 'comments' => $comments,
'errormsg' => $errormsg,
'urltoken' => serendipity_setFormToken('url'),
'formtoken' => serendipity_setFormToken()
));
$serendipity['smarty']->assign($codata);
# do not use $data, as already used above - use i.e. $codata['filters'] = $filters;
$tfile = dirname(__FILE__) . "/tpl/comments.inc.tpl"; $tfile = dirname(__FILE__) . "/tpl/comments.inc.tpl";

View File

@ -65,40 +65,39 @@ function highlightComment(id, checkvalue) {
<tr> <tr>
<td colspan="6" class="serendipity_admin_filters_headline"><strong>{$CONST.FILTERS}</strong> - {$CONST.FIND_COMMENTS}</td> <td colspan="6" class="serendipity_admin_filters_headline"><strong>{$CONST.FILTERS}</strong> - {$CONST.FIND_COMMENTS}</td>
</tr> </tr>
{* if we change/set $serendipity{'GET'] values in the parents php file ... does $smarty.get then know about them ??? *}
<tr> <tr>
<td>{$CONST.AUTHOR}:</td> <td>{$CONST.AUTHOR}:</td>
<td><input class="input_textbox" type="text" name="serendipity[filter][author]" size="15" value="{$smarty.get.filter.author|escape}" /></td> <td><input class="input_textbox" type="text" name="serendipity[filter][author]" size="15" value="{$getfilter.author|escape}" /></td>
<td>{$CONST.EMAIL}:</td> <td>{$CONST.EMAIL}:</td>
<td><input class="input_textbox" type="text" name="serendipity[filter][email]" size="15" value="{$smarty.get.filter.email|escape}" /></td> <td><input class="input_textbox" type="text" name="serendipity[filter][email]" size="15" value="{$getfilter.email|escape}" /></td>
<td>{$CONST.URL}:</td> <td>{$CONST.URL}:</td>
<td><input class="input_textbox" type="text" name="serendipity[filter][url]" size="15" value="{$smarty.get.filter.url|escape}" /></td> <td><input class="input_textbox" type="text" name="serendipity[filter][url]" size="15" value="{$getfilter.url|escape}" /></td>
</tr> </tr>
<tr> <tr>
<td>IP:</td> <td>IP:</td>
<td><input class="input_textbox" type="text" name="serendipity[filter][ip]" size="15" value="{$smarty.get.filter.ip|escape}" /></td> <td><input class="input_textbox" type="text" name="serendipity[filter][ip]" size="15" value="{$getfilter.ip|escape}" /></td>
<td>{$CONST.CONTENT}:</td> <td>{$CONST.CONTENT}:</td>
<td><input class="input_textbox" type="text" name="serendipity[filter][body]" size="15" value="{$smarty.get.filter.body|escape}" /></td> <td><input class="input_textbox" type="text" name="serendipity[filter][body]" size="15" value="{$getfilter.body|escape}" /></td>
<td>{$CONST.REFERER}:</td> <td>{$CONST.REFERER}:</td>
<td><input class="input_textbox" type="text" name="serendipity[filter][referer]" size="15" value="{$smarty.get.filter.referer|escape}" /></td> <td><input class="input_textbox" type="text" name="serendipity[filter][referer]" size="15" value="{$getfilter.referer|escape}" /></td>
</tr> </tr>
<tr> <tr>
<td>{$CONST.COMMENTS}:</td> <td>{$CONST.COMMENTS}:</td>
<td> <td>
<select name="serendipity[filter][perpage]">
{* Smarty 3 does support ternary syntax e.g. {('N'==$foo)?'Yes':'No'} *} {* Smarty 3 does support ternary syntax e.g. {('N'==$foo)?'Yes':'No'} *}
{foreach $filter_vals AS $filter_val} <select name="serendipity[filter][perpage]">
<option value="{$filter_val}" {($commentsPerPage == $filter_val) ? ' selected="selected"' : ''}>{$filter_val}</option> {foreach $filter_vals AS $filter}
<option value="{$filter}" {($commentsPerPage == $filter) ? ' selected="selected"' : ''}>{$filter}</option>
{/foreach} {/foreach}
</select> </select>
</td> </td>
<td>{$CONST.COMMENTS_FILTER_SHOW}:</td> <td>{$CONST.COMMENTS_FILTER_SHOW}:</td>
<td> <td>
<select name="serendipity[filter][show]"> <select name="serendipity[filter][show]">
<option value="all"{if $smarty.get.filter.show == 'all'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_ALL}</option> <option value="all"{if $getfilter.show == 'all'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_ALL}</option>
<option value="approved"{if $smarty.get.filter.show == 'approved'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_APPROVED_ONLY}</option> <option value="approved"{if $getfilter.show == 'approved'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_APPROVED_ONLY}</option>
<option value="pending"{if $smarty.get.filter.show == 'pending'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_NEED_APPROVAL}</option> <option value="pending"{if $getfilter.show == 'pending'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_NEED_APPROVAL}</option>
<option value="confirm"{if $smarty.get.filter.show == 'confirm'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_NEED_CONFIRM}</option> <option value="confirm"{if $getfilter.show == 'confirm'} selected="selected"{/if}>{$CONST.COMMENTS_FILTER_NEED_CONFIRM}</option>
</select> </select>
</td> </td>
<td>{$CONST.TYPE}</td> <td>{$CONST.TYPE}</td>
@ -121,6 +120,7 @@ function highlightComment(id, checkvalue) {
{if !is_array($sql)} {if !is_array($sql)}
<div align="center">- {$CONST.NO_COMMENTS} -</div> <div align="center">- {$CONST.NO_COMMENTS} -</div>
<div align="center">- Click button "{$CONST.GO}" again, please. -</div>
{else} {else}
<form action="" method="POST" name="formMultiDelete" id="formMultiDelete"> <form action="" method="POST" name="formMultiDelete" id="formMultiDelete">