4 * Copyright (C) 2011, Free Software Foundation, Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Ian Denhardt <ian@zenhack.net>
25 * @copyright 2011 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 if (!defined('STATUSNET')) {
33 class GNUsocialVideoPlugin extends MicroAppPlugin
36 function onCheckSchema()
38 $schema = Schema::get();
40 $schema->ensureTable('video', Video::schemaDef());
45 function onRouterInitialized($m)
47 $m->connect('main/postvideo', array('action' => 'postvideo'));
48 $m->connect('showvideo/:id', array('action' => 'showvideo'));
52 function entryForm($out)
54 return new VideoForm($out);
64 return 'GNUsocialVideo';
69 return array(Video::OBJECT_TYPE);
72 function saveNoticeFromActivity($activity, $actor, $options=array())
74 if(count($activity->objects) != 1) {
75 throw new Exception('Too many activity objects.');
78 $videoObj = $activity->objects[0];
80 if ($videoObj->type != Video::OBJECT_TYPE) {
81 throw new Exception('Wrong type for object.');
84 // For now we read straight from the xml tree, no other way to get this information.
85 // When there's a better API for this, we should change to it.
86 $uri = ActivityUtils::getLink($activity->entry, 'enclosure');
88 $options['object_type'] = Video::OBJECT_TYPE;
90 Video::saveNew($actor, $uri, $options);
94 function activityObjectFromNotice($notice)
96 $object = new ActivityObject();
97 $object->id = $notice->uri;
98 $object->type = Video::OBJECT_TYPE;
99 $object->title = $notice->content;
100 $object->summary = $notice->content;
101 $object->link = $notice->getUrl();
103 $vid = Video::getByNotice($notice);
106 $object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array());
113 function showNotice($notice, $out)
115 $vid = Video::getByNotice($notice);
117 $out->element('video', array('src' => $vid->url,
119 'controls' => 'controls'));
123 function deleteRelated($notice)
125 $vid = Video::getByNotice($notice);