Custom PHP Assignments

Custom PHP Publishing Assignments give you the opportunity to display your box for virtually any occassion you can think of. The only thing stopping you is having the PHP knowledge to code it and how far you are willing to go.

With Custom PHP Publishing Assignments you can get all the data available in the variables, URLs and even the database. Then you can do all kinds of checks on these data.

The main point of Custom PHP Publishing Assignments is that you always need to return either a TRUE or a FALSE value. For TRUE the assignment is valid and vice versa. Here's an example:

if ($variable == 'value') {
   return true;
} else {
   return false;
}
Or written in a more compact way:
return ($some_variable == 'some value');

Below are a (growing) collection of ready-to-use PHP assignment scripts. You can also use these as examples and starting-point to create your own custom scripts.

Assign to browser version

// Enter the browser type and version
$browserType = "msie";
$browserMinimumVersion = "9";
// DO NOT EDIT BELOW jimport('joomla.environment.browser'); $browser = JBrowser::getInstance(); return ($browser->getBrowser() == $browserType && $browser->getMajor() <= $browserMinimumVersion);

Assign to browser language

// comma separated list of accepted languages
$acceptLangs = "en, fr";
// DO NOT EDIT BELOW $browserLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : false; return in_array($browserLang, explode(',', $acceptLangs));

Assign to articles

The Joomla! Articles Assignment is available as a standalone assignment.

// comma separated list of allowed articles
$articles = "50, 51, 52";
// DO NOT EDIT BELOW if ($app->input->getCmd('option') != "com_content") { return false; } if ($app->input->getCmd('view') == "article") { return(in_array($app->input->getCmd('id'), explode(",", $articles))); }

Assign to categories

The Joomla! Categories Assignment is available as a standalone assignment.

// comma separated list of allowed categories
$categories = "50, 51, 52";
// DO NOT EDIT BELOW if ($app->input->getCmd('option') != "com_content") { return false; } if ($app->input->getCmd('view') == "category") { return(in_array($app->input->getCmd('id'), explode(",", $categories))); }

Assign to certain (parts of) email addresses

// comma separated list of (parts of) email addresses
$emails = '@yahoo.com,@hotmail.com';
// DO NOT EDIT BELOW $pass = 0; foreach(explode(',', $emails) as $email) { if (!(strpos($user->email, $email) === false)) { $pass = 1; break; } } return $pass;

Assign to IP addresses

The IP Assignment is available as a standalone assignment.

// comma separated list of IP addresses
$ips = '111.111.111.111,222.222.222.222';
// DO NOT EDIT BELOW return (in_array($_SERVER['REMOTE_ADDR'], explode(',',$ips)));

Assign to keyword (string) in page text

// string to be present in content area
$search = 'my search string';
// DO NOT EDIT BELOW $buffer = $doc->getBuffer('component'); if (!is_array($buffer) && !(strpos($buffer, $search) === false)) { return true; } else { return false; }

Assign to number of visits after new session

// the maximum number of pageloads after a new session
$max = 10;
// DO NOT EDIT BELOW $session = JFactory::getSession(); return ($session->get('session.counter', 0) <= $max);

Assign to certain domain referer

The Referrer Assignment is available as a standalone assignment.

// comma separated list of allowed domains
$domains = "facebook.com,twitter.com";
// DO NOT EDIT BELOW $referer = isset($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : false; if ($referer) { $domain = str_ireplace("www.", "", $referer); return (in_array($domain, explode(',', $domains))); }

Time Range

The Time Range Assignment is available as a standalone assignment.

$startTime = 'today 09am';
$endTime   = 'today 11am';
// DO NOT EDIT BELOW $startDate = strtotime(JFactory::getDate($startTime)); $endDate = strtotime(JFactory::getDate($endTime)); $now = strtotime(JFactory::getDate()->setTimeZone(new DateTimeZone($app->getCfg('offset')))); return ($now >= $startDate) && ($now <= $endDate);

Homepage

Target homepage only with Custom PHP. The homepage can be selected in the Menu Items assignment as well.

$menu = $app->getMenu();
return ($menu->getActive() == $menu->getDefault());
Get Engage Box for Joomla! for just 29€ Get it now!
Don't miss a thing!
Stay up-to-dated with my latest blog articles
Receive updates for my Joomla Extensions
No Spam! It's a promise.