]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialVideo/GNUsocialVideoPlugin.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / plugins / GNUsocialVideo / GNUsocialVideoPlugin.php
1 <?php
2 /**
3  * GNU Social
4  * Copyright (C) 2010, 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 2010 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     function onCheckSchema()
37     {
38         $schema = Schema::get();
39
40         $schema->ensureTable('video', Video::schemaDef());
41
42         return true;
43     }
44
45     function onAutoload($cls)
46     {
47         $dir = dirname(__FILE__);
48         switch($cls)
49         {
50         case 'PostvideoAction':
51             include_once $dir . '/actions/postvideo.php';
52             break;
53         case 'Video':
54             include_once $dir . '/Video.php';
55             break;
56         case 'VideoForm':
57             include_once $dir . '/videoform.php';
58             break;
59         case 'ShowvideoAction':
60             include_once $dir . '/showvideo.php';
61             break;
62         default:
63             break;
64         }
65         return true;
66     }
67
68     function onRouterInitialized($m)
69     {
70         $m->connect('main/postvideo', array('action' => 'postvideo'));
71         $m->connect('showvideo/:id', array('action' => 'showvideo'));
72         return true;
73     }
74
75     function entryForm($out)
76     {
77         return new VideoForm($out);
78     }
79
80     function appTitle()
81     {
82         return _('video');
83     }
84
85     function tag()
86     {
87         return 'GNUsocialVideo';
88     }
89
90     function types()
91     {
92         return array(Video::OBJECT_TYPE);
93     }
94
95     function saveNoticeFromActivity($activity, $actor, $options=array())
96     {
97         if(count($activity->objects) != 1) {
98             throw new Exception('Too many activity objects.');
99         }
100
101         $videoObj = $activity->objects[0];
102
103         if ($videoObj->type != Video::OBJECT_TYPE) {
104             throw new Exception('Wrong type for object.');
105         }
106
107         // For now we read straight from the xml tree, no other way to get this information.
108         // When there's a better API for this, we should change to it.
109         $uri = ActivityUtils::getLink($activity->entry, 'enclosure');
110
111         $options['object_type'] = Video::OBJECT_TYPE;
112
113         Video::saveNew($actor, $uri, $options);
114    
115     }
116
117     function activityObjectFromNotice($notice)
118     {
119         $object = new ActivityObject();
120         $object->id = $notice->uri;
121         $object->type = Video::OBJECT_TYPE;
122         $object->title = $notice->content;
123         $object->summary = $notice->content;
124         $object->link = $notice->bestUrl();
125
126         $vid = Video::getByNotice($notice);
127
128         if ($vid) {
129             $object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array());
130         }
131         
132         return $object;
133         
134     }
135
136     function showNotice($notice, $out)
137     {
138         $vid = Video::getByNotice($notice);
139         if ($vid) {
140             $out->element('video', array('src' => $vid->url));
141         }
142     }
143
144     function deleteRelated($notice)
145     {
146         exit(1); // TODO: implement
147     }
148 }