Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions class.geocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function __construct ($address) {
// trim all quotes (even smart) from address
$address = trim($address, '\'"”');
$address = urlencode( $address );

$geocoder = $settings->get('geocoder');

$cached_address = 'leaflet_' . $geocoder . '_' . $address;

/* retrieve cached geocoded location */
$found_cache = get_option( $cached_address );
$found_cache = get_transient( $cached_address );

if ( $found_cache ) {
if ( $found_cache !== false ) {
$location = $found_cache;
} else {
// try geocoding
Expand All @@ -54,12 +54,8 @@ public function __construct ($address) {
$location = (Object) $this->$geocoding_method( $address );

/* add location */
add_option($cached_address, $location);
set_transient( $cached_address, $location, DAY_IN_SECONDS );

/* add option key to locations for clean up purposes */
$locations = get_option('leaflet_geocoded_locations', array());
array_push($locations, $cached_address);
update_option('leaflet_geocoded_locations', $locations);
} catch (Exception $e) {
// failed
$location = $this->not_found;
Expand All @@ -76,11 +72,14 @@ public function __construct ($address) {
* Removes location caches
*/
public static function remove_caches () {
$addresses = get_option('leaflet_geocoded_locations', array());
foreach ($addresses as $address) {
delete_option($address);
}
delete_option('leaflet_geocoded_locations');
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$query = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s)", '\_transient\_leaflet\_%' ) );
if ( $query ) {
foreach ( $query as $option_name ) {
delete_transient( str_replace( '_transient_', '', $option_name ) );
}
}
}

/**
Expand Down Expand Up @@ -137,21 +136,21 @@ private function google_geocode ( $address ) {
// Leaflet_Map_Plugin_Settings
$settings = Leaflet_Map_Plugin_Settings::init();
$key = $settings->get('google_appkey');

$geocode_url = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s';
$geocode_url = sprintf($geocode_url, $address, $key);

$json = $this->get_url($geocode_url);
$json = json_decode($json);

/* found location */
if ($json->status == 'OK') {

$location = $json->results[0]->geometry->location;

return (Object) $location;
}

throw new Exception('No Address Found');
}

Expand Down Expand Up @@ -180,7 +179,7 @@ private function osm_geocode ( $address ) {

/**
* TODO: does this still work?
* Danish Addresses Web Application
* Danish Addresses Web Application
* (https://dawa.aws.dk)
*
* @param string $address the urlencoded address to look up
Expand All @@ -191,11 +190,11 @@ private function dawa_geocode ( $address ) {
$geocode_url .= $address;
$json = $this->get_url($geocode_url);
$json = json_decode($json);

/* found location */
return (Object) array(
'lat' => $json[0]->adgangsadresse->adgangspunkt->koordinater[1],
'lng' => $json[0]->adgangsadresse->adgangspunkt->koordinater[0]
);
}
}
}
20 changes: 15 additions & 5 deletions templates/shortcode-helper.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* Shortcode Helper Page
*
*
* PHP Version 5.5
*
*
* @category Admin
* @author Benjamin J DeLong <ben@bozdoz.com>
*/
Expand All @@ -19,7 +19,7 @@
}
}

/* wordpress messes up video tags */
/* wordpress messes up video tags */
video {
max-width: inherit;
}
Expand Down Expand Up @@ -143,12 +143,22 @@
echo '<div class="list-item">';
echo "<h3>$title</h3>";
foreach ($collection as $shortcode) {
echo do_shortcode($shortcode);
$sc_search = array(
'leaflet-map ',
'leaflet-image ',
'leaflet-wms ',
);
$replace = array(
'leaflet-map height=250 ',
'leaflet-image height=250 ',
'leaflet-wms height=250 ',

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not be the best way to do this, but I guess it works. I would have thought we could set height via css and make the css "!important".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we could set height via css and make the css "!important".

Thank you for hint.

);
echo do_shortcode( str_replace( $sc_search, $replace, $shortcode ) );
echo "<p>$shortcode</p>";
}
echo '</div>';
}
?>
?>
</div>
</div>
</div>
Expand Down