market.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * Elgg Market Plugin
  4. * @package market
  5. */
  6. $full = elgg_extract('full_view', $vars, FALSE);
  7. $post = $vars['entity'];
  8. if (!$post) {
  9. return TRUE;
  10. }
  11. $currency = elgg_get_plugin_setting('market_currency', 'market');
  12. $owner = $post->getOwnerEntity();
  13. $tu = $post->time_updated;
  14. $container = $post->getContainerEntity();
  15. $category = "<b>" . elgg_echo('market:category') . ":</b> " . elgg_echo("market:category:{$post->marketcategory}");
  16. $type = "<b>" . elgg_echo('market:type') . ":</b> " . elgg_echo("market:type:{$post->market_type}");
  17. $excerpt = elgg_get_excerpt($post->description);
  18. $owner_link = elgg_view('output/url', array(
  19. 'href' => "market/owned/{$owner->username}",
  20. 'text' => $owner->name,
  21. ));
  22. $author_text = elgg_echo('byline', array($owner_link));
  23. $image = elgg_view('market/thumbnail', array(
  24. 'guid' => $post->guid,
  25. 'imagenum' => 1,
  26. 'size' => 'medium',
  27. 'class' => '',
  28. 'tu' => $tu
  29. ));
  30. $market_img = elgg_view('output/url', array(
  31. 'href' => "market/view/$owner->username",
  32. 'text' => $image,
  33. ));
  34. $tags = elgg_view('output/tags', array('tags' => $post->tags));
  35. $date = elgg_view_friendly_time($post->time_created);
  36. $custom = '';
  37. if(isset($marketpost->custom) && elgg_get_plugin_setting('market_custom', 'market') == 'yes'){
  38. $custom = "<br><b>" . elgg_echo('market:custom:text') . ": </b>" . elgg_echo($post->custom);
  39. }
  40. $location = '';
  41. if (elgg_get_plugin_setting('location', 'market') == 'yes') {
  42. $location = elgg_view('output/location', array(
  43. 'entity' => $post,
  44. 'value' => $post->location,
  45. ));
  46. $location = "<br><b>" . elgg_echo('market:location') . ": </b>$location";
  47. }
  48. $comments_count = $post->countComments();
  49. //only display if there are commments
  50. if ($comments_count != 0) {
  51. $text = elgg_echo("comments") . " ($comments_count)";
  52. $comments_link = elgg_view('output/url', array(
  53. 'href' => $post->getURL() . '#market-comments',
  54. 'text' => $text,
  55. ));
  56. } else {
  57. $comments_link = '';
  58. }
  59. $metadata = elgg_view_menu('entity', array(
  60. 'entity' => $post,
  61. 'handler' => 'market',
  62. 'sort_by' => 'priority',
  63. 'class' => 'elgg-menu-hz',
  64. ));
  65. if ($full) {
  66. $post_body = '';
  67. $post_body .= "<div class='mbm mts'><span class='market_pricetag'><b>" . elgg_echo('market:price') . "</b> {$currency} {$post->price}</span></div>";
  68. $thumbnail = elgg_view('output/img', array(
  69. 'src' => "market/image/{$post->guid}/1/large/{$tu}.jpg",
  70. 'class' => 'elgg-photo',
  71. 'alt' => $post->guid,
  72. ));
  73. $img = elgg_view('output/url', array(
  74. 'href' => "market/image/{$post->guid}/1/master/{$tu}.jpg",
  75. 'text' => $thumbnail,
  76. 'class' => "elgg-lightbox-photo market-thumbnail",
  77. 'rel' => 'market-gallery',
  78. ));
  79. $obs_img = elgg_view('output/img', array(
  80. 'src' => "market/image/{$post->guid}/1/large/{$tu}",
  81. 'class' => 'elgg-photo',
  82. 'alt' => $post->guid,
  83. ));
  84. $images = unserialize($post->images);
  85. if (is_array($images)) {
  86. $post_images = '';
  87. foreach ($images as $key => $value) {
  88. if ($value) {
  89. $post_img = elgg_view('output/img', array(
  90. 'src' => "market/image/{$post->guid}/$key/small/{$tu}.jpg",
  91. 'class' => 'elgg-photo',
  92. 'alt' => $post->guid,
  93. ));
  94. $post_images .= elgg_view('output/url', array(
  95. 'href' => "market/image/{$post->guid}/$key/master/{$tu}.jpg",
  96. 'text' => $post_img,
  97. 'class' => "elgg-lightbox-photo market-thumbnail",
  98. 'rel' => 'market-gallery',
  99. 'data-colorboxOpts' => "{slideshow: true, rel: 'group'}",
  100. ));
  101. }
  102. }
  103. }
  104. if ($post_images) {
  105. $post_body .= "<div>$post_images</div>";
  106. }
  107. if (elgg_get_plugin_setting('market_allowhtml', 'market') != 'yes') {
  108. $post_body .= elgg_autop(parse_urls(strip_tags($post->description)));
  109. } else {
  110. $post_body .= elgg_view('output/longtext', array('value' => $post->description));
  111. }
  112. if (elgg_get_plugin_setting('market_pmbutton', 'market') == 'yes') {
  113. if ($owner->guid != elgg_get_logged_in_user_guid()) {
  114. $post_body .= elgg_view('output/url', array(
  115. 'class' => 'elgg-button elgg-button-action mtm',
  116. 'href' => "messages/compose?send_to={$owner->guid}",
  117. 'text' => elgg_echo('market:pmbuttontext'),
  118. ));
  119. }
  120. }
  121. $marketpost = elgg_view_image_block($img, $post_body, array('class' => 'market-image-block'));
  122. $subtitle = "{$author_text} {$date} {$comments_link}";
  123. $subtitle .= "<br>{$category}<br>{$type}{$custom}{$location}";
  124. $params = array(
  125. 'entity' => $post,
  126. 'header' => $header,
  127. 'metadata' => $metadata,
  128. 'subtitle' => $subtitle,
  129. 'tags' => $tags,
  130. );
  131. $params = $params + $vars;
  132. $list_body = elgg_view('object/elements/summary', $params);
  133. $owner_icon = elgg_view_entity_icon($owner, 'small');
  134. $marketpost_info = elgg_view_image_block($owner_icon, $list_body);
  135. echo $marketpost_info;
  136. echo $marketpost;
  137. echo "<script>$( document ).ready(function() { $('a.market-thumbnail').colorbox(); })</script>";
  138. } else {
  139. // brief view
  140. $img = elgg_view('output/img', array(
  141. 'src' => "market/image/{$post->guid}/1/medium/{$tu}",
  142. 'class' => 'market-image-list',
  143. 'alt' => $post->guid,
  144. ));
  145. $market_img = elgg_view('output/url', array(
  146. 'href' => "market/view/{$post->guid}/" . elgg_get_friendly_title($post->title),
  147. 'text' => $img,
  148. ));
  149. $subtitle = "{$author_text} {$date} {$comments_link}";
  150. $subtitle .= "<br>{$category}<br>{$type}<br>";
  151. $subtitle .= "<b>" . elgg_echo('market:price') . ":</b> {$currency} {$post->price}{$custom}{$location}";
  152. if (elgg_in_context('widgets')) {
  153. $metadata = '';
  154. $tags = false;
  155. }
  156. $params = array(
  157. 'entity' => $post,
  158. 'metadata' => $metadata,
  159. 'subtitle' => $subtitle,
  160. 'tags' => $tags,
  161. 'content' => $excerpt,
  162. );
  163. $params = $params + $vars;
  164. $list_body = elgg_view('object/elements/summary', $params);
  165. echo elgg_view_image_block($market_img, $list_body, array('class' => 'market-list-block'));
  166. }