--- auto_expire.module	2009-06-29 00:55:18.000000000 +-0200
+++ auto_expire_show_load_date.module	2009-07-08 23:07:01.000000000 +-0200
@@ -60,21 +60,30 @@
 function _auto_expire_is_expiring_node($node) {
   return variable_get(AUTO_EXPIRE_NODE_TYPE . $node->type .'_e', 0);
 }
+
+function _auto_expire_permission_user_extend($node_uid = 0) {
+  global $user;
+  return user_access(EXTEND_AUTO_EXPIRE_ALL) || (user_access(EXTEND_AUTO_EXPIRE_OWN) && $user->uid > 0 && $node_uid == $user->uid);
+}
 
-function _auto_expire_can_user_extend($nid) {
-  global $user;
-  
+function _auto_expire_can_user_extend($nid, $now = FALSE) {
   $node = node_load($nid);
   
   $will_expire = _auto_expire_is_expiring_node($node);
+  $has_permission = _auto_expire_permission_user_extend($node->uid);
   
-  if ($will_expire) {
-    return user_access(EXTEND_AUTO_EXPIRE_ALL) || (user_access(EXTEND_AUTO_EXPIRE_OWN) && $user->uid > 0 && $node->uid == $user->uid);
-  }
-  else {
-    return FALSE;
-  }
-}
+  if ($will_expire && $has_permission) {
+    if ($now) {
+      // Check if node is extendable right now.
+      $expire = $node->auto_expire['timestamp'];
+      $code = AUTO_EXPIRE_NODE_TYPE . $node->type;
+      $warn = variable_get($code . '_w', AUTO_EXPIRE_WARN);
+      return (time() > $expire - ($warn * 24 * 60 * 60));
+    }
+    return TRUE;
+  }
+  return FALSE;
+}
 
 function _auto_expire_expiry(&$form_state, $nid) {
   $node = node_load($nid);
@@ -205,6 +214,15 @@
       '#default_value' => variable_get($code .'_p', AUTO_EXPIRE_PURGE),
       '#description' => t('Number of days after an item has expired when it will be purged from the database. Set to 0 (zero) for no purge.'),
     );
+    
+    $form['nodetypes'][$type][$code .'_l'] = array(
+      '#type' => 'radios',
+      '#options' => array(0 => t('Never'), 1 => t('Only if user has permission to extend'), 2 => t('Always')),
+      '#title' => t('Show expiration date on node'),
+      '#return_value' => 1,
+      '#default_value' => variable_get($code .'_l', 0),
+      '#description' => t('Show the expiration date in the links div on a node page. This will also show an extend link in case the node can be extended.'),
+    );    
   }
   
   $form['email']['warn'] = array(
@@ -384,10 +402,48 @@
       case 'delete':
         db_query('DELETE FROM {auto_expire} WHERE nid = %d', $node->nid);
         break;
+
+      case 'load':
+        $expire = _auto_expire_get_expire($node->nid);
+        $output['auto_expire'] = array(
+          'timestamp' => $expire,
+          'date' => format_date($expire),
+        );
+        return $output;
     }
   }
 }
 
+/**
+ * Implementation of hook_link().
+ */
+function auto_expire_link($type, $object, $teaser = FALSE) {
+  $links = array();
+  $code = AUTO_EXPIRE_NODE_TYPE . $object->type;
+  
+  if ($type == 'node' && isset($object->auto_expire)) {
+    $show_links = variable_get($code .'_l', 0);
+    
+    // Show expiration date.
+    if ($show_links == 2 || ($show_links == 1 && _auto_expire_permission_user_extend($object->uid))) {
+      $links['auto_expire_date'] = array(
+        'title' => t('This node will expire on !date.', array('!date' => $object->auto_expire['date'])),
+      );
+    }
+    
+    // Show extend link if user can extend node right now.
+    $can_extend = _auto_expire_can_user_extend($object->nid, TRUE);
+    if ($show_links > 0 && $can_extend) {
+      $links['auto_expire_extend'] = array(
+        'title' => t('Extend now'),
+        'href' => "node/$object->nid/expiry",
+      );
+    }
+  }
+  
+  return $links;
+}
+
 /**
  * Implementation of hook_node_type().
  */

--- views_handler_field_auto_expire_link_extend.inc	2009-06-29 00:55:18.000000000 +-0200
+++ views_handler_field_auto_expire_link_extend_simplified.inc	2009-07-08 23:45:11.000000000 +-0200
@@ -13,18 +13,12 @@
   
     $nid = $values->{$this->aliases['nid']};
     
-    // check if user has rights to extend
-    if (_auto_expire_can_user_extend($nid)) {
-      // check if node is 'extendable' at this moment
-      $expire = _auto_expire_get_expire($nid);
-      $code = AUTO_EXPIRE_NODE_TYPE . $node->type;
-      $warn = variable_get($code . '_w', AUTO_EXPIRE_WARN);
-      if (time() > $expire - ($warn * 24 * 60 * 60)) {
-        $text = !empty($this->options['text']) ? $this->options['text'] : t('extend');
-        return l($text, "node/$nid/expiry", array('query' => drupal_get_destination()));
-      }
-    }
+    // check if user has rights to extend and if the node is extendable right now
+    if (_auto_expire_can_user_extend($nid, TRUE)) {
+      $text = !empty($this->options['text']) ? $this->options['text'] : t('extend');
+      return l($text, "node/$nid/expiry", array('query' => drupal_get_destination()));
+    }
     return;
 
   }
 }
