Home « Server software «
Documentation: locations/locations.php
Class Locations - The database abstraction layer for locations
Locations are geographical coordinates.Look at
list_by_distance() for the selection of locations based on relative distances.
Thanks to Eoin for having provided the adequate formula.This script is a reference file of this system.
Licence: GNU Lesser General Public License
Auteurs:
- Bernard Paques bernard.paques@bigfoot.com
- Eoin
- Florent
delete() - Delete one location in the database and in the file system
function delete($id)
- $id - the id of the location to delete
- returns an error message, if any
Voir aussi:
delete_for_anchor() - Delete all locations for a given anchor
function delete_for_anchor($anchor)
- $anchor - the anchor to check
- returns an error message, if any
Voir aussi:
get() - Get one location by id
function &get($id)
- $id - int the id of the location
- returns the resulting $item array, with at least keys: 'id', 'geo_place_name', etc.
Voir aussi:
get_url() - Get the url to view a location
function get_url($id, $action='view')
- $id - int the id of the location to view
- $action='view' - string the expected action ('view', 'edit', 'delete', ...)
- returns an anchor to the viewing script
locations/view.php?id=512'),
which may be not processed correctly by search engines.
If the parameter 'with_friendly_urls' has been set to 'Y' in the configuration panel,
this function will return an URL parsable by search engines (e.g. 'locations/view.php/512').Voir aussi:
- articles/article.php
- codes/codes.php
- control/configure.php
- locations/check.php
- locations/edit.php
- locations/view.php
- skins/skin_skeleton.php
- users/user.php
list_by_date() - List newest locations
function &list_by_date($offset=0, $count=10, $variant='full')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=10 - int the number of items to display
- $variant='full' - string the list variant, if any
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
// side bar with the list of most recent locations
include_once 'locations/locations.php';
$local['title_en'] = 'Most recent locations';
$local['title_fr'] = 'Emplacements récents';
$title = i18n::user('title');
$items = Locations::list_by_date(0, 10, '');
$text = Skin::build_list($items, 'compact');
$context['text'] .= Skin::build_box($title, $text, 'navigation');
You can also display the newest location separately, using
Locations::get_newest()
In this case, skip the very first location in the list by using
Locations::list_by_date(1, 10, '')Voir aussi:
list_by_date_for_anchor() - List newest locations for one anchor
function &list_by_date_for_anchor($anchor, $offset=0, $count=20, $variant=NULL, $capability='?')
- $anchor - string the anchor (e.g., 'article:123')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=20 - int the number of items to display
- $variant=NULL - string the list variant, if any
- $capability='?' - string actual surfer capability ('?', 'M', or 'A') -- see articles/edit.php
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
Voir aussi:
list_by_date_for_author() - List newest locations for one author
function &list_by_date_for_author($author_id, $offset=0, $count=20, $variant='date')
- $author_id - int the id of the author of the location
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=20 - int the number of items to display
- $variant='date' - string the list variant, if any
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
list_by_distance() - List nearest locations to one point
function &list_by_distance($latitude, $longitude, $offset=0, $count=20, $variant='compact')
- $latitude - float latitude of the target point
- $longitude - float longitude of the target point
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=20 - int the number of items to display
- $variant='compact' - string the list variant, if any
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
Voir aussi:
list_by_distance_for_anchor() - List nearest locations to one anchor
function list_by_distance_for_anchor($anchor, $offset=0, $count=20, $variant='compact')
- $anchor - string a reference to the target anchor (eg, 'article:123')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=20 - int the number of items to display
- $variant='compact' - string the list variant, if any
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
list_by_distance(),
except that it looks for a location for the given anchor first.Voir aussi:
list_selected() - List selected locations
function &list_selected(&$result, $layout='compact', $capability='?')
- &$result - resource result of database query
- $layout='compact' - string 'full', etc or object, i.e., an instance of Layout_Interface
- $capability='?' - string '?' or 'A', to support editors and to impersonate associates, where applicable
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
- 'compact' - to build short lists in boxes and sidebars (this is the default)
- 'no_anchor' - to build detailed lists in an anchor page
- 'full' - include anchor information
post() - Post a new location or an updated location
function post($fields)
- $fields - array an array of fields
- returns string either a null string, or some text describing an error to be inserted into the html response
Voir aussi:
setup() - Create or alter tables for locations
function setup()
Voir aussi:
stat() - Get some statistics
function &stat()
- returns the resulting ($count, $min_date, $max_date) array
Voir aussi:
stat_for_anchor() - Get some statistics for one anchor
function &stat_for_anchor($anchor)
- $anchor - the selected anchor (e.g., 'article:12')
- returns the resulting ($count, $min_date, $max_date) array