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