123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class NoticesitemapAction extends SitemapAction
- {
- var $notices = null;
- var $j = 0;
- function prepare($args)
- {
- parent::prepare($args);
- $y = $this->trimmed('year');
- $m = $this->trimmed('month');
- $d = $this->trimmed('day');
- $i = $this->trimmed('index');
- $y += 0;
- $m += 0;
- $d += 0;
- $i += 0;
- $this->notices = $this->getNotices($y, $m, $d, $i);
- $this->j = 0;
- return true;
- }
- function nextUrl()
- {
- if ($this->j < count($this->notices)) {
- $n = $this->notices[$this->j];
- $this->j++;
- return array(common_local_url('shownotice', array('notice' => $n[0])),
- common_date_w3dtf($n[1]),
- 'never',
- null);
- } else {
- return null;
- }
- }
- function getNotices($y, $m, $d, $i)
- {
- $n = Notice::cacheGet("sitemap:notice:$y:$m:$d:$i");
- if ($n === false) {
- $notice = new Notice();
- $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
-
-
-
- $theend = strtotime($begindt) + (24 * 60 * 60);
- $enddt = common_sql_date($theend);
- $notice->selectAdd();
- $notice->selectAdd('id, created');
- $notice->whereAdd("created >= '$begindt'");
- $notice->whereAdd("created < '$enddt'");
- $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
- $notice->orderBy('created');
- $offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
- $limit = SitemapPlugin::NOTICES_PER_MAP;
- $notice->limit($offset, $limit);
- $notice->find();
- $n = array();
- while ($notice->fetch()) {
- $n[] = array($notice->id, $notice->created);
- }
- $c = Cache::instance();
- if (!empty($c)) {
- $c->set(Cache::key("sitemap:notice:$y:$m:$d:$i"),
- $n,
- Cache::COMPRESSED,
- ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
- }
- }
- return $n;
- }
- }
|