tagcloud.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Elgg tagcloud
  4. * Displays a tagcloud. Accepts all output/tag options
  5. *
  6. * @package Elgg
  7. * @subpackage Core
  8. *
  9. * @uses $vars['tagcloud'] An array of stdClass objects with two elements: 'tag' (the text of the tag) and 'total' (the number of elements with this tag)
  10. * @uses $vars['value'] Sames as tagcloud
  11. */
  12. if (empty($vars['tagcloud']) && !empty($vars['value'])) {
  13. $vars['tagcloud'] = $vars['value'];
  14. }
  15. if (!empty($vars['tagcloud']) && is_array($vars['tagcloud'])) {
  16. $counter = 0;
  17. $max = 0;
  18. foreach ($vars['tagcloud'] as $tag) {
  19. if ($tag->total > $max) {
  20. $max = $tag->total;
  21. }
  22. }
  23. $params = $vars;
  24. unset($params['tagcloud']);
  25. $tags = array();
  26. foreach ($vars['tagcloud'] as $tag) {
  27. $params['value'] = $tag->tag;
  28. // protecting against division by zero warnings
  29. $size = round((log($tag->total) / log($max + .0001)) * 100) + 30;
  30. if ($size < 100) {
  31. $size = 100;
  32. }
  33. $params['style'] = "font-size: $size%;";
  34. $params['title'] = "$tag->tag ($tag->total)";
  35. $tags[] = elgg_view('output/tag', $params);
  36. }
  37. $cloud = implode(', ', $tags);
  38. $cloud .= elgg_view('tagcloud/extend');
  39. echo "<div class=\"elgg-tagcloud\">$cloud</div>";
  40. }