feedlist.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. /**
  34. * Widget for showing a list of feeds
  35. *
  36. * Typically used for Action::showExportList()
  37. *
  38. * @category Widget
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @author Sarven Capadisli <csarven@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. *
  45. * @see Action::showExportList()
  46. */
  47. class FeedList extends Widget
  48. {
  49. var $action = null;
  50. function __construct($action=null)
  51. {
  52. parent::__construct($action);
  53. $this->action = $action;
  54. }
  55. function show($feeds)
  56. {
  57. if (Event::handle('StartShowFeedLinkList', array($this->action, &$feeds))) {
  58. if (!empty($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 ($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, &$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. }