attachmentlist.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if (!count($attachments)) {
  74. return 0;
  75. }
  76. if ($this->notice->getProfile()->isSilenced()) {
  77. // TRANS: Message for inline attachments list in notices when the author has been silenced.
  78. $this->element('div', ['class'=>'error'],
  79. _('Attachments are hidden because this profile has been silenced.'));
  80. return 0;
  81. }
  82. $this->showListStart();
  83. foreach ($attachments as $att) {
  84. $item = $this->newListItem($att);
  85. $item->show();
  86. }
  87. $this->showListEnd();
  88. return count($attachments);
  89. }
  90. function showListStart()
  91. {
  92. $this->out->elementStart('ol', array('class' => 'attachments'));
  93. }
  94. function showListEnd()
  95. {
  96. $this->out->elementEnd('ol');
  97. }
  98. /**
  99. * returns a new list item for the current attachment
  100. *
  101. * @param File $attachment the current attachment
  102. *
  103. * @return AttachmentListItem a list item for displaying the attachment
  104. */
  105. function newListItem(File $attachment)
  106. {
  107. return new AttachmentListItem($attachment, $this->out);
  108. }
  109. }