]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Photos now show up in feed (locally anywyay.) need cleanup/federation
authorIan Denhardt <ian@zenhack.net>
Wed, 11 Aug 2010 14:54:06 +0000 (10:54 -0400)
committerIan Denhardt <ian@zenhack.net>
Wed, 11 Aug 2010 14:54:06 +0000 (10:54 -0400)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/photoupload.php
plugins/GNUsocialPhotos/classes/gnusocialphoto.php

index f7cb6f3982a76d2ecdb71edfab0c2c5b5a0f2b8c..46c67d5d9604bf0954937c1fa3e61612af003b21 100644 (file)
@@ -44,16 +44,16 @@ class GNUsocialPhotosPlugin extends Plugin
         case 'PhotosAction':
             include_once $dir . '/lib/photolib.php';
             include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
-            return false;
+            break;
         case 'PhotouploadAction':
             include_once $dir . '/lib/photolib.php';
-            include_once $dir . '/classes/gnusocialphoto.php';
             include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
-            return false;
+            break;
         default:
-            return true;
+            break;
         }
 
+        include_once $dir . '/classes/gnusocialphoto.php';
         return true;
     }
 
@@ -61,7 +61,7 @@ class GNUsocialPhotosPlugin extends Plugin
     {
         $schema = Schema::get();
         $schema->ensureTable('GNUsocialPhoto',
-                                array(new ColumnDef('object_id', 'integer', null, false, 'PRI', true, null, null, true),
+                                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)));
@@ -74,4 +74,29 @@ class GNUsocialPhotosPlugin extends Plugin
         common_log(LOG_INFO, "init'd!");
         return true;
     }
+
+    /* function onStartActivityDefaultObjectType(&$notice, &$xs, &$type)
+    {
+        $photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
+        if($photo) {
+            $type = ActivityObject::PHOTO;
+        }
+    } */
+
+    function onStartShowNoticeItem($action)
+    {
+        common_log(LOG_INFO, 'StartShowNoticeItem: ' . $action->notice->id);
+        $photo = GNUsocialPhoto::staticGet('notice_id', $action->notice->id);
+        if($photo) { 
+            common_log(LOG_INFO, 'is photo.');
+            $action->out->elementStart('a', array('href' => 'http://' . common_config('site', 'server') . $photo->path));
+            $action->out->element('img', array('src' => 'http://' . common_config('site', 'server') . $photo->thumb_path));
+            $action->out->elementEnd('a');
+            $action->showNoticeInfo();
+            $action->showNoticeOptions();
+            return false;
+        }
+        common_log(LOG_INFO, 'not photo');
+        return true;
+    }
 }
index 9a643dbe6325f8daf361178c4436d33a389e1e71..6fdf5153199c77ee2dee578abf1b4ddbcde925c6 100644 (file)
@@ -103,6 +103,14 @@ class PhotouploadAction extends Action
         }
     }
 
+    function showForm($msg, $success=false)
+    { 
+        $this->msg = $msg;
+        $this->success = $success;
+
+//        $this->showPage();
+    }
+
     function uploadPhoto()
     {
         common_log(LOG_INFO, 'Is this function even getting called?');
@@ -123,15 +131,13 @@ class PhotouploadAction extends Action
 
         common_log(LOG_INFO, 'upload path : ' . $imagefile->filepath);
 
-        $filename = $cur->nickname . '-' . common_timestamp() . sha1_file($imagefile->filepath) . '.' .  image_type_to_extension($imagefile->type);
+        $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);
-        $photo = new GNUsocialPhoto();
-        $photo->path = '/file/' . $filename;
-        $photo->thumb_path = '/file/thumb.' . $filename;
-        $photo->owner_id = $cur->id;
-        $photo->object_id = 'DEFAULT';
-        $photo->insert();
+        $path = '/file/' . $filename;
+        $thumb_path = '/file/thumb.' . $filename;
+        $profile_id = $cur->id;
+        GNUsocialPhoto::saveNew($profile_id, $thumb_path, $path, 'web');
     }
 
 }
index 882d1026ed9f807fc41433d644a770f06a9a7ff9..96288731e065433dcb14a223c997fc42b2bb61f9 100644 (file)
@@ -35,7 +35,7 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class GNUsocialPhoto extends Memcached_DataObject
 {
     public $__table = 'GNUsocialPhoto';
-    public $object_id;   // integer
+    public $noitce_id;   // integer
     public $path;        // varchar(150)
     public $thumb_path;  // varchar(156)
     public $owner_id;    // int(11) (user who posted the photo)
@@ -58,9 +58,51 @@ class GNUsocialPhoto extends Memcached_DataObject
 
     function table()
     {
-        return array('object_id' => DB_DATAOBJECT_INT,
+        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);
     }
+
+    function keys()
+    {
+        return array_keys($this->keyTypes());
+    }
+
+    function keyTypes()
+    {
+        return array('notice_id' => 'K');
+    }
+
+    function sequenceKey()
+    {
+        return array(false, false, false);
+    }
+
+    function saveNew($profile_id, $thumb_path, $path, $source)
+    {
+        $photo = new GNUsocialPhoto();
+        $photo->thumb_path = $thumb_path;
+        $photo->path = $path;
+        $photo->owner_id = $profile_id;
+
+        $notice = Notice::saveNew($profile_id, 'http://' . common_config('site', 'server') . $path, $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)
+    {
+        $object = new ActivityObject();
+
+        $object->type = ActivityObject::PHOTO;
+        $object->title = "";
+        $object->thumbnail = 'http://' . common_config('site', 'server') . $this->thumb_path;
+        $object->largerImage = 'http://' . common_config('site', 'server') . $this->path;
+        return $object;
+    } */
 }