noticesitemap.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. * Show list of user pages
  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. * sitemap for users
  28. *
  29. * @category Sitemap
  30. * @package GNUsocial
  31. * @author Evan Prodromou <evan@status.net>
  32. * @copyright 2010 StatusNet, Inc.
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. */
  35. class NoticesitemapAction extends SitemapAction
  36. {
  37. public $notices = null;
  38. public $j = 0;
  39. public function prepare(array $args = [])
  40. {
  41. parent::prepare($args);
  42. $y = $this->trimmed('year');
  43. $m = $this->trimmed('month');
  44. $d = $this->trimmed('day');
  45. $i = $this->trimmed('index');
  46. $y += 0;
  47. $m += 0;
  48. $d += 0;
  49. $i += 0;
  50. $this->notices = $this->getNotices($y, $m, $d, $i);
  51. $this->j = 0;
  52. return true;
  53. }
  54. public function nextUrl()
  55. {
  56. if ($this->j < count($this->notices)) {
  57. $n = $this->notices[$this->j];
  58. $this->j++;
  59. return array(common_local_url('shownotice', array('notice' => $n[0])),
  60. common_date_w3dtf($n[1]),
  61. 'never',
  62. null);
  63. } else {
  64. return null;
  65. }
  66. }
  67. public function getNotices($y, $m, $d, $i)
  68. {
  69. $n = Notice::cacheGet("sitemap:notice:{$y}:{$m}:{$d}:{$i}");
  70. if ($n === false) {
  71. $notice = new Notice();
  72. $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
  73. // XXX: estimates 1d == 24h, which screws up days
  74. // with leap seconds (1d == 24h + 1s). Thankfully they're
  75. // few and far between.
  76. $theend = strtotime($begindt) + (24 * 60 * 60);
  77. $enddt = common_sql_date($theend);
  78. $notice->selectAdd();
  79. $notice->selectAdd('id, created');
  80. $notice->whereAdd("created >= '$begindt'");
  81. $notice->whereAdd("created < '$enddt'");
  82. $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
  83. $notice->orderBy('created, id');
  84. $offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
  85. $limit = SitemapPlugin::NOTICES_PER_MAP;
  86. $notice->limit($offset, $limit);
  87. $notice->find();
  88. $n = array();
  89. while ($notice->fetch()) {
  90. $n[] = array($notice->id, $notice->created);
  91. }
  92. $c = Cache::instance();
  93. if (!empty($c)) {
  94. $c->set(
  95. Cache::key("sitemap:notice:$y:$m:$d:$i"),
  96. $n,
  97. Cache::COMPRESSED,
  98. ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60))
  99. );
  100. }
  101. }
  102. return $n;
  103. }
  104. }