This product is a plugin for the Movable Type blog platform to help content creator to simply add external videos to their posts.
From the internal Movable Type editor, with a BBCode-like tag, you can include embedding videos currently from this platform
If you write this
you get this
To use this plugin:
svn co https://svn.micso.net:666/bruni/MTOS/MTVideoEmbedding/trunk/MTVideoEmbedding/plugins/MTVideoEmbedding/ MTVideoEmbedding
For more information, read the README file.
This module is a completly rewrite of Crys Clouse and David Wees videoembedding.pl plugin. I rewrote most of the code to optimize regular expression and incapsulate some logics. I implement standard interface for movable type plugin and extend original module with other video source like vimeo and myspace.
For learning porpouse, this is the source code of the main module in version 02.02
1 #!/usr/bin/perl
2
3 package MT::Plugin::VideoEmbedding;
4
5 use strict;
6 use warnings;
7 use MT 4.0;
8 use base qw( MT::Plugin );
9
10 our $DISPLAY_NAME = 'Video Embedding via BBCode';
11 our $VERSION = '2.02';
12
13 our ($plugin, $PLUGIN_MODULE, $PLUGIN_KEY);
14 MT->add_plugin($plugin = __PACKAGE__->new({
15 id => plugin_module(),
16 key => plugin_key(),
17 name => plugin_name(),
18 description => "A text filter to use BBCode-like tag to include external video resource. You can embed an youtube video with this BBCode<p><pre>[yt]eR8swuWfKMI[/yt]</pre>",
19 version => $VERSION,
20 author_name => "Emiliano Bruni",
21 author_link => "http://www.ebruni.it",
22 plugin_link => "http://www.ebruni.it/software/os/mtos/videoembedding/",
23 doc_link => "http://www.ebruni.it/software/os/mtos/videoembedding/readme.htm"
24 }));
25
26 MT->add_text_filter(video => { label => 'Video', on_format => sub { &vcode }, });
27
28 sub init_registry {
29 my $plugin = shift;
30 $plugin->registry({
31 });
32 }
33
34 sub vcode {
35 my $s = shift;
36 vfullcodes($s);
37 }
38
39 sub vfullcodes {
40 my $s = $_[0];
41
42 $s = &youtube($s);
43 $s = &google($s);
44 $s = &vimeo($s);
45 $s = &myspace($s);
46
47 $s = vmaincodes($s);
48 return $s;
49 }
50
51 sub vcommentcodes {
52 my $s = $_[0];
53
54 $s =~ s!<!\*amp;lt;!g;
55 $s =~ s!>!\*amp;gt;!g;
56 $s = vmaincodes($s);
57 $s =~ s!\*amp;!&!g;
58
59 return $s;
60 }
61 sub vmaincodes {
62 my $s = $_[0];
63
64 $s =~ s!…!…!g;
65 $s =~ s!‘!‘!g;
66 $s =~ s!’!’!g;
67 $s =~ s!“!“!g;
68 $s =~ s!”!”!g;
69 $s =~ s!–!–!g;
70 $s =~ s!—!—!g;
71
72 $s = MT::Util::html_text_transform($_[0]);
73 $s =~ s!(<p>.*?</p>)!vsmarty_pnts($1)!geis;
74 $s =~ s!<linebreak>!\n!g;
75
76 return $s;
77 }
78
79 sub vsmarty_pnts {
80 my $s = $_[0];
81 my $smarty = $MT::Template::Context::Global_filters{'smarty_pants'};
82 return $smarty ? $smarty->($s, '1') : $s;
83 }
84
85 sub youtube {
86 my $er = sub() {
87 my ($v,$height,$width,$hq) = (shift,shift,shift,shift);
88 return <<""
89 <object width="$width" height="$height">
90 <param name="movie" value="http://www.youtube.com/v/$v" />
91 <param name="wmode" value="transparent" />
92 <embed src="http://www.youtube.com/v/$v" type="application/x-shockwave-flash" wmode="transparent" height="$height" width="$width">
93 </object>
94
95 };
96 return &_def_filter(shift,'yt',$er,350,425);
97 }
98
99 sub google {
100 my $er = sub() {
101 my ($v,$height,$width) = (shift,shift,shift,shift);
102 return <<""
103 <embed style="width:${width}px;height:${height}px" flashvars="" src="http://video.google.com/googleplayer.swf?docid=$v" type="application/x-shockwave-flash"> </embed>
104
105 };
106 return &_def_filter(shift,'gv',$er,326,400);
107 }
108
109 sub vimeo {
110 my $er = sub() {
111 my ($v,$height,$width) = (shift,shift,shift,shift);
112 return <<""
113 <object width="$width" height="$height">
114 <param name="allowfullscreen" value="true" />
115 <param name="allowscriptaccess" value="always" />
116 <param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=$v;show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" />
117 <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=$v&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="$width" height="$height"></embed>
118 </object>
119
120 };
121 return &_def_filter(shift,'vm',$er,225,400);
122 }
123
124 sub myspace {
125 my $er = sub() {
126 my ($v,$height,$width) = (shift,shift,shift);
127 return <<""
128 <object width="${width}px" height="${height}px">
129 <param name="wmode" value="transparent"/>
130 <param name="allowscriptaccess" value="always"/>
131 <param name="movie" value="http://lads.myspace.com/videos/vplayer.swf"/>
132 <param name="flashvars" value="a=0&ap=0&y=0&m=$v&userid=-1&showmenus=0&remove=0&t=&type=video"/>
133 <embed src="http://lads.myspace.com/videos/vplayer.swf" width="$width" height="$height" flashvars="a=0&ap=0&y=0&m=$v&userid=-1&showmenus=0&remove=0&t=&type=video" type="application/x-shockwave-flash" allowscriptaccess="always" />
134 </object>
135
136 };
137 return &_def_filter(shift,'ms',$er,386,430);
138 }
139
140 sub _def_filter {
141 my ($s,$tag,$er,$defH,$defW) = @_;
142
143 my $re = '\[' . $tag. '\s*(.*?)](.*?)\[\/' . $tag. ']';
144
145 $s =~ s{$re}{
146 my $params = $1;
147 my $v = $2;
148 my $height = ($params =~ /height\s*=\s*"?(\d+)"?/) ? $1 : $defH;
149 my $width = ($params =~ /width\s*=\s*"?(\d+)"?/) ? $1 : $defW;
150 $er->($v,$height,$width);
151 }gse;
152
153 return $s;
154 }
155
156
157 sub plugin_name { return ($DISPLAY_NAME || plugin_module()) }
158 sub plugin_module {
159 $PLUGIN_MODULE or ($PLUGIN_MODULE = __PACKAGE__) =~ s/^MT::Plugin:://;
160 return $PLUGIN_MODULE;
161 }
162 sub plugin_key {
163 $PLUGIN_KEY or ($PLUGIN_KEY = lc(plugin_module())) =~ s/\s+//g;
164 return $PLUGIN_KEY
165 }
166
167 1;