]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialVideo/Video.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / plugins / GNUsocialVideo / Video.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  * @package   GNU Social
23  * @author    Ian Denhardt <ian@zenhack.net>
24  * @copyright 2011 Free Software Foundation, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26  */
27
28 if(!defined('STATUSNET')){
29     exit(1);
30 }
31
32 /**
33  * Data class for videos.
34  */
35
36 class Video extends Managed_DataObject
37 {
38     const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/video';
39
40     public $__table = 'video'; // table name
41     public $id;                // char (36) // UUID
42     public $uri;               // varchar (255)  // This is the corresponding notice's uri.
43     public $url;               // varchar (255)
44     public $profile_id;        // int
45     
46     public function staticGet($k, $v=null)
47     {
48         return Memcached_DataObject::staticGet('Video', $k, $v);
49     }
50
51     public function getByNotice($notice)
52     {
53         return self::staticGet('uri', $notice->uri);
54     }
55
56     public function getNotice()
57     {
58         return Notice::staticGet('uri', $this->uri);
59     }
60
61     public static function schemaDef()
62     {
63         return array(
64             'description' => 'A video clip',
65             'fields' => array(
66                 'id' => array('type' => 'char',
67                               'length' => 36,
68                               'not null' => true,
69                               'description' => 'UUID'),
70                 'uri' => array('type' => 'varchar',
71                                'length' => 255,
72                                'not null' => true),
73                 'url' => array('type' => 'varchar',
74                                'length' => 255,
75                                'not null' => true),
76                 'profile_id' => array('type' => 'int', 'not null' => true),
77             ),
78             'primary key' => array('id'),
79             'foreign keys' => array('video_profile_id__key' => array('profile' => array('profile_id' => 'id'))),
80         );
81     }
82
83     function saveNew($profile, $url, $options=array())
84     {
85         $vid = new Video();
86
87         $vid->id =  UUID::gen();
88         $vid->profile_id = $profile->id;
89         $vid->url = $url;
90
91
92         $options['object_type'] = Video::OBJECT_TYPE;
93
94         if (!array_key_exists('uri', $options)) { 
95             $options['uri'] = common_local_url('showvideo', array('id' => $vid->id));
96         }
97
98         if (!array_key_exists('rendered', $options)) {
99             $options['rendered'] = sprintf("<video src=\"%s\">Sorry, your browser doesn't support the video tag.</video>", $url);
100         }
101
102         $vid->uri = $options['uri'];
103         
104         $vid->insert();
105
106         return Notice::saveNew($profile->id,
107                                '',
108                                'web',
109                                $options);
110
111     }
112 }