Coding standards
Security in ResourceSpace
Developer reference
- Project structure
- Database schema
- Fixed list fields
- Debugging ResourceSpace
- Writing your own plugins
- Context help links
- Custom fields ("user" defined)
- Query caching
- All user permissions
- Client side API calls
- Modals
- Sending user notifications
- Progressive Web App
- Managing (PHP) code dependencies
- Managing (JS) code dependencies
- OpenAPI documentation
- Automated Testing
Database
- Table: activity_log
- Table: annotation
- Table: annotation_node
- Table: api_log
- Table: collection
- Table: collection_keyword
- Table: collection_log
- Table: collection_resource
- Table: collection_savedsearch
- Table: comment
- Table: daily_stat
- Table: dash_tile
- Table: dynamic_tree_node
- Table: external_access_keys
- Table: filter
- Table: filter_rule
- Table: filter_rule_node
- Table: ip_lockout
- Table: job_queue
- Table: keyword
- Table: keyword_related
- Table: mail_log
- Table: message
- Table: node
- Table: node_keyword
- Table: plugins
- Table: preview_size
- Table: report
- Table: report_periodic_emails
- Table: report_periodic_emails_unsubscribe
- Table: request
- Table: research_request
- Table: resource
- Table: resource_alt_files
- Table: resource_custom_access
- Table: resource_dimensions
- Table: resource_keyword
- Table: resource_log
- Table: resource_node
- Table: resource_related
- Table: resource_type
- Table: resource_type_field
- Table: resource_type_field_resource_type
- Table: search_log
- Table: site_text
- Table: slideshow
- Table: sysvars
- Table: tab
- Table: user
- Table: user_collection
- Table: user_dash_tile
- Table: user_message
- Table: user_preferences
- Table: user_rating
- Table: user_report
- Table: user_userlist
- Table: usergroup
- Table: usergroup_collection
- Table: usergroup_dash_tile
User api session functions
Geolocation functions
geo_setcoords_from_country()
Description
Fill missing resource geolocation using the country metadata field.Parameters
| Column | Type | Default | Description |
|---|---|---|---|
| $output_newline | string | Line separator for CLI or HTML progress output. | |
| [] | |||
| 'schema'; |
Return
| void |
Location
include/geolocation_functions.php lines 9 to 48
Definition
function geo_setcoords_from_country(string $output_newline = PHP_EOL): void
{
$country_field = ps_query("SELECT ref FROM resource_type_field WHERE name='country'", [], 'schema');
if (count($country_field) === 0 || $country_field[0]['ref'] === '') {
echo " - Country field not found. Must have a field with shorthand name set to 'country'." . $output_newline;
return;
}
$resource_countries = ps_query(
'SELECT DISTINCT rn.resource, UPPER(n.name) name
FROM resource_node rn
JOIN node n ON n.ref=rn.node
JOIN resource r ON r.ref=rn.resource
WHERE n.resource_type_field=? AND (r.geo_lat IS NULL OR r.geo_long IS NULL)',
['i', $country_field[0]['ref']]
);
// Retain one country per resource, as before, without sorting every resource.
$resource_names = array_column($resource_countries, 'name', 'resource');
unset($resource_countries);
$countries = [];
foreach ($resource_names as $ref => $country) {
if ($country !== '') {
$countries[$country][] = $ref;
}
}
unset($resource_names);
$codes = build_codes();
$coords = build_coords();
foreach ($countries as $country => $refs) {
$latlong = fetch_country_coords($country, $codes, $coords);
update_country_coords($refs, $latlong);
echo escape(' - Country=' . $country . '; Resources=' . count($refs)
. (count($latlong) === 2 ? '' : '; coordinates not found')) . $output_newline;
if (PHP_SAPI === 'cli') {
if (ob_get_level() > 0) {
ob_flush();
}
flush();
}
}
}
This article was last updated 11th November 2026 19:05 Europe/London time based on the source file dated 11th November 2026 14:55 Europe/London time.