API - Custom Code/Plugin

Previous Next

The version 1.3 and above would support custom plugins and hooks. You can implement custom plugins or code by using the filter hook functionality. The data would be first passed by reference through your custom function.

So your function can change it or completely create new data. Multiple functions can be registered for the same hook and they will be executed one after another i.e. in the order they were registered and returned data will be passed by reference on to another registered function. The function should return the data in same format as it was passed. For ex, if string was passed to your custom function handler then string should be returned after necessary modification. If your custom function doesn't return the data, then code ahead of it may not work as it was supposed to.


Your custom plugin/code should be in plugins/Custom-Folder/default.php and it will be automatically loaded by the script.


Here Custom-Folder is the folder name of your custom plugin/code. In order to hook into one of the functions, you should first register it.


Register a function to a hook:


@param hook_name (String) The name of the hook to which custom function would be registered

@param handler (String) function name. Custom function through which the data would be passed and returned for further processing.


register_plugin(hook_name, handler);


for ex:

register_plugin("searchResults","searchFunction");


De-register a function from a hook:


@param hook_name (String) The name of the hook to which custom function which was registered earlier would be de-registered

@param handler (String) function name. Custom function name which was registered with this hook earlier.


deregister_plugin(hook_name, handler);


for ex:

deregister_plugin("searchResults","searchFunction");


Add a member menu:


@param $menu_name (String) Name of the menu to be shown in the left sidebar.

@param $handler (String) The custom function that would output/print the custom data  when $menu_name is clicked.

@param $member_level (int) The member level to which this menu should be accessible. 9 is for admin and 1 is for all other users.


add_member_menu($menu_name,$handler,$member_level);

for ex, add_member_menu("Menu Name","Handler",1);


function Handler(){

print "Here goes the content for my custom page. This can be a form too.";

}

Currently the following hooks are supported:


searchResults : This hook is related to the text home page search results. Registering your custom function to this hook would enable you to update its look n feel or format. Entire data shown is first passed through all the custom functions registered with this hook.


Parameter passed to the custom function: String by reference, &$vargs where $vargs contains the complete html data of the current page of the listings on text home page.


Register with this hook:


register_plugin("searchResults","searchFunction");


For ex, the following registered custom function would change the word 'alert-success' with 'alert-info', which happens to be a class name, in the data and return the updated data for printing or to another registered function.


function searchFunction(&$sargs){

   $sargs=str_replace('alert-success', 'alert-info', $sargs);

   return $sargs;

}


searchResultsRecords : The hook passes the search record arrays to the registered functions. The registered functions can do modification to the data and return the modified array.


Parameter passed to the custom function: Listing Array by reference, &$vargs.


Register with this hook:


register_plugin("searchResultsRecords","searchRecordsFunction");



viewFullListing: Functions registered with this hook are executed when full listing is shown.


Register with this hook:


register_plugin("viewFullListing","viewFunction");


function viewFunction(&$vargs){

   $vargs[0]=str_replace("Description", "Information", $vargs[0]);

   return $vargs;

}


Parameter passed to the custom function: Array by reference, &$vargs

$vargs[0] is the complete html listing.

$vargs[1] is the record array fetched directly from the database for a listing.


You can access them like this: $vargs[1]['id'] , $vargs[1]['user_id'] and so on. Please refer to the schema of database table 'listing' for column names.


addListingForm: Functions registered with this hook are executed when add listing form is shown.


Parameter passed to the custom function: String by reference, &$vargs where $vargs contains the complete html data of the 'Add listing' form.


allMarkers: The hook passes the Array of markers, as per the search criteria set in the search form, to your custom function.


Parameter passed to the custom function: Array by reference, &$vargs where $vargs contains all the markers for the listings that match the search criteria set in the search form.


Sample Array of 2 records that is passed to your custom function:


Array

(

   [0] => Array

       (

           [la] => 30.3644

           [lo] => 76.3866

       )


   [1] => Array

       (

           [la] => 43.5877

           [lo] => -79.6213

       )


)


Here 'la' is latitude and 'lo' is the longitude. The format of the returned array should be similar to the above one. This hook is useful is you want to append some extra records to the existing records.


markerRecord:  The hook passes the Array of marker data identified by a latitude and longitude.


Parameter passed to the custom function: Array by reference, &$vargs where $vargs contains the marker data of a listing/s related to a give latitude and longitude.


Sample Array that is passed to your custom function:


Array ( [0] => Array ( [id] => 5002 [user_id] => 1 [subcategory] => Commercial [price] => 0 [city] => Mississauga [state] => ON [country] => Canada [description] => This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline.This is a test headline. [relistingby] => owner [listing_by_other] => [contact_name] => Ravi [contact_phone] => [contact_email] => test@finethemes.com [contact_website] => [contact_address] => [show_image] => yes [pictures] => [ip] => [dttm] => 2013-04-08 10:45:41 [dttm_modified] => 2013-04-08 10:45:41 [address] => 171 Mississauga Valley Blvd. [postal] => [category] => Housing [headline] => This is a test headline.This is a test headline.This is a test headline. [useremail] => [permanent] => 0 [latitude] => 43.5877 [longitude] => -79.6213 [listing_type] => 1 [listing_expire] => [featured_till] => 0000-00-00 00:00:00 ) ) ""



getMarkerInfo: Functions registered with this hook are executed when marker balloon is shown after a marker on map is clicked.


Parameter passed to the custom function: String by reference, &$vargs where $vargs contains the complete html data that would be shown inside the marker balloon.


Register with this hook:


register_plugin("getMarkerInfo","markerFunction");


Following example handler function replaces  'More Info' with 'Extra Information'. You can also use preg_replace or other functions to do much more:


function markerFunction(&$vargs){

   $vargs=str_replace('More Info', 'Extra Information', $vargs);

   return $vargs;

}



sidebarTextResults: Functions registered with this hook are executed when text results in the map sidebar are loaded.


Register with this hook:


register_plugin("sidebarTextResults","sidebarFunction");


function sidebarFunction(&$sargs){

   $sargs=str_replace('Price', '<b>Value</b>', $sargs);

   return $sargs;

}


Parameter passed to the custom function: String by reference, &$sargs

$sargs is the complete text data shown in the map sidebar.



sitefooter: Functions registered with this hook are executed when footer is being rendered.


Parameter passed to the custom function: String by reference, &$vargs where $vargs contains the complete html data of the footer.


Register with this hook:


register_plugin("sitefooter","footerFunction");

Created with the Personal Edition of HelpNDoc: Write eBooks for the Kindle