Hello,

I needed to create a tag cloud to display on a userpage that would only display the tags /that/ user has used (as opposed to ALL the tags on the site). The attached patch will add this functionality without breaking existing functionality.

I actually placed it on my userpage by modifying the snippet I found here:
http://drupal.org/node/157802
to this:

<?php
$tagcloud = "";
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','tagadelic').'/tagadelic.css);</style>');
$vocs= array(4,5,410); //  ids of vocabs for which you want to build a tag cloud
$tagcloud = theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs, 6, 60, $uid)));
print $tagcloud;
?>

Notice that 6 and 60 in tagadelic_get_weighted_tags() are simply the defaults, and $uid should mean something (if you are using a different variable on your userpage for user id (like arg(1) or something), use that instead.

CommentFileSizeAuthor
tagadelic_13.patch1.7 KBentendu

Comments

Bèr Kessels’s picture

Status: Needs review » Closed (works as designed)

It is really easy to do a Db_query and pass that trough the APIs of tagadelic.
Having such arguments as $userspecific (code style says $user_specific, for one) is not a good idea. What is next? $christmas_only? or $in_types = array()?

Please read up on how to use the api and you can wirte a less then 20-lines module that gets/builds user_specific clouds.

mariusooms’s picture

Using the following code I'm setting the uid to the current user:

$accountid = arg(1); 
$user = user_load(array('uid' => $accountid));

So I end up with the following in a block:

$accountid = arg(1); 
$user = user_load(array('uid' => $accountid));
$tagcloud = "";
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','tagadelic').'/tagadelic.css);</style>');
$vocs= array(3); //  ids of vocabs for which you want to build a tag cloud
$tagcloud = theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs, 6, 60, $user->uid)));
print $tagcloud;

Note $user->uid in tagadelic_get_weighted_tags.

Bèr, the forum is loaded with request for user specific clouds, yet no-one has offered a good (or any other) solution. So if you are able to write a 20-lines less module that gets/builds user_specific clouds, the community would be forever grateful. For now...this patch gets the job done.

Kind regards,

Marius

Lausch’s picture

Mr. Kessels,

i agree with you. This code break the Drupal coding standard but its the only solution i ever see.

i shake my hands with mariusooms. so i will be happy too to see this "> 20 lines module"

regards

Lausch

Lausch’s picture

ok i found a solution that works for me with the community tags module

i want to see my tagcloud in a block so i added a block with the following php code:

if (arg(0) == 'node' && is_numeric(arg(1))) { // if im on a node, node->uid will be my userid
$node=node_load(arg(1));
  $userarg = $node->uid;
}
else { //my blog is blog/UID if im on the blog homepage arg(1) will be my userid
  $userarg = arg(1);
  }
  $result = _community_tags_get_tag_result($type = 'user', $limit = NULL, $arg1 = $userarg, $arg2 = NULL);
  $weighted_tags = tagadelic_build_weighted_tags($result);
  $sorted_tags = tagadelic_sort_tags($weighted_tags);
  print  theme('community_tags', $sorted_tags);

regards

Lausch

mariusooms’s picture

A great solution. Also it now allows to combines ajax user tagging on the fly. Great idea Lausch!

Regards,

Marius

Bèr Kessels’s picture

Please refer to http://drupal.org/node/253514 for this and other such requests.