usersitemap.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 UsersitemapAction extends SitemapAction
  36. {
  37. public $users = 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->users = $this->getUsers($y, $m, $d, $i);
  51. $this->j = 0;
  52. return true;
  53. }
  54. public function nextUrl()
  55. {
  56. if ($this->j < count($this->users)) {
  57. $nickname = $this->users[$this->j];
  58. $this->j++;
  59. return array(common_profile_url($nickname), null, null, '1.0');
  60. } else {
  61. return null;
  62. }
  63. }
  64. public function getUsers($y, $m, $d, $i)
  65. {
  66. $u = User::cacheGet("sitemap:user:$y:$m:$d:$i");
  67. if ($u === false) {
  68. $user = new User();
  69. $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
  70. // XXX: estimates 1d == 24h, which screws up days
  71. // with leap seconds (1d == 24h + 1s). Thankfully they're
  72. // few and far between.
  73. $theend = strtotime($begindt) + (24 * 60 * 60);
  74. $enddt = common_sql_date($theend);
  75. $user->selectAdd();
  76. $user->selectAdd('nickname');
  77. $user->whereAdd("created >= '$begindt'");
  78. $user->whereAdd("created < '$enddt'");
  79. $user->orderBy('created, id');
  80. $offset = ($i-1) * SitemapPlugin::USERS_PER_MAP;
  81. $limit = SitemapPlugin::USERS_PER_MAP;
  82. $user->limit($offset, $limit);
  83. $user->find();
  84. while ($user->fetch()) {
  85. $u[] = $user->nickname;
  86. }
  87. $c = Cache::instance();
  88. if (!empty($c)) {
  89. $c->set(
  90. Cache::key("sitemap:user:{$y}:{$m}:{$d}:{$i}"),
  91. $u,
  92. Cache::COMPRESSED,
  93. ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60))
  94. );
  95. }
  96. }
  97. return $u;
  98. }
  99. }