file.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * File renderer.
  4. *
  5. * @package ElggFile
  6. */
  7. $full = elgg_extract('full_view', $vars, FALSE);
  8. $file = elgg_extract('entity', $vars, FALSE);
  9. if (!$file) {
  10. return TRUE;
  11. }
  12. $owner = $file->getOwnerEntity();
  13. $container = $file->getContainerEntity();
  14. $categories = elgg_view('output/categories', $vars);
  15. $excerpt = elgg_get_excerpt($file->description);
  16. $mime = $file->mimetype;
  17. $base_type = $file->simpletype;
  18. $owner_link = elgg_view('output/url', array(
  19. 'href' => "file/owner/$owner->username",
  20. 'text' => $owner->name,
  21. 'is_trusted' => true,
  22. ));
  23. $author_text = elgg_echo('byline', array($owner_link));
  24. $date = elgg_view_friendly_time($file->time_created);
  25. $comments_count = $file->countComments();
  26. //only display if there are commments
  27. if ($comments_count != 0) {
  28. $text = elgg_echo("comments") . " ($comments_count)";
  29. $comments_link = elgg_view('output/url', array(
  30. 'href' => $file->getURL() . '#comments',
  31. 'text' => $text,
  32. 'is_trusted' => true,
  33. ));
  34. } else {
  35. $comments_link = '';
  36. }
  37. $metadata = elgg_view_menu('entity', array(
  38. 'entity' => $vars['entity'],
  39. 'handler' => 'file',
  40. 'sort_by' => 'priority',
  41. 'class' => 'elgg-menu-hz',
  42. ));
  43. $subtitle = "$author_text $date $comments_link $categories";
  44. // do not show the metadata and controls in widget view
  45. if (elgg_in_context('widgets')) {
  46. $metadata = '';
  47. }
  48. if ($full && !elgg_in_context('gallery')) {
  49. $text = elgg_view('output/longtext', array('value' => $file->description));
  50. $extra = '';
  51. if (elgg_view_exists("file/specialcontent/$mime")) {
  52. $extra = elgg_view("file/specialcontent/$mime", $vars);
  53. $text = '';
  54. } else if (elgg_view_exists("file/specialcontent/$base_type/default")) {
  55. $extra = elgg_view("file/specialcontent/$base_type/default", $vars);
  56. $text = '';
  57. }
  58. $params = array(
  59. 'entity' => $file,
  60. 'title' => false,
  61. 'metadata' => $metadata,
  62. 'subtitle' => $subtitle,
  63. );
  64. $params = $params + $vars;
  65. $summary = elgg_view('object/elements/summary', $params);
  66. $body = "$text $extra";
  67. $file_icon = elgg_view_entity_icon($file, 'small', array('href' => false));
  68. echo elgg_view('object/elements/full', array(
  69. 'entity' => $file,
  70. 'icon' => $file_icon,
  71. 'summary' => $summary,
  72. 'body' => $body,
  73. ));
  74. } elseif (elgg_in_context('gallery')) {
  75. echo '<div class="file-gallery-item">';
  76. echo "<h4>" . $file->title . "</h4>";
  77. echo elgg_view_entity_icon($file, 'medium');
  78. echo "<p class='subtitle'>$owner_link $date</p>";
  79. echo '</div>';
  80. } else {
  81. // brief view
  82. $file_icon = elgg_view_entity_icon($file, 'small');
  83. $params = array(
  84. 'entity' => $file,
  85. 'metadata' => $metadata,
  86. 'subtitle' => $subtitle,
  87. 'content' => $excerpt,
  88. );
  89. $params = $params + $vars;
  90. $list_body = elgg_view('object/elements/summary', $params);
  91. echo elgg_view_image_block($file_icon, $list_body);
  92. }