You are here

function edit_limit_comment_access in Edit Limit 6

Same name and namespace in other branches
  1. 7 edit_limit.module \edit_limit_comment_access()

Access check function to see if the user can still edit the comment or not. It must, at minimum, perform the comment module's access checks first.

1 string reference to 'edit_limit_comment_access'
edit_limit_menu_alter in ./edit_limit.module
Implement hook_menu_alter().

File

./edit_limit.module, line 132
edit_limit.module Primary module file for Edit Limit. This contains all the hooks needed to run the module.

Code

function edit_limit_comment_access() {
  if (user_access('post comments')) {
    if (user_access('bypass edit limit')) {
      return TRUE;
    }
    $return = TRUE;
    if (variable_get('edit_limit_comment_time_enabled', FALSE)) {

      // By this point, we want to return false if the time has passed.
      $cid = intval(arg(2));
      $timestamp = db_result(db_query("SELECT timestamp FROM {comments} WHERE cid=%d", $cid));
      if ($timestamp + intval(variable_get('edit_limit_comment_time', EDIT_LIMIT_COMMENT_TIME)) < time()) {
        $return = FALSE;
      }
      else {
        static $seconds;
        if (empty($seconds)) {
          drupal_add_js(drupal_get_path('module', 'edit_limit') . '/edit_limit.js');
          $seconds = $timestamp + intval(variable_get('edit_limit_comment_time', EDIT_LIMIT_COMMENT_TIME)) - time();
        }
        $type = 'status';
        drupal_set_message(t('You have !seconds seconds left to edit this comment.', array(
          '!seconds' => $seconds,
        )), $type, FALSE);
      }
    }
    return $return;
  }
  return FALSE;
}