forked from taviroquai/mapigniter2
/
MapController.php
104 lines (90 loc) · 2.34 KB
/
MapController.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
<?php namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Idiom;
use App\Map;
use App\Brand;
class MapController extends BaseController
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
// Load idiom
Idiom::loadIdiom();
}
/**
* Load map layout
*
* @param Map $map
*/
public function getMap(Map $map)
{
$data = [
'user' => \Auth::user(),
'brand' => Brand::where('active', 1)->first(),
'map' => $map
];
return view('map', $data);
}
/**
* Get map configuration
*
* @return Response
*/
public function getConfig(Map $map)
{
// Build output JSON config
$map->projection;
$config = [
'map' => $map,
'layers' => \App\Layeritem::with('layer', 'group', 'layer.content', 'group.content')
->where('map_id', $map->id)
->orderBy('displayorder')
->get(),
'layerswitcher' => [
"closed" => []
],
'proxy' => url('proxy')
];
return response()->json($config);
}
/**
* Forward HTTP request
* @param type $url
*/
public function proxyRequest($url)
{
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = base64_decode($url);
// Return not-allowed if is no OWS request
if (
!strpos($url, strtoupper('SERVICE'))
|| !strpos($url, strtoupper('REQUEST'))
) {
die('Invalid request');
}
//echo $url; die();
// Make request
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
list($header, $body) = explode("\r\n\r\n", $response, 2);
// Send headers
$i = 0;
$headers = explode("\r\n", $header);
foreach($headers as $header) {
$i++;
if ($i === 1) continue;
if ($header === 'Transfer-Encoding: chunked') continue;
header($header);
}
// Send file
die($body);
}
}