-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-widgetgd_banner.php
94 lines (80 loc) · 4.27 KB
/
wp-widgetgd_banner.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
<?php
class BannerWidget extends WP_Widget
{
function BannerWidget()
{
$widget_ops = array('classname' => 'BannerWidget', 'description' => 'Banner do Gabinente Digital.' );
$this->WP_Widget('BannerWidget', 'Gabinete Digital - Banner', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'imagem' => '', 'link'=>'', 'chk_legenda_externa' => 0, 'colunas' => '3', 'css_class'=>'', 'legenda' => '' ) );
$titulo = $instance['titulo'];
$imagem = $instance['imagem'];
$link = $instance['link'];
$legenda = $instance['legenda'];
$chk_legenda_externa = $instance['chk_legenda_externa'];
$colunas = $instance['colunas'];
$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('imagem'); ?>">Imagem: <input class="widefat" id="<?php echo $this->get_field_id('imagem'); ?>" name="<?php echo $this->get_field_name('imagem'); ?>" type="text" value="<?php echo attribute_escape($imagem); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('link'); ?>">Link: <input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo attribute_escape($link); ?>" /></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('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['imagem'] = $new_instance['imagem'];
$instance['link'] = $new_instance['link'];
$instance['legenda'] = $new_instance['legenda'];
$instance['chk_legenda_externa'] = $new_instance['chk_legenda_externa'];
$instance['colunas'] = $new_instance['colunas'];
$instance['css_class'] = $new_instance['css_class'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$linke = $instance['link'];
$legenda = $instance['legenda'];
$legenda_ext = $instance['chk_legenda_externa'];
if (!empty($linke)){
$pos = strpos($linke, "http://");
$pos1 = strpos(substr($linke, 0,1), "/");
if ($pos === false && $pos1 === false) {
$linke = "http://".$linke;
}
}
echo "<li class='span".$instance['colunas']."'>";
echo "<div class='thumbnail banner ".$instance['css_class']."'>";
if(!empty($linke)){
echo " <a href='" . $linke . "'>";
}
echo " <img src='" . $instance['imagem'] . "' alt='". $instance['titulo']."'>";
if(!empty($linke)){
echo " </a>";
}
if(!empty($legenda)){
if($legenda_ext){
$legenda = '<h4>' . $legenda . '</h4>';
echo "</div>";
echo "<div class='banner_legenda_externa'>";
echo $legenda;
echo "</div>";
} else {
$legenda = '<h4>' . $legenda . '</h4>';
echo $legenda;
echo "</div>";
}
}
echo "</li>";
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("BannerWidget");') );
?>