list.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. $page_owner = elgg_get_page_owner_entity();
  3. $folder_guid = (int) get_input("folder_guid", 0);
  4. $draw_page = get_input("draw_page", true);
  5. $sort_by = get_input("sort_by");
  6. $direction = get_input("direction");
  7. $limit = file_tools_get_list_length();
  8. $offset = (int) get_input("offset", 0);
  9. if (empty($page_owner) || (!elgg_instanceof($page_owner, "user") && !elgg_instanceof($page_owner, "group"))) {
  10. forward(REFERER);
  11. }
  12. elgg_group_gatekeeper();
  13. if ($page_owner->canEdit() || ($page_owner instanceof ElggGroup && $page_owner->isMember())) {
  14. elgg_require_js('file_tools/reorder');
  15. }
  16. if (empty($sort_by)) {
  17. $sort_value = "e.time_created";
  18. if (elgg_instanceof($page_owner, "group") && !empty($page_owner->file_tools_sort)) {
  19. $sort_value = $page_owner->file_tools_sort;
  20. } elseif ($site_sort_default = elgg_get_plugin_setting("sort", "file_tools")) {
  21. $sort_value = $site_sort_default;
  22. }
  23. $sort_by = $sort_value;
  24. }
  25. if (empty($direction)) {
  26. $sort_direction_value = "asc";
  27. if (elgg_instanceof($page_owner, "group") && !empty($page_owner->file_tools_sort_direction)) {
  28. $sort_direction_value = $page_owner->file_tools_sort_direction;
  29. } elseif ($site_sort_direction_default = elgg_get_plugin_setting("sort_direction", "file_tools")) {
  30. $sort_direction_value = $site_sort_direction_default;
  31. }
  32. $direction = $sort_direction_value;
  33. }
  34. $wheres = array();
  35. $wheres[] = "NOT EXISTS (
  36. SELECT 1 FROM " . elgg_get_config("dbprefix") . "entity_relationships r
  37. WHERE r.guid_two = e.guid AND
  38. r.relationship = '" . FILE_TOOLS_RELATIONSHIP . "')";
  39. $files_options = array(
  40. "type" => "object",
  41. "subtype" => "file",
  42. "limit" => $limit,
  43. "offset" => $offset,
  44. "container_guid" => $page_owner->getGUID()
  45. );
  46. $files_options["joins"][] = "JOIN " . elgg_get_config("dbprefix") . "objects_entity oe ON oe.guid = e.guid";
  47. if ($sort_by == "simpletype") {
  48. $files_options["order_by_metadata"] = array("name" => "mimetype", "direction" => $direction);
  49. } else {
  50. $files_options["order_by"] = $sort_by . " " . $direction;
  51. }
  52. $folder = false;
  53. if ($folder_guid !== false) {
  54. $folder = get_entity($folder_guid);
  55. if (!empty($folder) && elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE) && ($folder->getContainerGUID() == $page_owner->getGUID())) {
  56. $files_options["relationship"] = FILE_TOOLS_RELATIONSHIP;
  57. $files_options["relationship_guid"] = $folder_guid;
  58. $files_options["inverse_relationship"] = false;
  59. } else {
  60. $folder = false; // just to be save
  61. $files_options["wheres"] = $wheres;
  62. }
  63. }
  64. // get the files
  65. $files = elgg_get_entities_from_relationship($files_options);
  66. // get count
  67. $files_options["count"] = true;
  68. $files_count = elgg_get_entities_from_relationship($files_options);
  69. // do we need a more button
  70. $show_more = false;
  71. if ($limit) {
  72. $show_more = $files_count > ($offset + $limit);
  73. }
  74. if (!$draw_page) {
  75. echo elgg_view("file_tools/list/files", array(
  76. "folder" => $folder,
  77. "files" => $files,
  78. "sort_by" => $sort_by,
  79. "direction" => $direction,
  80. "show_more" => $show_more,
  81. "limit" => $limit,
  82. "offset" => $offset
  83. ));
  84. } else {
  85. // build breadcrumb
  86. elgg_push_breadcrumb(elgg_echo("file"), "file/all");
  87. elgg_push_breadcrumb($page_owner->name);
  88. // register title button to add a new file
  89. elgg_register_title_button();
  90. // get data for tree
  91. $folders = file_tools_get_folders($page_owner->getGUID());
  92. // build page elements
  93. $title_text = elgg_echo("file:user", array($page_owner->name));
  94. $body = "<div id='file_tools_list_files_container' class='elgg-content'>" . elgg_view("graphics/ajax_loader", array("hidden" => false)) . "</div>";
  95. // make sidebar
  96. $sidebar = elgg_view("file_tools/list/tree", array("folder" => $folder, "folders" => $folders));
  97. $sidebar .= elgg_view("file_tools/sidebar/sort_options");
  98. $sidebar .= elgg_view("file_tools/sidebar/info");
  99. $sidebar .= elgg_view("page/elements/tagcloud_block", array("subtypes" => "file", "owner_guid" => $page_owner->getGUID()));
  100. // build page params
  101. $params = array(
  102. "title" => $title_text,
  103. "content" => $body,
  104. "sidebar" => $sidebar
  105. );
  106. if (elgg_instanceof($page_owner, "user")) {
  107. if ($page_owner->getGUID() == elgg_get_logged_in_user_guid()) {
  108. $params["filter_context"] = "mine";
  109. } else {
  110. $params["filter_context"] = $page_owner->username;
  111. }
  112. } else {
  113. $params["filter"] = false;
  114. }
  115. echo elgg_view_page($title_text, elgg_view_layout("content", $params));
  116. }