Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 6 commits
  • 2 files changed
  • 0 comments
  • 2 contributors
68  podlove-web-player/podlove-chapters.js
... ...
@@ -1,31 +1,43 @@
1  
-function podlove_chapters (playerid){
2  
-	new MediaElement(playerid, {
3  
-		success: function (player) { 
  1
+var PODLOVE = PODLOVE || {};
4 2
 
5  
-			var list = 'table[rel='+playerid+']';
6  
-			jQuery(list).show();
  3
+PODLOVE.chapters = function (playerId) {
  4
+    MediaElement(playerId, {
  5
+        success: function (player) {
  6
+            PODLOVE.chapters.addBehaviour(playerId, player);
  7
+        }
  8
+    });
  9
+};
7 10
 
8  
-			jQuery(document).on('click', list+' a', function(){
9  
-			 player.setCurrentTime (jQuery(this).find('span').data('start'));
10  
-			 return false;
11  
-			});
  11
+PODLOVE.chapters.addBehaviour = function (playerId, player) {
  12
+    var list = jQuery('table[rel=' + playerId + ']')
  13
+        .show()
  14
+        .on('click', 'a', function () {
  15
+            var time = jQuery(this).find('span').data('start');
  16
+            player.setCurrentTime(time);
  17
+            player.play();
  18
+            return false;
  19
+        });
12 20
 
13  
-			player.addEventListener('timeupdate', function(e) {
14  
-				jQuery(list+' span').each(function(i){
15  
-					var mytr = jQuery(this).closest('tr');
16  
-					var curr = jQuery(this).data('start')
17  
-					var next = jQuery(this).data('end');
18  
-					if (player.currentTime > (curr - 0.3 ) && player.currentTime <= (next) ) {
19  
-						if (!jQuery(mytr).hasClass('active')) {
20  
-							jQuery(this).closest('table').find('tr.active').removeClass('active');
21  
-							jQuery(mytr).addClass('active');
22  
-						}
23  
-					}
24  
-					if (jQuery(this).data('buffered') == '0' && player.buffered.end(0) > curr) {
25  
-						jQuery(this).data('buffered', '1').wrap('<a href="#"></a>');
26  
-					}        
27  
-				});
28  
-			}, false);
29  
-	 	}
30  
-	});
31  
-}
  21
+    player.addEventListener('timeupdate', function (e) {
  22
+        list.find('span').each(function (i) {
  23
+            var span = jQuery(this),
  24
+                row = span.closest('tr'),
  25
+                startTime = span.data('start'),
  26
+                endTime = span.data('end'),
  27
+                isEnabled = span.data('enabled') === '1',
  28
+                isBuffered = player.buffered.end(0) > startTime,
  29
+                isActive = player.currentTime > startTime - 0.3 &&
  30
+                        player.currentTime <= endTime;
  31
+
  32
+            if (isActive && !row.hasClass('active')) {
  33
+                span.closest('table')
  34
+                    .find('tr.active')
  35
+                    .removeClass('active');
  36
+                row.addClass('active');
  37
+            }
  38
+            if (!isEnabled && isBuffered) {
  39
+                span.data('enabled', '1').wrap('<a href="#"></a>');
  40
+            }
  41
+        });
  42
+    }, false);
  43
+};
1,072  podlove-web-player/podlove-web-player.php
... ...
@@ -1,542 +1,530 @@
1  
-<?php
2  
-/**
3  
- * @package PodloveWebPlayer
4  
- * @version 0.9
5  
- */
6  
- 
7  
-/*
8  
-Plugin Name: Podlove Web Player
9  
-Plugin URI: http://podlove.org/podlove-web-player/
10  
-Description: 
11  
-Author: Gerrit van Aaken
12  
-Version: 0.9
13  
-Author URI: http://praegnanz.de
14  
-License: GPLv3, MIT
15  
-*/
16  
-
17  
-/*
18  
-Forked from: http://mediaelementjs.com/ plugin
19  
-which was adapted from: http://videojs.com/ plugin
20  
-*/
21  
-
22  
-$podlovePlayerIndex = 1;
23  
-define('MEDIAELEMENTJS_DIR', plugin_dir_url(__FILE__).'mediaelement/');
24  
-
25  
-/* Runs when plugin is activated */
26  
-register_activation_hook(__FILE__,'mejs_install'); 
27  
-
28  
-function mejs_install() {
29  
-	add_option('mep_video_skin', '');
30  
-	add_option('mep_script_on_demand', false);
31  
-	
32  
-	add_option('mep_default_video_height', 270);
33  
-	add_option('mep_default_video_width', 480);
34  
-	add_option('mep_default_video_type', '');
35  
-	
36  
-	add_option('mep_default_audio_height', 30);
37  
-	add_option('mep_default_audio_width', 400);
38  
-	add_option('mep_default_audio_type', '');
39  
-}
40  
-
41  
-/* Runs on plugin deactivation*/
42  
-register_deactivation_hook( __FILE__, 'mejs_remove' );
43  
-function mejs_remove() {
44  
-	delete_option('mep_video_skin');
45  
-	delete_option('mep_script_on_demand');
46  
-
47  
-	delete_option('mep_default_video_height');
48  
-	delete_option('mep_default_video_width');
49  
-	delete_option('mep_default_video_type');  
50  
-
51  
-	delete_option('mep_default_audio_height');
52  
-	delete_option('mep_default_audio_width');
53  
-	delete_option('mep_default_audio_type');
54  
-}
55  
-
56  
-// create custom plugin settings menu
57  
-add_action('admin_menu', 'mejs_create_menu');
58  
-
59  
-function mejs_create_menu() {
60  
-
61  
-	//create new top-level menu
62  
-	add_options_page('Podlove Web Player Options', 'Podlove Player', 'administrator', __FILE__, 'mejs_settings_page');
63  
-
64  
-	//call register settings function
65  
-	add_action( 'admin_init', 'mejs_register_settings' );
66  
-}
67  
-
68  
-
69  
-function mejs_register_settings() {
70  
-	//register our settings
71  
-	register_setting( 'mep_settings', 'mep_video_skin' );
72  
-	register_setting( 'mep_settings', 'mep_script_on_demand' );
73  
-	
74  
-	register_setting( 'mep_settings', 'mep_default_video_height' );
75  
-	register_setting( 'mep_settings', 'mep_default_video_width' );
76  
-	register_setting( 'mep_settings', 'mep_default_video_type' );
77  
-
78  
-	register_setting( 'mep_settings', 'mep_default_audio_height' );
79  
-	register_setting( 'mep_settings', 'mep_default_audio_width' );
80  
-	register_setting( 'mep_settings', 'mep_default_audio_type' );
81  
-}
82  
-
83  
-
84  
-function mejs_settings_page() {
85  
-?>
86  
-<div class="wrap">
87  
-<h2>Podlove Web Player Options</h2>
88  
-
89  
-<p>See <a href="http://mediaelementjs.com/">MediaElementjs.com</a> for more details on how the HTML5 player and Flash fallbacks work.</p>
90  
-
91  
-<form method="post" action="options.php">
92  
-<?php wp_nonce_field('update-options'); ?>
93  
-
94  
-	<h3 class="title"><span>General Settings</span></h3>
95  
-
96  
-	<table  class="form-table">
97  
-		<tr valign="top">
98  
-			<th scope="row">
99  
-				<label for="mep_script_on_demand">Load Script on Demand</label>
100  
-			</th>
101  
-			<td >
102  
-				<input name="mep_script_on_demand" type="checkbox" id="mep_script_on_demand" <?php echo (get_option('mep_script_on_demand') == true ? "checked" : "")  ?> />
103  
-			</td>
104  
-		</tr>
105  
-	</table>
106  
-
107  
-	<h3 class="title"><span>Video Settings</span></h3>
108  
-		
109  
-	<table  class="form-table">
110  
-		<tr valign="top">
111  
-			<th scope="row">
112  
-				<label for="mep_default_video_width">Default Width</label>
113  
-			</th>
114  
-			<td >
115  
-				<input name="mep_default_video_width" type="text" id="mep_default_video_width" value="<?php echo get_option('mep_default_video_width'); ?>" />
116  
-			</td>
117  
-		</tr>
118  
-		<tr valign="top">
119  
-			<th scope="row">
120  
-				<label for="mep_default_video_height">Default Height</label>
121  
-			</th>
122  
-			<td >
123  
-				<input name="mep_default_video_height" type="text" id="mep_default_video_height" value="<?php echo get_option('mep_default_video_height'); ?>" />
124  
-			</td>
125  
-		</tr> 
126  
-		<tr valign="top">
127  
-			<th scope="row">
128  
-				<label for="mep_default_video_type">Default Type</label>
129  
-			</th>
130  
-			<td >
131  
-				<input name="mep_default_video_type" type="text" id="mep_default_video_type" value="<?php echo get_option('mep_default_video_type'); ?>" /> <span class="description">such as "video/mp4"</span>
132  
-			</td>
133  
-		</tr> 
134  
-		<tr valign="top">
135  
-			<th scope="row">
136  
-				<label for="mep_video_skin">Video Skin</label>
137  
-			</th>
138  
-			<td >
139  
-				<select name="mep_video_skin" id="mep_video_skin">
140  
-					<option value="" <?php echo (get_option('mep_video_skin') == '') ? ' selected' : ''; ?>>Default</option>
141  
-					<option value="wmp" <?php echo (get_option('mep_video_skin') == 'wmp') ? ' selected' : ''; ?>>WMP</option>
142  
-					<option value="ted" <?php echo (get_option('mep_video_skin') == 'ted') ? ' selected' : ''; ?>>TED</option>
143  
-				</select>
144  
-			</td>
145  
-		</tr>          
146  
-	</table>
147  
-
148  
-	<h3 class="title"><span>Audio Settings</span></h3>
149  
-	
150  
-
151  
-	<table  class="form-table">
152  
-		<tr valign="top">
153  
-		<tr valign="top">
154  
-			<th scope="row">
155  
-				<label for="mep_default_audio_width">Default Width</label>
156  
-			</th>
157  
-			<td >
158  
-				<input name="mep_default_audio_width" type="text" id="mep_default_audio_width" value="<?php echo get_option('mep_default_audio_width'); ?>" />
159  
-			</td>
160  
-		</tr>
161  
-		<tr valign="top">
162  
-			<th scope="row">
163  
-				<label for="mep_default_audio_height">Default Height</label>
164  
-			</th>
165  
-			<td >
166  
-				<input name="mep_default_audio_height" type="text" id="mep_default_audio_height" value="<?php echo get_option('mep_default_audio_height'); ?>" />
167  
-			</td>
168  
-		</tr>       
169  
-			<th scope="row">
170  
-				<label for="mep_default_audio_type">Default Type</label>
171  
-			</th>
172  
-			<td >
173  
-				<input name="mep_default_audio_type" type="text" id="mep_default_audio_type" value="<?php echo get_option('mep_default_audio_type'); ?>" /> <span class="description">such as "audio/mp3"</span>
174  
-			</td>
175  
-		</tr>       
176  
-	</table>
177  
-
178  
-	<input type="hidden" name="action" value="update" />
179  
-	<input type="hidden" name="page_options" value="mep_default_video_width,mep_default_video_height,mep_default_video_type,mep_default_audio_type,mep_default_audio_width,mep_default_audio_height,mep_video_skin,mep_script_on_demand" />
180  
-
181  
-	<p>
182  
-		<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
183  
-	</p>
184  
-
185  
-</div>
186  
-
187  
-
188  
-
189  
-</form>
190  
-</div>
191  
-<?php
192  
-}
193  
-
194  
-
195  
-// Javascript
196  
-
197  
-// This is now handled by calling wp_enqueue_script inside the mejs_media_shortcode function by default. This means that MediaElement.js's JavaScript will only be called as needed
198  
-if (!get_option('mep_script_on_demand')) {
199  
-function mejs_add_scripts(){
200  
-	if (!is_admin()){
201  
-		// the scripts
202  
-		wp_enqueue_script("podlove-scripts", MEDIAELEMENTJS_DIR ."mediaelement-and-player.min.js", array('jquery'), "2.7.1", false);
203  
-		wp_enqueue_script("podlove-chapters", plugin_dir_url(__FILE__) ."podlove-chapters.js", array('jquery'), "2.7.1", false);
204  
-	}
205  
-}
206  
-add_action('wp_print_scripts', 'mejs_add_scripts');
207  
-}
208  
-
209  
-// CSS
210  
-// still always enqueued so it happens in the <head> tag
211  
-function mejs_add_styles(){
212  
-	 if (!is_admin()){
213  
-			// the style
214  
-			wp_enqueue_style("mediaelementjs-styles", MEDIAELEMENTJS_DIR ."mediaelementplayer.css");
215  
-			
216  
-			if (get_option('mep_video_skin') != '') {
217  
-			wp_enqueue_style("mediaelementjs-skins", MEDIAELEMENTJS_DIR ."mejs-skins.css");
218  
-		}
219  
-	 }
220  
-}
221  
-add_action('wp_print_styles', 'mejs_add_styles');
222  
-
223  
-function podlove_media_shortcode($tagName, $atts){
224  
-
225  
-	
226  
-	// only enqueue when needed
227  
-	if (get_option('mep_script_on_demand')) {
228  
-		wp_enqueue_script("mediaelementjs-scripts", MEDIAELEMENTJS_DIR ."mediaelement-and-player.min.js", array('jquery'), "2.7.0", false);
229  
-	}  
230  
-
231  
-	global $podlovePlayerIndex; 
232  
-	$dir = MEDIAELEMENTJS_DIR;
233  
-	$attributes = array();
234  
-	$sources = array();
235  
-	$options = array();
236  
-	$flash_src = '';
237  
-
238  
-	extract(shortcode_atts(array(
239  
-		'src' => '',  
240  
-		'mp4' => '',
241  
-		'mp3' => '',
242  
-		'wmv' => '',    
243  
-		'webm' => '',
244  
-		'flv' => '',
245  
-		'ogg' => '',
246  
-		'poster' => '',
247  
-		'width' => get_option('mep_default_'.$tagName.'_width'),
248  
-		'height' => get_option('mep_default_'.$tagName.'_height'),
249  
-		'type' => get_option('mep_default_'.$tagName.'_type'),
250  
-		'preload' => 'none',
251  
-		'skin' => get_option('mep_video_skin'),
252  
-		'autoplay' => '',
253  
-		'loop' => '',
254  
-		
255  
-		// old ones
256  
-		'duration' => 'true',
257  
-		'progress' => 'true',
258  
-		'fullscreen' => 'true',
259  
-		'volume' => 'true',
260  
-		
261  
-		// captions
262  
-		'captions' => '',
263  
-		'captionslang' => 'en',
264  
-
265  
-		// chapters
266  
-		'chapters' => ''
267  
-
268  
-	), $atts));
269  
-
270  
-	if ($type) {
271  
-		$attributes[] = 'type="'.$type.'"';
272  
-	}
273  
-
274  
-/*
275  
-	if ($src) {
276  
-		$attributes[] = 'src="'.htmlspecialchars($src).'"';
277  
-		$flash_src = htmlspecialchars($src);
278  
-	}
279  
-*/
280  
-
281  
-	if ($src) {
282  
-	
283  
-		// does it have an extension?
284  
-		if (substr($src, strlen($src)-4, 1)=='.') {
285  
-			$attributes[] = 'src="'.htmlspecialchars($src).'"';
286  
-			$flash_src = htmlspecialchars($src);
287  
-		} else {
288  
-			
289  
-			// for missing extension, we try to find all possible files in the system
290  
-			
291  
-			if (substr($src, 0, 4)!='http') 
292  
-				$filename = WP_CONTENT_DIR . substr($src, strlen(WP_CONTENT_DIR)-strrpos(WP_CONTENT_DIR, '/'));
293  
-			else 
294  
-				$filename = WP_CONTENT_DIR . substr($src, strlen(WP_CONTENT_URL));
295  
-
296  
-			if ($tagName == 'video') {
297  
-				// MP4
298  
-				if (file_exists($filename.'.mp4')) {
299  
-					$mp4=$src.'.mp4';
300  
-				} elseif (file_exists($filename.'.m4v')) {
301  
-					$mp4=$src.'.m4v';
302  
-				}
303  
-
304  
-				// WEBM
305  
-				if (file_exists($filename.'.webm')) {
306  
-					$webm=$src.'.webm';
307  
-				}
308  
-
309  
-				// OGG
310  
-				if (file_exists($filename.'.ogg')) {
311  
-					$ogg=$src.'.ogg';
312  
-				} elseif (file_exists($filename.'.ogv')) {
313  
-					$ogg=$src.'.ogv';
314  
-				}
315  
-
316  
-				// FLV
317  
-				if (file_exists($filename.'.flv')) {
318  
-					$flv=$src.'.flv';
319  
-				}
320  
-
321  
-				// WMV
322  
-				if (file_exists($filename.'.wmv')) {
323  
-					$wmv=$src.'.wmv';
324  
-				}           
325  
-				
326  
-				// POSTER
327  
-				if (file_exists($filename.'.jpg')) {
328  
-					$poster=$src.'.jpg';
329  
-				}
330  
-				
331  
-			} elseif ($tagName == 'audio') {
332  
-				
333  
-				// MP3
334  
-				if (file_exists($filename.'.mp3')) {
335  
-					$mp3=$src.'.mp3';
336  
-				}
337  
-				
338  
-				// OGG
339  
-				if (file_exists($filename.'.ogg')) {
340  
-					$ogg=$src.'.ogg';
341  
-				} elseif (file_exists($filename.'.oga')) {
342  
-					$ogg=$src.'.oga';
343  
-				}           
344  
-				
345  
-			}
346  
-		}
347  
-	}  
348  
-	
349  
-	// <source> tags
350  
-	if ($mp4) {
351  
-		$sources[] = '<source src="'.htmlspecialchars($mp4).'" type="'.$tagName.'/mp4" />';
352  
-		$flash_src = htmlspecialchars($mp4);
353  
-	}
354  
-	if ($mp3) {
355  
-		$sources[] = '<source src="'.htmlspecialchars($mp3).'" type="'.$tagName.'/mp3" />';
356  
-		$flash_src = htmlspecialchars($mp3);
357  
-	}
358  
-	if ($webm) {
359  
-		$sources[] = '<source src="'.htmlspecialchars($webm).'" type="'.$tagName.'/webm" />';
360  
-	}
361  
-	if ($ogg) {
362  
-		$sources[] = '<source src="'.htmlspecialchars($ogg).'" type="'.$tagName.'/ogg" />';
363  
-	}
364  
-	if ($flv) {
365  
-		$sources[] = '<source src="'.htmlspecialchars($flv).'" type="'.$tagName.'/flv" />';
366  
-	}
367  
-	if ($wmv) {
368  
-		$sources[] = '<source src="'.htmlspecialchars($wmv).'" type="'.$tagName.'/wmv" />';
369  
-	}  
370  
-	if ($captions) {
371  
-		$sources[] = '<track src="'.$captions.'" kind="subtitles" srclang="'.$captionslang.'" />';
372  
-	}  
373  
-
374  
-	// <audio|video> attributes
375  
-	if ($width && $tagName == 'video') {
376  
-		$attributes[] = 'width="'.$width.'"';
377  
-	}
378  
-	if ($height && $tagName == 'video') {
379  
-		$attributes[] = 'height="'.$height.'"';
380  
-	}    
381  
-	if ($poster) {
382  
-		$attributes[] = 'poster="'.htmlspecialchars($poster).'"';
383  
-	}
384  
-	if ($preload) {
385  
-		$attributes[] = 'preload="'.$preload.'"';
386  
-	}
387  
-	if ($autoplay) {
388  
-		$attributes[] = 'autoplay="'.$autoplay.'"';
389  
-	}
390  
-
391  
-	// MEJS JavaScript options
392  
-	if ($loop) {
393  
-		$options[]  = 'loop: ' . $loop;
394  
-	}
395  
-
396  
-	// CONTROLS array
397  
-	$controls_option[] = '"playpause"';
398  
-	if ($progress == 'true') {
399  
-		$controls_option[] = '"current"';
400  
-		$controls_option[] = '"progress"';
401  
-	}
402  
-	if ($duration == 'true') {
403  
-		$controls_option[] = '"duration"';
404  
-	}
405  
-	if ($volume == 'true') {
406  
-		$controls_option[] = '"volume"';
407  
-	}
408  
-	$controls_option[] = '"tracks"';
409  
-	if ($fullscreen == 'true') {
410  
-		$controls_option[] = '"fullscreen"';      
411  
-	}
412  
-
413  
-	$options[] = '"features":[' . implode(',', $controls_option).']';
414  
-
415  
-	// <audio> size
416  
-	if ($tagName == 'audio') {
417  
-		$options[] = '"audioWidth":'.$width;
418  
-		$options[] = '"audioHeight":'.$height;
419  
-	}
420  
-	
421  
-	// <video> class (skin)
422  
-	$skin_class = '';
423  
-	if ($skin != '') {
424  
-		$skin_class  = 'mejs-' . $skin;
425  
-	}
426  
-	
427  
-	// BUILD HTML
428  
-	$attributes_string = !empty($attributes) ? implode(' ', $attributes) : '';
429  
-	$sources_string = !empty($sources) ? implode("\n\t\t", $sources) : '';
430  
-	$options_string = !empty($options) ? '{' . implode(',', $options) . '}' : '';
431  
-
432  
-	$mediahtml = <<<_end_
433  
-	<{$tagName} id="wp_mep_{$podlovePlayerIndex}" controls="controls" {$attributes_string} class="mejs-player {$skin_class}" data-mejsoptions='{$options_string}'>
434  
-		{$sources_string}
435  
-		<object width="{$width}" height="{$height}" type="application/x-shockwave-flash" data="{$dir}flashmediaelement.swf">
436  
-			<param name="movie" value="{$dir}flashmediaelement.swf" />
437  
-			<param name="flashvars" value="controls=true&amp;file={$flash_src}" />        
438  
-		</object>      
439  
-	</{$tagName}>
440  
-_end_;
441  
-
442  
-	
443  
-	// Chapters Table and Behaviour
444  
-	if ($chapters) {
445  
-		$mediahtml .= "\n\n".podlove_render_chapters($chapters);
446  
-		$mediahtml .= "\n\n<script>podlove_chapters('wp_mep_{$podlovePlayerIndex}');</script>\n";
447  
-	}
448  
-
449  
-	$podlovePlayerIndex++;
450  
-	return $mediahtml;
451  
-}
452  
-
453  
-
454  
-function podlove_render_chapters($custom_field){
455  
-	global $post;
456  
-	global $podlovePlayerIndex;
457  
-	
458  
-	if ($custom_field != "" && $chapters = get_post_custom_values($custom_field, $post->ID)) {
459  
-		$chapters = podlove_chapters_from_string ($chapters[0]);
460  
-		
461  
-		//echo "<pre>";
462  
-		//var_dump ($chapters);
463  
-		//echo "</pre>";
464  
-	
465  
-		$output .= '<table rel="wp_mep_'.$podlovePlayerIndex.'" class="mejs_chapters" style="display:none"><tbody>';
466  
-		foreach($chapters as $i => $chapter) {
467  
-			if ($i == (count($chapters)-1)) {
468  
-				$end = "9999999";
469  
-			} else {
470  
-				$end = $chapters[$i+1]['timecode'];
471  
-			}
472  
-			$output .= '<tr>';
473  
-			$output .= '<td class="timecode"><code>'.$chapter['human_timecode'].'</code></td>';
474  
-			$output .= '<td class="title"><span data-buffered="0" data-start="'.$chapter['timecode'].'" data-end="'.$end.'">'.$chapter['title'].'</span></td>';
475  
-			$output .= '</tr>';
476  
-		}
477  
-		$output .= "</tbody></table>";
478  
-		
479  
-		
480  
-		return $output;
481  
-	} else {
482  
-		return false;
483  
-	}
484  
-}
485  
-
486  
-function podlove_chapters_from_string ($chapstring) {
487  
-	$lines = explode("\n", $chapstring);
488  
-	foreach ($lines as $i => $line) {
489  
-		 if (trim($line) != "") {
490  
-			$line = trim(str_replace("\n", "", $line));
491  
-			$div = stripos($line, " ");
492  
-			$chapters[$i]['title'] = trim(substr($line, $div+1));
493  
-			
494  
-			$time = trim(substr($line, 0, $div));
495  
-			$chapters[$i]['human_timecode'] = substr($time,0,8);
496  
-			$hours = substr($time, 0, 2);
497  
-			$mins = substr($time, 3, 2);
498  
-			$secs = substr($time, 6, 2);
499  
-			if (count(substr($time, 9, 1))) {
500  
-				$msecs = substr($time, 9, 3);
501  
-			} else {
502  
-				$msecs = 0;
503  
-			}
504  
-			$chapters[$i]['timecode'] = (($hours*3600) + ($mins*60) + ($secs*1)) . "." . floor($msecs);
505  
-			$chapters[$i]['hours'] = $hours;
506  
-			$chapters[$i]['minutes'] = $mins;
507  
-			$chapters[$i]['seconds'] = $secs;
508  
-			$chapters[$i]['milliseconds'] = $msecs;
509  
-		}
510  
-	}
511  
-	if ($chapters[$i]['hours'] == "00") {
512  
-		foreach ($chapters as $i => $chapter) {
513  
-			$chapters[$i]['human_timecode'] = substr($chapter['human_timecode'], 3);
514  
-		}
515  
-	}
516  
-	return $chapters;
517  
-}
518  
-
519  
-
520  
-
521  
-function podlove_audio_shortcode($atts){
522  
-	if (is_feed()) return "";
523  
-	return podlove_media_shortcode('audio',$atts);
524  
-}
525  
-function podlove_video_shortcode($atts){
526  
-	if (is_feed()) return "";
527  
-	return podlove_media_shortcode('video',$atts);
528  
-}
529  
-
530  
-add_shortcode('audio', 'podlove_audio_shortcode');
531  
-add_shortcode('podloveaudio', 'podlove_audio_shortcode');
532  
-add_shortcode('video', 'podlove_video_shortcode');
533  
-add_shortcode('podlovevideo', 'podlove_video_shortcode');   
534  
-
535  
-function podlove_init() {
536  
-	wp_enqueue_script( 'jquery' );
537  
-}    
538  
- 
539  
-add_action('init', 'podlove_init');
540  
-
541  
-	
542  
-?>
  1
+<?php
  2
+/**
  3
+ * @package PodloveWebPlayer
  4
+ * @version 0.9
  5
+ */
  6
+
  7
+/*
  8
+Plugin Name: Podlove Web Player
  9
+Plugin URI: http://podlove.org/podlove-web-player/
  10
+Description:
  11
+Author: Gerrit van Aaken
  12
+Version: 0.9
  13
+Author URI: http://praegnanz.de
  14
+License: GPLv3, MIT
  15
+*/
  16
+
  17
+/*
  18
+Forked from: http://mediaelementjs.com/ plugin
  19
+which was adapted from: http://videojs.com/ plugin
  20
+*/
  21
+
  22
+$podlovePlayerIndex = 1;
  23
+define('MEDIAELEMENTJS_DIR', plugin_dir_url(__FILE__) . 'mediaelement/');
  24
+
  25
+/* Runs when plugin is activated */
  26
+register_activation_hook(__FILE__, 'mejs_install');
  27
+
  28
+function mejs_install() {
  29
+    add_option('mep_video_skin', '');
  30
+    add_option('mep_script_on_demand', false);
  31
+
  32
+    add_option('mep_default_video_height', 270);
  33
+    add_option('mep_default_video_width', 480);
  34
+    add_option('mep_default_video_type', '');
  35
+
  36
+    add_option('mep_default_audio_height', 30);
  37
+    add_option('mep_default_audio_width', 400);
  38
+    add_option('mep_default_audio_type', '');
  39
+}
  40
+
  41
+/* Runs on plugin deactivation*/
  42
+register_deactivation_hook(__FILE__, 'mejs_remove');
  43
+
  44
+function mejs_remove() {
  45
+    delete_option('mep_video_skin');
  46
+    delete_option('mep_script_on_demand');
  47
+
  48
+    delete_option('mep_default_video_height');
  49
+    delete_option('mep_default_video_width');
  50
+    delete_option('mep_default_video_type');
  51
+
  52
+    delete_option('mep_default_audio_height');
  53
+    delete_option('mep_default_audio_width');
  54
+    delete_option('mep_default_audio_type');
  55
+}
  56
+
  57
+// create custom plugin settings menu
  58
+add_action('admin_menu', 'mejs_create_menu');
  59
+
  60
+function mejs_create_menu() {
  61
+    //create new top-level menu
  62
+    add_options_page('Podlove Web Player Options', 'Podlove Player', 'administrator', __FILE__, 'mejs_settings_page');
  63
+
  64
+    //call register settings function
  65
+    add_action( 'admin_init', 'mejs_register_settings' );
  66
+}
  67
+
  68
+
  69
+function mejs_register_settings() {
  70
+    //register our settings
  71
+    register_setting('mep_settings', 'mep_video_skin');
  72
+    register_setting('mep_settings', 'mep_script_on_demand');
  73
+
  74
+    register_setting('mep_settings', 'mep_default_video_height');
  75
+    register_setting('mep_settings', 'mep_default_video_width');
  76
+    register_setting('mep_settings', 'mep_default_video_type');
  77
+
  78
+    register_setting('mep_settings', 'mep_default_audio_height');
  79
+    register_setting('mep_settings', 'mep_default_audio_width');
  80
+    register_setting('mep_settings', 'mep_default_audio_type');
  81
+}
  82
+
  83
+
  84
+function mejs_settings_page() {
  85
+?>
  86
+<div class="wrap">
  87
+<h2>Podlove Web Player Options</h2>
  88
+
  89
+<p>See <a href="http://mediaelementjs.com/">MediaElementjs.com</a> for more details on how the HTML5 player and Flash fallbacks work.</p>
  90
+
  91
+<form method="post" action="options.php">
  92
+<?php wp_nonce_field('update-options'); ?>
  93
+
  94
+
  95
+    <h3 class="title"><span>General Settings</span></h3>
  96
+
  97
+    <table class="form-table">
  98
+        <tr valign="top">
  99
+            <th scope="row">
  100
+                <label for="mep_script_on_demand">Load Script on Demand</label>
  101
+            </th>
  102
+            <td >
  103
+                <input name="mep_script_on_demand" type="checkbox" id="mep_script_on_demand" <?php echo (get_option('mep_script_on_demand') == true ? "checked" : "")  ?> />
  104
+            </td>
  105
+        </tr>
  106
+    </table>
  107
+
  108
+
  109
+    <h3 class="title"><span>Video Settings</span></h3>
  110
+
  111
+    <table class="form-table">
  112
+        <tr valign="top">
  113
+            <th scope="row">
  114
+                <label for="mep_default_video_width">Default Width</label>
  115
+            </th>
  116
+            <td >
  117
+                <input name="mep_default_video_width" type="text" id="mep_default_video_width" value="<?php echo get_option('mep_default_video_width'); ?>" />
  118
+            </td>
  119
+        </tr>
  120
+        <tr valign="top">
  121
+            <th scope="row">
  122
+                <label for="mep_default_video_height">Default Height</label>
  123
+            </th>
  124
+            <td >
  125
+                <input name="mep_default_video_height" type="text" id="mep_default_video_height" value="<?php echo get_option('mep_default_video_height'); ?>" />
  126
+            </td>
  127
+        </tr> 
  128
+        <tr valign="top">
  129
+            <th scope="row">
  130
+                <label for="mep_default_video_type">Default Type</label>
  131
+            </th>
  132
+            <td >
  133
+                <input name="mep_default_video_type" type="text" id="mep_default_video_type" value="<?php echo get_option('mep_default_video_type'); ?>" /> <span class="description">such as "video/mp4"</span>
  134
+            </td>
  135
+        </tr> 
  136
+        <tr valign="top">
  137
+            <th scope="row">
  138
+                <label for="mep_video_skin">Video Skin</label>
  139
+            </th>
  140
+            <td >
  141
+                <select name="mep_video_skin" id="mep_video_skin">
  142
+                    <option value="" <?php echo (get_option('mep_video_skin') == '') ? ' selected' : ''; ?>>Default</option>
  143
+                    <option value="wmp" <?php echo (get_option('mep_video_skin') == 'wmp') ? ' selected' : ''; ?>>WMP</option>
  144
+                    <option value="ted" <?php echo (get_option('mep_video_skin') == 'ted') ? ' selected' : ''; ?>>TED</option>
  145
+                </select>
  146
+            </td>
  147
+        </tr>
  148
+    </table>
  149
+
  150
+
  151
+    <h3 class="title"><span>Audio Settings</span></h3>
  152
+
  153
+    <table class="form-table">
  154
+        <tr valign="top">
  155
+        <tr valign="top">
  156
+            <th scope="row">
  157
+                <label for="mep_default_audio_width">Default Width</label>
  158
+            </th>
  159
+            <td >
  160
+                <input name="mep_default_audio_width" type="text" id="mep_default_audio_width" value="<?php echo get_option('mep_default_audio_width'); ?>" />
  161
+            </td>
  162
+        </tr>
  163
+        <tr valign="top">
  164
+            <th scope="row">
  165
+                <label for="mep_default_audio_height">Default Height</label>
  166
+            </th>
  167
+            <td >
  168
+                <input name="mep_default_audio_height" type="text" id="mep_default_audio_height" value="<?php echo get_option('mep_default_audio_height'); ?>" />
  169
+            </td>
  170
+        </tr>
  171
+            <th scope="row">
  172
+                <label for="mep_default_audio_type">Default Type</label>
  173
+            </th>
  174
+            <td >
  175
+                <input name="mep_default_audio_type" type="text" id="mep_default_audio_type" value="<?php echo get_option('mep_default_audio_type'); ?>" /> <span class="description">such as "audio/mp3"</span>
  176
+            </td>
  177
+        </tr>
  178
+    </table>
  179
+
  180
+    <input type="hidden" name="action" value="update" />
  181
+    <input type="hidden" name="page_options" value="mep_default_video_width,mep_default_video_height,mep_default_video_type,mep_default_audio_type,mep_default_audio_width,mep_default_audio_height,mep_video_skin,mep_script_on_demand" />
  182
+
  183
+    <p>
  184
+        <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  185
+    </p>
  186
+
  187
+</div>
  188
+
  189
+
  190
+
  191
+</form>
  192
+</div>
  193
+<?php
  194
+}
  195
+
  196
+
  197
+// Javascript
  198
+
  199
+// This is now handled by calling wp_enqueue_script inside the mejs_media_shortcode function by default. This means that MediaElement.js's JavaScript will only be called as needed
  200
+if (!get_option('mep_script_on_demand')) {
  201
+function mejs_add_scripts() {
  202
+    if (!is_admin()) {
  203
+        // the scripts
  204
+        wp_enqueue_script('podlove-scripts', MEDIAELEMENTJS_DIR . 'mediaelement-and-player.min.js', array('jquery'), '2.7.1', false);
  205
+        wp_enqueue_script('podlove-chapters', plugin_dir_url(__FILE__) . 'podlove-chapters.js', array('jquery'), '2.7.1', false);
  206
+    }
  207
+}
  208
+add_action('wp_print_scripts', 'mejs_add_scripts');
  209
+}
  210
+
  211
+// CSS
  212
+// still always enqueued so it happens in the <head> tag
  213
+function mejs_add_styles() {
  214
+    if (!is_admin()) {
  215
+        // the style
  216
+        wp_enqueue_style('mediaelementjs-styles', MEDIAELEMENTJS_DIR . 'mediaelementplayer.css');
  217
+
  218
+        if (get_option('mep_video_skin') != '') {
  219
+            wp_enqueue_style('mediaelementjs-skins', MEDIAELEMENTJS_DIR . 'mejs-skins.css');
  220
+        }
  221
+    }
  222
+}
  223
+add_action('wp_print_styles', 'mejs_add_styles');
  224
+
  225
+
  226
+function podlove_media_shortcode($tagName, $atts) {
  227
+    // only enqueue when needed
  228
+    if (get_option('mep_script_on_demand')) {
  229
+        wp_enqueue_script('mediaelementjs-scripts', MEDIAELEMENTJS_DIR . 'mediaelement-and-player.min.js', array('jquery'), '2.7.0', false);
  230
+    }
  231
+
  232
+    global $podlovePlayerIndex;
  233
+    $dir = MEDIAELEMENTJS_DIR;
  234
+    $attributes = array();
  235
+    $sources = array();
  236
+    $options = array();
  237
+    $flash_src = '';
  238
+
  239
+    extract(shortcode_atts(array(
  240
+        'src' => '',
  241
+        'mp4' => '',
  242
+        'mp3' => '',
  243
+        'wmv' => '',
  244
+        'webm' => '',
  245
+        'flv' => '',
  246
+        'ogg' => '',
  247
+        'poster' => '',
  248
+        'width' => get_option('mep_default_' . $tagName . '_width'),
  249
+        'height' => get_option('mep_default_' . $tagName . '_height'),
  250
+        'type' => get_option('mep_default_' . $tagName . '_type'),
  251
+        'preload' => 'none',
  252
+        'skin' => get_option('mep_video_skin'),
  253
+        'autoplay' => '',
  254
+        'loop' => '',
  255
+
  256
+        // old ones
  257
+        'duration' => 'true',
  258
+        'progress' => 'true',
  259
+        'fullscreen' => 'true',
  260
+        'volume' => 'true',
  261
+
  262
+        // captions
  263
+        'captions' => '',
  264
+        'captionslang' => 'en',
  265
+
  266
+        // chapters
  267
+        'chapters' => ''
  268
+
  269
+    ), $atts));
  270
+
  271
+    if ($type) {
  272
+        $attributes[] = 'type="' . $type . '"';
  273
+    }
  274
+
  275
+/*
  276
+    if ($src) {
  277
+        $attributes[] = 'src="'.htmlspecialchars($src).'"';
  278
+        $flash_src = htmlspecialchars($src);
  279
+    }
  280
+*/
  281
+
  282
+    if ($src) {
  283
+
  284
+        // does it have an extension?
  285
+        if (substr($src, strlen($src)-4, 1) == '.') {
  286
+            $attributes[] = 'src="' . htmlspecialchars($src) . '"';
  287
+            $flash_src = htmlspecialchars($src);
  288
+        } else {
  289
+
  290
+            // for missing extension, we try to find all possible files in the system
  291
+
  292
+            if (substr($src, 0, 4) != 'http') {
  293
+                $filename = WP_CONTENT_DIR . substr($src, strlen(WP_CONTENT_DIR) - strrpos(WP_CONTENT_DIR, '/'));
  294
+            } else {
  295
+                $filename = WP_CONTENT_DIR . substr($src, strlen(WP_CONTENT_URL));
  296
+            }
  297
+
  298
+            if ($tagName == 'video') {
  299
+                // MP4
  300
+                if (file_exists($filename . '.mp4')) {
  301
+                    $mp4 = $src . '.mp4';
  302
+                } elseif (file_exists($filename . '.m4v')) {
  303
+                    $mp4 = $src . '.m4v';
  304
+                }
  305
+
  306
+                // WEBM
  307
+                if (file_exists($filename . '.webm')) {
  308
+                    $webm = $src . '.webm';
  309
+                }
  310
+
  311
+                // OGG
  312
+                if (file_exists($filename . '.ogg')) {
  313
+                    $ogg = $src . '.ogg';
  314
+                } elseif (file_exists($filename . '.ogv')) {
  315
+                    $ogg = $src . '.ogv';
  316
+                }
  317
+
  318
+                // FLV
  319
+                if (file_exists($filename . '.flv')) {
  320
+                    $flv = $src . '.flv';
  321
+                }
  322
+
  323
+                // WMV
  324
+                if (file_exists($filename . '.wmv')) {
  325
+                    $wmv = $src . '.wmv';
  326
+                }
  327
+
  328
+                // POSTER
  329
+                if (file_exists($filename . '.jpg')) {
  330
+                    $poster = $src . '.jpg';
  331
+                }
  332
+            } elseif ($tagName == 'audio') {
  333
+                // MP3
  334
+                if (file_exists($filename . '.mp3')) {
  335
+                    $mp3 = $src . '.mp3';
  336
+                }
  337
+
  338
+                // OGG
  339
+                if (file_exists($filename . '.ogg')) {
  340
+                    $ogg = $src . '.ogg';
  341
+                } elseif (file_exists($filename . '.oga')) {
  342
+                    $ogg = $src . '.oga';
  343
+                }
  344
+            }
  345
+        }
  346
+    }
  347
+
  348
+    // <source> tags
  349
+    if ($mp4) {
  350
+        $sources[] = '<source src="' . htmlspecialchars($mp4) . '" type="' . $tagName . '/mp4" />';
  351
+        $flash_src = htmlspecialchars($mp4);
  352
+    }
  353
+    if ($mp3) {
  354
+        $sources[] = '<source src="' . htmlspecialchars($mp3) . '" type="' . $tagName . '/mp3" />';
  355
+        $flash_src = htmlspecialchars($mp3);
  356
+    }
  357
+    if ($webm) {
  358
+        $sources[] = '<source src="' . htmlspecialchars($webm) . '" type="' . $tagName . '/webm" />';
  359
+    }
  360
+    if ($ogg) {
  361
+        $sources[] = '<source src="' . htmlspecialchars($ogg) . '" type="' . $tagName . '/ogg" />';
  362
+    }
  363
+    if ($flv) {
  364
+        $sources[] = '<source src="' . htmlspecialchars($flv) . '" type="' . $tagName . '/flv" />';
  365
+    }
  366
+    if ($wmv) {
  367
+        $sources[] = '<source src="' . htmlspecialchars($wmv) . '" type="' . $tagName . '/wmv" />';
  368
+    }
  369
+    if ($captions) {
  370
+        $sources[] = '<track src="' . $captions . '" kind="subtitles" srclang="' . $captionslang . '" />';
  371
+    }
  372
+
  373
+    // <audio|video> attributes
  374
+    if ($width && $tagName == 'video') {
  375
+        $attributes[] = 'width="' . $width . '"';
  376
+    }
  377
+    if ($height && $tagName == 'video') {
  378
+        $attributes[] = 'height="' . $height . '"';
  379
+    }
  380
+    if ($poster) {
  381
+        $attributes[] = 'poster="' . htmlspecialchars($poster) . '"';
  382
+    }
  383
+    if ($preload) {
  384
+        $attributes[] = 'preload="' . $preload . '"';
  385
+    }
  386
+    if ($autoplay) {
  387
+        $attributes[] = 'autoplay="' . $autoplay . '"';
  388
+    }
  389
+
  390
+    // MEJS JavaScript options
  391
+    if ($loop) {
  392
+        $options[]  = 'loop: ' . $loop;
  393
+    }
  394
+
  395
+    // CONTROLS array
  396
+    $controls_option[] = '"playpause"';
  397
+    if ($progress == 'true') {
  398
+        $controls_option[] = '"current"';
  399
+        $controls_option[] = '"progress"';
  400
+    }
  401
+    if ($duration == 'true') {
  402
+        $controls_option[] = '"duration"';
  403
+    }
  404
+    if ($volume == 'true') {
  405
+        $controls_option[] = '"volume"';
  406
+    }
  407
+    $controls_option[] = '"tracks"';
  408
+    if ($fullscreen == 'true') {
  409
+        $controls_option[] = '"fullscreen"';
  410
+    }
  411
+
  412
+    $options[] = '"features":[' . implode(',', $controls_option) . ']';
  413
+
  414
+    // <audio> size
  415
+    if ($tagName == 'audio') {
  416
+        $options[] = '"audioWidth":' . $width;
  417
+        $options[] = '"audioHeight":' . $height;
  418
+    }
  419
+
  420
+    // <video> class (skin)
  421
+    $skin_class = '';
  422
+    if ($skin != '') {
  423
+        $skin_class  = 'mejs-' . $skin;
  424
+    }
  425
+
  426
+    // BUILD HTML
  427
+    $attributes_string = !empty($attributes) ? implode(' ', $attributes) : '';
  428
+    $sources_string = !empty($sources) ? implode("\n\t\t", $sources) : '';
  429
+    $options_string = !empty($options) ? '{' . implode(',', $options) . '}' : '';
  430
+
  431
+    $mediahtml = <<<_end_
  432
+    <{$tagName} id="wp_mep_{$podlovePlayerIndex}" controls="controls" {$attributes_string} class="mejs-player {$skin_class}" data-mejsoptions='{$options_string}'>
  433
+        {$sources_string}
  434
+        <object width="{$width}" height="{$height}" type="application/x-shockwave-flash" data="{$dir}flashmediaelement.swf">
  435
+            <param name="movie" value="{$dir}flashmediaelement.swf" />
  436
+            <param name="flashvars" value="controls=true&amp;file={$flash_src}" />
  437
+        </object>
  438
+    </{$tagName}>
  439
+_end_;
  440
+
  441
+    // Chapters Table and Behaviour
  442
+    if ($chapters) {
  443
+        $mediahtml .= "\n\n" . podlove_render_chapters($chapters);
  444
+        $mediahtml .= "\n\n<script>PODLOVE.chapters('wp_mep_{$podlovePlayerIndex}');</script>\n";
  445
+    }
  446
+
  447
+    $podlovePlayerIndex++;
  448
+    return $mediahtml;
  449
+}
  450
+
  451
+
  452
+function podlove_render_chapters($custom_field) {
  453
+    global $post;
  454
+    global $podlovePlayerIndex;
  455
+
  456
+    if ($custom_field != '' && $chapters = get_post_custom_values($custom_field, $post->ID)) {
  457
+        $chapters = podlove_chapters_from_string($chapters[0]);
  458
+
  459
+        //echo "<pre>";
  460
+        //var_dump ($chapters);
  461
+        //echo "</pre>";
  462
+
  463
+        $output .= '<table rel="wp_mep_' . $podlovePlayerIndex . '" class="mejs_chapters" style="display:none"><tbody>';
  464
+        foreach ($chapters as $i => $chapter) {
  465
+            $end = ($i == (count($chapters) - 1)) ? '9999999' : $chapters[$i + 1]['timecode'];
  466
+            $output .= '<tr>';
  467
+            $output .= '<td class="timecode"><code>' . $chapter['human_timecode'] . '</code></td>';
  468
+            $output .= '<td class="title"><span data-buffered="0" data-start="' . $chapter['timecode'] . '" data-end="' . $end . '">' . $chapter['title'] . '</span></td>';
  469
+            $output .= '</tr>';
  470
+        }
  471
+        $output .= '</tbody></table>';
  472
+
  473
+
  474
+        return $output;
  475
+    } else {
  476
+        return false;
  477
+    }
  478
+}
  479
+
  480
+function podlove_chapters_from_string($chapstring) {
  481
+    $lines = explode("\n", $chapstring);
  482
+    foreach ($lines as $i => $line) {
  483
+        if (trim($line) != '') {
  484
+            $line = trim(str_replace("\n", '', $line));
  485
+            $div = stripos($line, ' ');
  486
+
  487
+            $time = trim(substr($line, 0, $div));
  488
+            $hours = substr($time, 0, 2);
  489
+            $mins = substr($time, 3, 2);
  490
+            $secs = substr($time, 6, 2);
  491
+            $msecs = count(substr($time, 9, 1)) ? substr($time, 9, 3) : 0;
  492
+
  493
+            $chapters[$i]['title'] = trim(substr($line, $div + 1));
  494
+            $chapters[$i]['human_timecode'] = substr($time, 0, 8);
  495
+            $chapters[$i]['timecode'] = ($hours * 3600 + $mins * 60 + $secs * 1) . '.' . floor($msecs);
  496
+            $chapters[$i]['hours'] = $hours;
  497
+            $chapters[$i]['minutes'] = $mins;
  498
+            $chapters[$i]['seconds'] = $secs;
  499
+            $chapters[$i]['milliseconds'] = $msecs;
  500
+        }
  501
+    }
  502
+    if ($chapters[$i]['hours'] == '00') {
  503
+        foreach ($chapters as $i => $chapter) {
  504
+            $chapters[$i]['human_timecode'] = substr($chapter['human_timecode'], 3);
  505
+        }
  506
+    }
  507
+    return $chapters;
  508
+}
  509
+
  510
+
  511
+
  512
+function podlove_audio_shortcode($atts) {
  513
+    return is_feed() ? '' : podlove_media_shortcode('audio', $atts);
  514
+}
  515
+function podlove_video_shortcode($atts) {
  516
+    return is_feed() ? '' : podlove_media_shortcode('video', $atts);
  517
+}
  518
+
  519
+add_shortcode('audio', 'podlove_audio_shortcode');
  520
+add_shortcode('podloveaudio', 'podlove_audio_shortcode');
  521
+add_shortcode('video', 'podlove_video_shortcode');
  522
+add_shortcode('podlovevideo', 'podlove_video_shortcode');
  523
+
  524
+function podlove_init() {
  525
+    wp_enqueue_script('jquery');
  526
+}
  527
+
  528
+add_action('init', 'podlove_init');
  529
+
  530
+?>

No commit comments for this range

Something went wrong with that request. Please try again.