--- tagadelic.module-old 2006-05-14 23:33:08.000000000 +0200 +++ tagadelic.module 2006-05-31 16:20:25.000000000 +0200 @@ -77,6 +77,7 @@ function tagadelic_settings() { */ function tagadelic_page_chunk() { $vocs = arg(2); + global $user; if (is_numeric($vocs)) { $vocs = array($vocs); @@ -90,7 +91,7 @@ function tagadelic_page_chunk() { } } - $output = theme('tagadelic_weighted',tagadelic_get_weighted_tags($vocs)); + $output = theme('tagadelic_weighted',tagadelic_get_weighted_tags($vocs,6,60,$user->uid)); if (!$output) { return drupal_not_found(); @@ -106,7 +107,8 @@ function tagadelic_page_chunk() { */ function tagadelic_page_list() { $vocs = arg(2); - + global $user; + if (is_numeric($vocs)) { $vocs = array($vocs); } @@ -122,7 +124,7 @@ function tagadelic_page_list() { if ($vocabulary->description) { $output .= theme("box", NULL, $vocabulary->description); } - $output .= theme('box', $vocabulary->name, theme('tagadelic_weighted', tagadelic_get_weighted_tags(array($vocabulary->vid)))); + $output .= theme('box', $vocabulary->name, theme('tagadelic_weighted', tagadelic_get_weighted_tags(array($vocabulary->vid),6,60,$user->uid))); } if (!$output) { @@ -174,7 +176,7 @@ function tagadelic_tags_lists($node) { * API that returns an array with weighted tags * This is the hard part. People with better ideas are very very welcome to send these to ber@webschuur.com. Distribution is one thing that needs attention. */ -function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) { +function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60, $uid = NULL) { if (!is_array($vids) || count($vids) == 0) { return array(); } @@ -187,10 +189,12 @@ function tagadelic_get_weighted_tags($vi $min = 1e9; $max = -1e9; while ($tag = db_fetch_object($result)) { - $tag->count = log($tag->count); - $min = min($min, $tag->count); - $max = max($max, $tag->count); - $tags[$tag->tid] = $tag; + if ($tag = tagadelic_check_permission($tag, $uid)) { + $tag->count = log($tag->count); + $min = min($min, $tag->count); + $max = max($max, $tag->count); + $tags[$tag->tid] = $tag; + } } // Note: we need to ensure the range is slightly too large to make sure even // the largest element is rounded down. @@ -219,6 +223,30 @@ function tagadelic_get_weighted_tags($vi } /** + * Check to see if user has permission to see a particular tag + */ +function tagadelic_check_permission($tag, $uid) { + $result = db_query('SELECT nid FROM {term_node} n INNER JOIN {term_data} d ON d.tid = n.tid WHERE d.name = "' . $tag->name .'" GROUP BY nid'); + + $allowed_count = 0; + while ($node = db_fetch_object($result)) { + $node = node_load($node); + if (node_access("view", $node, $uid)) { + $allowed = TRUE; + $allowed_count++; + } + } + + if ($allowed) { + $tag->count = $allowed_count; + return $tag; + } + else { + return FALSE; + } +} + +/** * callback for usort, sort by count */ function _tagadelic_sort_by_title($a, $b) { @@ -288,4 +316,4 @@ function tagadelic_block($op = 'list', $ } return $blocks; } -?> \ No newline at end of file +?>