-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-widgetgd_video.php
153 lines (131 loc) · 7.46 KB
/
wp-widgetgd_video.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
<?php
class VideoWidget extends WP_Widget
{
function VideoWidget()
{
$widget_ops = array('classname' => 'VideoWidget', 'description' => 'Video Gabinete Digital, id ou url do video.' );
$this->WP_Widget('VideoWidget', 'Gabinete Digital - Videos', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'colunas' => '3', 'css_class'=>'', 'id_url' => '', 'legenda' => '', 'chk_legenda_externa' => 0 ) );
$titulo = $instance['titulo'];
$legenda = $instance['legenda'];
$chk_legenda_externa = $instance['chk_legenda_externa'];
$colunas = $instance['colunas'];
$id_url = $instance['id_url'];
$embed = $instance['embed'];
$css_class = $instance['css_class'];
?>
<p><label for="<?php echo $this->get_field_id('titulo'); ?>">Titulo: <input class="widefat" id="<?php echo $this->get_field_id('titulo'); ?>" name="<?php echo $this->get_field_name('titulo'); ?>" type="text" value="<?php echo attribute_escape($titulo); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('legenda'); ?>">Legenda: <input class="widefat" id="<?php echo $this->get_field_id('legenda'); ?>" name="<?php echo $this->get_field_name('legenda'); ?>" type="text" value="<?php echo attribute_escape($legenda); ?>" /></label></p>
<p><input type="checkbox" name="<?php echo $this->get_field_name('chk_legenda_externa'); ?>" id="<?php echo $this->get_field_id('chk_legenda_externa'); ?>" value="1" <?php if ( $chk_legenda_externa ) { echo 'checked="checked"'; } ?> /><label for="<?php echo $this->get_field_id('chk_legenda_externa'); ?>"> Legenda Externa </label></p>
<p><label for="<?php echo $this->get_field_id('colunas'); ?>">Colunas: <input class="widefat" id="<?php echo $this->get_field_id('colunas'); ?>" name="<?php echo $this->get_field_name('colunas'); ?>" type="text" value="<?php echo attribute_escape($colunas); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('id_url'); ?>">ID/URL: <input class="widefat" id="<?php echo $this->get_field_id('id_url'); ?>" name="<?php echo $this->get_field_name('id_url'); ?>" type="text" value="<?php echo attribute_escape($id_url); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('embed'); ?>">EMBED: <textarea class="widefat" id="<?php echo $this->get_field_id('embed'); ?>" name="<?php echo $this->get_field_name('embed'); ?>"><?php echo attribute_escape($embed); ?></textarea>
<p><label for="<?php echo $this->get_field_id('css_class'); ?>">Classe CSS: <input class="widefat" id="<?php echo $this->get_field_id('css_class'); ?>" name="<?php echo $this->get_field_name('css_class'); ?>" type="text" value="<?php echo attribute_escape($css_class); ?>" /></label></p>
<?php
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['titulo'] = $new_instance['titulo'];
$instance['legenda'] = $new_instance['legenda'];
$instance['chk_legenda_externa'] = $new_instance['chk_legenda_externa'];
$instance['colunas'] = $new_instance['colunas'];
$instance['id_url'] = $new_instance['id_url'];
$instance['embed'] = $new_instance['embed'];
$instance['css_class'] = $new_instance['css_class'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$txtreturn = '';
$date = new DateTime();
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_title', $instance['titulo']);
$colunas = $instance['colunas'];
$id_url = $instance['id_url'];
$embed = $instance['embed'];
$legenda = $instance['legenda'];
$legendaExterna = $instance['chk_legenda_externa'];
$css_class = $instance['css_class'];
$idcontainer = rand($id_url,10000) . $id_url;
$pos = strpos($id_url, "http://");
if (!empty($legenda))
$legenda = $legenda;
else
$legenda = "";
$txtreturn .= "<li class='span".$colunas."'>";
$txtreturn .= "<div class='thumbnail video ".$css_class."'>";
$txtreturn .= "<a id=\"title-$idcontainer\" href='/videos/".$id_url."'>";
$txtreturn .= "<h4>".$titulo."</h4>";
if (!$legendaExterna){
$txtreturn .= '<h4>' . $legenda . '</h4>';
}
if(!empty($id_url)){
if ($pos === false) {
$video = wpgd_videos_get_video($id_url);
$sources = wpgd_videos_get_sources($id_url);
foreach ( $sources as $s ){
if( strpos( $s['format'] ,'ogg') > 0 ){
$url_video_ogg = $s['url'];
}
if( strpos( $s['format'] ,'mp4') > 0 ){
$url_video_mp4 = $s['url'];
}
if( strpos( $s['format'] ,'webm') > 0 ){
$url_video_webm = $s['url'];
}
}
$txtreturn .= " <video width=\"320\" height=\"240\" id=\"container$idcontainer\" style=\"width: 100%; height: 100%; max-width: 100%; max-height: 100%\" poster=\"".$video['thumbnail']."\" controls=\"controls\" preload=\"none\">\n";
$txtreturn .= " <source type=\"video/mp4\" src=\"".$url_video_mp4."\" />\n";
$txtreturn .= " <source type=\"video/webm\" src=\"".$url_video_webm."\" />\n";
$txtreturn .= " <object width=\"".$video['video_width']."\" height=\"".$video['video_height']."\" type=\"application/x-shockwave-flash\"\n";
$txtreturn .= " data=\"/static/me/build/flashmediaelement.swf\">\n";
$txtreturn .= " <param name=\"movie\" value=\"/static/me/build/flashmediaelement.swf\" /> \n";
$txtreturn .= " <param name=\"flashvars\" value=\"controls=true&file=".$url_video_mp4."\" /> \n";
$txtreturn .= " <img src=\"".$video['thumbnail']."\" width=\"".$video['video_width']."\" height=\"".$video['video_height']."\" alt=\"Here we are\" \n";
$txtreturn .= " title=\"No video playback capabilities\" />\n";
$txtreturn .= " </object>\n";
$txtreturn .= " </video>\n";
$txtreturn .= " <script type=\"text/javascript\">\n$(function(){";
$txtreturn .= " $('#container$idcontainer').mediaelementplayer({\n";
$txtreturn .= " enableAutosize: false,\n";
$txtreturn .= " enableKeyboard: true,\n";
$txtreturn .= " alwaysShowControls: true,\n";
$txtreturn .= " success: function(media, node, player) { ; \n";
$txtreturn .= " media.addEventListener('play', function(e) {\n";
$txtreturn .= " $('#title-$idcontainer').fadeOut();\n";
$txtreturn .= " },false);\n";
$txtreturn .= " media.addEventListener('pause', function(e) {\n";
$txtreturn .= " $('#title-$idcontainer').fadeIn();\n";
$txtreturn .= " });\n";
$txtreturn .= " media.addEventListener('ended', function(e) {\n";
$txtreturn .= " $('#title-$idcontainer').fadeIn();\n";
$txtreturn .= " });\n";
$txtreturn .= " }\n";
$txtreturn .= " });});\n";
$txtreturn .= " </script>\n";
} else {
$txtreturn .= "<iframe src='$id_url' width='100' height='100'</iframe> ";
}
}
elseif (!empty($embed)) {
$txtreturn .= $embed;
}
$txtreturn .= "</a>";
$txtreturn .= "</div>";
if ($legendaExterna){
$txtreturn .= "<div class='video_legenda_externa'>";
$txtreturn .= "<a id=\"title-$idcontainer\" href='/videos/".$id_url."'>";
$txtreturn .= $legenda;
$txtreturn .= "</a>";
$txtreturn .= "</div>";
}
$txtreturn .= "</li>";
echo $txtreturn;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("VideoWidget");') );
?>