task.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Elgg task icon
  4. *
  5. * @uses $vars['entity'] The task entity.
  6. * @uses $vars['size'] The size - tiny, small, medium or large. (medium)
  7. * @uses $vars['use_hover'] Display the hover menu? (true)
  8. * @uses $vars['use_link'] Wrap a link around image? (true)
  9. * @uses $vars['img_class'] Optional CSS class added to img
  10. * @uses $vars['link_class'] Optional CSS class for the link
  11. * @uses $vars['href'] Optional override of the link href
  12. */
  13. $task = elgg_extract('entity', $vars);
  14. $size = elgg_extract('size', $vars, 'medium');
  15. if (!in_array($size, array('topbar', 'tiny', 'small', 'medium', 'large', 'master'))) {
  16. $size = 'medium';
  17. }
  18. $use_link = elgg_extract('use_link', $vars, true);
  19. if (!elgg_instanceof($task, 'object', 'task')) {
  20. return true;
  21. }
  22. $title = htmlspecialchars($task->title, ENT_QUOTES, 'UTF-8', false);
  23. $guid = $task->guid;
  24. $img_class = '';
  25. if (isset($vars['img_class'])) {
  26. $img_class = $vars['img_class'];
  27. }
  28. $use_hover = elgg_extract('use_hover', $vars, $task->canEdit());
  29. if (isset($vars['hover']) ) {
  30. $use_hover = $vars['hover'];
  31. }
  32. $icon_url = elgg_format_url($task->getIconURL($size));
  33. $icon = elgg_view('output/img', array(
  34. 'src' => $icon_url,
  35. 'alt' => $name,
  36. 'title' => $name,
  37. 'class' => $img_class,
  38. ));
  39. ?>
  40. <div class="elgg-avatar elgg-task-icon">
  41. <?php
  42. if ($use_hover) {
  43. tasks_register_actions_menu($task);
  44. $params = array(
  45. 'entity' => $task,
  46. 'guid' => $guid,
  47. 'title' => $title,
  48. 'class' => 'elgg-menu-hover',
  49. );
  50. echo elgg_view_icon('hover-menu');
  51. echo elgg_view_menu('tasks_hover', $params);
  52. tasks_reset_actions_menu();
  53. }
  54. if ($use_link) {
  55. $class = elgg_extract('link_class', $vars, '');
  56. $url = elgg_extract('href', $vars, $task->getURL());
  57. echo elgg_view('output/url', array(
  58. 'href' => $url,
  59. 'text' => $icon,
  60. 'is_trusted' => true,
  61. 'class' => $class,
  62. ));
  63. } else {
  64. echo "<a>$icon</a>";
  65. }
  66. ?>
  67. </div>