forked from kaltura/mwEmbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmwEmbedFrame.php
168 lines (154 loc) · 4.56 KB
/
mwEmbedFrame.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* mwEmbedFrame is a special stand alone page for iframe embed of mwEmbed modules
*
* For now we just support the embedPlayer
*
* This enables sharing mwEmbed player without js includes ie:
*
* <iframe src="mwEmbedFrame.php?src={SRC URL}&poster={POSTER URL}&width={WIDTH}etc"> </iframe>
*/
// Setup the mwEmbedFrame
$myMwEmbedFrame = new mwEmbedFrame();
// Do mwEmbedFrame output:
$myMwEmbedFrame->outputFrame();
/**
* mwEmbed iFrame class
*/
class mwEmbedFrame {
/**
* Variables set by the Frame request:
*/
var $playerAttributes = array(
'apiTitleKey',
'apiProvider',
'durationHint',
'poster',
'kentryid',
'kwidgetid',
'skin'
);
var $playerIframeId = 'iframeVid';
var $debug = false;
// When used in direct source mode the source asset.
// NOTE: can be an array of sources in cases of "many" sources set
var $sources = array();
function __construct(){
//parse input:
$this->parseRequest();
}
function outputFrame(){
// Presently only video frame supported:
$this->outputEmbedFrame();
}
// Parse the embedFrame request and sanitize input
private function parseRequest(){
// Check for attributes
foreach( $this->playerAttributes as $attributeKey){
if( isset( $_GET[ $attributeKey ] ) ){
$this->$attributeKey = htmlspecialchars( $_GET[$attributeKey] );
}
}
// Check for debug flag
if( isset( $_GET['debug'] ) ){
$this->debug = true;
}
// Process the special "src" attribute
if( isset( $_GET['src'] ) ){
if( is_array( $_GET['src'] ) ){
foreach($_GET['src'] as $src ){
$this->sources[] = htmlspecialchars( $src );
}
} else {
$this->sources = array( htmlspecialchars( $_GET['src'] ) );
}
}
}
private function getVideoTag( ){
// Add default video tag with 100% width / height
// ( parent embed is responsible for setting the iframe size )
$o = '<video id="' . htmlspecialchars( $this->playerIframeId ) . '" style="width:100%;height:100%"';
foreach( $this->playerAttributes as $attributeKey){
if( isset( $this->$attributeKey ) ){
$o.= ' ' . $attributeKey . '="' . htmlspecialchars( $this->$attributeKey ) . '"';
}
}
//Close the video attributes
$o.='>';
// Output each source
if( count( $this->sources ) ){
foreach($this->sources as $src ){
$o.= '<source src="' . htmlspecialchars( $src ) . '"></source>';
}
}
$o.= '</video>';
return $o;
}
private function outputEmbedFrame( ){
// Setup the embed string based on attribute set:
$embedResourceList = 'window.jQuery,mwEmbed,mw.style.mwCommon,$j.fn.menu,mw.style.jquerymenu,mw.EmbedPlayer,mw.EmbedPlayerNative,mw.EmbedPlayerJava,mw.PlayerControlBuilder,$j.fn.hoverIntent,mw.style.EmbedPlayer,$j.cookie,$j.ui,mw.style.ui_redmond,$j.widget,$j.ui.mouse,mw.PlayerSkinKskin,mw.style.PlayerSkinKskin,mw.TimedText,mw.style.TimedText,$j.ui.slider';
if( isset( $this->kentryid ) ){
$embedResourceList.= ',' . implode(',', array(
'KalturaClientBase',
'KalturaClient',
'KalturaAccessControlService',
'KalturaAccessControlOrderBy',
'KalturaAccessControl',
'MD5',
'mw.KWidgetSupport',
'mw.KAnalytics',
'mw.KDPMapping',
'mw.MobileAdTimeline',
'mw.KAds'
) );
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mwEmbed iframe</title>
<style type="text/css">
body {
margin:0;
position:fixed;
top:0px;
left:0px;
bottom:0px;
right:0px;
}
</style>
<script type="text/javascript" src="ResourceLoader.php?class=<?php
echo $embedResourceList;
if( $this->debug ){
echo '&debug=true';
}
?>"></script>
<script type="text/javascript">
//Set some iframe embed config:
// We can't support full screen in object context since it requires outter page DOM control
mw.setConfig( 'EmbedPlayer.EnableFullscreen', false );
// Enable the iframe player server:
mw.setConfig( 'EmbedPlayer.EnalbeIFramePlayerServer', true );
mw.ready(function(){
// Trigger fullscreen so that iframe resize keeps player size
$j( '#<?php echo htmlspecialchars( $this->playerIframeId )?>' )
.get(0).fullscreen();
});
</script>
</head>
<body>
<?php
// Check if we have a way to get sources:
if( isset( $this->apiTitleKey ) || isset( $this->kentryid ) || count( $this->sources ) != 0 ) {
echo $this->getVideoTag();
} else {
echo "Error: mwEmbedFrame missing required parameter for video sources";
}
?>
</body>
</html>
<?php
}
}
?>