Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
Imported archived versions and current version 2.0.
  • Loading branch information
petkivim committed Mar 28, 2015
1 parent 8de7292 commit ee80f93
Show file tree
Hide file tree
Showing 32 changed files with 2,032 additions and 0 deletions.
Binary file added archive/j5-plg_content_embed_google_map-1.1.2.zip
Binary file not shown.
Binary file added archive/j5-plg_content_embed_google_map-1.2.0.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.0.0.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.1.0.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.1.1.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.2.0.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.2.1.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.2.2.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.3.0.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.4.0.zip
Binary file not shown.
Binary file added archive/plg_content_embed_google_map-1.5.0.zip
Binary file not shown.
29 changes: 29 additions & 0 deletions src/builderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @version $Id: Embed Google Map v2.0.0 2014-06-05 17:54 $
* @package Joomla 1.6
* @copyright Copyright (C) 2014 Petteri Kivimäki. All rights reserved.
* @author Petteri Kivimäki
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

require_once __DIR__ . '/classicHtmlBuilder.php';
require_once __DIR__ . '/newHtmlBuilder.php';
require_once __DIR__ . '/embedAPIHtmlBuilder.php';

class BuilderFactory {
public static function createBuilder($version) {
if(strcmp($version,'classic') == 0) {
return new ClassicHtmlBuilder;
} else if(strcmp($version,'new') == 0) {
return new NewHtmlBuilder;
} else if(strcmp($version,'embed') == 0) {
return new EmbedAPIHtmlBuilder;
}
return new NewHtmlBuilder;
}
}
?>
65 changes: 65 additions & 0 deletions src/classicHtmlBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @version $Id: Embed Google Map v2.0.0 2014-05-30 17:30 $
* @package Joomla 1.6
* @copyright Copyright (C) 2014 Petteri Kivimäki. All rights reserved.
* @author Petteri Kivimäki
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

require_once __DIR__ . '/htmlBuilder.php';

class ClassicHtmlBuilder extends HtmlBuilder {

private $baseUrl = "http://maps.google.com/";

public function buildHtml(&$params) {
$url = parent::getUrl($params, $this->baseUrl);

$html = parent::getIFrameBegin($params);

if($params->isLink() == 1) {
$url .= "?q=".$params->getAddress();
if(strlen($params->getInfoLabel()) > 0) {
$url .= "(".$params->getInfoLabel().")";
}
}

if($params->isGoogleMapsEngine() == 1) {
$url .= "&z=".$params->getZoomLevel();
$url .= "&t=".$params->getMapType();

if(strcmp($params->getLanguage(),'-') != 0) {
$url .= "&hl=".$params->getLanguage();
}

$info = ($params->getShowInfo() == 0) ? "" : "&iwloc=near";

// Unicode properties are available only if PCRE is compiled with "--enable-unicode-properties"
// '\pL' = any Unicode letter
if (preg_match('/^[^\pL]+$/u', $params->getAddress())) {
$info = ($params->getShowInfo() == 0) ? "&iwloc=near" : "";
}

$url .= $info;
}
$html .= "src='$url&output=svembed'></iframe>\n";

if($params->getAddLink() == 0) {
$output = ($params->getLinkFull() == 0) ? "&output=svembed" : "&output=classic";
if($params->isGoogleMapsEngine() == 0) {
$url = str_replace('/embed','/viewer', $url);
} else {
$url .= $output;
}
$html .= parent::getLinkHtml($url, $params->getLinkLabel());
}
return $html;
}
}

?>

62 changes: 62 additions & 0 deletions src/embedAPIHtmlBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @version $Id: Embed Google Map v2.0.0 2014-06-05 17:54 $
* @package Joomla 1.6
* @copyright Copyright (C) 2014 Petteri Kivimäki. All rights reserved.
* @author Petteri Kivimäki
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

require_once __DIR__ . '/htmlBuilder.php';

class EmbedAPIHtmlBuilder extends HtmlBuilder {

private $baseUrl = "https://www.google.com/maps/embed/v1/search";

public function buildHtml(&$params) {
$url = parent::getUrl($params, $this->baseUrl);

$html = parent::getIFrameBegin($params);

if($params->isLink() == 1) {
$url .= "?key=".$params->getEmbedAPIKey();
$url .= "&q=".urlencode($params->getAddress());
$url .= "&zoom=".$params->getZoomLevel();
$url .= "&maptype=".$this->getMapType($params->getMapType());
if(strcmp($params->getLanguage(),'-') != 0) {
$url .= "&language=".$params->getLanguage();
}
}
if($params->isLink() == 0 && $params->isGoogleMapsEngine() == 1) {
$html .= "src='$url&output=embed'></iframe>\n";
} else {
$html .= "src='$url'></iframe>\n";
}

if($params->getAddLink() == 0) {
if($params->isGoogleMapsEngine() == 0) {
$url = str_replace('/embed','/viewer', $url);
$html .= parent::getLinkHtml($url, $params->getLinkLabel());
} else if($params->isLink() == 0) {
$html .= parent::getLinkHtml($url, $params->getLinkLabel());
}
}
return $html;
}

private function getMapType($mapType) {
if(strcmp(strtolower($mapType),'m') == 0) {
return 'roadmap';
} else if(strcmp(strtolower($mapType),'k') == 0) {
return 'satellite';
} else {
return 'roadmap';
}
}
}

?>

103 changes: 103 additions & 0 deletions src/embed_google_map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* @version $Id: Embed Google Map v2.0.0 2014-06-05 17:50 $
* @package Joomla 1.6
* @copyright Copyright (C) 2014 Petteri Kivimäki. All rights reserved.
* @author Petteri Kivimäki
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.plugin.plugin');

require_once __DIR__ . '/parameters.php';
require_once __DIR__ . '/builderFactory.php';
require_once __DIR__ . '/parser.php';

class plgContentembed_google_map extends JPlugin
{
function plgContentembed_google_map( &$subject, $params )
{
parent::__construct( $subject, $params );
}

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 Parameters;
// 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 Parser;
// 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 = BuilderFactory::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;
}
}

?>
Loading

0 comments on commit ee80f93

Please sign in to comment.