$i = 0;
foreach ($sql as $rs) {
$i++;
- if (empty($rs['author'])) {
- $rs['author'] = ANONYMOUS;
- }
-
- $fullBody = $rs['body'];
- $summary = serendipity_mb('substr', $rs['body'], 0, $summaryLength);
+ $comment = array(
+ 'fullBody' => $rs['body'],
+ 'summary' => serendipity_mb('substr', $rs['body'], 0, $summaryLength),
+ 'status' => $rs['status'],
+ 'type' => $rs['type'],
+ 'id' => $rs['id'],
+ 'title' => $rs['title'],
+ 'timestamp' => $rs['timestamp'],
+ 'referer' => $rs['referer'],
+ 'url' => $rs['url'],
+ 'ip' => $rs['ip'],
+ 'email' => $rs['email'],
+ 'author' => (empty($rs['author']) ? ANONYMOUS : $rs['author']),
+ 'entry_id' => $rs['entry_id']
+ );
- if (strlen($fullBody) > strlen($summary) ) {
- $summary .= ' ...';
- $excerpt = true;
+ 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.
- $fullBody = nl2br(htmlspecialchars($fullBody));
- $summary = nl2br(strip_tags($summary));
+ $comment['fullBody'] = nl2br(htmlspecialchars($comment['fullBody']));
+ $comment['summary'] = nl2br(strip_tags($comment['summary']));
} else {
- $excerpt = false;
+ $comment['excerpt'] = false;
- $fullBody = $summary = nl2br(htmlspecialchars($fullBody));
+ $comment['fullBody'] = $comment['summary'] = nl2br(htmlspecialchars($comment['fullBody']));
}
+ serendipity_plugin_api::hook_event('backend_view_comment', $comment);
$class = 'serendipity_admin_list_item_' . (($i % 2 == 0 ) ? 'even' : 'uneven');
- $header_class = ($rs['status'] == 'pending' ? 'serendipityAdminMsgNote' : '');
+ $header_class = ($comment['status'] == 'pending' ? 'serendipityAdminMsgNote' : '');
?>
<tr>
- <td class="<?php echo $header_class; ?>"><a name="c<?php echo $rs['id'] ?>"></a>
- <?php echo ($rs['type'] == 'NORMAL' ? COMMENT : TRACKBACK) . ' #'. $rs['id'] .', '. IN_REPLY_TO .' <strong>'. $rs['title'] .'</strong>, '. ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime('%b %e %Y, %H:%M', $rs['timestamp']))?>
+ <td class="<?php echo $header_class; ?>"><a name="c<?php echo $comment['id'] ?>"></a>
+ <?php echo ($comment['type'] == 'NORMAL' ? COMMENT : TRACKBACK) . ' #'. $comment['id'] .', '. IN_REPLY_TO .' <strong>'. $comment['title'] .'</strong>, '. ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime('%b %e %Y, %H:%M', $comment['timestamp']))?>
</td>
</tr>
<tr>
- <td class="serendipity_admin_list_item <?php echo $class ?>" id="comment_<?php echo $rs['id'] ?>">
+ <td class="serendipity_admin_list_item <?php echo $class ?>" id="comment_<?php echo $comment['id'] ?>">
<table width="100%" cellspacing="0" cellpadding="3" border="0">
<tr>
- <td rowspan="3" width="20" align="center"><input type="checkbox" name="serendipity[delete][<?php echo $rs['id'] ?>]" value="<?php echo $rs['entry_id'] ?>" onclick="highlightComment('comment_<?php echo $rs['id'] ?>', this.checked)" tabindex="<?php echo $i ?>" /></td>
- <td width="40%"><strong><?php echo AUTHOR ?></strong>: <?php echo htmlspecialchars($rs['author']) ?></td>
+ <td rowspan="3" width="20" align="center"><input type="checkbox" name="serendipity[delete][<?php echo $comment['id'] ?>]" value="<?php echo $comment['entry_id'] ?>" onclick="highlightComment('comment_<?php echo $comment['id'] ?>', this.checked)" tabindex="<?php echo $i ?>" /></td>
+ <td width="40%"><strong><?php echo AUTHOR ?></strong>: <?php echo htmlspecialchars($comment['author']) ?></td>
<td><strong><?php echo EMAIL ?></strong>:
<?php
- if ( empty($rs['email']) ) {
+ if ( empty($comment['email']) ) {
echo 'N/A';
} else {
?>
- <a href="mailto:<?php echo htmlspecialchars($rs['email']) ?>"><?php echo htmlspecialchars($rs['email']) ?></a>
+ <a href="mailto:<?php echo htmlspecialchars($comment['email']) ?>"><?php echo htmlspecialchars($comment['email']) ?></a>
<?php } ?></td>
</tr>
<tr>
<td width="40%"><strong>IP</strong>:
<?php
- if ( empty($rs['ip']) ) {
+ if ( empty($comment['ip']) ) {
echo '0.0.0.0';
} else {
- echo htmlspecialchars($rs['ip']);
+ echo htmlspecialchars($comment['ip']);
}
?></td>
<td><strong><?php echo URL; ?></strong>:
<?php
- if ( empty($rs['url']) ) {
+ if ( empty($comment['url']) ) {
echo 'N/A';
} else {
?>
- <a href="<?php echo htmlspecialchars($rs['url']) ?>" target="_blank"><?php echo htmlspecialchars($rs['url']) ?></a>
+ <a href="<?php echo htmlspecialchars($comment['url']) ?>" target="_blank"><?php echo htmlspecialchars($comment['url']) ?></a>
<?php } ?></td>
</tr>
<tr>
<td width="40%"> </td>
<td><strong><?php echo REFERER; ?></strong>:
<?php
- if ( empty($rs['referer']) ) {
+ if ( empty($comment['referer']) ) {
echo 'N/A';
} else {
?>
- <a href="<?php echo htmlspecialchars($rs['referer']) ?>" title="<?php echo htmlspecialchars($rs['referer']) ?>"><?php echo htmlspecialchars(serendipity_truncateString($rs['referer'],30)) ?></a>
+ <a href="<?php echo htmlspecialchars($comment['referer']) ?>" title="<?php echo htmlspecialchars($comment['referer']) ?>"><?php echo htmlspecialchars(serendipity_truncateString($comment['referer'],30)) ?></a>
<?php } ?></td>
<tr>
<td style="border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC" colspan="3">
- <div id="<?php echo $rs['id'] ?>_summary"><?php echo $summary ?></div>
- <div id="<?php echo $rs['id'] ?>_full" style="display: none"><?php echo $fullBody ?></div>
+ <div id="<?php echo $comment['id'] ?>_summary"><?php echo $comment['summary'] ?></div>
+ <div id="<?php echo $comment['id'] ?>_full" style="display: none"><?php echo $comment['fullBody'] ?></div>
</td>
</tr>
</table>
-<?php if ($rs['status'] == 'pending') { ?>
- <a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=approve&serendipity[id]=<?php echo $rs['id'] ?>&<?php echo serendipity_setFormToken('url'); ?>" class="serendipityIconLink" title="<?php echo APPROVE; ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/accept.png'); ?>" alt="<?php echo APPROVE ?>" /><?php echo APPROVE ?></a>
+<?php if ($comment['status'] == 'pending') { ?>
+ <a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=approve&serendipity[id]=<?php echo $comment['id'] ?>&<?php echo serendipity_setFormToken('url'); ?>" class="serendipityIconLink" title="<?php echo APPROVE; ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/accept.png'); ?>" alt="<?php echo APPROVE ?>" /><?php echo APPROVE ?></a>
<?php } ?>
-<?php if ($excerpt) { ?>
- <a href="#c<?php echo $rs['id'] ?>" onclick="FT_toggle(<?php echo $rs['id'] ?>); return false;" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo VIEW; ?>" /><span id="<?php echo $rs['id'] ?>_text"><?php echo VIEW ?></span></a>
+<?php if ($comment['excerpt']) { ?>
+ <a href="#c<?php echo $comment['id'] ?>" onclick="FT_toggle(<?php echo $comment['id'] ?>); return false;" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo VIEW; ?>" /><span id="<?php echo $comment['id'] ?>_text"><?php echo VIEW ?></span></a>
<?php } ?>
- <a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=edit&serendipity[id]=<?php echo $rs['id'] ?>&serendipity[entry_id]=<?php echo $rs['entry_id'] ?>&<?php echo serendipity_setFormToken('url'); ?>" title="<?php echo EDIT; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?>" alt="<?php echo EDIT; ?>" /><?php echo EDIT ?></a>
- <a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=delete&serendipity[id]=<?php echo $rs['id'] ?>&serendipity[entry_id]=<?php echo $rs['entry_id'] ?>&<?php echo serendipity_setFormToken('url'); ?>" onclick='return confirm("<?php echo sprintf(COMMENT_DELETE_CONFIRM, $rs['id'], htmlspecialchars($rs['author'])) ?>")' title="<?php echo DELETE ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png'); ?>" alt="<?php echo DELETE; ?>" /><?php echo DELETE ?></a>
+ <a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=edit&serendipity[id]=<?php echo $comment['id'] ?>&serendipity[entry_id]=<?php echo $comment['entry_id'] ?>&<?php echo serendipity_setFormToken('url'); ?>" title="<?php echo EDIT; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?>" alt="<?php echo EDIT; ?>" /><?php echo EDIT ?></a>
+ <a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=delete&serendipity[id]=<?php echo $comment['id'] ?>&serendipity[entry_id]=<?php echo $comment['entry_id'] ?>&<?php echo serendipity_setFormToken('url'); ?>" onclick='return confirm("<?php echo sprintf(COMMENT_DELETE_CONFIRM, $comment['id'], htmlspecialchars($comment['author'])) ?>")' title="<?php echo DELETE ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png'); ?>" alt="<?php echo DELETE; ?>" /><?php echo DELETE ?></a>
</td>
</tr>
<tr>
@define('PLUGIN_EVENT_XHTMLCLEANUP_DESC', 'This plugin corrects common issues with XHTML markup in entries. It assists in keeping your blog XHTML compliant.');
@define('PLUGIN_EVENT_XHTMLCLEANUP_XHTML', 'Encode XML-parsed data?');
@define('PLUGIN_EVENT_XHTMLCLEANUP_XHTML_DESC', 'This plugin uses a XML parsing method to ensure XHTML validity of your code. This xml parsing may convert already valid entities to unescaped entities, so the plugin encodes all entities after the parsing. Set this flag to OFF if that introduces double encoding for you!');
+@define('PLUGIN_EVENT_XHTMLCLEANUP_UTF8', 'Cleanup UTF-8 entities?');
+@define('PLUGIN_EVENT_XHTMLCLEANUP_UTF8_DESC', 'If enabled, HTMLentities derived from UTF-8 characters will be properly converted and not double-encoded in your output.');
if (!function_exists('html_entity_decode')) {
function html_entity_decode($given_html, $quote_style = ENT_QUOTES) {
$propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
- $propbag->add('version', '1.3');
+ $propbag->add('version', '1.4');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
));
$propbag->add('groups', array('BACKEND_TEMPLATES'));
$propbag->add('cachable_events', array('frontend_display' => true));
- $propbag->add('event_hooks', array('frontend_display' => true));
+ $propbag->add('event_hooks', array(
+ 'frontend_display' => true,
+ 'frontend_display:html:per_entry' => true,
+ 'backend_view_comment' => true
+ ));
$this->markup_elements = array(
array(
$conf_array[] = $element['name'];
}
$conf_array[] = 'xhtml_parse';
+ $conf_array[] = 'utf8_parse';
$propbag->add('configuration', $conf_array);
}
function introspect_config_item($name, &$propbag)
{
- if ($name == 'xhtml_parse') {
+ if ($name == 'utf8_parse') {
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_UTF8);
+ $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_UTF8_DESC);
+ $propbag->add('default', 'true');
+ } elseif ($name == 'xhtml_parse') {
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_XHTML);
$propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_XHTML_DESC);
return true;
}
+ function fixUTFEntity(&$string) {
+ $string = preg_replace('/&#(x[a-f0-9]{1,4}|[0-9]{1,5});/', '&#$1;', $string);
+ return true;
+ }
+
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
-
+ static $convert_fields = array(
+ 'fullBody',
+ 'summary',
+ 'title',
+ 'author',
+ );
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
+ case 'backend_view_comment':
+ if (serendipity_db_bool($this->get_config('utf8_parse'))) {
+ foreach($convert_fields AS $convert_field) {
+ $this->fixUTFEntity($eventData[$convert_field]);
+ }
+ }
+ return true;
+ break;
+
case 'frontend_display':
$this->cleanup_parse = serendipity_db_bool($this->get_config('xhtml_parse'));
foreach ($this->markup_elements as $temp) {
}
}
+ if (serendipity_db_bool($this->get_config('utf8_parse'))) {
+ $this->fixUTFEntity($eventData['author']);
+ $this->fixUTFEntity($eventData['comment']);
+ }
+
+ return true;
+ break;
+
+ case 'frontend_display:html:per_entry':
+ if (serendipity_db_bool($this->get_config('utf8_parse'))) {
+ $this->fixUTFEntity($eventData['title']);
+ }
+
return true;
break;