Subversion Repositories googlemaps

Compare Revisions

Ignore whitespace Rev 3 → Rev 4

/trunk/extension/gmaplocation/CHANGELOG.txt
1,27 → 1,31
CHANGELOG
 
Version 0.5
-------------------------------------------------------------------------------
* only compatible with eZ Publish 4
 
Version 0.4
-------------------------------------------------------------------------------
* Resolved a few warnings and error messages.
 
* Much simpler install - modified the javascript so that no template changes
are required in the admin design.
 
* The editing controls will now work properly if there are multiple location
attributes on a single object.
* In the editing view, the map will now re-center on the clicked point. This
makes it easier to use the click-point and zoome controls to hone in on a
 
* In the editing view, the map will now re-center on the clicked point. This
makes it easier to use the click-point and zoome controls to hone in on a
specific point.
* The edit map now defaults to a zoom-level-0 view of the globe instead of
 
* The edit map now defaults to a zoom-level-0 view of the globe instead of
a gray square.
* The edit map is larger, so that the map type and directional controls don't
 
* The edit map is larger, so that the map type and directional controls don't
overlap.
 
* A new template has been included, gmap.tpl. This is a multi-purpose template
that can be included and configured to handle several common use-cases for
that can be included and configured to handle several common use-cases for
the gmaps datatype. See the doc on the template for specifics.
 
Version 0.3 - Initial Release
/trunk/extension/gmaplocation/design/standard/templates/class/datatype/edit/ezgmaplocation.tpl ___________________________________________________________________ Added: svn:eol-style + native
/trunk/extension/gmaplocation/design/standard/templates/class/datatype/view/ezgmaplocation.tpl ___________________________________________________________________ Added: svn:eol-style + native
/trunk/extension/gmaplocation/README.txt
1,40 → 1,40
gmapsLocation Datatype Extension
Version 0.4
Version 0.5
Developed by Blend Interactive
http://blendinteractive.com
----------------------
The GmapsLocation datatype extension provides a handy way to store
The GmapsLocation datatype extension provides a handy way to store
latitude/longitude points on an object by using Google Maps to identify
and mark positions using their address.
 
Installation
---------------
 
1.) Obtain a Google Maps Key for all domains you'll be using by registering
1.) Obtain a Google Maps Key for all domains you'll be using by registering
your domains with Google at http://www.google.com/apis/maps/
 
2.) Upload the gmapslocation folder to the extensions folder in your
2.) Upload the gmapslocation folder to the extensions folder in your
eZ Publish installation.
 
3.) Activate the extension from the 'Extensions' portion of the
3.) Activate the extension from the 'Extensions' portion of the
'Setup' tab in the eZ publish admin interface.
 
4.) Add your GmapsKey to the site.ini under [SiteSettings] like so:
4.) Add your GmapsKey to the site.ini under [SiteSettings] like so:
GMapsKey=<Long string of characters from Google>
 
Use
---------------
To use the extension, add the 'GMaps Location' datatype to your classes using
To use the extension, add the 'GMaps Location' datatype to your classes using
the class editor.
 
The most common use of the extension is to also Google Maps data on a public-
facing web site. The included gmap.tpl template will provide a basic gmap
with mapped points. See the instructions in design/standard/templates/gmap.tpl
for the full documentation of parameters.
facing web site. The included gmap.tpl template will provide a basic gmap
with mapped points. See the instructions in design/standard/templates/gmap.tpl
for the full documentation of parameters.
 
A few examples:
A few examples:
 
List all office objects under node 57 and display their 'location'
List all office objects under node 57 and display their 'location'
attributes on a 600x400 map. Also list the offices on the page:
 
{def $offices = fetch('content','list', hash(
42,14 → 42,14
'class_filter_type', 'include',
'class_filter_array', array('office')))}
 
{include uri='design:gmaps.tpl'
{include uri='design:gmaps.tpl'
locations=$offices
size=array(600,400)
show_popups_on_page=true()
}
 
 
Recursively get all image objects under node 243 and display their
Recursively get all image objects under node 243 and display their
'gps_point' attributes on a 400x400 map. Center the map on Yellowstone
National Park at a reasonable zoom level, and use the object's 'galleryline'
view for the map popups:
59,7 → 59,7
'class_filter_type', 'include',
'class_filter_array', array('image')))}
 
{include uri='design:gmaps.tpl'
{include uri='design:gmaps.tpl'
locations=$pictures
location_attribute='gps_point'
center=array(44.62566, -110.5389)
68,20 → 68,20
}
 
 
Pull the 'location' attribute from the object at node 415, and display a
Pull the 'location' attribute from the object at node 415, and display a
small map centered on that point. Don't display any markers.
{def $center = fetch('content','node', hash(
'node_id', 415))}
 
{include uri='design:gmaps.tpl'
 
{include uri='design:gmaps.tpl'
center=$center.object.data_map.location.content
zoom=8
size=array(150,150)
}
 
 
 
See the samples folder for samples of customized maps.
 
 
/trunk/extension/gmaplocation/datatypes/ezgmaplocation/ezgmaplocation.php
3,19 → 3,19
// Definition of eZGmapLocation class
//
// SOFTWARE NAME: Blend Gmap Location Class
// SOFTWARE RELEASE: 0.3
// COPYRIGHT NOTICE: Copyright (C) 2006 Blend Interactive
// SOFTWARE RELEASE: 0.5
// COPYRIGHT NOTICE: Copyright (C) 2006-2009 Blend Interactive
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2.0 of the GNU General
// Public License as published by the Free Software Foundation.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of version 2.0 of the GNU General
// Public License along with this program; if not, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29,7 → 29,7
/*!
\class eZGmapLocation ezgmaplocation.php
\ingroup eZDatatype
\brief The class eZGmapLocation provides a datatype for storing
\brief The class eZGmapLocation provides a datatype for storing
\latitude & longitude values.
 
*/
39,7 → 39,7
/*!
Constructor
*/
function eZGmapLocation( $latitude, $longitude )
function __construct( $latitude, $longitude )
{
$this->Latitude = $latitude;
$this->Longitude = $longitude;
59,7 → 59,7
return in_array( $name, $this->attributes() );
}
 
function &attribute( $name )
function attribute( $name )
{
switch ( $name )
{
73,7 → 73,7
}break;
default:
{
eZDebug::writeError( "Attribute '$name' does not exist", 'eZGmapLocation::attribute' );
eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
$retValue = null;
return $retValue;
}break;
83,23 → 83,21
 
function decodeXML( $xmlString )
{
include_once( 'lib/ezxml/classes/ezxml.php' );
$dom = new DOMDocument( '1.0', 'utf-8' );
 
$xml = new eZXML();
 
 
$dom =& $xml->domTree( $xmlString );
 
if ( $xmlString != "" )
{
$locationElement =& $dom->root( );
$success = $dom->loadXML( $xmlString );
if ( !$success )
{
eZDebug::writeError( 'Failed loading XML', __METHOD__ );
return false;
}
 
$latitude = $locationElement->attributeValue( 'latitude' );
$longitude = $locationElement->attributeValue( 'longitude' );
$locationElement = $dom->documentElement;
 
$this->Latitude = $latitude;
$this->Longitude = $longitude;
 
$this->Latitude = $locationElement->getAttribute( 'latitude' );
$this->Longitude = $locationElement->getAttribute( 'longitude' );
}
else
{
109,20 → 107,16
}
 
 
function &xmlString( )
function xmlString()
{
include_once( 'lib/ezxml/classes/ezdomdocument.php' );
$doc = new DOMDocument( '1.0', 'utf-8' );
 
$doc = new eZDOMDocument( "Location" );
$root = $doc->createElement( 'ezgmaplocation' );
$root->setAttribute( 'latitude', $this->Latitude );
$root->setAttribute( 'longitude', $this->Longitude );
$doc->appendChild( $root );
 
$root = $doc->createElementNode( "ezgmaplocation" );
$root->appendAttribute( $doc->createAttributeNode( "latitude", $this->Latitude ) );
$root->appendAttribute( $doc->createAttributeNode( "longitude", $this->Longitude ) );
$doc->setRoot( $root );
 
$xml = $doc->toString();
 
return $xml;
return $doc->saveXML();
}
 
function setLatitude( $value )
136,8 → 130,8
}
 
 
var $Latitude;
var $Longitude;
private $Latitude;
private $Longitude;
}
 
?>
/trunk/extension/gmaplocation/datatypes/ezgmaplocation/ezgmaplocationtype.php
3,19 → 3,19
// Definition of eZGmapLocationType class
//
// SOFTWARE NAME: Blend Gmap Location Class
// SOFTWARE RELEASE: 0.3
// COPYRIGHT NOTICE: Copyright (C) 2006 Blend Interactive
// SOFTWARE RELEASE: 0.5
// COPYRIGHT NOTICE: Copyright (C) 2006-2009 Blend Interactive
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2.0 of the GNU General
// Public License as published by the Free Software Foundation.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of version 2.0 of the GNU General
// Public License along with this program; if not, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
33,26 → 33,21
\brief The class eZGmapLocationType does
 
*/
include_once( "kernel/classes/ezdatatype.php" );
include_once( "extension/gmaplocation/datatypes/ezgmaplocation/ezgmaplocation.php" );
 
define( "EZ_GMAPLOCATION_DEFAULT_NAME_VARIABLE", "_ezgmaplocation_default_name_" );
 
 
define( "EZ_DATATYPESTRING_GMAPLOCATION", "ezgmaplocation" );
 
class eZGmapLocationType extends eZDataType
{
const DATA_TYPE_STRING = "ezgmaplocation";
 
/*!
Constructor
*/
function eZGmapLocationType()
function __construct()
{
$this->eZDataType( EZ_DATATYPESTRING_GMAPLOCATION, ezi18n( 'extension/gmaplocation/datatypes', "GMaps Location", 'Datatype name' ),
$this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'extension/gmaplocation/datatypes', "GMaps Location", 'Datatype name' ),
array( 'serialize_supported' => true ) );
}
 
function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) and
$http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) )
60,31 → 55,34
 
$latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
$longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
$classAttribute =& $contentObjectAttribute->contentClassAttribute();
$classAttribute = $contentObjectAttribute->contentClassAttribute();
if ( $latitude == '' or
$longitude == '' )
{
if ( ( !$classAttribute->attribute( 'is_information_collector' ) and
$contentObjectAttribute->validateIsRequired() ) )
if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
{
//TODO: In this case, we should directly call for geocoding.
$contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
'Missing Latitude/Longitude input.' ) );
return EZ_INPUT_VALIDATOR_STATE_INVALID;
'Missing Latitude/Longitude input.' ) );
return eZInputValidator::STATE_INVALID;
}
else
return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
{
return eZInputValidator::STATE_ACCEPTED;
}
}
}
else if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
{
return eZInputValidator::STATE_INVALID;
 
}
else
{
return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
return eZInputValidator::STATE_ACCEPTED;
}
 
 
}
 
function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
 
$latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
97,13 → 95,13
return true;
}
 
function storeObjectAttribute( &$contentObjectAttribute )
function storeObjectAttribute( $contentObjectAttribute )
{
$location =& $contentObjectAttribute->content();
$location = $contentObjectAttribute->content();
$contentObjectAttribute->setAttribute( "data_text", $location->xmlString() );
}
 
function &objectAttributeContent( &$contentObjectAttribute )
function objectAttributeContent( $contentObjectAttribute )
{
$location = new eZGmapLocation( '', '', '' );
$location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
115,14 → 113,14
return $contentObjectAttribute->attribute( "data_text" );
}
 
function title( &$contentObjectAttribute )
function title( $contentObjectAttribute, $name = null )
{
$location = new eZGmapLocation( '', '', '' );
$location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
return $location->attribute('latitude') . ', ' . $location->attribute('longitude');
}
 
function hasObjectAttributeContent( &$contentObjectAttribute )
function hasObjectAttributeContent( $contentObjectAttribute )
{
return true;
}
130,12 → 128,12
/*!
Sets the default value.
*/
function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
{
if ( $currentVersion == false )
{
$location =& $contentObjectAttribute->content();
$contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
$location = $contentObjectAttribute->content();
$contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
if ( !$location )
{
$location = new eZGmapLocation( $contentClassAttribute->attribute( 'data_text1' ), '', '' );
153,65 → 151,42
/*!
\reimp
*/
function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
function serializeContentObjectAttribute( $package, $objectAttribute )
{
$defaultValueName = $base . EZ_GMAPLOCATION_DEFAULT_NAME_VARIABLE . $classAttribute->attribute( 'id' );
if ( $http->hasPostVariable( $defaultValueName ) )
{
$defaultValueValue = $http->postVariable( $defaultValueName );
$node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
 
if ($defaultValueValue == ""){
$defaultValueValue = "";
}
$classAttribute->setAttribute( 'data_text1', $defaultValueValue );
return true;
$dom = new DOMDocument( '1.0', 'utf-8' );
$success = $dom->loadXML( $objectAttribute->attribute( 'data_text' ) );
 
if ( $success )
{
$importedNode = $node->ownerDocument->importNode( $dom->documentElement, true );
$node->appendChild( $importedNode );
}
return false;
}
else
{
eZDebug::writeError( 'Error parsing XML from data_text', __METHOD__ );
}
 
/*!
\reimp
*/
function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
{
$defaultName = $classAttribute->attribute( 'data_text1' );
$attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'default-name', $defaultName ) );
return $node;
}
 
/*!
\reimp
*/
function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
{
$defaultName = $attributeParametersNode->elementTextContentByName( 'default-name' );
$classAttribute->setAttribute( 'data_text1', $defaultName );
}
$locationNode = $attributeNode->getElementsByTagName( 'ezgmaplocation' )->item( 0 );
 
/*!
\reimp
*/
function serializeContentObjectAttribute( &$package, &$objectAttribute )
{
$node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
eZDebug::writeDebug( $locationNode->ownerDocument->saveXML( $locationNode ) );
 
$xml = new eZXML();
$domDocument = $xml->domTree( $objectAttribute->attribute( 'data_text' ) );
$node->appendChild( $domDocument->root() );
 
return $node;
if ( $locationNode )
{
$objectAttribute->setAttribute( 'data_text', $locationNode->ownerDocument->saveXML( $locationNode ) );
}
}
 
/*!
\reimp
*/
function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
{
$rootNode = $attributeNode->firstChild();
$xmlString = $rootNode->attributeValue( 'local_name' ) == 'data-text' ? $rootNode->toString( 0 ) : '';
$objectAttribute->setAttribute( 'data_text', $xmlString );
}
}
 
eZDataType::register( EZ_DATATYPESTRING_GMAPLOCATION, "ezgmaplocationtype" );
eZDataType::register( eZGmapLocationType::DATA_TYPE_STRING, "eZGmapLocationType" );
 
?>