noticesitemap.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 NoticesitemapAction extends SitemapAction
  42. {
  43. var $notices = 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->notices = $this->getNotices($y, $m, $d, $i);
  57. $this->j = 0;
  58. return true;
  59. }
  60. function nextUrl()
  61. {
  62. if ($this->j < count($this->notices)) {
  63. $n = $this->notices[$this->j];
  64. $this->j++;
  65. return array(common_local_url('shownotice', array('notice' => $n[0])),
  66. common_date_w3dtf($n[1]),
  67. 'never',
  68. null);
  69. } else {
  70. return null;
  71. }
  72. }
  73. function getNotices($y, $m, $d, $i)
  74. {
  75. $n = Notice::cacheGet("sitemap:notice:$y:$m:$d:$i");
  76. if ($n === false) {
  77. $notice = new Notice();
  78. $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
  79. // XXX: estimates 1d == 24h, which screws up days
  80. // with leap seconds (1d == 24h + 1s). Thankfully they're
  81. // few and far between.
  82. $theend = strtotime($begindt) + (24 * 60 * 60);
  83. $enddt = common_sql_date($theend);
  84. $notice->selectAdd();
  85. $notice->selectAdd('id, created');
  86. $notice->whereAdd("created >= '$begindt'");
  87. $notice->whereAdd("created < '$enddt'");
  88. $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
  89. $notice->orderBy('created');
  90. $offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
  91. $limit = SitemapPlugin::NOTICES_PER_MAP;
  92. $notice->limit($offset, $limit);
  93. $notice->find();
  94. $n = array();
  95. while ($notice->fetch()) {
  96. $n[] = array($notice->id, $notice->created);
  97. }
  98. $c = Cache::instance();
  99. if (!empty($c)) {
  100. $c->set(Cache::key("sitemap:notice:$y:$m:$d:$i"),
  101. $n,
  102. Cache::COMPRESSED,
  103. ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
  104. }
  105. }
  106. return $n;
  107. }
  108. }