sitemap.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Superclass for sitemap-generating actions
  18. *
  19. * @category Sitemap
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2010 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * superclass for sitemap actions
  28. *
  29. * @category Sitemap
  30. * @package GNUsocial
  31. * @author Evan Prodromou <evan@status.net>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class SitemapAction extends Action
  35. {
  36. /**
  37. * handle the action
  38. *
  39. * @param array $args unused.
  40. *
  41. * @return void
  42. */
  43. public function handle()
  44. {
  45. parent::handle();
  46. header('Content-Type: text/xml; charset=UTF-8');
  47. $this->startXML();
  48. $this->elementStart('urlset', array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'));
  49. while (!is_null($next = $this->nextUrl())) {
  50. $this->showUrl(...$next);
  51. }
  52. $this->elementEnd('urlset');
  53. $this->endXML();
  54. }
  55. public function lastModified()
  56. {
  57. $y = $this->trimmed('year');
  58. $m = $this->trimmed('month');
  59. $d = $this->trimmed('day');
  60. $y += 0;
  61. $m += 0;
  62. $d += 0;
  63. $begdate = strtotime("$y-$m-$d 00:00:00");
  64. $enddate = $begdate + (24 * 60 * 60);
  65. if ($enddate < time()) {
  66. return $enddate;
  67. } else {
  68. return null;
  69. }
  70. }
  71. public function showUrl(
  72. $url,
  73. $lastMod = null,
  74. $changeFreq = null,
  75. $priority = null
  76. ) {
  77. $this->elementStart('url');
  78. $this->element('loc', null, $url);
  79. if (!is_null($lastMod)) {
  80. $this->element('lastmod', null, $lastMod);
  81. }
  82. if (!is_null($changeFreq)) {
  83. $this->element('changefreq', null, $changeFreq);
  84. }
  85. if (!is_null($priority)) {
  86. $this->element('priority', null, $priority);
  87. }
  88. $this->elementEnd('url');
  89. }
  90. public function nextUrl()
  91. {
  92. return null;
  93. }
  94. public function isReadOnly()
  95. {
  96. return true;
  97. }
  98. }