3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
23 * Table Definition for notice
25 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
27 /* We keep the first three 20-notice pages, plus one for pagination check,
28 * in the memcached cache. */
30 define('NOTICE_CACHE_WINDOW', 61);
32 class Notice extends Memcached_DataObject
35 /* the code below is auto generated do not remove the above tag */
37 public $__table = 'notice'; // table name
38 public $id; // int(4) primary_key not_null
39 public $profile_id; // int(4) not_null
40 public $uri; // varchar(255) unique_key
41 public $content; // varchar(140)
42 public $rendered; // text()
43 public $url; // varchar(255)
44 public $created; // datetime() not_null
45 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
46 public $reply_to; // int(4)
47 public $is_local; // tinyint(1)
48 public $source; // varchar(32)
51 function staticGet($k,$v=NULL) {
52 return Memcached_DataObject::staticGet('Notice',$k,$v);
55 /* the code above is auto generated do not remove the tag below */
60 return Profile::staticGet('id', $this->profile_id);
65 $this->blowCaches(true);
66 $this->blowFavesCache(true);
67 $this->blowSubsCache(true);
69 $this->query('BEGIN');
70 //Null any notices that are replies to this notice
71 $this->query(sprintf("UPDATE notice set reply_to = null WHERE reply_to = %d", $this->id));
72 $related = array('Reply',
77 if (common_config('inboxes', 'enabled')) {
78 $related[] = 'Notice_inbox';
80 foreach ($related as $cls) {
82 $inst->notice_id = $this->id;
85 $result = parent::delete();
86 $this->query('COMMIT');
91 /* extract all #hastags */
92 $count = preg_match_all('/(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/', strtolower($this->content), $match);
97 /* Add them to the database */
98 foreach(array_unique($match[1]) as $hashtag) {
99 /* elide characters we don't want in the tag */
100 $this->saveTag($hashtag);
105 function saveTag($hashtag)
107 $hashtag = common_canonical_tag($hashtag);
109 $tag = new Notice_tag();
110 $tag->notice_id = $this->id;
111 $tag->tag = $hashtag;
112 $tag->created = $this->created;
113 $id = $tag->insert();
116 throw new ServerException(sprintf(_('DB error inserting hashtag: %s'),
117 $last_error->message));
122 static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
124 $profile = Profile::staticGet($profile_id);
126 $final = common_shorten_links($content);
128 if (mb_strlen($final) > 140) {
129 common_log(LOG_INFO, 'Rejecting notice that is too long.');
130 return _('Problem saving notice. Too long.');
134 common_log(LOG_ERR, 'Problem saving notice. Unknown user.');
135 return _('Problem saving notice. Unknown user.');
138 if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
139 common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
140 return _('Too many notices too fast; take a breather and post again in a few minutes.');
143 if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
144 common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
145 return _('Too many duplicate messages too quickly; take a breather and post again in a few minutes.');
148 $banned = common_config('profile', 'banned');
150 if ( in_array($profile_id, $banned) || in_array($profile->nickname, $banned)) {
151 common_log(LOG_WARNING, "Attempted post from banned user: $profile->nickname (user id = $profile_id).");
152 return _('You are banned from posting notices on this site.');
155 $notice = new Notice();
156 $notice->profile_id = $profile_id;
158 $blacklist = common_config('public', 'blacklist');
159 $autosource = common_config('public', 'autosource');
161 # Blacklisted are non-false, but not 1, either
163 if (($blacklist && in_array($profile_id, $blacklist)) ||
164 ($source && $autosource && in_array($source, $autosource))) {
165 $notice->is_local = -1;
167 $notice->is_local = $is_local;
170 $notice->query('BEGIN');
172 $notice->reply_to = $reply_to;
173 $notice->created = common_sql_now();
174 $notice->content = $final;
175 $notice->rendered = common_render_content($final, $notice);
176 $notice->source = $source;
179 if (Event::handle('StartNoticeSave', array(&$notice))) {
181 $id = $notice->insert();
184 common_log_db_error($notice, 'INSERT', __FILE__);
185 return _('Problem saving notice.');
188 # Update the URI after the notice is in the database
190 $orig = clone($notice);
191 $notice->uri = common_notice_uri($notice);
193 if (!$notice->update($orig)) {
194 common_log_db_error($notice, 'UPDATE', __FILE__);
195 return _('Problem saving notice.');
199 # XXX: do we need to change this for remote users?
201 $notice->saveReplies();
204 $notice->addToInboxes();
205 $notice->saveGroups();
207 $notice->query('COMMIT');
209 Event::handle('EndNoticeSave', array($notice));
212 # Clear the cache for subscribed users, so they'll update at next request
213 # XXX: someone clever could prepend instead of clearing the cache
215 $notice->blowCaches();
220 static function checkDupes($profile_id, $content) {
221 $profile = Profile::staticGet($profile_id);
225 $notice = $profile->getNotices(0, NOTICE_CACHE_WINDOW);
228 while ($notice->fetch()) {
229 if (time() - strtotime($notice->created) >= common_config('site', 'dupelimit')) {
231 } else if ($notice->content == $content) {
236 # If we get here, oldest item in cache window is not
237 # old enough for dupe limit; do direct check against DB
238 $notice = new Notice();
239 $notice->profile_id = $profile_id;
240 $notice->content = $content;
241 if (common_config('db','type') == 'pgsql')
242 $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit'));
244 $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit'));
246 $cnt = $notice->count();
250 static function checkEditThrottle($profile_id) {
251 $profile = Profile::staticGet($profile_id);
256 $notice = $profile->getNotices(common_config('throttle', 'count') - 1, 1);
257 if ($notice && $notice->fetch()) {
258 # If the Nth notice was posted less than timespan seconds ago
259 if (time() - strtotime($notice->created) <= common_config('throttle', 'timespan')) {
264 # Either not N notices in the stream, OR the Nth was not posted within timespan seconds
268 function blowCaches($blowLast=false)
270 $this->blowSubsCache($blowLast);
271 $this->blowNoticeCache($blowLast);
272 $this->blowRepliesCache($blowLast);
273 $this->blowPublicCache($blowLast);
274 $this->blowTagCache($blowLast);
275 $this->blowGroupCache($blowLast);
278 function blowGroupCache($blowLast=false)
280 $cache = common_memcache();
282 $group_inbox = new Group_inbox();
283 $group_inbox->notice_id = $this->id;
284 if ($group_inbox->find()) {
285 while ($group_inbox->fetch()) {
286 $cache->delete(common_cache_key('user_group:notice_ids:' . $group_inbox->group_id));
288 $cache->delete(common_cache_key('user_group:notice_ids:' . $group_inbox->group_id.';last'));
290 $member = new Group_member();
291 $member->group_id = $group_inbox->group_id;
292 if ($member->find()) {
293 while ($member->fetch()) {
294 $cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id));
296 $cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id . ';last'));
302 $group_inbox->free();
307 function blowTagCache($blowLast=false)
309 $cache = common_memcache();
311 $tag = new Notice_tag();
312 $tag->notice_id = $this->id;
314 while ($tag->fetch()) {
315 $tag->blowCache($blowLast);
323 function blowSubsCache($blowLast=false)
325 $cache = common_memcache();
329 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
330 $user->query('SELECT id ' .
332 "FROM $UT JOIN subscription ON $UT.id = subscription.subscriber " .
333 'WHERE subscription.subscribed = ' . $this->profile_id);
335 while ($user->fetch()) {
336 $cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id));
338 $cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last'));
346 function blowNoticeCache($blowLast=false)
348 if ($this->is_local) {
349 $cache = common_memcache();
350 if (!empty($cache)) {
351 $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id));
353 $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id.';last'));
359 function blowRepliesCache($blowLast=false)
361 $cache = common_memcache();
363 $reply = new Reply();
364 $reply->notice_id = $this->id;
365 if ($reply->find()) {
366 while ($reply->fetch()) {
367 $cache->delete(common_cache_key('reply:stream:'.$reply->profile_id));
369 $cache->delete(common_cache_key('reply:stream:'.$reply->profile_id.';last'));
378 function blowPublicCache($blowLast=false)
380 if ($this->is_local == 1) {
381 $cache = common_memcache();
383 $cache->delete(common_cache_key('public'));
385 $cache->delete(common_cache_key('public').';last');
391 function blowFavesCache($blowLast=false)
393 $cache = common_memcache();
396 $fave->notice_id = $this->id;
398 while ($fave->fetch()) {
399 $cache->delete(common_cache_key('fave:ids_by_user:'.$fave->user_id));
401 $cache->delete(common_cache_key('fave:ids_by_user:'.$fave->user_id.';last'));
410 # XXX: too many args; we need to move to named params or even a separate
411 # class for notice streams
413 static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0, $order=null, $since=null) {
415 if (common_config('memcached', 'enabled')) {
417 # Skip the cache if this is a since, since_id or max_id qry
418 if ($since_id > 0 || $max_id > 0 || $since) {
419 return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since);
421 return Notice::getCachedStream($qry, $cachekey, $offset, $limit, $order);
425 return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since);
428 static function getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since) {
433 if (preg_match('/\bWHERE\b/i', $qry)) {
447 $qry .= ' notice.id > ' . $since_id;
459 $qry .= ' notice.id <= ' . $max_id;
471 $qry .= ' notice.created > \'' . date('Y-m-d H:i:s', $since) . '\'';
474 # Allow ORDER override
479 $qry .= ' ORDER BY notice.created DESC, notice.id DESC ';
482 if (common_config('db','type') == 'pgsql') {
483 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
485 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
488 $notice = new Notice();
490 $notice->query($qry);
495 # XXX: this is pretty long and should probably be broken up into
496 # some helper functions
498 static function getCachedStream($qry, $cachekey, $offset, $limit, $order) {
500 # If outside our cache window, just go to the DB
502 if ($offset + $limit > NOTICE_CACHE_WINDOW) {
503 return Notice::getStreamDirect($qry, $offset, $limit, null, null, $order, null);
506 # Get the cache; if we can't, just go to the DB
508 $cache = common_memcache();
511 return Notice::getStreamDirect($qry, $offset, $limit, null, null, $order, null);
514 # Get the notices out of the cache
516 $notices = $cache->get(common_cache_key($cachekey));
518 # On a cache hit, return a DB-object-like wrapper
520 if ($notices !== false) {
521 $wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit));
525 # If the cache was invalidated because of new data being
526 # added, we can try and just get the new stuff. We keep an additional
527 # copy of the data at the key + ';last'
529 # No cache hit. Try to get the *last* cached version
531 $last_notices = $cache->get(common_cache_key($cachekey) . ';last');
535 # Reverse-chron order, so last ID is last.
537 $last_id = $last_notices[0]->id;
539 # XXX: this assumes monotonically increasing IDs; a fair
542 $new_notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW,
543 $last_id, null, $order, null);
546 $new_notices = array();
547 while ($new_notice->fetch()) {
548 $new_notices[] = clone($new_notice);
551 $notices = array_slice(array_merge($new_notices, $last_notices),
552 0, NOTICE_CACHE_WINDOW);
554 # Store the array in the cache for next time
556 $result = $cache->set(common_cache_key($cachekey), $notices);
557 $result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
559 # return a wrapper of the array for use now
561 return new ArrayWrapper(array_slice($notices, $offset, $limit));
565 # Otherwise, get the full cache window out of the DB
567 $notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, null, null, $order, null);
569 # If there are no hits, just return the value
575 # Pack results into an array
579 while ($notice->fetch()) {
580 $notices[] = clone($notice);
585 # Store the array in the cache for next time
587 $result = $cache->set(common_cache_key($cachekey), $notices);
588 $result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
590 # return a wrapper of the array for use now
592 $wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit));
597 function getStreamByIds($ids)
599 $cache = common_memcache();
601 if (!empty($cache)) {
603 foreach ($ids as $id) {
604 $notices[] = Notice::staticGet('id', $id);
606 return new ArrayWrapper($notices);
608 $notice = new Notice();
609 $notice->whereAdd('id in (' . implode(', ', $ids) . ')');
610 $notice->orderBy('id DESC');
617 function publicStream($offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
619 $ids = Notice::stream(array('Notice', '_publicStreamDirect'),
622 $offset, $limit, $since_id, $max_id, $since);
624 return Notice::getStreamByIds($ids);
627 function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
629 $notice = new Notice();
631 $notice->selectAdd(); // clears it
632 $notice->selectAdd('id');
634 $notice->orderBy('id DESC');
636 if (!is_null($offset)) {
637 $notice->limit($offset, $limit);
640 if (common_config('public', 'localonly')) {
641 $notice->whereAdd('is_local = 1');
644 $notice->whereAdd('is_local != -1');
647 if ($since_id != 0) {
648 $notice->whereAdd('id > ' . $since_id);
652 $notice->whereAdd('id <= ' . $max_id);
655 if (!is_null($since)) {
656 $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
661 if ($notice->find()) {
662 while ($notice->fetch()) {
663 $ids[] = $notice->id;
673 function addToInboxes()
675 $enabled = common_config('inboxes', 'enabled');
677 if ($enabled === true || $enabled === 'transitional') {
678 $inbox = new Notice_inbox();
679 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
680 $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
681 "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
682 "FROM $UT JOIN subscription ON $UT.id = subscription.subscriber " .
683 'WHERE subscription.subscribed = ' . $this->profile_id . ' ' .
684 'AND NOT EXISTS (SELECT user_id, notice_id ' .
685 'FROM notice_inbox ' .
686 "WHERE user_id = $UT.id " .
687 'AND notice_id = ' . $this->id . ' )';
688 if ($enabled === 'transitional') {
689 $qry .= " AND $UT.inboxed = 1";
696 function saveGroups()
698 $enabled = common_config('inboxes', 'enabled');
699 if ($enabled !== true && $enabled !== 'transitional') {
703 /* extract all !group */
704 $count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/',
705 strtolower($this->content),
711 $profile = $this->getProfile();
713 /* Add them to the database */
715 foreach (array_unique($match[1]) as $nickname) {
716 /* XXX: remote groups. */
717 $group = User_group::staticGet('nickname', $nickname);
723 // we automatically add a tag for every group name, too
725 $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname),
726 'notice_id' => $this->id));
729 $this->saveTag($nickname);
732 if ($profile->isMember($group)) {
734 $gi = new Group_inbox();
736 $gi->group_id = $group->id;
737 $gi->notice_id = $this->id;
738 $gi->created = common_sql_now();
740 $result = $gi->insert();
743 common_log_db_error($gi, 'INSERT', __FILE__);
746 // FIXME: do this in an offline daemon
748 $this->addToGroupInboxes($group);
753 function addToGroupInboxes($group)
755 $inbox = new Notice_inbox();
756 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
757 $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
758 "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
759 "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
760 'WHERE group_member.group_id = ' . $group->id . ' ' .
761 'AND NOT EXISTS (SELECT user_id, notice_id ' .
762 'FROM notice_inbox ' .
763 "WHERE user_id = $UT.id " .
764 'AND notice_id = ' . $this->id . ' )';
765 if ($enabled === 'transitional') {
766 $qry .= " AND $UT.inboxed = 1";
768 $result = $inbox->query($qry);
771 function saveReplies()
773 // Alternative reply format
775 if (preg_match('/^T ([A-Z0-9]{1,64}) /', $this->content, $match)) {
778 // extract all @messages
779 $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $this->content, $match);
783 if ($cnt || $tname) {
784 // XXX: is there another way to make an array copy?
785 $names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]);
788 $sender = Profile::staticGet($this->profile_id);
792 // store replied only for first @ (what user/notice what the reply directed,
793 // we assume first @ is it)
795 for ($i=0; $i<count($names); $i++) {
796 $nickname = $names[$i];
797 $recipient = common_relative_profile($sender, $nickname, $this->created);
801 if ($i == 0 && ($recipient->id != $sender->id) && !$this->reply_to) { // Don't save reply to self
802 $reply_for = $recipient;
803 $recipient_notice = $reply_for->getCurrentNotice();
804 if ($recipient_notice) {
805 $orig = clone($this);
806 $this->reply_to = $recipient_notice->id;
807 $this->update($orig);
810 // Don't save replies from blocked profile to local user
811 $recipient_user = User::staticGet('id', $recipient->id);
812 if ($recipient_user && $recipient_user->hasBlocked($sender)) {
815 $reply = new Reply();
816 $reply->notice_id = $this->id;
817 $reply->profile_id = $recipient->id;
818 $id = $reply->insert();
820 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
821 common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message);
822 common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message));
825 $replied[$recipient->id] = 1;
829 // Hash format replies, too
830 $cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $this->content, $match);
832 foreach ($match[1] as $tag) {
833 $tagged = Profile_tag::getTagged($sender->id, $tag);
834 foreach ($tagged as $t) {
835 if (!$replied[$t->id]) {
836 // Don't save replies from blocked profile to local user
837 $t_user = User::staticGet('id', $t->id);
838 if ($t_user && $t_user->hasBlocked($sender)) {
841 $reply = new Reply();
842 $reply->notice_id = $this->id;
843 $reply->profile_id = $t->id;
844 $id = $reply->insert();
846 common_log_db_error($reply, 'INSERT', __FILE__);
849 $replied[$recipient->id] = 1;
856 foreach (array_keys($replied) as $recipient) {
857 $user = User::staticGet('id', $recipient);
859 mail_notify_attn($user, $this);
864 function asAtomEntry($namespace=false, $source=false)
866 $profile = $this->getProfile();
868 $xs = new XMLStringer(true);
871 $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
872 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0');
877 $xs->elementStart('entry', $attrs);
880 $xs->elementStart('source');
881 $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
882 $xs->element('link', array('href' => $profile->profileurl));
883 $user = User::staticGet('id', $profile->id);
885 $atom_feed = common_local_url('api',
886 array('apiaction' => 'statuses',
887 'method' => 'user_timeline',
888 'argument' => $profile->nickname.'.atom'));
889 $xs->element('link', array('rel' => 'self',
890 'type' => 'application/atom+xml',
891 'href' => $profile->profileurl));
892 $xs->element('link', array('rel' => 'license',
893 'href' => common_config('license', 'url')));
896 $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
899 $xs->elementStart('author');
900 $xs->element('name', null, $profile->nickname);
901 $xs->element('uri', null, $profile->profileurl);
902 $xs->elementEnd('author');
905 $xs->elementEnd('source');
908 $xs->element('title', null, $this->content);
909 $xs->element('summary', null, $this->content);
911 $xs->element('link', array('rel' => 'alternate',
912 'href' => $this->bestUrl()));
914 $xs->element('id', null, $this->uri);
916 $xs->element('published', null, common_date_w3dtf($this->created));
917 $xs->element('updated', null, common_date_w3dtf($this->modified));
919 if ($this->reply_to) {
920 $reply_notice = Notice::staticGet('id', $this->reply_to);
921 if (!empty($reply_notice)) {
922 $xs->element('link', array('rel' => 'related',
923 'href' => $reply_notice->bestUrl()));
924 $xs->element('thr:in-reply-to',
925 array('ref' => $reply_notice->uri,
926 'href' => $reply_notice->bestUrl()));
930 $xs->element('content', array('type' => 'html'), $this->rendered);
932 $tag = new Notice_tag();
933 $tag->notice_id = $this->id;
935 while ($tag->fetch()) {
936 $xs->element('category', array('term' => $tag->tag));
941 $xs->elementEnd('entry');
943 return $xs->getString();
948 if (!empty($this->url)) {
950 } else if (!empty($this->uri) && preg_match('/^https?:/', $this->uri)) {
953 return common_local_url('shownotice',
954 array('notice' => $this->id));
958 function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
960 $cache = common_memcache();
963 $since_id != 0 || $max_id != 0 || (!is_null($since) && $since > 0) ||
964 ($offset + $limit) > NOTICE_CACHE_WINDOW) {
965 return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id,
969 $idkey = common_cache_key($cachekey);
971 $idstr = $cache->get($idkey);
973 if (!empty($idstr)) {
974 // Cache hit! Woohoo!
975 $window = explode(',', $idstr);
976 $ids = array_slice($window, $offset, $limit);
980 $laststr = $cache->get($idkey.';last');
982 if (!empty($laststr)) {
983 $window = explode(',', $laststr);
984 $last_id = $window[0];
985 $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
986 $last_id, 0, null)));
988 $new_window = array_merge($new_ids, $window);
990 $new_windowstr = implode(',', $new_window);
992 $result = $cache->set($idkey, $new_windowstr);
993 $result = $cache->set($idkey . ';last', $new_windowstr);
995 $ids = array_slice($new_window, $offset, $limit);
1000 $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
1003 $windowstr = implode(',', $window);
1005 $result = $cache->set($idkey, $windowstr);
1006 $result = $cache->set($idkey . ';last', $windowstr);
1008 $ids = array_slice($window, $offset, $limit);