# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -45,6 +45,62 @@
 }

 /**
+ * Implementation of hook_menu_alter().
+ */
+function comment_edited_menu_alter(&$items) {
+  $items['comment/edit']['access callback'] = 'comment_edited_edit_access';
+}
+
+/**
+ * Access callback on comment/edit paths.
+ */
+function comment_edited_edit_access($op) {
+  if (arg(0) != 'comment' || arg(1) != 'edit') {
+    return FALSE;
+  }
+
+  // Code based on core comment_edit() from comment.pages.inc
+  $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', arg(2)));
+  $comment = drupal_unpack($comment);
+  if (comment_edited_past_time_limit($comment)) {
+    return FALSE;
+  }
+
+  return comment_access('edit', $comment);
+}
+
+/**
+ * Implementation of hook_link_alter().
+ *
+ * Note: $comment object only available since Drupal 6.17.
+ * See http://drupal.org/node/374463
+ */
+function comment_edited_link_alter(&$links, $node, $comment = NULL) {
+  if (!is_null($comment) && comment_edited_past_time_limit($comment)) {
+    unset($links['comment_edit']);
+  }
+}
+
+/**
+ * Determines if the edit time limit has passed for a comment
+ */
+function comment_edited_past_time_limit($comment) {
+  if (!user_access('administer comments')) {
+    $node = node_load($comment->nid);
+    $limit = variable_get('comment_edited_timelimit_'. $node->type, 0);
+    $ignore = user_access('ignore time limit on '. $node->type);
+
+    if (is_numeric($limit) && $limit > 0 && !$ignore) {
+      $created = db_result(db_query('SELECT created FROM {comment_edited_comments} WHERE cid = %d', $comment->cid));
+      if (time() > ($created + $limit)) {
+        return TRUE;
+      }
+    }
+	}
+  return FALSE;
+}
+
+/**
  * Adding a time limit field to the content type form, comment section.
  */
 function comment_edited_form_alter(&$form, &$form_state, $form_id) {
@@ -58,27 +114,7 @@
       '#description' => t('Set the time limit (in seconds) for editing comments, calculated from the creation of the comment. 0 means disabled.'),
     );
   }
-  // Disable the form if the time limit expired, and user has no permission to circumvent it.
-  if ('comment_form' == $form_id) {
-    $node = node_load($form['nid']['#value']);
-    $limit = variable_get('comment_edited_timelimit_'. $node->type, 0);
-    $ignore = user_access('ignore time limit on '. $node->type);
-    $cid = $form['cid']['#value']; // Existing comment
-    if (is_numeric($limit) && (0 != $limit) && !$ignore && !user_access('administer comments') && isset($cid)) {
-      drupal_set_message(t('Time limit enabled!'));
-      $created = db_result(db_query('SELECT created FROM {comment_edited_comments} WHERE cid = %d', $form['cid']['#value']));
-      $now = time();
-      if ($now > ($created + $limit)) {
-        $form['subject']['#disabled'] = TRUE;
-        $form['comment_filter']['comment']['#disabled'] = TRUE;
-
-        unset($form['submit']);
-        unset($form['preview']);
-        drupal_set_message(t('Sorry, the time limit for editing this has run out.'), 'error');
       }
-    }
-  }
-}

 /**
  * Implementation of hook_comment().
