2010-08-11 19:27:42 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* GNU Social
|
2011-05-27 17:22:47 +01:00
|
|
|
* Copyright (C) 2011, Free Software Foundation, Inc.
|
2010-08-11 19:27:42 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* @category Widget
|
|
|
|
* @package GNU Social
|
|
|
|
* @author Ian Denhardt <ian@zenhack.net>
|
2011-05-27 17:22:47 +01:00
|
|
|
* @copyright 2011 Free Software Foundation, Inc.
|
2010-08-11 19:27:42 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-16 03:51:07 +00:00
|
|
|
class GNUsocialVideoPlugin extends MicroAppPlugin
|
2010-08-11 19:27:42 +01:00
|
|
|
{
|
2011-03-16 03:51:07 +00:00
|
|
|
|
2014-07-01 14:48:34 +01:00
|
|
|
var $oldSaveNew = true;
|
|
|
|
|
2011-03-16 03:51:07 +00:00
|
|
|
function onCheckSchema()
|
|
|
|
{
|
|
|
|
$schema = Schema::get();
|
|
|
|
|
|
|
|
$schema->ensureTable('video', Video::schemaDef());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-11 19:27:42 +01:00
|
|
|
function onRouterInitialized($m)
|
|
|
|
{
|
|
|
|
$m->connect('main/postvideo', array('action' => 'postvideo'));
|
2011-03-16 03:51:07 +00:00
|
|
|
$m->connect('showvideo/:id', array('action' => 'showvideo'));
|
2010-08-11 19:27:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-03-16 03:51:07 +00:00
|
|
|
|
|
|
|
function entryForm($out)
|
|
|
|
{
|
|
|
|
return new VideoForm($out);
|
|
|
|
}
|
|
|
|
|
|
|
|
function appTitle()
|
|
|
|
{
|
2011-05-24 20:48:34 +01:00
|
|
|
return _('Video');
|
2011-03-16 03:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function tag()
|
|
|
|
{
|
|
|
|
return 'GNUsocialVideo';
|
|
|
|
}
|
|
|
|
|
|
|
|
function types()
|
|
|
|
{
|
|
|
|
return array(Video::OBJECT_TYPE);
|
|
|
|
}
|
|
|
|
|
2014-07-02 10:37:46 +01:00
|
|
|
function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
|
2011-03-16 03:51:07 +00:00
|
|
|
{
|
|
|
|
if(count($activity->objects) != 1) {
|
|
|
|
throw new Exception('Too many activity objects.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$videoObj = $activity->objects[0];
|
|
|
|
|
|
|
|
if ($videoObj->type != Video::OBJECT_TYPE) {
|
|
|
|
throw new Exception('Wrong type for object.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now we read straight from the xml tree, no other way to get this information.
|
|
|
|
// When there's a better API for this, we should change to it.
|
|
|
|
$uri = ActivityUtils::getLink($activity->entry, 'enclosure');
|
|
|
|
|
|
|
|
$options['object_type'] = Video::OBJECT_TYPE;
|
|
|
|
|
|
|
|
Video::saveNew($actor, $uri, $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-02 10:37:46 +01:00
|
|
|
function activityObjectFromNotice(Notice $notice)
|
2011-03-16 03:51:07 +00:00
|
|
|
{
|
|
|
|
$object = new ActivityObject();
|
|
|
|
$object->id = $notice->uri;
|
|
|
|
$object->type = Video::OBJECT_TYPE;
|
|
|
|
$object->title = $notice->content;
|
|
|
|
$object->summary = $notice->content;
|
2014-04-29 18:46:58 +01:00
|
|
|
$object->link = $notice->getUrl();
|
2011-03-16 03:51:07 +00:00
|
|
|
|
|
|
|
$vid = Video::getByNotice($notice);
|
|
|
|
|
|
|
|
if ($vid) {
|
|
|
|
$object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-04 13:14:49 +01:00
|
|
|
function showNotice(Notice $notice, HTMLOutputter $out)
|
2011-03-16 03:51:07 +00:00
|
|
|
{
|
|
|
|
$vid = Video::getByNotice($notice);
|
|
|
|
if ($vid) {
|
2011-03-28 12:59:07 +01:00
|
|
|
$out->element('video', array('src' => $vid->url,
|
|
|
|
'width' => '100%',
|
|
|
|
'controls' => 'controls'));
|
2011-03-16 03:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-02 10:37:46 +01:00
|
|
|
function deleteRelated(Notice $notice)
|
2011-03-16 03:51:07 +00:00
|
|
|
{
|
2011-03-28 09:32:46 +01:00
|
|
|
$vid = Video::getByNotice($notice);
|
|
|
|
if ($vid) {
|
|
|
|
$vid->delete();
|
|
|
|
}
|
2011-03-16 03:51:07 +00:00
|
|
|
}
|
2010-08-11 19:27:42 +01:00
|
|
|
}
|