private function _process_map($id, $tag, $value) { $out = array(); if (isset($value['adr'])) { $out['adr'] = $value['adr']; $out['_title'] = $value['adr']; $out['_default'] = $value['adr']; if (!isset($value['lat'])) { $lat = false; $lng = false; $path = '/maps/api/geocode/json?address=' . urlencode($value['adr']) . '&sensor=false'; $result = PerchUtil::http_get_request('http://', 'maps.googleapis.com', $path); if ($result) { $result = PerchUtil::json_safe_decode($result, true); //PerchUtil::debug($result); if ($result['status'] == 'OK') { if (isset($result['results'][0]['geometry']['location']['lat'])) { $lat = $result['results'][0]['geometry']['location']['lat']; $lng = $result['results'][0]['geometry']['location']['lng']; } } } } else { $lat = $value['lat']; $lng = $value['lng']; } $out['lat'] = $lat; $out['lng'] = $lng; if (!isset($value['clat'])) { $clat = $lat; $clng = $lng; } else { $clat = $value['clat']; $clng = $value['clng']; } $out['clat'] = $clat; $out['clng'] = $clng; if (!isset($value['zoom'])) { if ($tag->zoom()) { $zoom = $tag->zoom(); } else { $zoom = 15; } } else { $zoom = $value['zoom']; } if (!isset($value['type'])) { if ($tag->type()) { $type = $tag->type(); } else { $type = 'roadmap'; } } else { $type = $value['type']; } $adr = $value['adr']; if (PERCH_RWD) { $width = $tag->width() ? $tag->width() : ''; $height = $tag->height() ? $tag->height() : ''; } else { $width = $tag->width() ? $tag->width() : '460'; $height = $tag->height() ? $tag->height() : '320'; } $static_width = $width == '' ? '460' : $width; $static_height = $height == '' ? '320' : $height; $out['zoom'] = $zoom; $out['type'] = $type; $r = '<img id="cmsmap' . PerchUtil::html($id) . '" src="//maps.google.com/maps/api/staticmap'; $r .= '?center=' . $clat . ',' . $clng . '&size=' . $static_width . 'x' . $static_height . '&zoom=' . $zoom . '&maptype=' . $type; if ($lat && $lng) { $r .= '&markers=color:red|color:red|' . $lat . ',' . $lng; } $r .= '" '; if ($tag->class()) { $r .= ' class="' . PerchUtil::html($tag->class()) . '"'; } $r .= ' width="' . $static_width . '" height="' . $static_height . '" alt="' . PerchUtil::html($adr) . '" />'; $out['admin_html'] = $r; $map_js_path = PerchUtil::html(PERCH_LOGINPATH) . '/core/assets/js/public_maps.min.js'; if (defined('PERCH_MAP_JS') && PERCH_MAP_JS) { $map_js_path = PerchUtil::html(PERCH_MAP_JS); } // JavaScript $r .= '<script type="text/javascript">/* <![CDATA[ */ '; $r .= "if(typeof CMSMap =='undefined'){var CMSMap={};CMSMap.maps=[];document.write('<scr'+'ipt type=\"text\\/javascript\" src=\"" . $map_js_path . "\"><'+'\\/sc'+'ript>');}"; $r .= "CMSMap.maps.push({'mapid':'cmsmap" . PerchUtil::html($id) . "','width':'" . $width . "','height':'" . $height . "','type':'" . $type . "','zoom':'" . $zoom . "','adr':'" . addslashes(PerchUtil::html($adr)) . "','lat':'" . $lat . "','lng':'" . $lng . "','clat':'" . $clat . "','clng':'" . $clng . "'});"; $r .= '/* ]]> */'; $r .= '</script>'; if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) { $r = str_replace('/>', '>', $r); } $out['html'] = $r; } return $out; }