]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/Video.php
Standardize Video plugin to use ImgObject() for embedded objects.
[SourceForge/phpwiki.git] / lib / plugin / Video.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  * Copyright 2009 Roger Guignard and Marc-Etienne Vargenau, Alcatel-Lucent
5  * Copyright 2009 Reini Urban
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki 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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with PhpWiki; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 /*
25  * Standard Alcatel-Lucent disclaimer for contributing to open source
26  *
27  * "The VideoPlugin ("Contribution") has not been tested and/or
28  * validated for release as or in products, combinations with products or
29  * other commercial use. Any use of the Contribution is entirely made at
30  * the user's own responsibility and the user can not rely on any features,
31  * functionalities or performances Alcatel-Lucent has attributed to the
32  * Contribution.
33  *
34  * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
35  * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
37  * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
38  * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
39  * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
40  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41  * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
42  * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
43  * ALONE BASIS."
44  */
45
46 class WikiPlugin_Video
47 extends WikiPlugin
48 {
49     function getName() {
50         return _("Video");
51     }
52
53     function getDescription() {
54         return _("Display video in Flash");
55     }
56
57     function getVersion() {
58         return preg_replace("/[Revision: $]/", '',
59                             "\$Revision$");
60     }
61
62     function getDefaultArguments() {
63         return array('width'    => 460,
64                      'height'   => 320,
65                      'url'      => '',
66                      'file'     => '',
67                      'autoplay' => 'false'
68                      'image'    => '',
69                      );
70     }
71
72     function run($dbi, $argstr, &$request, $basepage) {
73
74         global $WikiTheme;
75         $args = $this->getArgs($argstr, $request);
76         extract($args);
77
78         if (! $url && ! $file) {
79             return $this->error(_("Both 'url' or 'file' parameters missing."));
80         } elseif ($url && $file) {
81             return $this->error(_("Choose only one of 'url' or 'file' parameters."));
82         } elseif ($file) {
83             $url = getUploadDataPath() . $file;
84         }
85
86         // TODO: Check HTML5 browser capabilities
87         if (string_ends_with($url, ".ogg")) {
88             return HTML::video(array('autoplay' => 'true', 'controls' => 'true', 'src' => $url),
89                                _("Your browser does not understand the HTML 5 video tag."));
90         }
91         if (!$image) $image = $url;
92         if ($autoplay != 'true' and $autoplay != 'false')
93             return $this->error(fmt("Invalid argument %s", "autoplay"));
94         if (!is_numeric($width))
95             return $this->error(fmt("Invalid argument %s", "width"));
96         if (!is_numeric($height))
97             return $this->error(fmt("Invalid argument %s", "height"));
98         if (preg_match("/'/", $url))
99             return $this->error(fmt("Invalid argument %s", "url"));
100
101         $params = array("data" => SERVER_URL . $WikiTheme->_findData('flowplayer-3.1.3.swf'),
102                         "type"              => "application/x-shockwave-flash",
103                         "width"             => $width,
104                         "height"            => $height,
105                         "allowfullscreen"   => "true",
106                         "allowscriptaccess" => "false",
107                         "flashvars"=>
108                           "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}'");
109         return ImgObject(HTML::img(array('src' => $image)), $params);
110     }
111 };
112
113 // Local Variables:
114 // mode: php
115 // tab-width: 4
116 // c-basic-offset: 4
117 // c-hanging-comment-ender-p: nil
118 // indent-tabs-mode: nil
119 // End:
120 ?>