content.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. $widget = elgg_extract("entity", $vars);
  3. $site_url = elgg_get_site_url();
  4. if ($folder_guids = $widget->folder_guids) {
  5. $show_content = $widget->show_content;
  6. if (!is_array($folder_guids)) {
  7. $folder_guids = array($folder_guids);
  8. }
  9. $folder_guids = array_map("sanitise_int", $folder_guids);
  10. $folders = "";
  11. foreach ($folder_guids as $guid) {
  12. if (($folder = get_entity($guid)) && ($folder->getSubtype() == FILE_TOOLS_SUBTYPE)) {
  13. if (!empty($show_content)) {
  14. // list the files
  15. $folders .= elgg_view_entity($folder, array("full_view" => false));
  16. // list the content
  17. if (!($sub_folders = file_tools_get_sub_folders($folder))) {
  18. $sub_folders = array();
  19. }
  20. $files_options = array(
  21. "type" => "object",
  22. "subtype" => "file",
  23. "limit" => false,
  24. "container_guid" => $widget->getOwnerGUID(),
  25. "relationship" => FILE_TOOLS_RELATIONSHIP,
  26. "relationship_guid" => $folder->getGUID(),
  27. "inverse_relationship" => false,
  28. );
  29. $files = elgg_get_entities_from_relationship($files_options);
  30. $entities = array_merge($sub_folders, $files);
  31. $folders .= "<div class='mlm'>";
  32. $folders .= elgg_view_entity_list($entities, array("full_view" => false, "pagination" => false));
  33. $folders .= "</div>";
  34. } else {
  35. $folders .= elgg_view_entity($folder);
  36. }
  37. }
  38. }
  39. if (!empty($folders)) {
  40. $owner = $widget->getOwnerEntity();
  41. if (elgg_instanceof($owner, "user")) {
  42. $more_url = $site_url . "file/owner/" . $owner->username;
  43. } else {
  44. $more_url = $site_url . "file/group/" . $owner->getGUID() . "/all";
  45. }
  46. echo $folders;
  47. echo "<div class='widget_more_wrapper'>";
  48. echo elgg_view("output/url", array("href" => $more_url, "text" => elgg_echo("widgets:file_tree:more")));
  49. echo "</div>";
  50. } else {
  51. echo elgg_echo("notfound");
  52. }
  53. } else {
  54. echo elgg_echo("widgets:file_tree:no_folders");
  55. }