]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
first whack at proper photo sharing federation w/ activity streams.
authorIan Denhardt <ian@zenhack.net>
Mon, 16 Aug 2010 20:21:27 +0000 (16:21 -0400)
committerIan Denhardt <ian@zenhack.net>
Mon, 16 Aug 2010 20:21:27 +0000 (16:21 -0400)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/photoupload.php
plugins/GNUsocialPhotos/classes/gnusocialphoto.php

index 480f4ca46e7a90f771fafeafb6c4f915628e5d51..2a98a35d29c11499a3099d44b65b9a3f2d012f2e 100644 (file)
@@ -48,12 +48,12 @@ class GNUsocialPhotosPlugin extends Plugin
         case 'PhotouploadAction':
             include_once $dir . '/lib/photolib.php';
             include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
-            include_once $dir . '/classes/gnusocialphoto.php';
             break;
         default:
             break;
         }
 
+        include_once $dir . '/classes/gnusocialphoto.php';
         return true;
     }
 
@@ -61,10 +61,9 @@ class GNUsocialPhotosPlugin extends Plugin
     {
         $schema = Schema::get();
         $schema->ensureTable('GNUsocialPhoto',
-                                array(new ColumnDef('notice_id', 'integer', null, false, null, true, null, null, true),
-                                      new ColumnDef('path', 'varchar(150)', null, false),
-                                      new ColumnDef('thumb_path', 'varchar(156)', null, false), // 156 = 150 + strlen('thumb.')
-                                      new ColumnDef('owner_id', 'int(11)', null, false)));
+                                array(new ColumnDef('notice_id', 'int(11)', null, false),
+                                      new ColumnDef('uri', 'varchar(512)', null, false),
+                                      new ColumnDef('thumb_uri', 'varchar(512)', null, false)));
     }
 
     function onRouterInitialized($m)
@@ -81,7 +80,47 @@ class GNUsocialPhotosPlugin extends Plugin
         if($photo) {
             $type = ActivityObject::PHOTO;
         }
-    } 
+    }
+
+    function onStartActivityObjects(&$notice, &$xs, &$objects)
+    {
+        $photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
+        if($photo) {
+            $object = new ActivityObject();
+            $object->thumbnail = $photo->thumb_uri;
+            $object->largerImage = $photo->uri;
+            $object->type = ActivityObject::PHOTO;
+            
+            $object->id = $notice->id;
+            $objects[0] = $object;
+        }
+    }
+
+    function onStartHandleFeedEntry($activity)
+    {
+        if ($activity->verb == ActivityVerb::POST) {
+            $oprofile = Ostatus_profile::ensureActorProfile($activity);
+            foreach ($activity->objects as $object) {
+                if ($object->type == ActivityObject::PHOTO) {
+                    $uri = $object->largerImage;
+                    $thumb_uri = $object->thumbnail;
+                    $profile_id = $oprofile->profile_id;
+                    $source = 'unknown'; // TODO: put something better here.
+
+                    $uri = filter_var($uri, FILTER_SANITIZE_URL);
+                    $thumb_uri = filter_var($thumb_uri, FILTER_SANITIZE_URL);
+                    $uri = filter_var($uri, FILTER_VALIDATE_URL);
+                    $thumb_uri = filter_var($thumb_uri, FILTER_VALIDATE_URL);
+                    if (!empty($uri) && !empty($thumb_uri)) {
+                        GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, $source);
+                    }
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
 /*
     function onStartShowNoticeItem($action)
     {
index 6fdf5153199c77ee2dee578abf1b4ddbcde925c6..216f1768f00eb40a19176a5b1f37b3b4103da6d6 100644 (file)
@@ -134,10 +134,10 @@ class PhotouploadAction extends Action
         $filename = $cur->nickname . '-' . common_timestamp() . sha1_file($imagefile->filepath) .  image_type_to_extension($imagefile->type);
         move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $filename);
         photo_make_thumbnail($filename);
-        $path = '/file/' . $filename;
-        $thumb_path = '/file/thumb.' . $filename;
+        $uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
+        $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
         $profile_id = $cur->id;
-        GNUsocialPhoto::saveNew($profile_id, $thumb_path, $path, 'web');
+        GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, 'web');
     }
 
 }
index c724db1f1c27a063b359d5504c8ab3ad54fb38ed..4965cd0d9cec5a499f511e8de7214bc43f7bbcc0 100644 (file)
@@ -35,35 +35,33 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class GNUsocialPhoto extends Memcached_DataObject
 {
     public $__table = 'GNUsocialPhoto';
-    public $noitce_id;   // integer
-    public $path;        // varchar(150)
-    public $thumb_path;  // varchar(156)
-    public $owner_id;    // int(11) (user who posted the photo)
-
+    public $notice_id;  // int(11)
+    public $uri;        // varchar(512)
+    public $thumb_uri;  // varchar(512)
+    
     function staticGet($k,$v=NULL)
     {
         return Memcached_DataObject::staticGet('GNUsocialPhoto',$k,$v);
     }
 
-    function delete()
+/*    function delete()
     {
-        if(!unlink(INSTALLDIR . $this->thumb_path)) {
+        if(!unlink(INSTALLDIR . $this->thumb_uri)) {
             return false;
         }
         if(!unlink(INSTALLDIR . $this->path)) {
             return false;
         }
         return parent::delete();
-    }
+    } */
 
     function table()
     {
-        return array('notice_id' => DB_DATAOBJECT_INT,
-                     'path' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'thumb_path' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'owner_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL);
+        return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+                     'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
+                     'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
     }
-
+    
     function keys()
     {
         return array_keys($this->keyTypes());
@@ -79,23 +77,21 @@ class GNUsocialPhoto extends Memcached_DataObject
         return array(false, false, false);
     }
 
-    function saveNew($profile_id, $thumb_path, $path, $source)
+    function saveNew($profile_id, $thumb_uri, $uri, $source)
     {
         $photo = new GNUsocialPhoto();
-        $photo->thumb_path = $thumb_path;
-        $photo->path = $path;
-        $photo->owner_id = $profile_id;
+        $photo->thumb_uri = $thumb_uri;
+        $photo->uri = $uri;
 
-        $rend = sprintf('<a href="http://%s%s"><img src="http://%s%s" /></a>', common_config('site', 'server'), $path, common_config('site', 'server'), $thumb_path);
-
-        $notice = Notice::saveNew($profile_id, 'http://' . common_config('site', 'server') . $path, $source, array('rendered' => $rend));
+        $notice = Notice::saveNew($profile_id, $uri, $source);
         $photo->notice_id = $notice->id;
         $photo_id = $photo->insert();
         if (!$photo_id) {
             common_log_db_error($photo, 'INSERT', __FILE__);
             throw new ServerException(_m('Problem Saving Photo.'));
         }
-    }    
+    }
+
     /*
     function asActivityNoun($element)
     {
@@ -103,7 +99,7 @@ class GNUsocialPhoto extends Memcached_DataObject
 
         $object->type = ActivityObject::PHOTO;
         $object->title = "";
-        $object->thumbnail = 'http://' . common_config('site', 'server') . $this->thumb_path;
+        $object->thumbnail = 'http://' . common_config('site', 'server') . $this->thumb_uri;
         $object->largerImage = 'http://' . common_config('site', 'server') . $this->path;
         return $object;
     } */