Skip to content

Commit

Permalink
Location Field for Powermail
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/powermail/trunk@61502 735d13b6-9817-0410-8766-e36946ffe9aa
  • Loading branch information
wunschtacho committed May 5, 2012
1 parent 0a4d68b commit f67cc3b
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Classes/Utility/EidGetLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Alex Kellner <[email protected]>, in2code.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* This class could called with AJAX via eID and returns a location from geo coordinates
*
* @author Alex Kellner <[email protected]>, in2code.
* @package TYPO3
* @subpackage eidGetLocation
*/
class eidGetLocation {

/**
* Generates the output
*
* @return string from action
*/
public function main() {
$lat = t3lib_div::_GP('lat');
$lng = t3lib_div::_GP('lng');

$csv = t3lib_div::getUrl('http://maps.google.com/maps/geo?&output=csv&q=' . $lat . ',' . $lng);
$csvParts = Tx_Extbase_Utility_Arrays::trimExplode('"', $csv, 1);
return $csvParts[1];
}
}

$eid = t3lib_div::makeInstance('eidGetLocation'); // make instance
echo $eid->main(); // print content
?>
53 changes: 53 additions & 0 deletions Resources/Public/Js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
jQuery(document).ready(function($) {

// Baseurl
var baseurl = getBaseUrl();

// Form validation
$('.powermail_form').validationEngine();

Expand Down Expand Up @@ -39,6 +42,11 @@ jQuery(document).ready(function($) {
prevText: '&lt;',
firstDay: 1
});

// Location field
if ($('.powermail_fieldwrap_location input').length > 0) {
getLocationAndWrite();
}
});

/**
Expand All @@ -63,3 +71,48 @@ function checkCheckboxes(field, rules, i, options) {
return options.allrules.checkCheckboxes.alertText;
}
}

/**
* Getting the Location by the browser and write to inputform as address
*
* @return void
*/
function getLocationAndWrite() {
if (navigator.geolocation) { // Read location from Browser
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var url = baseurl + '/index.php' + '?eID=' + 'powermailEidGetLocation';
$.ajax({
url: url,
data: 'lat=' + lat + '&lng=' + lng,
cache: false,
beforeSend: function(jqXHR, settings) {
$('body').css('cursor', 'wait');
},
complete: function(jqXHR, textStatus) {
$('body').css('cursor', 'default');
},
success: function(data) { // return values
if (data) {
$('.powermail_fieldwrap_location input').val(data);
}
}
});
});
}
}

/**
* Return BaseUrl as prefix
*
* @return string Base Url
*/
function getBaseUrl() {
if ($('base').length > 0) {
baseurl = $('base').attr('href');
} else {
baseurl = window.location.hostname;
}
return baseurl;
}
5 changes: 5 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] =
'EXT:' . $_EXTKEY . '/Classes/Utility/InitialMarker.php:Tx_Powermail_Utility_InitialMarker';

/**
* eID to get location from geo coordinates
*/
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailEidGetLocation'] = 'EXT:powermail/Classes/Utility/EidGetLocation.php';

/**
* Extra evaluation of TCA fields
*/
Expand Down

0 comments on commit f67cc3b

Please sign in to comment.