]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Properly structure X-XSS-Protection header
[quix0rs-gnu-social.git] / classes / Notice.php
index ba66dd8054440ffd1297f0fd3b2d37e93d5dc5c9..650dca051b359727ec00cc64c8f44b07cd280a3e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2011 StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -84,9 +84,14 @@ class Notice extends Memcached_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
+       function multiGet($kc, $kvs, $skipNulls=true)
+       {
+               return Memcached_DataObject::multiGet('Notice', $kc, $kvs, $skipNulls);
+       }
+       
     /* Notice types */
     const LOCAL_PUBLIC    =  1;
-    const REMOTE_OMB      =  0;
+    const REMOTE          =  0;
     const LOCAL_NONPUBLIC = -1;
     const GATEWAY         = -2;
 
@@ -229,11 +234,11 @@ class Notice extends Memcached_DataObject
      *              string 'created' timestamp of notice; defaults to now
      *              int 'is_local' source/gateway ID, one of:
      *                  Notice::LOCAL_PUBLIC    - Local, ok to appear in public timeline
-     *                  Notice::REMOTE_OMB      - Sent from a remote OMB service;
+     *                  Notice::REMOTE          - Sent from a remote service;
      *                                            hide from public timeline but show in
      *                                            local "and friends" timelines
      *                  Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
-     *                  Notice::GATEWAY         - From another non-OMB service;
+     *                  Notice::GATEWAY         - From another non-OStatus service;
      *                                            will not appear in public views
      *              float 'lat' decimal latitude for geolocation
      *              float 'lon' decimal longitude for geolocation
@@ -448,7 +453,7 @@ class Notice extends Memcached_DataObject
             if (!empty($reply)) {
                 $notice->scope = $reply->scope;
             } else {
-                $notice->scope = common_config('notice', 'defaultscope');
+                $notice->scope = self::defaultScope();
             }
         } else {
             $notice->scope = $scope;
@@ -561,10 +566,10 @@ class Notice extends Memcached_DataObject
 
     function blowOnInsert($conversation = false)
     {
-        self::blow('profile:notice_ids:%d', $this->profile_id);
+        $this->blowStream('profile:notice_ids:%d', $this->profile_id);
 
         if ($this->isPublic()) {
-            self::blow('public');
+            $this->blowStream('public');
         }
 
         // XXX: Before we were blowing the casche only if the notice id
@@ -574,7 +579,7 @@ class Notice extends Memcached_DataObject
         self::blow('conversation::notice_count:%d', $this->conversation);
 
         if (!empty($this->repeat_of)) {
-            self::blow('notice:repeats:%d', $this->repeat_of);
+            $this->blowStream('notice:repeats:%d', $this->repeat_of);
         }
 
         $original = Notice::staticGet('id', $this->repeat_of);
@@ -582,11 +587,12 @@ class Notice extends Memcached_DataObject
         if (!empty($original)) {
             $originalUser = User::staticGet('id', $original->profile_id);
             if (!empty($originalUser)) {
-                self::blow('user:repeats_of_me:%d', $originalUser->id);
+                $this->blowStream('user:repeats_of_me:%d', $originalUser->id);
             }
         }
 
         $profile = Profile::staticGet($this->profile_id);
+
         if (!empty($profile)) {
             $profile->blowNoticeCount();
         }
@@ -624,6 +630,42 @@ class Notice extends Memcached_DataObject
         }
     }
 
+    function blowStream()
+    {
+        $c = self::memcache();
+
+        if (empty($c)) {
+            return false;
+        }
+
+        $args = func_get_args();
+
+        $format = array_shift($args);
+
+        $keyPart = vsprintf($format, $args);
+
+        $cacheKey = Cache::key($keyPart);
+        
+        $c->delete($cacheKey);
+
+        // delete the "last" stream, too, if this notice is
+        // older than the top of that stream
+
+        $lastKey = $cacheKey.';last';
+
+        $lastStr = $c->get($lastKey);
+
+        if ($lastStr !== false) {
+            $window     = explode(',', $lastStr);
+            $lastID     = $window[0];
+            $lastNotice = Notice::staticGet('id', $lastID);
+            if (empty($lastNotice) // just weird
+                || strtotime($lastNotice->created) >= strtotime($this->created)) {
+                $c->delete($lastKey);
+            }
+        }
+    }
+
     /** save all urls in the notice to the db
      *
      * follow redirects and save all available file information
@@ -1819,7 +1861,11 @@ class Notice extends Memcached_DataObject
         } else {
             $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
             if ($idstr !== false) {
-                $ids = explode(',', $idstr);
+               if (empty($idstr)) {
+                       $ids = array();
+               } else {
+                       $ids = explode(',', $idstr);
+               }
             } else {
                 $ids = $this->_repeatStreamDirect(100);
                 $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
@@ -1848,18 +1894,7 @@ class Notice extends Memcached_DataObject
             $notice->limit(0, $limit);
         }
 
-        $ids = array();
-
-        if ($notice->find()) {
-            while ($notice->fetch()) {
-                $ids[] = $notice->id;
-            }
-        }
-
-        $notice->free();
-        $notice = NULL;
-
-        return $ids;
+        return $notice->fetchAll('id');
     }
 
     function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
@@ -2432,5 +2467,18 @@ class Notice extends Memcached_DataObject
         $skip = array('_original', '_profile');
         return array_diff($vars, $skip);
     }
+    
+    static function defaultScope()
+    {
+       $scope = common_config('notice', 'defaultscope');
+       if (is_null($scope)) {
+               if (common_config('site', 'private')) {
+                       $scope = 1;
+               } else {
+                       $scope = 0;
+               }
+       }
+       return $scope;
+    }
 
 }