This repository was archived by the owner on May 11, 2023. It is now read-only.
forked from simgia/infocongo
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.php
More file actions
573 lines (485 loc) · 20.8 KB
/
Copy pathfunctions.php
File metadata and controls
573 lines (485 loc) · 20.8 KB
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
<?php
/*
* InfoCongo resources
*/
// Template functions
include(STYLESHEETPATH . '/inc/template-functions.php');
// Countries
include(STYLESHEETPATH . '/inc/countries.php');
// Topics
include(STYLESHEETPATH . '/inc/topics.php');
// Datasets
include(STYLESHEETPATH . '/inc/datasets.php');
// Advanced Navigation
include(STYLESHEETPATH . '/inc/advanced-navigation.php');
//Submit Story
include(STYLESHEETPATH . '/inc/submit-story.php');
// Geocode box
include(STYLESHEETPATH . '/inc/geocode-box.php');
// Shares
//include(STYLESHEETPATH . '/inc/shares.php');
// Update shares on post view
/*function publica_update_shares() {
if(is_single()) {
global $post;
publica_get_shares($post->ID);
}
}
add_action('wp_head', 'publica_update_shares');*/
/*
* Clears JEO default front-end styles and scripts
*/
function infocongo_scripts() {
// deregister jeo styles
wp_deregister_style('jeo-main');
// deregister jeo site frontend infocongo_scripts
//wp_deregister_script('jeo-site');
// Chosen
wp_enqueue_script('chosen', get_stylesheet_directory_uri() . '/lib/chosen.jquery.min.js', array('jquery'));
// register normalize and grid system
wp_register_style('infocongo-normalize', get_stylesheet_directory_uri() . '/css/normalize.css', array(), '2.0.4');
wp_register_style('infocongo-skeleton', get_stylesheet_directory_uri() . '/css/skeleton.css', array('infocongo-normalize'), '2.0.4');
// Responsive
// wp_register_style('infocongo-responsive', get_stylesheet_directory_uri() . '/css/responsive.css', array(), '1.0');
}
add_action('wp_enqueue_scripts', 'infocongo_scripts', 10);
// load translation file for the child theme
load_theme_textdomain('infocongo', get_stylesheet_directory() . '/languages');
/*
* JEO Hooks examples
* Most common hooks
*/
// Action right after JEO functionality inits
function infocongo_init() {
// Action goes here
}
add_action('jeo_init', 'infocongo_init');
// Hook scripts after JEO scripts has been initialized
function infocongo_jeo_scripts() {
// Register and enqueue scripts here
// Enqueue main CSS (with grid system dependency)
wp_enqueue_style('infocongo-styles', get_stylesheet_directory_uri() . '/css/main.css', array('infocongo-skeleton'));
}
add_action('jeo_enqueue_scripts', 'infocongo_jeo_scripts', 20);
// Filter to change posts GeoJSON data (also changes the GeoJSON API output)
function infocongo_marker_data($data, $post) {
global $post;
$permalink = $data['url'];
if(function_exists('qtrans_getLanguage'))
$permalink = add_query_arg(array('lang' => qtrans_getLanguage()), $permalink);
$data['permalink'] = $permalink;
$data['url'] = $permalink;
$data['content'] = get_the_excerpt();
if(get_post_meta($post->ID, 'geocode_zoom', true))
$data['zoom'] = get_post_meta($post->ID, 'geocode_zoom', true);
// source
$publishers = get_the_terms($post->ID, 'publisher');
if($publishers) {
$publisher = array_shift($publishers);
$data['source'] = apply_filters('single_cat_title', $publisher->name);
}
return $data;
}
add_filter('jeo_marker_data', 'infocongo_marker_data', 10, 2);
// Filter to change GeoJSON response
function infocongo_markers_data($data, $query) {
// Change $data here
return $data;
}
add_filter('jeo_markers_data', 'infocongo_markers_data', 10, 2);
// Filter to programatically change map data
function infocongo_map_data($data, $map) {
// Change $data here
return $data;
}
add_filter('jeo_map_data', 'infocongo_map_data', 10, 2);
// image sizes
add_action( 'after_setup_theme', 'images_theme_setup' );
function images_theme_setup() {
add_image_size( 'featured', 500, 464, array( 'center', 'top' ));
add_image_size( 'home-list', 300, 200, array( 'center', 'top' ));
add_image_size( 'loop-list', 300, 200, array( 'center', 'top' ));
add_image_size( 'home-slider', 540, 200, array( 'center', 'top' ));
add_image_size( 'archive-list', 220, 220, array( 'center', 'top' ));
add_image_size( 'author-thumb', 120, 120, array( 'center', 'top' ));
}
// Register Custom Taxonomy
function register_taxonomies() {
$labels = array(
'name' => _x( 'Topics', 'Taxonomy General Name', 'infocongo' ),
'singular_name' => _x( 'Topic', 'Taxonomy Singular Name', 'infocongo' ),
'menu_name' => __( 'Topics', 'infocongo' ),
'all_items' => __( 'All Topics', 'infocongo' ),
'parent_item' => __( 'Parent Topics', 'infocongo' ),
'parent_item_colon' => __( 'Parent Topic:', 'infocongo' ),
'new_item_name' => __( 'New Topic Name', 'infocongo' ),
'add_new_item' => __( 'Add New Topic', 'infocongo' ),
'edit_item' => __( 'Edit Topic', 'infocongo' ),
'update_item' => __( 'Update Topic', 'infocongo' ),
'view_item' => __( 'View Topic', 'infocongo' ),
'separate_items_with_commas' => __( 'Separate Topic with commas', 'infocongo' ),
'add_or_remove_items' => __( 'Add or remove Topic', 'infocongo' ),
'choose_from_most_used' => __( 'Choose from the most used', 'infocongo' ),
'popular_items' => __( 'Popular Topics', 'infocongo' ),
'search_items' => __( 'Search Topics', 'infocongo' ),
'not_found' => __( 'Not Found', 'infocongo' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'show_admin_column' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'topic', 'with_front' => true),
'query_var' => 'topic'
);
register_taxonomy( 'topic', array( 'post' ), $args );
$labels = array(
'name' => _x( 'Countries', 'Taxonomy General Name', 'infocongo' ),
'singular_name' => _x( 'Country', 'Taxonomy Singular Name', 'infocongo' ),
'menu_name' => __( 'Countries', 'infocongo' ),
'all_items' => __( 'All Countries', 'infocongo' ),
'parent_item' => __( 'Parent Countries', 'infocongo' ),
'parent_item_colon' => __( 'Parent Country:', 'infocongo' ),
'new_item_name' => __( 'New Country Name', 'infocongo' ),
'add_new_item' => __( 'Add New Country', 'infocongo' ),
'edit_item' => __( 'Edit Country', 'infocongo' ),
'update_item' => __( 'Update Country', 'infocongo' ),
'view_item' => __( 'View Country', 'infocongo' ),
'separate_items_with_commas' => __( 'Separate Country with commas', 'infocongo' ),
'add_or_remove_items' => __( 'Add or remove Country', 'infocongo' ),
'choose_from_most_used' => __( 'Choose from the most used', 'infocongo' ),
'popular_items' => __( 'Popular Countries', 'infocongo' ),
'search_items' => __( 'Search Countries', 'infocongo' ),
'not_found' => __( 'Not Found', 'infocongo' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'show_admin_column' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'country', 'with_front' => true),
'query_var' => 'country'
);
register_taxonomy( 'country', array( 'post' ), $args );
$labels = array(
'name' => __('Publishers', 'Taxonomy General Name', 'infocongo'),
'singular_name' => __('Publisher', 'Taxonomy Singular Name', 'infocongo'),
'search_items' => __('Search publishers', 'infocongo'),
'popular_items' => __('Popular publishers', 'infocongo'),
'all_items' => __('All publishers', 'infocongo'),
'parent_item' => __('Parent publisher', 'infocongo'),
'parent_item_colon' => __('Parent publisher:', 'infocongo'),
'edit_item' => __('Edit publisher', 'infocongo'),
'update_item' => __('Update publisher', 'infocongo'),
'add_new_item' => __('Add new publisher', 'infocongo'),
'new_item_name' => __('New publisher name', 'infocongo'),
'separate_items_with_commas' => __('Separate publishers with commas', 'infocongo'),
'add_or_remove_items' => __('Add or remove publishers', 'infocongo'),
'choose_from_most_used' => __('Choose from most used publishers', 'infocongo'),
'menu_name' => __('Publishers', 'infocongo')
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'show_admin_column' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'publisher', 'with_front' => true),
'query_var' => 'publisher'
);
register_taxonomy('publisher', array('post'), $args);
}
add_action( 'jeo_init', 'register_taxonomies' );
// Register Custom Post Type
function custom_post_type() {
$labels = array(
'name' => _x( 'Authors', 'Post Type General Name', 'infocongo' ),
'singular_name' => _x( 'Author', 'Post Type Singular Name', 'infocongo' ),
'menu_name' => __( 'Authors', 'infocongo' ),
'name_admin_bar' => __( 'Authors', 'infocongo' ),
'parent_item_colon' => __( 'Parent author:', 'infocongo' ),
'all_items' => __( 'All authors', 'infocongo' ),
'add_new_item' => __( 'Add New author', 'infocongo' ),
'add_new' => __( 'Add New', 'infocongo' ),
'new_item' => __( 'New author', 'infocongo' ),
'edit_item' => __( 'Edit author', 'infocongo' ),
'update_item' => __( 'Update author', 'infocongo' ),
'view_item' => __( 'View author', 'infocongo' ),
'search_items' => __( 'Search author', 'infocongo' ),
'not_found' => __( 'Not found', 'infocongo' ),
'not_found_in_trash' => __( 'Not found in Trash', 'infocongo' ),
);
$args = array(
'label' => __( 'Author', 'infocongo' ),
'description' => __( 'Authors of the team', 'infocongo' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-users',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'authors', $args );
$labels = array(
'name' => _x( 'Publishers', 'Post Type General Name', 'infocongo' ),
'singular_name' => _x( 'Publisher', 'Post Type Singular Name', 'infocongo' ),
'menu_name' => __( 'Publishers', 'infocongo' ),
'name_admin_bar' => __( 'Publishers', 'infocongo' ),
'parent_item_colon' => __( 'Parent publisher:', 'infocongo' ),
'all_items' => __( 'All publishers', 'infocongo' ),
'add_new_item' => __( 'Add New publisher', 'infocongo' ),
'add_new' => __( 'Add New', 'infocongo' ),
'new_item' => __( 'New publisher', 'infocongo' ),
'edit_item' => __( 'Edit publisher', 'infocongo' ),
'update_item' => __( 'Update publisher', 'infocongo' ),
'view_item' => __( 'View publisher', 'infocongo' ),
'search_items' => __( 'Search publisher', 'infocongo' ),
'not_found' => __( 'Not found', 'infocongo' ),
'not_found_in_trash' => __( 'Not found in Trash', 'infocongo' ),
);
$args = array(
'label' => __( 'Publisher', 'infocongo' ),
'description' => __( 'Publishers of the team', 'infocongo' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-media-document',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'publishers', $args );
// Add new type Special Reports.
$labels = array(
'name' => _x( 'Special Reports', 'Post Type General Name', 'infocongo' ),
'singular_name' => _x( 'Special Report', 'Post Type Singular Name', 'infocongo' ),
'menu_name' => __( 'Special Reports', 'infocongo' ),
'name_admin_bar' => __( 'Special Reports', 'infocongo' ),
'parent_item_colon' => __( 'Parent special report:', 'infocongo' ),
'all_items' => __( 'All special reports', 'infocongo' ),
'add_new_item' => __( 'Add New special report', 'infocongo' ),
'add_new' => __( 'Add New', 'infocongo' ),
'new_item' => __( 'New special report', 'infocongo' ),
'edit_item' => __( 'Edit special report', 'infocongo' ),
'update_item' => __( 'Update special report', 'infocongo' ),
'view_item' => __( 'View special report', 'infocongo' ),
'search_items' => __( 'Search special report', 'infocongo' ),
'not_found' => __( 'Not found', 'infocongo' ),
'not_found_in_trash' => __( 'Not found in Trash', 'infocongo' ),
);
$args = array(
'label' => __( 'Special Report', 'infocongo' ),
'description' => __( 'Special Reports of the team', 'infocongo' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type('special-reports', $args);
}
add_action( 'init', 'custom_post_type', 0 );
register_nav_menus( array(
'footer_menu' => 'Footer Menu',
) );
add_filter("manage_posts_columns", "my_post_edit_columns" );
function my_post_edit_columns($columns){
unset($columns['categories']);
unset($columns['tags']);
return $columns;
}
//limit excerpt length
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
//limit content length
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
//limit title length
function title($limit) {
$title = explode(' ', get_the_title(), $limit);
if (count($title)>=$limit) {
array_pop($title);
$title = implode(" ",$title).'...';
} else {
$title = implode(" ",$title);
}
$title = preg_replace('/\[.+\]/','', $title);
$title = apply_filters('the_title', $title);
$title = str_replace(']]>', ']]>', $title);
return $title;
}
function infocongo_submit_story() {
wp_register_script('submit-story', get_stylesheet_directory_uri() . '/js/submit-story.js', array('jquery'), '0.1.1');
wp_enqueue_script('submit-story');
wp_localize_script('submit-story', 'infoamazonia_submit', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'success_label' => __('Success! Thank you, your story will be reviewed by one of our editors and soon will be online.', 'infoamazonia'),
'redirect_label' => __('You\'re being redirect to the home page in 4 seconds.', 'infoamazonia'),
'home' => home_url('/'),
'error_label' => __('Oops, please try again in a few minutes.', 'infoamazonia')
));
}
add_action('wp_enqueue_scripts', 'infocongo_submit_story', 100);
function my_remove_frontpage_map_query($query) {
if(is_front_page()) {
$query->set('without_map_query', 1);
}
}
add_action('pre_get_posts', 'my_remove_frontpage_map_query');
add_filter( 'rp4wp_append_content', '__return_false' );
function ic_author_function($atts, $content = null) {
extract(shortcode_atts(array(
'name' => '',
), $atts));
$return_string = '<h3>'.$content.'</h3>';
$return_string .= '<ul>';
query_posts(array(
'name' => $name,
'post_type' => 'authors',
'numberposts' => 1
));
if (have_posts()) :
while (have_posts()) : the_post();
$return_string .= '<div>'.get_the_post_thumbnail($post->ID, 'author-thumb').'</div>';
$return_string .= '<div>'.get_the_title().'</div>';
$return_string .= '<div>'.get_the_excerpt().'</div>';
endwhile;
endif;
$return_string .= '</ul>';
wp_reset_query();
return $return_string;
}
add_shortcode('author', 'ic_author_function');
// Meta Box Map Options in Post.
add_action('add_meta_boxes', 'map_options_add_meta_box');
function map_options_add_meta_box() {
add_meta_box(
'map-options',
__('Map options', 'jeo'),
'map_options_box',
'post',
'advanced',
'high'
);
}
function map_options_box( $post ){
$show_map = '';
if($post) {
$show_map = get_post_meta($post->ID, 'show_map', true);
$selected = isset( $show_map ) ? esc_attr( $show_map ) : '';
}
?>
<p>
<label for="show_map"> <?php _e('Show Map', 'jeo'); ?></label>
<select name="show_map" id="show_map">
<option value="yes" <?php selected( $selected, 'yes' ); ?>>yes</option>
<option value="no" <?php selected( $selected, 'no' ); ?>>no</option>
</select>
</p>
<?php
}
add_action('save_post', 'map_options_save');
function map_options_save($post_id) {
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (false !== wp_is_post_revision($post_id))
return;
if(isset($_REQUEST['show_map'])){
update_post_meta($post_id, 'show_map', $_REQUEST['show_map']);
}
}
// Meta Box Map Options in Maps.
add_action('add_meta_boxes', 'map_index_options_add_meta_box');
function map_index_options_add_meta_box() {
add_meta_box(
'map-options',
__('Map options', 'jeo'),
'map_index_options_box',
'map',
'advanced',
'high'
);
}
function map_index_options_box( $post ){
$show_map_index = '';
if($post) {
$show_map_index = get_post_meta($post->ID, 'show_map_index', true);
$selected = isset( $show_map_index ) ? esc_attr( $show_map_index ) : '';
}
?>
<p>
<label for="show_map_index"> <?php _e('Show Map Home', 'jeo'); ?></label>
<select name="show_map_index" id="show_map_index">
<option value="no" <?php selected( $selected, 'no' ); ?>>no</option>
<option value="yes" <?php selected( $selected, 'yes' ); ?>>yes</option>
</select>
</p>
<?php
}
add_action('save_post', 'map_index_options_save');
function map_index_options_save($post_id) {
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (false !== wp_is_post_revision($post_id))
return;
if(isset($_REQUEST['show_map_index'])){
update_post_meta($post_id, 'show_map_index', $_REQUEST['show_map_index']);
}
}