PHP Developer, PHP Development, Web Site Design and Web Development by Eduardo Marques

Do I really HAVE TO say Google is the best?
» Add-on: How to?
Add-ons are very powerful modules for O-R v.2.x that will allow most user modifications to be put into an add-on format instead of having to edit the core code of O-R. This will make upgrading to future versions of O-R much easier for the site developers and prevent users from ending up with an unsupported version of O-R due to code modifications.

All add-ons must have an addon.inc.php file. This file is the core of the add-on system. It is what O-R will look for to setup and integrate the module. Download the sample Framework Add-on to use as an example of a correctly formatted add-on. There will be the following defined functions:

Add-on Functions:
All add-on functions should be prefixed with the add-on name. This prefix name should match the add-on folder name and is represented below by name_.

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 add-on in the add-ons table and compare the add-on 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;
	}
		
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 add-on to show users what's installed, or a link to an administrative page of your add-on. 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;
	}
		
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 add-on 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;
	}
		
This function handles the add-on'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;
	}
		
This function handles the add-on'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;
	}
		
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;
	}
		
Add-on Specific Functions:
Add-on specific functions are functions that are created specifically for the add-on's use. An example of this would be if a user wanted to create an add-on 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 add-on functions you would be calling the following Add-on Specific Functions:
// Add-on Specific Function
function name_display_addon_link() {
	$display = '<a href="index.php?action=addon_name_showpage1">name Test</a>';
	return $display;
	} 
// Add-on Specific Function
function name_display_addon_page() {
	$display = 'This is a add-on page';
	return $display;
	} 
// Add-on Specific Function
function name_display_admin_page() {
	$display = 'This is a add-on page';
	return $display;
	}
		
Javascript:
As of Open-Realty 2.1 add-ons can now load javascript into the template using two new global variables. Add-ons should add any javascirpt they want to load to the global variables making sure to include the tags around their javascript. You MUST define the variable as a global variable in your function(s). You would use these variables in your add-on specific function(s). The new variables are:

Javascript added to this global variable will be loaded into the main template in place of the "{load_js}" template tag. You must use $jscript .= XXX (dot equal) so the main OR javascript is not over written with your code.
$jscript
Javascript added to this global varible will be loaded into the main template in place of the "{load_js_last}" template tag.
$jscript_last
Search Results:
If creating an add-on 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:

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