Addon Documentation

From Open-Realty Wiki

Jump to: navigation, search
Add-on System Specifications Version 1 for Open-Realty 2.0

Description: The purpose of this specification is to make a module system that auto-loads any add-ons.

Addons are very powerful modules for Open-Realty 2.0 that will allow most user modifications to be put into an Addon format instead of having to edit the Core code of Open-Realty. This will make upgrading to future versions of Open-Realty much easier for the site developers and prevent users from ending up with an unsupported version of Open-Realty due to code modifications.

All add-ons should have an addon.inc.php file. - This file is the core of the add-on system. It is what Open-Realty will look for to setup and integrate the module. There will be the following defined functions.

Download the sample Framework Addon to use as an example of a correctly formatted Addon.

Contents

Important Information

Javascript

As of Open-Realty 2.1 Addons can now load javascript into the template using two new global variables. Addons should add any javascirpt they want to load to the global variables making sure to include the <script> </script> tags around their javascript. The new variables are:

    1: $jscript   Javascript added to this global variable will be loaded into the main template in place of the "{load_js}" template tag.
    2: $jscript_last   Javascript added to this global varible will be loaded into the main template in place of the "{load_js_last}" template tag.

You must use $jscript .= XXX so the main OR javascript is not over written with your code. You MUST define the variable as a global variable in your function(s). You would use these variables in your addon specific function(s).

Search Results

If creating an addon that will be used on the search results page and you would like to get the listing_ids for the listings in the search results you can use one of these bits of code:

    1: $matched_listing_ids = search_page::search_results(true);   returns the listing_ids for all of the listings in the search results
    2: $matched_listing_ids = search_page::search_results(perpage);   returns the listing_ids for the search results with pagination (only the ones displayed on that page of the search results)


Addon Functions

All addon functions should be prefixed with the addon name. This prefix name should match the addon folder name, and is represented below by name_.

name_install_addon()

This function should add new database tables and data or modify existing tables and data when necessary. This should be used to store the version number of your addon in the addons table and compare the addon version to the previously installed version, if any and determine if an installation or an update is needed and then carry out any required database modifications. Here is an example of a proper name_install_addon function:

function name_install_addon()
{
$current_version = "1";
global $conn, $config;
require_once($config['basepath'].'/include/misc.inc.php');
$misc = new Misc();
//Check Current Installed Version
$sql = 'SELECT addons_version FROM '.$config['table_prefix_no_lang'].'addons WHERE addons_name = \'name\;
$recordSet = $conn->Execute($sql);
$version = $recordSet->fields[0];
if ($version == ) 
{
// Preform a new install. Create any needed databases etc, and insert version number into addon table.
$sql = 'INSERT INTO '.$config['table_prefix_no_lang'].'addons (addons_version, addons_name) VALUES (\'1\',\'name\')';
$recordSet = $conn->Execute($sql);
return TRUE; 
}
elseif ($version != $current_version)
{
//Preform Updates to database based on previous installed version.
switch($version)
{
case '0';
break;
} // switch
return TRUE;
}
return FALSE;
}

name_show_admin_icons()

This function should return an array of the html links that should be shown on the administrative page. You can post as simple as a text name of your addon to show users what's installed, or a link to an administrative page of your addon. You can display a link using something like this: index.php?action=name_addonname_admin You will need to define the action "name_addonname_admin" in "name_run_action_admin_template" to define it as a $_GET[] action for the admin page. Here is an example of a proper name_show_admin_icons function:

function name_show_admin_icons()
{
$admin_link = '<a href="index.php?action=addon_name_admin">name</a>';
return $admin_link;
} 

name_load_template()

This should return an array with all the template tags for open-realty's template engine to parse. If you don't define your template tags for the addon here they won't be parsed by the template system and properly displayed. The actual replacement of the tags that are defined here is done by the function name_run_template_user_fields Here is an example of a proper name_load_template function:

function name_load_template()
{
$template_array = array('addon_name_link');
return $template_array;
} 

name_run_action_user_template()

This function handles the addon's $_GET[] actions for the USER pages. Each get action should have the function to be called defined. The Function must be named using this method: addon_name_description. Here is an example of proper code for this function:

function name_run_action_user_template()
{
switch ($_GET['action']) {
case 'addon_name_showpage1':
$data = name_display_addon_page();
break;
default:
$data = ;
break;
} // End switch ($_GET['action'])
return $data;
}

name_run_action_admin_template()

This function handles the addon's $_GET[] actions for the ADMIN pages. Each get action should have the function to be called defined. The Function must be named using this method: addon_name_description. Here is an example of proper code for this function:

function name_run_action_admin_template()
{
switch ($_GET['action']) {
case 'addon_name_admin':
$data = name_display_admin_page();
break;
default:
$data = ;
break;
} // End switch ($_GET['action'])
return $data;
}

name_run_template_user_fields()

This function handles all the replacement of {addon_name_template_tags} with the actual content. The tag replacement can call any function that already exists in Open-Realty or you can create your own ADDON Specific functions. All tags setup here must also be added to the name_load_template function in order for open-realty to parse them. Here is an example of proper code for this function:

function name_run_template_user_fields($tag = )
{
switch ($tag) {
case 'addon_name_link':
$data = name_display_addon_link();
break;
default:
$data = ;
break;
} // End switch ($_GET['action'])
return $data;
}


Addon Specific Functions

Addon specific functions are functions that are created specifically for the addon's use. An example of this would be if a user wanted to create an addon for a customized Featured Listing layout then the user can write their own Featured listing display function and have it called by the template tag {addon_superniftyfeaturedlisting_display} Using all of the above examples of properly formatted addon functions you would be calling the following Addon Specific Functions:

// Addon Specific Function
function name_display_addon_link()
{
$display = '<a href="index.php?action=addon_name_showpage1">name Test</a>';
return $display;
} 
// Addon Specific Function
function name_display_addon_page()
{
$display = 'This is a Addon page';
return $display;
} 
// Addon Specific Function
function name_display_admin_page()
{
$display = 'This is a Addon page';
return $display;
} 

All of these functions have been rolled into a sample addon called "Framework". You can download the sample Framework Addon to use as an example or starting point for making your own addons.

Download the sample Framework Addon to use as an example of a correctly formatted Addon.

Personal tools