Index: contribs/weblinks_blocks/weblinks_blocks.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/contribs/weblinks_blocks/Attic/weblinks_blocks.module,v
retrieving revision 1.1.2.2.2.4
diff -u -r1.1.2.2.2.4 weblinks_blocks.module
--- contribs/weblinks_blocks/weblinks_blocks.module	30 Mar 2009 07:51:22 -0000	1.1.2.2.2.4
+++ contribs/weblinks_blocks/weblinks_blocks.module	4 Apr 2009 17:56:38 -0000
@@ -63,6 +63,8 @@
   $title_length = variable_get('weblinks_trim_blocks', 0);
   $show_image = variable_get('weblinks_blocks_image_'. $blktid, FALSE);
   $related = FALSE;
+  $show_count = variable_get('weblinks_blocks_show_count_'. $blktid, FALSE);
+  $show_last = variable_get('weblinks_blocks_show_last_'. $blktid, FALSE);
 
   $options = $items = array();
   if (variable_get('weblinks_external', TRUE)) {
@@ -87,7 +89,21 @@
 
   $result = _weblinks_get_query($qtid, $sort, ($limit ? $limit + $more : 0));
   while ($row = db_fetch_array($result)) {
-    $items[] = theme('weblinks_block_item', node_load($row['nid']), $title_length, $urlnode, $options, $show_image);
+    $node = node_load($row['nid']);
+    if ($sort == 'popular') {
+      // Include click count and date for popular block.
+      $stuff = array();
+      if ($show_count) {
+        $stuff[] = $node->click_count;
+      }
+      if ($show_last) {
+        $stuff[] = format_date($node->last_click, 'small');
+      }
+      if ($stuff) {
+        $node->title .= ' ('. implode(', ', $stuff) .')';
+      }
+    }
+    $items[] = theme('weblinks_block_item', $node, $title_length, $urlnode, $options, $show_image);
   }
 
   if ($more && $limit && (count($items) > $limit)) {
@@ -158,62 +174,6 @@
 }
 
 /**
- * Prepare the Popular Links block.
- */
-function _weblinks_blocks_popular_block($group_id, $no_limit = FALSE) {
-  $block = array();
-  $blktid = $group_id ? '_'. $group_id : NULL;
-  $urlnode = variable_get('weblinks_blocks_urlnode_popular'. $blktid, 'url');
-  $more = variable_get('weblinks_blocks_more_popular'. $blktid, FALSE);
-  $limit = $no_limit ? 0 : variable_get('weblinks_maxdisp_blocks_popular'. $blktid, 10);
-  $desc = variable_get('weblinks_blocks_description_popular'. $blktid, FALSE);
-  $title_length = variable_get('weblinks_trim_blocks', 0);
-  $show_image = variable_get('weblinks_blocks_image_popular'. $blktid, FALSE);
-
-  $options = array();
-  if (variable_get('weblinks_external', TRUE)) {
-    $options['attributes']['target'] = '_blank';
-  }
-  if (variable_get('weblinks_nofollow', FALSE)) {
-    $options['attributes']['rel'] = 'nofollow';
-  }
-
-  $items = array();
-  $query = "SELECT n.nid FROM {node_counter} c JOIN {node} n ON n.nid=c.nid ";
-  if ($group_id) {
-    $query .= 'LEFT JOIN {term_node} tn ON tn.nid=n.nid AND tn.vid=n.vid ';
-  }
-  $query .= "WHERE n.type='weblinks' AND c.totalcount > 0 ";
-  if ($group_id) {
-    $query .= "AND tn.tid = $group_id ";
-  }
-  $query .= "ORDER by c.totalcount DESC, c.timestamp DESC";
-  if ($no_limit) {
-    $result = db_query($query);
-  }
-  else {
-    $result = db_query_range($query, 0, $limit + 1);
-  }
-
-  while ($row = db_fetch_array($result)) {
-    $items[] = theme('weblinks_block_item', node_load($row['nid']), $title_length, $urlnode, $options, $show_image);
-  }
-
-  if ($more && $limit && (count($items) > $limit)) {
-    unset($items[$limit]);
-    $more_link = '<div class="weblinks-more">'. l(t('more&#8230;'), 'weblinks/popular'. ($group_id ? '/'. $group_id : NULL)) .'</div>';
-  }
-  else {
-    $more_link = NULL;
-  }
-
-  $block['subject'] = t('Most Popular Web Links');
-  $block['content'] = $items ? decode_entities(theme('item_list', $items, NULL, variable_get('weblinks_blocks_popular_list_type', 'ul')) . $more_link) : t('No links have been visited since statistics were enabled or the "Count content views" option was not enabled.');
-
-  return $block;
-}
-
-/**
  * Implementation of hook_block().
  */
 function weblinks_blocks_block($op = 'list', $delta = 0, $edit = array()) {
@@ -358,12 +318,8 @@
 
   switch ($tid) {
     case 'popular':
-      $block = _weblinks_blocks_popular_block($group_id);
-      break;
-
     case 'recent':
-      $block['subject'] = t('Recent Web Links');
-      $block['content'] = _weblinks_blocks_content('recent', 'recent', $limit, $group_id);
+      $block['content'] = _weblinks_blocks_content($tid, $tid, $limit, $group_id);
       break;
 
     case 'related':
@@ -462,10 +418,7 @@
 function weblinks_blocks_block_configure($delta = 0) {
   $form = array();
   list($type, $tid, $group_id) = explode('-', $delta);
-  // For the special blocks, we add the group_id if there is one.
-  if (!is_numeric($tid) && $group_id) {
-    $tid .= '_'. $group_id;
-  }
+  $blktid = $tid . ($group_id ? '_'. $group_id : NULL);
 
   $form['weblinks'] = array(
     '#type' => 'fieldset',
@@ -485,7 +438,7 @@
     return $form;  // That's all for this block.
   }
 
-  $disp = variable_get('weblinks_maxdisp_blocks_'. $tid, ($tid == 'random' ? 1 : 10));
+  $disp = variable_get('weblinks_maxdisp_blocks_'. $blktid, ($tid == 'random' ? 1 : 10));
   $disp = empty($disp) ? 10 : $disp;
   $form['weblinks']['weblinks_maxdisp_blocks'] = array(
     '#type' => 'textfield',
@@ -502,22 +455,43 @@
     $form['weblinks']['weblinks_blocks_more'] = array(
       '#type' => 'checkbox',
       '#title' => t('"More..." link?'),
-      '#default_value' => variable_get('weblinks_blocks_more_'. $tid, FALSE),
+      '#default_value' => variable_get('weblinks_blocks_more_'. $blktid, FALSE),
       '#description' => t('If there are more links than the limit above, do you want a "more..." link?'),
       );
   }
 
+  if ($tid == 'popular') {
+    $form['weblinks']['weblinks_blocks_show_count'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show click count?'),
+      '#default_value' => variable_get('weblinks_blocks_show_count_'. $blktid, FALSE),
+      '#description' => t('If this is selected, the number of times the link has ben clicked will be shown.'),
+      );
+
+    $fmt = variable_get('date_format_short', 'm/d/Y - H:i');
+    $form['weblinks']['weblinks_blocks_show_last'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show last click date?'),
+      '#default_value' => variable_get('weblinks_blocks_show_last_'. $blktid, FALSE),
+      '#description' => t('If this is selected, the number of times the link has been clicked will be shown in the site short date format ("%fmt").', array('%fmt' => $fmt)),
+      );
+  }
+  else {
+    $form['weblinks']['weblinks_blocks_show_count'] = array('#type' => 'value', '#value' => FALSE);
+    $form['weblinks']['weblinks_blocks_show_last'] = array('#type' => 'value', '#value' => FALSE);
+  }
+
   $form['weblinks']['weblinks_blocks_description'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show description?'),
-    '#default_value' => variable_get('weblinks_blocks_description_'. $tid, FALSE),
+    '#default_value' => variable_get('weblinks_blocks_description_'. $blktid, FALSE),
     '#description' => t("If checked, the link's description will be shown."),
     );
 
   $form['weblinks']['weblinks_blocks_image'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show image?'),
-    '#default_value' => variable_get('weblinks_blocks_image_'. $tid, FALSE),
+    '#default_value' => variable_get('weblinks_blocks_image_'. $blktid, FALSE),
     '#description' => t("If checked, the link's attached image will be shown."),
     );
 
@@ -536,7 +510,7 @@
       $form['weblinks']['weblinks_blocks_urlnode'] = array(
         '#type' => 'radios',
         '#title' => t('Links lead to URL or Web Link node'),
-        '#default_value' => variable_get('weblinks_blocks_urlnode_'. $tid, 'url'),
+        '#default_value' => variable_get('weblinks_blocks_urlnode_'. $blktid, 'url'),
         '#description' => t('Most people will want to leave this as URL. Specifying "node" makes it easier to edit the links, but requires an additional click to follow the link.'),
         '#options' => array('url' => t('URL'), 'node' => t('node')),
         '#prefix' => '<div class="weblinks-radios">',
@@ -565,7 +539,7 @@
       '#type' => 'radios',
       '#options' => $sort_options,
       '#title' => t('blocks Sort order'),
-      '#default_value' => variable_get('weblinks_blocks_sort_'. $tid, 'title'),
+      '#default_value' => variable_get('weblinks_blocks_sort_'. $blktid, 'title'),
       '#description' => t('This determines how the links blocks will sort the links.'),
       '#prefix' => '<div class="weblinks-radios">',
       '#suffix' => '</div>',
@@ -577,14 +551,14 @@
       '#type' => 'textfield',
       '#size' => 4,
       '#maxlength' => 3,
-      '#default_value' => variable_get('weblinks_blocks_update_interval_'. $tid, ''),
+      '#default_value' => variable_get('weblinks_blocks_update_interval_'. $blktid, ''),
       '#field_prefix' => '<strong>'. t('Update every') .'</strong>',
       '#prefix' => '<div class="container-inline">',
       );
 
     $form['weblinks']['cron_step'] = array(
       '#type' => 'select',
-      '#default_value' => variable_get('weblinks_blocks_update_step_'. $tid, 86400),
+      '#default_value' => variable_get('weblinks_blocks_update_step_'. $blktid, 86400),
       '#options' => array(
         1 => t('seconds'),
         60 => t('minutes'),
@@ -619,29 +593,29 @@
  */
 function weblinks_blocks_block_save($delta = 0, $edit = array()) {
   list($type, $tid, $group_id) = explode('-', $delta);
-  if (!is_numeric($tid) && $group_id) {
-    $tid .= '_'. $group_id;
-  }
+  $blktid = $tid . ($group_id ? '_'. $group_id : NULL);
 
-  variable_set('weblinks_maxdisp_blocks_'. $tid, $edit['weblinks_maxdisp_blocks']);
+  variable_set('weblinks_maxdisp_blocks_'. $blktid, $edit['weblinks_maxdisp_blocks']);
   if ($tid == 'contributors') {
     return;
   }
-  variable_set('weblinks_blocks_urlnode_'. $tid, $edit['weblinks_blocks_urlnode']);
-  variable_set('weblinks_blocks_more_'. $tid, $edit['weblinks_blocks_more']);
-  variable_set('weblinks_blocks_description_'. $tid, $edit['weblinks_blocks_description']);
-  variable_set('weblinks_blocks_image_'. $tid, $edit['weblinks_blocks_image']);
+  variable_set('weblinks_blocks_urlnode_'. $blktid, $edit['weblinks_blocks_urlnode']);
+  variable_set('weblinks_blocks_more_'. $blktid, $edit['weblinks_blocks_more']);
+  variable_set('weblinks_blocks_description_'. $blktid, $edit['weblinks_blocks_description']);
+  variable_set('weblinks_blocks_image_'. $blktid, $edit['weblinks_blocks_image']);
   // Don't save sort for popular or recent.
   if ($tid != 'popular' && $tid != 'recent') {
-    variable_set('weblinks_blocks_sort_'. $tid, $edit['weblinks_blocks_sort']);
+    variable_set('weblinks_blocks_sort_'. $blktid, $edit['weblinks_blocks_sort']);
   }
 
   if ($tid = 'popular') {
     variable_set('weblinks_blocks_popular_list_type', $edit['weblinks_blocks_popular_list_type']);
+    variable_set('weblinks_blocks_show_count_'. $blktid, $edit['weblinks_blocks_show_count']);
+    variable_set('weblinks_blocks_show_last_'. $blktid, $edit['weblinks_blocks_show_last']);
   }
 
   if ($tid = 'random') {
-    variable_set('weblinks_blocks_update_interval_'. $tid, $edit['cron_interval']);
-    variable_set('weblinks_blocks_update_step_'. $tid, $edit['cron_step']);
+    variable_set('weblinks_blocks_update_interval_'. $blktid, $edit['cron_interval']);
+    variable_set('weblinks_blocks_update_step_'. $blktid, $edit['cron_step']);
   }
 }
Index: weblinks-link.tpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/Attic/weblinks-link.tpl.php,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 weblinks-link.tpl.php
--- weblinks-link.tpl.php	1 Apr 2009 20:49:59 -0000	1.1.2.4
+++ weblinks-link.tpl.php	4 Apr 2009 15:41:14 -0000
@@ -14,12 +14,19 @@
 <?php print $status; ?>
 <?php print $link; ?>
   
-  <div class="weblinks-body">
+<div class="weblinks-body">
   <?php
     print $weblinks_body;
     if (isset($pagerank)) {
       print "<p>Google page rank: $pagerank &nbsp; (as of ". format_date($rank_checked, 'small') .")</p>";
     }
   ?>
-  </div>
+</div>
+<div class="weblinks-click-stats">
+<?php
+  if ($click_count) {
+    print '<p>'. t('Clicked !count times. Last clicked !last.', array('!count' => $click_count, '!last' => $last_click)) .'</p>';
+  }
+?>
+</div>
 </div>
Index: weblinks.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks.admin.inc,v
retrieving revision 1.34.2.43.2.6
diff -u -r1.34.2.43.2.6 weblinks.admin.inc
--- weblinks.admin.inc	1 Apr 2009 20:49:59 -0000	1.34.2.43.2.6
+++ weblinks.admin.inc	4 Apr 2009 14:38:44 -0000
@@ -194,7 +194,7 @@
     '#title' => t('Links lead to URL or Web Link node'),
     '#default_value' => variable_get('weblinks_urlnode', 'url'),
     '#description' => t('Most people will want to leave this as URL. Specifying "node" makes it easier to edit the links, but requires an additional click to follow the link.'),
-    '#options' => array('url' => t('URL'), 'node' => t('node')),
+    '#options' => array('url' => t('URL'), 'node' => t('node'), 'goto' => t('redirect')),
     '#prefix' => '<div class="weblinks-radios">',
     '#suffix' => '</div>',
     );
Index: weblinks.admin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/Attic/weblinks.admin.js,v
retrieving revision 1.1.4.3
diff -u -r1.1.4.3 weblinks.admin.js
--- weblinks.admin.js	26 Feb 2009 16:40:06 -0000	1.1.4.3
+++ weblinks.admin.js	4 Apr 2009 15:53:53 -0000
@@ -1,7 +1,7 @@
 /* $Id: weblinks.admin.js,v 1.1.4.3 2009/02/26 16:40:06 nancyw Exp $ */
 
 function weblinks_urlnode_handler(event) {
-  if ($("input[@name=weblinks_urlnode]:checked").val() == 'url') {
+  if ($("input[@name=weblinks_urlnode]:checked").val() != 'node') {
     $("div.weblinks_external_hide").show();
   }
   else {
Index: weblinks.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks.css,v
retrieving revision 1.11.2.13.2.3
diff -u -r1.11.2.13.2.3 weblinks.css
--- weblinks.css	1 Apr 2009 20:49:59 -0000	1.11.2.13.2.3
+++ weblinks.css	4 Apr 2009 15:43:06 -0000
@@ -205,3 +205,8 @@
 .weblinks-body {
   margin-left: 2em;  
 }
+
+.weblinks-click-stats {
+  margin-left: 2em;
+  font-style: italic;
+}
Index: weblinks.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks.module,v
retrieving revision 1.86.2.85.2.7
diff -u -r1.86.2.85.2.7 weblinks.module
--- weblinks.module	1 Apr 2009 20:49:59 -0000	1.86.2.85.2.7
+++ weblinks.module	4 Apr 2009 17:19:01 -0000
@@ -422,7 +422,7 @@
     $user_link = variable_get('weblinks_user_links', FALSE);
 
     $options = array();
-    if (variable_get('weblinks_external', TRUE) && $urlnode == 'url') {
+    if (variable_get('weblinks_external', TRUE) && $urlnode != 'node') {
       $options['attributes']['target'] = '_blank';
     }
 
@@ -456,8 +456,11 @@
     $variables['alexa'] = $node->alexa;
     $variables['rank_checked'] = $node->rank_checked;
   }
-  $variables['title'] = weblinks_build_link($variables[0], 0, ($urlnode == 'node' ? 'node' : 'url'), $options);
+//  $variables['title'] = weblinks_build_link($variables[0], 0, ($urlnode == 'node' ? 'node' : 'url'), $options);
+  $variables['title'] = weblinks_build_link($variables[0], 0, $urlnode, $options);
   $variables['link'] = theme('weblinks_node_view', $node, $options);
+  $variables['click_count'] = $node->click_count;
+  $variables['last_click'] = format_date($node->last_click, 'small');
 
   if ($info) {
     $variables['status'] = theme('weblinks_status', $node); 
@@ -900,7 +903,7 @@
 
   // Handle 'weblinks/goto/nid'.
   if ($tid === 'goto') {
-    return _weblinks_goto(arg(2));
+    return weblinks_goto(arg(2));
   }
 
   // Handle 'weblinks/user/uid'.
@@ -918,17 +921,8 @@
       return ' ';
     }
 
-//    $path = drupal_get_path('module', 'weblinks_blocks') .'/weblinks_blocks.module';
-//   drupal_set_message("trying to include $path.");
-//    include($path);
     $group_id = arg(2);
-    if ($tid == 'popular') {
-      $blk = _weblinks_blocks_popular_block($group_id, TRUE);
-      $content = $blk['content'];
-    }
-    else {
-      $content = _weblinks_blocks_content($tid, $tid, 0, $group_id);
-    }
+    $content = _weblinks_blocks_content($tid, $tid, 0, $group_id);
 
     $term = taxonomy_get_term($group_id);
     $fieldset = array(
@@ -1040,7 +1034,7 @@
  */
 function weblinks_goto($nid) {
   $node = node_load($nid);
-  $qargs = array($time(), $node->nid, $node->vid);
+  $qargs = array(time(), $node->nid, $node->vid);
   db_query("UPDATE {weblinks} SET click_count=click_count+1, last_click=%d WHERE nid=%d AND vid=%d", $qargs);
   if (module_exists('statistics')) {
     statistics_exit('node', $node->nid, '');
@@ -1231,6 +1225,11 @@
       $query .= 'ORDER BY bw.weight ASC, n.title ASC';
       $cols[] = 'bw.weight, n.title';
       break;
+    case 'popular':
+      $query .= 'AND bw.click_count>0 ';
+      $query .= 'ORDER BY bw.click_count DESC, bw.last_click DESC';
+      $cols[] = 'bw.click_count, bw.last_click';
+      break;
     case 'user':
       $query .= "AND n.uid=%s ";
       $query .= 'ORDER BY n.sticky, bw.weight, n.created';
Index: weblinks_node_view.tpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks_node_view.tpl.php,v
retrieving revision 1.5.2.7.2.1
diff -u -r1.5.2.7.2.1 weblinks_node_view.tpl.php
--- weblinks_node_view.tpl.php	17 Mar 2009 15:31:39 -0000	1.5.2.7.2.1
+++ weblinks_node_view.tpl.php	4 Apr 2009 14:52:00 -0000
@@ -20,7 +20,8 @@
       else {
         $url = $node->url;
       }
-      $link = l(_weblinks_trim($url, variable_get('weblinks_trim', 0)), $node->url, $options);
+//      $link = l(_weblinks_trim($url, variable_get('weblinks_trim', 0)), $node->url, $options);
+      $title = _weblinks_trim($url, variable_get('weblinks_trim', 0));
       break;
 
     case 'visit':
@@ -31,8 +32,14 @@
       else {
         $title = str_replace('[title]', check_plain($node->title), $title_text);
       }
-      $link = decode_entities(l($title, $node->url, $options));
+//      $link = decode_entities(l($title, $node->url, $options));
       break;
   }
+  if (variable_get('weblinks_urlnode', 'url') == 'goto') {
+    $link = decode_entities(l($title, 'weblinks/goto/'. $node->nid, $options));
+  }
+  else {
+    $link = decode_entities(l($title, $node->url, $options));
+  }
   echo '<div class="weblinks-linkview">'. $link .'</div>';
 }

