-
Notifications
You must be signed in to change notification settings - Fork 1
/
backend.php
72 lines (65 loc) · 2.32 KB
/
backend.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
<?php
require ('../../../wp-load.php');
if ($_GET['endpoint'] == 'networkNews') {
$postsPerPage =20;
$qParams=array(
'post_type' => array('post')
,'cat' => get_cat_id('Map it')
,'posts_per_page' => $postsPerPage
,'post_status' => array('publish')
);
/*** late in the game we ran into a pagination issue, so we're running a second query here ***/
$custom_query_args= $qParams;
$custom_query = new WP_Query( $custom_query_args );
$features = array();
if ( $custom_query->have_posts() ) :
$counter = 0;
while ( $custom_query->have_posts() ) : $custom_query->the_post();
$id = $_GET['page_id'];
$location = get_post_meta( $id, 'map_location', true );
$storyLink = get_permalink();
$mapHeadline = get_post_meta( $id, 'map_headline', true );
//$mapHeadline = "<a href='". $storyLink ."'>" . $mapHeadline . '</a>';
$mapDescription = get_the_title();
$mapDate = get_the_date();
$mapDescription = $mapDescription . " <span class='bbg__map__infobox__date'>(" . $mapDate . ")</span>";
$pinColor = "#981b1e";
if (has_category('VOA')){
$pinColor = "#344998";
$mapHeadline = "<h5><a href='". $storyLink ."'>VOA | " . $mapHeadline . '</a></h5>';
} elseif (has_category('RFA')){
$pinColor = "#009c50";
$mapHeadline = "<h5><a href='". $storyLink ."'>RFA | " . $mapHeadline . '</a></h5>';
} elseif (has_category('RFE/RL')){
$pinColor = "#ea6828";
$mapHeadline = "<h5><a href='". $storyLink ."'>RFE/RL | " . $mapHeadline . '</a></h5>';
} else {
$mapHeadline = "<h5><a href='". $storyLink ."'>" . $mapHeadline . '</a></h5>';
}
$features[] = array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
'coordinates' => array($location['lng'],$location['lat'])
),
'properties' => array(
'title' => $mapHeadline,
'description' => $mapDescription,
'marker-color' => $pinColor,
'marker-size' => 'large',
'marker-symbol' => ''
)
);
endwhile;
$geojsonObj= array(array(
'type' => 'FeatureCollection',
'features' => $features
));
header('Content-Type: application/javascript');
header("Access-Control-Allow-Origin: *");
$geojsonStr=json_encode(new ArrayValue($geojsonObj), JSON_PRETTY_PRINT, 10);
echo "geojson = $geojsonStr";
//echo $geojsonStr;
endif;
}
?>