![]() MetaMod — the Joomla! module for selectively including other modules on a Joomla! page
changelog
DescriptionHave you ever wished you could set start and end dates for when modules display? Or wished you could set up your modules so that guests connecting from the USA see a different module to people connecting from Germany? Or wanted to restrict modules by IP address? Now you can. MetaMod is a “Meta Module” - a module that includes other modules, according to rules that you set up. If you download and install the free GeoLite Country database from MaxMind, you can base your rules on the country names of the people connecting to your site (GeoIP targeting). Suggested uses (see recipes, below)
Installationmod_metamod basic package
GeoIP Country/City database
Joomla modifications (for Joomla 1.0.x version only — J1.5 version doesn’t require this)
How to Use
NOTE:
ConfigurationTo set up MetaMod, find the MetaMod module in the Modules->Site Modules
menu. Title: This title will appear at the top of the module position, if the “Show title” option is chosen (next). Show title: No/Yes: (standard module control) In many cases you won't want this turned on, because the included modules will have their own titles. Position: (standard module control) the module position the modules will be loaded into Module Order: (standard module control) Access Level: (standard module control) Published: No/Yes: (standard module control) Don't forget to turn this on! Available Modules: If the admin.modules.php patch is applied (see above) then this will display a list of available modules and their ID numbers. This is for convenience. Module Class Suffix: a suffix which will be added to the CSS class name of the <div> or <table> surrounding the entire module and any other modules it contains. Start and End date/time (freeform): These fields are extremely versatile. They control when MetaMod will start/stop including other modules. Important: the main title of the MetaMod module is not controlled by this date – if you have “Show title” turned on then it will always show regardless of the Start and End date/time settings. Here are some examples:
Start date/time (freeform): Enter a date, time or both, for when the module will start to include other modules. End date/time (freeform): Note: if you enter a date without a time, then the time period will end at the BEGINNING (midnight) of the day that you specify. Time Zone: Choose either "Default Joomla" to use the default Joomla time zone setting, or choose a new time zone from the drop-down list. The advantage of setting a time zone here is that time zones in this list obey Daylight Savings — the standard Joomla time zone does not. This matters if you are setting particular times of the day to display modules, because otherwise Daylight Savings time can put your timings out by an hour during some times of the year. Debug: Off/On: If you are having trouble working out why your modules are not being included, or what the values of $id, $Itemid etc are, then turn this on. You'll see a summary of information in the module position, about all these parameters, and which modules it decided to include in the end. Check: If the admin.modules.php patch is applied (see above) this checks to see if the GeoIP.dat file is installed on your system. It looks for a folder in your Joomla installation called “geoip” and a file in it called “GeoIP.dat”. Because MaxMind updates their database monthly, you need to get a fresh file from their website, and it's not included in this module. See GeoLite Country page, or download latest database. Enable GeoIP/GeoCity: Disabled/GeoIP Country/GeoLite City (free)/GeoCity (commercial): Because looking up the country code of the web visitor takes a little time, MetaMod won't do it unless you say you want it. Select your database here if you want to use the “Only these countries” or “Exclude these countries” fields below, or if you want to use the variables $fromCountryId or $fromCountryName in the PHP block. You will also need to download the relevant database from Maxmind and install them on your server. Only these countries: Enter a comma-separated list of 2-letter country codes. Only visitors from these countries will see the modules that you specify below. Don't forget to turn on the lookup, above. Exclude these countries: Enter a comma-separated list of 2-letter country codes. If a visitor comes from one of these countries, the modules will not be shown. Don't forget to turn on the lookup, above. $language handling: Choose how the PHP variable “$language” will be determined. Choose from: “Browser's preferred language”, “Most preferred language from supplied list” or “Joomla front-end language”. Preferred list of languages: Comma-separated list of preferred language codes, lower case. If “Most preferred language from supplied list” is specified above, then $language will contain the language from this list that appears highest in the browser's preferred language settings. E.g. a browser may be set up for “ar,fr”. If you only test for the first language in the list, but have no content to display for Arabic (ar), you might miss the opportunity to present your French (fr) content. So by specifying a list of the languages you do cater for here, MetaMod will return the one that ranks highest for a particular visitor. If 'Strict language comparison' is turned off, then specifying a major language here (e.g. fr) will match any variants of that in the user's browser, such as fr-fr, fr-ch, fr-be or plain fr. EXAMPLE: de,fr-fr,fr-be,cs Strict language comparison: For use with “Most preferred language from supplied list” above. If turned off, then specifying a language without a region here (e.g. plain “fr” and not “fr-be” or “fr-ch”) will match any variants of that in the user’s browser, such as fr-fr, fr-ch, fr-be or plain fr. Style for included modules: Specify how the included modules will appear. These are standard Joomla options for what will surround the contents of a module. All included modules for this MetaMod module will share this parameter. If you want to use a different parameter for one of the included modules, then make another MetaMod module to wrap the target module, and include the second MetaMod inside the first one.
Style override for included modules: The standard Joomla styles for included modules can be chosen from the previous dropdown, but what happens if your template defines custom module styles? This parameter is your chance to specify exactly which style the included module(s) should use. e.g. for the YooTheme "Evolution" template, many of the module positions use a style called "yoo". So you would enter that in this box. Quick module id include: Here's where you can put in a module id or comma-separated list of ids. The modules that you specify will be displayed inside this MetaMod module in the order that you give, subject to the date and country constraints that you specify above. If you have some PHP rules below that return more module numbers, they will be displayed AFTER any modules specified here. PHP: Here's where you can get creative with your modules, and create rules. At the end of each rule, return the id number of the module that you want to display. If you want to display more than one, return an array or a comma-separated string of id numbers. You get access to a number of PHP variables which you can use in addition to $_SERVER, $_GET, $_POST and $_COOKIE variables Available PHP Variables
Available PHP Constants (from MetaMod 1.5h onwards)These constants can be used in your rules just like variables, except they don't need a "$" in front of them.
PHP Example RecipesImportant: the numbers after the “return” statements have to correspond to the ID number of the module you want to include. Don’t forget to customise these for your own setup! // SHOW MODULE ON ALL PAGES EXCEPT FRONTPAGE (Joomla 1.5) // this assumes that you are using the standard "frontpage" component as the first // menu item on your main menu. If you have changed to a different component for the // first page on your site, then use the MetaMod Debug mode to find the right combination // of $Itemid, $option and $view to identify the page and therefore not show the module // on it. if (! ($view == "frontpage" && $option == "com_content" ) ) return 101; // DATE AND TIME EXAMPLES (new MetaMod 1.5h style)
if ( MM_MONTH == 5 ) return 74; /* month of May, any year */
if ( MM_DATE >= 20090201 && MM_DATE <= 20090524) return 75; /* 1st Feb 2009 to 24 May 2009 */
if ( MM_TIME >= 70000 && MM_TIME < 93000 && MM_DAY_OF_WEEK == 0 ) return 76; /* 7:00-9:00 every Sunday */
if ( MM_DAY_OF_WEEK == 6 || MM_DAY_OF_WEEK == 0 ) return 76; /* every Saturday and Sunday */
if ( ( MM_DAY_OF_MONTH == 5 && MM_TIME >= 180000 )
|| MM_DAY_OF_WEEK == 6
|| MM_DAY_OF_WEEK == 0 ) return 76; /* 6PM Friday to midnight Sunday night */
if ( MM_DAY_OF_MONTH <= 7 ) return 76; /* 1st to 7th day of every month */
// DATE AND TIME EXAMPLES (Joomla 1.0)
if (time() >= strtotime("1 Oct 2007") && time() < strtotime("1 November 2007")) return 74;
if (time() < strtotime("1 Nov 2008")) return 75;
// GEOIP EXAMPLES (all versions)
if ($fromCountryId == "US") return 55;
if ($fromCountryId == "GB") return "55,56,57";
if ($fromCountryId == "NL") return array(58,59,73);
if ($fromCountryName == "New Zealand") return 21;
//advert in mornings for US viewers
if ($fromCountryId == "US" && time() >= strtotime("07:00") && time() <= strtotime("12:00")) return 23;
//advert in lunch break for US viewers
if ($fromCountryId == "US" && time() >= strtotime("12:00") && time() <= strtotime("14:00")) return 24;
// SHOW A MODULE IF A PARTICULAR PERSON IS LOGGED IN TO THE FRONTEND (Joomla 1.5) // this is an interesting one. Let's say you want everyone to know whan a particular // person is logged in to the system (e.g. for technical support). // Joomla keeps track of all logged-in users. If you log out explicitly, then your // entry is deleted from the session table immediately. If you allow your login to // just expire without logging out, then this method thinks you are logged in until // your session expires. Login session length is controlled in the Joomla backend. // Don't set it for really long times, or else this method will think that your user // is still logged in until far after they have gone! $search_user_name = 'some_guy23'; // change some_guy23 to the login name of the person you are tracking $username = $db->getEscaped($search_user_name); $query = "SELECT username " . " FROM #__session WHERE username = '$username' " . " AND guest = 0 " . " AND client_id = 0 ;" ; $db->setQuery( $query ); $found = $db->loadAssoc(); if (is_array($found)) return 101; /* found him/her. customise to your own module number. */ return 102; /* didn't find him/her. customise to your own module number. */ // SHOW A MODULE ONCE PER SESSION (all versions)
session_start();
$instance_name = "shown_module_1"; /* use a different name for each module that you want to show only once */
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == false) {
$_SESSION[$instance_name] = true;
return 101; /* customise to your own module number. This is the one that gets shown just once per session. */
}
return 102; /* the module you want to display on the 2nd, 3rd... showing */
// ADVANCED: CYCLE THROUGH DIFFERENT MODULES ON CONSECUTIVE PAGE VIEWS
session_start();
$instance_name = "module_counter1"; /* use a different name for each "setup" */
$modules = array(101,0,54,0,62,0,84,33,34); /* use as many or as few as you like, or "0" for no module */
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == "") {
$_SESSION[$instance_name] = 0;
}
$index = $_SESSION[$instance_name] % count($modules);
$_SESSION[$instance_name]++;
$module_no = $modules[$index];
if ($module_no > 0) return $module_no;
// CLIENT IP ADDRESS (all versions)
if ($_SERVER['REMOTE_ADDR'] == "123.22.33.44") return 56;
// IP address range example 123.22.33.50-55
$ip_numbers = explode(".",$_SERVER['REMOTE_ADDR']); // split ip address into numbers, we test individually
if ($ip_numbers[0] == 123 &&
$ip_numbers[1] == 22 &&
$ip_numbers[2] == 33 &&
$ip_numbers[3] >= 50 &&
$ip_numbers[3] <= 55) return 12;
// RANDOMISED MODULES (all versions) $r = rand(1,3); // get a random number: 1-3 inclusive if ($r == 1) return 44; if ($r == 2) return 88; if ($r == 3) return 42; // TIME OF LAST VISIT (Joomla 1.0)
if (strtotime("-1 month") > strtotime($my->lastvisitDate)) return 12; // user has not logged in for over 1 month
// TIME OF LAST VISIT (Joomla 1.5)
if (strtotime("-1 month") > strtotime($user->lastvisitDate)) return 12; // user has not logged in for over 1 month
// BROWSER DETECTION (display a different module based on which browser is being used)
$UA = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$SF = strstr($UA, 'Safari') ? true : false;
$OP = strstr($UA, 'Opera') ? true : false;
$OPV = $OP ? preg_split('/opera\//i', $UA) : false;
$OPV = $OPV ? floatval($OPV[1]) : false;
$FF = !$OP && strstr($UA, 'Firefox') ? true : false;
$FFV = $FF ? preg_split('/firefox\//i', $UA) : false;
$FFV = $FFV ? floatval($FFV[1]) : false;
$IE = strstr($UA, 'MSIE') ? true : false;
$IEV = $IE ? preg_split('/msie/i', $UA) : false;
$IEV = $IEV ? floatval($IEV[1]) : false;
if ($IEV >= 7) return 55; // any version of IE greater or equal to 7
if ($IEV >= 6) return 55; // any version of IE greater or equal to 6
if ($IE) return 55; // any version (at all) of IE
if ($OP) return 66; // any version of Opera
if ($FF) return 77; // any version of Firefox
if ($SF) return 88; // any version of Safari
// USER/GROUP things JOOMLA 1.5, from MetaMod 1.5h onwards: // First option: just use the new drop-down box at the top of the module configuration. // Then put the modules you want to show into the "Quick module id include" box. // Second option, use one of the following rules, which allow you to // provide alternatives if the main rule is not met // if user is not logged in, show mod 44. If they are logged in show mod 45: if ( MM_NOT_LOGGED_IN ) return 44; else return 45; // if user is not logged in, show mod 44. If they are logged in show nothing at all: if ( MM_NOT_LOGGED_IN ) return 44; else return; // if user IS logged in, show module 44, else show nothing at all: if ( MM_LOGGED_IN ) return 44; else return; if ( MM_USER_REGISTERED ) return 46; // a plain registered user, no additional privileges if ( MM_USER_AUTHOR ) return 47; // show a notice for "Author" users if ( MM_USER_EDITOR ) return 48; // show a notice for "Editor" users if ( MM_USER_PUBLISHER ) return 49; // show a notice for "Publisher" users if ( MM_USER_MANAGER ) return 50; // show a notice for "Manager" users if ( MM_USER_ADMINISTRATOR ) return 51; // show a notice for "Administrator" users if ( MM_USER_SUPER_ADMINISTRATOR ) return 52; // show a notice for "Super Administrator" users if ( MM_LOGGED_IN && MM_NOT_USER_AUTHOR ) return 53; // show a notice to anyone logged in who is not in the "Author" group // USER/GROUP things JOOMLA 1.0.x // if user is not logged in, show mod 44. If they are logged in show mod 45: if ($my->usertype == "" || $my->usertype == "Public Frontend") return 44; else return 45; // if user is not logged in, show mod 44. If they are logged in show nothing at all: if ($my->usertype == "" || $my->usertype == "Public Frontend") return 44; else return; // if user IS logged in, show module 45, else show nothing at all: if ($my->usertype != "" && $my->usertype != "Public Frontend") return 44; else return; if ($my->usertype == "User") return 46; // a plain registered user, no additional privileges if ($my->usertype == "Publisher") return 47; // show a notice for users with "Publisher" privileges // ARTICLE SECTION/CATEGORY EXAMPLE (Joomla 1.0) // Detect the section and category of the article currently displaying on the page, and make decisions // based on which section or category is being displayed. // // e.g. show different modules when the "hockey" or "football" (category ids 14 and 15) categories in // the "sports" section (section id 5) are being displayed. // // This assumes that the module is only displaying on pages that are displaying // a content article of some sort. Therefore the "id" is assumed to be an article id. // If it's not, then you might get some strange results. // THIS VERSION FOR JOOMLA 1.0.x ONLY! global $id; $nullDate = $database->Quote( $database->getNullDate() ); $row = null; $my_id = $database->getEscaped($id); $query = "SELECT title, id, catid, sectionid" . " FROM #__content WHERE id = '$my_id' AND state = 1" . " AND ( publish_up = " . $nullDate . " OR publish_up <= CURRENT_TIMESTAMP )" . " AND ( publish_down = " . $nullDate . " OR publish_down >= CURRENT_TIMESTAMP " . " )" ; $database->setQuery( $query, 0, 1 ); $database->loadObject($row); $catid = $row->catid; $sectionid = $row->sectionid; // now you can use $catid and $sectionid in your test: if ($catid == 14) return 1234; // for hockey articles show module 1234 if ($catid == 15) return 5678; // for football articles show module 5678 /////////////////////////////////// // JOOMLA 1.5 VERSION OF THE ABOVE $nullDate = $db->Quote($db->getNullDate()); $my_id = $db->getEscaped((int)$id); $query = "SELECT title, id, catid, sectionid" . " FROM #__content WHERE id = '$my_id' AND state = 1" . " AND ( publish_up = " . $nullDate . " OR publish_up <= CURRENT_TIMESTAMP )" . " AND ( publish_down = " . $nullDate . " OR publish_down >= CURRENT_TIMESTAMP )" ; $db->setQuery( $query, 0, 1 ); $row = $db->loadObject(); $catid = $row->catid; $sectionid = $row->sectionid; // now you can use $catid and $sectionid in your test: if ($catid == 14) return 1234; // for hockey articles show module 1234 if ($catid == 15) return 5678; // for football articles show module 5678 /////////////////////////////////// // IMPROVED VERSION FOR JOOMLA 1.5, SPECIFICALLY FOR GETTING CATEGORIES
// INCLUDING BLOG OR LIST STYLE CATEGORY PAGES
if ($option == "com_content" && $view == "category") {
/* category list pages (blog or list style) */
$category_id = (int)$id;
} else if (array_key_exists("catid",$_REQUEST)) {
/* if the category id is in the URL */
$category_id = (int)$_REQUEST["catid"];
} else if ($option == "com_content" && $view == "article") {
/* if it's an article page without the catid mentioned in the url */
$nullDate = $db->Quote($db->getNullDate());
$my_id = $db->getEscaped((int)$id);
$query = "SELECT title, id, catid, sectionid"
. " FROM #__content WHERE id = '$my_id' AND state = 1"
. " AND ( publish_up = " . $nullDate
. " OR publish_up <= CURRENT_TIMESTAMP )"
. " AND ( publish_down = " . $nullDate
. " OR publish_down >= CURRENT_TIMESTAMP )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$category_id = $row->catid;
$section_id = $row->sectionid;
}
if ($category_id == 1) return 55;/* on category 1, return module 55 */
if ($category_id == 2) return 56;/* on category 2, return module 56 */
if ($category_id == 3) return 57;/* on category 3, return module 57 */
return 50; /* default if nothing else matches */
///////////////////////////////////
// COMMUNITY BUILDER (Joomla 1.0.x and legacy mode under Joomla 1.5)
// In this example we choose modules based on the zipcode that the logged-in user has
// entered with their address in their profile.
// You can even select based on their state, country or anything else in their profile.
$user_id = $db->getEscaped((int)($user->id)); // for Joomla 1.5 - delete this line if you're on Joomla 1.0.x
$user_id = $db->getEscaped((int)($my->id)); // for Joomla 1.0.x - delete this line if you're on Joomla 1.5
if ($user_id > 0) {
$query = "select * from #__comprofiler where user_id = '$user_id';";
$db->setQuery( $query );
$row = $db->loadObject();
$zipcode = $row->zipcode;
/* you can also get hold of city, state, phone, fax, website, location, or whatever else they enter: */
$country = strtolower($row->country); /* (like this - I lower-case it to make it easier to compare later) */
$state = $row->state; /* (or this) */
// rules:
if ($country == "new zealand" || $country == "nz") return 30; /* check for countries first */
if ($zipcode == 90210) return 55; /* module 55 is the one with the advert for people in zip code 90210 */
if ($zipcode == 90211) return 56; /* module 56 is the one with the advert for people in zip code 90211 */
if ($zipcode >= 90212 && $zipcode <= 90300) return 57; /* use module 57 for the range 90212-90300 */
/* In PHP, || means "or", && means "and" */
if ($zipcode == 22222 || $zipcode == 33333 || ($zipcode >= 90212 && $zipcode <= 90300) ) return 58;
}
// JREVIEWS (Joomla 1.5)
// In this example, we return different modules depending on whether jReviews is on its
// "base" page or looking at a "category". We can choose the modules according to category
// as seen below. Note that if you have SEO urls turned on, jReviews acts slightly differently
// to when they are not turned on, so the code below tests for both cases. It's not the most
// elegant way to handle it, but shows you how to handle the situation.
if ($option == "com_jreviews") {
$url = preg_replace("#/$#",'',$_GET['url']);
if ($url == "") return 18; // the top level page, not in a section or category
$parts = explode("/",$url);
$last_part = $parts[count($parts)-1];
$last_part = preg_replace("#_.*$#","",$last_part);
switch ($last_part) {
case "jreviews-category-list": // seo off
case "jreviews:category:list": // seo on
return 38;
case "the-community": // seo off
case "the:community": // seo on
return 47;
case "the-project": // seo off
case "the:project": // seo on
return 19;
}
}
// VIRTUEMART (Joomla 1.5 -- Joomla 1.0 is probably similar but untested)
// Use this to display different modules on different pages
// e.g. display a certain module when a certain product is being displayed in detail,
// e.g. display a certain module when a certain product category is being listed
// e.g. show certain modules on various other VirtueMart pages, e.g. shopping cart,
// signup, any of the checkout pages, profile pages, search pages, etc etc.
if ($option == "com_virtuemart") {
$page = array_key_exists("page",$_REQUEST) ? $_REQUEST["page"] : "";
$category_id = array_key_exists("category_id",$_REQUEST) ? $_REQUEST["category_id"] : "";
$product_id = array_key_exists("product_id",$_REQUEST) ? $_REQUEST["product_id"] : "";
$search_category = array_key_exists("search_category",$_REQUEST) ? $_REQUEST["search_category"] : "";
if ($search_category != "") {
if ($search_category == 1) return 95; /* searched for a specific category */
return 96; /*searched on any other category */
}
if ($page == "shop.browse") {
if ($category_id == "2") return 97; /* when browsing a specific category (2 in this case) */
return 98; /* when browsing any other category */
}
if ($page == "shop.product_details") {
if ($product_id == "4") return 99; /* modules that should appear for very specific products */
if ($product_id == "44") return 100;
/* when viewing a product in a specific category (2 in this case). Doesn't always show up: */
if ($category_id == "2") return 101;
return 102; /* when viewing any other product not mentioned above */
}
if ($page == "shop.ask") return 103; /* "ask a question about this product" */
if ($page == "shop.cart") return 104; /* viewing shopping cart */
if ($page == "shop.search") return 1041; /* advanced search page */
if ($page == "account.index") return 1042; /* customer account page */
if ($page == "account.shipping") return 1043; /* customer account shipping address page */
if ($page == "account.shipto") return 1044; /* customer account add shipping address page */
if ($page == "account.billing") return 1045; /* customer account billing info page */
if ($page == "shop.savedcart") return 1046; /* page about saved carts */
$last_step = array_key_exists("checkout_last_step",$_REQUEST) ? $_REQUEST["checkout_last_step"] : "";
/* $last_step is:
* "" on the first checkout page (as long as page is "checkout.index")
* 1 on the page for shipping method,
* 2 on the page for taking the credit card number
* 3 on the page for reviewing the order
* 4 on the page for confirming the order
*/
// now some more possible rules:
if ($page == "checkout.index" && $last_step == "" ) return 105; /* checkout, before or after login */
if ($last_step == 1) return 106; /* the page for selecting shipping method */
if ($last_step == 2) return 107; /* the page for taking the credit card number */
if ($last_step == 3) return 108; /* the page for reviewing the order */
if ($last_step == 4) return 109; /* the page for confirming the order */
if ($page == "account.order_details") return 110; /* after submitting order, view complete order details */
}
// END OF VIRTUEMART RULES
// JOOMFISH 2.0 (Joomla 1.5)
// This is a useful addition to JoomFish's translation capabilities. Instead of just translating each
// item in a menu into each language, just set up an entire "duplicate menu" for each
// alternative language, and use MetaMod to switch the entire menu to a different one, depending on
// the language the user has selected.
// This has the additional advantage that you can have some completely different menu items in each
// language which is often useful, as the audiences in each language might be quite different.
// Of course, this depends on the menus being controlled in Module Positions -- note that some templates
// out there (e.g. RocketTheme) embed the main menus into the template itself, so cannot be controlled
// with MetaMod.
global $mainframe;
$language = $mainframe->getCfg('language');
if ($language=="en-GB") return 100;
if ($language=="el-GR") return 101;
// PAGE REDIRECTION
// This example doesn't exactly load alternative modules, but uses MetaMod's rules system to redirect
// to another page entirely if the rules succeed.
// This might be useful, for example, for helping to protect a page from viewing unless particular
// conditions are met, in a more flexible way than you can normally do with Joomla
// e.g. limit page view to a particular user, or GeoIP country, and kick any other users or countries
// onto an alternative, more apropriate page...
// Page redirection examples, Joomla 1.5:
global $mainframe; /* always include this line once before using the $mainframe->redirect method... */
if ($user->name != "John Doe") mosRedirect("http://www.example.com/alternative_page.html");
// GeoIP example, this page is only for New Zealand viewers, kick Australians onto specific page and
// all other countries onto an international pricing page:
if ($fromCountryId == "AU") $mainframe->redirect("http://www.example.com/oz_pricing");
else if ($fromCountryId != "NZ") $mainframe->redirect("http://www.example.com/international_pricing");
// Page redirection examples, Joomla 1.0:
if ($my->name != "John Doe") mosRedirect("http://www.example.com/alternative_page.html");
// GeoIP example, this page is only for New Zealand viewers, kick Australians onto specific page and
// all other countries onto an international pricing page:
if ($fromCountryId == "AU") mosRedirect("http://www.example.com/oz_pricing");
else if ($fromCountryId != "NZ") mosRedirect("http://www.example.com/international_pricing");
// INCLUDE HTML DIRECTLY IN METAMOD // Note: Mambots (plugins in J1.5) don't run in MetaMod output, so SEF URLs and other "replacements" // may not work as expected. (e-mail author if you would like this feature...) if (some rules here...) return 45; /* the next line (questionmark greater-than) is important. Always put this before a block of html... */ ?> <b>Here is my HTML code here. This will show if the previous rule fails</b><br /> <i>If there was no rule before this, then this HTML would display before any other modules were included, if any</i> <?php /* after the block of HTML you always have to put the preceding line, even if that's the last * line of the MetaMod PHP block. */ // INCLUDE PHP CODE DIRECTLY IN METAMOD // Hey, MetaMod PHP is just normal PHP, so if you like you can put anything you want in here! This includes // "echo" commands or anything else that produces output. // Any PHP output is output *after* any "Quick module id include" modules, but *before* any modules that you // "return" from the PHP. // It can be really handy to use MetaMod just as a generic PHP/HTML module, with the added benefit of being // able to include extra modules if necessary. if ($user->name == "John Doe") echo "Hi John, nice to see you!"; else if ($user->usertype != "" && $user->usertype != "Public Frontend") echo "Please log in!"; else echo "Welcome " . $user->usertype; // BASE MODULE SELECTION ON MAIN COMPONENT HTML CONTENT, META-DESCRIPTION OR META-KEYWORDS
// This awesome recipe allows you to "search" the content of the page (actually just the main
// component, not including other modules), OR the Meta-Description, OR the Meta-Keywords, and
// base module selection on what you find there.
//
// To set it up, just edit the "$source", "$case_sensitive", "$allow_as_substrings", "$names"
// and "$max_num_modules" variables below. The "$names" array contains the words/phrases that
// you want to search for, and the module ID to use when any one of them is found.
$source = "content"; /* either "keywords", "description" or "content" */
$case_sensitive = false; /* set to true or false */
/* if you set $allow_as_substrings to true, then the search
* will pick up "billybob thornton" even if you are trying
* to search for "bob thornton". Set it to false to make
* sure that there's an least 1 non-alphabet character on
* each end of the string you are searching for.
*/
$allow_as_substrings = false; /* set to true or false */
$max_num_modules = 3; /* it will just give you the first 3 it finds */
/* In this array, the first part is the text to search for, and the last part
* is the module number to include if that text is found. Add as many as you like.
* Remember every line has to end in a comma EXCEPT the last one!
*/
$names = array(
"bob jones" => 29,
"jim baker" => 22,
"john major" => 27,
"tony blair" => 56,
"CREATIVE" => 19,
"global action" => 1,
"joomla" => 39,
"CMS" => 33,
"graphical user interface" => 40
);
/*****************************************/
/* you shouldn't need to edit below here */
/*****************************************/
$document =& JFactory::getDocument();
switch ($source) {
case "keywords":
$content = $document->getMetaData('keywords');
break;
case "description":
$content = $document->getMetaData('description');
break;
default:
$buffer = $document->getBuffer();
$content = $buffer['component'][''];
}
$names_escaped = array();
foreach ($names as $key=>$module) {
if (!$case_sensitive) {
$key = strtolower($key);
}
$names_escaped[preg_quote($key)] = $module;
}
$names = $names_escaped;
$names_only = str_replace('/','\/',implode("|", array_keys($names)));
$word_boundary = $allow_as_substrings ? '' : '\b';
$result = preg_match_all("/" . $word_boundary . "(" . $names_only . ")" . $word_boundary . "/"
. ($case_sensitive ? '' : 'i'), $content, $all);
if ($result > 0) {
$modules = array();
foreach ($all[0] as $matched_name) {
$module = $names[$case_sensitive ? $matched_name : strtolower($matched_name)];
if ( array_search( $module, $modules) === false ) {
$modules[] = $module;
}
}
if ( count($modules) > $max_num_modules ) {
return array_slice( $modules, 0, $max_num_modules );
}
return $modules;
}
|
|||||||||||||||||||||||||||||||