forked from kaltura/mwEmbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmwEmbedLoader.php
110 lines (92 loc) · 4.26 KB
/
mwEmbedLoader.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
<?php
// Special mwEmbedLoader.js entry point with php based configuration
// ( will be deprecated once we move to new resource loader )
// Include configuration
require_once( realpath( dirname( __FILE__ ) ) . '/includes/DefaultSettings.php' );
// Kaltura Comment
$loaderComment = "'video audio source track'.replace(/\w+/g, function(n){ document.createElement(n); });
/**
* Kaltura HTML5 Library v$wgMwEmbedVersion
* Library Page http://www.kaltura.org/project/HTML5_Video_Media_JavaScript_Library
*
* Common configuration options see:
* http://html5video.org/wiki/Kaltura_SaaS_FAQ
*
* Whats in this version of Kaltura HTML5
* http://html5video.org/wiki/Kaltura_HTML5_Release_Notes
*
*/\n";
// Append ResourceLoder path to loader.js
$loaderJs = "window['SCRIPT_LOADER_URL'] = '". addslashes( $wgResourceLoaderUrl ) . "';\n";
// Add the library version:
$loaderJs .= "window['KALTURA_LOADER_VERSION'] = '$wgMwEmbedVersion';\n";
// Get resource ( kWidgetLoader.js )
$loaderJs .= file_get_contents( 'kWidgetLoader.js' );
// Get resource ( mwEmbedLoader.js )
$loaderJs .= file_get_contents( 'mwEmbedLoader.js' );
// Include checkUserAgentPlayer code
$loaderJs .= file_get_contents( 'modules/KalturaSupport/kdpPageJs/checkUserAgentPlayerRules.js' );
// Set up globals to be exported as mwEmbed config:
$exportedJsConfig= array(
'debug' => $wgEnableScriptDebug,
'Kaltura.UseManifestUrls' => $wgKalturaUseManifestUrls,
'Kaltura.Protocol' => $wgHTTPProtocol,
'Kaltura.ServiceUrl' => $wgKalturaServiceUrl,
'Kaltura.ServiceBase' => $wgKalturaServiceBase,
'Kaltura.CdnUrl' => $wgKalturaCDNUrl,
'Kaltura.StatsServiceUrl' => $wgKalturaStatsServiceUrl,
'Kaltura.IframeRewrite' => $wgKalturaIframeRewrite,
'EmbedPlayer.EnableIframeApi' => $wgEnableIframeApi,
'EmbedPlayer.EnableIpadHTMLControls' => $wgEnableIpadHTMLControls,
'EmbedPlayer.UseFlashOnAndroid' => true,
'Kaltura.LoadScriptForVideoTags' => true,
'Kaltura.AllowIframeRemoteService' => $wgKalturaAllowIframeRemoteService,
'Kaltura.UseAppleAdaptive' => $wgKalturaUseAppleAdaptive,
'Kaltura.EnableEmbedUiConfJs' => $wgKalturaEnableEmbedUiConfJs
);
// Append Custom config:
foreach( $exportedJsConfig as $key => $val ){
// @@TODO use a library Boolean conversion routine:
$val = ( $val === true )? $val = 'true' : $val;
$val = ( $val === false )? $val = 'false' : $val;
$val = ( $val != 'true' && $val != 'false' )? "'" . addslashes( $val ) . "'": $val;
$loaderJs .= "mw.setConfig('". addslashes( $key ). "', $val );\n";
}
header("Content-type: text/javascript");
if( isset( $_GET['debug'] ) || $wgEnableScriptDebug ){
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
echo $loaderComment . $loaderJs;
} else {
// Get the JSmin class:
require_once( realpath( dirname( __FILE__ ) ) . '/includes/library/JSMin.php' );
// Set the expire time for the loader to 5 min. ( it controls the version of the actual library payload )
$max_age = 60*5;
header("Cache-Control: private, max-age=$max_age max-stale=0");
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $max_age) . 'GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
// TODO Minify via php_min
// ob_gzhandler automatically checks for browser gzip support and gzips
ob_start("ob_gzhandler");
// Create cache directory if not exists
if( ! file_exists( $wgScriptCacheDirectory ) ) {
$created = @mkdir( $wgScriptCacheDirectory );
if( ! $created ) {
echo "if( console ){ console.log('Error in creating cache directory: ". $wgScriptCacheDirectory . "'); }";
}
}
$loaderCacheFile = $wgScriptCacheDirectory . '/loader_' . $wgHTTPProtocol . '.min.' . $wgMwEmbedVersion . '.js';
$javascriptModTime = @filemtime( 'mwEmbedLoader.js' );
$cacheModTime = @filemtime( $loaderCacheFile );
// check if there were any updates to the mwEmbedLoader file
if( is_file( $loaderCacheFile ) && $javascriptModTime < $cacheModTime ){
echo $loaderComment . file_get_contents( $loaderCacheFile );
} else {
$loaderMin = JSMin::minify( $loaderJs );
if( !@file_put_contents( $loaderCacheFile, $loaderMin ) ){
echo "if( console ){ console.log('Error in creating loader cache: ". $wgScriptCacheDirectory . "'); }";
}
echo $loaderComment . $loaderMin;
}
}