(12 votes, average 4.75 out of 5)

Ask JomGenius – JomGenius Knows!

Which Joomla page is the user viewing? … How many items are in the VirtueMart cart? … Has this page been requested by a bot or a browser or IE6 or other? … Is it between 4AM Monday and 1AM Wednesday in Denmark? … Is it more than a week since this user’s last visit? … Is this user visiting from my internal network? … Is the logged-in user a Publisher? … Is the displayed article more than a month old? … Is this article a frontpage article? …

… just ask JomGenius!

Using MetaMod and Chameleon (+ Pro versions), you can change which modules and/or templates will appear on any given Joomla! page, using information from JomGenius.

JomGenius is built-in to Chameleon (from v1.5), and MetaMod (from v2.4). It's a GPL library and will likely be released for use in other Joomla extensions [to come].

In Chameleon, JomGenius forms the foundation of a series of new form controls. These make it easy to assign templates to particular pages, including VirtueMart pages.

In both Chameleon and MetaMod, you can use the simplified JomGenius syntax to replace much more complex PHP rules that were sometimes necessary.

JomGenius syntax is simple but extremely powerful.

JomGenius was developed to simplify the PHP rules used in MetaMod and Chameleon. While PHP is a great web programming language, many of the “recipes” developed for MetaMod configuration needed to be simplified for public consumption.

A good example is finding the section id of the displayed article. It’s one thing to require PHP for the basic "if (condition) return XXX;" constructions, which most people understand, more or less. It’s quite another thing to ask people to copy and paste a big chunk of code into their MetaMod/Chameleon boxes, and expect them to maintain/edit it to meet their needs.

JomGenius is based around two key methods.

  • An "info" method allows you to get named information out of JomGenius (e.g. "pagetype").
  • A "check" method allows you to compare information from "info" against some values, and get a true/false result which you can use in PHP to do something.

The comparison operators in "check" allow easy equality tests ( = ), numerical tests ( <, >, <=, >= ), string comparisons ( contains, starts with, ends with, regex), and set inclusion e.g. "all of setOfStrings contains word", or "word = some of this, that, other" ("some of" means "at least one of"). Check out the examples to see how easy this is (it is, honestly!).

See the configuration page for a complete description of all the options.

if ( $core_genius->check( "pagetype = frontpage, categoryblog, searchresults" ) )
        echo "Viewing frontpage or category-style blog page, or search results";
if ( $core_genius->check( "dayssinceregistration >= 7" ) )
        echo "User has been registered more than 1 week";
if ( $core_genius->check( "browsertype != iphone" ) )
        echo "the browser is NOT iphone";
if ( $core_genius->inTimeSpan( "wed 06:00 - thu 05:45" )
        echo "It's between 6AM Wednesday and 5:45 AM Thursday";

See the configuration page for a complete description of all the options.

if ( $menu_genius->check( "menutype = mainmenu" ) )
        echo "We are on a page on the main menu";
if ( $menu_genius->check( "some of parentitemids = 23" ) )
        echo "We are nested below an ancestor menu item with id 23";

See the configuration page for a complete description of all the options.

if ( $content_genius->check( "article_introtext contains joomla" ) )
        echo "The word joomla appears in the intro text of the displayed article";
if ( $content_genius->check( "article_created_by = 62" ) )
        echo "The article was created by user id 62";
if ( $content_genius->check( "article_title starts with FEATURE:" ) )
        echo "The title of the displayed article starts with FEATURE:";
if ( $content_genius->check( "article_frontpage is true" ) )
        echo "The displayed article also appears on the frontpage";

See the configuration page for a complete description of all the options.

$vm = JomGenius( "virtuemart" );
if ($vm) { // if vm is installed on this site...
 if ( $vm->check( "pagetype = frontpage" )
        echo "On front page of VirtueMart component";
 if ( $vm->check( "productid = 56, 26, 33, 66" )
        echo "ID of displayed product is one of 56, 26, 33 and 66";
 if ( $vm->check( "billtocountry2 = US" )
        echo "Billto country of logged-in user is US";
 if ( $vm->check( "number_cart_items > 20" )
        echo "Hey big spender!";

Once you have a JomGenius object, there are 2 main operations you can perform. You can request information (which returns a string, true/false, or array of values), or you can check the value of that information against a list of your own values.

e.g. to request info:

// display "frontpage" if that is what the user is viewing
echo $core_genius->info( "pagetype" );

e.g. to check the value of a parameter against your own list of values:

if ( $core_genius->check( "pagetype = frontpage, article" ) )
        echo "We are on the frontpage OR an article page";

Some JomGenius objects define other methods (apart from "info" and "check"). e.g. the core_genius object has a sophisticated date/time span checker, which can be called like this:

if ( $core_genius->inTimeSpan( "mon 06:00 - tue 05:45" ) )
        echo "It's between mon 06:00 and tue 05:45";

The full syntax of the "check()" method is as follows:

$res = $obj->check("prefix1 parameter negator operator prefix2 valuelist", extra options... );

prefix1 and prefix2 optional any 1 of the following: any of, all of, none of, number of (spaces optional)
parameter compulsory any of the parameters defined in the particular JomGenius. e.g. "pagetype", "productid", etc. See here for a list.
negator optional may contain "not" or "!"
operator compulsory any 1 of the following: =, !=, <, <=, >, >=, equals, contains, starts with, ends with, regex
valuelist optional

one or more values, comma-separated. If the valuelist is not specified, then you must provide a second parameter to the check() method containing a string or array of values to check, e.g. ->check("pagetype = ", array("frontpage","article"));
If a value in your valuelist contains a comma, you must specify it as an additional parameter.

extra options optional Place extra options, separated by commas, after the main string described above.
If there is no valuelist, add a parameter containing a value or array of values.
Add another parameter containing "true" if you want the comparison to be case SENSITIVE (default false for case insensitive)
Add another parameter containing "true" if you want the comparison to be STRICT. Strict comparisons maintain leading and trailing whitespace which otherwise gets trimmed before comparison. If you specify this option, you must also specify a value for the last option (case sensitivity).


$result = $genius->check( "none of parent_item_ids = 55" );
$result = $genius->check( "some of parent_item_ids < 20" );
$result = $genius->check( "article_metakeywords contains all of keyword1, keyword2" );
$result = $genius->check( "article_metakeywords contains any of keyword1, keyword2" );
$result = $genius->check( "article_metakeywords contains none of keyword1, keyword2" );
$result = $genius->check( "article_title not starts with Foxes" );

Last Updated on Monday, 11 November 2013 11:41