_plgYandexMapsNr = (int)$this->_plgYandexMapsNr + 1; } function plgContentYandexMaps( &$subject, $params ) { parent::__construct( $subject, $params ); } function onPrepareContent( &$article, &$params, $limitstart ) { // Start Plugin $regex_one = '/({yandexmaps\s*)(.*?)(})/si'; $regex_all = '/{yandexmaps\s*.*?}/si'; $matches = array(); $count_matches = preg_match_all($regex_all,$article->text,$matches,PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER); // Start if count_matches if ($count_matches != 0) { $document = &JFactory::getDocument(); $db = &JFactory::getDBO(); $menu = &JSite::getMenu(); $plugin = &JPluginHelper::getPlugin('content', 'yandexmaps'); $paramsP = new JParameter( $plugin->params ); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_yandexmaps'.DS.'helpers'.DS.'yandexmaps.php' ); $component = 'com_yandexmaps'; $table =& JTable::getInstance('component'); $table->loadByOption( $component ); $paramsC = new JParameter( $table->params ); $tmpl = array(); if (!JComponentHelper::isEnabled('com_yandexmaps', true)) { JText::_('Yandex Maps Plugin requires Yandex Maps Component'); return true; } $document->addStyleSheet(JURI::base(true).'/components/com_yandexmaps/assets/yandexmaps.css'); for($i = 0; $i < $count_matches; $i++) { $this->_setYandexMapsPluginNumber(); $mC = 'PlgPM'.(int)$this->_plgYandexMapsNr; $view = ''; $id = ''; $text = ''; // Get plugin parameters $yandexMaps = $matches[0][$i][0]; preg_match($regex_one,$yandexMaps,$yandexMaps_parts); $parts = explode("|", $yandexMaps_parts[2]); $values_replace = array ("/^'/", "/'$/", "/^'/", "/'$/", "/
/"); foreach($parts as $key => $value) { $values = explode("=", $value, 2); foreach ($values_replace as $key2 => $values2) { $values = preg_replace($values2, '', $values); } // Get plugin parameters from article if($values[0]=='view') {$view = $values[1];} else if($values[0]=='id') {$id = $values[1];} else if($values[0]=='text') {$text = $values[1];} } $output = ''; switch($view) { // - - - - - - - - - - - - - - - - // Map // - - - - - - - - - - - - - - - - case 'map': $query = 'SELECT a.*' .' FROM #__yandexmaps_map AS a' .' WHERE a.id = '.(int) $id; $db->setQuery($query); $map = $db->loadObject(); $query = 'SELECT a.*' .' FROM #__yandexmaps_marker AS a' .' LEFT JOIN #__yandexmaps_map AS c ON c.id = a.catid ' .' WHERE c.id = '.(int) $id .' AND a.published = 1'; $db->setQuery($query); $marker = $db->loadObjectList(); if (empty($map)) { JError::raiseError('Yandex Maps Plugin Error', JText::_('Map does not exist or is unpublished') . ' (ID = '.$id.')'); } // Parameters $tmpl['apikey'] = $paramsC->get( 'google_maps_api_key', '' ); $tmpl['displayyandexinfo'] = $paramsC->get( 'display_yandex_info', 1 ); $tmpl['displaymapdescription'] = $paramsP->get( 'display_map_description', 0 ); // - - - - - - - - - - - - - - - // RENDER if ($tmpl['apikey'] == '') { $output .= '

' . JText::_('Google Maps API Key Error Front') . '

'; } else if ((!isset($map->longitude)) || (!isset($map->latitude)) || (isset($map->longitude) && $map->longitude == '') || (isset($map->latitude) && $map->latitude == '')) { $output .= '

' . JText::_('Google Maps Error Front') . '

'; } else { if (isset($map->description) && $map->description != '' && $tmpl['displaymapdescription'] == 1) { $output .= '
'.$map->description.'
'; } // Basic settings $fullWidth = 0; if (!isset($map->width)) { $map->width = 400; } if (isset($map->width) && (int)$map->width < 1) { $fullWidth = 1; } if (!isset($map->height) || (isset($map->height) && (int)$map->height < 1)) { $map->height = 400; } if (!isset($map->zoom) || (isset($map->zoom) && (int)$map->zoom < 1)) { $map->height = 2; } $mapLang = ''; if (!isset($map->lang) || (isset($map->lang) && $map->lang =='')) { $mapLang = ''; } else { $mapLang = $map->lang; } //$document = & JFactory::getDocument(); $scriptLink = 'http://api-maps.yandex.ru/'.$mapLang.'/index.xml?key='. $tmpl['apikey']; //загружаем api $document->addScript($scriptLink); //$output.= ''; // Map Box if ($fullWidth == 1) {//если 0 то растягиваем на 100% $output .= '
'; }else{//если больше 0 то по заданным размерам $output .= '
'; } if (isset($map->displayroute) && $map->displayroute == 1) { if (isset($marker) && !empty($marker)) { $countMarker = count($marker); if ((int)$countMarker > 1) { $output .= '
'; $output .= JText::_('From Address').': '; $output .= ' ' . JText::_('To').': '; $output .= '
'; $output .= '
'; $output .= '

'; $output .= '
'; } else if ((int)$countMarker == 1) { $output .= '

'; $output .= '
'; //$output .= '
'; } } } $output.=''."\n"; $output.=''; } $output .= '
Разработка сайтов
'; // END RENDER // - - - - - - - - - - - - - - - break; // - - - - - - - - - - - - - - - - // Выводим ссылкой в модальном или попап окне // - - - - - - - - - - - - - - - - case 'link': if ((int)$id > 0) { $query = 'SELECT a.*,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug' .' FROM #__yandexmaps_map AS a' .' WHERE a.id = '.(int) $id; $db->setQuery($query); $map = $db->loadObject(); $query = 'SELECT a.id' .' FROM #__yandexmaps_marker AS a' .' LEFT JOIN #__yandexmaps_map AS c ON c.id = a.catid ' .' WHERE c.id = '.(int) $id .' AND a.published = 1'; $db->setQuery($query); $marker = $db->loadObjectList(); if (empty($map)) { JError::raiseError('Yandex Maps Plugin Error', JText::_('Map does not exist or is unpublished') . ' (ID = '.$id.')'); } // Is there a Itemid for category $items = $menu->getItems('link', 'index.php?option=com_yandexmaps&view=map&id='. $map->id); if(isset($items[0])) { $itemid = $items[0]->id; $linkMap = JRoute::_('index.php?option=com_yandexmaps&view=map&id='. $map->id.'&tmpl=component&Itemid='.$itemid ); } else { $itemid = 0; $linkMap = JRoute::_('index.php?option=com_yandexmaps&view=map&id='. $map->slug .'&tmpl=component' ); } // --------------------------------------------------------------------------------- if ($text =='') { $text = JText::_('Link to Map'); } // Parameters $tmpl['detailwindow'] = $paramsP->get( 'detail_window', 0 ); $tmpl['mbbordercolor'] = $paramsP->get( 'modal_box_border_color', '#6b6b6b' ); $tmpl['mbborderwidth'] = $paramsP->get( 'modal_box_border_width', 2 ); $tmpl['mboverlaycolor'] = $paramsP->get( 'modal_box_overlay_color', '#000000' ); $tmpl['mboverlayopacity'] = $paramsP->get( 'modal_box_overlay_opacity', 0.3 ); if ($map->width > 0) { $tmpl['windowwidth'] = (int)$map->width + 20; } else { $tmpl['windowwidth'] = 640; } $tmpl['windowheight'] = (int)$map->height + 20; //Route if (isset($map->displayroute) && $map->displayroute == 1) { if (isset($marker) && !empty($marker)) { $tmpl['windowheight'] = (int)$tmpl['windowheight'] + 40; } } if ($tmpl['detailwindow'] == 1) { $button = new JObject(); $button->set('name', 'yandexmaps'); $button->set('methodname', 'js-button'); $button->set('options', "window.open(this.href,'win2','width=".$tmpl['windowwidth'].",height=".$tmpl['windowheight'].",menubar=no,resizable=yes'); return false;"); $output .= ''.$text.''; } else if ($tmpl['detailwindow'] == 0) { // Button JHTML::_('behavior.modal', 'a.modal-button'); $cssSbox = " #sbox-window {background-color:".$tmpl['mbbordercolor'].";padding:".$tmpl['mbborderwidth']."px} \n" ." #sbox-overlay {background-color:".$tmpl['mboverlaycolor'].";} \n"; $document->addCustomTag( "\n"); $button = new JObject(); $button->set('name', 'yandexmaps'); $button->set('modal', true); $button->set('methodname', 'modal-button'); $button->set('options', "{handler: 'iframe', size: {x: ".$tmpl['windowwidth'].", y: ".$tmpl['windowheight']."}, overlayOpacity: ".$tmpl['mboverlayopacity'].", classWindow: 'yandexmaps-plugin-window', classOverlay: 'yandexmaps-plugin-overlay'}"); $output .= ''.$text.''; } } break; } $article->text = preg_replace($regex_all, $output, $article->text, 1); } }// end if count_matches return true; } } ?>