开发者

How to change the title of comment form in drupal

开发者 https://www.devze.com 2023-02-18 08:44 出处:网络
At my website there is \"Login or register to post comments..\" I want to change the message to: \"Login or register to post comments(comments will be moderated)..\"

At my website there is "Login or register to post comments.."

I want to change the message to: "Login or register to post comments(comments will be moderated).."

Because plenty of spammers are just creating logins to post spam comme开发者_如何学Gonts. Although all comments are moderated now. Putting this message will give clear info that spamming may not be possible and spammers will not create logins.


Assuming you are using Drupal 6, the code that creates the comment form is in the file comments.module in the Drupal module directory. Fortunately, the function allows for theming.

What you can do is copy and paste the function theme_comment_post_forbidden($node) and place it in the template.php file in your theme directory. You will also need to rename the function, replacing 'theme' with your theme name.

For example, say your theme name is 'utilitiesindia'. Then you will rename your function to utilitiesindia_comment_post_forbidden.

So, in your template.php file in a theme named utilitiesindia, use this function:

/**
 * Theme a "you can't post comments" notice.
 *
 * @param $node
 *   The comment node.
 * @ingroup themeable
 */
function utiltiesindia_comment_post_forbidden($node) {
  global $user;
  static $authenticated_post_comments;

  if (!$user->uid) {
    if (!isset($authenticated_post_comments)) {
      // We only output any link if we are certain, that users get permission
      // to post comments by logging in. We also locally cache this information.
      $authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, user_roles(TRUE, 'post comments') + user_roles(TRUE, 'post comments without approval'));
    }

    if ($authenticated_post_comments) {
      // We cannot use drupal_get_destination() because these links
      // sometimes appear on /node and taxonomy listing pages.
      if (variable_get('comment_form_location_'. $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
        $destination = 'destination='. rawurlencode("comment/reply/$node->nid#comment-form");
      }
      else {
        $destination = 'destination='. rawurlencode("node/$node->nid#comment-form");
      }

      if (variable_get('user_register', 1)) {
        // Users can register themselves.
        return t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments(comments will be moderated)', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination)))
);
      }
      else {
        // Only admins can add new users, no public registration.
        return t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
      }
    }
  }
}


how to change the comment link text " Login or register to post comment" to be shorter ,eg " comment"

Also you can use String overrides module.


In Drupal 6:
Another option is to create a small custom module. This uses hook_link_alter(). This is a small example module to change the title of the "Login to post new comment" link: (Replace every instance of MYMODULE_NAME with the name you choose for the module)

STEP 1: Create a file called MYMODULE_NAME.info and add:

; $Id$
name = "MYMODULE_NAME"
description = "Change the appearance of links that appear on nodes"
core = 6.x

STEP 2: Create file called MYMODULE_NAME.module and add:

<?php
  // $Id$;

  /**
   * Implementation of hook_link_alter
   */
  function MYMODULE_NAME_link_alter(&$links, $node){
    if (!empty($links['comment_forbidden'])) {
      // Set "Login to post new comment" link text
      $links['comment_forbidden']['title'] = 'NEW TEXT';

      // Add this to allow HTML in the link text
      $links['comment_forbidden']['html'] = TRUE;
    }
  }

STEP 3: Put these files in a folder called MYMODULE_NAME, place the folder in sites/all/modules, and enable the module


If you actually want to stop spammers from creating accounts, you should use something like the CAPTCHA module, since they typically use bots that will ignore instructions in any case.

http://drupal.org/project/captcha

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号