Custom PHP Assignments

Custom PHP assignments give you the opportunity to assign to anything you can think of. You need to know what PHP code you should use.

With Custom PHP publishing assignment you can get all data available in the variables, URLs even database. And then do your checks on this data. You can tell the extension whether it should be displayed by ending the PHP code with a return true or false based on your checks, like:

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

This assignment is available in the Publishing Assignments tab since version 3.1.2

// 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

This assignment is available in the Publishing Assignments tab since version 3.1.2

// 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; $user = JFactory::getUser(); foreach(explode(',', $emails) as $email) { if (!(strpos($user->email, $email) === false)) { $pass = 1; break; } } return $pass;

Assign to IP addresses

// 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 = JFactory::getDocument()->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

This assignment is available in the Publishing Assignments tab since version 2.6.0

// 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

$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);

Downloads

Find the download links to the extensions you have a valid subscription for.

View Downloads

Documentation

Read a growing list of tutorials, articles and frequently asked questions.

Read Documentation

Subscriptions

A detailed list with your active or expired subscriptions.

View Subscriptions

Old Releases

Download older releases of the extensions you have a valid subscription for.

Download Old Releases

Help me Grow

If you love using my extensions or have had a positive experience I am asking you to spread the word.

Write a Review on JED

Support

I am always happy to help! If you can't find answers, feel free to send me a message.

Contact me
×
×
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.