]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/Video.php
Improve Video plugin
[SourceForge/phpwiki.git] / lib / plugin / Video.php
1 <?php
2
3 /*
4  * Copyright 2009 Roger Guignard and Marc-Etienne Vargenau, Alcatel-Lucent
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /*
24  * Standard Alcatel-Lucent disclaimer for contributing to open source
25  *
26  * "The VideoPlugin ("Contribution") has not been tested and/or
27  * validated for release as or in products, combinations with products or
28  * other commercial use. Any use of the Contribution is entirely made at
29  * the user's own responsibility and the user can not rely on any features,
30  * functionalities or performances Alcatel-Lucent has attributed to the
31  * Contribution.
32  *
33  * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34  * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36  * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37  * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38  * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40  * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41  * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
42  * ALONE BASIS."
43  */
44
45 class WikiPlugin_Video
46     extends WikiPlugin
47 {
48     function getDescription()
49     {
50         return _("Display video in Flash or HTML5.");
51     }
52
53     function getDefaultArguments()
54     {
55         return array('width' => 460,
56             'height' => 320,
57             'url' => '',
58             'file' => '',
59             'autoplay' => 'false'
60         );
61     }
62
63     /**
64      * @param WikiDB $dbi
65      * @param string $argstr
66      * @param WikiRequest $request
67      * @param string $basepage
68      * @return mixed
69      */
70     function run($dbi, $argstr, &$request, $basepage)
71     {
72
73         global $WikiTheme;
74         $args = $this->getArgs($argstr, $request);
75         $url = $args['url'];
76         $file = $args['file'];
77         $width = $args['width'];
78         $height = $args['height'];
79         $autoplay = $args['autoplay'];
80
81         if (!$url && !$file) {
82             return $this->error(_("Both 'url' or 'file' parameters missing."));
83         } elseif ($url && $file) {
84             return $this->error(_("Choose only one of 'url' or 'file' parameters."));
85         } elseif ($file) {
86             // $url = SERVER_URL . getUploadDataPath() . '/' . $file;
87             $url = getUploadDataPath() . '/' . $file;
88         }
89
90         if (string_ends_with($url, ".ogg")
91            || string_ends_with($url, ".mp4")
92            || string_ends_with($url, ".webm")) {
93             $video = HTML::video(array('controls' => 'controls',
94                                        'width' => $width,
95                                        'height' => $height,
96                                        'src' => $url),
97                 _("Your browser does not understand the HTML 5 video tag."));
98             if ($autoplay == 'true') {
99                 $video->setAttr('autoplay', 'autoplay');
100             }
101             return $video;
102         }
103
104         $html = HTML();
105
106         if (isBrowserIE()) {
107             $object = HTML::object(array('id' => 'flowplayer',
108                 'classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
109                 'width' => $width,
110                 'height' => $height));
111
112             $param = HTML::param(array('name' => 'movie',
113                 'value' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf')));
114             $object->pushContent($param);
115
116             $param = HTML::param(array('name' => "allowfullscreen",
117                 'value' => "true"));
118             $object->pushContent($param);
119
120             $param = HTML::param(array('name' => "allowscriptaccess",
121                 'value' => "false"));
122             $object->pushContent($param);
123
124             $flashvars = "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}";
125
126             $param = HTML::param(array('name' => 'flashvars',
127                 'value' => $flashvars));
128             $object->pushContent($param);
129
130             $embed = HTML::embed(array('type' => 'application/x-shockwave-flash',
131                 'width' => $width,
132                 'height' => $height,
133                 'src' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf'),
134                 'flashvars' => $flashvars));
135             $object->pushContent($embed);
136
137             $html->pushContent($object);
138
139         } else {
140             $object = HTML::object(array('data' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf'),
141                 'type' => "application/x-shockwave-flash",
142                 'width' => $width,
143                 'height' => $height));
144
145             $param = HTML::param(array('name' => "allowfullscreen",
146                 'value' => "true"));
147             $object->pushContent($param);
148
149             $param = HTML::param(array('name' => "allowscriptaccess",
150                 'value' => "false"));
151             $object->pushContent($param);
152
153             $value = "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}";
154             $param = HTML::param(array('name' => "flashvars",
155                 'value' => $value));
156             $object->pushContent($param);
157
158             $html->pushContent($object);
159         }
160         return $html;
161     }
162 }
163
164 // Local Variables:
165 // mode: php
166 // tab-width: 8
167 // c-basic-offset: 4
168 // c-hanging-comment-ender-p: nil
169 // indent-tabs-mode: nil
170 // End: