forked from martinosmartinos/Mongabay-Wordpress-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
1254 lines (1101 loc) · 53.8 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
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include (get_template_directory().'/custom-code/url-rewrites.php');
include (get_template_directory().'/custom-code/figure-caption.php');
include (get_template_directory().'/custom-code/taxonomy-location.php');
include (get_template_directory().'/custom-code/taxonomy-serial.php');
include (get_template_directory().'/custom-code/taxonomy-topic.php');
include (get_template_directory().'/custom-code/thumbnailed-recent-posts.php');
include (get_template_directory().'/custom-code/feed-query.php');
include (get_template_directory().'/custom-code/meta.php');
include (get_template_directory().'/custom-code/menus.php');
include (get_template_directory().'/custom-code/analytics.php');
if (function_exists('add_theme_support'))
{
add_theme_support('menus');
add_theme_support( 'post-formats', array( 'aside' ) );
add_theme_support('post-thumbnails');
add_image_size('large', 1200, 800, true); // Large Thumbnail
add_image_size('medium', 768, 512, true); // Medium Thumbnail
add_image_size('cover-image', 1280, 450, true); // Cover Thumbnail
add_image_size('thumbnail', 100, 100, true); // Small Thumbnail
load_theme_textdomain('mongabay', get_template_directory() . '/languages');
}
/*------------------------------------*\
Functions
\*------------------------------------*/
//Spot.im script function
function mongabay_comments() {
$site_id = get_current_blog_id();
$post_id = get_the_ID();
$spot_id = '';
switch ($site_id) {
case '20':
$spot_id = 'sp_8TLFqmLV';
break;
case '23':
$spot_id = 'sp_A3SnHcgH';
break;
case '24':
$spot_id = 'sp_ZwMqGXOu';
break;
case '25':
$spot_id = 'sp_1xRecNST';
break;
case '26':
$spot_id = 'sp_sbJbR9zO';
break;
case '27':
$spot_id = 'sp_NNvA5Ksj';
break;
case '28':
$spot_id = 'sp_elj4Klyl';
break;
case '29':
$spot_id = 'sp_yZlmuqld';
break;
case '30':
$spot_id = 'sp_uf34MHbE';
break;
};
print '<script async src="https://recirculation.spot.im/spot/'.$spot_id.'"></script>
<div data-spotim-module="recirculation" data-spot-id="'.$spot_id.'"></div><script async data-spotim-module="spotim-launcher" src="https://launcher.spot.im/spot/'.$spot_id.'" data-post-id="'.$post_id.'"></script>';
}
// Get current host
function mongabay_subdomain_name() {
$parsedUrl = parse_url($_SERVER['SERVER_NAME']);
$host = explode('.', $parsedUrl['path']);
$domain = $host[0];
return $domain;
}
// Main WP_query modifier to process multiple vars
function mongabay_mega_query($query) {
if ($query->is_home() && $query->is_main_query() && ! is_admin()) {
$home_url = esc_url( home_url( '/' ) );
$section = get_query_var('section');
$firstvar = get_query_var('nc1');
$secondvar = get_query_var('nc2');
if(get_current_blog_id() == 1) {
switch_to_blog(20);
$query->set('post_type', 'post');
}
if(get_current_blog_id() == 22) {
$tax_query = array(array('taxonomy' => 'topic', 'field' => 'slug', 'terms' => 'technology'));
switch_to_blog(20);
$query->set('tax_query', $tax_query);
}
if(get_current_blog_id() == 31) {
$tax_query = array(array('taxonomy' => 'location', 'field' => 'slug', 'terms' => 'sri-lanka'));
switch_to_blog(20);
$query->set('tax_query', $tax_query);
}
if(get_current_blog_id() == 32) {
$tax_query = array(array('taxonomy' => 'location', 'field' => 'slug', 'terms' => 'africa'));
switch_to_blog(20);
$query->set('tax_query', $tax_query);
}
if(get_current_blog_id() == 33) {
$tax_query = array(array('taxonomy' => 'location', 'field' => 'slug', 'terms' => 'madagascar'));
switch_to_blog(20);
$query->set('tax_query', $tax_query);
}
if(get_current_blog_id() == 34) {
$tax_query = array(array('taxonomy' => 'location', 'field' => 'slug', 'terms' => 'philippines'));
switch_to_blog(20);
$query->set('tax_query', $tax_query);
}
if($section == 'moved') {
$moved_query = array('post_type' => 'post', 'posts_per_page' => 1, 'offset' => 0, array('key' => 'mongabay_post_legacy_url', 'value' => $secondvar, 'compare' => '='));
$query->set('meta_query', $moved_query);
}
if($section == 'list' && empty($firstvar)) {
wp_redirect( $home_url );
exit;
}
if($section == 'list' && !empty($firstvar) && empty($secondvar)) {
$item1 = get_terms(array('topic','location'), array('slug' => $firstvar));
$tax_query = array(
array(
'taxonomy' => $item1[0]->taxonomy,
'field' => 'slug',
'terms' => $item1[0]->slug
)
);
$query->set('tax_query', $tax_query);
}
if($section == 'list' && !empty($firstvar) && !empty($secondvar)) {
$item1 = get_terms(array('topic','location'), array('slug' => $firstvar));
$item2 = get_terms(array('topic','location'), array('slug' => $secondvar));
$tax_query = array(
'relation' => 'AND',
array(
'taxonomy' => $item1[0]->taxonomy,
'field' => 'slug',
'terms' => $item1[0]->slug
),
array(
'taxonomy' => $item2[0]->taxonomy,
'field' => 'slug',
'terms' => $item2[0]->slug
)
);
$query->set('tax_query', $tax_query);
if($item1[0]->taxonomy=='location' && $item2[0]->taxonomy=='topic') {
wp_redirect( $home_url.'list/'.$secondvar.'/'.$firstvar );
exit;
}
}
}
}
//fix topics links
function mongabay_topic_link( $link, $term, $taxonomy )
{
if ( $taxonomy !== 'topic' )
return $link;
return str_replace( 'topic/', 'list/', $link );
}
//fix locations links
function mongabay_location_link( $link, $term, $taxonomy )
{
if ( $taxonomy !== 'location' )
return $link;
return str_replace( 'location/', 'list/', $link );
}
//fix byline links
function mongabay_byline_link( $link, $term, $taxonomy )
{
if ( $taxonomy !== 'byline' )
return $link;
return str_replace( 'byline/', 'by/', $link );
}
/*
leave
that
space
so
translation
is
not
shifting
*/
// special series section function. Usage mongabay_series_section (array('slug1','slug2','slug3'), 3) where 3 is number of posts
function mongabay_series_section ( $names, $number) {
echo '<div id="special-series">';
if(mongabay_layout() == 'container-fluid') echo '<div class="container">';
$count = 0;
if(get_current_blog_id() == 1) switch_to_blog(20);
foreach ($names as $name) {
$count = $count + 1;
$title = ucfirst(str_replace('-', ' ', $name));
switch ($count) {
case '1': ?>
<div class="row"><h2><?php _e( 'Special series', 'mongabay' ); ?></h2>
<?php break;
case '5': ?>
<div class="spacer clearfix"></div>
<div class="row">
<?php break;
} ?>
<div class="col-lg-3">
<h4><?php echo $title; ?></h4>
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => $number,
'tax_query' => array(
array(
'taxonomy' => 'serial',
'field' => 'slug',
'terms' => $name,
),
),
);
$query = new WP_Query( $args );
if ($query->have_posts()) { ?>
<ul>
<?php
$counter = 0;
while ( $query->have_posts() ) : $query->the_post();
$counter = $counter + 1; ?>
<li class="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<div class="thumbnail-series">
<img src="<?php echo get_template_directory_uri(); ?>/img/series/<?php echo $name; ?>.jpg" alt="<?php echo $title; ?>"/>
</div>
<?php
}
wp_reset_postdata(); ?>
<div class="more-special">
<a href="<?php echo esc_url( home_url( '/' ) ).'series/'.$name; ?>"><?php _e('More articles', 'mongabay'); ?></a>
</div>
</div>
<?php if ($count == 4 || $count == 8) { ?>
</div>
<?php }
} ?>
<?php if(mongabay_layout() == 'container-fluid') echo '</div>';?>
</div>
<?php }
// Function to detect if we are dealing with featured aside article
function mongabay_layout() {
if ( is_single() ) {
$post_id = get_the_ID();
$aside = get_post_format($post_id);
$featured = get_post_meta( $post_id, 'featured_as', false );
if ( $aside == 'aside' && in_array('featured', $featured) ) {
$container = 'container-fluid';
}
else {
$container = 'container';
}
}
else {
$container = 'container';
}
return $container;
}
// sanitize content
function mongabay_sanitized_content($post_id) {
if (get_post_meta($post_id,"mongabay_post_legacy_status",true) == 'yes') {
$content = get_the_content();
$content = preg_replace('/<font.*?>/', '', $content);
$content = preg_replace('/<\/font>/', '', $content);
$content = str_replace(']]>', '', $content);
$content = str_replace(array("}","{"),'',$content);
$content = str_replace(array('<br>','<BR>','<br/>','<BR/>'),"\n",$content);
$content = apply_filters('the_content', $content);
$content = str_replace('<p></p>', '', $content);
echo $content;
}
else {
the_content();
}
}
// Load scripts
function mongabay_header_scripts()
{
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
wp_register_script('fittext', get_template_directory_uri() . '/js/lib/jq.fittext.min.js', array('jquery'), '1.2', true);
wp_enqueue_script('fittext');
wp_register_script('bootstraputils', get_template_directory_uri() . '/js/lib/util.min.js', array('jquery'), '4.0.0', true);
wp_enqueue_script('bootstraputils');
wp_register_script('bootstraptabs', get_template_directory_uri() . '/js/lib/tabs.min.js', array('jquery'), '4.0.0', true);
wp_enqueue_script('bootstraptabs');
wp_register_script('scripts', get_template_directory_uri() . '/js/scripts.min.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('scripts');
}
}
// Load conditional scripts
function mongabay_conditional_scripts()
{
if ( mongabay_layout() == 'container-fluid') {
wp_register_script('parallax', get_template_directory_uri() . '/js/lib/parallax.min.js', array(), '1.4.2', true);
wp_enqueue_script('parallax');
wp_register_script('iframeresize', 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.14/iframeResizer.min.js', array(), '3.5.14', true);
wp_enqueue_script('iframeresize');
}
if (!is_singular() || is_home() || is_page(__('series', 'mongabay'))) {
wp_register_script('salvattore', get_template_directory_uri() . '/js/lib/salvattore.min.js', array(), '1.0.9', true);
wp_enqueue_script('salvattore');
}
}
// Featured articles template
function mongabay_featured() {
if ( mongabay_layout() == "container-fluid" ) {
include (TEMPLATEPATH . '/single-featured.php');
exit;
}
}
// Load styles
function mongabay_styles()
{
//wp_register_style('main', get_template_directory_uri() . '/style2017.css', array(), '1.0', 'all');
//wp_enqueue_style('main');
wp_register_style('framework', get_template_directory_uri() . '/css/framework.min.css', array(), '1.0', 'all');
wp_enqueue_style('framework');
wp_register_style('boostrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '4.0.0', 'all');
wp_enqueue_style('boostrap');
}
// Register Navigation
function register_mongabay_menu()
{
register_nav_menus(array( // Using array to specify more menus if needed
'header-menu' => __('Header Menu', 'mongabay'), // Main Navigation
'sidebar-menu' => __('Sidebar Menu', 'mongabay'), // Sidebar Navigation
'extra-menu' => __('Extra Menu', 'mongabay') // Extra Navigation if needed (duplicate as many as you need!)
));
}
// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
$args['container'] = false;
return $args;
}
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
return is_array($var) ? array() : '';
}
// Remove invalid rel attribute values in the categorylist
function remove_category_rel_from_category_list($thelist)
{
return str_replace('rel="category tag"', 'rel="tag"', $thelist);
}
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
function add_slug_to_body_class($classes)
{
global $post;
if (is_home()) {
$key = array_search('blog', $classes);
if ($key > -1) {
unset($classes[$key]);
}
} elseif (is_page()) {
$classes[] = sanitize_html_class($post->post_name);
} elseif (is_singular()) {
$classes[] = sanitize_html_class($post->post_name);
}
return $classes;
}
// If Dynamic Sidebar Exists
if (function_exists('register_sidebar'))
{
// Define Sidebar Widget
register_sidebar(array(
'name' => __('Sidebar Widget', 'mongabay'),
'description' => __('All sidebar widgets should be placed here.', 'mongabay'),
'id' => 'sidebar-widget',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
// Define Footer Widget 1/4
register_sidebar(array(
'name' => __('Footer Widget 1/4', 'mongabay'),
'description' => __('First column widget', 'mongabay'),
'id' => 'footer-widget-1',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
// Define Footer Widget 2/4
register_sidebar(array(
'name' => __('Footer Widget 2/4', 'mongabay'),
'description' => __('Second column widget', 'mongabay'),
'id' => 'footer-widget-2',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
// Define Footer Widget 3/4
register_sidebar(array(
'name' => __('Footer Widget 3/4', 'mongabay'),
'description' => __('Third column widget', 'mongabay'),
'id' => 'footer-widget-3',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
// Define Footer Widget 4/4
register_sidebar(array(
'name' => __('Footer Widget 4/4', 'mongabay'),
'description' => __('Forth column widget', 'mongabay'),
'id' => 'footer-widget-4',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
// Tabbed articles by topic/location
function mongabay_tabs() {
register_widget( 'mongabay_topic_location' );
}
class mongabay_topic_location extends WP_Widget {
function __construct() {
parent::__construct(
'mongabay_topic_location',
__('Topic and location tabs', 'mongabay'),
array( 'description' => __( 'Listing topics and locations as tabbed content', 'mongabay' ), )
);
}
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
if ( ! empty( $title ) )
echo '<p>' . $title . '</p>';
?>
<?php
function mongabay_tabbed_content ($home_url, $items) {
foreach ($items as $item) {
$title = ucwords($item);
$slug = sanitize_title($item);?>
<a class="widget-term" href="<?php echo $home_url.'list/'.$slug ;?>"><?php echo $title; ?></a>
<?php }
}
?>
<ul class="nav nav-tabs">
<li><a data-toggle="tab" href="#topic" class="active"><h2><?php _e('By topic', 'mongabay'); ?></h2></a></li>
<li><a data-toggle="tab" href="#location"><h2><?php _e('By location', 'mongabay'); ?></h2></a></li>
</ul>
<div class="tab-content">
<div id="topic" class="tab-pane fade in active show">
<?php
switch (get_current_blog_id()) {
case '1':
//General www
mongabay_tabbed_content('https://news.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous peoples','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
case '20':
//News
mongabay_tabbed_content('https://news.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous peoples','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
case '21':
//Kidsnews
mongabay_tabbed_content('https://kidsnews.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous people','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
case '22':
//Wildtech
mongabay_tabbed_content('https://wildtech.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous people','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
case '23':
//Chinese
mongabay_tabbed_content('https://cn.mongabay.com/', array('农业','动物','鸟类','气候变化','保全','森林毁坏','能量','特色','森林','乐观积极的环境(新闻)','爬虫','Indigenous people','Interviews','哺乳动物','New Species','海洋','油棕种植园','雨林','Technology','野生动物'));
break;
case '24':
//German
mongabay_tabbed_content('https://de.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous people','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
case '25':
//Spanish
mongabay_tabbed_content('https://es.mongabay.com/', array('Agricultura','Animales','Pájaros','Cambio Climático','Conservación','Deforestación','Energía','Destacado','Bosques','Optimismo medioambiental','Herpetología','Indigenous people','Entrevistas','Mamíferos','Nuevas especies','Océanos','Plantaciones de aceite de palma','Selvas tropicales','Tecnología','Vida silvestre'));
break;
case '26':
//French
mongabay_tabbed_content('https://news.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous people','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
case '27':
//Italian
mongabay_tabbed_content('https://it.mongabay.com/', array('Agricoltura','Animali','Uccelli','Cambiamento climatico','Conservazione','Deforestazione','Energia','In primo piano','Foreste Andine','Buone notizie per lambiente','Herpetologia','Indigenous people','Interviews','Mammiferi','New species','Oceani','Piantagioni di palme da olio','Foreste pluviali','Technology','Fauna selvatica'));
break;
case '28':
//Japanese
mongabay_tabbed_content('https://jp.mongabay.com/', array('農業','動物','鳥類','気候変動e','保全','森林破壊','エネルギー','特集','森林','明るくポジティブな環境ニュース','両生・爬虫類','Indigenous people','Interviews','哺乳類','New species','海洋','パーム油プランテーション','熱帯雨林','Technology','野生動物'));
break;
case '29':
//Portuguese
mongabay_tabbed_content('https://brasil.mongabay.com/', array('Agricultura','Animais','Aves','Alterações Climáticas','Conservação','Desflorestação','Energia','Destaque','Florestas','Otimismo ambiental','Herpetologia','Indigenous People','Interviews','Mamíferos','New species','Oceanos','Plantações de Óleo de Palma','Florestas Tropicais','Technology','Vida Selvagem'));
break;
case '30':
//India
mongabay_tabbed_content('https://india.mongabay.com/', array('Animals','Biodiversity','Climate change','Conservation','Deforestation','Energy','Environment','Featured','Forests','Positive environmental','Indigenous peoples','Interviews','Mammals','New species','Oceans','Pollution','Rainforests','Technology','Wildlife'));
break;
default:
mongabay_tabbed_content('https://news.mongabay.com/', array('Agriculture','Animals','Birds','Climate change','Conservation','Deforestation','Energy','Featured','Forests','Happy-upbeat environmental','Herps','Indigenous peoples','Interviews','Mammals','New species','Oceans','Palm oil','Rainforests','Technology','Wildlife'));
break;
}
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>topics" class="plus-link"><?php _e('Many more topics', 'mongabay'); ?></a>
</div>
<div id="location" class="tab-pane fade">
<?php
switch (get_current_blog_id()) {
case '1':
mongabay_tabbed_content('https://news.mongabay.com/', array('Africa','Amazon','Asia','Australia','Borneo','Brazil','Cameroon','Central America','China','Colombia','Congo','India','Indonesia','Latin America','Madagascar','Malaysia','New Guinea','Peru','Sumatra','United States'));
break;
case '20':
mongabay_tabbed_content('https://news.mongabay.com/', array('Africa','Amazon','Asia','Australia','Borneo','Brazil','Cameroon','Central America','China','Colombia','Congo','India','Indonesia','Latin America','Madagascar','Malaysia','New Guinea','Peru','Sumatra','United States'));
break;
case '21':
mongabay_tabbed_content('https://kidsnews.mongabay.com/', array('Africa','Amazon','Asia','Australia','Borneo','Brazil','Cameroon','Central America','China','Colombia','Congo','India','Indonesia','Latin America','Madagascar','Malaysia','New Guinea','Peru','Sumatra','United States'));
break;
case '22':
mongabay_tabbed_content('https://news.mongabay.com/', array('Africa','Amazon','Asia','Australia','Borneo','Brazil','Cameroon','Central America','China','Colombia','Congo','India','Indonesia','Latin America','Madagascar','Malaysia','New Guinea','Peru','Sumatra','United States'));
break;
case '23':
mongabay_tabbed_content('https://cn.mongabay.com/', array('非洲','亚马逊','亚洲','澳大利亚','婆罗洲','巴西','喀麦隆','中美洲','中国','哥伦比亚','刚果','印度尼西亚','印度尼西亚','拉丁美洲','马达加斯加','马来西亚','新几内亚','秘鲁','苏门答腊','美国'));
break;
case '24':
mongabay_tabbed_content('https://de.mongabay.com/', array('Afrika','Amazonas','Asien','Australien','Borneo','Brasilien','Kamerun','Zentralamerika','China','Kolumbien','Kongo','Indien','Indonesien','Lateinamerika','Madagaskar','Malaysia','Neuguinea','Peru','Sumatra','Vereinigte Staaten'));
break;
case '25':
mongabay_tabbed_content('https://es.mongabay.com/', array('Africa','Amazonas','Asia','Australia','Borneo','Brasil','Camerún','América Central','China','El Congo','Congo','India','Indonesia','América Latina','Madagascar','Malasia','Nueva Guinea','Perú','Sumatra','Estados Unidos'));
break;
case '26':
mongabay_tabbed_content('https://news.mongabay.com/', array('Africa','Amazon','Asia','Australia','Borneo','Brazil','Cameroon','Central America','China','Colombia','Congo','India','Indonesia','Latin America','Madagascar','Malaysia','New Guinea','Peru','Sumatra','United States'));
break;
case '27':
mongabay_tabbed_content('https://it.mongabay.com/', array('Africa','Amazzonia','Asia','Australia','Borneo','Brasile','Camerun','America Centrale','Cina','Colombia','Congo','India','Indonesia','America Latina','Madagascar','Malesia','Nuova Guinea','Perù','Sumatra','Stati Uniti'));
break;
case '28':
mongabay_tabbed_content('https://jp.mongabay.com/', array('アフリカ','アマゾン','アジア','オーストラリア','ボルネオ','ブラジル','カメルーン','中央アメリカ','中国','コロンビア','コンゴ','インド','インドネシア','ラテンアメリカ','マダガスカル','マレーシア','ニューギニア','ペルー','スマトラ','米国'));
break;
case '29':
mongabay_tabbed_content('https://brasil.mongabay.com/', array('África','Amazónia','Ásia','Austrália','Bornéu','Brasil','Camarões','América Central','China','Colômbia','Congo','Índia','Indonésia','América Latina','Madagáscar','Malásia','Nova Guiné','Peru','Sumatra','Estados Unidos'));
break;
case '30':
mongabay_tabbed_content('https://india.mongabay.com/', array('Deccan Plateau','Himalayas','Eastern Ghats','Western Ghats','Thar Desert ','Sundarbans','Andhra Pradesh','Assam','Arunachal Pradesh','Andaman and Nicobar Islands','Bihar','Chhattisgarh','Dadra and Nagar Haveli','Daman and Diu','Delhi','Goa','Gujarat','Haryana','Himachal Pradesh','Jammu and Kashmir','Jharkhand','Karnataka','Kerala'));
break;
default:
mongabay_tabbed_content('https://news.mongabay.com/', array('Africa','Amazon','Asia','Australia','Borneo','Brazil','Cameroon','Central America','China','Colombia','Congo','India','Indonesia','Latin America','Madagascar','Malaysia','New Guinea','Peru','Sumatra','United States'));
break;
}
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>locations" class="plus-link"><?php _e('Browse more locations', 'mongabay'); ?></a>
</div>
</div>
<?php
echo $args['after_widget'];
}
// Widget Backend
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'mongabay' );
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
// Remove wp_head() injected Recent Comment styles
function my_remove_recent_comments_style()
{
global $wp_widget_factory;
remove_action('wp_head', array(
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
'recent_comments_style'
));
}
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function mongabay_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}
// Custom Excerpts
function mongabay_index($length) // Create 20 Word Callback for Index page Excerpts, call using mongabay_excerpt('mongabay_index');
{
return 20;
}
// Create 40 Word Callback for Custom Post Excerpts, call using mongabay_excerpt('mongabay_custom_post');
function mongabay_custom_post($length)
{
return 40;
}
// Create the Custom Excerpts
function mongabay_excerpt()
{
global $post;
if ( empty( $post->post_excerpt ) ) {
$output_1 = strip_shortcodes ($post->post_content);
$output_2 = wp_strip_all_tags($output_1);
$output = wp_trim_words( $output_2, 30 );
} else {
$output = $post->post_excerpt;
}
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
echo $output;
}
// Custom View Article link to Post
function mongabay_blank_view_article($more)
{
global $post;
return '... <a class="view-article" href="' . get_permalink($post->ID) . '">' . __('View Article', 'mongabay') . '</a>';
}
// Remove Admin bar
function remove_admin_bar()
{
return false;
}
// Remove 'text/css' from our enqueued stylesheet
function mongabay_style_remove($tag)
{
return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag);
}
// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
function remove_thumbnail_dimensions( $html )
{
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
}
// Register custom query vars
function mongabay_query_var( $vars ) {
$vars[] = 'section';
$vars[] = 'nc1';
$vars[] = 'nc2';
return $vars;
}
// Customize RSS feed
remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'mongabay_feed_rss2', 10, 1 );
function mongabay_feed_rss2() {
$rss_template = get_template_directory() . '/custom-code/feed-rss2.php';
load_template( $rss_template );
}
// Parallax Shortcode
function parallax_img($atts){
extract(shortcode_atts(array('imagepath' => 'Image Needed','id' => '1', 'px_title' => 'Slide Title', 'title_color' => '#FFFFFF' , 'img_caption' => 'Your image caption'),$atts));
return "<div class='clearfix'></div><div class='parallax-section full-height' data-parallax='scroll' id='".$id."' data-image-src='".$imagepath."' style='background-size: cover'><div class='featured-article-meta'><span class='subtitle' style='color:".$title_color."'>".$img_caption."</span></div></div><div class='clearfix'></div>";
}
function parallax_open() {
return "<div class='container'><div class='row justify-content-center'><div id='main' class='col-lg-8 single'>";
}
function parallax_close() {
return "</div></div></div>";
}
// Parallax Slide Shortcode Button in a text editor
function px_shortcode_button() {
if(wp_script_is("quicktags"))
{
?>
<script type="text/javascript">
function getSel()
{
var txtarea = document.getElementById("content");
var start = txtarea.selectionStart;
var finish = txtarea.selectionEnd;
return txtarea.value.substring(start, finish);
}
QTags.addButton(
"parallax_shortcode",
"ParallaxSlide",
callback
);
function callback()
{
var selected_text = getSel();
QTags.insertContent("[parallax-img imagepath='image_url' id='1' px_title='First Title' title_color='#333333' img_caption='Your image caption']");
}
</script>
<?php
}
}
// Parallax Content Shortcode Button in a text editor
function open_close_px_content()
{
if(wp_script_is("quicktags"))
{
?>
<script type="text/javascript">
function getSel()
{
var txtarea = document.getElementById("content");
var start = txtarea.selectionStart;
var finish = txtarea.selectionEnd;
return txtarea.value.substring(start, finish);
}
QTags.addButton(
"pxcontent_shortcode",
"ParallaxContent",
callback
);
function callback()
{
var selected_text = getSel();
QTags.insertContent("[open-parallax-content]" + selected_text + "[close-parallax-content]")
}
</script>
<?php
}
}
// Remove meta boxes from post editing screen
function mongabay_remove_custom_fields() {
$post_types = get_post_types( '', 'names' );
foreach ( $post_types as $post_type ) {
remove_meta_box( 'postcustom' , $post_type , 'normal' );
}
}
// Prevent from aading new location tags
function mongabay_prevent_terms ( $term, $taxonomy ) {
if ( 'location' === $taxonomy && !current_user_can( 'activate_plugins' ) ) {
return new WP_Error( 'term_addition_blocked', __( 'You cannot add terms to this taxonomy' ) );
}
if ( 'topic' === $taxonomy && !current_user_can( 'activate_plugins' ) ) {
return new WP_Error( 'term_addition_blocked', __( 'You cannot add terms to this taxonomy' ) );
}
return $term;
}
// Stats pages dynamic sidebar
if (function_exists('register_sidebar'))
{
register_sidebar(array(
'name' => __('Stats Widget', 'mongabay'),
'description' => __('Stats page sidebar widgets should be placed here.', 'mongabay'),
'id' => 'stats-widget',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}
// Remove query strings from scripts and css
function remove_query_string( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
if ( !is_admin() ) {
add_filter( 'script_loader_src', 'remove_query_string', 15, 1 );
add_filter( 'style_loader_src', 'remove_query_string', 15, 1 );
}
// Custom rewrite rule for wildtech posts
function mongabay_wildtech_post_link( $url, $post, $leavename ) {
$parsed = parse_url($url);
if ( $post->post_type == 'post') {
$tech = has_term('technology', 'topic');
if ( $tech ) $url = get_home_url().'/wildtech'.$parsed['path'];
}
return $url;
}
// Listings proper page title
function mongabay_custom_title() {
$firstvar = get_query_var('nc1');
$secondvar = get_query_var('nc2');
if (get_query_var('section')=='list') {
if (!empty($firstvar) && empty($secondvar)) {
$item1 = get_terms(array('topic','location'), array('slug' => $firstvar));
$title = $item1[0] -> name;
_e( 'Conservation news on', 'mongabay' );
echo ' '.$title;
}
if (!empty($firstvar) && !empty($secondvar)) {
$item1 = get_terms(array('topic','location'), array('slug' => $firstvar));
$item2 = get_terms(array('topic','location'), array('slug' => $secondvar));
$title1 = $item1[0] -> name;
$title2 = $item2[0] -> name;
$title = $title1.' and '.$title2;
_e( 'Conservation news on', 'mongabay' );
echo ' '.$title;
}
}
else {
wp_title('');
}
}
// Customized mobile detection function
function mongabay_wp_is_mobile() {
static $is_mobile;
if ( isset($is_mobile) )
return $is_mobile;
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
$is_mobile = false;
} elseif (
strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) {
$is_mobile = true;
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') == false) {
$is_mobile = true;
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false) {
$is_mobile = false;
} else {
$is_mobile = false;
}
return $is_mobile;
}
// Add the filter parameter for API
function rest_api_filter_add_filters() {
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
add_filter( 'rest_' . $post_type->name . '_query', 'rest_api_filter_add_filter_param', 10, 2 );
}
}
function rest_api_filter_add_filter_param( $args, $request ) {
if ( empty( $request['filter'] ) || ! is_array( $request['filter'] ) ) {
return $args;
}
$filter = $request['filter'];
if ( isset( $filter['posts_per_page'] ) && ( (int) $filter['posts_per_page'] >= 1 && (int) $filter['posts_per_page'] <= 100 ) ) {
$args['posts_per_page'] = $filter['posts_per_page'];
}
global $wp;
$vars = apply_filters( 'query_vars', $wp->public_query_vars );
foreach ( $vars as $var ) {
if ( isset( $filter[ $var ] ) ) {
$args[ $var ] = $filter[ $var ];
}
}
return $args;
}
function mongabay_rss_pre_get_posts( $query ) {
if( $query->is_feed && $query->is_main_query() ) {
if( isset( $query->query_vars['grant'] ) && ! empty( $query->query_vars['grant'] ) ) {
// if you only want to allow 'alpha-numerics':
$grant = preg_replace( "/[^a-zA-Z0-9]/", "", $query->query_vars['grant'] );
$query->set( 'meta_key', 'grant' );
$query->set( 'meta_value', $grant );
}
}
}
// Remove p tags from images, scripts, and iframes.
function mongabay_remove_iframe_ptags( $content ) {
$content = preg_replace('/<p>.*?\s*(<iframe.*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
return $content;
}
// Detect Android Mobile phone
function is_android_mobile() { // detect only Android phones
$is_android = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android');