Implemented first version of <wrvideo> tag based on <wrmap> tag.
[philipp/winterrodeln/mediawiki_extensions/wrvideo.git] / wrvideo.body.php
1 <?php
2
3 // WrVideo
4 // -------
5
6 class WrVideo {
7         /// Renders the <video> tag.
8         /// @param $content string - the content of the <video> tag
9         /// @param $args array - the array of attribute name/value pairs for the tag
10         /// @param $parser Parser - the MW Parser object for the current page
11         ///
12         /// @return string - the html for rendering the map
13         public static function render($content, $args, $parser, $frame) {
14                 $parserOutput = $parser->getOutput();
15                 $parserOutput->addModules('ext.wrvideo');
16
17                 try {
18                         // default properties
19                         $properties = array('width' => 500, 'height' => 281);
20
21                         // video properties
22                         if (isset($args['id'])) $properties['id'] = (int) $args['id']; // video ID
23                         if (isset($args['width'])) $properties['width'] = (int) $args['width']; // width as int value
24                         if (isset($args['height'])) $properties['height'] = (int) $args['height']; // height as int value
25
26                         // verify properties
27                         if (!isset($properties['id'])) throw new Exception(wfMessage('wrvideo-error-no-id')->text());
28
29                         // build iframe
30                         $doc = new DOMDocument();
31                         $child = $doc->appendChild($doc->createElement('iframe'));
32                         $child->setAttribute('src', '//player.vimeo.com/video/' . $properties['id'] . '?byline=0&amp;portrait=0&amp;color=014e9a');
33                         $child->setAttribute('width', $properties['width']);
34                         $child->setAttribute('height', $properties['height']);
35                         $child->setAttribute('frameborder', 0);
36                         $child->setAttribute('webkitallowfullscreen', '');
37                         $child->setAttribute('mozallowfullscreen', '');
38                         $child->setAttribute('allowfullscreen', '');
39                 } catch (Exception $e) {
40                         $doc = new DOMDocument();
41                         $child = $doc->appendChild($doc->createElement('div'));
42                         $child->setAttribute('class', 'error');
43                         $child->appendChild($doc->createTextNode(wfMessage('wrvideo-error-msg')->text() . $e->getMessage()));
44                 }
45                 return array($doc->saveHTML($doc->firstChild), 'markerType' => 'nowiki');
46         }
47
48 }
49
50 ?>