Skip to content

Commit

Permalink
Add {field:map_url} tag to output a link to the address on one of sev…
Browse files Browse the repository at this point in the history
…eral mapping services.
  • Loading branch information
elivz committed Apr 6, 2012
1 parent e922ec1 commit 2511652
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Will output the complete address, in a standard format. Use the `style=""` attri
{address_field:country [code="yes"]}

Output particular pieces of the address. If you use the parameter `code="yes"` on the country tag, you will get the the international country code rather than the full name.

{address_field:map_url [source="google|yahoo|bing|mapquest"] [params=""]}

Output a URL to the address on any one of a variety of mapping services. Specify which service you want to use with the `source` parameter (Google Maps is the default). Anything you put in the `params` parameter will be added to the end of the map URL, use it to specify zoom levels, map types, etc.

### Tag Pair ###

Expand Down
67 changes: 55 additions & 12 deletions vz_address/ft.vz_address.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Vz_address_ft extends EE_Fieldtype {

public $info = array(
'name' => 'VZ Address',
'version' => '1.2.1',
'version' => '1.3.0',
);

public $has_array_data = TRUE;
Expand Down Expand Up @@ -399,17 +399,6 @@ function replace_tag($address, $params=array(), $tagdata=FALSE)

return $output;
}

/**
* Display Low Variables tag
*/
function display_var_tag($var_data, $tagparams, $tagdata)
{
$data = htmlspecialchars_decode($var_data);
$decoded = (array) json_decode($data);
$data = $decoded ? $decoded : unserialize($data);
return $this->replace_tag($data, $tagparams, $tagdata);
}

/*
* Individual address pieces
Expand Down Expand Up @@ -449,6 +438,60 @@ function replace_country($address, $params=array(), $tagdata=FALSE)
return $this->EE->lang->line($address['country']);
}
}

/*
* Check if the address is empty
*/
function replace_is_empty($address, $params=array(), $tagdata=FALSE)
{
$address = array_merge($this->fields, $address);
return $address == $this->fields ? 'y' : '';
}

function replace_is_not_empty($address, $params=array(), $tagdata=FALSE)
{
$address = array_merge($this->fields, $address);
return $address == $this->fields ? '' : 'y';
}

/*
* Output a URL to the address in one of several mapping websites
*/
function replace_map_url($address, $params=array(), $tagdata=FALSE)
{
$source = isset($params['source']) ? strtolower($params['source']) : 'google';
$params = isset($params['params']) ? '&' . strtolower($params['params']) : '';

// Create the url-encoded address
if (isset($address['name'])) unset($address['name']);
$query = urlencode(implode(', ', array_filter($address)));

switch ($source)
{
case 'yahoo':
$output = "http://maps.yahoo.com/#q={$query}{$params}";
case 'bing':
$output = "http://www.bing.com/maps/?v=2&where1={$query}{$params}";
case 'mapquest':
$output = "http://mapq.st/map?q={$query}{$params}";
case 'google': default:
$output = "http://maps.google.com/maps?q={$query}{$params}";
break;
}

return $output;
}

/**
* Display Low Variables tag
*/
function display_var_tag($var_data, $tagparams, $tagdata)
{
$data = htmlspecialchars_decode($var_data);
$decoded = (array) json_decode($data);
$data = $decoded ? $decoded : unserialize($data);
return $this->replace_tag($data, $tagparams, $tagdata);
}
}

/* End of file ft.vz_address.php */

0 comments on commit 2511652

Please sign in to comment.