attachmentlist.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * widget for displaying a list of notice attachments
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category UI
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @author Sarven Capadisli <csarven@status.net>
  26. * @copyright 2008 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * widget for displaying a list of notice attachments
  33. *
  34. * There are a number of actions that display a list of notices, in
  35. * reverse chronological order. This widget abstracts out most of the
  36. * code for UI for notice lists. It's overridden to hide some
  37. * data for e.g. the profile page.
  38. *
  39. * @category UI
  40. * @package StatusNet
  41. * @author Evan Prodromou <evan@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  43. * @link http://status.net/
  44. * @see Notice
  45. * @see NoticeListItem
  46. * @see ProfileNoticeList
  47. */
  48. class AttachmentList extends Widget
  49. {
  50. /** the current stream of notices being displayed. */
  51. var $notice = null;
  52. /**
  53. * constructor
  54. *
  55. * @param Notice $notice stream of notices from DB_DataObject
  56. */
  57. function __construct(Notice $notice, $out=null)
  58. {
  59. parent::__construct($out);
  60. $this->notice = $notice;
  61. }
  62. /**
  63. * show the list of attachments
  64. *
  65. * "Uses up" the stream by looping through it. So, probably can't
  66. * be called twice on the same list.
  67. *
  68. * @return int count of items listed.
  69. */
  70. function show()
  71. {
  72. $attachments = $this->notice->attachments();
  73. foreach ($attachments as $key=>$att) {
  74. // Remove attachments which are not representable with neither a title nor thumbnail
  75. if ($att->getTitle() === null && !$att->hasThumbnail()) {
  76. unset($attachments[$key]);
  77. }
  78. }
  79. if (!count($attachments)) {
  80. return 0;
  81. }
  82. if ($this->notice->getProfile()->isSilenced()) {
  83. // TRANS: Message for inline attachments list in notices when the author has been silenced.
  84. $this->element('div', ['class'=>'error'], _('Attachments are hidden because this profile has been silenced.'));
  85. return 0;
  86. }
  87. $this->showListStart();
  88. foreach ($attachments as $att) {
  89. $item = $this->newListItem($att);
  90. $item->show();
  91. }
  92. $this->showListEnd();
  93. return count($attachments);
  94. }
  95. function showListStart()
  96. {
  97. $this->out->elementStart('ol', array('class' => 'attachments'));
  98. }
  99. function showListEnd()
  100. {
  101. $this->out->elementEnd('ol');
  102. }
  103. /**
  104. * returns a new list item for the current attachment
  105. *
  106. * @param File $attachment the current attachment
  107. *
  108. * @return AttachmentListItem a list item for displaying the attachment
  109. */
  110. function newListItem(File $attachment)
  111. {
  112. return new AttachmentListItem($attachment, $this->out);
  113. }
  114. }