usersitemap.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show list of user pages
  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. * sitemap for users
  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 UsersitemapAction extends SitemapAction
  42. {
  43. var $users = null;
  44. var $j = 0;
  45. function prepare(array $args = array())
  46. {
  47. parent::prepare($args);
  48. $y = $this->trimmed('year');
  49. $m = $this->trimmed('month');
  50. $d = $this->trimmed('day');
  51. $i = $this->trimmed('index');
  52. $y += 0;
  53. $m += 0;
  54. $d += 0;
  55. $i += 0;
  56. $this->users = $this->getUsers($y, $m, $d, $i);
  57. $this->j = 0;
  58. return true;
  59. }
  60. function nextUrl()
  61. {
  62. if ($this->j < count($this->users)) {
  63. $nickname = $this->users[$this->j];
  64. $this->j++;
  65. return array(common_profile_url($nickname), null, null, '1.0');
  66. } else {
  67. return null;
  68. }
  69. }
  70. function getUsers($y, $m, $d, $i)
  71. {
  72. $u = User::cacheGet("sitemap:user:$y:$m:$d:$i");
  73. if ($u === false) {
  74. $user = new User();
  75. $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
  76. // XXX: estimates 1d == 24h, which screws up days
  77. // with leap seconds (1d == 24h + 1s). Thankfully they're
  78. // few and far between.
  79. $theend = strtotime($begindt) + (24 * 60 * 60);
  80. $enddt = common_sql_date($theend);
  81. $user->selectAdd();
  82. $user->selectAdd('nickname');
  83. $user->whereAdd("created >= '$begindt'");
  84. $user->whereAdd("created < '$enddt'");
  85. $user->orderBy('created');
  86. $offset = ($i-1) * SitemapPlugin::USERS_PER_MAP;
  87. $limit = SitemapPlugin::USERS_PER_MAP;
  88. $user->limit($offset, $limit);
  89. $user->find();
  90. while ($user->fetch()) {
  91. $u[] = $user->nickname;
  92. }
  93. $c = Cache::instance();
  94. if (!empty($c)) {
  95. $c->set(Cache::key("sitemap:user:$y:$m:$d:$i"),
  96. $u,
  97. Cache::COMPRESSED,
  98. ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
  99. }
  100. }
  101. return $u;
  102. }
  103. }