content.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * content of the group news widget
  4. */
  5. $widget = $vars["entity"];
  6. $configured_projects = array();
  7. for ($i = 1; $i < 6; $i++) {
  8. $metadata_name = "project_" . $i;
  9. if ($guid = $widget->$metadata_name) {
  10. $group = get_entity($guid);
  11. if (!empty($group) && elgg_instanceof($group, "group")) {
  12. $configured_projects[] = $group;
  13. }
  14. }
  15. }
  16. if (!empty($configured_projects)) {
  17. if (elgg_is_xhr()) {
  18. echo "<script type='text/javascript'>require(['group_tools/group_news']);</script>";
  19. } else {
  20. elgg_require_js("group_tools/group_news");
  21. }
  22. $blog_count = sanitise_int($widget->blog_count);
  23. if ($blog_count < 1) {
  24. $blog_count = 5;
  25. }
  26. $group_icon_size = $widget->group_icon_size;
  27. if ($group_icon_size !== "small") {
  28. $group_icon_size = "medium";
  29. }
  30. echo "<div class='widget_group_news_container'>";
  31. foreach ($configured_projects as $key => $group) {
  32. $body = "<h3>" . $group->name . "</h3>";
  33. $icon = elgg_view_entity_icon($group, $group_icon_size);
  34. $group_news = elgg_get_entities(array(
  35. "type" => "object",
  36. "subtype" => "blog",
  37. "container_guid" => $group->getGUID(),
  38. "limit" => $blog_count
  39. ));
  40. if (!empty($group_news)) {
  41. $body .= "<ul>";
  42. foreach ($group_news as $news) {
  43. $body .= "<li><a href='" . $news->getURL() . "'>" . $news->title . "</a></li>";
  44. }
  45. $body .= "</ul>";
  46. } else {
  47. $body .= elgg_echo("widgets:group_news:no_news");
  48. }
  49. $class = "widget_group_news_" . ($key + 1) . "_" . $group->getGUID();
  50. if ($key !== 0) {
  51. $class .= " hidden";
  52. }
  53. echo elgg_view_image_block($icon, $body, array("class" => $class));
  54. }
  55. echo "</div>";
  56. $configured_projects = array_values($configured_projects);
  57. echo "<div class='widget_group_news_navigator'>";
  58. foreach ($configured_projects as $key => $group) {
  59. $class = "";
  60. if ($key == 0) {
  61. $class = " class='active'";
  62. }
  63. echo "<span rel='widget_group_news_" . ($key + 1) . "_" . $group->getGUID() . "'" . $class . ">" . ($key + 1) . "</span>";
  64. }
  65. echo "</div>";
  66. } else {
  67. echo elgg_echo("widgets:group_news:no_projects");
  68. }