Developing software for Jomres

 
Introduction
 
We are keen to encourage developers to build and release (either free, or for-profit) plugins for Jomres, so here we will discuss how you can create a simple plugin for the system. Once you've seen how easy it is to build a plugin for the system, we're sure you'll be building complex applications in no time.
 
A simple plugin
 
Let's start, first, with some basic information about how Jomres calls dynamic functionality (your plugin's files).
 
Jomres knows to look in the /jomres/core-plugins/ and /jomres/remote_plugins directories for subdirectories and files with the naming syntax jNNNNNXXXXXX.class.php. These files are stored in it's registry.
 
Let's say for example you want to create a new plugin "Hello JomresWorld" (Yes, that old chestnut).
 
First, create a new directory in /jomres/remote_plugins/ called "hello_jomresworld". Now, create a file in that directory called j06000hello_jomresworld.class.php.
 
In that file, put the following lines :
 
<?php
 
defined( '_JOMRES_INITCHECK' ) or die( '' );
 
class j06000hello_jomresworld
{
function j06000hello_jomresworld()
{
$MiniComponents =jomres_getSingleton('mcHandler');
if ($MiniComponents->template_touch)
{
$this->template_touchable=false; return;
}
echo "Hello Jomres User";
}
 
function getRetVals()
{
return $this->ret_vals;
}
}
 
?>
 
This is the absolute bare bones needed for a Jomres plugin (in fact, you don't actually need the "echo" line, but it's always nice to see some output to confirm that your code is working.
 
Now, go to the administrator area of your Jomres installation and use the "Rebuild Registry" button, this will cause Jomres to note the existance of this new plugin.
 
Next, go to your browser's address bar. Assuming that you're developing on localhost, you would put something like the following in the address bar and hit enter :
 
http://localhost/index.php?option-com_jomres&task=hello_jomresworld
 
You should now see "Hello Jomres User" in the content area of your Joomla installation.
 
That's it, you've created a simple Jomres plugin.
 
You don't need to use the Rebuild Registry button every time you edit the file, once is enough just to tell Jomres that the file's there.
 
Let's look at the script in a little more detail.
 
In depth
 
We've put the file in /jomres/remote_plugins/hello_jomresworld. So long as the file's in a subdirectory off remote_plugins, it doesn't matter what the directory's name is, so long as there aren't any spaces in it. You can call it what you like.
 
 
Because we're creating a dynamic task for Jomres, it's important that the file name ( j06000hello_jomresworld.class.php ) the class name ( class j06000hello_jomresworld ) and the function name ( function j06000hello_jomresworld() ) all reflect the same jnnnnnxxxxx pattern. If they're not then you'll either create a fatal error, or the script simply won't run.
 
Next we call
 
$MiniComponents =jomres_getSingleton('mcHandler');
if ($MiniComponents->template_touch)
{
$this->template_touchable=false;return;
}
 
These lines are used by the label edit feature. If a plugin uses unique labels (for example, from it's own language file) you can set template_touchable to true, then include another function called touch_template_language. If you do that, then when you visit the Label Editing feature in the administrator area of Jomres you'll see
 
j06000hello_jomresworld.class.php
 
and in blue underneath will be the strings you'd like to translate/rename. For example, you'd put something like this :
 
function touch_template_language()
{
$output=array();
$output[]=jr_gettext('CUSTOM_STRING_1',CUSTOM_STRING_1);
$output[]=jr_gettext('CUSTOM_STRING_2',CUSTOM_STRING_2);
 
foreach ($output as $o)
{
echo $o;
echo "<br/>";
}
}
 
 
Finally, we do
 
function getRetVals()
{
return $this->ret_vals;
}
 
Again, this needs to be in every minicomponent (any file with the pattern jnnnnnxxxxx.class.php is called a minicomponent). If you want to pass back some data from this script to it's calling script, you'd put the output in the $this->ret_vals variable.
 
Ok, that's the basis of a minicomponent. If you're already a skilled php developer you probably know enough now to make a start on your own plugins.
 
 
 
 
 
 
 
 
This document is copyright Vince Wooll/Woollyinwales IT, 2011. All rights reserved.