/
functions.php
960 lines (721 loc) · 26.1 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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<?php
session_start();
if ( ! isset( $content_width ) )
$content_width = 1000;
add_action( 'after_setup_theme', 'historias_setup' );
function historias_setup() {
/**
* Handle the custom post types
*/
//require_once( get_template_directory() . '/includes/post_type-historias_filmes.php' );
require_once( get_template_directory() . '/includes/post_type_projetos.php' );
//require_once( get_template_directory() . '/includes/post_type-consultant.php' );
require_once( get_template_directory() . '/includes/post_type_foruns.php' );
/**
* We need these for the inscricoes
*/
require_once( get_template_directory() . '/includes/theme-options.php' );
require_once( get_template_directory() . '/vote/vote-functions.php' );
require_once( get_template_directory() . '/includes/shame.php' );
require_once( get_template_directory() . '/includes/customizr.php' );
require_once( get_template_directory() . '/includes/contextual-help.php' );
require_once( get_template_directory() . '/includes/post2home/post2home.php' );
require_once( get_template_directory() . '/includes/estatisticas-inscricoes.php' );
// require_once( get_template_directory() . '/includes/admin-cpfs-cnpjs.php' );
// inscrições
require_once( get_template_directory() . '/inscricoes/inscricoes-functions.php' );
// inscrições
require_once( get_template_directory() . '/relatorios/relatorios-functions.php' );
// classes
require_once( get_template_directory() . '/includes/validator.class.php' );
require_once( get_template_directory() . '/includes/filter.class.php' );
// widgets
require_once( get_template_directory() . '/widgets/cnpc-widget-custom-page.php' );
require_once( get_template_directory() . '/widgets/cnpc-widget-setoriais-menu.php' );
require_once( get_template_directory() . '/widgets/cnpc-widget-login.php' );
// formulário de contato
require_once(get_template_directory() . '/includes/contactform/process.php');
require_once(get_template_directory() . '/includes/contactform/shortcode-contato.php');
require_once(get_template_directory() . '/includes/cnpc_users.class.php');
// torna o tema traduzível
load_theme_textdomain( 'historias', get_template_directory() . '/languages' );
// os arquivos de tradução ficam na pasta /languages/
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// adiciona estilo ao editor
add_editor_style();
// adiciona os links pros feeds padrão
add_theme_support( 'automatic-feed-links' );
/**
* Add excerpt to pages
*/
add_post_type_support( 'page', 'excerpt' );
// adiciona suporte a shortcode nos widgets
add_filter('widget_text', 'do_shortcode');
// adiciona o suporte aos formatos de post
add_theme_support( 'post-formats', array( 'aside', 'chat', 'image', 'gallery', 'link', 'video', 'quote', 'audio', 'status' ) );
// adiciona suporte a imagens destacadas
add_theme_support( 'post-thumbnails' );
add_image_size( 'avatar_candidate', 200, 200, true );
// registra o menu
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'historias' ),
'secondary' => __( 'Secondary Menu', 'historias' ),
'mobile' => __( 'Mobile Menu', 'historias' )
) );
// chama os javascripts
add_action( 'template_redirect', 'historias_load_scripts' );
add_action( 'wp_enqueue_scripts', 'historias_enqueue_styles' );
// registra as áreas de widgets
add_action( 'widgets_init', 'historias_register_sidebars' );
// adiciona o suporte a fundo personalizado
$bg_args = array(
'default-color' => 'fff',
// 'default-image' => get_template_directory_uri() . '/images/default_bg.png',
);
add_theme_support( 'custom-background', $bg_args );
// remove o estilo padrão das galerias
add_filter( 'use_default_gallery_style', '__return_false' );
// filtra os padroes dos uploads
update_option( 'image_default_align','center' );
register_congelado_form('formulario-contato', array(
'nome' => array('not_empty'),
'email' => array('not_empty','is_valid_email'),
'mensagem' => array('not_empty'),
'assunto' => array()
));
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'editor-style.css', str_replace( ',', '%2C', 'http://fonts.googleapis.com/css?family=Sanchez:400italic,400' ) ) );
}
function custom_attachment_link( $link ) {
$link = preg_replace("/('>){1}/", "' target='_blank'>", $link );
return $link;
}
add_filter( 'wp_get_attachment_link', 'custom_attachment_link', 999);
function custom_excerpt_length( $length ) {
return 50;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/**
* Enqueue custom JS using wp_enqueue_script()
*
*/
function historias_load_scripts() {
/**
* Respond.js
* Media queries polyfill
*/
wp_enqueue_script( 'respond', get_template_directory_uri() . '/js/respond.js', '', '1.1.0' );
wp_enqueue_script( 'responsive-nav', get_template_directory_uri() . '/js/responsive-nav.min.js', array( 'jquery' ), '1.0.32', true );
/* Modernizr */
wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/js/modernizr.js', '', '2.6.2' );
/* Slider */
// if ( is_page_template( 'page-templates/home-divulgacao.php' ) )
// wp_enqueue_script( 'swiper', get_template_directory_uri() . '/js/idangerous.swiper-2.1.min.js', array( 'jquery' ), '2.1', true );
/* Load the comment reply JavaScript. */
if ( is_singular() && get_option( 'thread_comments' ) && comments_open() )
wp_enqueue_script( 'comment-reply' );
/* Foruns de discussão e votação */
if ( is_single() ) {
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('jquery-flexslider', get_template_directory_uri().'/js/flexslider-min.js', array('jquery'));
wp_enqueue_script('foruns', get_template_directory_uri() . '/js/foruns.js');
wp_localize_script('foruns', 'vars', array( 'ajaxurl' => admin_url('admin-ajax.php')));
}
/* Para todo o tema */
wp_enqueue_script( 'setoriaiscnpc', get_template_directory_uri() . '/js/setoriaiscnpc.js');
}
/**
* Chama as funções
*
*/
function historias_footer_scripts() {
}
add_action( 'wp_footer', 'historias_footer_scripts', 99 );
function historias_enqueue_styles() {
/* Lovely Google Fonts for body and titles */
// wp_enqueue_style( 'google-fonts', 'http://fonts.googleapis.com/css?family=Sanchez:400italic,400' ) ;
/* JUDO Font Awesome for the icons */
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' );
}
function historias_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'historias' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'historias_wp_title', 10, 2 );
function historias_share() {
global $post; ?>
<div class="entry-share clearfix">
<input type="text" class="share-shortlink" value="<?php echo wp_get_shortlink( get_the_ID() ); ?>" onclick="this.focus(); this.select();" readonly="readonly" />
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
<a href="<?php comments_link(); ?>" class="comments-link"><i class="fa fa-comment"></i> <?php echo comments_number( __('Leave a reply','historias'), __('One comment','historias'), __('% comments','historias') ); ?></a>
<?php endif; ?>
</div>
<?php
}
function historias_postedby() {
global $post;
?>
<span class="author vcard">
<?php if ( is_multi_author() ) {
the_author_posts_link();
} else {
the_author();
} ?>
</span>
<?php
}
// filtra a data para que o human_time_diff apenas apareça em posts com menos de um mês
function historias_the_time() {
global $post;
$time = mysql2date( 'G', $post->post_date );
$time_diff = time() - $time; ?>
<span class="entry-date">
<?php if ( ! is_single() && ( $time_diff > 0 && $time_diff < 30*24*60*60 ) )
printf( __( '%s ago', 'historias' ), human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) );
else
the_time( get_option( 'date_format' ) );
?>
</span>
<?php }
function historias_content_nav( $nav_id ) {
global $wp_query;
$nav_class = 'paging-navigation';
if ( is_single() )
$nav_class = 'post-navigation';
?>
<nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>">
<h1 class="assistive-text"><?php _e( 'Post navigation', 'historias' ); ?></h1>
<?php if ( is_single() ) : ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<i class="fa fa-arrow-left"></i> %title' ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<i class="fa fa-arrow-right"></i> %title' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( sprintf( __('%s Older posts', 'historias' ), '<i class="fa fa-arrow-left"></i>' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( sprintf( __('%s Newer posts', 'historias' ), '<i class="fa fa-arrow-right"></i>' ) ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- /<?php echo $nav_id; ?> -->
<?php
}
// ativa as áreas de widgets
function historias_register_sidebars() {
// lateral 1
register_sidebar( array (
'name' => __( 'Primary Widget Area','historias' ),
'description' => __( 'Its the coloured one.','historias' ),
'id' => 'primary-widget-area',
'before_widget' => '<aside id="%1$s" class="widget widget--negative %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget__title">',
'after_title' => '</h3>',
) );
register_sidebar( array (
'name' => __( 'Front Page Widget Area','historias' ),
'description' => __( 'Front page.','historias' ),
'id' => 'front-page-widget-area',
'before_widget' => '<aside id="%1$s" class="widget widget--negative %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget__title">',
'after_title' => '</h3>',
) );
}
/**
* Adiciona os favicons aos pingbacks & trackbacks
*
*/
function historias_get_favicon( $url = '' ) {
if ( ! empty ( $url ) )
$url = parse_url( $url );
$url = 'http://www.google.com/s2/favicons?domain=' . $url['host'];
return $url;
}
function historias_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
$is_candidate = is_valid_candidate($comment->user_id);
// $is_candidate = get_user_meta( $comment->user_id, 'e_candidato', true);
$class = ( $is_candidate==1 ) ? 'candidate' : '';
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="pingback">
<?php if(function_exists('historias_get_favicon')) { ?><img src="<?php echo historias_get_favicon( $comment->comment_author_url ); ?>" alt="Favicon" class="favicon" /><?php } ?><?php comment_author_link(); ?><?php edit_comment_link( sprintf( __( '%s Edit', 'historias' ), '<i class="fa fa-pencil"></i>' ) ); ?>
<?php
break;
default :
?>
<li <?php comment_class($class); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment-container">
<div class="vcard">
<div class="comment-author-avatar">
<?php if( $is_candidate == 1 ) : ?>
<?php echo get_avatar_candidate( $comment->user_id ); ?>
<?php else: ?>
<?php echo get_avatar( $comment, 96 ); ?>
<?php endif; ?>
</div>
</div>
<header class="comment-meta">
<cite class="fn">
<?php if( $is_candidate == 1 ) : ?>
<span class="entry-author"><a href="<?php echo get_link_forum_user( $comment->user_id ); ?>"><?php echo get_display_name_candidate( $comment->user_id ); ?> </a> - candidato(a)</span>
<?php else: ?>
<span class="entry-author"><?php echo get_comment_author_link(); ?></span>
<?php endif; ?>
<span class="entry-date"><?php echo get_comment_date(); ?> / <?php echo get_setorial_and_uf_user($comment->user_id); ?></span>
</cite>
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => 'Responder', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
<?php edit_comment_link( sprintf( __( '%s Edit', 'historias' ), '<i class="fa fa-pencil"></i>' ) ); ?>
</header>
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- /comment-content -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-on-hold"><?php _e( 'Your comment is awaiting moderation.', 'historias' ); ?></em>
<?php endif; ?>
</article><!-- /comment -->
<?php
break;
endswitch;
}
add_filter('img_caption_shortcode', 'historias_img_caption_shortcode',10,3);
function historias_img_caption_shortcode($val, $attr, $content = null) {
extract(shortcode_atts(array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $val;
$capid = '';
if ( $id ) {
$id = esc_attr($id);
$capid = 'id="figcaption_'. $id . '" ';
$id = 'id="' . $id . '" aria-labelledby="figcaption_' . $id . '" ';
}
return '<figure ' . $id . 'class="wp-caption ' . esc_attr($align) . '">' . do_shortcode( $content ) . '<figcaption ' . $capid
. 'class="wp-caption-text">' . $caption . '</figcaption></figure>';
}
/**
* Returns true if a blog has more than 1 category
*
* @since Jecebel 3.0
*/
function historias_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
// This blog has more than 1 category so historias_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so historias_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in historias_categorized_blog
*
* @since Jecebel 3.0
*/
function historias_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'historias_category_transient_flusher' );
add_action( 'save_post', 'historias_category_transient_flusher' );
/**
* Retorna os logins digitados dentro do custom field
*
*/
function historias_get_users() {
global $post;
$equipe = get_post_meta( $post->ID, 'historias_users', true );
if ( $equipe ) {
// Transforma em minúsculas e cria um array
$equipe = strtolower( $equipe );
$equipe = explode( ',', $equipe );
return $equipe;
}
}
/**
* Verifica se o usuário preencheu sua descrição e só então a mostra
*
*/
function historias_user_description( $description ) {
if ( !empty( $description ) ) {
$output = '<div class="member-description">';
$output .= $description;
$output .= '</div>';
echo $output;
}
}
/**
* Return the post format (if not Standard)
*
*/
function historias_the_format() {
global $post;
$format = get_post_format();
$pretty_format = get_post_format_string($format);
$permalink = get_permalink();
if( $format ) echo '<a href="' . $permalink . '" class="entry-format">' . $pretty_format . '</a>';
}
/**
* Add an option to gallery images with no links
*/
add_shortcode( 'gallery', 'new_gallery_shortcode' );
function new_gallery_shortcode($attr) {
global $post, $wp_locale;
$output = gallery_shortcode($attr);
if($attr['link'] == "none") {
$output = preg_replace(array('/<a[^>]*>/', '/<\/a>/'), '', $output);
}
return $output;
}
/**
* A default menu for when they don't have one set.
* Everybody sees a page list + the admins see a message about setting up the
* menus in admin
*
*/
function default_menu() { ?>
<ul id="menu-main" class="menu--main menu clearfix">
<?php if ( is_user_logged_in() && current_user_can( 'level_10' ) ) : ?>
<li><a href="<?php bloginfo('url'); ?>/wp-admin/nav-menus.php"><?php _e('Hey admin, don\'t forget to set up a menu!', 'historias' ); ?></a></li>
<?php endif; ?>
<?php wp_list_pages('title_li='); ?>
<?php wp_list_categories('title_li='); ?>
</ul>
<?php }
/**
* Load Meta Box for the "Capa/Inscricoes" Template
*/
require get_template_directory() . '/includes/meta_box-feature-url.php';
/**
* Load Meta Box for the Front Page
*/
require get_template_directory() . '/includes/meta_box-feature-text.php';
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// EMAILS SENDER /////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
add_filter( 'wp_mail_from_name', 'hqf_mail_sender_name' );
function hqf_mail_sender_name($from_name) {
return get_option('blogname');
}
add_filter( 'wp_mail_from', 'hqf_mail_sender' );
function hqf_mail_sender($from_name) {
return 'nao-responder-votacultura@cultura.gov.br';
}
function get_all_states() {
return array(
'AC'=>'Acre',
'AL'=>'Alagoas',
'AM'=>'Amazonas',
'AP'=>'Amapá',
'BA'=>'Bahia',
'CE'=>'Ceará',
'DF'=>'Distrito Federal',
'ES'=>'Espírito Santo',
'GO'=>'Goiás',
'MA'=>'Maranhão',
'MT'=>'Mato Grosso',
'MS'=>'Mato Grosso do Sul',
'MG'=>'Minas Gerais',
'PA'=>'Pará',
'PB'=>'Paraíba',
'PR'=>'Paraná',
'PE'=>'Pernambuco',
'PI'=>'Piauí',
'RJ'=>'Rio de Janeiro',
'RN'=>'Rio Grande do Norte',
'RS'=>'Rio Grande do Sul',
'RO'=>'Rondônia',
'RR'=>'Roraima',
'SC'=>'Santa Catarina',
'SP'=>'São Paulo',
'SE'=>'Sergipe',
'TO'=>'Tocantins'
);
}
function dropdown_states( $name, $selected = null, $all = false, $extra = null )
{
$states = get_all_states();
$output = "<select id='{$name}' name='{$name}' {$extra}>";
if( $all )
$output .= "<option value=''>----------</option>";
foreach( $states as $acronym => $state )
{
$att = '';
if( $acronym == $selected )
$att = 'selected="selected"';
$output .= "<option value='{$acronym}' {$att}>{$state}</option>";
}
$output .= "</select>";
return $output;
}
function get_state_name_by_uf( $uf ) {
$states = get_all_states();
if( isset( $states[$uf] ) )
return $states[$uf];
}
function show_text_state_by_uf( $uf ) {
$uf = strtoupper($uf);
switch($uf) {
case 'BA':
case 'PB':
$text = 'da';
break;
case 'AL':
case 'GO':
case 'MT':
case 'MS':
case 'MG':
case 'PE':
case 'RO':
case 'RR':
case 'SC':
case 'SP':
case 'SE':
$text = 'de';
break;
case 'AP':
case 'AM':
case 'CE':
case 'DF':
case 'ES':
case 'MA':
case 'PA':
case 'PR':
case 'PI':
case 'RJ':
case 'RN':
case 'RS':
case 'TO':
$text = 'do';
break;
default:
$text = 'do';
}
return $text .' '. get_state_name_by_uf($uf) .' ('. $uf .')';
}
function get_setoriais() {
return array(
'arquitetura-urbanismo' => 'Arquitetura e Urbanismo',
'arquivos' => 'Arquivos',
'arte-digital' => 'Arte Digital',
'artes-visuais' => 'Artes Visuais',
'artesanato' => 'Artesanato',
'circo' => 'Circo',
'afro-brasileiro' => 'Culturas Afro-Brasileiras',
'culturas-populares' => 'Culturas Populares',
'danca' => 'Dança',
'design' => 'Design',
'literatura-livro-leitura' => 'Literatura, Livro e Leitura',
'moda' => 'Moda',
'musica' => 'Música',
'patrimonio-imaterial' => 'Patrimônio Imaterial',
'patrimonio-material' => 'Patrimônio Material',
'teatro' => 'Teatro'
);
}
function get_label_setorial_by_slug( $slug ) {
$setoriais = get_setoriais();
if( isset( $setoriais[$slug] ) )
return $setoriais[$slug];
}
/**
* show a menu dropdown from the setorial
*
* @name dropdown_states
* @return string
*/
function dropdown_setoriais( $name, $selected = null, $all = false, $extra = null )
{
$setoriais = get_setoriais();
$output = "<select id='{$name}' name='{$name}' {$extra}>";
if( $all )
$output .= "<option value=''>----------</option>";
foreach( $setoriais as $acronym => $setorial )
{
$att = '';
if( $acronym == $selected )
$att= 'selected="selected"';
$output .= "<option value='{$acronym}' {$att}>{$setorial}</option>";
}
$output .= "</select>";
return $output;
}
/**
* return races
*
* @name get_races
* @return array
*/
function get_races() {
return array(
'branco' => 'Branco',
'preto' => 'Preto',
'pardo' => 'Pardo',
'amarelo' => 'Amarelo',
'indigena' => 'Indigena',
'sem-declaracao' => 'Sem declaração'
);
}
/**
* show a menu dropdown from the setorial
*
* @name dropdown_states
* @return select
*/
function dropdown_races( $name, $selected = null, $all = false, $extra = null ) {
$races = get_races();
$output = "<select id='{$name}' name='{$name}' {$extra}>";
if( $all )
$output .= "<option value=''>----------</option>";
foreach( $races as $acronym => $race )
{
$att = '';
if( $acronym == $selected )
$att= 'selected="selected"';
$output .= "<option value='{$acronym}' {$att}>{$race}</option>";
}
$output .= "</select>";
return $output;
}
/**
* return genres
*
* @name get_generos
* @return array
*/
function get_genres() {
return array(
'masculino' => 'Masculino',
'feminino' => 'Feminino'
);
}
/**
* show a menu dropdown of genre
*
* @name dropdown_genres
* @return select
*/
function dropdown_genres( $name, $selected = null, $all = false, $extra = null )
{
$genres = get_genres();
$output = "<select id='{$name}' name='{$name}' {$extra}>";
if( $all )
$output .= "<option value=''>----------</option>";
foreach( $genres as $acronym => $genre )
{
$att = '';
if( $acronym == $selected )
$att= 'selected="selected"';
$output .= "<option value='{$acronym}' {$att}>{$genre}</option>";
}
$output .= "</select>";
return $output;
}
function convert_format_date( $d ) {
if( empty($d))
return false;
$format = "d/m/Y";
$dateTime = DateTime::createFromFormat($format, $d);
return $dateTime->format("Y-m-d");
}
function restore_format_date( $d ) {
if( !empty( $d ) ) {
$format = "Y-m-d";
$dateTime = DateTime::createFromFormat($format, $d);
return $dateTime->format("d/m/Y");
}
return false;
}
function user_short_name( $name = null ) {
if( is_user_logged_in() ) {
global $current_user;
if( empty( $name ) )
$name = $current_user->display_name;
preg_match( '/^([^\s]+)/', $name, $matches);
return ucfirst(strtolower($matches[0]));
} else
return "visitante";
}
function get_link_forum_user( $user_id=null ) {
$uf_setorial = get_user_option( 'uf-setorial', $user_id );
if( !empty( $uf_setorial ) )
return site_url('foruns/' . $uf_setorial );
return false;
}
function get_setorial_and_uf_user( $user_id ) {
$uf_setorial = get_user_option( 'uf-setorial', $user_id );
return get_label_setorial_by_slug( substr( $uf_setorial, 3) ) . ' - ' . substr( $uf_setorial, 0, 2 );
}
add_filter( 'preprocess_comment', 'cnpc_preprocess_comment' );
function cnpc_preprocess_comment($comment) {
if ( strlen( $comment['comment_content'] ) > 8000 ) {
wp_die( 'Seu comentário é muito grande. A quantidade máxima permitida é de 8.000 caracteres', 'Comentário grande', array( 'back_link' => true ) );
}
return $comment;
}
/*
Copyright 2012 George Notaras <gnot@g-loaded.eu>, CodeTRAX.org
*/
function rpcif__set_client_ip()
{
/**
* Security Note
* -------------
* We ultimately trust the IPs provided in the X-Forwarded-For header.
* The reliability of the X-Forwarded-For header should be checked
* at the reverse proxy level.
*/
// Use IP set in the REMOTE_ADDR server variable by default
$CLIENT_IP = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['X_FORWARDED_FOR'])) {
$X_FORWARDED_FOR = explode(',', $_SERVER['X_FORWARDED_FOR']);
}
// Extra check taken from The WordPress Codex at:
// http://codex.wordpress.org/Plugin_API/Filter_Reference/pre_comment_user_ip
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$X_FORWARDED_FOR = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
}
// If we got a
if (!empty($X_FORWARDED_FOR)) {
$CLIENT_IP = trim($X_FORWARDED_FOR[0]);
//$CLIENT_IP = preg_replace('/[^0-9a-f:\., ]/si', '', $CLIENT_IP);
}
return $CLIENT_IP;
}
add_filter ('pre_comment_user_ip', 'rpcif__set_client_ip');
?>