messages.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * ElggPG -- Display encrypted message
  4. *
  5. * @package Lorea
  6. * @subpackage ElggPG
  7. * @override mod/messages/views/object/messages.php
  8. *
  9. * Copyright 2011-2013 Lorea Faeries <federation@lorea.org>
  10. *
  11. * This file is part of the ElggPG plugin for Elgg.
  12. *
  13. * ElggPG is free software: you can redistribute it and/or modify it
  14. * under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * ElggPG is distributed in the hope that it will be useful, but
  19. * WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public
  24. * License along with this program. If not, see
  25. * <http://www.gnu.org/licenses/>.
  26. */
  27. $full = elgg_extract('full_view', $vars, false);
  28. $message = elgg_extract('entity', $vars, false);
  29. if (!$message) {
  30. return true;
  31. }
  32. if ($message->toId == elgg_get_page_owner_guid()) {
  33. // received
  34. $user = get_entity($message->fromId);
  35. if ($user) {
  36. $icon = elgg_view_entity_icon($user, 'tiny');
  37. $user_link = elgg_view('output/url', array(
  38. 'href' => "messages/compose?send_to=$user->guid",
  39. 'text' => $user->name,
  40. 'is_trusted' => true,
  41. ));
  42. } else {
  43. $icon = '';
  44. $user_link = elgg_echo('messages:deleted_sender');
  45. }
  46. if ($message->readYet) {
  47. $class = 'message read';
  48. } else {
  49. $class = 'message unread';
  50. }
  51. } else {
  52. // sent
  53. $user = get_entity($message->toId);
  54. if ($user) {
  55. $icon = elgg_view_entity_icon($user, 'tiny');
  56. $user_link = elgg_view('output/url', array(
  57. 'href' => "messages/compose?send_to=$user->guid",
  58. 'text' => elgg_echo('messages:to_user', array($user->name)),
  59. 'is_trusted' => true,
  60. ));
  61. } else {
  62. $icon = '';
  63. $user_link = elgg_echo('messages:deleted_sender');
  64. }
  65. $class = 'message read';
  66. }
  67. $timestamp = elgg_view_friendly_time($message->time_created);
  68. $subject_info = '';
  69. if (!$full) {
  70. $subject_info .= "<input type='checkbox' name=\"message_id[]\" value=\"{$message->guid}\" />";
  71. }
  72. $subject_info .= elgg_view('output/url', array(
  73. 'href' => $message->getURL(),
  74. 'text' => $message->title,
  75. 'is_trusted' => true,
  76. ));
  77. $delete_link = elgg_view("output/confirmlink", array(
  78. 'href' => "action/messages/delete?guid=" . $message->getGUID(),
  79. 'text' => "<span class=\"elgg-icon elgg-icon-delete float-alt\"></span>",
  80. 'confirm' => elgg_echo('deleteconfirm'),
  81. 'encode_text' => false,
  82. ));
  83. $body = <<<HTML
  84. <div class="messages-owner">$user_link</div>
  85. <div class="messages-subject">$subject_info</div>
  86. <div class="messages-timestamp">$timestamp</div>
  87. <div class="messages-delete">$delete_link</div>
  88. HTML;
  89. if ($full) {
  90. echo elgg_view_image_block($icon, $body, array('class' => $class));
  91. if (strpos($message->description, "-----BEGIN PGP MESSAGE-----") !== false) {
  92. echo "<pre class=\"pgparmor\">" . $message->description . "</pre>";
  93. } else {
  94. echo elgg_view('output/longtext', array('value' => $message->description));
  95. }
  96. } else {
  97. echo elgg_view_image_block($icon, $body, array('class' => $class));
  98. }