View source
<?php
define('VAR_RADIOACTIVITY_DRUPAL_ROOT_DEPTH_LIMIT', 10);
if (!defined("DRUPAL_ROOT")) {
_radioactivity_light_initialization();
}
else {
define("VAR_RADIOACTIVITY_CHECKSUM_SALT", variable_get("radioactivity_checksum_salt", "undefined"));
define("VAR_RADIOACTIVITY_TEMP_DIR", variable_get('radioactivity_temp_dir', sys_get_temp_dir()));
if (class_exists('Memcache') || class_exists("Memcached")) {
define("VAR_RADIOACTIVITY_MEMCACHED_HOST", variable_get("radioactivity_memcached_host", "localhost"));
define("VAR_RADIOACTIVITY_MEMCACHED_PORT", variable_get("radioactivity_memcached_port", "11211"));
define("VAR_RADIOACTIVITY_MEMCACHED_PREFIX", variable_get("radioactivity_memcached_prefix", ""));
}
if (class_exists("Redis")) {
define("VAR_RADIOACTIVITY_REDIS_HOST", variable_get("radioactivity_redis_host", "localhost"));
define("VAR_RADIOACTIVITY_REDIS_PORT", variable_get("radioactivity_redis_port", "6379"));
}
}
function _radioactivity_get_config_file_path() {
$dir = dirname(__FILE__);
$config_file = $dir . "/radioactivity-bootstrap.cfg.inc";
return $config_file;
}
function _radioactivity_light_initialization() {
if (!defined("RADIOACTIVITY_BOOTSTRAPPED")) {
$config_file = _radioactivity_get_config_file_path();
if (file_exists($config_file)) {
include $config_file;
}
else {
_radioactivity_require_bootstrapping();
$var = variable_get('radioactivity_checksum_salt', 'undefined');
define("VAR_RADIOACTIVITY_CHECKSUM_SALT", $var);
define("VAR_RADIOACTIVITY_TEMP_DIR", variable_get('radioactivity_temp_dir', sys_get_temp_dir()));
if (!variable_get('radioactivity_config_warning')) {
variable_set("radioactivity_config_warning", TRUE);
}
if (class_exists('Memcache') || class_exists("Memcached")) {
define("VAR_RADIOACTIVITY_MEMCACHED_HOST", variable_get("radioactivity_memcached_host", "localhost"));
define("VAR_RADIOACTIVITY_MEMCACHED_PORT", variable_get("radioactivity_memcached_port", "11211"));
define("VAR_RADIOACTIVITY_MEMCACHED_PREFIX", variable_get("radioactivity_memcached_prefix", ""));
}
if (class_exists("Redis")) {
define("VAR_RADIOACTIVITY_REDIS_HOST", variable_get("radioactivity_redis_host", "localhost"));
define("VAR_RADIOACTIVITY_REDIS_PORT", variable_get("radioactivity_redis_port", "6379"));
}
}
define("RADIOACTIVITY_BOOTSTRAPPED", TRUE);
}
}
function _radioactivity_require_bootstrapping() {
if (!defined("VERSION")) {
include "radioactivity.module";
if (defined("VAR_RADIOACTIVITY_DRUPAL_ROOT")) {
define('DRUPAL_ROOT', VAR_RADIOACTIVITY_DRUPAL_ROOT);
chdir(DRUPAL_ROOT);
}
else {
$depth = 0;
do {
chdir('../');
if (file_exists('./includes/bootstrap.inc')) {
define('DRUPAL_ROOT', getcwd());
break;
}
$depth++;
} while ($depth < VAR_RADIOACTIVITY_DRUPAL_ROOT_DEPTH_LIMIT);
}
if (!file_exists('./includes/bootstrap.inc')) {
die("Unable to figure out bootstrapping directory!");
}
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if (!variable_get('radioactivity_bootstrap_warning')) {
variable_set("radioactivity_bootstrap_warning", TRUE);
}
}
}
function _radioactivity_filter_nested_array($array) {
return !is_array($array) ? TRUE : FALSE;
}
function _radioactivity_checksum_generate($data) {
$temp = array_filter($data, "_radioactivity_filter_nested_array");
unset($temp['checksum']);
ksort($temp);
$temp = join(',', $temp);
return md5(VAR_RADIOACTIVITY_CHECKSUM_SALT . $temp);
}
function _radioactivity_checksum_validate($data, $checksum) {
return strcmp(_radioactivity_checksum_generate($data), $checksum) === 0;
}
function _radioactivity_validate_incident($incident) {
return _radioactivity_checksum_validate($incident, $incident['checksum']);
}
function _radioactivity_prepare_incident($incident) {
ksort($incident);
$incident['checksum'] = _radioactivity_checksum_generate($incident);
return $incident;
}