feed.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Data structure for info about syndication feeds (RSS 1.0, RSS 2.0, Atom)
  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 Feed
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Data structure for feeds
  34. *
  35. * This structure is a helpful container for shipping around information about syndication feeds.
  36. *
  37. * @category Feed
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @author Sarven Capadisli <csarven@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  42. * @link http://status.net/
  43. */
  44. class Feed
  45. {
  46. const RSS1 = 1;
  47. const RSS2 = 2;
  48. const ATOM = 3;
  49. const FOAF = 4;
  50. const JSON = 5; // Activity Streams
  51. var $type = null;
  52. var $url = null;
  53. var $title = null;
  54. function __construct($type, $url, $title)
  55. {
  56. $this->type = $type;
  57. $this->url = $url;
  58. $this->title = $title;
  59. }
  60. function getUrl()
  61. {
  62. return $this->url;
  63. }
  64. function mimeType()
  65. {
  66. switch ($this->type) {
  67. case Feed::RSS1:
  68. return 'application/rdf+xml';
  69. case Feed::RSS2:
  70. return 'application/rss+xml';
  71. case Feed::ATOM:
  72. return 'application/atom+xml';
  73. case Feed::FOAF:
  74. return 'application/rdf+xml';
  75. case Feed::JSON:
  76. return 'application/stream+json';
  77. default:
  78. return null;
  79. }
  80. }
  81. function typeName()
  82. {
  83. switch ($this->type) {
  84. case Feed::RSS1:
  85. // TRANS: Feed type name.
  86. return _('RSS 1.0');
  87. case Feed::RSS2:
  88. // TRANS: Feed type name.
  89. return _('RSS 2.0');
  90. case Feed::ATOM:
  91. // TRANS: Feed type name.
  92. return _('Atom');
  93. case Feed::FOAF:
  94. // TRANS: Feed type name. FOAF stands for Friend of a Friend.
  95. return _('FOAF');
  96. case Feed::JSON:
  97. // TRANS: Feed type name. See http://activitystrea.ms/
  98. return _('Activity Streams');
  99. default:
  100. return null;
  101. }
  102. }
  103. function rel()
  104. {
  105. switch ($this->type) {
  106. case Feed::RSS1:
  107. case Feed::RSS2:
  108. case Feed::ATOM:
  109. case Feed::JSON:
  110. return 'alternate';
  111. case Feed::FOAF:
  112. return 'meta';
  113. default:
  114. return null;
  115. }
  116. }
  117. }