]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Photo federation is basically working now, could use some polish.
authorIan Denhardt <ian@zenhack.net>
Tue, 21 Dec 2010 03:02:50 +0000 (22:02 -0500)
committerIan Denhardt <ian@zenhack.net>
Tue, 21 Dec 2010 03:02:50 +0000 (22:02 -0500)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/photoupload.php
plugins/GNUsocialPhotos/classes/gnusocialphoto.php
plugins/GNUsocialPhotos/lib/tempphoto.php [new file with mode: 0644]

index 8aa10c7f70a65e7a425bff88356b575c469e6049..8e603c2fe08af45745a4be08a133ba8d14426131 100644 (file)
@@ -39,6 +39,7 @@ class GNUsocialPhotosPlugin extends Plugin
     {
         $dir = dirname(__FILE__);
 
+        include_once $dir . '/lib/tempphoto.php';
         switch ($cls)
         {
         case 'PhotosAction':
@@ -81,54 +82,73 @@ class GNUsocialPhotosPlugin extends Plugin
         return true;
     }
 
-    function onStartActivityDefaultObjectType(&$notice, &$xs, &$type)
+    function onStartNoticeDistribute($notice)
     {
-        $photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
-        if($photo) {
-            $type = ActivityObject::PHOTO;
+        common_log(LOG_INFO, "event: StartNoticeDistribute");
+        if (GNUsocialPhotoTemp::$tmp) {
+            GNUsocialPhotoTemp::$tmp->notice_id = $notice->id;
+            $photo_id = GNUsocialPhotoTemp::$tmp->insert();
+            if (!$photo_id) {
+                common_log_db_error($photo, 'INSERT', __FILE__);
+                throw new ServerException(_m('Problem saving photo.'));
+            }
         }
+        return true;
     }
 
-    function onStartActivityObjects(&$notice, &$xs, &$objects)
+    function onEndNoticeAsActivity($notice, &$activity)
     {
+        common_log(LOG_INFO, 'photo plugin: EndNoticeAsActivity');
         $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;
+        if(!$photo) {
+            common_log(LOG_INFO, 'not a photo.');
+            return true;
         }
+
+        $activity->objects[0]->type = ActivityObject::PHOTO;
+        $activity->objects[0]->thumbnail = $photo->thumb_uri;
+        $activity->objects[0]->largerImage = $photo->uri;
+        return false;
     }
 
+
     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;
+        common_log(LOG_INFO, 'photo plugin: onEndAtomPubNewActivity');
+        $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.
+
+                common_log(LOG_INFO, 'uri : ' .  $uri);
+                common_log(LOG_INFO, 'thumb_uri : ' . $thumb_uri);
+
+                // It's possible this is validated elsewhere, but I'm not sure and
+                // would rather be safe.
+                $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($thumb_uri)) {
+                    // We need a thumbnail, so if we aren't given one, use the actual picture for now.
+                    $thumb_uri = $uri;
                 }
+
+                if (!empty($uri) && !empty($thumb_uri)) {
+                    GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, $source, false);
+                } else {
+                    common_log(LOG_INFO, 'bad URI for photo');
+                }
+                return false;
             }
         }
         return true;
     }
 
-
     function onStartShowNoticeItem($action)
     {
         $photo = GNUsocialPhoto::staticGet('notice_id', $action->notice->id);
index 209b31ab4f30c9dcf77fb5f610af59868d76bd15..b4e7771a18ff1b39e93df113be5bf3fb30d47fc3 100644 (file)
@@ -142,9 +142,9 @@ class PhotouploadAction extends Action
         $album = GNUsocialPhotoAlbum::staticGet('profile_id', $profile_id);
         if(!$album) {
             $album = GNUsocialPhotoAlbum::newAlbum($profile_id, 'Default');
-            GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web');
+            GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false);
         } else {
-            GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web');
+            GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false);
         }
     }
 
index 1314ba87e02a9417b4c7806de10bb6805549e613..3df160822b3596f461b34b9690b3e1b478906289 100644 (file)
@@ -89,19 +89,24 @@ class GNUsocialPhoto extends Memcached_DataObject
         return array(false, false, false);
     }
 
-    function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source)
+    function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source, $insert_now)
     {
         $photo = new GNUsocialPhoto();
         $photo->thumb_uri = $thumb_uri;
         $photo->uri = $uri;
                $photo->album_id = $album_id;
 
-        $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.'));
+        if($insert_now) {
+            $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.'));
+            }
+        } else {
+            GNUsocialPhotoTemp::$tmp = $photo;
+            Notice::saveNew($profile_id, $uri, $source);
         }
     }
 
@@ -128,16 +133,4 @@ class GNUsocialPhoto extends Memcached_DataObject
 
         return $photos;
     }
-
-    /*
-    function asActivityNoun($element)
-    {
-        $object = new ActivityObject();
-
-        $object->type = ActivityObject::PHOTO;
-        $object->title = "";
-        $object->thumbnail = 'http://' . common_config('site', 'server') . $this->thumb_uri;
-        $object->largerImage = 'http://' . common_config('site', 'server') . $this->path;
-        return $object;
-    } */
 }
diff --git a/plugins/GNUsocialPhotos/lib/tempphoto.php b/plugins/GNUsocialPhotos/lib/tempphoto.php
new file mode 100644 (file)
index 0000000..119c301
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * GNU Social
+ * Copyright (C) 2010, Free Software Foundation, Inc.
+ *
+ * PHP version 5
+ *
+ * LICENCE:
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package   GNU Social
+ * @author    Ian Denhardt <ian@zenhack.net>
+ * @copyright 2010 Free Software Foundation, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+// XXX: This entire file is an ugly hack and needs to be replaced. It is essentially a global variable
+// used to store information about a photo we want to insert in onStartNoticeDistribute(), which we
+// can't actually pass to that function.
+class GNUsocialPhotoTemp {
+    public static $tmp = null; 
+}