Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Developer's Guide

ReversedK edited this page Aug 16, 2016 · 1 revision

The Addon Helper Class

The Addon Helper Class is essentially a wrapper designed to facilitate greatly the development of addons. It contains all the methods you need to add new filters, post type, markers, map layout and more.Just call the methods,the Addon Helper does the work for you.

Magic methods

Locate_Anything_Addon_Helper::define_custom_tags($arr_tags,$scope,$getDataCallbackFn,$addon_name)

Description : LocateAnything tags are pseudo-shortcodes of the form : |nameOfTag| , ex : |MyAddon_field_animal_owned|
They are used in the navlist and tooltip template editors. They symbolize a piece of data and will be substituted by their value at runtime.

This method allows you to define new custom tags.

Args :
[array] $arr_tags : array of tags. Form expected: $arr_tags = array(field name => Tagname);
[string] $scope : The scope of the filters : a post type, "user" or "all" [string] $getDataCallbackFn : callback function name, gets the datas for passed field and marker ID [string] $addon_name : Addon name, no space or special char

Example : This will create a tag |Animal_owned| for the field MyAddon_animal_owned . The new tag appears in the backoffice, in the "Tooltips & Navlist" tab. You can now, if you want to, define a filter on that tag using Locate_Anything_Addon_Helper::define_filters

$tags = array ('MyAddon_field_animal_owned'=>sanitize_key('Animal owned');
Locate_Anything_Addon_Helper::define_custom_tags($tags,'all',$getDataCallbackFn,$addon_name)

Example of callback function : This function fetches the data from various external functions( 'get_bogus_user_data' and 'get_status') and returns the appropriate field

    public static function get_vars($field,$id){
        if($field=='MyAddon_status') $r = get_status($id); 
       else {
            $p=get_bogus_user_data($id);    // returns array('Animal_owned'=>'cat','eye_color'=>'blue','age'=>22)               
        $r = $p[$field];    
            }
         return $r;     
    }

Locate_Anything_Addon_Helper::define_filters($arr_filters,$scope,$getDataCallbackFn,$addon_name)

Description : LocateAnything in its core version allows you to use any taxonomy as a filter.
In case you need to search on something else than taxonomies like, for example a custom field or a LocateAnything tag, this method allows you to define new filters.

Args :
[array] $arr_filters : array of filters. Form expected: $arr_filters = array(field name => array( 'name'=> filter caption,'values'=>array(field values)));
[string] $scope : The scope of the filters : a post type, "user" or "all"
[string] $getDataCallbackFn : callback function name, gets the datas for passed field and marker ID
[string] $addon_name : Addon name, no space or special char

Example : This will create a filter for the custom field MyAddon_animal_owned with the values 'cat','dog' and bird'. The new filter appears in the backoffice, in the "Filters" tab. Just tick its checkbox to activate it.

$filters = array ('MyAddon_field_animal_owned'=>array( 'name' =>'Animal owned','values'=>array('cat','dog','bird'));
Locate_Anything_Addon_Helper::define_filters($filters,'all',$getDataCallbackFn,$addon_name)

Asset Methods

Asset methods are used to add new assets : new overlays, marker icons, map layout, navlist or tooltip preset, etc...

Locate_Anything_Addon_Helper::add_overlays($addon_name, $overlays)

Description : Add overlays to the overlay list shown in General settings tab
Args :
[string] $addon_name : Addon name, no space or special char
[array] $overlays [array of overlay objects]

Overlay Object example :

    $overlays[]=(object) array(  
     "name"=> ‘Esri World Street Map’,  
     "url"=>’http://mymapURL.Com/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}’,  
     "attribution"=> ‘Tiles © EsriSource: My map attribution, 2012’,  
     "maxZoom"=>20,  
     "minZoom"=>2,  
     "zoom"=>10);

Locate_Anything_Addon_Helper::add_marker_icons($addon_name, $markers)

Description : Add marker icons to the  list shown in the Marker tab
Args :
[string] $addon_name : Addon name, no space or special char
[array] $markers [array of marker icon objects]

Marker Object example :

$markers[ ]=(object) array(
"url"=>plugin_dir_url(__FILE__).’/markers/marker-img.png’,
"width"=>’48’,
"height"=>’48’,
"shadowUrl"=>plugin_dir_url(__FILE__).’/markers/marker-shadow.png’,
"shadowWidth"=> ’48’,
"shadowHeight"=>’48’);

Locate_Anything_Addon_Helper::add_map_layouts($addon_name, $layouts)

Description : Add layouts to the  list shown in the Map Layouts tab
Args :
[string] $addon_name : Addon name, no space or special char [array] $layouts [array of map layout objects]

Map Layout Object example :

$layouts[ ]=(object) array("url"=>dirname(__FILE__).’/layout/layout.php’,"name"=>’Best Layout Ever’);

Locate_Anything_Addon_Helper::add_tooltip_presets($addon_name, $presets)

Description :

Add Tooltip presets.
Tooltip presets are used in the tooltip that pops up when a marker is selected.
They contain a CSS class, a name and a HTML template that can contain LocateAnything tags.

Args : [string] $addon_name : Addon name, no space or special char
[array] $presets [array of preset objects]

Tooltip Preset Object example :

    $preset = (object)array("class"=>'nice-tooltips',"name"=>'Nice Tooltips',"template"=>"|small_thumbnail|
<p>|content_stripped|</p>");  

Locate_Anything_Addon_Helper::add_navlist_presets($addon_name, $presets)

Description :

Add Navlist presets.
Navlist presets are used in the navigation list linked to the map.
Like the tooltip presets they contain a CSS class, a name and a HTML template that can contain LocateAnything tags.

Args : [string] $addon_name : Addon name, no space or special char
[array] $presets [array of preset objects]

Tooltip Preset Object example :

    $preset = (object)array("class"=>'nice-tooltips',"name"=>'Nice Tooltips',"template"=>"|small_thumbnail|
<p>|content_stripped|</p>");  

Locate_Anything_Addon_Helper::add_option_pane($fn,$addon_name)

[string] $addon_name : Addon name, no space or special char
[string] $fn : the name of the static method used to generate the option pane HTML code

Description : Adds an option pane to the Option page. Note : option names must be of the following form : "locate-anything-option-"+your addon identifier+"-"+option name. (ex : locate-anything-option-buddypress-xcpfield12)

Example

public static function get_option_pane_html(){		
	$fields = array('My animal'=>'myAddon_animal_owned',...);
        $html="<table>";
	foreach ($fields as $name => $field) {		
		$input = "<input type='text' name ='locate-anything-option-myAddon-$field' value = '$val'>";			
		$html.="<tr>";
		$html.="<td>".$name."</td>";
		$html.="<td>".$input."</td>";
		$html.="</tr>";
	}
	$html.="</table>";
	return $html;
}