blog.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * View for blog objects
  4. *
  5. * @package Blog
  6. */
  7. $full = elgg_extract('full_view', $vars, FALSE);
  8. $blog = elgg_extract('entity', $vars, FALSE);
  9. if (!$blog) {
  10. return TRUE;
  11. }
  12. $owner = $blog->getOwnerEntity();
  13. $categories = elgg_view('output/categories', $vars);
  14. $excerpt = $blog->excerpt;
  15. if (!$excerpt) {
  16. $excerpt = elgg_get_excerpt($blog->description);
  17. }
  18. $owner_icon = elgg_view_entity_icon($owner, 'tiny');
  19. $owner_link = elgg_view('output/url', array(
  20. 'href' => "blog/owner/$owner->username",
  21. 'text' => $owner->name,
  22. 'is_trusted' => true,
  23. ));
  24. $author_text = elgg_echo('byline', array($owner_link));
  25. $date = elgg_view_friendly_time($blog->time_created);
  26. // The "on" status changes for comments, so best to check for !Off
  27. if ($blog->comments_on != 'Off') {
  28. $comments_count = $blog->countComments();
  29. //only display if there are commments
  30. if ($comments_count != 0) {
  31. $text = elgg_echo("comments") . " ($comments_count)";
  32. $comments_link = elgg_view('output/url', array(
  33. 'href' => $blog->getURL() . '#comments',
  34. 'text' => $text,
  35. 'is_trusted' => true,
  36. ));
  37. } else {
  38. $comments_link = '';
  39. }
  40. } else {
  41. $comments_link = '';
  42. }
  43. $metadata = elgg_view_menu('entity', array(
  44. 'entity' => $vars['entity'],
  45. 'handler' => 'blog',
  46. 'sort_by' => 'priority',
  47. 'class' => 'elgg-menu-hz',
  48. ));
  49. $subtitle = "$author_text $date $comments_link $categories";
  50. // do not show the metadata and controls in widget view
  51. if (elgg_in_context('widgets')) {
  52. $metadata = '';
  53. }
  54. if ($full) {
  55. $body = elgg_view('output/longtext', array(
  56. 'value' => $blog->description,
  57. 'class' => 'blog-post',
  58. ));
  59. $params = array(
  60. 'entity' => $blog,
  61. 'title' => false,
  62. 'metadata' => $metadata,
  63. 'subtitle' => $subtitle,
  64. );
  65. $params = $params + $vars;
  66. $summary = elgg_view('object/elements/summary', $params);
  67. echo elgg_view('object/elements/full', array(
  68. 'summary' => $summary,
  69. 'icon' => $owner_icon,
  70. 'body' => $body,
  71. ));
  72. } else {
  73. // brief view
  74. $params = array(
  75. 'entity' => $blog,
  76. 'metadata' => $metadata,
  77. 'subtitle' => $subtitle,
  78. 'content' => $excerpt,
  79. );
  80. $params = $params + $vars;
  81. $list_body = elgg_view('object/elements/summary', $params);
  82. echo elgg_view_image_block($owner_icon, $list_body);
  83. }