feedlist.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget for showing a list of feeds
  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 Widget
  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 showing a list of feeds
  33. *
  34. * Typically used for Action::showExportList()
  35. *
  36. * @category Widget
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @author Sarven Capadisli <csarven@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. *
  43. * @see Action::showExportList()
  44. */
  45. class FeedList extends Widget
  46. {
  47. var $action = null;
  48. protected $feeds = null;
  49. public function __construct(Action $action=null, array $feeds=array())
  50. {
  51. parent::__construct($action);
  52. $this->action = $action;
  53. $this->feeds = $feeds;
  54. }
  55. public function show()
  56. {
  57. if (Event::handle('StartShowFeedLinkList', array($this->action, &$this->feeds))) {
  58. if (!empty($this->feeds)) {
  59. $this->out->elementStart('div', array('id' => 'export_data',
  60. 'class' => 'section'));
  61. // TRANS: Header for feed links (h2).
  62. $this->out->element('h2', null, _('Feeds'));
  63. $this->out->elementStart('ul', array('class' => 'xoxo'));
  64. foreach ($this->feeds as $feed) {
  65. $this->feedItem($feed);
  66. }
  67. $this->out->elementEnd('ul');
  68. $this->out->elementEnd('div');
  69. }
  70. Event::handle('EndShowFeedLinkList', array($this->action, &$this->feeds));
  71. }
  72. }
  73. function feedItem($feed)
  74. {
  75. if (Event::handle('StartShowFeedLink', array($this->action, &$feed))) {
  76. $classname = null;
  77. switch ($feed->type) {
  78. case Feed::RSS1:
  79. case Feed::RSS2:
  80. $classname = 'rss';
  81. break;
  82. case Feed::ATOM:
  83. $classname = 'atom';
  84. break;
  85. case Feed::FOAF:
  86. $classname = 'foaf';
  87. break;
  88. case Feed::JSON:
  89. $classname = 'json';
  90. break;
  91. }
  92. $this->out->elementStart('li');
  93. $this->out->element('a', array('href' => $feed->url,
  94. 'class' => $classname,
  95. 'type' => $feed->mimeType(),
  96. 'title' => $feed->title),
  97. $feed->typeName());
  98. $this->out->elementEnd('li');
  99. Event::handle('EndShowFeedLink', array($this->action, $feed));
  100. }
  101. }
  102. }