forked from GNUsocial/gnu-social
Photo federation is basically working now, could use some polish.
This commit is contained in:
parent
39d0420ab6
commit
30815645fc
@ -39,6 +39,7 @@ class GNUsocialPhotosPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
$dir = dirname(__FILE__);
|
$dir = dirname(__FILE__);
|
||||||
|
|
||||||
|
include_once $dir . '/lib/tempphoto.php';
|
||||||
switch ($cls)
|
switch ($cls)
|
||||||
{
|
{
|
||||||
case 'PhotosAction':
|
case 'PhotosAction':
|
||||||
@ -81,53 +82,72 @@ class GNUsocialPhotosPlugin extends Plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStartActivityDefaultObjectType(&$notice, &$xs, &$type)
|
function onStartNoticeDistribute($notice)
|
||||||
{
|
{
|
||||||
$photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
|
common_log(LOG_INFO, "event: StartNoticeDistribute");
|
||||||
if($photo) {
|
if (GNUsocialPhotoTemp::$tmp) {
|
||||||
$type = ActivityObject::PHOTO;
|
GNUsocialPhotoTemp::$tmp->notice_id = $notice->id;
|
||||||
}
|
$photo_id = GNUsocialPhotoTemp::$tmp->insert();
|
||||||
}
|
if (!$photo_id) {
|
||||||
|
common_log_db_error($photo, 'INSERT', __FILE__);
|
||||||
function onStartActivityObjects(&$notice, &$xs, &$objects)
|
throw new ServerException(_m('Problem saving photo.'));
|
||||||
{
|
|
||||||
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onEndNoticeAsActivity($notice, &$activity)
|
||||||
|
{
|
||||||
|
common_log(LOG_INFO, 'photo plugin: EndNoticeAsActivity');
|
||||||
|
$photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
|
||||||
|
if(!$photo) {
|
||||||
|
common_log(LOG_INFO, 'not a photo.');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$activity->objects[0]->type = ActivityObject::PHOTO;
|
||||||
|
$activity->objects[0]->thumbnail = $photo->thumb_uri;
|
||||||
|
$activity->objects[0]->largerImage = $photo->uri;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onStartHandleFeedEntry($activity)
|
||||||
|
{
|
||||||
|
common_log(LOG_INFO, 'photo plugin: onEndAtomPubNewActivity');
|
||||||
|
$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.
|
||||||
|
|
||||||
|
common_log(LOG_INFO, 'uri : ' . $uri);
|
||||||
|
common_log(LOG_INFO, 'thumb_uri : ' . $thumb_uri);
|
||||||
|
|
||||||
|
// It's possible this is validated elsewhere, but I'm not sure and
|
||||||
|
// would rather be safe.
|
||||||
|
$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($thumb_uri)) {
|
||||||
|
// We need a thumbnail, so if we aren't given one, use the actual picture for now.
|
||||||
|
$thumb_uri = $uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($uri) && !empty($thumb_uri)) {
|
||||||
|
GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, $source, false);
|
||||||
|
} else {
|
||||||
|
common_log(LOG_INFO, 'bad URI for photo');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function onStartShowNoticeItem($action)
|
function onStartShowNoticeItem($action)
|
||||||
{
|
{
|
||||||
|
@ -142,9 +142,9 @@ class PhotouploadAction extends Action
|
|||||||
$album = GNUsocialPhotoAlbum::staticGet('profile_id', $profile_id);
|
$album = GNUsocialPhotoAlbum::staticGet('profile_id', $profile_id);
|
||||||
if(!$album) {
|
if(!$album) {
|
||||||
$album = GNUsocialPhotoAlbum::newAlbum($profile_id, 'Default');
|
$album = GNUsocialPhotoAlbum::newAlbum($profile_id, 'Default');
|
||||||
GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web');
|
GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false);
|
||||||
} else {
|
} else {
|
||||||
GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web');
|
GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,19 +89,24 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
return array(false, false, false);
|
return array(false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source)
|
function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source, $insert_now)
|
||||||
{
|
{
|
||||||
$photo = new GNUsocialPhoto();
|
$photo = new GNUsocialPhoto();
|
||||||
$photo->thumb_uri = $thumb_uri;
|
$photo->thumb_uri = $thumb_uri;
|
||||||
$photo->uri = $uri;
|
$photo->uri = $uri;
|
||||||
$photo->album_id = $album_id;
|
$photo->album_id = $album_id;
|
||||||
|
|
||||||
$notice = Notice::saveNew($profile_id, $uri, $source);
|
if($insert_now) {
|
||||||
$photo->notice_id = $notice->id;
|
$notice = Notice::saveNew($profile_id, $uri, $source);
|
||||||
$photo_id = $photo->insert();
|
$photo->notice_id = $notice->id;
|
||||||
if (!$photo_id) {
|
$photo_id = $photo->insert();
|
||||||
common_log_db_error($photo, 'INSERT', __FILE__);
|
if (!$photo_id) {
|
||||||
throw new ServerException(_m('Problem Saving Photo.'));
|
common_log_db_error($photo, 'INSERT', __FILE__);
|
||||||
|
throw new ServerException(_m('Problem Saving Photo.'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GNUsocialPhotoTemp::$tmp = $photo;
|
||||||
|
Notice::saveNew($profile_id, $uri, $source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,16 +133,4 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
|
|
||||||
return $photos;
|
return $photos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
function asActivityNoun($element)
|
|
||||||
{
|
|
||||||
$object = new ActivityObject();
|
|
||||||
|
|
||||||
$object->type = ActivityObject::PHOTO;
|
|
||||||
$object->title = "";
|
|
||||||
$object->thumbnail = 'http://' . common_config('site', 'server') . $this->thumb_uri;
|
|
||||||
$object->largerImage = 'http://' . common_config('site', 'server') . $this->path;
|
|
||||||
return $object;
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
37
plugins/GNUsocialPhotos/lib/tempphoto.php
Normal file
37
plugins/GNUsocialPhotos/lib/tempphoto.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* GNU Social
|
||||||
|
* Copyright (C) 2010, Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* PHP version 5
|
||||||
|
*
|
||||||
|
* LICENCE:
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* @package GNU Social
|
||||||
|
* @author Ian Denhardt <ian@zenhack.net>
|
||||||
|
* @copyright 2010 Free Software Foundation, Inc.
|
||||||
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('STATUSNET')) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX: This entire file is an ugly hack and needs to be replaced. It is essentially a global variable
|
||||||
|
// used to store information about a photo we want to insert in onStartNoticeDistribute(), which we
|
||||||
|
// can't actually pass to that function.
|
||||||
|
class GNUsocialPhotoTemp {
|
||||||
|
public static $tmp = null;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user