X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FGNUsocialVideo%2FGNUsocialVideoPlugin.php;h=3310712ba76da6b470a6ea6383fd3eb7212044d2;hb=63ab20d20bfe2985402f7f66c3679bcb36e497e8;hp=5e9a6f85e9588b077b60f3c17ed99dab9216f372;hpb=df562a1d8f4515462b190a214a4b6642f7855130;p=quix0rs-gnu-social.git diff --git a/plugins/GNUsocialVideo/GNUsocialVideoPlugin.php b/plugins/GNUsocialVideo/GNUsocialVideoPlugin.php index 5e9a6f85e9..3310712ba7 100644 --- a/plugins/GNUsocialVideo/GNUsocialVideoPlugin.php +++ b/plugins/GNUsocialVideo/GNUsocialVideoPlugin.php @@ -1,7 +1,7 @@ - * @copyright 2010 Free Software Foundation, Inc. + * @copyright 2011 Free Software Foundation, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 */ @@ -30,25 +30,103 @@ if (!defined('STATUSNET')) { exit(1); } -class GNUsocialVideoPlugin extends Plugin +class GNUsocialVideoPlugin extends MicroAppPlugin { - function onAutoload($cls) - { - $dir = dirname(__FILE__); - switch($cls) - { - case 'PostvideoAction': - include_once $dir . '/actions/postvideo.php'; - break; - default: - break; - } + + var $oldSaveNew = true; + + function onCheckSchema() + { + $schema = Schema::get(); + + $schema->ensureTable('video', Video::schemaDef()); + return true; } function onRouterInitialized($m) { $m->connect('main/postvideo', array('action' => 'postvideo')); + $m->connect('showvideo/:id', array('action' => 'showvideo')); return true; } + + function entryForm($out) + { + return new VideoForm($out); + } + + function appTitle() + { + return _('Video'); + } + + function tag() + { + return 'GNUsocialVideo'; + } + + function types() + { + return array(Video::OBJECT_TYPE); + } + + function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array()) + { + 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); + + } + + function activityObjectFromNotice(Notice $notice) + { + $object = new ActivityObject(); + $object->id = $notice->uri; + $object->type = Video::OBJECT_TYPE; + $object->title = $notice->content; + $object->summary = $notice->content; + $object->link = $notice->getUrl(); + + $vid = Video::getByNotice($notice); + + if ($vid) { + $object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array()); + } + + return $object; + + } + + function showNotice(Notice $notice, HTMLOutputter $out) + { + $vid = Video::getByNotice($notice); + if ($vid) { + $out->element('video', array('src' => $vid->url, + 'width' => '100%', + 'controls' => 'controls')); + } + } + + function deleteRelated(Notice $notice) + { + $vid = Video::getByNotice($notice); + if ($vid) { + $vid->delete(); + } + } }