From 58d98a4c2b58fc69ddef81c2a0f32c079344e0d9 Mon Sep 17 00:00:00 2001 From: Ian Denhardt Date: Wed, 11 Aug 2010 10:54:06 -0400 Subject: [PATCH] Photos now show up in feed (locally anywyay.) need cleanup/federation --- .../GNUsocialPhotos/GNUsocialPhotosPlugin.php | 35 ++++++++++++-- .../GNUsocialPhotos/actions/photoupload.php | 20 +++++--- .../classes/gnusocialphoto.php | 46 ++++++++++++++++++- 3 files changed, 87 insertions(+), 14 deletions(-) diff --git a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php index f7cb6f3982..46c67d5d96 100644 --- a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php +++ b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php @@ -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; + } } diff --git a/plugins/GNUsocialPhotos/actions/photoupload.php b/plugins/GNUsocialPhotos/actions/photoupload.php index 9a643dbe63..6fdf515319 100644 --- a/plugins/GNUsocialPhotos/actions/photoupload.php +++ b/plugins/GNUsocialPhotos/actions/photoupload.php @@ -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'); } } diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php index 882d1026ed..96288731e0 100644 --- a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php +++ b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php @@ -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; + } */ } -- 2.39.5