还原Drupal的Blog评论模式

一直以来对于 Drupal 最不满意的就是必须用email注册来回复否则只能匿名回复,毕竟 Drupal 是一个以 blog 为主的系统,不是论坛,所以决定把Blog的评论模式还给 Drupal,按照 movabletype 的样式重新打造评论模块。

两点说明:1、方法非官方,事先请备份文件。2、参考自davidnunez的Anonymous Comments Hack

具体方法:

1.在数据库中的comments表添加3列:cnme, ceml, curl
sql语句:

ALTER TABLE comments ADD cnme varchar(60) DEFAULT NULL;
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语句

db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users, thread, cnme, ceml, curl)
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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值