]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
Remove sequenceKey() since we now use Managed_DataObject
[quix0rs-gnu-social.git] / classes / File.php
index ef9dbf14aba1226c744df6f55472350852bef1d7..f716a9d64cfa6eadcb18e81f3a39b9b03e8d23bd 100644 (file)
@@ -29,7 +29,7 @@ require_once INSTALLDIR.'/classes/File_to_post.php';
 /**
  * Table Definition for file
  */
-class File extends Memcached_DataObject
+class File extends Managed_DataObject
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -51,19 +51,30 @@ class File extends Memcached_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    function isProtected($url) {
-        return 'http://www.facebook.com/login.php' === $url;
+    public static function schemaDef()
+    {
+        return array(
+            'fields' => array(
+                'id' => array('type' => 'serial', 'not null' => true),
+                'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'destination URL after following redirections'),
+                'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
+                'size' => array('type' => 'int', 'description' => 'size of resource when available'),
+                'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of resource when available'),
+                'date' => array('type' => 'int', 'description' => 'date of resource according to http query'),
+                'protected' => array('type' => 'int', 'description' => 'true when URL is private (needs login)'),
+                'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'if a local file, name of the file'),
+
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('id'),
+            'unique keys' => array(
+                'file_url_key' => array('url'),
+            ),
+        );
     }
 
-    function getAttachments($post_id) {
-        $query = "select file.* from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $this->escape($post_id);
-        $this->query($query);
-        $att = array();
-        while ($this->fetch()) {
-            $att[] = clone($this);
-        }
-        $this->free();
-        return $att;
+    function isProtected($url) {
+        return 'http://www.facebook.com/login.php' === $url;
     }
 
     /**
@@ -412,4 +423,58 @@ class File extends Memcached_DataObject
     {
         return File_thumbnail::staticGet('file_id', $this->id);
     }
+
+    /**
+     * Blow the cache of notices that link to this URL
+     *
+     * @param boolean $last Whether to blow the "last" cache too
+     *
+     * @return void
+     */
+
+    function blowCache($last=false)
+    {
+        self::blow('file:notice-ids:%s', $this->url);
+        if ($last) {
+            self::blow('file:notice-ids:%s;last', $this->url);
+        }
+        self::blow('file:notice-count:%d', $this->id);
+    }
+
+    /**
+     * Stream of notices linking to this URL
+     *
+     * @param integer $offset   Offset to show; default is 0
+     * @param integer $limit    Limit of notices to show
+     * @param integer $since_id Since this notice
+     * @param integer $max_id   Before this notice
+     *
+     * @return array ids of notices that link to this file
+     */
+
+    function stream($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
+    {
+        $stream = new FileNoticeStream($this);
+        return $stream->getNotices($offset, $limit, $since_id, $max_id);
+    }
+
+    function noticeCount()
+    {
+        $cacheKey = sprintf('file:notice-count:%d', $this->id);
+        
+        $count = self::cacheGet($cacheKey);
+
+        if ($count === false) {
+
+            $f2p = new File_to_post();
+
+            $f2p->file_id = $this->id;
+
+            $count = $f2p->count();
+
+            self::cacheSet($cacheKey, $count);
+        } 
+
+        return $count;
+    }
 }