]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialVideo/GNUsocialVideoPlugin.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / GNUsocialVideo / GNUsocialVideoPlugin.php
1 <?php
2 /**
3  * GNU Social
4  * Copyright (C) 2011, Free Software Foundation, Inc.
5  *
6  * PHP version 5
7  *
8  * LICENCE:
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Widget
23  * @package   GNU Social
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
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 class GNUsocialVideoPlugin extends MicroAppPlugin
34 {
35
36     var $oldSaveNew = true;
37
38     function onCheckSchema()
39     {
40         $schema = Schema::get();
41
42         $schema->ensureTable('video', Video::schemaDef());
43
44         return true;
45     }
46
47     function onRouterInitialized(URLMapper $m)
48     {
49         $m->connect('main/postvideo', array('action' => 'postvideo'));
50         $m->connect('showvideo/:id', array('action' => 'showvideo'));
51         return true;
52     }
53
54     function entryForm($out)
55     {
56         return new VideoForm($out);
57     }
58
59     function appTitle()
60     {
61         return _('Video');
62     }
63
64     function tag()
65     {
66         return 'GNUsocialVideo';
67     }
68
69     function types()
70     {
71         return array(Video::OBJECT_TYPE);
72     }
73
74     function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
75     {
76         if(count($activity->objects) != 1) {
77             throw new Exception('Too many activity objects.');
78         }
79
80         $videoObj = $activity->objects[0];
81
82         if ($videoObj->type != Video::OBJECT_TYPE) {
83             throw new Exception('Wrong type for object.');
84         }
85
86         // For now we read straight from the xml tree, no other way to get this information.
87         // When there's a better API for this, we should change to it.
88         $uri = ActivityUtils::getLink($activity->entry, 'enclosure');
89
90         $options['object_type'] = Video::OBJECT_TYPE;
91
92         Video::saveNew($actor, $uri, $options);
93    
94     }
95
96     function activityObjectFromNotice(Notice $notice)
97     {
98         $object = new ActivityObject();
99         $object->id = $notice->uri;
100         $object->type = Video::OBJECT_TYPE;
101         $object->title = $notice->content;
102         $object->summary = $notice->content;
103         $object->link = $notice->getUrl();
104
105         $vid = Video::getByNotice($notice);
106
107         if ($vid) {
108             $object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array());
109         }
110         
111         return $object;
112         
113     }
114
115     function showNotice(Notice $notice, HTMLOutputter $out)
116     {
117         $vid = Video::getByNotice($notice);
118         if ($vid) {
119             $out->element('video', array('src' => $vid->url,
120                 'width' => '100%',
121                 'controls' => 'controls'));
122         }
123     }
124
125     function deleteRelated(Notice $notice)
126     {
127         $vid = Video::getByNotice($notice);
128         if ($vid) {
129             $vid->delete();
130         }
131     }
132 }