first whack at proper photo sharing federation w/ activity streams.

This commit is contained in:
Ian Denhardt 2010-08-16 16:21:27 -04:00
parent 70c3532996
commit 56c0f97bea
3 changed files with 66 additions and 31 deletions

View 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)
{

View 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');
}
}

View 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;
} */