diff -Naur video/plugins/video_filter/video_filter.module video_patched/plugins/video_filter/video_filter.module --- video/plugins/video_filter/video_filter.module 1970-01-01 01:00:00.000000000 +0100 +++ video_patched/plugins/video_filter/video_filter.module 2006-07-26 13:10:25.000000000 +0200 @@ -0,0 +1,85 @@ + + */ + + +/** + * Implementation of hook_help(). + */ +function video_filter_help($section) { + switch ($section) { + case 'admin/modules#description': + return t('Allow user to inject video player into text.'); + } +} + +/** + * Implementation of hook_filter(). + */ +function video_filter_filter($op, $delta = 0, $format = -1, $text = '') { + switch ($op) { + case 'list': + return array(0 => t('Inject video')); + case 'description': + return t('Substitutes [video=NID] for player object with video.'); + case 'no cache': + return TRUE; + case 'prepare': + return $text; + case 'process': + return preg_replace_callback('/\[video=(\d+)(\s?,\s?.*)?\]/U', '_video_filter_replace', $text); + case 'settings': + default: + break; + } +} + +/** + * Implementation of hook_filter_tips(). + */ +function video_filter_filter_tips($delta, $format, $long = FALSE) { + if ($long) { + return t('Substitute [video=NID] for player object with video.'); + } + else { + return t('Substitutes [video=NID] for player object with video. NID is a node id number of video node. You can also add "autoplay" option with value of "false" or "true" to turn off or on autoplay (for example: [video=23,autoplay=false]).'); + } +} + +/** + * Private function; Patern replacing callback. + */ +function _video_filter_replace($matches) { + // $matches[1] contains ID of video node, $matches[2] contains rest of "command line" + $nid = trim($matches[1]); + if (!is_numeric($nid) || !($node = node_load($nid))) { + // Return whole line, just in case it's a command for some other filter + return $matches[0]; + } + + $autoplay = FALSE; + $align = 'none'; + + // Parse params + $params = preg_split('/[\=,]+/', $matches[2], -1, PREG_SPLIT_NO_EMPTY); + for ($i = 0; $i < count($params); $i+=2) { + switch (trim($param[$i])) { + case 'autoplay': + $autoplay = (trim($param[$i+1]) == 'true' ? TRUE : FALSE); + break; + case 'align': + $align = trim($param[$i+1]); + break; + default: + break; + } + } + + return str_replace('class="video_player"', 'class="video_player video_align_'. $align .'"', theme_video_play($node, $autoplay)); +} diff -Naur video/video.css video_patched/video.css --- video/video.css 2006-06-18 16:12:07.000000000 +0200 +++ video_patched/video.css 2006-07-26 10:59:31.000000000 +0200 @@ -19,3 +19,19 @@ .video_image_view { /* inser here rules for node page image */ } + +.video_align_none { +} + +.video_align_left { + float: left; +} + +.video_align_right { + float: right; +} + +.video_align_center { + width: 100%; + text-align: center; +} diff -Naur video/video.js video_patched/video.js --- video/video.js 2006-06-18 16:16:10.000000000 +0200 +++ video_patched/video.js 2006-07-26 11:00:37.000000000 +0200 @@ -26,13 +26,13 @@ } - function InsertQuicktimeVideo(vidfile, height, width) + function InsertQuicktimeVideo(vidfile, height, width, autoplay) { document.writeln(''); document.writeln(''); - document.writeln(''); + document.writeln(''); document.writeln(''); - document.writeln('\n'); + document.writeln('\n'); } } diff -Naur video/video.module video_patched/video.module --- video/video.module 2006-07-16 11:26:00.000000000 +0200 +++ video_patched/video.module 2006-07-26 12:01:37.000000000 +0200 @@ -614,8 +614,7 @@ $node = node_prepare($node, $teaser); //Run the body through the standard filters. // include the video css file - theme_add_style(drupal_get_path('module', 'video').'/video.css'); - + theme('video_get_style'); } /******************************************************************** @@ -767,44 +766,19 @@ * Implements play callback function from node menu */ function video_play() { - if ($node = node_load(arg(1))) { - // include video.js file for Internet Explorer fixes - theme('video_get_script'); - drupal_set_title(t('Playing') . ' ' . theme('placeholder', $node->title)); - if (variable_get('video_playcounter', 1)) { - db_query("UPDATE {video} SET play_counter = play_counter + 1 where vid = %d", $node->vid); //Increment play counter. - } - switch (_video_get_filetype($node->vidfile)) { - case 'mov': - case 'mp4': - case '3gp': - case '3g2': - return theme('video_play_quicktime', $node); - case 'rm': - return theme('video_play_realmedia', $node); - case 'flv': - return theme('video_play_flash', $node); - case 'swf': - return theme('video_play_swf', $node); - case 'dir': - case 'dcr': - return theme('video_play_dcr', $node); - case 'wmv': - return theme('video_play_windowsmedia', $node); - case 'ogg': - return theme('video_play_ogg_theora', $node); - case 'youtube': - return theme('video_play_youtube', $node); - case 'googlevideo': - return theme('video_play_googlevideo', $node); - default: - drupal_set_message('Video type not supported', 'error'); - drupal_goto("node/$node->nid"); - break; - } + $node = node_load(arg(1)); + if (!$node) { + drupal_not_found(); + } + + drupal_set_title(t('Playing') .' '. theme('placeholder', $node->title)); + + if ($output = theme('video_play', $node)) { + return $output; } else { - drupal_not_found(); + drupal_set_message('Video type not supported', 'error'); + drupal_goto("node/$node->nid"); } } @@ -813,15 +787,79 @@ *********************************************************************/ /** + * Output "player" code + * + * @param $node + * object with node information + * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * + * @return + * string of content to display + */ +function theme_video_play($node, $autoplay = FALSE) { + if (variable_get('video_playcounter', 1)) { + db_query("UPDATE {video} SET play_counter = play_counter + 1 where vid = %d", $node->vid); //Increment play counter. + } + + switch (_video_get_filetype($node->vidfile)) { + case 'mov': + case 'mp4': + case '3gp': + case '3g2': + $output = theme('video_play_quicktime', $node, $autoplay); + break; + case 'rm': + $output = theme('video_play_realmedia', $node, $autoplay); + break; + case 'flv': + $output = theme('video_play_flash', $node, $autoplay); + break; + case 'swf': + $output = theme('video_play_swf', $node, $autoplay); + break; + case 'dir': + case 'dcr': + $output = theme('video_play_dcr', $node, $autoplay); + break; + case 'wmv': + $output = theme('video_play_windowsmedia', $node, $autoplay); + break; + case 'youtube': + $output = theme('video_play_youtube', $node, $autoplay); + break; + case 'googlevideo': + $output = theme('video_play_googlevideo', $node, $autoplay); + break; + default: + $output = NULL; + break; + } + + if ($output) { + // include video.js file for Internet Explorer fixes + theme('video_get_script'); + // include the video css file + theme('video_get_style'); + } + + return $output; +} + +/** * Play videos from in FLV Flash video format * * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_flash($node) { +function theme_video_play_flash($node, $autoplay = FALSE) { $loader_location = variable_get('video_flvplayerloader', 'Player.swf'); $url = _video_get_fileurl($node->vidfile); @@ -845,12 +883,12 @@ $output .= ' - ' . "\n" + ' . "\n" . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

'; - $output = _theme_video_format_play($output, t('http://www.macromedia.com/go/getflashplayer'), + $output = theme('video_play_container', $output, t('http://www.macromedia.com/go/getflashplayer'), t('Link to Macromedia Flash Player Download Page'), t('Download latest Flash Player')); return $output; @@ -862,10 +900,13 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_swf($node) { +function theme_video_play_swf($node, $autoplay = FALSE) { $url = _video_get_fileurl($node->vidfile); @@ -882,13 +923,15 @@ codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"> ' . "\n"; + // TODO: add support for autoplay param + // params will be passed to both IE or not IE browsers $output .= '' . "\n" . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

'; - $output = _theme_video_format_play($output, t('http://www.macromedia.com/go/getflashplayer'), t('Link to Flash player download'), t('Download the latest Flash player')); + $output = theme('video_play_container', $output, t('http://www.macromedia.com/go/getflashplayer'), t('Link to Flash player download'), t('Download the latest Flash player')); return $output; } @@ -900,11 +943,14 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_dcr($node) { +function theme_video_play_dcr($node, $autoplay = FALSE) { $url = _video_get_fileurl($node->vidfile); @@ -921,13 +967,15 @@ codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,0,0,0"> ' . "\n"; + // TODO: add support for autoplay param + // params will be passed to both IE or not IE browsers $output .= '' . "\n" . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

'; - $output = _theme_video_format_play($output, t('http://www.macromedia.com/shockwave/download/'), + $output = theme('video_play_container', $output, t('http://www.macromedia.com/shockwave/download/'), t('Link to Macromedia Shockwave Player Download Page'), t('Download latest Shockwave Player')); return $output; @@ -940,10 +988,13 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_quicktime($node) { +function theme_video_play_quicktime($node, $autoplay = FALSE) { //Increase the height to accommodate the player controls on the bottom. $height = $node->videoy + 16; @@ -963,7 +1014,7 @@ // params will be passed to both IE or not IE browsers $output .= ' - + ' . "\n" . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

@@ -972,12 +1023,12 @@ /* $output = ''; */ - $output = _theme_video_format_play($output, t('http://www.apple.com/quicktime/download'), + $output = theme('video_play_container', $output, t('http://www.apple.com/quicktime/download'), t('Link to QuickTime Download Page'), t('Download latest Quicktime Player')); return $output; @@ -989,10 +1040,13 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_realmedia($node) { +function theme_video_play_realmedia($node, $autoplay = FALSE) { // Real's embeded player includes the controls // in the height $node->videoy += 40; @@ -1013,7 +1067,7 @@ $output .= ' - + @@ -1029,7 +1083,7 @@ '; // only one needed becouse only one opening tag has been parsed by browsers - $output = _theme_video_format_play($output, t('http://www.real.com/'), + $output = theme('video_play_container', $output, t('http://www.real.com/'), t('Link to Real'), t('Download latest Realmedia Player')); return $output; @@ -1041,10 +1095,13 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_windowsmedia($node) { +function theme_video_play_windowsmedia($node, $autoplay = FALSE) { // Windows Media's embeded player includes the controls in the height $node->videoy += 68; $url = _video_get_fileurl($node->vidfile); @@ -1066,7 +1123,7 @@ - + ' . _video_get_parameters($node) . @@ -1074,7 +1131,7 @@ '; // only one needed becouse only one opening tag has been parsed by browsers - $output = _theme_video_format_play($output, t('http://windowsupdate.microsoft.com/'), + $output = theme('video_play_container', $output, t('http://windowsupdate.microsoft.com/'), t('Link to Windows Update'), t('Download latest Windows Media Player')); return $output; @@ -1088,10 +1145,13 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_youtube($node) { +function theme_video_play_youtube($node, $autoplay = FALSE) { $width = ($node->videox ? $node->videox : '425'); $height = ($node->videoy ? $node->videoy : '350'); @@ -1099,7 +1159,7 @@ // this will be executed by not Internet Explorer browsers $output = ' +data="http://www.youtube.com/v/' . check_plain($node->vidfile) . ($autoplay ? '&autoplay=1' : '') .'"> ' . "\n"; // this will be executed by Internet Explorer @@ -1110,13 +1170,13 @@ ' . "\n"; // params will be passed to both IE or not IE browsers - $output .= '' . "\n" + $output .= '' . "\n" . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

'; - $output = _theme_video_format_play($output, t('http://www.youtube.com/help.php'), t('Link to youtube.com'), t('youtube.com')); + $output = theme('video_play_container', $output, t('http://www.youtube.com/help.php'), t('Link to youtube.com'), t('youtube.com')); return $output; } @@ -1127,10 +1187,13 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_googlevideo($node) { +function theme_video_play_googlevideo($node, $autoplay = FALSE) { $width = ($node->videox ? $node->videox : '425'); $height = ($node->videoy ? $node->videoy : '350'); // Strip heading "google:" @@ -1150,7 +1213,7 @@ ' . "\n"; // params will be passed to both IE or not IE browsers - $output .= '' . "\n"; + $output .= '' . "\n"; // following a list of params simply copied from old embed tag params. I don't know if this are really needed. $output .= ' @@ -1158,13 +1221,13 @@ - ' + ' . _video_get_parameters($node) . '

'. t('Your browser is not able to display this multimedia content.') .'

'; - $output = _theme_video_format_play($output, t('http://video.google.com/support'), t('Link to video.google.com'), t('video.google.com')); + $output = theme('video_play_container', $output, t('http://video.google.com/support'), t('Link to video.google.com'), t('video.google.com')); return $output; } @@ -1174,17 +1237,22 @@ * @param $node * object with node information * + * @param $autoplay + * TRUE to play automatically, FALSE to make user click to start playing + * * @return * string of content to display */ -function theme_video_play_ogg_theora($node) { +function theme_video_play_ogg_theora($node, $autoplay = FALSE) { global $base_url; $cortado_location = variable_get('video_cortado', $base_url . '/cortado.jar'); $url = _video_get_fileurl($node->vidfile); $width = ($node->videox ? $node->videox : '425'); $height = ($node->videoy ? $node->videoy : '350'); - + + // TODO: add support for autoplay param + $output = ' '; - $output = _theme_video_format_play($output, + $output = theme('video_play_container', $output, t('http://java.com/download/'), t('Link to java.com'), t('Download Java')); return $output; } @@ -1238,8 +1306,8 @@ * @return * string HTML link */ -function _theme_video_format_play($output, $url, $title, $link_text) { - $output = "\n
\n" . $output; +function theme_video_play_container($output, $url, $title, $link_text) { + $output = "\n
\n" . $output; $output .= "

\n". t('Problems viewing videos?'); $output .= "
\n"; $output .= l($link_text, $url, array('title' => $title), NULL, NULL, TRUE); @@ -1272,9 +1340,26 @@ * Import the video.js script */ function theme_video_get_script() { - drupal_set_html_head(''); + static $video_js_done = FALSE; + if (!$video_js_done) { + $video_js_done = TRUE; + drupal_set_html_head(''); + } } + +/** + * Import the video.css stylesheet + */ +function theme_video_get_style() { + static $video_css_done = FALSE; + if (!$video_css_done) { + $video_css_done = TRUE; + theme_add_style(drupal_get_path('module', 'video').'/video.css'); + } +} + + /****************************************************************************** * End theme functions ******************************************************************************