Update extension.json to version 2 with "updateExtensionJsonSchema.php".
[philipp/winterrodeln/mediawiki_extensions/wrvideo.git] / wrvideo.body.php
1 <?php
2 /* This extension embeds a video in a mediawiki page.
3 Currently vimeo is supported.
4
5
6 To embed the vimeo video
7 https://vimeo.com/104778486
8
9 the following HTML code has to be inserted into mediawiki:
10 <iframe src="//player.vimeo.com/video/104778486?byline=0&amp;portrait=0&amp;color=51735d" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
11
12 This extension allows this by the following tag:
13 <wrvideo id="104778486" />
14 <wrvideo id="104778486" width="500" height="281" />
15 */
16
17
18 // WrVideo
19 // -------
20
21 class WrVideo {
22         /// Renders the <video> tag.
23         /// @param $content string - the content of the <video> tag
24         /// @param $args array - the array of attribute name/value pairs for the tag
25         /// @param $parser Parser - the MW Parser object for the current page
26         ///
27         /// @return string - the html for rendering the map
28         public static function render($content, $args, $parser, $frame) {
29                 $parserOutput = $parser->getOutput();
30                 $parserOutput->addModules('ext.wrvideo');
31
32                 try {
33                         // default properties
34                         $properties = array('width' => 500, 'height' => 281);
35
36                         // video properties
37                         if (isset($args['id'])) $properties['id'] = (int) $args['id']; // video ID
38                         if (isset($args['width'])) $properties['width'] = (int) $args['width']; // width as int value
39                         if (isset($args['height'])) $properties['height'] = (int) $args['height']; // height as int value
40
41                         // verify properties
42                         if (!isset($properties['id'])) throw new Exception(wfMessage('wrvideo-error-no-id')->text());
43
44                         // build iframe
45                         $doc = new DOMDocument();
46                         $child = $doc->appendChild($doc->createElement('iframe'));
47                         $child->setAttribute('src', '//player.vimeo.com/video/' . $properties['id'] . '?byline=0&amp;portrait=0&amp;color=014e9a');
48                         $child->setAttribute('width', $properties['width']);
49                         $child->setAttribute('height', $properties['height']);
50                         $child->setAttribute('frameborder', 0);
51                         $child->setAttribute('webkitallowfullscreen', '');
52                         $child->setAttribute('mozallowfullscreen', '');
53                         $child->setAttribute('allowfullscreen', '');
54                 } catch (Exception $e) {
55                         $doc = new DOMDocument();
56                         $child = $doc->appendChild($doc->createElement('div'));
57                         $child->setAttribute('class', 'error');
58                         $child->appendChild($doc->createTextNode(wfMessage('wrvideo-error-msg')->text() . $e->getMessage()));
59                 }
60                 return array($doc->saveHTML($doc->firstChild), 'markerType' => 'nowiki');
61         }
62
63         public static function ParserFirstCallInitHook(Parser &$parser) {
64                 $parser->setHook('wrvideo', 'WrVideo::render');
65                 return true;
66         }
67
68 }
69
70 ?>