\GeoMashupDB

Static class to provide a namespace for Geo Mashup data functions.

Summary

Methods
Properties
Constants
init()
add_geodata_sync_hooks()
remove_geodata_sync_hooks()
action_added_post_meta()
action_added_user_meta()
action_added_comment_meta()
filter_update_post_metadata()
filter_update_user_metadata()
filter_update_comment_metadata()
copy_to_geodata()
installed_version()
object_storage()
table_to_object_name()
join_post_queries()
query_vars()
parse_query()
posts_fields()
posts_join()
posts_where()
activation_log()
install()
get_administrative_name()
primary_language_code()
geocode()
are_any_location_fields_empty()
bulk_reverse_geocode()
cache_administrative_name()
duplicate_geodata()
blank_location()
blank_object_location()
get_distinct_located_values()
get_post_location()
get_object_location()
get_location()
get_post_locations()
get_object_locations()
wpml_filter_get_translatable_documents()
set_object_location()
set_location()
delete_object_location()
delete_location()
get_saved_locations()
category_located_post_count()
get_comment_in()
get_user_in()
delete_post()
delete_comment()
delete_user()
post_meta_key_suggest()
$geocode_error
No constants found
No protected methods found
No protected properties found
N/A
copy_from_geodata()
set_installed_version()
query_extension()
get_cached_administrative_name()
fill_empty_location_fields()
reverse_geocode_location()
make_alternate_reverse_geocoder()
duplicate_geodata_type()
convert_prior_locations()
translate_object()
get_located_categories()
$installed_version
$copied_to_geodata
$geodata_keys
N/A

Properties

$geocode_error

$geocode_error : \WP_Error

The last geocode error, or empty if no error.

Type

\WP_Error

$installed_version

$installed_version : string

Current installed database version.

Type

string

$copied_to_geodata

$copied_to_geodata : array

Flag for objects that have geodata fields copied to.

Key $meta_type-$object_id, value true.

Type

array

$geodata_keys

$geodata_keys : array

Meta keys used to store geodata

Type

array

Methods

init()

init()

WordPress action to set up data-related WordPress hooks.

add_geodata_sync_hooks()

add_geodata_sync_hooks()

Add hooks to synchronize Geo Mashup ojbect locations with WordPress geodata.

remove_geodata_sync_hooks()

remove_geodata_sync_hooks()

Remove hooks to synchronize Geo Mashup ojbect locations with WordPress geodata.

action_added_post_meta()

action_added_post_meta( $meta_id,  $post_id,  $meta_key,  $meta_value)

WordPress action to update Geo Mashup post location when geodata custom fields are updated.

Parameters

$meta_id
$post_id
$meta_key
$meta_value

action_added_user_meta()

action_added_user_meta( $meta_id,  $user_id,  $meta_key,  $meta_value)

WordPress action to update Geo Mashup user location when geodata custom fields are updated.

Parameters

$meta_id
$user_id
$meta_key
$meta_value

action_added_comment_meta()

action_added_comment_meta( $meta_id,  $comment_id,  $meta_key,  $meta_value)

WordPress action to update Geo Mashup comment location when geodata custom fields are updated.

Parameters

$meta_id
$comment_id
$meta_key
$meta_value

filter_update_post_metadata()

filter_update_post_metadata( $ok,  $object_id,  $meta_key,  $meta_value,  $prev_value)

WordPress filter to prevent updates to geodata fields we've already updated.

Parameters

$ok
$object_id
$meta_key
$meta_value
$prev_value

filter_update_user_metadata()

filter_update_user_metadata( $ok,  $object_id,  $meta_key,  $meta_value,  $prev_value)

WordPress filter to prevent updates to geodata fields we've already updated.

Parameters

$ok
$object_id
$meta_key
$meta_value
$prev_value

filter_update_comment_metadata()

filter_update_comment_metadata( $ok,  $object_id,  $meta_key,  $meta_value,  $prev_value)

WordPress filter to prevent updates to geodata fields we've already updated.

Parameters

$ok
$object_id
$meta_key
$meta_value
$prev_value

copy_to_geodata()

copy_to_geodata(string $meta_type, integer $object_id, string $geo_date, integer $location_id)

Update object geodata if needed.

Parameters

string $meta_type

'post','user','comment'

integer $object_id
string $geo_date
integer $location_id

The location to copy from.

installed_version()

installed_version() : string

Get the installed database version.

Returns

string —

The installed database version.

object_storage()

object_storage(string $object_name, array $new_storage) : array|boolean

Get or set storage information for an object name.

Potentially you could add storage information for a new kind of object: GeoMashupDB::object_storage( 'foo', array(

'table' => $wpdb->prefix . 'foos',
'id_column' => 'foo_id',
'label_column' => 'foo_display_name',
'sort' => 'foo_order ASC' )

); Would add the necessary information for a custom table of foo objects. By convention the object name is the singular form of the table name without a prefix.

Parameters

string $object_name

A type of object to be stored, default is 'post', 'user', and 'comment'.

array $new_storage

If provided, adds or replaces the storage information for the object name.

Returns

array|boolean —

The storage information array, or false if not found.

table_to_object_name()

table_to_object_name(string $table) : string

Return a conventional object name given a table name.

Parameters

string $table

Returns

string

join_post_queries()

join_post_queries(boolean $new_value) : boolean

Toggle joining of WordPress queries with Geo Mashup tables.

Use the public wrapper GeoMashup::join_post_queries()

Parameters

boolean $new_value

If provided, replaces the current active state.

Returns

boolean —

The current state.

query_vars()

query_vars( $public_query_vars)

WordPress filter to add Geo Mashup public query variables.

query_vars filter called by Wordpress.

Parameters

$public_query_vars

parse_query()

parse_query( $query)

WordPress action to capture custom orderby field before it is removed.

parse_query action called by WordPress.

Parameters

$query

posts_fields()

posts_fields( $fields,  $query)

WordPress filter to add Geo Mashup fields to WordPress post queries.

posts_fields filter called by WordPress.

Parameters

$fields
$query

posts_join()

posts_join( $join,  $query)

WordPress filter to join Geo Mashup tables to WordPress post queries.

posts_join filter called by WordPress.

Parameters

$join
$query

posts_where()

posts_where( $where,  $query)

WordPress filter to incorporate geo mashup query vars in WordPress post queries.

posts_where filter called by WordPress.

Parameters

$where
$query

activation_log()

activation_log(string $message, boolean $write) : string

Append to the activation log.

Add a message and optionally write the activation log. Needs to be written before the end of the request or it will not be saved.

Parameters

string $message

The message to append.

boolean $write

Whether to save the log.

Returns

string —

The current log.

install()

install()

Install or update Geo Mashup tables.

get_administrative_name()

get_administrative_name(string $country_code, string $admin_code, string $language) : string|null

Try to get a language-sensitive place administrative name.

First look in the names cached in the database, then query geonames.org for it. If a name can't be found for the requested language, a default name is returned, usually in the local language. If nothing can be found, returns NULL.

Parameters

string $country_code

Two-character ISO country code.

string $admin_code

Code for the administrative area within the country, or NULL to get the country name.

string $language

Language code, defaults to the WordPress locale language.

Returns

string|null —

Place name in the appropriate language, or if not available in the default language.

primary_language_code()

primary_language_code(string $language) : string

Trim a locale or browser accepted languages string down to the 2 or 3 character primary language code.

Parameters

string $language

Local or language code string, NULL for blog locale.

Returns

string —

Two (rarely three?) character language code.

geocode()

geocode(mixed $query, array $location, string $language) : boolean

Try to fill in coordinates and other fields of a location from a textual location search.

Multiple geocoding services may be used. Google services are only used if the default map provider is Google.

Parameters

mixed $query

The search string.

array $location

The location array to geocode, modified.

string $language

Returns

boolean —

Whether a lookup succeeded.

are_any_location_fields_empty()

are_any_location_fields_empty(array $location, array $fields) : boolean

Check a location for empty fields.

Parameters

array $location

The location to check.

array $fields

The fields to check.

Returns

boolean —

Whether any of the specified fields are empty.

bulk_reverse_geocode()

bulk_reverse_geocode() : string

Try to reverse-geocode all locations with relevant missing data.

Used by the options page. Tries to comply with the PHP maximum execution time, and delay requests if Google sends a 604.

Returns

string —

An HTML log of the actions performed.

cache_administrative_name()

cache_administrative_name(string $country_code, string $admin_code, string $isolanguage, string $name, string $geoname_id) : integer

Store an administrative name in the database to prevent future web service lookups.

Parameters

string $country_code
string $admin_code
string $isolanguage
string $name
string $geoname_id

Returns

integer —

Rows affected.

duplicate_geodata()

duplicate_geodata() : boolean

Copy missing geo data to and from the standard location (http://codex.wordpress.org/Geodata) for posts, users, and comments.

Returns

boolean —

True if no more orphan locations can be found.

blank_location()

blank_location(string $format) : array|object

Get a blank location.

Used to return object fields too - use blank_object_location for that if desired.

Parameters

string $format

OBJECT or ARRAY_A

Returns

array|object —

Empty location.

blank_object_location()

blank_object_location(string $format) : array|object

Get a blank object location.

Parameters

string $format

OBJECT or ARRAY_A

Returns

array|object —

Empty object location.

get_distinct_located_values()

get_distinct_located_values(string $names, array $where) : array

Get distinct values of one or more object location fields.

Can be used to get a list of countries with locations, for example.

Parameters

string $names

Comma separated table field names.

array $where

Associtive array of conditional field names and values.

Returns

array —

WP_DB query results.

get_post_location()

get_post_location(\id $post_id) : object

Get the location of a post.

Parameters

\id $post_id

Returns

object —

Post location.

get_object_location()

get_object_location(string $object_name, integer $object_id, string $output) : object|array

Get the location of an object.

Parameters

string $object_name

'post', 'user', a GeoMashupDB::object_storage() index.

integer $object_id

Object

string $output

(optional) one of ARRAY_A | ARRAY_N | OBJECT constants. Return an

    associative array (column => value, ...), a numerically indexed array (0 => value, ...)
    or an object ( ->column = value ), respectively.

Returns

object|array —

Result or null if not found.

get_location()

get_location(integer $location_id, string $output) : object|array

Get a location by ID.

Parameters

integer $location_id
string $output

(optional) one of ARRAY_A | ARRAY_N | OBJECT constants. Return an

    associative array (column => value, ...), a numerically indexed array (0 => value, ...)
    or an object ( ->column = value ), respectively.

Returns

object|array —

Result or null if not found.

get_post_locations()

get_post_locations(string $query_args) : array

Get locations of posts.

Parameters

string $query_args

Same as GeoMashupDB::get_object_locations()

Returns

array —

Array of matching rows.

get_object_locations()

get_object_locations(string $query_args) : array

Get locations of objects.

$results = GeoMashupDB::get_object_locations( array(

'object_name' => 'user',
'minlat' => 30,
'maxlat' => 40,
'minlon' => -106,
'maxlat' => -103 )

);

Parameters

string $query_args

Override default args.

Returns

array —

Array of matching rows.

wpml_filter_get_translatable_documents()

wpml_filter_get_translatable_documents( $post_types) : array

Expand the post types returned by WPML for our queries

Parameters

$post_types

Returns

array —

Location enabled post types, flipped so ids are keys as WPML expects

set_object_location()

set_object_location(string $object_name, \id $object_id, \id|array $location, boolean $do_lookups, string $geo_date) : \id|\WP_Error

Save an object location in the database.

Object data is saved in the geo_mashup_location_relationships table, and location data is saved in geo_mashup_locations.

Parameters

string $object_name

'post', 'user', a GeoMashupDB::object_storage() index.

\id $object_id

ID of the object to save the location for.

\id|array $location

If an ID, the location is not modified. If an array of valid location fields,

    the location is added or updated. If empty, the object location is deleted.
boolean $do_lookups

Whether to try looking up missing location information, which can take extra time.

    Default is to use the saved option.
string $geo_date

Optional geo date to associate with the object.

Returns

\id|\WP_Error —

The location ID now assiociated with the object.

set_location()

set_location(array $location, boolean $do_lookups) : \id|\WP_Error

Save a location.

This can create a new location or update an existing one. If a location exists within 5 decimal places of the passed in coordinates, it will be updated. If the saved_name of a different location is given, it will be removed from the other location and saved with this one. Blank fields will not replace existing data.

Parameters

array $location

Location to save, may be modified to match actual saved data.

boolean $do_lookups

Whether to try to look up address information before saving,

    default is to use the saved option.

Returns

\id|\WP_Error —

The location ID saved, or a WordPress error.

delete_object_location()

delete_object_location(string $object_name, \id|array $object_ids) : integer|\WP_Error

Delete an object location or locations.

This removes the association of an object with a location, but does NOT delete the location.

Parameters

string $object_name

'post', 'user', a GeoMashupDB::object_storage() index.

\id|array $object_ids

Object ID or array of IDs to remove the locations of.

Returns

integer|\WP_Error —

Rows affected or WordPress error.

delete_location()

delete_location(\id|array $ids) : integer|\WP_Error

Delete a location or locations.

Parameters

\id|array $ids

Location ID or array of IDs to delete.

Returns

integer|\WP_Error —

Rows affected or Wordpress error.

get_saved_locations()

get_saved_locations() : array|\WP_Error

Get locations with saved names.

Returns

array|\WP_Error —

Array of location rows or WP_Error.

category_located_post_count()

category_located_post_count(\id $category_id) : integer

Get the number of located posts in a category.

Parameters

\id $category_id

Returns

integer

get_comment_in()

get_comment_in( $args) : array

Get multiple comments.

What is the WordPress way? Expect deprecation.

Parameters

$args

Returns

array —

Comments.

get_user_in()

get_user_in( $args) : array

Get multiple users.

Now just a wrapper for get_users().

Parameters

$args

Returns

array —

Users.

delete_post()

delete_post( $id)

When a post is deleted, remove location relationships for it.

delete_post action called by WordPress.

Parameters

$id

delete_comment()

delete_comment( $id)

When a comment is deleted, remove location relationships for it.

delete_comment action called by WordPress.

Parameters

$id

delete_user()

delete_user( $id)

When a user is deleted, remove location relationships for it.

delete_user action called by WordPress.

Parameters

$id

post_meta_key_suggest()

post_meta_key_suggest()

Geo Mashup action to echo post meta keys that match a jQuery suggest query.

copy_from_geodata()

copy_from_geodata( $meta_type,  $meta_id,  $object_id,  $meta_key,  $meta_value)

Create a Geo Mashup object location from WordPress geodata.

Parameters

$meta_type
$meta_id
$object_id
$meta_key
$meta_value

set_installed_version()

set_installed_version(string $new_version)

Set the installed database version.

Parameters

string $new_version

query_extension()

query_extension(\WP_Query $query, string $key, mixed $value) : mixed

Set or get custom data associated with a WP_Query object.

Parameters

\WP_Query $query
string $key

Optional - return all data for the query if missing.

mixed $value

Optional - set or overwrite data for the key if present.

Returns

mixed —

Extension data if present.

get_cached_administrative_name()

get_cached_administrative_name(string $country_code, string $admin_code, string $language) : string|null

Look in the database for a cached administrative name.

Parameters

string $country_code

Two-character ISO country code.

string $admin_code

Code for the administrative area within the country, or NULL to get the country name.

string $language

Language code, defaults to the WordPress locale language.

Returns

string|null —

Place name or NULL.

fill_empty_location_fields()

fill_empty_location_fields(array $primary, array $secondary)

Copy empty fields in one location array from another.

Parameters

array $primary

Location to copy to, modified.

array $secondary

Location to copy from.

reverse_geocode_location()

reverse_geocode_location(array $location, string $language) : boolean

Add missing location fields, and update country and admin codes with authoritative Geonames values.

Parameters

array $location

The location to geocode, modified.

string $language

Optional ISO language code.

Returns

boolean —

Success.

make_alternate_reverse_geocoder()

make_alternate_reverse_geocoder()

duplicate_geodata_type()

duplicate_geodata_type(string $meta_type) : boolean

Copy missing geo data to and from the standard location (http://codex.wordpress.org/Geodata) for a specific object type.

Parameters

string $meta_type

One of the WP meta types, 'post', 'user', 'comment'

Returns

boolean —

True if no more orphan locations can be found.

convert_prior_locations()

convert_prior_locations() : boolean

Convert Geo plugin locations to Geo Mashup format.

Returns

boolean —

True if no more unconverted locations can be found.

translate_object()

translate_object(object $obj, \constant $output) : object|array

Format a query result as an object or array.

Parameters

object $obj

To be formatted.

\constant $output

Format.

Returns

object|array —

Result.

get_located_categories()

get_located_categories() : array

Get categories that contain located objects.

Not sufficient - probably want parent categories.

Returns

array —

Located category id, name, slug, description, and parent id