| Server IP : 46.105.57.169 / Your IP : 216.73.216.144 Web Server : Apache System : Linux webd003.cluster120.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : maitricfuz ( 93378) PHP Version : 8.4.10 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/maitricfuz/www/saint-martin-lg/plugins/pagebuilderck/openstreetmap/ |
Upload File : |
<?php
/**
* @copyright Copyright (C) 2015 Cédric KEIFLIN alias ced1870
* https://www.template-creator.com
* https://www.joomlack.fr
* @license GNU/GPL
* */
defined('_JEXEC') or die('Restricted access');
jimport('joomla.event.plugin');
class plgPagebuilderckOpenstreetmap extends \Joomla\CMS\Plugin\CMSPlugin {
private $context = 'PLG_PAGEBUILDERCK_OPENSTREETMAP';
private $type = 'openstreetmap';
function __construct(&$subject, $params) {
parent::__construct($subject, $params);
}
/*
* Construct the Menu Item to drag into the interface
*
* Return Object with item data
*/
public function onPagebuilderckAddItemToMenu() {
$doc = Pagebuilderck\CKFof::getDocument();
/* get the style for the leaflet map */
$doc->addStyleSheet('https://cdn.jsdelivr.net/leaflet/1/leaflet.css');
/* get the script for the leaflet map */
$doc->addScript('https://cdn.jsdelivr.net/leaflet/1/leaflet.js');
PagebuilderckFrontHelper::addStyleDeclaration('.openstreetmapmarkertitleck, .openstreetmapmarkercontentck {display: none;}');
// load the language files of the plugin
$this->loadLanguage();
// create the menu item
$menuitem = new stdClass();
$menuitem->type = $this->type;
$menuitem->group = 'other';
$menuitem->title = Pagebuilderck\CKText::_($this->context . '_MENUITEM_TITLE');
$menuitem->description = Pagebuilderck\CKText::_($this->context . '_MENUITEM_DESC');
$menuitem->image = Pagebuilderck\CKUri::root(true) . '/plugins/pagebuilderck/openstreetmap/assets/images/map.svg';
return $menuitem;
}
/*
* Display the html code for the item to be used into the interface
*
* Return String the html code
*/
public function onPagebuilderckLoadItemContentOpenstreetmap() {
// ckstyle and inner classes are needed to get the styles from the interface
$input = Pagebuilderck\CKFof::getInput();
$id = $input->get('ckid', '', 'string');
?>
<div id="<?php echo $id; ?>" class="cktype" data-type="<?php echo $this->type ?>">
<div class="ckstyle">
</div>
<div class="openstreetmapck inner">
<img style="display:block;margin: 0 auto;" src="<?php echo Pagebuilderck\CKUri::root(true); ?>/plugins/pagebuilderck/openstreetmap/assets/images/open_street_map_example.svg" width="100%" height="auto" />
<div class="openstreetmapmarkertitleck"></div>
<div class="openstreetmapmarkercontentck"></div>
</div>
</div>
<?php
}
/*
* Display the html code for the item to be used into the interface
*
* Return String the html code
*/
public function onPagebuilderckLoadItemOptionsOpenstreetmap() {
// load the language files of the plugin
$this->loadLanguage();
// load the interface for the options
$tpl = JPATH_SITE . '/plugins/pagebuilderck/openstreetmap/layouts/edit_openstreetmap.php';
return $tpl;
}
/*
* Display the html code for the item to be used into the frontend page
* @param string the item object from simple_html_dom
*
* Return String the html code
*/
public function onPagebuilderckRenderItemOpenstreetmap($item) {
// load the helper to help us to use the parameters
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/pagebuilderckfront.php';
// ckstyle and inner classes are needed to get the styles from the interface
$ckstyle = $item->find('.ckstyle');
$styles = count($ckstyle) ? $ckstyle[0]->innertext : '';
// get the content of the marker
$content = $item->find('.openstreetmapmarkercontentck');
$content = count($content) ? $content[0]->innertext : '';
// get the title of the marker
$title = $item->find('.openstreetmapmarkertitleck');
$title = count($title) ? $title[0]->innertext : '';
$mapattrs = $item->find('.tab_map'); // this is the tab id in the interface which contains the map options
$params = PagebuilderckFrontHelper::createParamsFromElement($mapattrs);
// get custom data for the addon ID
$data = PagebuilderckHelper::getOption('openstreetmap.' . $item->attr['id']);
if ($data) $data = unserialize($data);
// $apikey = $this->params->get('gmapapikey', '');
$doc = Pagebuilderck\CKFof::getDocument();
/* get the style for the leaflet map */
$doc->addStyleSheet('https://cdn.jsdelivr.net/leaflet/1/leaflet.css');
/* get the script for the leaflet map */
$doc->addScript('https://cdn.jsdelivr.net/leaflet/1/leaflet.js');
$layers = [
"default" => "var mapLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
});
",
"roadmap" => "var mapLayer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
attribution: '© OpenStreetMap, © CartoDB'
});
",
"satellite" => "var mapLayer = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: '© Esri & contributors'
});
",
"hybrid" => "var mapLayer = L.layerGroup([
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'),
L.tileLayer('https://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}', {
attribution: '© Esri'
})
]);
"
];
$html = '<style>
#openstreetmapwrapper'.$item->attr['id'].' {
width: ' . PagebuilderckFrontHelper::testUnit($params->get('mapwidth', '500px')) .';
height: ' . PagebuilderckFrontHelper::testUnit($params->get('mapheight', '400px')) .';
overflow: hidden;
}
</style>
<div class="ckstyle">
'. $styles . '
</div>
<div id="openstreetmapwrapper'.$item->attr['id'].'" class="openstreetmapck inner">
<div id="map'.$item->attr['id'].'" style="height:100%;width:100%;"></div>
</div>
<script>
(function ($) {
var map'.$item->attr['id'].';
$(function () {
// Initialize the map
// This variable map is inside the scope of the jQuery function.
// Now map reference the global map declared in the first line
' . $layers[$params->get('maptype', 'default')] . '
map'.$item->attr['id'].' = L.map(\'map'.$item->attr['id'].'\', {
scrollWheelZoom: ' . $params->get('scroll', 'true') . ', layers: [mapLayer]
}).setView([' . $params->get('latitude', '44.5403') . ', ' . $params->get('longitude', '-78.5463') . '], ' . $params->get('mapzoom', 8) . ');
// L.tileLayer(\'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\', {
// attribution: \'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>\',
// maxZoom: 18
// }).addTo(map'.$item->attr['id'].');
var map'.$item->attr['id'].'_bounds = L.latLngBounds()
';
if (empty($data)) {
$html .= 'markerck = L.marker([' . $params->get('latitude', '44.5403') . ', ' . $params->get('longitude', '-78.5463') . ']).addTo(map'.$item->attr['id'].');
if (\'' . !empty($content) . '\' || \'' . !empty($title) . '\') {
markerck.bindPopup("' . $title . '<br/>' . addslashes(str_replace(array("\r\n", "\r", "\n"), "<br style=\"display:none;\"/>", trim($content))) . '");
if (\'' . $params->get('markershowon', '') . '\' == \'always\') {
markerck.openPopup();
} else {
markerck.on(\'click\', function() { markerck.openPopup() });
}
}';
} else {
foreach($data as $i => $d) {
/*$html .= 'markerck = L.marker([' . $params->get('latitude', '44.5403') . ', ' . $params->get('longitude', '-78.5463') . ']).addTo(map'.$item->attr['id'].');
if (\'' . !empty($content) . '\' || \'' . !empty($title) . '\') {
markerck.bindPopup("' . $title . '<br/>' . addslashes(str_replace(array("\r\n", "\r", "\n"), "<br style=\"display:none;\"/>", trim($content))) . '");
if (\'' . $params->get('markershowon', '') . '\' == \'always\') {
markerck.openPopup();
} else {
markerck.on(\'click\', function() { markerck.openPopup() });
}
}';*/
if ($d['lat'] && $d['long']) {
if ($d['title'] || $d['text']) {
$popup = 'markerck'.$item->attr['id'].'' . $i . '.bindPopup("' . $d['title'] . '<br/>' . addslashes(str_replace(array("\r\n", "\r", "\n"), "<br style=\"display:none;\"/>", trim($d['text']))) . '");';
if ($params->get('markershowon', '') == 'always') {
$popup .= 'markerck'.$item->attr['id'].'' . $i . '.openPopup();';
} else {
$popup .= 'markerck'.$item->attr['id'].'' . $i . '.on(\'click\', function() { markerck.openPopup() });';
}
} else {
$popup = '';
}
$html .= 'const lat_lng'.$item->attr['id'].'' . $i . ' = [' . $d['lat'] . ', ' . $d['long'] . '];'
. '
markerck'.$item->attr['id'].'' . $i . ' = L.marker(lat_lng'.$item->attr['id'].'' . $i . ').addTo(map'.$item->attr['id'].');'
. $popup
. '
map'.$item->attr['id'].'_bounds.extend(lat_lng'.$item->attr['id'].'' . $i . ');'
;
}
}
if ($params->get('latitude', '') && $params->get('longitude', '')) {
$html .= '
map'.$item->attr['id'].'.setView([zoomLat, zoomLong], parseInt(mapzoom));';
} else if ($params->get('mapzoom', '')) {
$html .= '
map'.$item->attr['id'].'.fitBounds(map'.$item->attr['id'].'_bounds);
const map'.$item->attr['id'].'_fitCenter = map'.$item->attr['id'].'.getCenter();
map'.$item->attr['id'].'.setView(map'.$item->attr['id'].'_fitCenter, parseInt(' . $params->get('mapzoom', '') . '));';
} else {
$html .= 'map'.$item->attr['id'].'.fitBounds(map'.$item->attr['id'].'_bounds);';
}
}
$html .= '
});
})(jQuery);
</script>
';
return $html;
}
}