Ejemplo n.º 1
0
 function onContentPrepare($context, &$row, &$params, $limitstart)
 {
     $output = $row->text;
     $regex = "#{google_map}(.*?){/google_map}#s";
     $found = preg_match_all($regex, $output, $matches);
     $count = 0;
     if ($found) {
         foreach ($matches[0] as $value) {
             // Plugin params
             $plgParams = new EmbedGoogleMapParameters();
             // Load plugin params
             $plgParams->setVersion($this->params->def('version', 'new'));
             $plgParams->setEmbedAPIKey($this->params->def('embed_api_key', ''));
             $plgParams->setMapType($this->params->def('map_type', 'm'));
             $plgParams->setZoomLevel($this->params->def('zoom', 14));
             $plgParams->setLanguage($this->params->def('language', '-'));
             $plgParams->setAddLink($this->params->def('add_link', 1));
             $plgParams->setLinkLabel($this->params->def('link_label', 'View Larger Map'));
             $plgParams->setLinkFull($this->params->def('link_full', 1));
             $plgParams->setShowInfo($this->params->def('show_info', 0));
             $plgParams->setHeight($this->params->def('height', 300));
             $plgParams->setWidth($this->params->def('width', 400));
             $plgParams->setBorder($this->params->def('border', 0));
             $plgParams->setBorderStyle($this->params->def('border_style', 'solid'));
             $plgParams->setBorderColor($this->params->def('border_color', '#000000'));
             $plgParams->setHttps($this->params->def('https', 1));
             $plgParams->setInfoLabel("");
             $map = $value;
             $map = str_replace('{google_map}', '', $map);
             $map = str_replace('{/google_map}', '', $map);
             $find = '|';
             if (strstr($map, $find)) {
                 // New Parser object
                 $parser = new EmbedGoogleMapParser();
                 // Parse parameters
                 $parser->parse($map, $plgParams);
             } else {
                 $plgParams->setAddress($map);
             }
             // If system language is used, get the system language code
             if (strcmp($plgParams->getLanguage(), 'system') == 0) {
                 $lng = JFactory::getLanguage();
                 $langtag = $lng->getTag();
                 $langprfx = explode('-', $langtag);
                 $plgParams->setLanguage($langprfx[0]);
             }
             // If translated string is used as link label, get the string
             if (preg_match('/{(.*?)}/', $plgParams->getLinkLabel(), $mtcs)) {
                 $plgParams->setLinkLabel(JText::_($mtcs[1]));
             }
             // Create new HTML builder
             $builder = EmbedGoogleMapBuilderFactory::createBuilder($plgParams->getVersion());
             // Generate HTML code
             $replacement[$count] = $builder->buildHtml($plgParams);
             // Increase counter
             $count++;
         }
         for ($i = 0; $i < count($replacement); $i++) {
             $row->text = preg_replace($regex, $replacement[$i], $row->text, 1);
         }
     }
     return true;
 }
Ejemplo n.º 2
0
function the_google_map_embedder($content)
{
    // Regex for finding all the google_map tags
    $regex = "#{google_map}(.*?){/google_map}#s";
    // Read all the tags in an array
    $found = preg_match_all($regex, $content, $matches);
    // Get default options
    $options = get_option('embed_google_map_options');
    // Initialize options
    init_embed_google_map_options($options);
    // Check if any matches were found
    if ($found) {
        // Loop through all the matches
        foreach ($matches[0] as $value) {
            // Plugin params
            $plgParams = new EmbedGoogleMapParameters();
            // Set default parameters
            $plgParams->setVersion($options['version']);
            $plgParams->setEmbedAPIKey($options['embed_api_key']);
            $plgParams->setMapType($options['map_type']);
            $plgParams->setZoomLevel($options['zoom_level']);
            $plgParams->setLanguage($options['language']);
            $plgParams->setAddLink($options['add_link']);
            $plgParams->setLinkLabel($options['link_label']);
            $plgParams->setLinkFull($options['link_full']);
            $plgParams->setShowInfo($options['show_info']);
            $plgParams->setHeight($options['height']);
            $plgParams->setWidth($options['width']);
            $plgParams->setBorder($options['border']);
            $plgParams->setBorderStyle($options['border_style']);
            $plgParams->setBorderColor($options['border_color']);
            $plgParams->setHttps($options['https']);
            $plgParams->setInfoLabel($options['info_label']);
            $map = $value;
            $map = str_replace('{google_map}', '', $map);
            $map = str_replace('{/google_map}', '', $map);
            $find = '|';
            // Check parameters
            if (strstr($map, $find)) {
                // New Parser object
                $parser = new EmbedGoogleMapParser();
                // Parse parameters
                $parser->parse($map, $plgParams);
            } else {
                $plgParams->setAddress($map);
            }
            // Create new HTML builder
            $builder = EmbedGoogleMapBuilderFactory::createBuilder($plgParams->getVersion());
            // Generate HTML code
            $replacement = $builder->buildHtml($plgParams);
            // Replace the tag with the html code that embeds the map
            $content = str_replace($value, $replacement, $content);
        }
    }
    return $content;
}