$chunk = $modx->newObject('modChunk', array('name' => "{geocoding_tmp}-{$uniqid}")); $chunk->setCacheable(false); $tpl = $modx->getOption('gmarker.formatting_string'); $secure = $modx->getOption('gmarker.secure'); $lat_tv = $hook->getValue('gmarker.lat_tv') ? $hook->getValue('gmarker.lat_tv') : $modx->getOption('gmarker.lat_tv'); $lng_tv = $hook->getValue('gmarker.lng_tv') ? $hook->getValue('gmarker.lng_tv') : $modx->getOption('gmarker.lng_tv'); if (empty($lat_tv) || empty($lng_tv)) { $modx->log(xPDO::LOG_LEVEL_ERROR, '[Glocation] ' . $modx->lexicon('hook_error')); return true; } $goog['address'] = $chunk->process($props, $tpl); $goog['bounds'] = $hook->getValue('gmarker.bounds') ? $hook->getValue('gmarker.bounds') : $modx->getOption('gmarker.bounds'); $goog['components'] = $hook->getValue('gmarker.components') ? $hook->getValue('gmarker.components') : $modx->getOption('gmarker.components'); $goog['region'] = $hook->getValue('gmarker.region') ? $hook->getValue('gmarker.region') : $modx->getOption('gmarker.region'); $goog['language'] = $hook->getValue('gmarker.language') ? $hook->getValue('gmarker.language') : $modx->getOption('gmarker.language'); $Gmarker->lookup($goog, $secure, $refresh); $lat = $Gmarker->get('location.lat'); if (empty($lat)) { $lat = 0; } $lng = $Gmarker->get('location.lng'); if (empty($lng)) { $lng = 0; } $hook->setValue($lat_tv, $lat); $hook->setValue($lng_tv, $lng); return true; } //------------------------------------------------------------------------------ //! Snippet Mode //------------------------------------------------------------------------------
$props['region'] = $modx->getOption('region', $scriptProperties, $modx->getOption('gmarker.region')); $props['language'] = $modx->getOption('language', $scriptProperties, $modx->getOption('gmarker.language')); // Other props that are used in the output $props2 = array(); $props2['h'] = (int) $modx->getOption('height', $scriptProperties, $modx->getOption('gmarker.default_height')); $props2['w'] = (int) $modx->getOption('width', $scriptProperties, $modx->getOption('gmarker.default_width')); $props2['id'] = $modx->getOption('id', $scriptProperties, 'map'); $props2['zoom'] = $modx->getOption('zoom', $scriptProperties, 15); $props2['type'] = $modx->getOption('type', $scriptProperties, 'ROADMAP'); $props2['gmarker_url'] = $Gmarker->get_maps_url(array('key' => $modx->getOption('gmarker.apikey')), $secure); // Verify inputs if (empty($address) && empty($latlng) && empty($components)) { $modx->log(xPDO::LOG_LEVEL_ERROR, '[Gmap] ' . $modx->lexicon('missing_params')); return $Gmarker->alert($modx->lexicon('missing_params')); } if (!$props2['h']) { $props2['h'] = 300; } if (!$props2['w']) { $props2['w'] = 500; } // Handle lookups and caching // Fingerprint the lookup $json = $Gmarker->lookup($props); // Pull the coordinates out $props2['lat'] = number_format($Gmarker->get('location.lat'), 8); $props2['lng'] = number_format($Gmarker->get('location.lng'), 8); // Add the stuff to the head $modx->regClientStartupHTMLBlock($modx->getChunk($headTpl, $props2)); return $modx->parseChunk($outTpl, $props2); /*EOF*/
$modx->log(xPDO::LOG_LEVEL_ERROR, '[Gmarker] ' . $modx->lexicon('invalid_resource', array('id' => $p->get('id'), 'var' => 'Chunk:' . $infoChunk))); } } else { $prps['info'] = ''; } // If there are no geocoordinates, optionally look them up if (!$suppressLookup && (empty($prps[$lat_tv]) || empty($prps[$lng_tv]))) { $uniqid = uniqid(); $chunk = $modx->newObject('modChunk', array('name' => "{geocoding_tmp}-{$uniqid}")); $chunk->setCacheable(false); $goog['address'] = $chunk->process($raw_prps, $tpl); $goog['bounds'] = $modx->getOption('gmarker.bounds'); $goog['components'] = $modx->getOption('gmarker.components'); $goog['region'] = $modx->getOption('gmarker.region'); $goog['language'] = $modx->getOption('gmarker.language'); $json = $Gmarker->lookup($goog, $secure); if (!$p->setTVValue($lat_tv, $Gmarker->get('location.lat'))) { $modx->log(xPDO::LOG_LEVEL_ERROR, '[Gmarker] ' . $modx->lexicon('problem_saving', array('id' => $resource->get('id')))); } if (!$p->setTVValue($lng_tv, $Gmarker->get('location.lng'))) { $modx->log(xPDO::LOG_LEVEL_ERROR, '[Gmarker] ' . $modx->lexicon('problem_saving', array('id' => $resource->get('id')))); } } // Set checkbox group $this_group = $p->getTVValue($group); $distinct_groups[$this_group] = 1; $prps['group_json'] = '""'; if ($group) { $group_str = trim($p->getTVValue($group)); if ($groupCallback) { $group_str = $modx->runSnippet($groupCallback, array('group' => $group_str));