AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.112
Web Server : Apache
System : Linux webm013.cluster127.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 : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/nice2/plugins/djclassifieds/leaflet/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/nice2/plugins/djclassifieds/leaflet/leaflet.php
<?php
/**
 * @package DJ-Classifieds
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 *
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );

class plgDJClassifiedsLeaflet extends JPlugin
{
	static private $_enabled = false;

	public function __construct(&$subject, $config)
	{
		$par = JComponentHelper::getParams('com_djclassifieds');
		if($par->get('map_provider') == 'leaflet'){
			self::$_enabled = true;
		}

		parent::__construct ( $subject, $config );
		$this->loadLanguage ();
	}

	public function onIncludeMapsScripts(&$load_gm_script)
	{	
		if(!self::$_enabled){
			return;
		}

	 	$document = JFactory::getDocument();

		$ver = $this->params->get('ver','1.3.4');
		$document->addStyleSheet('https://unpkg.com/leaflet@'.$ver.'/dist/leaflet.css');
		$document->addScript('https://unpkg.com/leaflet@'.$ver.'/dist/leaflet.js');
		
		$load_gm_script = 0;
		return true;
	}
	
	function onGeocoderGetLocation(&$use_gm, $address)
	{
		if(!self::$_enabled){
			return;
		}

		$use_gm = 0;		
		return $this->onLeafletGetLocation($address);
	}

	function onGeocoderGetLocationPostCode(&$use_gm, $post_code, $address)
	{
		if(!self::$_enabled){
			return;
		}

		$use_gm = 0;
		return $this->onLeafletGetLocation($address, $post_code);
	}

	function onGeocoderGetAddressLatLon(&$use_gm, $latlng)
	{
		if(!self::$_enabled){
			return;
		}

		$use_gm = 0;
		$latlng_arr = explode(',', $latlng);
		$resp = $this->leafletGetLocationReverse($latlng_arr[0], $latlng_arr[1]);

		if(isset($resp['display_name'])){
			return $resp['display_name'];
		}elseif(isset($resp['error'])){
			return $resp['error'];
		}else{
            return null;
        }
	}

	public function onItemEditFormSections($item, $par, $subscr_id)
	{
		if(!self::$_enabled){
			return;
		}
		if($par->get('allow_user_lat_lng','0') == '0'){
			return null;
		}
		$isnew = !$item->id ? true : false;
		return $this->scriptMap($item, $par, $isnew);
	}

	public function onProfileEditFormSections($profile, $custom_fields, $custom_values_c, $profile_image, &$par)
	{
		if(!self::$_enabled){
			return;
		}
		if($par->get('allow_user_lat_lng','0') == '0'){
			return null;
		}
		$isnew = false;
		return $this->scriptMap($profile, $par, $isnew);
	}

	public function onUserRegistrationForm(&$par)
	{
		if(!self::$_enabled){
			return;
		}
		if($par->get('allow_user_lat_lng','0') == '0'){
			return null;
		}
		$isnew = true;
		return $this->scriptMap(null, $par, $isnew);
	}

	function scriptMap($item, $par, $isnew)
	{
		$document = JFactory::getDocument();
		if($par->get('places_in_address','0')){
			$document->addScript(JURI::base(true).'/plugins/djclassifieds/leaflet/assets/js/poi.jquery.js');
			$document->addStyleSheet(JURI::base(true).'/plugins/djclassifieds/leaflet/assets/css/poi.css');
		}

		$tile_data = $this->onGetLeafletTileProvider();
		$tile_data = isset($tile_data[0]) && is_array($tile_data[0]) ? $tile_data[0] : $tile_data;

		$lat = '';
		$lng = '';
		if($item && floatval($item->latitude) && floatval($item->longitude)){
			$lat = $item->latitude;
			$lng = $item->longitude;
		}else if(isset($_COOKIE["djcf_latlon"])) {
			$lat_lon = explode('_', $_COOKIE["djcf_latlon"]);
			$lat = $lat_lon[0];
			$lng = $lat_lon[1];
		}else{
			$loc_coord = $this->onLeafletGetLocation($par->get('map_lat_lng_address','England, London'));
			if($loc_coord){
				$lat = $loc_coord['lat'];
				$lng = $loc_coord['lng'];
			}
		}

		$content = DJClassifiedsTheme::renderLayout('form', array(
			'lat' => $lat,
			'lng' => $lng,
			'isnew' => $isnew,
			'tile_data' => $tile_data,
			'par' => $par,
			'params' => $this->params
		), 'plugin', $this->_name);

		return $content;
	}

	public function onPrepareDJClassifiedsSearchModule($params, $mod)
	{
		if(!self::$_enabled){
			return;
		}
		$document = JFactory::getDocument();
		if($params->get('show_address','0')){
			$document->addScript(JURI::base(true).'/plugins/djclassifieds/leaflet/assets/js/poi.jquery.js');
			$document->addStyleSheet(JURI::base(true).'/plugins/djclassifieds/leaflet/assets/css/poi.css');
		}
	}

	public function onBeforeDJClassifiedsDisplayAdvertMap($item, $par, $view_type)
	{
		if(!self::$_enabled){
			return;
		}
		$app = JFactory::getApplication();
		if(($par->get('show_googlemap','0')=='0' || $par->get('show_googlemap','0')=='3') && !$app->isClient('administrator')){
			return;
		}
		
		return $this->displayMap($item, $par, $view_type);
	}

	public function onBeforeDJClassifiedsDisplayProfileMap($profile, $par, $view_type)
	{
		if(!self::$_enabled){
			return;
		}
		if(($par->get('show_googlemap','0')=='0' || $par->get('show_googlemap','0')=='2') && !JFactory::getApplication()->isClient('administrator')){
			return;
		}

		$item = new stdClass();
		$item->latitude = '';
		$item->longitude = '';
		$item->name = '';
		$item->intro_desc = '';

		if(is_array($profile)){ // front
			if(!empty($profile['details']->latitude) && !empty($profile['details']->longitude)){
				$item->latitude = $profile['details']->latitude;
				$item->longitude = $profile['details']->longitude;
				$item->name = $profile['name'];
				$item->intro_desc = !empty($profile['details']->address) ? $profile['details']->address : '';
			}
		}else{ // back-end
			$item->latitude = $profile->latitude;
			$item->longitude = $profile->longitude;
			$item->name = $profile->user_id;
			$item->intro_desc = $profile->address;
		}

		return $this->displayMap($item, $par, $view_type);
	}

	function displayMap($item, $par, $view_type)
	{
		$app = JFactory::getApplication();

		$par->set('show_googlemap',0);

		if(($item->latitude=='0.000000000000000' && $item->longitude=='0.000000000000000') || (!$item->latitude && !$item->longitude)){
			if($app->isClient('administrator')){ // geocode only on front
				return;
			}

			if($address = $this->getFullAddress($item)){
				$lat_lng = $this->onLeafletGetLocation($address);

				if($lat_lng){
					$item->latitude = $lat_lng['lat'];
					$item->longitude = $lat_lng['lng'];
				}else{
					return false;
				}
			}else{
				return false;
			}
		}

		$tile_data = $this->onGetLeafletTileProvider();
		$tile_data = isset($tile_data[0]) && is_array($tile_data[0]) ? $tile_data[0] : $tile_data;

		if(empty($tile_data)){
			die('no Leaflet tile data found');
		}

		$use_gm = 0;
		$this->onIncludeMapsScripts($use_gm);

		$marker_img = DJClassifiedsGeocode::getMarkerIconImg($par, !empty($item->cat_id) ? $item->cat_id : null);
		$icon_size = !empty($marker_img) ? getimagesize(JPATH_ROOT.'/'.$marker_img) : array('','');
		$icon_img = !empty($marker_img) ? JUri::root().$marker_img : '';

		$content = DJClassifiedsTheme::renderLayout('item', array(
			'view_type' => $view_type,
			'item' => $item,
			'icon_img' => $icon_img,
			'icon_size' => $icon_size,
			'tile_data' => $tile_data,
			'par' => $par,
			'params' => $this->params
		), 'plugin', $this->_name);

		return $content;
	}

	public function onGetLeafletTileProvider()
	{
		if(!self::$_enabled){
			return;
		}
		$tile_provider = $this->params->get('tile_provider', 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
		$tile_options = $this->params->get('tile_options', '&#123;&quot;attribution&quot;: &quot;&#169; &lt;a target=&apos;_blank&apos; rel=&apos;noopener noreferrer&apos; href=&apos;https://www.openstreetmap.org/copyright&apos;&gt;OpenStreetMap&lt;/a&gt;&quot;&#125;');
		$tile_options = json_decode($tile_options);
		$attribution_prefix = $this->params->get('attribution_prefix', '<a href="https://leafletjs.com" rel="noopener noreferrer" title="A JS library for interactive maps">Leaflet</a>');

		return [$tile_provider, $tile_options, $attribution_prefix];
	}

	function onLeafletGetLocation($address, $post_code = '')
	{
		if(!self::$_enabled){
			return;
		}

		require_once(JPATH_ROOT.'/administrator/components/com_djclassifieds/lib/djgeocoder.php');
		DJClassifiedsGeocode::serverFnCheck();

		$address_query = str_replace('ul. ', '', $address); // this street prefix is causing a problem in nominatim
		if($post_code){
			$address_query .= ', '.$post_code;
		}

		$url = "https://nominatim.openstreetmap.org/search?format=json&q=".urlencode($address_query);

		$c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($c, CURLOPT_REFERER, JURI::root()); // nominatim requires providing HTTP REFERER
        
		$resp_json = curl_exec($c);
        curl_close($c);
			        	        
		$resp = json_decode($resp_json, true);

		if(isset($resp[0])){
			return array('lat' => $resp[0]['lat'], 'lng' => $resp[0]['lon']);
		}elseif($post_code){ // if no results - try again without a postcode
			return $this->onLeafletGetLocation($address);
		}else{
            return null;
        }
	}

	function leafletGetLocationReverse($lat, $lng)
	{
		if(!self::$_enabled){
			return;
		}
		$url = "https://nominatim.openstreetmap.org/reverse.php?format=json&lat=".$lat."&lon=".$lng;

		$c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($c, CURLOPT_REFERER, JURI::root()); // nominatim requires providing HTTP REFERER
        
		$resp_json = curl_exec($c);
        curl_close($c);
			        	        
		$resp = json_decode($resp_json, true);

		return $resp;
	}

	private function getFullAddress($item)
	{
		$db = JFactory::getDBO();

		$address = '';
		if(!empty($item->region_id)){
			$select = "SELECT CONCAT_WS(', '";
			$from = "FROM #__djcf_regions r1 ";
			for($i=1; $i<5; $i++){
				$j=$i+1;
				$select .= ", r".$i.".name";
				$from .= "LEFT JOIN #__djcf_regions r".$j." ON r".$i.".parent_id=r".$j.".id AND (r".$j.".city=1 OR r".$j.".country=1) ";
			}
			$select .= ") ";
			$where = "WHERE r1.id=".$item->region_id." AND (r1.city=1 OR r1.country=1)";
			$query = $select.$from.$where;

			$db->setQuery($query);
			$location = $db->loadResult();

			$address .= $location ? $location : '';
		}
		if(!empty($item->address)){
			$address .= $address ? ', '.$item->address : $item->address;
		}
		return $address;
	}

	function onAjaxLeafletGetLocation()
	{
		if(!self::$_enabled){
			return;
		}
		$app = JFactory::getApplication();
		$address = $app->input->getVar('address', '');
		$postcode = $app->input->getVar('postcode', '');
		$lat_lng = $this->onLeafletGetLocation($address, $postcode);
		echo json_encode($lat_lng);
		$app->close();
	}

	function onAjaxLeafletGetLocationReverse()
	{
		if(!self::$_enabled){
			return;
		}
		$app = JFactory::getApplication();
		$lat = $app->input->getVar('lat', '');
		$lng = $app->input->getVar('lng', '');
		$res = $this->leafletGetLocationReverse($lat, $lng);
		echo json_encode($res);
		$app->close();
	}

	function onAjaxLeafletDriveDirections()
	{
		if(!self::$_enabled){
			return;
		}
		$app = JFactory::getApplication();
		$lat = $app->input->getVar('lat', '');
		$lng = $app->input->getVar('lng', '');
		$s_addr = $app->input->getVar('saddr', '');

		if($s_addr){
			$s_loc_coord = $this->onLeafletGetLocation($s_addr);
		}
		
		if(!empty($s_loc_coord) && $lat && $lng){
			$app->redirect('https://www.openstreetmap.org/directions?route='.$s_loc_coord['lat'].','.$s_loc_coord['lng'].';'.$lat.','.$lng);
		}elseif($lat && $lng){
			$app->redirect('https://www.openstreetmap.org/directions?route=0.000,0.000;'.$lat.','.$lng);
		}else{
			$app->redirect('https://www.openstreetmap.org/directions');
		}
	}

	function onAjaxLeafletGetPoi()
	{
		if(!self::$_enabled){
			return;
		}
		$app = JFactory::getApplication();
		$val = $app->input->getVar('val', '');
		$url = "https://photon.komoot.io/api/?q=".urlencode($val)."&limit=5";

		if(isset($_COOKIE["djcf_latlon"])){
			$lat_lon = explode('_', $_COOKIE["djcf_latlon"]);
			if($lat_lon){
				$url .= "&lat=".$lat_lon[0]."&lon=".$lat_lon[1];
			}
		}

		$lang = JFactory::getLanguage();
		$tag_arr = explode('-',$lang->getTag());
		$supported_lang = array('de','en','it','fr');
		if(!empty($tag_arr[0]) && in_array($tag_arr[0], $supported_lang)){
			$url .= "&lang=".$tag_arr[0];
		}

		$c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
        
		$resp_json = curl_exec($c);
		curl_close($c);
		if($app->input->getVar('dev', '')){
			echo '<pre>';print_r(json_decode($resp_json));die();
		}
		echo $resp_json;
		$app->close();
	}
}

Anon7 - 2022
AnonSec Team