-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.php
187 lines (172 loc) · 4.59 KB
/
public.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
<?php
require_once('db.php');
require_once('marker.php');
/**
* @category plugin
* @package gmap
* @copyright MAGIX CMS Copyright (c) 2011 Gerits Aurelien, http://www.magix-dev.be, http://www.magix-cms.com
* @license Dual licensed under the MIT or GPL Version 3 licenses.
* @version 1.0
* @create 20-12-2021
* @author Aurélien Gérits <aurelien@magix-cms.com>
* @name plugins_gmap_public
*/
class plugins_gmap_public extends plugins_gmap_db {
/**
* @var frontend_model_template $template
* @var frontend_model_data $data
*/
protected frontend_model_template $template;
protected frontend_model_data $data;
/**
* @var bool $dotless
*/
public bool $dotless;
/**
* @var string $lang
* @var string $marker
*/
public string
$lang,
$marker;
/**
* @var array $conf
*/
public array $conf;
/**
*
*/
public function __construct() {
$this->template = new frontend_model_template();
$this->data = new frontend_model_data($this);
$this->lang = $this->template->lang;
if(http_request::isGet('marker')) $this->marker = form_inputEscape::simpleClean($_GET['marker']);
$this->dotless = http_request::isGet('dotless');
$config = $this->getItems('config');
if(!empty($config)) {
$configId = [];
$configValue = [];
foreach($config as $key){
$configId[] = $key['config_id'];
$configValue[] = $key['config_value'];
}
$config = array_combine($configId,$configValue);
}
$this->conf = $config;
}
/**
* Assign data to the defined variable or return the data
* @param string $type
* @param string|array|null $id
* @param string|null $context
* @param bool|string $assign
* @return mixed
*/
private function getItems(string $type, $id = null, ?string $context = null, $assign = false) {
return $this->data->getItems($type, $id, $context, $assign);
}
/**
* Load map data
* @return string
*/
private function setJsConfig(): string {
$addresses = $this->getAddresses();
//$config = $this->conf;
$config = ['api_key' => $this->conf['api_key']];
if($addresses != null) {
$map = [];
foreach ($addresses as $addr){
$mark = '{';
foreach ($addr as $k => $v) {
$mark .= '"'.str_replace('_address','',$k).'":'.json_encode($v).',';
}
$mark = substr($mark, 0, -1).'}';
$map[] = $mark;
}
$config['markers'] = '['.implode(',',$map).']';
}
else {
$config['markers'] = '[]';
}
$configString = [];
foreach ($config as $k => $v) {
if($k != 'markers')
$v = json_encode($v);
$configString[]= $k.':'.$v;
}
$detect = new Mobile_Detect;
$OS = false;
if( $detect->isiOS() ){
$OS = 'IOS';
}
elseif( $detect->isAndroidOS() ){
$OS = 'Android';
}
$configString[] = '"OS":"'.$OS.'"';
$configString[] = '"lang":"'.$this->lang.'"';
return '{'.implode(',',$configString).'}';
}
/**
* Load map data
* @return array
*/
private function setConfig(): array {
$config = [];
if(!empty($this->conf)) {
foreach ($this->conf as $k => $v) {
$config[$k] = $v;
}
}
return $config;
}
/**
* Execute le plugin dans la partie public
*/
public function run() {
$this->template->configLoad();
if(isset($this->marker)) {
$img = '';
if($this->marker === 'main') {
$markerPath = component_core_system::basePath().'/plugins/gmap/markers/'.$this->marker.($this->dotless?'-dotless':'').'.svg';
if(!file_exists($markerPath)) {
$config = parent::fetchData(array('context' => 'one','type' => 'config'));
$marker = new plugins_gmap_marker($config['markerColor'],$this->template);
$marker->createMarker();
} else {
$img = file_get_contents($markerPath);
}
}
else {
$img = file_get_contents(component_core_system::basePath().'/plugins/gmap/markers/grey'.($this->dotless?'-dotless':'').'.svg');
}
if($img !== '') {
header('Content-type: image/svg+xml');
print $img;
}
}
else {
$this->getItems('page',['lang' => $this->lang],'one',true);
$this->template->breadcrumb->addItem($this->template->getConfigVars('gmap'));
$this->template->assign('addresses',$this->getAddresses());
$this->template->assign('config',$this->setConfig());
$this->template->assign('config_gmap',$this->setJsConfig());
$this->template->display('gmap/index.tpl');
}
}
/**
* @return array
*/
public function outrun(): array {
return [
'page' => $this->getItems('page',['lang' => $this->lang],'one'),
'config' => $this->setConfig(),
'config_gmap' => $this->setJsConfig()
];
}
/**
* @return array
*/
public function getAddresses(): array {
return $this->getItems('addresses',['lang' => $this->lang],'all')?: [];
}
}