sitemapindex.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Generate sitemap index
  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 Sitemap
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2010 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')) {
  30. exit(1);
  31. }
  32. /**
  33. * Show the sitemap index
  34. *
  35. * @category Sitemap
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class SitemapindexAction extends Action
  42. {
  43. /**
  44. * handle the action
  45. *
  46. * @param array $args unused.
  47. *
  48. * @return void
  49. */
  50. function handle()
  51. {
  52. header('Content-Type: text/xml; charset=UTF-8');
  53. $this->startXML();
  54. $this->elementStart('sitemapindex', array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'));
  55. $this->showNoticeSitemaps();
  56. $this->showUserSitemaps();
  57. $this->elementEnd('sitemapindex');
  58. $this->endXML();
  59. }
  60. function showUserSitemaps()
  61. {
  62. $userCounts = Sitemap_user_count::getAll();
  63. foreach ($userCounts as $dt => $cnt) {
  64. $cnt = $cnt+0;
  65. if ($cnt == 0) {
  66. continue;
  67. }
  68. $n = (int)$cnt / (int)SitemapPlugin::USERS_PER_MAP;
  69. if (($cnt % SitemapPlugin::USERS_PER_MAP) != 0) {
  70. $n++;
  71. }
  72. for ($i = 1; $i <= $n; $i++) {
  73. $this->showSitemap('user', $dt, $i);
  74. }
  75. }
  76. }
  77. function showNoticeSitemaps()
  78. {
  79. $noticeCounts = Sitemap_notice_count::getAll();
  80. foreach ($noticeCounts as $dt => $cnt) {
  81. if ($cnt == 0) {
  82. continue;
  83. }
  84. $n = $cnt / SitemapPlugin::NOTICES_PER_MAP;
  85. if ($cnt % SitemapPlugin::NOTICES_PER_MAP) {
  86. $n++;
  87. }
  88. for ($i = 1; $i <= $n; $i++) {
  89. $this->showSitemap('notice', $dt, $i);
  90. }
  91. }
  92. }
  93. function showSitemap($prefix, $dt, $i)
  94. {
  95. list($y, $m, $d) = explode('-', $dt);
  96. $this->elementStart('sitemap');
  97. $this->element('loc', null, common_local_url($prefix.'sitemap',
  98. array('year' => $y,
  99. 'month' => $m,
  100. 'day' => $d,
  101. 'index' => $i)));
  102. $begdate = strtotime("$y-$m-$d 00:00:00");
  103. $enddate = $begdate + (24 * 60 * 60);
  104. if ($enddate < time()) {
  105. $this->element('lastmod', null, date(DATE_W3C, $enddate));
  106. }
  107. $this->elementEnd('sitemap');
  108. }
  109. }