gallery.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Gallery view
  4. *
  5. * Implemented as an unorder list
  6. *
  7. * @uses $vars['items'] Array of ElggEntity, ElggAnnotation or ElggRiverItem objects
  8. * @uses $vars['offset'] Index of the first list item in complete list
  9. * @uses $vars['limit'] Number of items per page
  10. * @uses $vars['count'] Number of items in the complete list
  11. * @uses $vars['pagination'] Show pagination? (default: true)
  12. * @uses $vars['position'] Position of the pagination: before, after, or both
  13. * @uses $vars['full_view'] Show the full view of the items (default: false)
  14. * @uses $vars['gallery_class'] Additional CSS class for the <ul> element
  15. * @uses $vars['item_class'] Additional CSS class for the <li> elements
  16. * @uses $vars['item_view'] Alternative view to render list items
  17. * @uses $vars['no_results'] Message to display if no results (string|Closure)
  18. */
  19. $items = $vars['items'];
  20. $count = elgg_extract('count', $vars);
  21. $pagination = elgg_extract('pagination', $vars, true);
  22. $position = elgg_extract('position', $vars, 'after');
  23. $no_results = elgg_extract('no_results', $vars, '');
  24. if (!$items && $no_results) {
  25. if ($no_results instanceof Closure) {
  26. echo $no_results();
  27. return;
  28. }
  29. echo "<p class='elgg-no-results'>$no_results</p>";
  30. return;
  31. }
  32. if (!is_array($items) || count($items) == 0) {
  33. return;
  34. }
  35. elgg_push_context('gallery');
  36. $list_classes = ['elgg-gallery'];
  37. if (isset($vars['gallery_class'])) {
  38. $list_classes[] = $vars['gallery_class'];
  39. }
  40. $item_classes = ['elgg-item'];
  41. if (isset($vars['item_class'])) {
  42. $item_classes[] = $vars['item_class'];
  43. }
  44. $nav = ($pagination) ? elgg_view('navigation/pagination', $vars) : '';
  45. $list_items = '';
  46. foreach ($items as $item) {
  47. $item_view = elgg_view_list_item($item, $vars);
  48. if (!$item_view) {
  49. continue;
  50. }
  51. $li_attrs = ['class' => $item_classes];
  52. if ($item instanceof \ElggEntity) {
  53. $li_attrs['id'] = "elgg-{$item->getType()}-{$item->getGUID()}";
  54. } else if (is_callable(array($item, 'getType'))) {
  55. $li_attrs['id'] = "item-{$item->getType()}-{$item->id}";
  56. }
  57. $list_items .= elgg_format_element('li', $li_attrs, $item_view);
  58. }
  59. if ($position == 'before' || $position == 'both') {
  60. echo $nav;
  61. }
  62. echo elgg_format_element('ul', ['class' => $list_classes], $list_items);
  63. if ($position == 'after' || $position == 'both') {
  64. echo $nav;
  65. }
  66. elgg_pop_context();