web/drupal/modules/imce/inc/core_profiles.inc
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: core_profiles.inc,v 1.2.2.3 2008/06/10 08:34:20 ufku Exp $
       
     3 
       
     4 /**
       
     5  * Create core profiles and import settings from 5.x
       
     6  */
       
     7 function imce_install_profiles() {
       
     8 
       
     9   //already installed
       
    10   if (in_array(1, array_keys(variable_get('imce_profiles', array())))) {
       
    11     return FALSE;
       
    12   }
       
    13 
       
    14   $profiles = array(1 => imce_user1_profile(), 2 => imce_sample_profile());
       
    15   $index = 2;
       
    16   $role_profile = array();
       
    17 
       
    18   //import user-1 settings
       
    19   if ($u1p = variable_get('imce_settings_user1', NULL)) {
       
    20     $profiles[1]['dimensions'] = $u1p['width'] .'x'. $u1p['height'];
       
    21   }
       
    22 
       
    23   //role settings
       
    24   $user_roles = user_roles();
       
    25   //determine weights
       
    26   $weights = array();
       
    27   $sort = variable_get('imce_settings_rank', array());
       
    28   foreach ($sort as $i => $rid) {
       
    29     if (isset($user_roles[$rid])) {
       
    30       $weights[$rid] = $i-10;
       
    31     }
       
    32   }
       
    33 
       
    34   //import role settings.
       
    35   foreach (variable_get('imce_settings_roles', array()) as $rid => $set) {
       
    36     if (isset($user_roles[$rid])) {
       
    37       $dirs = $thumbs = array();
       
    38 
       
    39       //directories
       
    40       $set['shared'] = $set['shared'] == '/' ? '.' : $set['shared'];
       
    41       $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']));
       
    42 
       
    43       //subdirectories
       
    44       if ($set['subnav'] && $set['subdirs'] != '') {
       
    45         foreach (explode(',', $set['subdirs']) as $subdir) {
       
    46           $subdir = trim($subdir);
       
    47           if ($subdir != '') {
       
    48             $dirs[] = array($dirs[0][0] .'/'. $subdir, 0, 1, $set['upload'], $dirs[0][4], $set['delete'], $set['resize']);
       
    49           }
       
    50         }
       
    51       }
       
    52 
       
    53       //thumbnails
       
    54       if ($set['twidth'] && $set['theight']) {
       
    55         $thumbs = array(array('Thumbnail-1', $set['twidth'] .'x'. $set['theight'], '', ''));
       
    56       }
       
    57 
       
    58       //extensions
       
    59       $ext = 'gif png jpg jpeg';
       
    60       $ext .= $set['extensions'] ? ' '. str_replace(array(',', '.', '  '), array(' ', '', ' '), $set['extensions']) : '';
       
    61 
       
    62       //file size - quota
       
    63       $fsize = $set['nolimit'] ? 0 : round($set['filesize']/1024, 1);
       
    64       $quota = $set['nolimit'] ? 0 : round($set['quota']/1024, 1);
       
    65 
       
    66       //create profile
       
    67       $profile_name = $user_roles[$rid];
       
    68       $profiles[$index] = imce_construct_profile($profile_name, $fsize, $quota, 0, $ext, $set['width'] .'x'. $set['height'], 1, $dirs, $thumbs);
       
    69 
       
    70       //assign the profile to the role.
       
    71       $role_profile[$rid] = array('pid' => $index, 'weight' => $weights[$rid]);
       
    72       $index++;
       
    73     }
       
    74   }
       
    75 
       
    76   //delete old variables
       
    77   variable_del('imce_settings_roles');
       
    78   variable_del('imce_settings_user1');
       
    79   variable_del('imce_settings_rank');
       
    80   variable_del('imce_settings_tinymce');
       
    81   variable_del('imce_settings_fck');
       
    82 
       
    83   //set new variables
       
    84   variable_set('imce_profiles', $profiles);
       
    85   variable_set('imce_roles_profiles', $role_profile);
       
    86 
       
    87   return TRUE;
       
    88 }
       
    89 
       
    90 /**
       
    91  * Construct a profile based on arguments.
       
    92  */
       
    93 function imce_construct_profile($n, $f, $q, $tq, $e, $d, $fn, $ds, $ts) {
       
    94   $profile = array('name' => $n, 'filesize' => $f, 'quota' => $q, 'tuquota' => $tq, 'extensions' => $e, 'dimensions' => $d, 'filenum' => $fn, 'directories' => array(), 'thumbnails' => array());
       
    95   foreach ($ds as $d) {
       
    96     $profile['directories'][] = array('name' => $d[0], 'subnav' => $d[1], 'browse' => $d[2], 'upload' => $d[3], 'thumb' => $d[4], 'delete' => $d[5], 'resize' => $d[6]);
       
    97   }
       
    98   foreach ($ts as $t) {
       
    99     $profile['thumbnails'][] = array('name' => $t[0], 'dimensions' => $t[1], 'prefix' => $t[2], 'suffix' => $t[3]);
       
   100   }
       
   101   return $profile;
       
   102 }
       
   103 
       
   104 /**
       
   105  * User1's profile.
       
   106  */
       
   107 function imce_user1_profile() {
       
   108   $profiles = variable_get('imce_profiles', array());
       
   109   return isset($profiles[1]) ? $profiles[1] : imce_construct_profile('User-1', 0, 0, 0, '*', '1200x1200', 0, array(array('.', 1, 1, 1, 1, 1, 1)), array(array('Small', '90x90', 'small_', ''), array('Medium', '120x120', 'medium_', ''), array('Large', '180x180', 'large_', '')));
       
   110 }
       
   111 
       
   112 /**
       
   113  * Default profile.
       
   114  */
       
   115 function imce_sample_profile() {
       
   116   return imce_construct_profile('Sample profile', 1, 2, 0, 'gif png jpg jpeg', '800x600', 1, array(array('u%uid', 0, 1, 1, 1, 0, 0)), array(array('Thumb', '90x90', 'thumb_', '')));
       
   117 }