page_top.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * View for page object
  4. *
  5. * @package ElggPages
  6. *
  7. * @uses $vars['entity'] The page object
  8. * @uses $vars['full_view'] Whether to display the full view
  9. * @uses $vars['revision'] This parameter not supported by elgg_view_entity()
  10. */
  11. $full = elgg_extract('full_view', $vars, FALSE);
  12. $page = elgg_extract('entity', $vars, FALSE);
  13. $revision = elgg_extract('revision', $vars, FALSE);
  14. if (!$page) {
  15. return TRUE;
  16. }
  17. // pages used to use Public for write access
  18. if ($page->write_access_id == ACCESS_PUBLIC) {
  19. // this works because this metadata is public
  20. $page->write_access_id = ACCESS_LOGGED_IN;
  21. }
  22. if ($revision) {
  23. $annotation = $revision;
  24. } else {
  25. $annotation = $page->getAnnotations(array(
  26. 'annotation_name' => 'page',
  27. 'limit' => 1,
  28. 'reverse_order_by' => true,
  29. ));
  30. if ($annotation) {
  31. $annotation = $annotation[0];
  32. } else {
  33. elgg_log("Failed to access annotation for page with GUID {$page->guid}", 'WARNING');
  34. return;
  35. }
  36. }
  37. $page_icon = elgg_view('pages/icon', array('annotation' => $annotation, 'size' => 'small'));
  38. $editor = get_entity($annotation->owner_guid);
  39. $editor_link = elgg_view('output/url', array(
  40. 'href' => "pages/owner/$editor->username",
  41. 'text' => $editor->name,
  42. 'is_trusted' => true,
  43. ));
  44. $date = elgg_view_friendly_time($annotation->time_created);
  45. $editor_text = elgg_echo('pages:strapline', array($date, $editor_link));
  46. $categories = elgg_view('output/categories', $vars);
  47. $comments_count = $page->countComments();
  48. //only display if there are commments
  49. if ($comments_count != 0 && !$revision) {
  50. $text = elgg_echo("comments") . " ($comments_count)";
  51. $comments_link = elgg_view('output/url', array(
  52. 'href' => $page->getURL() . '#comments',
  53. 'text' => $text,
  54. 'is_trusted' => true,
  55. ));
  56. } else {
  57. $comments_link = '';
  58. }
  59. $subtitle = "$editor_text $comments_link $categories";
  60. // do not show the metadata and controls in widget view
  61. if (!elgg_in_context('widgets')) {
  62. // If we're looking at a revision, display annotation menu
  63. if ($revision) {
  64. $metadata = elgg_view_menu('annotation', array(
  65. 'annotation' => $annotation,
  66. 'sort_by' => 'priority',
  67. 'class' => 'elgg-menu-hz float-alt',
  68. ));
  69. } else {
  70. // Regular entity menu
  71. $metadata = elgg_view_menu('entity', array(
  72. 'entity' => $vars['entity'],
  73. 'handler' => 'pages',
  74. 'sort_by' => 'priority',
  75. 'class' => 'elgg-menu-hz',
  76. ));
  77. }
  78. }
  79. if ($full) {
  80. $body = elgg_view('output/longtext', array('value' => $annotation->value));
  81. $params = array(
  82. 'entity' => $page,
  83. 'metadata' => $metadata,
  84. 'subtitle' => $subtitle,
  85. );
  86. $params = $params + $vars;
  87. $summary = elgg_view('object/elements/summary', $params);
  88. echo elgg_view('object/elements/full', array(
  89. 'entity' => $page,
  90. 'title' => false,
  91. 'icon' => $page_icon,
  92. 'summary' => $summary,
  93. 'body' => $body,
  94. ));
  95. } else {
  96. // brief view
  97. $excerpt = elgg_get_excerpt($page->description);
  98. $params = array(
  99. 'entity' => $page,
  100. 'metadata' => $metadata,
  101. 'subtitle' => $subtitle,
  102. 'content' => $excerpt,
  103. );
  104. $params = $params + $vars;
  105. $list_body = elgg_view('object/elements/summary', $params);
  106. echo elgg_view_image_block($page_icon, $list_body);
  107. }