function adserve_variable in Advertisement 5.2
Same name and namespace in other branches
- 5 adserve.inc \adserve_variable()
- 6.3 adserve.inc \adserve_variable()
- 6 adserve.inc \adserve_variable()
- 6.2 adserve.inc \adserve_variable()
- 7 adserve.inc \adserve_variable()
Retrieve variables from $_GET array or from passed in $value array.
23 calls to adserve_variable()
- adserve_ad in ./
adserve.inc - The main adserve logic.
- adserve_cache in ./
adcache.inc - Wrapper for calling adserve_cache functions.
- adserve_cache_display in ./
adcache.inc - Default function for displaying advertisements. This is not generally replaced by ad cache modules.
- adserve_cache_get_ad_ids in ./
adcache.inc - Default wrapper function for displaying advertisements. This generally is not replaced by ad caches modules.
- adserve_cache_increment in ./
adcache.inc - Increment action directly in the database.
File
- ./
adserve.inc, line 51
Code
function adserve_variable($variable, $value = NULL) {
global $conf;
static $variables = NULL, $overridden = NULL, $cache_loaded = array();
// Update the value, if set.
if (isset($value)) {
$variables->{$variable} = $value;
}
$loaded = FALSE;
if (!isset($variables->loaded) || $variable == 'variable_load') {
if ($variable == 'variable_load' && isset($value)) {
$values['debug'] = $value['debug'];
$values['c'] = $value['adcache'];
$values['n'] = $value['nids'];
$values['t'] = $value['tids'];
$values['k'] = $value['hostid'];
$values['q'] = $value['quantity'];
$values['m'] = $value['ad_display'];
unset($value);
}
else {
$values = $_GET;
}
// Don't use getcwd as path may involve symbolic links
$variables->ad_dir = dirname($_SERVER['SCRIPT_FILENAME']);
// 'debug' is an integer.
$variables->debug = isset($values['debug']) ? (int) $values['debug'] : 0;
// Cache types are comprised of only letters.
$variables->adcache = isset($values['c']) ? preg_replace('/[^a-zA-Z]/', '', $values['c']) : 'none';
// Nids is an integer or a ",".
$variables->nids = isset($values['n']) ? preg_replace('/[^0-9,]/', '', $values['n']) : '';
// Tids is an integer or a ",".
$variables->tids = isset($values['t']) ? preg_replace('/[^0-9,]/', '', $values['t']) : '';
// Hostid is an md5() which is comprised of numbers and letters a-f.
$variables->hostid = isset($values['k']) ? preg_replace('/[^0-9a-f]/', '', $values['k']) : '';
// Click url
$variables->url = isset($values['u']) ? $values['u'] : '';
if (!$variables->url) {
$variables->url = $_SERVER['HTTP_REFERER'];
}
// Quantity is an integer.
$variables->quantity = isset($values['q']) ? (int) $values['q'] : 0;
// Ad ID is an integer.
$variables->aid = isset($values['a']) ? (int) $values['a'] : 0;
// Method is compriese of only letters.
$variables->ad_display = isset($values['m']) ? preg_replace('/[^a-zA-Z]/', '', $values['m']) : 'javascript';
// Set defaults.
$variables->quantity = $variables->quantity ? $variables->quantity : 1;
if ($variables->debug) {
foreach ($variables as $variable => $val) {
echo "{$variable}: '{$val}'<br />\n";
}
if ($variables->debug == 1) {
exit;
}
}
$variables->loaded = TRUE;
// Override the value, if set during initialization.
if (isset($value)) {
$variables->{$variable} = $value;
}
$loaded = TRUE;
}
if (!$overridden) {
if (isset($conf)) {
foreach ($conf as $var => $val) {
$variables->{$var} = $val;
if ($variables->debug) {
echo "Override {$var}: '{$val}'<br />\n";
}
}
$overridden = TRUE;
}
}
if (!isset($cache_loaded[$variables->adcache])) {
// Retrieve variables defined by cache plugin, if enabled.
if ($variables->adcache != 'none') {
$include = $variables->ad_dir . "/cache/{$variables->adcache}/ad_cache_{$variables->adcache}.inc";
if (file_exists($include)) {
if ($variables->debug) {
echo "Attempting to include cache include file '{$include}'.<br />\n";
}
require_once $include;
}
else {
if ($variables->debug) {
echo "Failed to find cache include file '{$include}'.<br />\n";
}
}
$function = "ad_cache_{$variables->adcache}" . '_variables';
if (function_exists($function)) {
$external_variables = $function();
foreach ($external_variables as $key => $val) {
if (!isset($variables->{$key})) {
$variables->{$key} = $val;
}
}
}
}
$cache_loaded[$variables->adcache] = TRUE;
}
if ($variable == 'variable_dump') {
echo "Dumping \$variables:<br />\n";
echo '<pre>';
foreach ($variables as $var => $val) {
echo " {$var}({$val})<br />\n";
}
echo '</pre>';
}
if (isset($variables->{$variable})) {
return $variables->{$variable};
}
else {
return NULL;
}
}