### Eclipse Workspace Patch 1.0
#P drupal
Index: modules/statistics/statistics.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.test,v
retrieving revision 1.25
diff -u -r1.25 statistics.test
--- modules/statistics/statistics.test	4 Feb 2011 18:42:22 -0000	1.25
+++ modules/statistics/statistics.test	13 Feb 2011 15:37:17 -0000
@@ -418,12 +418,8 @@
   function testStatisticsTokenReplacement() {
     global $language;
 
-    // Create user and node.
-    $user = $this->drupalCreateUser(array('create page content'));
-    $this->drupalLogin($user);
-    $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $user->uid));
-
-    // Hit the node.
+    // Create and visit a node.
+    $node = $this->drupalCreateNode();
     $this->drupalGet('node/' . $node->nid);
     $statistics = statistics_get($node->nid);
 
@@ -441,5 +437,20 @@
       $output = token_replace($input, array('node' => $node), array('language' => $language));
       $this->assertFalse(strcmp($output, $expected), t('Statistics token %token replaced.', array('%token' => $input)));
     }
+
+    // Create a new node but do not visit it.
+    $unvisited_node = $this->drupalCreateNode();
+
+    // Generate and test tokens for the node that has not yet been viewed.
+    $tests = array();
+    $tests['[node:total-count]'] = 0;
+    $tests['[node:day-count]'] = 0;
+    $tests['[node:last-view]'] = '';
+    $tests['[node:last-view:short]'] = '';
+
+    foreach ($tests as $input => $expected) {
+      $output = token_replace($input, array('node' => $unvisited_node), array('language' => $language, 'clear' => TRUE));
+      $this->assertFalse(strcmp($output, $expected), t('Statistics token %token replaced.', array('%token' => $input)));
+    }
   }
 }
Index: modules/statistics/statistics.tokens.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.tokens.inc,v
retrieving revision 1.4
diff -u -r1.4 statistics.tokens.inc
--- modules/statistics/statistics.tokens.inc	20 Apr 2010 09:48:06 -0000	1.4
+++ modules/statistics/statistics.tokens.inc	13 Feb 2011 15:37:17 -0000
@@ -11,16 +11,16 @@
  */
 function statistics_token_info() {
   $node['total-count'] = array(
-    'name' => t("Number of views"),
-    'description' => t("The number of visitors who have read the node."),
+    'name' => t('Number of views'),
+    'description' => t('The number of visitors who have read the node.'),
   );
   $node['day-count'] = array(
-    'name' => t("Views today"),
-    'description' => t("The number of visitors who have read the node today."),
+    'name' => t('Views today'),
+    'description' => t('The number of visitors who have read the node today.'),
   );
   $node['last-view'] = array(
-    'name' => t("Last view"),
-    'description' => t("The date on which a visitor last read the node."),
+    'name' => t('Last view'),
+    'description' => t('The date on which a visitor last read the node.'),
     'type' => 'date',
   );
 
@@ -33,30 +33,31 @@
  * Implements hook_tokens().
  */
 function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) {
-  $url_options = array('absolute' => TRUE);
   $replacements = array();
 
-  if ($type == 'node' & !empty($data['node'])) {
-    $node = $data['node'];
-
-    foreach ($tokens as $name => $original) {
-      if ($name == 'total-count') {
-        $statistics = statistics_get($node->nid);
-        $replacements[$original] = $statistics['totalcount'];
-      }
-      elseif ($name == 'day-count') {
-        $statistics = statistics_get($node->nid);
-        $replacements[$original] = $statistics['daycount'];
-      }
-      elseif ($name == 'last-view') {
-        $statistics = statistics_get($node->nid);
-        $replacements[$original] = format_date($statistics['timestamp']);
-      }
-    }
-
-    if ($created_tokens = token_find_with_prefix($tokens, 'last-view')) {
-      $statistics = statistics_get($node->nid);
-      $replacements += token_generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options);
+  if ($type == 'node' && !empty($data['node'])) {
+    if ($statistics = statistics_get($data['node']->nid)) {;
+	    foreach ($tokens as $name => $original) {
+	      switch ($name) {
+	        case 'total-count':
+	          $replacements[$original] = $statistics['totalcount'];
+	          break;
+	        case 'day-count':
+	          $replacements[$original] = $statistics['daycount'];
+	          break;
+	        case 'last-view':
+	        	if (!empty($statistics['timestamp'])) {
+	            $language_code = isset($options['language']->language) ? $options['language']->language : NULL;
+		          $replacements[$original] = format_date($statistics['timestamp'], 'medium', '', NULL, $language_code);
+	        	}
+	          break;
+	      }
+	    }
+	    if (($last_view_tokens = token_find_with_prefix($tokens, 'last-view'))) {
+	      if (!empty($statistics['timestamp'])) {
+	        $replacements += token_generate('date', $last_view_tokens, array('date' => $statistics['timestamp']), $options);
+	      }
+	    }
     }
   }
 
