-
Notifications
You must be signed in to change notification settings - Fork 17
/
delibera_filtros.php
283 lines (256 loc) · 7.76 KB
/
delibera_filtros.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
function delibera_filtros_gerar()
{
global $deliberaThemes;
?>
<div id="filtro-horizontal">
<h4><?php _e( 'Filtros de conteúdo', 'delibera' ); ?><span id="delibera-filtros-archive-mostrar" onclick="delibera_filtros_archive_mostrar()" class="delibera-filtros-mostrar" style="display: none" title="Mostrar Filtros" ></span><span id="delibera-filtros-archive-esconder" onclick="delibera_filtros_archive_esconder()" class="delibera-filtros-esconder" title="Esconder Filtros"></span></h4>
<form action="<?php the_permalink(); ?>" id="form-filtro" method="post">
<?php
delibera_filtros_get_filtros('tema');
?>
<div style="clear:both;"> </div>
<span id="form-filtro-button"><?php _e("Recarregar", 'delibera')?></span>
</form>
</div><!-- #filtro -->
<script type="text/javascript">
//<![CDATA[
jQuery.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return jQuery.getUrlVars()[name];
}
});
function delibera_filtros_archive_mostrar()
{
document.getElementById('form-filtro').style.display = 'block';
document.getElementById('delibera-filtros-archive-esconder').style.display = 'block';
document.getElementById('delibera-filtros-archive-mostrar').style.display = 'none';
return false;
}
function delibera_filtros_archive_esconder()
{
document.getElementById('form-filtro').style.display = 'none';
document.getElementById('delibera-filtros-archive-mostrar').style.display = 'block';
document.getElementById('delibera-filtros-archive-esconder').style.display = 'none';
return false;
}
function overlay_filtro(id)
{
var html = '<div id="'+id+'">';
<?php
$iloader = $deliberaThemes->getThemeDir() . "/images/ajax-loader.gif";
$iloader_padrao = $deliberaThemes->getThemeUrl() . "/images/ajax-loader.gif";
if(file_exists($iloader))
{
?>
html += '<img id="overlay_filtros" src="'+'<?php echo $iloader; ?>" ';
<?php
}
else
{
?>
html += '<img id="overlay_filtros" src="'+'<?php echo $iloader_padrao; ?>" ';
<?php
}
?>
html += 'alt="<?php _e("Carregando","delibera") ?>…"';
html += '</div>';
jQuery('#'+id).replaceWith(html);
}
function delibera_update_posts()
{
var tema_filtro = new Array();
jQuery("input[name='tema_filtro[]']:checked").each(function() {tema_filtro.push(jQuery(this).val());});
var data =
{
action: 'delibera_filtros_archive',
tema_filtro: tema_filtro
};
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: data,
success: function(response)
{
jQuery('#lista-de-pautas').replaceWith(response);
delibera_update_pager();
},
beforeSend: function()
{
overlay_filtro('lista-de-pautas');
},
});
}
jQuery(document).ready(function()
{
jQuery('#form-filtro-button').click(function()
{
delibera_update_posts();
});
delibera_update_posts();
});
function delibera_update_pager()
{
jQuery('.page').click(function()
{
var tema_filtro = new Array();
jQuery("input[name='tema_filtro[]']:checked").each(function() {tema_filtro.push(jQuery(this).val());});
var paged = this.text;
var data =
{
action: 'delibera_filtros_archive',
tema_filtro: tema_filtro,
paged: paged
};
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: data,
success: function(response)
{
jQuery('#lista-de-pautas').replaceWith(response);
delibera_update_pager();
},
beforeSend: function()
{
overlay_filtro('lista-de-pautas');
},
});
return false;
});
}
//]]>
</script>
<?php
}
function delibera_filtros_get_filtros($tax, $value = false, $linha = "<br/>")
{
$terms = get_terms($tax, array('hide_empty' => 0, 'filtro' => true));
?>
<label class="form-filtro-ultimos-chebox-label-todos"><input type="checkbox"
name="<?php echo "{$tax}_todos[]"; ?>"
value="todos" class="form-filtro-ultimos-chebox-todos"
autocomplete="off"
id="form-filtro-ultimos-todos-<?php echo "{$tax}"; ?>"
onclick="jQuery('input[name=\'<?php echo $tax; ?>_filtro[]\']').prop('checked', this.checked);"
/><?php _e("Marcar todos", 'delibera'); ?></label>
<div class="form-filtro-ultimos-div">
<?php
foreach ($terms as $term)
{
?>
<span class="form-filtro-ultimos-chebox-span">
<label class="form-filtro-ultimos-chebox-label"><input type="checkbox" name="<?php echo "{$tax}_filtro[]"; ?>" value="<?php echo $term->slug; ?>" class="form-filtro-ultimos-chebox" autocomplete="off" /><?php _e($term->name, 'delibera'); ?></label><?php echo $linha; ?>
</span>
<?php
}
?>
</div>
<?php
if($value !== false)
{
if(is_array($value))
{
$values = $value;
foreach ($values as $value)
{
?>
<script type="text/javascript">
//<![CDATA[
jQuery("input[value='<?php echo $value; ?>']").attr('checked', true);
//]]>
</script>
<?php
}
}
else
{
?>
<script type="text/javascript">
//<![CDATA[
jQuery("input[value='<?php echo $value; ?>']").attr('checked', true);
//]]>
</script>
<?php
}
}
}
function delibera_filtros_archive_callback()
{
global $wp_query, $deliberaThemes;
$action = new stdClass();
$action->canQuery = true;
$args = delibera_filtros_get_tax_filtro($_POST, array('post_type' => 'pauta', 'post_status' => 'publish'));
$paged = ( array_key_exists('paged', $_POST) && $_POST['paged'] > 0 ) ? $_POST['paged'] : 1;
$args['paged'] = $paged;
$args = apply_filters('delibera_filtros_archive_callback_filter', $args);
query_posts($args);
?>
<div id="lista-de-pautas">
<?php $deliberaThemes->archiveLoop(); // Chama o loop do arquivo ?>
<div id="nav-below" class="navigation">
<?php if ( function_exists( 'wp_pagenavi' ) ) wp_pagenavi(); ?>
</div><!-- #nav-below -->
</div>
<?php
die();
}
add_action('wp_ajax_delibera_filtros_archive', 'delibera_filtros_archive_callback');
add_action('wp_ajax_nopriv_delibera_filtros_archive', 'delibera_filtros_archive_callback');
/**
*
* Retorna array com o filtro de tax para ser usado nas querys do WP
* @param array $dados Exemplo: $_POST deve conter a chave (array)tema_filtro para tema
* @param array $args Query
*/
function delibera_filtros_get_tax_filtro($dados, $args, $field = "slug")
{
$tax_query = array();
if(array_key_exists('tema_filtro', $dados) && is_array($dados['tema_filtro']))
{
$terms = array();
foreach ($dados['tema_filtro'] as $tema)
{
$terms[] = $tema;
}
if(count($terms) > 0)
{
$tax_query[] = array(
'taxonomy' => 'tema',
'field' => $field,
'terms' => $terms,
//'operator' => 'OR'
);
}
}
if(!array_key_exists("tax_query", $args))
{
$args["tax_query"] = array();
}
$args["tax_query"] = array_merge($args["tax_query"], $tax_query);
if(count($args["tax_query"]) > 1)
{
$args["tax_query"]['relation'] = 'AND';
}
return $args;
}
function delibera_filtros_scripts()
{
if(is_pauta())
{
wp_enqueue_script('ui-tooltip',WP_CONTENT_URL.'/plugins/delibera/js/jquery.ui.tooltip.js', array( 'jquery', 'jquery-ui-widget'));
}
}
add_action( 'wp_print_scripts', 'delibera_filtros_scripts' );
?>