Tips and Tricks

Here we'll discuss some techniques we use when developing plugins for Jomres.
 
Different minicomponents are called at different times, depending on their trigger number. We'll refer to these types of scripts by their trigger number, and occasionally offer examples where you can see them in use.
 
 
Useful variables
 
 
 
get_showtime('ePointFilepath')
 
Calling this function will give you the absolute path to this script. If you're using template files to generate layout (and you should be), then you'll need to do something like
 
$tmpl->setRoot( get_showtime('ePointFilepath')."templates" );
 
to tell the $tmpl object where your custom template file is located.
 
Hint : If you intend to call other minicomponents from this minicomponent, call get_showtime('ePointFilepath') and put the results in a variable before calling another minicomponent. The instant the next minicomponent is called, get_showtime('ePointFilepath') is reset to the next minicomponent's absolute path.
 
 
 
get_showtime('eLiveSite')
 
This is a little similar to ePointFilepath, in that it points to the directory this script's running in, relatively from the base of your website. Let's say that your website's at http://www.domain.com, then eLiveSite will point to the url http://www.domain.com/jomres/remote_plugins/xxxxxx/
 
In the flipwall plugin you'll see that we use this variable to include the flipwall's jquery.flip.js file in the host CMS's header, like so :
 
jomres_cmsspecific_addheaddata("javascript",get_showtime('eLiveSite').'javascript/',"jquery.flip.js",false);
 
 
j00005 scripts.
 
 
 
Including language files
 
These are generally your setup scripts, where you include functions files, import classes and include language files. Let's see how that's done in funky_search_features plugin j00005funky_search_features.class.php :
 
$ePointFilepath = get_showtime('ePointFilepath');
if (file_exists($ePointFilepath.'language'.JRDS.get_showtime('lang').'.php'))
require_once($ePointFilepath.'language'.JRDS.get_showtime('lang').'.php');
else
{
if (file_exists($ePointFilepath.'language'.JRDS.'en-GB.php'))
require_once($ePointFilepath.'language'.JRDS.'en-GB.php');
}
 
Here we're looking to find the current language's language file for this plugin. If it doesn't exist, we'll fall back to the english language file for this plugin (if it exists).
 
 
 
Switching stuff off
 
Ok, that's mundane enough, let's try something a little bit more fun.
 
Let's say that our plugin introduces functionality so unique, that we want to disable certain things in the system based on certain conditions. Let's see how Jintour's j00005get_jintour_property_data.class.php file does things.
 
In a Jintour based property, we can't show the normal dashboard, because Jintour bookings aren't the same as normal bookings, so to switch off the standard dashboard script, we do the following :
 
unset($MiniComponents->registeredClasses['00013dashboard']);
 
How cool is that? Just like that, for Jintour based properties, with one line we've switched off (among other things) the dashboard calendar.
 
 
Redirecting template calls
 
Something else we can do, and we typically do this in j00005 scripts, is redirect calls from one of the core template files, to another template file. Again, Jintour's j00005 script gives us an example of how this is done :
 
if ($_REQUEST['task'] == "editProperty")
{
$current_custom_paths = get_showtime('custom_paths');
$current_custom_paths['edit_property.html'] = $ePointFilepath.'templates';
set_showtime('custom_paths',$current_custom_paths);
}
 
Jintour based properties have less information to show in the property details, so in the event that the currently viewed property is a jintour property (see that script to see how we determine that) we tell Jomres to use the edit_property.html file in our /templates directory, not the one in /jomres/templates/jomres/backend.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
This document is copyright Vince Wooll/Woollyinwales IT, 2011. All rights reserved.