-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
551 lines (476 loc) · 16.2 KB
/
functions.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<?php
/**
* Pontos de Cultura functions and definitions
*
* @package Pontos de Cultura
* @since Pontos de Cultura 1.0
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */
}
if ( ! function_exists( 'pontosdecultura_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function pontosdecultura_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on _s, use a find and replace
* to change '_s' to the name of your theme in all the template files
*/
load_theme_textdomain( 'pontosdecultura', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
//add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Secondary Menu', 'pontosdecultura' ),
) );
// Enable support for Post Formats.
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
// Enable support for HTML5 markup.
add_theme_support( 'html5', array(
'comment-list',
'search-form',
'comment-form',
'gallery',
'caption',
) );
}
endif; // pontosdecultura_setup
add_action( 'after_setup_theme', 'pontosdecultura_setup' );
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function pontosdecultura_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'pontosdecultura' ),
'id' => 'sidebar-main',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area', 'pontosdecultura' ),
'id' => 'sidebar-footer',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'pontosdecultura_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function pontosdecultura_scripts() {
// Normalize.css
wp_register_style( 'pontosdecultura-normalize', get_template_directory_uri() . '/css/normalize.css', array(), '3.0.1' );
wp_enqueue_style( 'pontosdecultura-normalize' );
// General style
wp_enqueue_style( 'pontosdecultura-style', get_stylesheet_uri() );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'pontosdecultura_scripts' );
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Add a custom logo for the login screen
*
*/
function pontosdecultura_custom_login_logo() {
echo '
<style type="text/css">
.login h1 a {
background: url("' . get_template_directory_uri() . '/images/logo-cultura-viva.png") top center no-repeat;
background-size: contain;
margin: 0 auto;
height: 150px;
width: 150px;
}
</style>';
}
add_action( 'login_head', 'pontosdecultura_custom_login_logo', 11 );
class Pontosdecultura {
/**
* Registra actions do wordpress
*
*/
public function __construct()
{
add_action('wp_enqueue_scripts', array($this, 'javascript'));
add_filter('nav_menu_css_class', array($this, 'nav_menu_css_class'));
add_action('wp_enqueue_scripts', array($this, 'map_scritps'));
add_filter('mapasdevista_filters_show_tax_title', array($this, 'mapasdevista_filters_show_tax_title'));
add_action( 'wp_ajax_home_search', array($this, 'home_search_callback') );
add_action( 'wp_ajax_nopriv_home_search', array($this, 'home_search_callback') );
add_action( 'wp_ajax_map_results', array($this, 'map_results_callback') );
add_action( 'wp_ajax_nopriv_map_results', array($this, 'map_results_callback') );
add_action( 'wp_ajax_select_cidade', array($this, 'select_cidade_callback') );
add_action( 'wp_ajax_nopriv_select_cidade', array($this, 'select_cidade_callback') );
add_action( 'wp_ajax_pontos_load_post', array($this, 'pontos_load_post_callback') );
add_action( 'wp_ajax_nopriv_pontos_load_post', array($this, 'pontos_load_post_callback') );
add_filter('mapasdevista_mapinfo_localize_script', array($this, 'mapinfo_localize_script'));
add_filter('mapasdevista_load_bubbles', array($this, 'mapasdevista_load_bubbles'));
add_filter('mapasdevista_load_style', array($this, 'mapasdevista_load_style'));
add_filter('mapasdevista_create_post_overlay', array($this, 'mapasdevista_create_post_overlay'));
add_action( 'wp_ajax_filter_select_cidade', array($this, 'filter_select_cidade_callback') );
add_action( 'wp_ajax_nopriv_filter_select_cidade', array($this, 'filter_select_cidade_callback') );
add_filter('mapasdevista_map_div', array($this, 'mapasdevista_map_div'));
}
public static function mapasdevista_create_post_overlay($load)
{
global $wp_query;
if(is_home())
{
return false;
}
return $load;
}
public static function mapasdevista_load_bubbles($load)
{
global $wp_query;
if(is_home() && !$wp_query->get('mapa-tpl'))
{
return false;
}
return $load;
}
public static function mapinfo_localize_script($mapinfo)
{
global $wp_query;
if(is_home() && !$wp_query->get('mapa-tpl'))
{
$mapinfo['loadPosts'] = false;
}
return $mapinfo;
}
public static function mapasdevista_load_style($load)
{
return false;
}
public static function mapasdevista_map_div($mapDiv)
{
global $wp_query;
if(is_home() && $wp_query->get('mapa-tpl'))
{
return '
<div id="post_overlay">
<a id="pontos_close_post_overlay" title="Fechar">'.
'<img src="'.mapasdevista_get_image("close.png").'" alt="Fechar" /></a>
<div id="post_overlay_content" class="post_overlay_content" >
</div>
</div>
<div id="map" class="map-fullscreen">
</div>
';
}
return $mapDiv;
}
/**
* Controla os arquivos javascript do site
*
*/
public function javascript(){
$path = get_template_directory_uri() . '/js';
global $wp_query;
wp_register_script('map-functions', $path . '/map-functions.js', array('jquery'));
wp_register_script('homescripts', $path . '/home.js', array('jquery', 'jquery-ui-core', 'jquery-ui-progressbar', 'map-functions'));
wp_register_script('jqloader', get_template_directory_uri() . '/lib/jqloader/jqloader.debug.js', array('jquery'));
wp_register_style('jqloader', get_template_directory_uri() . '/lib/jqloader/jqloader.debug.css');
wp_register_script('map-page-scripts', $path . '/map-page-scripts.js', array('jquery', 'map-functions'));
if(is_home() && !$wp_query->get('mapa-tpl'))
{
wp_enqueue_script('homescripts');
wp_enqueue_script('jqloader');
wp_enqueue_style('jqloader');
wp_localize_script( 'homescripts', 'homescripts_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' )) );
}
elseif(is_home() && $wp_query->get('mapa-tpl'))
{
wp_enqueue_script('map-page-scripts');
/*wp_localize_script( 'mapscripts', 'mapscripts',
array( 'ajax_url' => admin_url( 'admin-ajax.php' )) );*/
}
if(is_home()) // has map
{
wp_enqueue_script('map-functions');
}
}
public static function language_selector()
{
if(function_exists('icl_get_languages'))
{
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages))
{
echo '<div id="pontosdecultura_language_selector" onclick="pontosdecultura_language_selector_swapper();">';
$l = array();
foreach($languages as $language)
{
if(count($l) == 0)
{
$l = $language;
$f = $l['url'];
continue;
}
/*if(!$l['active']) echo '<a href="'.$l['url'].'">';
echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
if(!$l['active']) echo '</a>';*/
echo '<a href="'.$language['url'].'"><span '.($l['active'] ? '' : 'style="display:none"').'>'.$l['translated_name'].'</span></a>';
$l = $language;
}
if(count($l) > 0) echo '<a href="'.$f.'"><span '.($l['active'] ? '' : 'style="display:none"').'>'.$l['translated_name'].'</span></a>';
echo '</div>';
}
}
}
public function nav_menu_css_class($classes)
{
$classes[] = 'span';
return $classes;
}
/**
* Display the map
*
* @since pontosdecultura 1.0
*/
public static function the_map() {
if(function_exists('mapasdevista_view'))
{
mapasdevista_view();
}
}
/**
* Display the map filters on home
*
* @since pontosdecultura 1.0
*
*/
public static function the_map_filters() {
if(function_exists('mapasdevista_view'))
{
?>
<div id="map-filters">
<div id="filter-cycle-prev" class="filter-cycle-prev cycle-prev filter-cycle-button" ></div>
<?php
mapasdevista_view_filters('categoria-mapa');
?>
<div id="filter-cycle-next" class="filter-cycle-next cycle-next filter-cycle-button" ></div>
<div id="filter-link-to-map" class="filter-link-to-map" ><a href="<?php echo get_bloginfo('url').'/mapa'; ?>">
<img src="<?php echo get_template_directory_uri().'/images/expand.png'; ?>" alt="<?php _e('Veja o mapa completo', 'pontosdecultura'); ?>" title="<?php _e('Veja o mapa completo', 'pontosdecultura'); ?>" />
</a></div>
</div>
<?php
}
}
public static function map_scritps()
{
if(function_exists('mapasdevista_view') && !get_query_var('mapa-tpl') && get_theme_mod('pontosdecultura_display_home_map_filters') == 1)
{
wp_enqueue_script('jquery-cycle2', get_template_directory_uri() . '/js/jquery.cycle2.min.js', array('jquery'));
wp_enqueue_script('jquery-cycle2-carousel', get_template_directory_uri() . '/js/jquery.cycle2.carousel.min.js', array('jquery-cycle2'));
wp_enqueue_script('jquery-cycle2-swipe', get_template_directory_uri() . '/js/jquery.cycle2.swipe.min.js', array('jquery-cycle2'));
wp_enqueue_script('map_filters_scroller', get_template_directory_uri() . '/js/map_filters_scroller.js', array('jquery-cycle2'));
}
}
//add_action('wp_enqueue_scripts', 'pontosdecultura_map_scritps');
public static function mapasdevista_filters_show_tax_title($show)
{
return false;
}
//add_filter('mapasdevista_filters_show_tax_title', 'pontosdecultura_mapasdevista_filters_show_tax_title');
function home_search_callback()
{
/* @var $wpdb wpdb */
global $wpdb; // this is how you get access to the database
$s = sanitize_text_field( $_POST['s'] );
$post_type = 'mapa';
$querystr = "
SELECT $wpdb->posts.ID FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE
$wpdb->posts.post_type = 'mapa'
AND (
$wpdb->terms.name like '%$s%'
OR $wpdb->posts.post_title like '%$s%'
OR $wpdb->posts.post_content like '%$s%'
OR $wpdb->posts.post_excerpt like '%$s%'
OR $wpdb->postmeta.meta_value like '%$s%'
)
GROUP BY $wpdb->posts.ID
ORDER BY $wpdb->posts.ID asc
";
$posts = $wpdb->get_results($querystr, ARRAY_N);
/*echo '<div id="results" class="clearfix">';
echo '<pre>';
//echo $querystr;
print_r($posts);
echo '</pre>';
echo '</div>';*/
echo json_encode($posts);
if(count($posts) > 0)
{
$pontosdecultura_home_searches = get_option('pontosdecultura_home_searches', array());
if(array_key_exists(sanitize_title($s), $pontosdecultura_home_searches))
{
$pontosdecultura_home_searches[sanitize_title($s)]->count++;
}
else
{
$term_obj = new stdClass();
$term_obj->term_id = 0; //5745
$term_obj->name = $s; //Conhecimento e Tradições Orais
$term_obj->slug = sanitize_title($term_obj->name); //conhecimento-e-tradicoes-orais
$term_obj->term_group = 0; //0
$term_obj->term_taxonomy_id = 0; //5754
$term_obj->taxonomy = "false"; //tematico
$term_obj->description = ""; //
$term_obj->parent = 0; //0
$term_obj->count = 1;
$term_obj->link = $term_obj->slug;
$term_obj->id = $term_obj->term_id;
$pontosdecultura_home_searches[sanitize_title($term_obj->name)] = $term_obj;
}
update_option('pontosdecultura_home_searches', $pontosdecultura_home_searches);
}
die(); // this is required to return a proper result
}
public static function map_results_callback()
{
echo '<div id="search-result-list" class="search-result-list gr gr-small">';
mapasdevista_view_results();
echo '</div>';
die();
}
public static function select_cidade_callback()
{
?>
<select name="adv-search-cidade" class="adv-search-cidade">
<option value="" selected="selected" ><?php echo esc_attr_x('Cidade', 'pontosdecultura' ); ?></option>
<?php
if(array_key_exists('uf', $_POST) && !empty($_POST['uf']))
{
$parent = get_term_by('slug', $_POST['uf'], 'territorio');
if(is_object($parent))
{
$terms = get_terms('territorio', array('child_of' => $parent->term_id, 'orderby' => 'name'));
foreach ($terms as $term)
{
?>
<option value="<?php echo $term->slug; ?>" ><?php echo $term->name; ?></option>
<?php
}
}
}
?>
</select>
<?php
die();
}
public static function filter_select_cidade_callback()
{
?>
<select name="filter-panel-cidade" class="filter-panel-cidade">
<option value="" selected="selected" ><?php echo esc_attr_x('Cidade', 'pontosdecultura' ); ?></option>
<?php
if(array_key_exists('uf', $_POST) && !empty($_POST['uf']))
{
$parent = get_term_by('slug', $_POST['uf'], 'territorio');
if(is_object($parent))
{
$terms = get_terms('territorio', array('child_of' => $parent->term_id, 'orderby' => 'name'));
foreach ($terms as $term)
{
if($term->count > 0)
{
?>
<option value="<?php echo $term->slug; ?>" ><?php echo $term->name; ?></option>
<?php
}
}
}
}
?>
</select>
<?php
die();
}
public static function pontos_load_post_callback()
{
$p = $_POST['post_id'];
if (!is_numeric($p))
die('error');
query_posts('post_type=any&p='.$p);
?>
<div class="single single-mapa postid-2915 single-format-standard logged-in admin-bar group-blog singular customize-support">
<div class="site-wrapper hfeed">
<div id="content" class="site-content site-area">
<div class="container">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main"><?php
if (have_posts())
{
while (have_posts())
{
the_post();
global $post;
include dirname(__FILE__).'/content-mapa.php';
if ( comments_open() || '0' != get_comments_number() ) :
comments_template();
endif;
}
}
else
{
die('error');
}
?>
</main><!-- #main -->
</div><!-- #primary -->
</div>
</div>
</div>
</div>
<?php
die();
}
}
$pontosdecultura = new Pontosdecultura();
/** Lib estadocidades **/
include_once dirname(__FILE__).'/lib/estadoscidades/taxs.php';
/** Opções do Tema **/
include_once dirname(__FILE__).'/inc/options.php';
/** Taxs do Pontos **/
include_once dirname(__FILE__).'/inc/taxs.php';
?>