Index: weblinks.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks.module,v retrieving revision 1.46 diff -u -r1.46 weblinks.module --- weblinks.module 13 Jul 2008 22:58:00 -0000 1.46 +++ weblinks.module 14 Jul 2008 18:30:11 -0000 @@ -1046,9 +1054,9 @@ /** * Prepare block content. */ -function _weblinks_get_query($tid = 0, $sort = 'title') { +function _weblinks_get_query($tid = 0, $sort = 'title', $limit = 0) { // Get the max number of posts to display - $limitnum = variable_get('weblinks_maxdisp_'. $tid, 10); + $limitnum = $limit ? $limit : variable_get('weblinks_maxdisp_'. $tid, 10); $query = 'SELECT nr.body, nr.format, n.*, bw.url '; $query .= 'FROM {node} n '; @@ -1083,8 +1091,8 @@ /** * Prepare block content. */ -function _weblinks_block_content($tid = 0, $sort) { - $result = _weblinks_get_query($tid, $sort); +function _weblinks_block_content($tid = 0, $sort, $limit) { + $result = _weblinks_get_query($tid, $sort, $limit); $urlnode = variable_get('weblinks_block_urlnode', 'url'); $options = $items = array(); if (variable_get('weblinks_external', true)) { @@ -1107,46 +1115,87 @@ /** * Implementation of hook_block(). */ -function weblinks_block($op = 'list', $delta = 0) { - if ($op == 'list') { - $tree = module_invoke('taxonomy', 'get_tree', _weblinks_get_vocid()); -dsm($tree); -dsm($taxonomy_get_tree(_weblinks_get_vocid())); - if ($tree) { - foreach ($tree as $linkcat) { - $block['weblink-'. $linkcat->tid]['info'] = 'Web Link: '. $linkcat->name; +function weblinks_block($op = 'list', $delta = 0, $edit = array()) { + $block = $form = array(); + switch ($op) { + case 'list': + $tree = module_invoke('taxonomy', 'get_tree', _weblinks_get_vocid()); + if ($tree) { + foreach ($tree as $linkcat) { + $block['weblink-'. $linkcat->tid]['info'] = 'Web Link: '. $linkcat->name; + } } - } - $block['weblink-recent']['info'] = 'Recent Web Links'; - return $block; - } - else if ($op == 'view') { - list($type, $tid) = explode('-', $delta); - if ($type == 'weblink') { - if ($linkcat = module_invoke('taxonomy', 'get_term', $tid)) { - $block['subject'] = check_plain($linkcat->name); - $block['content'] = _weblinks_block_content($tid, variable_get('weblinks_block_sort', 'title')); + $block['weblink-recent']['info'] = 'Web Links: Recent'; + if (module_exists('statistics')) { + $block['weblink-popular']['info'] = 'Web Links: Most Popular'; } - else if ($tid == 'recent') { - $block['subject'] = t('Recent Web Links'); - $block['content'] = _weblinks_block_content(0, 'recent_block'); + return $block; + + case 'view': + list($type, $tid) = explode('-', $delta); + $limit = variable_get('weblinks_maxdisp_block_'. $tid, 10); + switch ($tid) { + case 'popular': + $urlnode = variable_get("weblinks_block_urlnode", 'url'); + $options = array(); + if (variable_get('weblinks_external', true)) { + $options['attributes']['target'] = '_blank'; + } + if (variable_get('weblinks_nofollow', false)) { + $options['attributes']['rel'] = 'nofollow'; + } + $items = array(); + $result = db_query_range("SELECT n.nid FROM {node_counter} c JOIN {node} n ON n.nid=c.nid WHERE n.type='weblinks' AND c.totalcount > 0 ORDER by c.totalcount DESC, c.timestamp DESC", 0, $limit); + while ($row = db_fetch_array($result)) { + $node = node_load($row['nid']); + $items[] = l($node->title, ($urlnode == 'node' ? 'node/'. $node->nid : $node->url), $options); + } + $block['subject'] = t('Most Popular Web Links'); + $block['content'] = $items ? theme('item_list', $items, null, variable_get('weblinks_popular_list_type', 'ul')) : t('No links have been visited since statistics were enabled or the "Count content views" option was not enabled.'); + break; + + case 'recent': + $block['subject'] = t('Recent Web Links'); + $block['content'] = _weblinks_block_content(0, 'recent_block', $limit); + break; + + default: + $linkcat = taxonomy_get_term($tid); + $block['subject'] = check_plain($linkcat->name); + $block['content'] = _weblinks_block_content($tid, variable_get('weblinks_block_sort', 'title'), $limit); } - } - return $block; - } - elseif ($op == 'configure') { - $form = array(); - switch ($delta) { - case 'weblink-recent': - $form['weblinks_maxdisp_block_recent'] = array( - '#type' => 'textfield', - '#title' => t('Maximum Recent Web Links'), - '#default_value' => variable_get('weblinks_maxdisp_block_recent', 10), - '#description' => t('The number of links to show.'), + return $block; + + case 'configure': + list($type, $tid) = explode('-', $delta); + $form['weblinks_maxdisp_block'] = array( + '#type' => 'textfield', + '#title' => t('Maximum weblinks to display'), + '#size' => 3, + '#default_value' => variable_get('weblinks_maxdisp_block_'. $tid, 10), + '#description' => t('The number of links to show in this block.'), + ); + + if ($tid == 'popular') { + $form['weblinks_popular_list_type'] = array( + '#type' => 'radios', + '#title' => t('List type'), + '#options' => array('ul' => 'simple list', 'ol' => 'numbered list'), + '#default_value' => variable_get('weblinks_popular_list_type', 'ul'), + '#description' => t('This sets the way the list will be displayed.'), + '#prefix' => '', ); - break; - } - return $block; + } + return $form; + + case 'save': + list($type, $tid) = explode('-', $delta); + variable_set('weblinks_maxdisp_block_'. $tid, $edit['weblinks_maxdisp_block']); + if (isset($edit['weblinks_popular_list_type'])) { + variable_set('weblinks_popular_list_type', $edit['weblinks_popular_list_type']); + } + break; } } Index: weblinks.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks.admin.inc,v retrieving revision 1.10 diff -u -r1.10 weblinks.admin.inc --- weblinks.admin.inc 12 Jul 2008 21:01:24 -0000 1.10 +++ weblinks.admin.inc 14 Jul 2008 16:38:23 -0000 @@ -211,15 +211,16 @@ '#description' => t('Leave blank if you would not like to limit the number of links displayed'), ); - // Set the maximum number of links to display in the block for each category - $form['categories'][$row->tid]['weblinks_maxdisp_block_'. $row->tid] = array( - '#type' => 'textfield', - '#title' => t('Maximum block entries to display'), - '#default_value' => variable_get('weblinks_maxdisp_block_'. $row->tid, NULL), - '#size' => 2, - '#required' => FALSE, - '#description' => t('Leave blank if you would not like to limit the number of links displayed'), - ); +// Moved to block settings. +// // Set the maximum number of links to display in the block for each category +// $form['categories'][$row->tid]['weblinks_maxdisp_block_'. $row->tid] = array( +// '#type' => 'textfield', +// '#title' => t('Maximum block entries to display'), +// '#default_value' => variable_get('weblinks_maxdisp_block_'. $row->tid, NULL), +// '#size' => 2, +// '#required' => FALSE, +// '#description' => t('Leave blank if you would not like to limit the number of links displayed'), +// ); } return system_settings_form($form); }