feed.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 mimeType()
  61. {
  62. switch ($this->type) {
  63. case Feed::RSS1:
  64. return 'application/rdf+xml';
  65. case Feed::RSS2:
  66. return 'application/rss+xml';
  67. case Feed::ATOM:
  68. return 'application/atom+xml';
  69. case Feed::FOAF:
  70. return 'application/rdf+xml';
  71. case Feed::JSON:
  72. return 'application/stream+json';
  73. default:
  74. return null;
  75. }
  76. }
  77. function typeName()
  78. {
  79. switch ($this->type) {
  80. case Feed::RSS1:
  81. // TRANS: Feed type name.
  82. return _('RSS 1.0');
  83. case Feed::RSS2:
  84. // TRANS: Feed type name.
  85. return _('RSS 2.0');
  86. case Feed::ATOM:
  87. // TRANS: Feed type name.
  88. return _('Atom');
  89. case Feed::FOAF:
  90. // TRANS: Feed type name. FOAF stands for Friend of a Friend.
  91. return _('FOAF');
  92. case Feed::JSON:
  93. // TRANS: Feed type name. See http://activitystrea.ms/
  94. return _('Activity Streams');
  95. default:
  96. return null;
  97. }
  98. }
  99. function rel()
  100. {
  101. switch ($this->type) {
  102. case Feed::RSS1:
  103. case Feed::RSS2:
  104. case Feed::ATOM:
  105. case Feed::JSON:
  106. return 'alternate';
  107. case Feed::FOAF:
  108. return 'meta';
  109. default:
  110. return null;
  111. }
  112. }
  113. }