-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.php
543 lines (428 loc) · 15.7 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
<?php
// Query multisite
require_once(STYLESHEETPATH . '/inc/query-multisite.php');
// Theme options
require_once(STYLESHEETPATH . '/inc/theme-options.php');
// Briefings
require_once(STYLESHEETPATH . '/inc/briefings.php');
// Announcements
require_once(STYLESHEETPATH . '/inc/announcements.php');
// Site updates
require_once(STYLESHEETPATH . '/inc/site-updates.php');
// Map category
require_once(STYLESHEETPATH . '/inc/layer-category.php');
// summary
require_once(STYLESHEETPATH . '/inc/summary.php');
// Live search
require_once(STYLESHEETPATH . '/inc/live-search/live-search.php');
// Interactive map
require_once(STYLESHEETPATH . '/inc/interactive-map.php');
// Category widget
require_once(STYLESHEETPATH . '/inc/category-widget.php');
// Related resources
require_once(STYLESHEETPATH . '/inc/related-resources-widget.php');
// Advanced nav
require_once(STYLESHEETPATH . '/inc/advanced-navigation.php');
// Advanced nav
require_once(STYLESHEETPATH . '/inc/category-walker.php');
function opendev_setup_theme() {
register_sidebar(array(
'name' => __('Briefing sidebar', 'jeo'),
'id' => 'briefing',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
}
add_action('after_setup_theme', 'opendev_setup_theme');
function opendev_styles() {
$options = get_option('opendev_options');
$css_base = get_stylesheet_directory_uri() . '/css/';
//wp_dequeue_style('jeo-main');
wp_register_style('webfont-droid-serif', 'http://fonts.googleapis.com/css?family=Droid+Serif:400,700');
wp_register_style('webfont-opendev', get_stylesheet_directory_uri() . '/font/style.css');
wp_register_style('opendev-base', $css_base . 'opendev.css', array('webfont-droid-serif', 'webfont-opendev'));
wp_register_style('opendev-cambodia', $css_base . 'cambodia.css');
wp_register_style('opendev-thailand', $css_base . 'thailand.css');
wp_register_style('opendev-laos', $css_base . 'laos.css');
wp_register_style('opendev-myanmar', $css_base . 'myanmar.css');
wp_register_style('opendev-vietnam', $css_base . 'vietnam.css');
wp_enqueue_style('opendev-base');
if($options['style']) {
wp_enqueue_style('opendev-' . $options['style']);
}
}
add_action('wp_enqueue_scripts', 'opendev_styles', 15);
function opendev_jeo_scripts() {
wp_dequeue_script('jeo-site');
wp_enqueue_script('jquery-isotope');
wp_register_script('twttr', 'http://platform.twitter.com/widgets.js');
// custom marker system
global $jeo_markers;
wp_deregister_script('jeo.markers');
wp_register_script('jeo.markers', get_stylesheet_directory_uri() . '/js/markers.js', array('jeo', 'underscore', 'twttr'), '0.3.17', true);
wp_localize_script('jeo.markers', 'opendev_markers', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'query' => $jeo_markers->query(),
'stories_label' => __('stories', 'opendev'),
'home' => (is_home() && !is_paged() && !$_REQUEST['opendev_filter_']),
'copy_embed_label' => __('Copy the embed code', 'opendev'),
'share_label' => __('Share', 'opendev'),
'print_label' => __('Print', 'opendev'),
'embed_base_url' => home_url('/embed/'),
'share_base_url' => home_url('/share/'),
'marker_active' => array(
'iconUrl' => get_stylesheet_directory_uri() . '/img/marker_active.png',
'iconSize' => array(26, 30),
'iconAnchor' => array(13, 30),
'popupAnchor' => array(0, -40),
'markerId' => 'none'
),
'site_url' => home_url('/'),
'read_more_label' => __('Read more', 'opendev'),
'lightbox_label' => array(
'slideshow' => __('Open slideshow', 'opendev'),
'videos' => __('Watch video gallery', 'opendev'),
'video' => __('Watch video', 'opendev'),
'images' => __('View image gallery', 'opendev'),
'image' => __('View fullscreen image', 'opendev'),
'infographic' => __('View infographic', 'opendev'),
'infographics' => __('View infographics', 'opendev')
),
'enable_clustering' => jeo_use_clustering() ? true : false,
'default_icon' => jeo_formatted_default_marker()
));
if(is_home())
wp_enqueue_script('opendev-sticky', get_stylesheet_directory_uri() . '/js/sticky-posts.js', array('jeo.markers', 'jquery'), '0.1.2');
//wp_enqueue_script('opendev-interactive-map', get_stylesheet_directory_uri() . '/inc/interactive-map.js', array('jeo'));
}
add_action('wp_enqueue_scripts', 'opendev_jeo_scripts', 100);
// custom marker data
function opendev_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);
// thumbnail
$data['thumbnail'] = opendev_get_thumbnail();
return $data;
}
add_filter('jeo_marker_data', 'opendev_marker_data', 10, 2);
function opendev_get_thumbnail($post_id = false) {
global $post;
$post_id = $post_id ? $post_id : $post->ID;
$thumb_src = wp_get_attachment_image_src(get_post_thumbnail_id(), 'post-thumb');
if($thumb_src)
return $thumb_src[0];
else
return get_post_meta($post->ID, 'picture', true);
}
function opendev_logo() {
$logo = opendev_get_logo();
if($logo && !is_multisite()) {
?>
<h1 class="with-logo">
<a href="<?php echo home_url('/'); ?>" title="<?php bloginfo('name'); ?>">
<?php bloginfo('name'); ?>
<?php echo $logo; ?>
</a>
</h1>
<?php
} else {
?>
<h1>
<a href="<?php echo home_url('/'); ?>" title="<?php bloginfo('name'); ?>">
<?php // bloginfo('name'); ?>
<span class="icon-od-logo"></span>
Op<sup>e</sup>nDevelopment
</a>
</h1>
<?php
}
}
function opendev_social_apis() {
// Facebook
?>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/pt_BR/all.js#xfbml=1&appId=1413694808863403";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<?php
// Twitter
?>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<?php
// Google Plus
?>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<?php
}
add_action('wp_footer', 'opendev_social_apis');
function opendev_ms_nav() {
if(is_multisite()) {
$sites = wp_get_sites();
if(!empty($sites) && count($sites) > 1) {
$current = get_current_blog_id();
// $name = str_replace('Open Development ', '', get_bloginfo('name'));
// $logo = opendev_get_logo();
// if($logo)
// $name = $logo;
?>
<ul class="ms-nav">
<?php
foreach($sites as $site) {
$details = get_blog_details($site['blog_id']);
$name = str_replace('Open Development ', '', $details->blogname);
$siteurl = $details->siteurl;
switch_to_blog($site['blog_id']);
?>
<li class="site-item">
<a href="<?php echo $siteurl; ?>"><?php echo $name; ?></a>
<div class="sub-menu">
<ul class="first-menu">
<li data-content="news"><a href="<?php echo $siteurl; ?>">
<span class="icon-text"></span> <?php _e('News', 'opendev'); ?>
</a></li>
<li data-content="issues"><a href="<?php echo get_post_type_archive_link('briefing'); ?>">
<span class="icon-docs"></span> <?php _e('Issues', 'opendev'); ?>
</a></li>
<li data-content="maps"><a href="<?php echo get_post_type_archive_link('map'); ?>">
<span class="icon-map"></span> <?php _e('Maps', 'opendev'); ?>
</a></li>
<?php
$data_page_id = opendev_get_data_page_id();
if($data_page_id) :
?>
<li data-content="data"><a href="<?php echo get_permalink($data_page_id); ?>">
<span class="icon-archive"></span> <?php _e('Data', 'opendev'); ?>
</a></li>
<?php
endif;
?>
</ul>
<div class="content">
<?php query_posts(array('posts_per_page' => 3, 'without_map_query' => true)); ?>
<?php if(have_posts()) : ?>
<div class="news content-item">
<h2><?php _e('Latest news', 'opendev'); ?></h2>
<ul>
<?php while(have_posts()) : the_post(); ?>
<li>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php query_posts(array('post_type' => 'briefing', 'posts_per_page' => 3, 'without_map_query' => true)); ?>
<?php if(have_posts()) : ?>
<div class="issues content-item">
<h2><?php _e('Latest issues', 'opendev'); ?></h2>
<ul>
<?php while(have_posts()) : the_post(); ?>
<li>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php query_posts(array('post_type' => 'map', 'posts_per_page' => 3, 'without_map_query' => true)); ?>
<?php if(have_posts()) : ?>
<div class="maps content-item">
<h2><?php _e('Latest maps', 'opendev'); ?></h2>
<ul>
<?php while(have_posts()) : the_post(); ?>
<li>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</li>
<?php
restore_current_blog();
}
?>
</ul>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.ms-nav').each(function() {
$nav = $(this);
$nav.find('.site-item').each(function() {
var $siteNav = $(this);
$siteNav.find('.content-item').hide();
$siteNav.find('.content-item:first-child').show();
$siteNav.find('.first-menu li:first-child').addClass('active');
$siteNav.find('.first-menu li').on('mouseover', function() {
var $content = $siteNav.find('.content-item.' + $(this).data('content'));
if($content.length) {
$siteNav.find('.first-menu li').removeClass('active');
$(this).addClass('active');
$siteNav.find('.content-item').hide();
$siteNav.find('.content-item.' + $(this).data('content')).show();
}
});
});
});
});
</script>
<?php
}
}
}
function opendev_wpckan_post_types() {
return array('post','page','briefing','layer');
}
add_filter('wpckan_post_types', 'opendev_wpckan_post_types');
if(!function_exists('IsNullOrEmptyString')) {
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
}
function opendev_get_related_datasets($atts = false) {
if(!$atts)
$atts = array();
if(!isset($atts['post_id']))
$atts['post_id'] = get_the_ID();
$related_datasets_json = get_post_meta( $atts['post_id'], 'wpckan_related_datasets', true );
$related_datasets = array();
if (!IsNullOrEmptyString($related_datasets_json))
$related_datasets = json_decode($related_datasets_json,true);
$dataset_array = array();
foreach ($related_datasets as $dataset){
$dataset_atts = array("id" => $dataset["dataset_id"]);
try{
array_push($dataset_array,wpckan_api_get_dataset($dataset_atts));
} catch(Exception $e) {
wpckan_log($e->getMessage());
}
if (array_key_exists("limit",$atts) && (count($dataset_array) >= (int)($atts["limit"]))) break;
}
return $dataset_array;
}
function opendev_wpckan_api_query_datasets($atts) {
if (is_null(wpckan_get_ckan_settings()))
wpckan_api_settings_error("wpckan_api_query_datasets");
if (!isset($atts['query']))
wpckan_api_call_error("wpckan_api_query_datasets",null);
try {
$settings = wpckan_get_ckan_settings();
$ckanClient = CkanClient::factory($settings);
$commandName = 'PackageSearch';
$arguments = array('q' => $atts['query']);
if (isset($atts['limit'])){
$arguments['rows'] = (int)$atts['limit'];
if (isset($atts['page'])){
$page = (int)$atts['page'];
if ($page > 0) $arguments['start'] = (int)$atts['limit'] * ($page - 1);
}
}
$filter = null;
if (isset($atts['organization'])) $filter = $filter . "+owner_org:" . $atts['organization'];
if (isset($atts['organization']) && isset($atts['group'])) $filter = $filter . " ";
if (isset($atts['group'])) $filter = $filter . "+groups:" . $atts['group'];
if (!is_null($filter)){
$arguments["fq"] = $filter;
}
$command = $ckanClient->getCommand($commandName,$arguments);
$response = $command->execute();
wpckan_log("wpckan_api_query_datasets commandName: " . $commandName . " arguments: " . print_r($arguments,true) . " settings: " . print_r($settings,true));
if ($response["success"]==false){
wpckan_api_call_error("wpckan_api_query_datasets",null);
}
} catch (Exception $e){
wpckan_api_call_error("wpckan_api_query_datasets",$e->getMessage());
}
return $response;
}
// Disable mousewheel zoom by default
function opendev_map_data($data) {
$data['disable_mousewheel'] = true;
return $data;
}
add_filter('jeo_map_data', 'opendev_map_data');
add_filter('jeo_mapgroup_data', 'opendev_map_data');
function opendev_custom_admin_css() {
?>
<style>
.handlers.map-setting { display: none !important; }
</style>
<?php
}
add_action('admin_footer', 'opendev_custom_admin_css');
function opendev_search_pre_get_posts($query) {
if(!is_admin() && ($query->is_search || get_query_var('opendev_advanced_nav') || $query->is_tax || $query->is_category || $query->is_tag)) {
$query->set('post_type', get_post_types(array('public' => true)));
}
}
add_action('pre_get_posts', 'opendev_search_pre_get_posts');
function opendev_category_pre_get_posts($query) {
if($query->is_category) {
$post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
$query->set('post_type', array($post_type));
}
}
add_action('pre_get_posts', 'opendev_category_pre_get_posts', 20, 1);
function opendev_posts_clauses_join($join) {
global $wpdb;
$join = " INNER JOIN {$wpdb->postmeta} m_maps ON ({$wpdb->posts}.ID = m_maps.post_id) ";
return $join;
}
//add_filter('jeo_posts_clauses_join', 'opendev_posts_clauses_join');
function opendev_posts_clauses_where($where) {
$map_id = jeo_get_map_id();
$where = '';
// MAP
if(get_post_type($map_id) == 'map') {
$where = " AND ( m_maps.meta_key = 'maps' AND CAST(m_maps.meta_value AS CHAR) = '{$map_id}' ) ";
// MAPGROUP
} elseif(get_post_type($map_id) == 'map-group') {
$groupdata = get_post_meta($map_id, 'mapgroup_data', true);
if(isset($groupdata['maps']) && is_array($groupdata['maps'])) {
$where = " AND ( ";
$size = count($groupdata['maps']);
$i = 1;
foreach($groupdata['maps'] as $m) {
$c_map_id = $m['id'];
$where .= " ( m_maps.meta_key = 'maps' AND CAST(m_maps.meta_value AS CHAR) = '{$c_map_id}' ) ";
if($i < $size) {
$where .= ' OR ';
}
$i++;
}
$where .= " ) ";
}
}
return $where;
}
//add_filter('jeo_posts_clauses_where', 'opendev_posts_clauses_where');
function opendev_ignore_sticky($query) {
if($query->is_main_query()) {
$query->set('ignore_sticky_posts', true);
}
}
add_action('pre_get_posts', 'opendev_ignore_sticky');