Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
google_map.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/page_templates/page_asset_listing/page_asset_listing.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44  $this->_ser_attrs = TRUE;
45  $this->api_key = '';
46 
47  }//end constructor
48 
49 
60  function _createAdditional(&$link, $args=Array())
61  {
62  if (!parent::_createAdditional($link)) return FALSE;
63 
64  $this->createBodycopy('Popup Window');
65 
66  return TRUE;
67 
68  }//end _createAdditional()
69 
70 
77  function createBodycopy($name)
78  {
79  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
80  $bodycopy = new Bodycopy();
81  $bodycopy->setAttrValue('name', $name);
82  $content_type = 'content_type_raw_html';
83 
84  $content = $this->_getDefaultBodycopyContent(str_replace(' ','_', strtolower($name)));
85 
86  $bc_data = Array (
87  'attributes' => Array (
88  'content_type' => $content_type,
89  ),
90  'content' => $content,
91  );
92 
93  $copy_link = Array (
94  'asset' => $this,
95  'link_type' => SQ_LINK_TYPE_2,
96  'is_dependant' => 1,
97  'is_exclusive' => 1,
98  'value' => $name,
99  );
100 
101  if (!$bodycopy->create($copy_link, $bc_data)) {
102  return FALSE;
103  }//end if
104 
105  }//end createBodycopy()
106 
107 
115  function _getAllowedLinks()
116  {
117 
118  $allowed_link['asset']['card'] = 'M';
119  $allowed_link['asset']['exclusive'] = FALSE;
120 
121  $links[SQ_LINK_TYPE_1] = $allowed_link;
122  $links[SQ_LINK_TYPE_2] = $allowed_link;
123  $links[SQ_LINK_TYPE_3] = $allowed_link;
124  $links[SQ_LINK_NOTICE] = $allowed_link;
125 
126  return $links;
127 
128  }//end _getAllowedLinks()
129 
130 
137  public function getCacheKey()
138  {
139  $root_nodes = $this->getRootNodes();
140  $hash_str = '';
141  foreach ($root_nodes as $root_assetid) {
142  $hash_str .= $root_assetid;
143  }//end
144  $hash = md5($hash_str);
145 
146  return $hash;
147  }//end getCacheKey()
148 
149 
158  public function getCachedResultSet($cache_key='')
159  {
160  $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cache_manager');
161  $result = $cm->loadFromCache($this->id, $this->type(), $cache_key, FALSE);
162 
163  // empty string means that the result was not serialised
164  // which means cache manager does not have an entry for this cache_key
165  if ($result === FALSE) return FALSE;
166 
167  $result = unserialize($result);
168  return $result;
169 
170  }//end getCachedResultSet()
171 
172 
179  private function cacheResultSet(Array $result, $cache_key='')
180  {
181  $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cache_manager');
182  $r = $cm->saveToCache($this->id, $this->type(), $cache_key, serialize($result), FALSE);
183 
184  }//end cacheResultSet()
185 
186 
193  public function printBody()
194  {
195  $api_key = $this->attr('api_key');
196  $this->api_key = $api_key;
197  $lat = $this->attr('default_latitude');
198  $lng = $this->attr('default_longitude');
199  $zoom_level = $this->attr('default_zoom_level');
200  $map_type = $this->attr('default_map_type');
201  $use_google_marker = $this->attr('use_google_marker_icon');
202  $icon_url = '';
203  if (!$use_google_marker)
204  $icon_url = $this->attr('default_marker_icon');
205  $icon_width = $this->attr('default_icon_width');
206  $icon_height = $this->attr('default_icon_height');
207  $default_icon_size = $this->attr('default_icon_size');
208  if ($default_icon_size) {
209  $icon_height = 25;
210  $icon_width = 25;
211  }//end if
212 
213  $description = 'defaultlocation';
214  $keywords_list = $this->attr('asset_types_keywords');
215  $street_view = $this->attr('enable_street_view');
216  $create_location = $this->attr('enable_create_location');
217 
218  $dynamic_lat = $this->getDynamicVariableValue('latitude');
219  $dynamic_lng = $this->getDynamicVariableValue('longitude');
220  $dynamic_desc = $this->getDynamicVariableValue('description');
221  $dynamic_zoom_level = $this->getDynamicVariableValue('zoom_level');
222  $dynamic_map_type = $this->getDynamicVariableValue('map_type');
223 
224  if ($dynamic_lat && $dynamic_lng) {
225  $lat = $dynamic_lat;
226  $lng = $dynamic_lng;
227  }//end if
228 
229  if (!empty($dynamic_zoom_level)) $zoom_level = $dynamic_zoom_level;
230  if (!empty($dynamic_desc)) $description = $dynamic_desc;
231  if (!empty($dynamic_map_type)) $map_type = $dynamic_map_type;
232 
233  $cache_key = $this->getCacheKey();
234  $cached_result = $this->getCachedResultSet($cache_key);
235 
236  $bodycopy_popup_window = $this->getBodycopy('Popup Window');
237  $keywords = $bodycopy_popup_window->getKeywords();
238 
239  $root_node_id = $this->attr('root_assetid');
240 
241  $res = $this->getAssetList();
242 
243  $exclude_assets = $this->attr('exclude_assets');
244 
245  // get children of exclude root nodes, add them to the exclude list
246  $exclude_root_nodes = $this->attr('exclude_root_nodes');
247  foreach($exclude_root_nodes as $key => $value) {
248  $exclude_children = $GLOBALS['SQ_SYSTEM']->am->getChildren($value);
249  $exclude_assets += array_keys($exclude_children);
250  }//end foreach
251 
252  if (!empty($exclude_assets)) {
253  foreach ($exclude_assets as $index => $assetid) {
254  if (isset($res[$assetid])) {
255  unset($res[$assetid]);
256  }//end if
257  }//end foreach
258  }//end if
259 
260 
261  $res = $this->convertProxyAssetTypes($res);
262  $this->filterAssetList($res);
263 
264  $root_nodes = $this->getRootNodes();
265 
266  $assets_parent = Array();
267 
268  $toggle_root_nodes = $this->attr('toggle_root_nodes');
269 
270  // Only query the tree when we are not using grouping, but toggling is turned on
271  if ($toggle_root_nodes) {
272  foreach ($root_nodes as $root_assetid) {
273  $children = $this->classifyChildren($root_assetid, array_keys($res));
274  if (!empty($children)) {
275  foreach ($children as $child_info) {
276  $assets_parent[$child_info['minorid']][] = $root_assetid;
277  }//end foreach
278  }//end if
279  }//end foreach
280  }//end if
281 
282  $locations_info = Array();
283  $address_keyword = FALSE;
284  $listing_ldap_user = FALSE;
285 
286  if (!empty($res)) {
287  $node_info = Array();
288 
289  foreach ($res as $child_assetid => $asset_type)
290  {
291  $popup_html = '';
292  $child_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($child_assetid);
293  $child_asset_type = $child_asset->type();
294 
295  $child_address = NULL;
296  if ($child_asset->type() == 'google_map_location') {
297  $child_title = $child_asset->attr('name');
298  $child_latitude = $child_asset->attr('latitude');
299  $child_longitude = $child_asset->attr('longitude');
300  $child_icon_url = $child_asset->attr('icon_url');
301  $child_description = $child_asset->attr('description');
302  } else {
303  $child_title = $child_asset->getKeywordReplacement(str_replace('%', '', $keywords_list[$child_asset_type]['name_keyword']));
304  if (is_array($child_title)) {
305  $child_title = implode(' ', $child_title);
306  }//end if
307 
308  $child_latitude = $child_asset->getKeywordReplacement(str_replace('%', '', $keywords_list[$child_asset_type]['latitude_keyword']));
309  $child_longitude = $child_asset->getKeywordReplacement(str_replace('%', '', $keywords_list[$child_asset_type]['longitude_keyword']));
310  $child_icon_url = $this->replaceKeywordCombination($keywords_list[$child_asset_type]['icon_url_keyword'], $child_asset);
311  $child_description = $child_asset->getKeywordReplacement(str_replace('%', '', $keywords_list[$child_asset_type]['description_keyword']));
312  $address_keyword = array_get_index($keywords_list[$child_asset_type], 'address_keyword', NULL);
313  if ($address_keyword) {
314  $child_address = $this->replaceKeywordCombination($address_keyword, $child_asset);
315  }//end if
316  }//end if
317 
318  $loc_index = $child_assetid;
319  $ldap_user = ($child_asset->type() instanceof Ldap_User || $child_asset->type() instanceof Ldap_User_Group);
320 
321  // Override if ldap user
322  if ($address_keyword && !is_int($child_assetid) && $ldap_user) {
323  $loc_index = $child_asset->getKeywordReplacement('asset_attribute_uid');
324  }//end if
325 
326  $locations_info[$loc_index]['title']= $child_title;
327  $locations_info[$loc_index]['lat'] = $child_latitude;
328  $locations_info[$loc_index]['lng'] = $child_longitude;
329  $locations_info[$loc_index]['icon'] = !empty($child_icon_url) ? $child_icon_url : $icon_url;
330  $locations_info[$loc_index]['desc'] = $child_description;
331  if ($address_keyword) {
332  $locations_info[$loc_index]['addr'] = $child_address;
333 
334  // This is special case when we use LDAP, but what if we dont use LDAP
335  $index = $child_asset->id;
336  $asset_types_list = array_keys($GLOBALS['SQ_SYSTEM']->am->getAssetTypeHierarchy('ldap_user'));
337  $asset_types_list[] = 'ldap_user';
338  $listing_ldap_user = in_array($child_asset_type, $asset_types_list);
339  if ($listing_ldap_user) {
340  $index = $child_asset->getKeywordReplacement('asset_attribute_uid');
341  }//end if
342  $locations_info[$loc_index]['index'] = $index;
343 
344  // Now if we use address, we will check
345  if (empty($child_latitude) || empty($child_longitude)) {
346  // Check the cache
347  if (!empty($cached_result) && isset($cached_result[$index])) {
348  // If in cache
349  if (isset($locations_info[$loc_index]['lat'])) {
350  $locations_info[$loc_index]['lat'] = $cached_result[$index]['lat'];
351  }//end if
352  if (isset($locations_info[$loc_index]['lng'])) {
353  $locations_info[$loc_index]['lng'] = $cached_result[$index]['lng'];
354  }//end if
355  } else {
356  // We are calling the Geocoding service
357  $result = $this->getLatLngFromAddress($child_address);
358  $cached_result[$index] = $result;
359  if ($result !== FALSE) {
360  $locations_info[$loc_index]['lat'] = $cached_result[$index]['lat'];
361  $locations_info[$loc_index]['lng'] = $cached_result[$index]['lng'];
362  }//end if
363  $this->cacheResultSet($cached_result, $cache_key);
364  }//end else
365  }//end if
366 
367  }//end if
368 
369  $replacements = Array();
370  foreach ($keywords as $word) {
371  $asset_keyword = $this->getMappedKeyword($child_asset_type, $word);
372  $replacements[$word] = $child_asset->getKeywordReplacement($asset_keyword);
373  }//end foreach
374 
375  $bodycopy_popup_window->setKeywordReplacements($replacements);
376  ob_start();
377  $bodycopy_popup_window->printBody();
378  $popup_html = ob_get_contents();
379  ob_end_clean();
380 
381  $locations_info[$loc_index]['html'] = $popup_html;
382 
383  }//end foreach
384 
385  }//end if
386 
387  ?>
388  <script src="<?php echo (current_protocol()); ?>://maps.googleapis.com/maps/api/js?key=<?php echo $api_key; ?>&amp;sensor=false" type="text/javascript"></script>
389  <script type="text/javascript">
390  //<![CDATA[
391  <?php if (!empty($popup_html)) {
392  $popup_html = preg_replace('/(\r\n|\r|\n)/s','', $popup_html);
393  ?>
394  var popup_html = '<?php echo preg_replace("/'/", "\'", $popup_html); ?>';
395  <?php } ?>
396  var centerLatitude = <?php echo (float) $lat; ?>;
397  var centerLongitude = <?php echo (float) $lng; ?>;
398  var desc = '<?php echo $description; ?>';
399  var zoomLevel = <?php echo (int) $zoom_level; ?>;
400  var map_type = google.maps.MapTypeId.<?php echo $map_type; ?>;
401  var icon_url = '<?php echo $icon_url; ?>';
402  var icon_width = <?php echo $icon_width; ?>;
403  var icon_height = <?php echo $icon_height; ?>;
404 
405  // The MAP
406  var map;
407  var myPano; // The street view object
408  var overlay = null;
409  var geocoder = null;
410  var allMarkerList = {};
411  var allDisplayingMarker = {};
412  var markerTypes = {};
413  var markerRootNodes = {};
414  var addressList = [];
415  var cache_home_url = '<?php echo $this->getUrl(); ?>';
416  var cache_key = '<?php echo $cache_key; ?>';
417 
418  var current_marker = null;
419  var current_listener = null;
420  var current_listener_name = 'navigate_tool';
421 
422 
423  <?php
424  $geocoder = $this->attr('enable_geocoder');
425  if ($geocoder) {
426  ?>
427  geocoder = new google.maps.Geocoder();
428  <?php
429  }//end if
430 
431 
432  ?>
433  //]]>
434  </script>
435  <script type="text/javascript" src="<?php echo sq_web_path('data').'/asset_types/google_map/js/map_lib.js'?>"></script>
436 
437 
438  <?php
439 
440  // Need to print here so we can have the "map" div, and add stuff to it.
441  parent::printBody();
442 
443  if (!empty($locations_info)) {
444  ?>
445  <script type="text/javascript">
446  //<![CDATA[
447  var lat;
448  var lng;
449 
450  var newMarkers = [];
451  var newPolylines = [];
452  // Now we are listing new markers, but we have to store them in a central array.
453 
454  <?php
455 
456 
457  $asset_types = $this->attr('types');
458  foreach ($asset_types as $type_code => $inherit) {
459  ?>
460  markerTypes['<?php echo $type_code; ?>'] = { toggle:true };
461  <?php
462  }//end foreach
463 
464  if ($toggle_root_nodes) {
465  foreach ($root_nodes as $root_assetid) {
466  ?>
467  markerRootNodes['<?php echo $root_assetid; ?>'] = { toggle:true };
468  <?php
469  }//end foreach
470  }//end if
471 
472  foreach ($locations_info as $child_assetid => $location_info) {
473 
474  if ( empty($location_info['lat']) || empty($location_info['lng'])) {
475  // We can't map this address so just continue
476  continue;
477  } else {
478 
479  $popup_content = isset($location_info['html']) && !empty($location_info['html']) ? $location_info['html'] : $location_info['desc'];
480  $html = str_replace('', '', preg_replace("/'/", "\'", $popup_content));
481  $html = preg_replace('/(\r\n|\r|\n)/s','<br />', $html);
482  $title = preg_replace('/\s/', '_', $location_info['title']);
483  $title = preg_replace('/(\'|\.)/', '_', $title);
484  $location_lat = (float) $location_info['lat'];
485  $location_lng = (float) $location_info['lng'];
486  if (isset($cached_result[$child_assetid])) {
487  $location_lat = $cached_result[$child_assetid]['lat'];
488  $location_lng = $cached_result[$child_assetid]['lng'];
489  }//end if
490 
491  ?>
492  var marker = addMarker('<?php echo $title ?>' ,<?php echo $location_lat; ?>, <?php echo $location_lng; ?>, '<?php echo $location_info['icon']; ?>', '<?php echo $html;?>', <?php echo $street_view ? 'true' : 'false'; ?>);
493  <?php
494  if ($toggle_root_nodes && !$listing_ldap_user) {
495  if (isset($assets_parent[$child_assetid])) {
496  //We can't have marker toggling while listing ldap users (use Geocoder to find addresses)
497  // Array structure does not allow so
498  ?>
499  markerRootNodes['<?php echo $assets_parent[$child_assetid][0]; ?>']['<?php echo $child_assetid;?>'] = marker;
500  <?php
501  }//end if
502  }//end if ?>
503 
504  allMarkerList['<?php echo $child_assetid; ?>'] = marker;
505  <?php
506  if (!$listing_ldap_user) {
507  // We can't have marker toggling while listing ldap users (use Geocoder to find addresses),
508  // Array structure does not allow so
509  ?>
510  markerTypes['<?php echo $res[$child_assetid][0]['type_code']; ?>']['<?php echo $child_assetid;?>'] = marker;
511  <?php
512  }//end if
513  }//end if
514 
515  }//end foreach
516  if ($dynamic_lat && $dynamic_lng) {
517  ?>
518  var marker = addMarker('center', <?php echo (float) $dynamic_lat; ?>, <?php echo (float) $dynamic_lng; ?>);
519  <?php
520  }//end if
521  ?>
522  //]]>
523  </script>
524  <?php
525  if ($create_location) {
527  }//end if
528 
529  if ($street_view) {
530  $this->enableStreetView();
531  }//end if
532  }//end if
533 
534 
535  }//end printBody();
536 
537 
544  function replaceKeywordCombination($combination, $asset)
545  {
546  $multiple_keywords = extract_keywords($combination);
547  $replacements = Array();
548  foreach ($multiple_keywords as $keyword) {
549  $replacements[$keyword] = $asset->getKeywordReplacement($keyword);
550  }//end foreach
551 
552  replace_keywords($combination, $replacements);
553 
554  return $combination;
555 
556  }//end replaceKeywordCombination();
557 
558 
567  function getBodycopy($name)
568  {
569  $null = NULL;
570  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $name, 'major');
571  if (empty($link)) return $null;
572  $bodycopy = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
573  return $bodycopy;
574 
575  }//end getBodycopy()
576 
577 
586  public function getDynamicVariableValue($variable_name)
587  {
588  $dynamic_vars = $this->attr('dynamic_vars');
589  if (!isset($dynamic_vars[$variable_name])) return '';
590 
591  $parameter_map = $this->getAttribute('parameter_map');
592  $value = $parameter_map->getParameterValue($variable_name);
593 
594  if (empty($value)) {
595  $value = array_get_index($dynamic_vars, $variable_name, '');
596  }//end if
597 
598  return $value;
599 
600  }//end getDynamicVariableValue()
601 
602 
610  {
611 
612  $keywords = parent::_getContentsKeywords();
613  $keywords['location_name'] = translate('google_map_name_keyword');
614  $keywords['location_latitude'] = translate('google_map_latitude_keyword');
615  $keywords['location_longitude'] = translate('google_map_longitude_keyword');
616  $keywords['location_description'] = translate('google_map_description_keyword');
617  $keywords['location_icon_url'] = translate('google_map_icon_url_keyword');
618  $keywords['google_map'] = translate('google_map_initialisation');
619 
620  $keywords['street_view'] = translate('google_map_street_view');
621  $keywords['toggle_street_view_window'] = translate('google_map_toggle_street_view_window');
622  $keywords['toggle_new_address_list']= translate('google_map_toggle_new_address_list');
623  $keywords['toggle_tool_bar'] = translate('google_map_toggle_tool_bar');
624  $keywords['tool_bar'] = translate('google_map_tool_bar');
625  $keywords['toggle_address_finder'] = translate('google_map_toggle_address_finder');
626 
627  $keywords['toggle_asset_types'] = translate('google_map_toggle_asset_types');
628  $keywords['toggle_root_nodes'] = translate('google_map_toggle_root_nodes');
629 
630  $keywords['address_finder'] = translate('google_map_address_finder');
631  $keywords['new_address_list'] = translate('google_map_new_address_list');
632  $keywords['asset_builder'] = translate('google_map_asset_builder');
633 
634  $keywords['get_closest_location'] = translate('google_map_get_closest_location');
635  $keywords['clear_new_markers'] = translate('google_map_clear_new_markers');
636  $keywords['map_type_menu'] = translate('google_map_map_type_menu');
637 
638  return $keywords;
639 
640  }//end _getContentsKeywords()
641 
642 
651  public function getKeywordReplacement($keyword)
652  {
653  if ($keyword == 'google_map') {
654  $map_code = $this->attr('map_code');
655  return $map_code;
656  } else if ($keyword == 'street_view') {
657  $street_view_code = $this->attr('street_view_code');
658  return $street_view_code;
659  } else if ($keyword == 'address_finder') {
660  $street_view_enabled = $this->attr('enable_street_view');
661  $street_view_enabled = $street_view_enabled ? 'true' : 'false';
662  return '<div id="address_finder" class="address_finder_div">
663  <form action="#" onsubmit="findLocationFromAddress(this.address.value, null, null, '.$street_view_enabled.'); return false">
664  <p>
665  <input type="text" style="width:400px;" name="address" value="" />
666  <input type="submit" value="Find Location" />
667  </p>
668  </form>
669  </div>';
670  } else if ($keyword == 'new_address_list') {
671  return '<div id="new_address_list" class="new_address_list">
672  </div>';
673  } else if ($keyword == 'map_type_menu') {
674  $map_menu = '<ul id="map_menu" class="map_type_menu" style="list-style:none;">
675  <li><button onClick="setMapType(google.maps.MapTypeId.ROADMAP);">ROADMAP</button></li>
676  <li><button onClick="setMapType(google.maps.MapTypeId.SATELLITE);">SATELLITE</button></li>
677  <li><button onClick="setMapType(google.maps.MapTypeId.TERRAIN);">TERRAIN</button></li>
678  <li><button onClick="setMapType(google.maps.MapTypeId.HYBRID);">HYBRID</button></li>';
679  $map_menu .= '</ul>';
680  return $map_menu;
681  } else if ($keyword == 'clear_new_markers') {
682  return '<a href="javascript:clearNewMarker(newMarkers);clearNewMarker(newPolylines);">Clear New Markers</a>';
683  } else if ($keyword == 'get_closest_location') {
684  return '<a href="javascript:getClosestLocation();">Get Closest Location</a>';
685  } else if ($keyword == 'asset_builder') {
686  return '<div id="asset_builder" class="asset_builder_div">NEST YOUR ASSET BUILDER HERE</div>';
687  } else if ($keyword == 'toggle_street_view_window') {
688  return '<a href="javascript:toggleDiv(\'street_view\');" id="toggle_street_view">Toggle Street View</a>';
689  } else if ($keyword == 'toggle_new_address_list') {
690  return '<a href="javascript:toggleDiv(\'new_address_list\');" id="toggle_new_address_list">Toggle New Address List</a>';
691  } else if ($keyword == 'toggle_address_finder') {
692  return '<a href="javascript:toggleDiv(\'address_finder\');" id="toggle_address_finder">Toggle Address Finder</a>';
693  } else if ($keyword == 'toggle_tool_bar') {
694  return '<a href="javascript:toggleDiv(\'tool_bar_list\');" id="toggle_tool_bar">Toggle Tool Bar</a>';
695  } else if ($keyword == 'tool_bar') {
696  return '
697  <ul id="tool_bar_list" class="tool_bar" style="list-style:none;">
698  <li><a href="javascript:addListeners(\'navigate\', this.id);" style="color:red;" title="Navigate Map" >
699  <img src="'.sq_web_path('data').'/asset_types/google_map/images/map.png'.'" style="border-color:red;border:2px solid;" id="navigate_tool" name="navigate_tool"/>
700  </a>
701  </li>
702  <li>
703  <a href="javascript:addListeners(\'add_marker\', this.id);" style="color:white;" title="Add Marker">
704  <img src="'.sq_web_path('data').'/asset_types/google_map/images/arrowdown.png'.'" style="border-color:white;border:2px solid;" id="add_marker_tool" name="add_marker_tool"/>
705  </a>
706  </li>
707  <li>
708  <a href="javascript:addListeners(\'street_view\', this.id);" style="color:white;" title="Street View">
709  <img src="'.sq_web_path('data').'/asset_types/google_map/images/binocular.png'.'" style="border-color:white;border:2px solid;" id="street_view_tool" name="street_view_tool"/>
710  </a>
711  </li>
712  </ul>';
713  } else if ($keyword == 'toggle_asset_types') {
714  $asset_types = $this->attr('types');
715  $result = '';
716  foreach ($asset_types as $type => $inherit) {
717  $result .= '<a href="javascript:toggleDisplay(markerTypes, \''.$type.'\')">Toggle '.ucwords(str_replace('_', ' ', $type)).'</a><br />';
718  }//end foreach
719  return $result;
720  } else if ($keyword == 'toggle_root_nodes') {
721  $root_nodes = $this->getRootNodes();
722  $result = '';
723  foreach ($root_nodes as $root_assetid) {
724  $root_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($root_assetid);
725  $result .= '<a href="javascript:toggleDisplay(markerRootNodes, \''.$root_assetid.'\')">Toggle '.$root_asset->attr('name').'</a><br />';
726  }//end foreach
727  return $result;
728  } else {
729  parent::getKeywordReplacement($keyword);
730  }//end if
731 
732  }//end getKeywordReplacement()
733 
734 
744  public function getMappedKeyword($type_code, $keyword)
745  {
746  $keywords_list = $this->attr('asset_types_keywords');
747  if (isset($keywords_list[$type_code])) {
748  switch ($keyword) {
749  case 'location_name':
750  return str_replace('%', '', $keywords_list[$type_code]['name_keyword']);
751  break;
752  case 'location_latitude':
753  return str_replace('%', '', $keywords_list[$type_code]['latitude_keyword']);
754  break;
755  case 'location_longitude':
756  return str_replace('%', '', $keywords_list[$type_code]['longitude_keyword']);
757  break;
758  case 'location_description':
759  return str_replace('%', '', $keywords_list[$type_code]['description_keyword']);
760  break;
761  case 'location_icon_url':
762  return str_replace('%', '', $keywords_list[$type_code]['icon_url_keyword']);
763  break;
764  default:
765  return $keyword;
766  break;
767  }//end switch
768  } else if ($type_code == 'google_map_location') {
769  switch ($keyword) {
770  case 'location_name':
771  return 'asset_attribute_name';
772  break;
773  case 'location_latitude':
774  return 'asset_attribute_latitude';
775  break;
776  case 'location_longitude':
777  return 'asset_attribute_longitude';
778  break;
779  case 'location_description':
780  return 'asset_attribute_description';
781  break;
782  case 'location_icon_url':
783  return 'asset_attribute_icon_url';
784  break;
785  default:
786  return $keyword;
787  break;
788  }//end switch
789  } else {
790  return FALSE;
791  }//end else
792  }//end getMappedKeyword()
793 
794 
803  function _getDefaultBodycopyContent($bodycopy_code)
804  {
805  switch ($bodycopy_code) {
806  case 'page_contents':
807  return '%google_map%
808  %asset_listing%';
809  case 'default_format':
810  return '<a href="javascript:getInfo(\'%asset_assetid%\');">%asset_name%</a>';
811  case 'popup_window':
812  return '%location_name% - %location_description%';
813  case 'input_form':
814  ob_start();?>
815  <fieldset style="width:200px;color:black;background:#DDDDDD;">
816  <legend style="font-weight:bold;">New Marker</legend>
817  <label for="found">Location</label>
818  <input type="text" id="found" style="width:100%;"/>
819  <input type="hidden" id="depth" value="" style="width:100%;"/>
820  <label for="depth">Who drowned here?</label>
821  <input type="text" id="icon" style="width:100%;"/>
822  <input type="hidden" id="longitude" value="' , lng , '"/>
823  <input type="hidden" id="latitude" value="' , lat , '"/><br />
824  <input type="submit" value="Add Location" style="margin-left:20px;"/>
825  </fieldset><?php
826  $content = ob_get_contents();
827  ob_end_clean();
828 
829  return $content;
830  }//end switch
831 
832  parent::_getDefaultBodycopyContent($bodycopy_code);
833 
834  }//end _getDefaultBodycopyContent()
835 
836 
846  public function classifyChildren($root_id, $assetids)
847  {
848  $sql = 'SELECT minorid FROM sq_ast_lnk WHERE majorid = \''.$root_id.'\' AND minorid IN (\''.implode("', '", $assetids).'\')';
849 
850  $query = MatrixDAL::preparePdoQuery($sql);
851  $children = MatrixDAL::executePdoAssoc($query);
852 
853  if (empty($children)) {
854  $root_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($root_id);
855  if (implements_interface($root_asset, 'bridge')) {
856  $children = $root_asset->getChildren($root_id);
857  $children_ids = Array();
858  foreach ($children as $assetid => $type_code_info) {
859  $children_ids[] = Array ('minorid' => $assetid);
860  }//end if
861  $children = $children_ids;
862  }//end if
863  }//end if
864 
865  return $children;
866 
867  }//end find_children()
868 
869 
876  public function getGoogleMapLocationAssetAttributeId()
877  {
878  $sql = 'select name, attrid from sq_ast_attr where type_code = \'google_map_location\' and name IN (\'name\', \'description\', \'latitude\', \'longitude\')';
879  $query = MatrixDAL::preparePdoQuery($sql);
880  $result = MatrixDAL::executePdoGroupedAssoc($query);
881 
882  if (!empty($result)) {
883  ?>
884  <script type="text/javascript">
885  //<![CDATA[
886  var FormEle = {};
887  <?php
888  foreach ($result as $attr_name => $attr_id_info) {
889  // Giving a shot here, how would I know whether it is google_map_location_"0" or "1"? It's better be the asset builder only built for the map
890  ?>
891  FormEle.<?php echo $attr_name; ?> = '<?php echo 'google_map_location_0_'.$attr_id_info[0]['attrid']; ?>';
892  <?php
893  }//end foreach
894  ?>
895  //]]>
896  </script>
897  <?php
898 
899  }//end if
900 
901  }//end getGoogleMapLocationAttributeId()
902 
903 
910  public function enableStreetView()
911  {
912  ?>
913  <script type="text/javascript">
914  //<![CDATA[
915  var center = new google.maps.LatLng(centerLatitude, centerLongitude);
916  panoramaOptions = { position:center };
917  myPano = new google.maps.StreetViewPanorama(document.getElementById("street_view"), panoramaOptions);
918  map.setStreetView(myPano);
919  //]]>
920  </script>
921  <?php
922  }//end enableStreetView()
923 
924 
931  public function getLatLngFromAddress($address)
932  {
933  if (empty($this->api_key)) {
934  $this->api_key = $this->attr('api_key');
935  }//end if
936  $base_url = "http://maps.googleapis.com/maps/api/geocode/xml";
937  $request_url = $base_url."?address=" . urlencode($address).'&sensor=false';
938 
939  $geocode_pending = TRUE;
940 
941  $lat = NULL;
942  $lng = NULL;
943  $steps = 0;
944  while ($geocode_pending) {
945  $delay = 0;
946 
947  $options = array(
948  'RETURNTRANSFER' => 1,
949  );
950 
951  $details = fetch_url($request_url, $options);
952  $maps_xml = $details['response'];
953 
954  $xml = simplexml_load_string($maps_xml) or die("url not loading");
955 
956  $status = (string) $xml->status;
957 
958  if ($status == "OK") {
959  $geocode_pending = false;
960  $result = $xml->result;
961 
962  $coordinates = $result[0]->geometry->location;
963 
964  $lat = (string) $coordinates->lat;
965  $lng = (string) $coordinates->lng;
966 
967  } else {
968  // GeoCoder returns this status on 2 conditions: 1. sending addresses too fast 2. exceeding 15000 addresses per 24Hr
969  // slow down, and bail if steps is too great (to prevent an infinite loop, by exceeding 15000 addresses)
970  if ($steps < 100) {
971  $delay += 100000;
972  $steps++;
973  } else {
974  $geocode_pending = FALSE;
975  }//end if
976  }
977  usleep($delay);
978  }//end while
979 
980  if (!empty($lat) && !empty($lng)) {
981  $result = Array (
982  'lat' => $lat,
983  'lng' => $lng,
984  );
985  return $result;
986  } else {
987  return FALSE;
988  }//end else
989 
990  }//end getLatLngFromAddress()
991 
992 
993 
994 }//end class
995 ?>