You are here

function cf_settings_boot in Common Functionality 7.2

Implements hook_boot().

Related topics

File

modules/cf_settings/cf_settings.module, line 39
Common Functionality - PHP INI module.

Code

function cf_settings_boot() {
  global $conf;
  global $user;
  if (!isset($conf['role_php_ini']) || !is_array($conf['role_php_ini'])) {
    $conf['role_php_ini'] = array();
  }
  if (!isset($conf['user_php_ini']) || !is_array($conf['user_php_ini'])) {
    $conf['user_php_ini'] = array();
  }
  if (!isset($conf['ip_php_ini']) || !is_array($conf['ip_php_ini'])) {
    $conf['ip_php_ini'] = array();
  }

  // External functions cannot be called during hook_boot() so do things manually here.
  $static_vars =& drupal_static(__FUNCTION__, array());
  if (!isset($static_vars['roles'])) {
    if ($user->uid == 0) {
      $static_vars['roles'] = array(
        1,
      );
    }
    else {
      $roles_object = db_query('SELECT rid from {users_roles} where uid = :uid', array(
        ':uid' => $user->uid,
      ));
      if (!is_object($roles_object)) {
        return;
      }
      $static_vars['roles'] = array_keys($roles_object
        ->fetchAllAssoc('rid'));
      if (!in_array(2, $static_vars['roles'])) {
        $static_vars['roles'][] = 2;
      }
    }
  }
  if (!isset($static_vars['registered_type'])) {
    $registered_types_object = db_query('SELECT * from {cf_settings_options_variable_type} where machine_name = \'php_ini\'');
    if (!is_object($registered_types_object)) {
      return;
    }
    $registered_types = $registered_types_object
      ->fetchAll();
    $static_vars['registered_type'] = reset($registered_types);
  }
  $registered_php_ini = cf_settings_get_registered(array(
    'variable_type' => $static_vars['registered_type']->id,
  ), 'id');
  if (empty($registered_php_ini)) {
    return;
  }
  $client_ip = ip_address();
  foreach ($registered_php_ini as $id => &$variable) {
    if (array_key_exists($variable->variable_name, $conf['role_php_ini'])) {
      foreach ($conf['role_php_ini'][$variable->variable_name] as $key => &$value) {
        if (in_array($key, $static_vars['roles'])) {
          ini_set($variable->variable_name, $value);
        }
      }
    }
    if (array_key_exists($variable->variable_name, $conf['user_php_ini'])) {
      foreach ($conf['user_php_ini'][$variable->variable_name] as $key => &$value) {
        if ($key == $user->uid) {
          ini_set($variable->variable_name, $value);
        }
      }
    }
    if (array_key_exists($variable->variable_name, $conf['ip_php_ini'])) {
      foreach ($conf['ip_php_ini'][$variable->variable_name] as $key => &$value) {
        if (!empty($value) && $key == $client_ip) {
          ini_set($variable->variable_name, $value);
        }
      }
    }
  }
}