registerEvent( 'onBeforeDisplayContent', 'plgContentYMap' ); function plgContentYMap ( &$row, &$params, $page=0 ) { $plugin =& JPluginHelper::getPlugin('content', 'plugin_yandexmap'); $pluginParams = new JParameter( $plugin->params ); preg_match_all('/\{ymap\s*([^}]*)}/',$row->text,$matches,PREG_OFFSET_CAPTURE); $html = array(); foreach ($matches[0] as $tag_num => $tag) { $html[$tag_num]['content'] = YMapProcessTag($matches[1][$tag_num][0], $pluginParams); $html[$tag_num]['offset'] = $tag[1]; $html[$tag_num]['length'] = strlen($tag[0]); } /* echo "
";
		print_r($html);
		echo "
"; */ // $row->text = preg_replace('/\{ymap\}/','FUCK',$row->text); $str = & $row->text; foreach (array_reverse($html) as $part) { $str = substr_replace($str,$part['content'],$part['offset'],$part['length']); } } function YMapProcessTag(& $tag_params, & $plugin_params) { static $y_map_id = 0; preg_match_all('/(\S+)\s*=\s*(\S+)/',$tag_params, $matches); $my_params = array(); foreach ($matches[1] as $num=>$key) { $my_params[$key] = $matches[2][$num]; } $doc = & JFactory::getDocument(); foreach ($plugin_params->toArray() as $p_name => $p_value) { if (!isset($my_params[$p_name])) $my_params[$p_name] = $p_value; } if ($y_map_id === 0) { $doc->addScript('http://api-maps.yandex.ru/1.1/index.xml?key='.$my_params['apiKey']); } $my_params['mapType'] = strtolower($my_params['mapType']); switch ($my_params['mapType']) { case 'map': $map_type = 'map.setType(YMaps.MapType.MAP);'; break; case 'satellite': $map_type = 'map.setType(YMaps.MapType.SATELLITE);'; break; case 'hybrid': $map_type = 'map.setType(YMaps.MapType.HYBRID);'; break; default: $map_type = ''; } $my_params['zoomType'] = strtolower($my_params['zoomType']); switch ($my_params['zoomType']) { case 'large': $zoom_type = 'var zoomControl = new YMaps.Zoom();'; break; case 'small': $zoom_type = 'var zoomControl = new YMaps.SmallZoom();'; break; default: $zoom_type = ''; break; } if (!empty($zoom_type)) { $zoom_type .= "\nmap.addControl(zoomControl);"; } if (intval($my_params['showMapType'])) { $typeControl = 'var typeControl = new YMaps.TypeControl();'; $typeControl .= 'map.addControl(typeControl);'; } else { $typeControl = ''; } if (intval($my_params['showToolBar'])) { $toolbarControl = 'var toolbarControl = new YMaps.ToolBar();'; $toolbarControl .= 'map.addControl(toolbarControl);'; } else { $toolbarControl = ''; } if (intval($my_params['showSearchControl'])) { $searchControl = 'map.addControl(new YMaps.SearchControl(), new YMaps.ControlPosition(YMaps.ControlPosition.BOTTOM_LEFT, new YMaps.Size(5, 20)));'; } else { $searchControl = ''; } if (intval($my_params['YMapsML_enabled'])){ $YMapsMLfiles = 'var mlm = new YMaps.YMapsML(\''.$my_params['YMapsML_files'].'\'); map.addOverlay(mlm);'; } else { $YMapsMLfiles = ''; } if (intval($my_params['showMiniMap'])) { $mmControl = 'var minimapControl = new YMaps.MiniMap();'; $mmControl .= 'map.addControl(minimapControl);'; } else { $mmControl = ''; } if (intval($my_params['scrollZoom'])) { $scrollZoom = 'map.enableScrollZoom();'; } else { $scrollZoom = 'map.disableScrollZoom();'; } if (intval($my_params['dblClickZoom'])) { $dblClickZoom = 'map.enableDblClickZoom();'; } else { $dblClickZoom = 'map.disableDblClickZoom();'; } $placemarks = ''; for ($i = 0; $i < 2; $i++) { if (!isset($my_params['placemark_enabled_'.$i])) break; $placemark_enabled = $my_params['placemark_enabled_'.$i]; if (!$placemark_enabled) continue; $placemark_lat = $my_params['placemark_lat_'.$i]; $placemark_lon = $my_params['placemark_lon_'.$i]; $placemark_content = $my_params['placemark_content_'.$i]; $placemark_open = intval($my_params['placemark_open_'.$i]); $placemark_ballon = $my_params['placemark_ballon_'.$i]; $placemarks .= 'var placemark_'.$i.' = new YMaps.Placemark(new YMaps.GeoPoint('.$placemark_lon.', '.$placemark_lat.'));'; if (!empty($placemark_content)) $placemarks .= "\n".'placemark_'.$i.'.setIconContent("'.addslashes($placemark_content).'");'; $placemarks .= "\n".'map.addOverlay(placemark_'.$i.');'; $placemarks .= "\n".'placemark_'.$i.'.setBalloonContent("'.addslashes($placemark_ballon).'");'; if ($placemark_open) { $placemarks .= "\n".'placemark_'.$i.'.openBalloon();'; } } $j_content = ' window.addEvent(\'domready\', function() { var map = new YMaps.Map(document.getElementById("YMaps_'.$y_map_id.'")); center = new YMaps.GeoPoint('.$my_params['lon'].', '.$my_params['lat'].'); map.setCenter(center, '.$my_params['zoom'].'); '.$map_type.' '.$zoom_type.' '.$typeControl.' '.$toolbarControl.' '.$searchControl.' '.$YMapsMLfiles.' '.$mmControl.' '.$scrollZoom.' '.$dblClickZoom.' '.$placemarks.' } ) '; $doc->addScriptDeclaration($j_content); $content = ''; $content .= '
'; $y_map_id += 1; return $content; } ?>