attachmentlist.php 3.5 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, $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. $representable = false;
  74. foreach ($attachments as $key=>$att) {
  75. // Only show attachments representable with a title
  76. if ($att->getTitle() === null) {
  77. unset($attachments[$key]);
  78. }
  79. }
  80. if (!count($attachments)) {
  81. return 0;
  82. }
  83. $this->showListStart();
  84. foreach ($attachments as $att) {
  85. $item = $this->newListItem($att);
  86. $item->show();
  87. }
  88. $this->showListEnd();
  89. return count($attachments);
  90. }
  91. function showListStart()
  92. {
  93. $this->out->elementStart('ol', array('class' => 'attachments'));
  94. }
  95. function showListEnd()
  96. {
  97. $this->out->elementEnd('ol');
  98. }
  99. /**
  100. * returns a new list item for the current attachment
  101. *
  102. * @param File $attachment the current attachment
  103. *
  104. * @return AttachmentListItem a list item for displaying the attachment
  105. */
  106. function newListItem(File $attachment)
  107. {
  108. return new AttachmentListItem($attachment, $this->out);
  109. }
  110. }