summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Denhardt <ian@zenhack.net>2010-08-16 16:21:27 -0400
committerIan Denhardt <ian@zenhack.net>2010-08-16 16:21:27 -0400
commit56c0f97bea15a6ca2733530fc9212c00a8946431 (patch)
treee7a3c436b30b62c6785024519719176e5c87ca2b
parent70c3532996b4239880607e705ffb4e9f9aaa692a (diff)
first whack at proper photo sharing federation w/ activity streams.
-rw-r--r--plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php51
-rw-r--r--plugins/GNUsocialPhotos/actions/photoupload.php6
-rw-r--r--plugins/GNUsocialPhotos/classes/gnusocialphoto.php40
3 files changed, 66 insertions, 31 deletions
diff --git a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
index 480f4ca46..2a98a35d2 100644
--- a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
+++ b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
@@ -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)
{
diff --git a/plugins/GNUsocialPhotos/actions/photoupload.php b/plugins/GNUsocialPhotos/actions/photoupload.php
index 6fdf51531..216f1768f 100644
--- a/plugins/GNUsocialPhotos/actions/photoupload.php
+++ b/plugins/GNUsocialPhotos/actions/photoupload.php
@@ -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');
}
}
diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php
index c724db1f1..4965cd0d9 100644
--- a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php
+++ b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php
@@ -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;
} */