You are here

function cf_init in Common Functionality 7

Implements hook_init().

File

./cf.module, line 6

Code

function cf_init() {
  cf_error_append_history($function_history, __FUNCTION__);
  global $conf;
  if (!isset($conf['role_memory_limits']) || !is_array($conf['role_memory_limits'])) {
    $conf['role_memory_limits'] = array();
  }
  if (!isset($conf['user_memory_limits']) || !is_array($conf['user_memory_limits'])) {
    $conf['user_memory_limits'] = array();
  }
  if (!isset($conf['ip_memory_limits']) || !is_array($conf['ip_memory_limits'])) {
    $conf['ip_memory_limits'] = array();
  }
  $user = cf_current_user();
  foreach ($conf['role_memory_limits'] as $key => &$value) {
    if (array_key_exists($key, $user->roles) && !empty($value)) {
      ini_set('memory_limit', $value);
    }
  }
  foreach ($conf['user_memory_limits'] as $key => &$value) {
    if ($key == $user->uid && !empty($value)) {
      ini_set('memory_limit', $value);
    }
  }
  $client_ip = ip_address();
  foreach ($conf['ip_memory_limits'] as $key => &$value) {
    if (!empty($value) && $key == $client_ip) {
      ini_set('memory_limit', $value);
    }
  }
}