forked from GNUsocial/gnu-social
first whack at proper photo sharing federation w/ activity streams.
This commit is contained in:
parent
70c3532996
commit
56c0f97bea
@ -48,12 +48,12 @@ class GNUsocialPhotosPlugin extends Plugin
|
|||||||
case 'PhotouploadAction':
|
case 'PhotouploadAction':
|
||||||
include_once $dir . '/lib/photolib.php';
|
include_once $dir . '/lib/photolib.php';
|
||||||
include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
|
include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
|
||||||
include_once $dir . '/classes/gnusocialphoto.php';
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_once $dir . '/classes/gnusocialphoto.php';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,10 +61,9 @@ class GNUsocialPhotosPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
$schema = Schema::get();
|
$schema = Schema::get();
|
||||||
$schema->ensureTable('GNUsocialPhoto',
|
$schema->ensureTable('GNUsocialPhoto',
|
||||||
array(new ColumnDef('notice_id', 'integer', null, false, null, true, null, null, true),
|
array(new ColumnDef('notice_id', 'int(11)', null, false),
|
||||||
new ColumnDef('path', 'varchar(150)', null, false),
|
new ColumnDef('uri', 'varchar(512)', null, false),
|
||||||
new ColumnDef('thumb_path', 'varchar(156)', null, false), // 156 = 150 + strlen('thumb.')
|
new ColumnDef('thumb_uri', 'varchar(512)', null, false)));
|
||||||
new ColumnDef('owner_id', 'int(11)', null, false)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRouterInitialized($m)
|
function onRouterInitialized($m)
|
||||||
@ -81,7 +80,47 @@ class GNUsocialPhotosPlugin extends Plugin
|
|||||||
if($photo) {
|
if($photo) {
|
||||||
$type = ActivityObject::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)
|
function onStartShowNoticeItem($action)
|
||||||
{
|
{
|
||||||
|
@ -134,10 +134,10 @@ class PhotouploadAction extends Action
|
|||||||
$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);
|
move_uploaded_file($imagefile->filepath, INSTALLDIR . '/file/' . $filename);
|
||||||
photo_make_thumbnail($filename);
|
photo_make_thumbnail($filename);
|
||||||
$path = '/file/' . $filename;
|
$uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
|
||||||
$thumb_path = '/file/thumb.' . $filename;
|
$thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
|
||||||
$profile_id = $cur->id;
|
$profile_id = $cur->id;
|
||||||
GNUsocialPhoto::saveNew($profile_id, $thumb_path, $path, 'web');
|
GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, 'web');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,35 +35,33 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
|
|||||||
class GNUsocialPhoto extends Memcached_DataObject
|
class GNUsocialPhoto extends Memcached_DataObject
|
||||||
{
|
{
|
||||||
public $__table = 'GNUsocialPhoto';
|
public $__table = 'GNUsocialPhoto';
|
||||||
public $noitce_id; // integer
|
public $notice_id; // int(11)
|
||||||
public $path; // varchar(150)
|
public $uri; // varchar(512)
|
||||||
public $thumb_path; // varchar(156)
|
public $thumb_uri; // varchar(512)
|
||||||
public $owner_id; // int(11) (user who posted the photo)
|
|
||||||
|
|
||||||
function staticGet($k,$v=NULL)
|
function staticGet($k,$v=NULL)
|
||||||
{
|
{
|
||||||
return Memcached_DataObject::staticGet('GNUsocialPhoto',$k,$v);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if(!unlink(INSTALLDIR . $this->path)) {
|
if(!unlink(INSTALLDIR . $this->path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return parent::delete();
|
return parent::delete();
|
||||||
}
|
} */
|
||||||
|
|
||||||
function table()
|
function table()
|
||||||
{
|
{
|
||||||
return array('notice_id' => DB_DATAOBJECT_INT,
|
return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||||
'path' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||||
'thumb_path' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
|
||||||
'owner_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function keys()
|
function keys()
|
||||||
{
|
{
|
||||||
return array_keys($this->keyTypes());
|
return array_keys($this->keyTypes());
|
||||||
@ -79,23 +77,21 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
return array(false, false, false);
|
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 = new GNUsocialPhoto();
|
||||||
$photo->thumb_path = $thumb_path;
|
$photo->thumb_uri = $thumb_uri;
|
||||||
$photo->path = $path;
|
$photo->uri = $uri;
|
||||||
$photo->owner_id = $profile_id;
|
|
||||||
|
|
||||||
$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, $uri, $source);
|
||||||
|
|
||||||
$notice = Notice::saveNew($profile_id, 'http://' . common_config('site', 'server') . $path, $source, array('rendered' => $rend));
|
|
||||||
$photo->notice_id = $notice->id;
|
$photo->notice_id = $notice->id;
|
||||||
$photo_id = $photo->insert();
|
$photo_id = $photo->insert();
|
||||||
if (!$photo_id) {
|
if (!$photo_id) {
|
||||||
common_log_db_error($photo, 'INSERT', __FILE__);
|
common_log_db_error($photo, 'INSERT', __FILE__);
|
||||||
throw new ServerException(_m('Problem Saving Photo.'));
|
throw new ServerException(_m('Problem Saving Photo.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function asActivityNoun($element)
|
function asActivityNoun($element)
|
||||||
{
|
{
|
||||||
@ -103,7 +99,7 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
|
|
||||||
$object->type = ActivityObject::PHOTO;
|
$object->type = ActivityObject::PHOTO;
|
||||||
$object->title = "";
|
$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;
|
$object->largerImage = 'http://' . common_config('site', 'server') . $this->path;
|
||||||
return $object;
|
return $object;
|
||||||
} */
|
} */
|
||||||
|
Loading…
Reference in New Issue
Block a user