messagelistitem.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * A single list item for showing in a message list
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Widget
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * A single item in a message list
  37. *
  38. * @category Widget
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. abstract class MessageListItem extends Widget
  46. {
  47. var $message;
  48. /**
  49. * Constructor
  50. *
  51. * @param HTMLOutputter $out Output context
  52. * @param Message $message Message to show
  53. */
  54. function __construct($out, $message)
  55. {
  56. parent::__construct($out);
  57. $this->message = $message;
  58. }
  59. /**
  60. * Show the widget
  61. *
  62. * @return void
  63. */
  64. function show()
  65. {
  66. $this->out->elementStart('li', array('class' => 'h-entry notice',
  67. 'id' => 'message-' . $this->message->id));
  68. $profile = $this->getMessageProfile();
  69. $this->out->elementStart('a', array('href' => $profile->profileurl,
  70. 'class' => 'p-author'));
  71. $avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
  72. $this->out->element('img', array('src' => $avatarUrl,
  73. 'class' => 'avatar u-photo',
  74. 'width' => AVATAR_STREAM_SIZE,
  75. 'height' => AVATAR_STREAM_SIZE,
  76. 'alt' => $profile->getBestName()));
  77. $this->out->element('span', array('class' => 'nickname fn'), $profile->getNickname());
  78. $this->out->elementEnd('a');
  79. // FIXME: URL, image, video, audio
  80. $this->out->elementStart('div', array('class' => 'e-content'));
  81. $this->out->raw($this->message->rendered);
  82. $this->out->elementEnd('div');
  83. $messageurl = common_local_url('showmessage',
  84. array('message' => $this->message->id));
  85. // XXX: we need to figure this out better. Is this right?
  86. if (strcmp($this->message->uri, $messageurl) != 0 &&
  87. preg_match('/^http/', $this->message->uri)) {
  88. $messageurl = $this->message->uri;
  89. }
  90. $this->out->elementStart('div', 'entry-metadata');
  91. $this->out->elementStart('a', array('rel' => 'bookmark',
  92. 'class' => 'timestamp',
  93. 'href' => $messageurl));
  94. $dt = common_date_iso8601($this->message->created);
  95. $this->out->element('time', array('class' => 'dt-published',
  96. 'datetime' => common_date_iso8601($this->message->created),
  97. // TRANS: Timestamp title (tooltip text) for NoticeListItem
  98. 'title' => common_exact_date($this->message->created)),
  99. common_date_string($this->message->created));
  100. $this->out->elementEnd('a');
  101. if ($this->message->source) {
  102. $this->out->elementStart('span', 'source');
  103. // FIXME: bad i18n. Device should be a parameter (from %s).
  104. // TRANS: Followed by notice source (usually the client used to send the notice).
  105. $this->out->text(_('from'));
  106. $this->showSource($this->message->source);
  107. $this->out->elementEnd('span');
  108. }
  109. $this->out->elementEnd('div');
  110. $this->out->elementEnd('li');
  111. }
  112. /**
  113. * Dummy method. Serves no other purpose than to make strings available used
  114. * in self::showSource() through xgettext.
  115. *
  116. * @return void
  117. */
  118. function messageListItemDummyMessages()
  119. {
  120. // A dummy array with messages. These will get extracted by xgettext and
  121. // are used in self::showSource().
  122. $dummy_messages = array(
  123. // TRANS: A possible notice source (web interface).
  124. _m('SOURCE','web'),
  125. // TRANS: A possible notice source (XMPP).
  126. _m('SOURCE','xmpp'),
  127. // TRANS: A possible notice source (e-mail).
  128. _m('SOURCE','mail'),
  129. // TRANS: A possible notice source (OpenMicroBlogging).
  130. _m('SOURCE','omb'),
  131. // TRANS: A possible notice source (Application Programming Interface).
  132. _m('SOURCE','api'),
  133. );
  134. }
  135. /**
  136. * Show the source of the message
  137. *
  138. * Returns either the name (and link) of the API client that posted the notice,
  139. * or one of other other channels.
  140. *
  141. * @param string $source the source of the message
  142. *
  143. * @return void
  144. */
  145. function showSource($source)
  146. {
  147. $source_name = _m('SOURCE',$source);
  148. switch ($source) {
  149. case 'web':
  150. case 'xmpp':
  151. case 'mail':
  152. case 'omb':
  153. case 'api':
  154. $this->out->element('span', 'device', $source_name);
  155. break;
  156. default:
  157. $ns = Notice_source::getKV($source);
  158. if ($ns) {
  159. $this->out->elementStart('span', 'device');
  160. $this->out->element('a', array('href' => $ns->url,
  161. 'rel' => 'external'),
  162. $ns->name);
  163. $this->out->elementEnd('span');
  164. } else {
  165. $this->out->element('span', 'device', $source_name);
  166. }
  167. break;
  168. }
  169. return;
  170. }
  171. /**
  172. * Return the profile to show in the message item
  173. *
  174. * Overridden in sub-classes to show sender, receiver, or whatever
  175. *
  176. * @return Profile profile to show avatar and name of
  177. */
  178. abstract function getMessageProfile();
  179. }