-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-widgetgd_fotodia.php
118 lines (100 loc) · 4.99 KB
/
wp-widgetgd_fotodia.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
<?php
class FotoWidget extends WP_Widget
{
function FotoWidget()
{
$widget_ops = array('classname' => 'FotoWidget', 'description' => 'Foto do dia, conforme a galeria escolhida' );
$this->WP_Widget('FotoWidget', 'Gabinete Digital - Foto do dia', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo'=> '', 'id_galeria' => '', 'chk_rand' => 0, 'colunas' => '3', 'css_class' => '', 'legenda_externa' => 0 ) );
$titulo = $instance['titulo'];
$id_galeria = $instance['id_galeria'];
$chk_rand = $instance['chk_rand'];
$chk_legenda_externa = $instance['chk_legenda_externa'];
$colunas = $instance['colunas'];
$css_class = $instance['css_class'];
global $nggdb;
$id_galeria_selec = attribute_escape($id_galeria);
$gallerylist = $nggdb->find_all_galleries('name', 'ASC' , TRUE, 0, 0);
?>
<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('id_galeria'); ?>">ID_Galeria
<select name="<?php echo $this->get_field_name('id_galeria'); ?>" id="<?php echo $this->get_field_id('id_galeria'); ?>" class="widefat">
<option value="">Selecione uma Galeria</option>
<?php
foreach($gallerylist as $gallery) {
if ($id_galeria_selec == $gallery->gid)
echo "<option value='$gallery->gid' selected=selected>$gallery->name</option>";
else
echo "<option value='$gallery->gid'>$gallery->name</option>";
}
?>
</select>
</label>
</p>
<p><label for="<?php echo $this->get_field_id('chk_rand'); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('chk_rand'); ?>" id="<?php echo $this->get_field_id('chk_rand'); ?>" value="1" <?php if ( $chk_rand ) { echo 'checked="checked"'; } ?> /> Foto randomica</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['id_galeria'] = $new_instance['id_galeria'];
$instance['chk_rand'] = $new_instance['chk_rand'];
$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);
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_title', $instance['titulo']);
$galeria = $instance['id_galeria'];
$random = $instance['chk_rand'];
$chk_legenda_externa = $instance['chk_legenda_externa'];
global $nggdb;
if(empty($galeria)){
$gallerylist = $nggdb->find_all_galleries('gid', 'DESC' , TRUE, 1, 0);
foreach($gallerylist as $gallery) {
$galeria = $gallery->gid;
}
}
if(!empty($random)){
$galery = $nggdb->get_random_images(1, $galeria);
} else {
$galery = $nggdb->get_gallery($galeria, 'pid', 'DESC');
}
foreach ($galery as $key => $value) {
$foto = $galery[$key] ;
break;
}
if ($chk_legenda_externa){
$legenda_ext = "</div>";
$legenda_ext .= "<div class='fotodia_legenda_ext'>";
$legenda_ext .= $foto->description;
$legenda_ext .= "</div>";
} else {
$legenda_ext = " <h3>".$foto->description."</h3>";
$legenda_ext .= "</div>";
}
$txtreturn = '';
$txtreturn .= '<li class=\'span'.$instance['colunas'].'\'>';
$txtreturn .= " <a href='/fotos/". $foto->slug ."'>";
$txtreturn .= ' <div class=\'thumbnail fotodia '.$instance['css_class'].'\'>';
$txtreturn .= " <img src='" . $foto->thumbURL . "' alt='". $foto->description."'>";
$txtreturn .= " <h4><i class='icon-camera icon-white'></i>" . $titulo . "</h4>";
$txtreturn .= $legenda_ext;
$txtreturn .= " </a>";
$txtreturn .= "</li>";
echo $txtreturn;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("FotoWidget");') );
?>