file.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Elgg file browser.
  4. * File renderer.
  5. *
  6. * @package ElggFile
  7. */
  8. $file = elgg_extract("entity", $vars, false);
  9. $full_view = elgg_extract("full_view", $vars, false);
  10. if (empty($file)) {
  11. return true;
  12. }
  13. $file_guid = $file->getGUID();
  14. $owner = $file->getOwnerEntity();
  15. $tags = elgg_view("output/tags", array("value" => $file->tags));
  16. $categories = elgg_view('output/categories', $vars);
  17. $title = $file->title;
  18. $mime = $file->mimetype;
  19. $base_type = substr($mime, 0, strpos($mime,'/'));
  20. $owner_link = elgg_view("output/url", array("text" => $owner->name, "href" => $owner->getURL(), "is_trusted" => true));
  21. $author_text = elgg_echo("byline", array($owner_link));
  22. // which time format to show
  23. $time_preference = "date";
  24. if ($user_time_preference = elgg_get_plugin_user_setting("file_tools_time_display", null, "file_tools")) {
  25. $time_preference = $user_time_preference;
  26. } elseif ($site_time_preference = elgg_get_plugin_setting("file_tools_default_time_display", "file_tools")) {
  27. $time_preference = $site_time_preference;
  28. }
  29. if ($time_preference == "date") {
  30. $date = date(elgg_echo("friendlytime:date_format"), $file->time_created);
  31. } else {
  32. $date = elgg_view_friendly_time($file->time_created);
  33. }
  34. // count comments
  35. $comments_link = "";
  36. $comment_count = (int) $file->countComments();
  37. if ($comment_count > 0) {
  38. $comments_link = elgg_view("output/url", array(
  39. "href" => $file->getURL() . "#file-comments",
  40. "text" => elgg_echo("comments") . " ($comment_count)",
  41. "is_trusted" => true,
  42. ));
  43. }
  44. $subtitle = "$author_text $date $comments_link $categories";
  45. // title
  46. if (empty($title)) {
  47. $title = elgg_echo("untitled");
  48. }
  49. // entity actions
  50. $entity_menu = "";
  51. if (!elgg_in_context("widgets")) {
  52. $entity_menu = elgg_view_menu("entity", array(
  53. "entity" => $file,
  54. "handler" => "file",
  55. "sort_by" => "priority",
  56. "class" => "elgg-menu-hz"
  57. ));
  58. }
  59. if ($full_view && !elgg_in_context("gallery")) {
  60. // normal full view
  61. // add folder structure to the breadcrumbs
  62. if (file_tools_use_folder_structure()) {
  63. // @todo this should probably be moved to the file view page, but that is currently not under control of file_tools
  64. $endpoint = elgg_pop_breadcrumb();
  65. $parent_folder = elgg_get_entities_from_relationship(array(
  66. 'relationship' => 'folder_of',
  67. 'relationship_guid' => $file->getGUID(),
  68. 'inverse_relationship' => true
  69. ));
  70. $folders = array();
  71. if ($parent_folder) {
  72. $parent_guid = (int) $parent_folder[0]->guid;
  73. while (!empty($parent_guid) && ($parent = get_entity($parent_guid))) {
  74. $folders[] = $parent;
  75. $parent_guid = (int) $parent->parent_guid;
  76. }
  77. }
  78. while ($p = array_pop($folders)) {
  79. elgg_push_breadcrumb($p->title, $p->getURL());
  80. }
  81. elgg_push_breadcrumb($file->title);
  82. }
  83. $extra = "";
  84. if (elgg_view_exists("file/specialcontent/$mime")) {
  85. $extra = elgg_view("file/specialcontent/$mime", $vars);
  86. } elseif (elgg_view_exists("file/specialcontent/$base_type/default")) {
  87. $extra = elgg_view("file/specialcontent/$base_type/default", $vars);
  88. }
  89. $params = array(
  90. "entity" => $file,
  91. "title" => elgg_view("output/url", array("text" => $title, "href" => "file/download/" . $file->getGUID())),
  92. "metadata" => $entity_menu,
  93. "subtitle" => $subtitle,
  94. "tags" => $tags
  95. );
  96. $params = $params + $vars;
  97. $summary = elgg_view("object/elements/summary", $params);
  98. $text = elgg_view("output/longtext", array("value" => $file->description));
  99. $body = "$text $extra";
  100. echo elgg_view("object/elements/full", array(
  101. "entity" => $file,
  102. "title" => false,
  103. "icon" => elgg_view_entity_icon($file, "small"),
  104. "summary" => $summary,
  105. "body" => $body
  106. ));
  107. } elseif (elgg_in_context("gallery")) {
  108. // gallery view of the file
  109. echo "<div class='file-gallery-item'>";
  110. echo "<h3>" . $file->title . "</h3>";
  111. echo elgg_view_entity_icon($file, "medium");
  112. echo "<p class='elgg-quiet'>$owner_link $date</p>";
  113. echo "</div>";
  114. } else {
  115. // listing view of the file
  116. $file_icon_alt = "";
  117. if (file_tools_use_folder_structure()) {
  118. $file_icon = elgg_view_entity_icon($file, "tiny", array("img_class" => "file-tools-icon-tiny"));
  119. if (elgg_in_context("file_tools_selector")) {
  120. $file_icon_alt = elgg_view("input/checkbox", array("name" => "file_guids[]", "value" => $file->getGUID(), "default" => false));
  121. }
  122. $excerpt = "";
  123. $subtitle = "";
  124. $tags = "";
  125. } else {
  126. $file_icon = elgg_view_entity_icon($file, "small");
  127. $excerpt = elgg_get_excerpt($file->description);
  128. }
  129. $params = array(
  130. "entity" => $file,
  131. "metadata" => $entity_menu,
  132. "subtitle" => $subtitle,
  133. "tags" => $tags,
  134. "content" => $excerpt
  135. );
  136. $params = $params + $vars;
  137. $list_body = elgg_view("object/elements/summary", $params);
  138. echo elgg_view_image_block($file_icon, $list_body, array("class" => "file-tools-file", "image_alt" => $file_icon_alt));
  139. }