You are here

function imce_install_profiles in IMCE 6

Same name and namespace in other branches
  1. 6.2 inc/imce.core.profiles.inc \imce_install_profiles()
  2. 7 inc/imce.core.profiles.inc \imce_install_profiles()

Create core profiles and import settings from 5.x

2 calls to imce_install_profiles()
imce_admin in inc/admin.inc
Admin main page.
imce_install in ./imce.install
Implementation of hook_install().

File

inc/core_profiles.inc, line 6

Code

function imce_install_profiles() {

  //already installed
  if (in_array(1, array_keys(variable_get('imce_profiles', array())))) {
    return FALSE;
  }
  $profiles = array(
    1 => imce_user1_profile(),
    2 => imce_sample_profile(),
  );
  $index = 2;
  $role_profile = array();

  //import user-1 settings
  if ($u1p = variable_get('imce_settings_user1', NULL)) {
    $profiles[1]['dimensions'] = $u1p['width'] . 'x' . $u1p['height'];
  }

  //role settings
  $user_roles = user_roles();

  //determine weights
  $weights = array();
  $sort = variable_get('imce_settings_rank', array());
  foreach ($sort as $i => $rid) {
    if (isset($user_roles[$rid])) {
      $weights[$rid] = $i - 10;
    }
  }

  //import role settings.
  foreach (variable_get('imce_settings_roles', array()) as $rid => $set) {
    if (isset($user_roles[$rid])) {
      $dirs = $thumbs = array();

      //directories
      $set['shared'] = $set['shared'] == '/' ? '.' : $set['shared'];
      $dirs = array(
        array(
          $set['shared'] == '' ? $set['prefix'] . '%uid' : $set['shared'],
          $set['subnav'] && $set['subdirs'] == '',
          1,
          $set['upload'],
          $set['twidth'] && $set['theight'],
          $set['delete'],
          $set['resize'],
        ),
      );

      //subdirectories
      if ($set['subnav'] && $set['subdirs'] != '') {
        foreach (explode(',', $set['subdirs']) as $subdir) {
          $subdir = trim($subdir);
          if ($subdir != '') {
            $dirs[] = array(
              $dirs[0][0] . '/' . $subdir,
              0,
              1,
              $set['upload'],
              $dirs[0][4],
              $set['delete'],
              $set['resize'],
            );
          }
        }
      }

      //thumbnails
      if ($set['twidth'] && $set['theight']) {
        $thumbs = array(
          array(
            'Thumbnail-1',
            $set['twidth'] . 'x' . $set['theight'],
            '',
            '',
          ),
        );
      }

      //extensions
      $ext = 'gif png jpg jpeg';
      $ext .= $set['extensions'] ? ' ' . str_replace(array(
        ',',
        '.',
        '  ',
      ), array(
        ' ',
        '',
        ' ',
      ), $set['extensions']) : '';

      //file size - quota
      $fsize = $set['nolimit'] ? 0 : round($set['filesize'] / 1024, 1);
      $quota = $set['nolimit'] ? 0 : round($set['quota'] / 1024, 1);

      //create profile
      $profile_name = $user_roles[$rid];
      $profiles[$index] = imce_construct_profile($profile_name, $fsize, $quota, 0, $ext, $set['width'] . 'x' . $set['height'], 1, $dirs, $thumbs);

      //assign the profile to the role.
      $role_profile[$rid] = array(
        'pid' => $index,
        'weight' => $weights[$rid],
      );
      $index++;
    }
  }

  //delete old variables
  variable_del('imce_settings_roles');
  variable_del('imce_settings_user1');
  variable_del('imce_settings_rank');
  variable_del('imce_settings_tinymce');
  variable_del('imce_settings_fck');

  //set new variables
  variable_set('imce_profiles', $profiles);
  variable_set('imce_roles_profiles', $role_profile);
  return TRUE;
}