This repository was archived by the owner on May 5, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmembermap.php
executable file
·145 lines (113 loc) · 4.92 KB
/
membermap.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
<?php
/**
* @author Branko Wilhelm <[email protected]>
* @link http://www.z-index.net
* @copyright (c) 2014 - 2015 Branko Wilhelm
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die;
class plgSystemMemberMap extends JPlugin
{
protected $loaded = false;
protected $adapter = null;
public function onAjaxMembermap()
{
$input = JFactory::getApplication()->input;
$key = $input->getString('key');
$val = $input->getString('val');
if (!empty($val)) {
$val = explode(',', $val);
$obj = new stdClass;
$obj->lat = (float)filter_var($val[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
$obj->lng = (float)filter_var($val[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
$val = $obj;
}
return $this->handleLocation($key, $val);
}
protected function handleLocation($key, $val = null)
{
$cache = JFactory::getCache('membermap', 'output');
$cache->setCaching(1);
$cache->setLifeTime($this->params->get('cache_timeout', 24) * 60);
$key = md5($key);
if (empty($val)) {
return $cache->get($key);
} else {
return $cache->store($val, $key);
}
}
public function onContentPrepare($context, &$row, &$params, $page = 0)
{
if (JString::strpos($row->text, '{membermap}') === false) {
return true;
}
$this->loadLanguage();
JLoader::discover('MemberMapAdapter', __DIR__ . '/adapters/');
$class = 'MemberMapAdapter' . $this->params->get('source');
if (class_exists($class)) {
$this->adapter = new $class($this->params);
} else {
JFactory::getApplication()->enqueueMessage(JText::sprintf('PLG_SYSTEM_MEMBERMAP_SOURCE_NOT_AVAILABLE', $this->params->get('source')), 'error');
return true;
}
if ($this->loaded == true) {
JFactory::getApplication()->enqueueMessage(JText::_('PLG_SYSTEM_MEMBERMAP_ONLY_ONE_INSTANCE'), 'error');
return true;
} else {
$this->initMap();
$this->loaded = true;
}
$row->text = JString::str_ireplace('{membermap}', '<div id="membermap"></div>', $row->text);
}
protected function initMap()
{
$users = $this->adapter->getUsers();
if (empty($users)) {
JFactory::getApplication()->enqueueMessage(JText::_('PLG_SYSTEM_MEMBERMAP_NO_USERS'), 'warning');
return false;
}
$doc = JFactory::getDocument();
$query['sensor'] = $this->params->get('sensor') ? 'true' : 'false';
if ($this->params->get('key')) {
$query['key'] = $this->params->get('key');
}
$query = http_build_query($query);
$doc->addScript('//maps.googleapis.com/maps/api/js?' . $query);
if ($this->params->get('cluster')) {
$doc->addScript('//cdnjs.cloudflare.com/ajax/libs/js-marker-clusterer/1.0.0/markerclusterer_compiled.js');
}
foreach ($users as $user) {
if ($postion = $this->handleLocation($user->address)) {
$user->position = $postion;
$user->position->lat = (float)$user->position->lat;
$user->position->lng = (float)$user->position->lng;
$user->ready = true;
}
}
$js[] = 'membermap.users = ' . json_encode($users);
if ($this->params->get('legend', 1)) {
$css[] = '#membermap_legend{max-height:' . ($this->params->get('height', 500) - 100) . 'px;}';
$doc->addStyleDeclaration(implode($css));
$doc->addStyleSheet('media/plg_system_membermap/membermap.css');
}
$config = new stdClass;
$config->center = (int)$this->params->get('center', 2);
$config->legend = $this->params->get('legend', 1) ? true : false;
$config->drop = $this->params->get('drop', 1) ? true : false;
$config->delay = (int)$this->params->get('delay', 750);
$config->width = $this->params->get('width', '100%');
$config->height = (int)$this->params->get('height', 500);
$config->type = strtoupper($this->params->get('type', 'ROADMAP'));
$config->zoom = (int)$this->params->get('zoom', 1);
$config->lat = (float)$this->params->get('lat', 42);
$config->lng = (float)$this->params->get('lng', 11);
$config->requests = (int)$this->params->get('requests', 3);
$config->size = (int)$this->params->get('size', 30);
$config->cluster = $this->params->get('cluster', 1) ? true : false;
$config->base = JUri::base();
$js[] = 'membermap.config = ' . json_encode($config);
$doc->addScriptDeclaration(implode(';', $js));
JHtml::_('jquery.framework');
$doc->addScript('media/plg_system_membermap/membermap.js');
}
}