还原Drupal的Blog评论模式
来源:互联网 发布:淘宝代运营服务项目 编辑:程序博客网 时间:2024/05/19 20:46
一直以来对于 Drupal 最不满意的就是必须用email注册来回复否则只能匿名回复,毕竟 Drupal 是一个以 blog 为主的系统,不是论坛,所以决定把Blog的评论模式还给 Drupal,按照 movabletype 的样式重新打造评论模块。
两点说明:1、方法非官方,事先请备份文件。2、参考自davidnunez的Anonymous Comments Hack
具体方法:
1.在数据库中的comments表添加3列:cnme, ceml, curl
sql语句:
ALTER TABLE comments ADD ceml varchar(64) DEFAULT NULL;
ALTER TABLE comments ADD curl varchar(255) DEFAULT NULL;
2.改includes/common.inc
将其中的format_name方法替换为:
function format_name($object) {
if ($object->uid && $object->name) {
/*
** Shorten the name when it is too long or it will break many
** tables.
*/
if (strlen($object->name) > 20) {
$name = truncate_utf8($object->name, 15) ."...";
}
else {
$name = $object->name;
}
if (arg(0) == "admin" and user_access("administer users")) {
$output = l($name, "admin/user/edit/$object->uid", array("title" => t("Administer user profile.")));
}
else {
$output = l($name, "user/view/$object->uid", array("title" => t("View user profile.")));
}
}
else if ($object->name) {
/*
** Sometimes modules display content composed by people who are
** not registers members of the site (i.e. mailing list or news
** aggregator modules). This clause enables modules to display
** the true author of the content.
*/
$output = $object->name;
}
//******HACK
else if ($object->cnme) {
if ($object->curl) {
$pos = strpos($object->curl, "http://");
if (is_int($pos)) {
$output = l($object->cnme, "$object->curl");
}
else {
$output = l($object->cnme, "curl/">http://$object->curl");
}
}
else {
$output = $object->cnme;
}
}
//******END HACK
else {
$output = t(variable_get("anonymous", "Anonymous"));
}
return $output;
}
3.将modules/comment.module里的theme_comment_form方法替换为:
function theme_comment_form($edit, $title) {
global $user;
$form .= "/n";
//******HACKED
// name field:
//$form .= form_item(t("Your name"), format_name($user));
if (!empty($user->name)) {
$form .= form_item(t("Your name"), format_name($user));
} else {
$form .= form_textfield(t("Your name"), "cnme", $edit["cnme"], 50, 64);
$form .= form_textfield(t("E-Mail (Optional)"), "ceml", $edit["ceml"], 50,64);
$form .= form_textfield(t("Web Site (Optional)"), "curl", $edit["curl"], 50,64, "Be sure to start with http://");
}
//******
// subject field:
$form .= form_textfield(t("Subject"), "subject", $edit["subject"], 50, 64);
// comment field:
$form .= form_textarea(t("Comment"), "comment", $edit["comment"] ? $edit["comment"] : $user->signature, 70, 10, filter_tips_short());
// preview button:
$form .= form_hidden("cid", $edit["cid"]);
$form .= form_hidden("pid", $edit["pid"]);
$form .= form_hidden("nid", $edit["nid"]);
if (!$edit["comment"] && variable_get("comment_preview", 1)) {
$form .= form_submit(t("Preview comment"));
}
else {
$form .= form_submit(t("Preview comment"));
$form .= form_submit(t("Post comment"));
}
return theme("box", $title, form($form, "post", url("comment/reply/". $edit["nid"])));
}
4.将modules/comment.module中的对应语句替换(注意是db_query的INSERT INTO语句
VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit["cid"], $edit["nid"],
$edit["pid"], $user->uid, $edit["subject"], $edit["comment"],
$_SERVER['REMOTE_ADDR'], time(), $status, $score, $users, $thread, $edit["cnme"], $edit["ceml"], $edit["curl"]);
5.更改所使用的theme模板文件
如果使用的是xtemplate更改xtemplate.theme内相应方法:
function xtemplate_comment($comment, $links = 0) {
global $xtemplate;
//**********HACK
$result = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = %d", $comment->cid));
$comment->cnme=$result->cnme;
$comment->curl=$result->curl;
$comment->ceml=$result->ceml;
//**********END HACK
$xtemplate->template->assign(array (
"new" => t("new"),
"submitted" => t("Submitted by %a on %b.",
array("%a" => format_name($comment),
"%b" => format_date($comment->timestamp))),
"title" => $comment->subject,
"author" => format_name($comment),
"date" => format_date($comment->timestamp),
"content" => $comment->comment
));
if ($comment->new) {
$xtemplate->template->parse("comment.new");
}
if ($picture = theme('user_picture', $comment)) {
$xtemplate->template->assign("picture", $picture);
$xtemplate->template->parse("comment.picture");
}
if ($links) {
$xtemplate->template->assign("links", $links);
$xtemplate->template->parse("comment.links");
}
$xtemplate->template->parse("comment");
$output = $xtemplate->template->text("comment");
$xtemplate->template->reset("comment");
return $output;
}
如果使用phptemplate将phptemplate.theme内对应方法改为:
function phptemplate_comment_view($comment, $links = "", $visible = 1) {
//**********HACK
$result = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = %d", $comment->cid));
$comment->cnme=$result->cnme;
$comment->curl=$result->curl;
$comment->ceml=$result->ceml;
//**********END HACK
$output = "";
if (node_is_new($comment->nid, $comment->timestamp)) {
$comment->new = 1;
}
if ($visible) {
$comment->comment = check_output($comment->comment);
$output .= theme("comment", $comment, $links);
}
else {
$output .= theme("comment_folded", $comment);
}
return $output;
}
Done!
- 还原Drupal的Blog评论模式
- 在储诚云blog的再次评论
- 用Drupal打造Blog
- 个人感觉drupal就是blog和wiki的合体!
- 商品评论的Tag模式
- 关于设计模式的评论
- JavaScript设计模式的评论
- CSDN的Blog终于加了"最新评论"的功能~~
- 我的blog终于有了来自他人的评论
- 发现几个指向自己BLOG的Trackbacks和评论
- blog读者不愿发表评论的10种心态
- Cs Tip19: 高亮Blog Owner的评论
- blog之评论功能中遇到的问题
- 这个问题真的好麻烦,blog/评论,理想数据库
- 简单Blog项目笔记之七:文章的评论
- 设计模式之禅我的评论
- 【blog推荐】好的设计模式BLOG
- 解决CSDN blog不能评论
- Java行业的圣经-四本最重要的个人藏书
- 数值计算方法程序库
- 随机产生用户密码
- 经典柔情摇滚
- drupal 的简单模板修改
- 还原Drupal的Blog评论模式
- Drupal的Trackback模组的改进
- Drupal区块路径设置的BUG
- 基于Spring+session bean+hibernate的j2ee开发
- 安装Feed2JS
- 使用模板实现ASP代码与页面分离
- 心目中的编程高手
- 最近长牙,喉咙疼的很
- 实现千万级数据的分页显示!