\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'pi3/static/', 'WEC Table Map'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'pi2/static/', 'WEC Frontend User Map'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'pi1/static/', 'WEC Simple Map'); $TCA['tx_wecmap_external'] = array('ctrl' => array('title' => 'LLL:EXT:wec_map/locallang_db.xml:tx_wecmap_external', 'label' => 'title', 'tstamp' => 'tstamp', 'crdate' => 'crdate', 'delete' => 'deleted', 'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'tca.php', 'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'res/icon_tx_wecmap_external_resource.gif'), 'feInterface' => array('fe_admin_fieldList' => 'title, url')); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_wecmap_external'); /* Define the address related fields for a frontend user */ if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sr_feuser_register')) { $TCA['fe_users']['ctrl']['EXT']['wec_map'] = array('isMappable' => 1, 'addressFields' => array('street' => 'address', 'city' => 'city', 'state' => 'zone', 'zip' => 'zip', 'country' => 'static_info_country')); } else { $TCA['fe_users']['ctrl']['EXT']['wec_map'] = array('isMappable' => 1, 'addressFields' => array('street' => 'address', 'city' => 'city', 'state' => '', 'zip' => 'zip', 'country' => 'country')); } if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_address')) { $TCA['tt_address']['ctrl']['EXT']['wec_map'] = array('isMappable' => 1, 'addressFields' => array('street' => 'address', 'city' => 'city', 'state' => 'region', 'zip' => 'zip', 'country' => 'country')); } if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('nn_address')) { $TCA['tx_nnaddress_domain_model_address']['ctrl']['EXT']['wec_map'] = array('isMappable' => 1, 'addressFields' => array('street' => 'street', 'city' => 'city', 'state' => 'region', 'zip' => 'zip', 'country' => 'country')); } /* If we want to show a map in frontend user records, add it to the TCA */ if (tx_wecmap_backend::getExtConf('feUserRecordMap')) { $mapTCA = array('tx_wecmap_map' => array('exclude' => 1, 'label' => 'LLL:EXT:wec_map/locallang_db.xml:berecord_maplabel', 'config' => array('type' => 'passthrough', 'form_type' => 'user', 'userFunc' => 'tx_wecmap_backend->drawMap'))); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('fe_users', $mapTCA, 1); $TCA['fe_users']['interface']['showRecordFieldList'] .= ',tx_wecmap_map'; \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('fe_users', '--div--;LLL:EXT:wec_map/locallang_db.xml:berecord_maplabel,tx_wecmap_map'); } /* If we want to show the geocoding status in frontend user records, add it to the TCA */ if (tx_wecmap_backend::getExtConf('geocodingStatus')) { $geocodeTCA = array('tx_wecmap_geocode' => array('exclude' => 1, 'label' => 'LLL:EXT:wec_map/locallang_db.xml:berecord_geocodelabel', 'config' => array('type' => 'passthrough', 'form_type' => 'user', 'userFunc' => 'tx_wecmap_backend->checkGeocodeStatus'))); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('fe_users', $geocodeTCA, 1); $TCA['fe_users']['interface']['showRecordFieldList'] .= ',tx_wecmap_geocode'; \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('fe_users', 'tx_wecmap_geocode'); }
/** * Performs basic normalize on the address compontents. Should be called * before any function searches cached data by address name or inserts * values into the cache. All parameters are passed by reference and * normalized. * * @param string The street address. * @param string The city name. * @param string The state name. * @param string This ZIP code. * @param string The country name. * @param string The optional API key to use in the lookup. * @return none */ static function normalizeAddress(&$street, &$city, &$state, &$zip, &$country) { // pseudo normalize data: first letter uppercase. // @todo: get rid of this once we implement normalization properly $street = ucwords($street); $city = ucwords($city); $state = ucwords($state); // some zip codes contain letters, so just upper case them all $zip = strtoupper($zip); // if length of country string is 3 or less, it's probably an abbreviation; // make it all upper case then if (strlen($country) < 4) { $country = strtoupper($country); } else { $country = ucwords($country); } // to somehow normalize the data we get, we will check for country codes like DEU that the geocoder // doesn't understand and look up a real country name from static_info_countries // 1. check if static_info_tables is available if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) { // 2. check the length of the country and do lookup only if it's 2 or 3 characters $length = strlen($country); if ($length == 2) { // try to find a country with that two character code $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('cn_short_en', 'static_countries', 'cn_iso_2=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($country, static_countries)); $newCountry = $rows[0]['cn_short_en']; if (!empty($newCountry)) { $country = $newCountry; } } else { if ($length == 3) { // try to find a country with that two character code $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('cn_short_en', 'static_countries', 'cn_iso_3=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($country, static_countries)); $newCountry = $rows[0]['cn_short_en']; if (!empty($newCountry)) { $country = $newCountry; } } else { // try to find a country with that two character code $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('cn_short_en', 'static_countries', 'cn_short_local=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($country, static_countries)); $newCountry = $rows[0]['cn_short_en']; if (!empty($newCountry)) { $country = $newCountry; } } } } // if we still have no country, use the default one if (empty($country)) { $country = tx_wecmap_backend::getExtConf('defaultCountry'); // TODO: devlog start if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Using default country: ' . $country, 'wec_map_geocode'); } // devlog end } }
function getApiKeys() { return tx_wecmap_backend::getExtConf('apiKey.google'); }
/** * Main function to draw the map. Outputs all the necessary HTML and * Javascript to draw the map in the frontend or backend. * * @access public * @return string HTML and Javascript markup to draw the map. */ function drawMap() { // TODO: devlog start if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': starting map drawing', 'wec_map_api'); \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': API key: ' . $this->key, 'wec_map_api'); \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': domain: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'), 'wec_map_api'); \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': map type: ' . $this->type, 'wec_map_api'); } // devlog end $lang = \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile('EXT:wec_map/map_service/google/locallang.xml', $this->lang); $hasThingsToDisplay = $this->hasThingsToDisplay(); $hasHeightWidth = $this->hasHeightWidth(); // make sure we have markers to display and an API key if ($hasThingsToDisplay && $hasHeightWidth) { // auto center and zoom if necessary $this->autoCenterAndZoom(); $htmlContent = $this->mapDiv(); $get = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged('tx_wecmap_api'); // if we're forcing static display, skip the js if ($this->static && ($this->staticMode == 'force' || $this->staticUrlParam && intval($get['static']) == 1)) { return $htmlContent; } $scheme = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://'; // get the correct API URL $apiURL = $scheme . 'maps.googleapis.com/maps/api/js?sensor=false&language=' . $this->lang . '&libraries=places'; if (tx_wecmap_backend::getExtConf('useOwnJS')) { $mmURL = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('wec_map') . 'contribJS/markermanager.js'; $ibURL = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('wec_map') . 'contribJS/infobubble.js'; $omURL = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('wec_map') . 'contribJS/oms.min.js'; } else { $mmURL = $scheme . 'google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/src/markermanager.js'; $ibURL = $scheme . 'google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/src/infobubble.js'; $omURL = $scheme . 'jawj.github.com/OverlappingMarkerSpiderfier/bin/oms.min.js'; } if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': loading API from URL: ' . $apiURL, 'wec_map_api'); } /* If we're in the frontend, use TSFE. Otherwise, include JS manually. */ $jsDir = tx_wecmap_backend::getExtConf('jsDir'); if (empty($jsDir)) { $jsDir = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('wec_map') . 'res/'; } $jsFile = $jsDir . 'wecmap.js'; $jsFile2 = $jsDir . 'copyrights.js'; $jsFile3 = $jsDir . 'wecmap_backend.js'; if (TYPO3_MODE == 'FE') { $GLOBALS['TSFE']->additionalHeaderData['wec_map_googleMaps'] = '<script src="' . $apiURL . '" type="text/javascript"></script>' . '<script src="' . $mmURL . '" type="text/javascript"></script>' . '<script src="' . $ibURL . '" type="text/javascript"></script>' . '<script src="' . $omURL . '" type="text/javascript"></script>'; $GLOBALS['TSFE']->additionalHeaderData['wec_map'] = ($jsFile ? '<script src="' . $jsFile . '" type="text/javascript"></script>' : '') . ($jsFile2 ? '<script src="' . $jsFile2 . '" type="text/javascript"></script>' : ''); } else { $htmlContent .= '<script src="' . $apiURL . '" type="text/javascript"></script>'; if (tx_wecmap_backend::getExtConf('useOwnJS')) { $htmlContent .= '<script src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $mmURL . '" type="text/javascript"></script>'; $htmlContent .= '<script src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $ibURL . '" type="text/javascript"></script>'; $htmlContent .= '<script src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $omURL . '" type="text/javascript"></script>'; } else { $htmlContent .= '<script src="' . $mmURL . '" type="text/javascript"></script>'; $htmlContent .= '<script src="' . $ibURL . '" type="text/javascript"></script>'; $htmlContent .= '<script src="' . $omURL . '" type="text/javascript"></script>'; } $htmlContent .= ($jsFile ? '<script src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $jsFile . '" type="text/javascript"></script>' : '') . ($jsFile2 ? '<script src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $jsFile2 . '" type="text/javascript"></script>' : '') . ($jsFile3 ? '<script src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $jsFile3 . '" type="text/javascript"></script>' : ''); } if ($this->enableOverlappingMarkerManager) { $mapOptions['enableOverlappingMarkerManager'] = true; } $jsContent = array(); $jsContent[] = $this->js_createLabels($lang); $jsContent[] = ''; $jsContent[] = $this->js_drawMapStart($mapOptions); $jsContent[] = $this->js_newGDirections(); $jsContent[] = $this->js_setCenter($this->lat, $this->long, $this->zoom, $this->type); if (is_array($this->controls)) { $jsContent = array_merge($jsContent, $this->controls); } $jsContent[] = $this->js_icons(); if (is_array($this->groups)) { foreach ($this->groups as $key => $group) { if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': adding ' . $group->getMarkerCount() . ' markers from group ' . $group->id, 'wec_map_api'); } $jsContent = array_merge($jsContent, $group->drawMarkerJS()); $jsContent[] = ''; } } $jsContent[] = $this->js_initialOpenInfoWindow(); $jsContent[] = $this->js_addKMLOverlay(); $jsContent[] = $this->js_loadCalls(); $jsContent[] = $this->js_drawMapEnd(); if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': finished map drawing', 'wec_map_api'); } // get our content out of the array into a string $jsContentString = implode(chr(10), $jsContent); // then return it return $htmlContent . \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS($jsContentString); } else { if (!$hasThingsToDisplay) { $error = '<p>' . $this->getLL($lang, 'error_nothingToDisplay') . '</p>'; } else { if (!$hasHeightWidth) { $error = '<p>' . $this->getLL($lang, 'error_noHeightWidth') . '</p>'; } } } if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($this->mapName . ': finished map drawing with errors', 'wec_map_api', 2); } return $error; }