Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / php / cortado_iframe.php
blob1ff30e22932d98a2154300659e7a7e7fcf440bb5
1 <?php
2 /*
3 cortado_embed.php
4 all file checks and conditions should be checked prior to loading this page.
5 this page serves as a wrapper for the cortado java applet
7 @@this may be deprecated in favor of a central hosted java applet
8 */
10 cortado_iframe();
12 function cortado_iframe() {
13 if( !function_exists( 'filter_input' ) ){
14 die( 'your version of PHP lacks <b>filter_input()</b> function<br />' );
17 // load the http GETS:
18 // set the parent domain if provided
19 $parent_domain = isset( $_GET['parent_domain'] ) ? $_GET['parent_domain'] : false;
21 // default to null media in not provided:
22 $media_url = isset( $_GET['media_url'] ) ? $_GET['media_url'] : false;
23 if( strval( $media_url ) === '' ){
24 error_out( 'invalid or missing media URL' );
27 // default duration to 30 seconds if not provided. (ideally cortado would read this from the video file)
28 //$duration = ( isset( $_GET['duration'] ) ) ? $_GET['duration'] : 0;
29 $duration = filter_input( INPUT_GET, 'duration', FILTER_SANITIZE_NUMBER_INT );
30 if( is_null( $duration ) || $duration === false ){
31 $duration = 0;
34 // id (set to random if none provided)
35 //$id = ( isset( $_GET['id'] ) ) ? $_GET['id'] : 'vid_' . rand( '10000000' );
36 $id = isset( $_GET['id'] ) ? $_GET['id'] : false;
37 if( is_null( $id ) || $id === false ){
38 $id = 'vid_' . rand( 0, 10000000 );
41 $width = filter_input( INPUT_GET, 'width', FILTER_SANITIZE_NUMBER_INT );
42 if( is_null( $width ) || $width === false ){
43 $width = 320;
45 $height = filter_input( INPUT_GET, 'height', FILTER_SANITIZE_NUMBER_INT );
46 // default to video:
47 $stream_type = ( isset( $_GET['stream_type'] ) ) ? $_GET['stream_type'] : 'video';
48 if( $stream_type == 'video' ){
49 $audio = $video = 'true';
50 if( is_null( $height ) || $height === false )
51 $height = 240;
52 } else { // if( $stream_type == 'audio' )
53 $audio = 'true';
54 $video = 'false';
55 if( is_null( $height ) || $height === false )
56 $height = 20;
59 // everything good output page:
60 output_page(array(
61 'id' => $id,
62 'media_url' => $media_url,
63 'audio' => $audio,
64 'video' => $video,
65 'duration' => $duration,
66 'width' => $width,
67 'height' => $height,
68 'parent_domain' => $parent_domain
69 ));
72 /**
73 * JS escape function copied from MediaWiki's Xml::escapeJsString()
75 function escapeJsString( $string ) {
76 // See ECMA 262 section 7.8.4 for string literal format
77 $pairs = array(
78 "\\" => "\\\\",
79 "\"" => "\\\"",
80 '\'' => '\\\'',
81 "\n" => "\\n",
82 "\r" => "\\r",
84 # To avoid closing the element or CDATA section
85 "<" => "\\x3c",
86 ">" => "\\x3e",
88 # To avoid any complaints about bad entity refs
89 "&" => "\\x26",
91 # Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152
92 # Encode certain Unicode formatting chars so affected
93 # versions of Gecko don't misinterpret our strings;
94 # this is a common problem with Farsi text.
95 "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER
96 "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
98 return strtr( $string, $pairs );
101 function error_out( $error = '' ){
102 output_page( array( 'error' => $error ) );
103 exit();
106 function output_page( $params ){
107 extract( $params );
108 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
109 <html xmlns="http://www.w3.org/1999/xhtml">
110 <head>
111 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
112 <title>cortado_embed</title>
113 <script type="text/javascript">
114 <?php //set the parent domain:
115 if( $parent_domain ){?>
116 try {
117 document.domain = '<?php echo htmlspecialchars( $parent_domain ) ?>';
118 } catch ( e ) {
119 if( window.console )
120 console.log('could not set domain to <?php echo htmlspecialchars( $parent_domain ) ?>');
122 <?php
123 } ?>
124 var jPlayer = null;
125 function setGlobalJplayer(){
126 jPlayer = document.getElementById('<?php echo htmlspecialchars( $id ) ?>');
128 </script>
129 <style type="text/css">
130 <!--
131 body {
132 margin-left: 0px;
133 margin-top: 0px;
134 margin-right: 0px;
135 margin-bottom: 0px;
138 </style></head>
139 <body onload="setGlobalJplayer()" >
140 <?php
141 $appid = ( preg_match( "/MSIE/i", getenv( "HTTP_USER_AGENT" ) ) ) ? '' : 'classid="java:com.fluendo.player.Cortado.class"';
142 if( empty( $error ) ){ ?>
143 <div id="jPlayer"></div>
144 <OBJECT id="<?php echo htmlspecialchars( $id ) ?>"
145 code="com.fluendo.player.Cortado.class"
146 <?php echo $appid ?>
147 archive="binPlayers/cortado/cortado-wmf-r46643.jar"
148 width="<?php echo htmlspecialchars( $width ) ?>"
149 height="<?php echo htmlspecialchars( $height ) ?>" >
150 <param name="url" value="<?php echo htmlspecialchars( $media_url ) ?>" />
151 <param name="local" value="false"/>
152 <param name="keepaspect" value="true" />
153 <param name="video" value="<?php echo htmlspecialchars( $video ) ?>" />
154 <param name="audio" value="<?php echo htmlspecialchars( $audio ) ?>" />
155 <param name="seekable" value="false" />
156 <?php if( $duration != 0 ){ ?>
157 <param name="duration" value="<?php echo htmlspecialchars( $duration ) ?>" />
158 <?php } ?>
159 <param name="showStatus" value="hide" />
160 <param name="autoPlay" value="true" />
161 <param name="BufferSize" value="8192" />
162 <param name="BufferHigh" value="30" />
163 <param name="BufferLow" value="5" />
164 </OBJECT>
165 <?php } else { ?>
166 <b>Error:</b> <?php echo htmlspecialchars( $error ) ?>
167 <?php
170 </body>
171 </html>
172 <?php
175 javascript envoked version:
176 function doPlayer(){
177 jPlayer = document.createElement('OBJECT');
178 jPlayer.setAttribute('classid', 'java:com.fluendo.player.Cortado.class');
179 jPlayer.type = 'application/x-java-applet';
180 jPlayer.setAttribute('archive', this.CortadoLocation);
181 jPlayer.id = '<?php echo htmlspecialchars( $id ) ?>';
182 jPlayer.width = '<?php echo htmlspecialchars( $width )?>';
183 jPlayer.height = '<?php echo htmlspecialchars( $height )?>';
185 var params = {
186 'code': 'com.fluendo.player.Cortado',
187 'archive': 'cortado-wmf-r46643.jar',
188 'url': '<?php echo htmlspecialchars( $media_url )?>',
189 'local': 'false',
190 'keepAspect': 'true',
191 'video': '<?php echo htmlspecialchars( $video )?>',
192 'audio': '<?php echo htmlspecialchars( $audio )?>',
193 'seekable': 'false',
194 'showStatus': 'hide',
195 'autoPlay': 'true',
196 'bufferSize': '8192',
197 'BufferHigh':'30',
198 'BufferLow' : '5',
199 <? if($duration!=0){
201 'duration':'<?php echo htmlspecialchars( $duration )?>',
203 } ?>
204 'debug': 0
206 for(name in params){
207 var p = document.createElement('param');
208 p.name = name;
209 p.value = params[name];
210 jPlayer.appendChild(p);
212 var pHolder = document.getElementById('jPlayer');
213 if(pHolder)
214 pHolder.appendChild( jPlayer );
216 doPlayer();
217 //then in the page:
218 <script type="text/javascript">
219 doPlayer();
220 </script>