Skip to content

Commit 891d3ff

Browse files
committed
Added Helper function
1 parent f91d40b commit 891d3ff

File tree

3 files changed

+270
-131
lines changed

3 files changed

+270
-131
lines changed

inc/Front/Waymark_HTTP.php

+130-130
Original file line numberDiff line numberDiff line change
@@ -3,185 +3,185 @@
33
class Waymark_HTTP {
44

55
function __construct() {
6-
add_filter('query_vars', array($this, 'query_vars'));
7-
add_action('template_redirect', array($this, 'template_redirect'));
8-
6+
add_filter('query_vars', array($this, 'query_vars'));
7+
add_action('template_redirect', array($this, 'template_redirect'));
8+
99
//Setup AJAX
10-
Waymark_JS::add_chunk('//HTTP');
11-
Waymark_JS::add_chunk('var waymark_http_endpoint = "' . Waymark_Helper::http_url() . '";');
10+
Waymark_JS::add_chunk('//HTTP');
11+
Waymark_JS::add_chunk('var waymark_http_endpoint = "' . Waymark_Helper::http_url() . '";');
1212
}
1313

1414
public function query_vars($vars) {
1515
$vars[] = 'waymark_http';
16-
16+
1717
return $vars;
1818
}
1919

2020
public function template_redirect() {
2121
//If not Waymark HTTP request
22-
if(! get_query_var('waymark_http')) {
23-
//WP loads normally
22+
if (!get_query_var('waymark_http')) {
23+
//WP loads normally
2424
return;
2525
}
2626

2727
//Action
2828
//!!! Submission
29-
if(array_key_exists('waymark_message', $_REQUEST)) {
29+
if (array_key_exists('waymark_message', $_REQUEST)) {
3030
//Waymark_Helper::debug('Joetest!' . $_REQUEST['waymark_message'], false);
3131
}
3232

3333
//Action
34-
if(array_key_exists('waymark_action', $_REQUEST)) {
34+
if (array_key_exists('waymark_action', $_REQUEST)) {
3535
//Requires Map Data
36-
if(in_array($_REQUEST['waymark_action'], array(
36+
if (in_array($_REQUEST['waymark_action'], array(
3737
'get_map_data',
3838
'download_map_data',
39-
'download_collection_data'
39+
'download_collection_data',
4040
))) {
4141
//Do we have data?
42-
if(array_key_exists('map_id', $_REQUEST) && is_numeric($_REQUEST['map_id'])) {
42+
if (array_key_exists('map_id', $_REQUEST) && is_numeric($_REQUEST['map_id'])) {
4343
//Valid Map
44-
if($Map = new Waymark_Map($_REQUEST['map_id'])) {
45-
if(isset($Map->data['map_data']) && ! empty($Map->data['map_data'])) {
44+
if ($Map = new Waymark_Map($_REQUEST['map_id'])) {
45+
if (isset($Map->data['map_data']) && !empty($Map->data['map_data'])) {
4646
//Clean
47-
$map_data = Waymark_Helper::remove_unwanted_data_properties($Map->data['map_data']);
48-
//Invalid Map data
47+
$map_data = Waymark_Helper::remove_unwanted_overlay_properties($Map->data['map_data']);
48+
//Invalid Map data
4949
} else {
5050
die("-1");
51-
}
52-
//Invalid Map
51+
}
52+
//Invalid Map
5353
} else {
54-
die("-1");
54+
die("-1");
5555
}
56-
} elseif(array_key_exists('collection_id', $_REQUEST) && is_numeric($_REQUEST['collection_id'])) {
56+
} elseif (array_key_exists('collection_id', $_REQUEST) && is_numeric($_REQUEST['collection_id'])) {
5757
$Collection = new Waymark_Collection($_REQUEST['collection_id']);
58-
//Invalid Map ID
58+
//Invalid Map ID
5959
} else {
60-
die("-1");
60+
die("-1");
6161
}
6262

6363
//Gzip supported?
64-
if(function_exists('gzcompress') && ! in_array('ob_gzhandler', ob_list_handlers())) {
65-
ob_start("ob_gzhandler");
64+
if (function_exists('gzcompress') && !in_array('ob_gzhandler', ob_list_handlers())) {
65+
ob_start("ob_gzhandler");
6666
} else {
67-
ob_start();
68-
}
67+
ob_start();
68+
}
6969

7070
//Cache
71-
header('Cache-control: public,max-age=' . DAY_IN_SECONDS);
72-
73-
switch($_REQUEST['waymark_action']) {
74-
// === AJAX Load ===
75-
76-
case 'get_map_data' :
77-
//Security
78-
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
79-
80-
//Required data
81-
if(! isset($map_data) || ! isset($Map)) {
82-
die("-1");
83-
}
84-
85-
//Modify
86-
if(Waymark_Config::get_setting('misc', 'collection_options', 'link_to_maps') == true && $_REQUEST['link_to_map'] == true) {
87-
$map_data = Waymark_Helper::add_map_link_to_description($Map->post_id, $Map->post_title, $map_data);
88-
}
89-
90-
//Type
91-
header('Content-Type: application/geo+json');
71+
header('Cache-control: public,max-age=' . DAY_IN_SECONDS);
72+
73+
switch ($_REQUEST['waymark_action']) {
74+
// === AJAX Load ===
75+
76+
case 'get_map_data':
77+
//Security
78+
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
79+
80+
//Required data
81+
if (!isset($map_data) || !isset($Map)) {
82+
die("-1");
83+
}
84+
85+
//Modify
86+
if (Waymark_Config::get_setting('misc', 'collection_options', 'link_to_maps') == true && $_REQUEST['link_to_map'] == true) {
87+
$map_data = Waymark_Helper::add_map_link_to_description($Map->post_id, $Map->post_title, $map_data);
88+
}
89+
90+
//Type
91+
header('Content-Type: application/geo+json');
92+
93+
//The content
94+
if (isset($map_data) && $map_data) {
95+
echo $map_data;
96+
}
97+
98+
break;
9299

93-
//The content
94-
if(isset($map_data) && $map_data) {
95-
echo $map_data;
96-
}
97-
98-
break;
99-
100100
// === Collection Export ===
101-
102-
case 'download_collection_data' :
103-
//Security
104-
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
105-
106-
//Required data
107-
if(! isset($Collection)) {
108-
die("-1");
109-
}
110-
111-
//File download name
112-
$export_filename = $Collection->slug . '-' . $Collection->collection_id . '.' . $_REQUEST['export_format'];
113-
101+
102+
case 'download_collection_data':
103+
//Security
104+
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
105+
106+
//Required data
107+
if (!isset($Collection)) {
108+
die("-1");
109+
}
110+
111+
//File download name
112+
$export_filename = $Collection->slug . '-' . $Collection->collection_id . '.' . $_REQUEST['export_format'];
113+
114+
break;
115+
116+
// === Map Export ===
117+
118+
case 'download_map_data':
119+
//Security
120+
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
121+
122+
//Required data
123+
if (!isset($map_data) || !isset($Map)) {
124+
die("-1");
125+
}
126+
127+
//File download name
128+
$export_filename = get_post_field('post_name', $Map->post_id) . '-' . $Map->post_id . '.' . $_REQUEST['export_format'];
129+
130+
break;
131+
}
132+
133+
//Echo
134+
if (isset($export_filename) && isset($_REQUEST['map_data'])) {
135+
header('Content-Disposition: attachment; filename="' . $export_filename . '"');
136+
137+
switch ($_REQUEST['export_format']) {
138+
case 'gpx':
139+
header('Content-Type: application/gpx+xml');
140+
114141
break;
115-
116-
// === Map Export ===
117-
118-
case 'download_map_data' :
119-
//Security
120-
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
121-
122-
//Required data
123-
if(! isset($map_data) || ! isset($Map)) {
124-
die("-1");
125-
}
126-
127-
//File download name
128-
$export_filename = get_post_field('post_name', $Map->post_id) . '-' . $Map->post_id . '.' . $_REQUEST['export_format'];
129-
142+
case 'kml':
143+
header('Content-Type: application/vnd.google-earth.kml+xml');
144+
145+
break;
146+
case 'geojson':
147+
header('Content-Type: application/geo+json');
148+
130149
break;
131-
}
132-
133-
//Echo
134-
if(isset($export_filename) && isset($_REQUEST['map_data'])) {
135-
header('Content-Disposition: attachment; filename="' . $export_filename . '"');
136-
137-
switch($_REQUEST['export_format']) {
138-
case 'gpx' :
139-
header('Content-Type: application/gpx+xml');
140-
141-
break;
142-
case 'kml' :
143-
header('Content-Type: application/vnd.google-earth.kml+xml');
144-
145-
break;
146-
case 'geojson' :
147-
header('Content-Type: application/geo+json');
148-
149-
break;
150150
}
151151

152-
echo rawurldecode(strip_tags($_REQUEST['map_data']));
152+
echo rawurldecode(strip_tags($_REQUEST['map_data']));
153153
}
154-
154+
155155
//That's it, that's all...
156-
die;
157-
158-
//Does not require Map data
156+
die;
157+
158+
//Does not require Map data
159159
} else {
160-
switch($_REQUEST['waymark_action']) {
161-
// === Public Submissions ===
162-
case'public_add_map' :
163-
//Security
164-
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
165-
166-
//Create submission
167-
$Submission = new Waymark_Submission($_REQUEST);
168-
169-
//Ensure submissions allowed
170-
if($Submission->get_allowed() === true) {
171-
//Create Map
172-
$Submission->create_map();
173-
174-
$Submission->do_redirect();
175-
160+
switch ($_REQUEST['waymark_action']) {
161+
// === Public Submissions ===
162+
case 'public_add_map':
163+
//Security
164+
check_ajax_referer(Waymark_Config::get_item('nonce_string'), 'waymark_security');
165+
166+
//Create submission
167+
$Submission = new Waymark_Submission($_REQUEST);
168+
169+
//Ensure submissions allowed
170+
if ($Submission->get_allowed() === true) {
171+
//Create Map
172+
$Submission->create_map();
173+
174+
$Submission->do_redirect();
175+
176176
// Waymark_Helper::debug($Submission);
177177
//Submission not allowed
178-
} else {
179-
///!!! Submission
180-
}
181-
182-
break;
183-
}
184-
178+
} else {
179+
///!!! Submission
180+
}
181+
182+
break;
183+
}
184+
185185
die;
186186
}
187187
}

0 commit comments

Comments
 (0)