📄 serendipity_plugin_comments.php
字号:
<?php # $Id: serendipity_plugin_comments.php,v 1.16.4.2 2004/04/13 10:01:14 garvinhicking Exp $
/*******************************************************汉化作者:youngong(http://youngong.blogbus.com) **官方主页:http://www.s9y.corg **我的信箱:youngong@163.com **如果有问题,欢迎和作者及汉化作者联系。 ********************************************************/
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_COMMENTS_BLAHBLAH', 'Zeigt die letzten Kommentare');
@define('PLUGIN_COMMENTS_WORDWRAP', 'Zeilenumbruch');
@define('PLUGIN_COMMENTS_WORDWRAP_BLAHBLAH', 'Nach wievielen W鰎tern soll ein Zeilenumbruch eingef黦t werden? (Standard: 30)');
@define('PLUGIN_COMMENTS_MAXCHARS', 'Zeichen pro Kommentar');
@define('PLUGIN_COMMENTS_MAXCHARS_BLAHBLAH', 'Wieviele Zeichen sollen pro Kommentar gezeigt werden? (Standard: 120)');
@define('PLUGIN_COMMENTS_MAXENTRIES', 'Anzahl an Kommentaren');
@define('PLUGIN_COMMENTS_MAXENTRIES_BLAHBLAH', 'Wieviele Kommentare sollen gezeigt werden? (Standard: 15)');
@define('PLUGIN_COMMENTS_ABOUT', '%s zu%s');
break;
case 'cn':
@define('PLUGIN_COMMENTS_BLAHBLAH', '显示最近的评论');
@define('PLUGIN_COMMENTS_WORDWRAP', '词语限制');
@define('PLUGIN_COMMENTS_WORDWRAP_BLAHBLAH', '词语限制数? (默认:30)');
@define('PLUGIN_COMMENTS_MAXCHARS', '评论最多字数');
@define('PLUGIN_COMMENTS_MAXCHARS_BLAHBLAH', '每个评论显示多少字? (默认:120)');
@define('PLUGIN_COMMENTS_MAXENTRIES', '评论最多次数');
@define('PLUGIN_COMMENTS_MAXENTRIES_BLAHBLAH', '显示多少评论? (默认:15)');
@define('PLUGIN_COMMENTS_ABOUT', '%s 关于%s');
break;
case 'en':
case 'es':
default:
@define('PLUGIN_COMMENTS_BLAHBLAH', 'Displays the last comments to your entries');
@define('PLUGIN_COMMENTS_WORDWRAP', 'Wordwrap');
@define('PLUGIN_COMMENTS_WORDWRAP_BLAHBLAH', 'How many words until a wordwrap will occur? (Default: 30)');
@define('PLUGIN_COMMENTS_MAXCHARS', 'Maximum chars per comment');
@define('PLUGIN_COMMENTS_MAXCHARS_BLAHBLAH', 'How many chars will be displayed for each comment? (Default: 120)');
@define('PLUGIN_COMMENTS_MAXENTRIES', 'Maximum number of comments');
@define('PLUGIN_COMMENTS_MAXENTRIES_BLAHBLAH', 'How many comments will be shown? (Default: 15)');
@define('PLUGIN_COMMENTS_ABOUT', '%s about%s');
break;
}
class serendipity_plugin_comments extends serendipity_plugin
{
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', COMMENTS);
$propbag->add('description', PLUGIN_COMMENTS_BLAHBLAH);
$propbag->add('configuration', array(
'wordwrap',
'max_chars',
'max_entries',
'dateformat'));
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'wordwrap':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_COMMENTS_WORDWRAP);
$propbag->add('description', PLUGIN_COMMENTS_WORDWRAP_BLAHBLAH);
break;
case 'max_chars':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_COMMENTS_MAXCHARS);
$propbag->add('description', PLUGIN_COMMENTS_MAXCHARS_BLAHBLAH);
break;
case 'max_entries':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_COMMENTS_MAXENTRIES);
$propbag->add('description', PLUGIN_COMMENTS_MAXENTRIES_BLAHBLAH);
break;
case 'dateformat':
$propbag->add('type', 'string');
$propbag->add('name', GENERAL_PLUGIN_DATEFORMAT);
$propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%a, %m.%m.%Y %H:%M'));
break;
default:
return false;
}
return true;
}
function generate_content(&$title)
{
global $serendipity;
$title = COMMENTS;
$max_entries = $this->get_config('max_entries');
$max_chars = $this->get_config('max_chars');
$wordwrap = $this->get_config('wordwrap');
$dateformat = $this->get_config('dateformat');
if (!$max_entries || !is_numeric($max_entries) || $max_entries < 1) {
$max_entries = 15;
}
if (!$max_chars || !is_numeric($max_chars) || $max_chars < 1) {
$max_chars = 120;
}
if (!$wordwrap || !is_numeric($wordwrap) || $wordwrap < 1) {
$wordwrap = 30;
}
if (!$dateformat || strlen($dateformat) < 1) {
$dateformat = '%a, %d.%m.%Y %H:%M';
}
$q = 'SELECT c.body AS comment,
c.timestamp AS stamp,
c.author AS user,
e.title AS subject,
e.id AS entry_id,
c.id AS comment_id,
c.type AS comment_type,
c.url AS comment_url,
c.title AS comment_title
FROM '.$serendipity['dbPrefix'].'comments AS c,
'.$serendipity['dbPrefix'].'entries AS e
WHERE e.id = c.entry_id
AND NOT (c.type = \'TRACKBACK\' AND c.author = \'' . serendipity_db_escape_string($serendipity['blogTitle']) . '\' AND c.title != \'\')
ORDER BY c.timestamp DESC
LIMIT ' . $max_entries;
?>
<div style="margin: 0px; padding: 0px; text-align: left;">
<?php
$sql = serendipity_db_query($q);
if ($sql && is_array($sql)) {
foreach($sql AS $key => $row) {
$comments = wordwrap(strip_tags($row['comment']), $max_chars, '@@@', 1);
$aComment = explode('@@@', $comments);
$comment = $aComment[0];
if (count($aComment) > 1) {
$commentar .= ' [...]';
}
if ($row['comment_type'] == 'TRACKBACK' && $row['comment_url'] != '') {
$user = '<a class="highlight" href="' . strip_tags($row['comment_url']) . '" title="' . htmlspecialchars(strip_tags($row['comment_title'])) . '">' . htmlspecialchars(strip_tags($row['user'])) . '</a>';
} else {
$user = htmlspecialchars(strip_tags($row['user']));
}
$entry = array('comment' => wordwrap($comment, $wordwrap, "\n", 1));
serendipity_plugin_api::hook_event('frontend_display', $entry);
printf(
PLUGIN_COMMENTS_ABOUT,
$user,
' <a class="highlight" href="' . serendipity_archiveURL($row['entry_id'], $row['subject']) .'#c' . $row['comment_id'] . '" title="' . htmlspecialchars($row['subject']) . '">'
. htmlspecialchars($row['subject'])
. '</a><br />' . "\n"
. htmlspecialchars(strftime($dateformat, $row['stamp'])) . '<br />' . "\n"
. $entry['comment']
. '<br /><br /><br />' . "\n\n"
);
}
}
?>
</div>
<?php
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -