[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/imce/inc/ -> imce.admin.inc (source)

   1  <?php
   2  // $Id: imce.admin.inc,v 1.1.2.3 2010/06/02 08:33:21 ufku Exp $
   3  
   4  /**
   5   * @file
   6   * Serves administration pages of IMCE.
   7   */
   8  
   9  /**
  10   * Admin main page.
  11   */
  12  function imce_admin() {
  13  
  14    $profiles = variable_get('imce_profiles', array());
  15  
  16    $header = array(t('Profile name'), array('data' => t('Operations'), 'colspan' => 2));
  17    $rows = array();
  18  
  19    foreach ($profiles as $pid => $profile) {
  20      $rows[] = array($profile['name'],
  21        l(t('Edit'), 'admin/settings/imce/profile/edit/'. $pid),
  22        $pid == 1 ? '' : l(t('Delete'), 'admin/settings/imce/profile/delete/'. $pid),
  23      );
  24    }
  25  
  26    $rows[] = array('', array('data' => l(t('Add new profile'), 'admin/settings/imce/profile'), 'colspan' => 2));
  27  
  28    $output = '<h2 class="title">'. t('Configuration profiles') .'</h2>';
  29    $output .= theme('table', $header, $rows);
  30    $output .= drupal_get_form('imce_admin_form');
  31  
  32    return $output;
  33  }
  34  
  35  /**
  36   * Admin form.
  37   */
  38  function imce_admin_form(&$form_state) {
  39    //roles profiles
  40    $form['roles'] = array('#tree' => TRUE);
  41    $roles = imce_sorted_roles();
  42    $form['#weighted'] = count($roles) > 3;
  43  
  44    foreach ($roles as $rid => $role) {
  45      $core = $rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID;
  46      $form['roles'][$rid] = imce_role_form($role, $form['#weighted'], $core);
  47    }
  48  
  49    //common settings
  50    $form['common'] = array(
  51      '#type' => 'fieldset',
  52      '#title' => t('Common settings'),
  53      '#collapsible' => TRUE,
  54      '#collapsed' => TRUE,
  55    );
  56    if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) {
  57      $form['common']['disable_private'] = array(
  58        '#type' => 'checkbox',
  59        '#title' => t('Disable serving of private files'),
  60        '#default_value' => variable_get('imce_settings_disable_private', 0),
  61        '#description' => t('By default IMCE serves all files under private files directory without applying any access restrictions. This allows anonymous access to any file(/system/files/filename) unless there is a module restricting access to the files. Here you can disable this default behavior.'),
  62      );
  63    }
  64    $form['common']['textarea'] = array(
  65      '#type' => 'textfield',
  66      '#title' => t('Enable inline image/file insertion into plain textareas'),
  67      '#default_value' => variable_get('imce_settings_textarea', ''),
  68      '#maxlength' => NULL,
  69      '#description' => t('If you don\'t use any WYSIWYG editor, this feature will allow you to add your images or files as <strong>html code into any plain textarea</strong>. Enter <strong>comma separated textarea IDs</strong> under which you want to enable a link to IMCE. Hint: ID of Body fields in most node types is edit-body.'),
  70    );
  71    $form['common']['absurls'] = array(
  72      '#type' => 'checkbox',
  73      '#title' => t('Absolute URLs'),
  74      '#default_value' => variable_get('imce_settings_absurls', 0),
  75      '#description' => t('Check if you want IMCE to return absolute file URLs.'),
  76    );
  77    $form['common']['replace'] = array(
  78      '#type' => 'radios',
  79      '#title' => t('Default behaviour for existing files during file uploads'),
  80      '#default_value' => variable_get('imce_settings_replace', FILE_EXISTS_RENAME),
  81      '#options' => array(
  82        FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'),
  83        FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'),
  84        FILE_EXISTS_REPLACE => t('Replace the existing file with the new one')
  85      ),
  86    );
  87    $form['common']['thumb_method'] = array(
  88      '#type' => 'radios',
  89      '#title' => t('Default method for creating thumbnails'),
  90      '#default_value' => variable_get('imce_settings_thumb_method', 'scale_and_crop'),
  91      '#options' => array(
  92        'scale' => t('Scale the image with respect to the thumbnail dimensions.'),
  93        'scale_and_crop' => t('First scale then crop the image to fit the thumbnail dimensions.')
  94      ),
  95    );
  96  
  97    $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
  98    $form['#theme'] = 'imce_admin';
  99    $form['#submit'][] = 'imce_admin_submit';
 100    return $form;
 101  }
 102  
 103  /**
 104   * Admin form themed.
 105   */
 106  function imce_admin_theme($form = array()) {
 107    $u1p = imce_user1_profile();
 108    $header = array(t('User role'), t('Assigned profile'));
 109    $keys = array('name', 'pid');
 110    $rows[0] = array(t('user #1'), $u1p['name']);
 111    $info = '';
 112  
 113    if ($form['#weighted']) {
 114      $header[] = t('Weight');
 115      $keys[] = 'weight';
 116      $rows[0][] = t('n/a');
 117      $info = t('For users who have <strong>multiple roles</strong>, <strong>weight</strong> property will determine the assigned profile. Lighter roles that are placed upper will take the precedence. So, an administrator role should be placed over other roles by having a smaller weight, ie. -10.');
 118    }
 119  
 120    foreach (element_children($form['roles']) as $rid) {
 121      $cells = array();
 122      foreach ($keys as $key) {
 123        $cells[] = drupal_render($form['roles'][$rid][$key]);
 124      }
 125      $rows[] = $cells;
 126    }
 127  
 128    $output = '<h2 class="title">'. t('Role-profile assignments') .'</h2>';
 129    $output .= theme('table', $header, $rows);
 130    $output .= '<div class="form-item"><div class="description">'. t('Assign profiles to user roles.') .' '. $info .'</div></div>';
 131    $output .= drupal_render($form['common']);
 132    $output .= drupal_render($form);
 133    return $output;
 134  }
 135  
 136  /**
 137   * Submit admin form.
 138   */
 139  function imce_admin_submit($form, &$form_state) {
 140    $roles = $form_state['values']['roles'];
 141    if (count($roles) > 3) {
 142      uasort($roles, 'imce_rolesort');
 143    }
 144    variable_set('imce_roles_profiles', $roles);
 145    variable_set('imce_settings_textarea', $form_state['values']['textarea']);
 146    variable_set('imce_settings_absurls', $form_state['values']['absurls']);
 147    variable_set('imce_settings_replace', $form_state['values']['replace']);
 148    variable_set('imce_settings_thumb_method', $form_state['values']['thumb_method']);
 149    if (isset($form_state['values']['disable_private'])) {
 150      variable_set('imce_settings_disable_private', $form_state['values']['disable_private']);
 151    }
 152    drupal_set_message(t('Changes have been saved.'));
 153  }
 154  
 155  /**
 156   * Add-Edit-Delete profiles.
 157   */
 158  function imce_profile_operations($op = 'add', $pid = 0) {
 159    //delete
 160    if ($op == 'delete') {
 161      drupal_set_title(t('Delete configuration profile'));
 162      return drupal_get_form('imce_profile_delete_form', $pid);
 163    }
 164    //add-edit
 165    if ($pid != 1 || $GLOBALS['user']->uid == 1) {
 166      return drupal_get_form('imce_profile_form', $pid);
 167    }
 168    drupal_access_denied();
 169  }
 170  
 171  /**
 172   * Profile form.
 173   */
 174  function imce_profile_form(&$form_state, $pid = 0) {
 175  
 176    if ($pid && $profile = imce_load_profile($pid)) {
 177      drupal_set_title($profile['name']);
 178    }
 179    else {
 180      $pid = 0;
 181      $profile = imce_sample_profile();
 182      $profile['name'] = '';
 183    }
 184  
 185    //import profile
 186    if (isset($_GET['import']) && $imported = imce_load_profile($_GET['import'])) {
 187      if (empty($form_state['post'])) {
 188        drupal_set_message(t('Settings were imported from the profile %name', array('%name' => $imported['name'])));
 189      }
 190      $imported['name'] = $profile['name']; //preserve the original name.
 191      $profile = $imported;
 192    }
 193  
 194    $form_state['profile'] = $profile;//store the original profile just in case.
 195  
 196    $form = array('#tree' => TRUE);
 197    $form['name'] = array(
 198      '#type' => 'textfield',
 199      '#title' => t('Profile name'),
 200      '#default_value' => $profile['name'],
 201      '#description' => t('Give a name to this profile.'),
 202      '#required' => TRUE,
 203    );
 204    $form['import'] = array(
 205      '#type' => 'markup',
 206      '#value' => imce_profile_import_html($pid),
 207    );
 208    $form['usertab'] = array(
 209      '#type' => 'checkbox',
 210      '#title' => t('Display file browser tab in user profile pages.'),
 211      '#default_value' => $profile['usertab'],
 212    );
 213    $form['filesize'] = array(
 214      '#type' => 'textfield',
 215      '#title' => t('Maximum file size per upload'),
 216      '#default_value' => $profile['filesize'],
 217      '#description' => t('Set to 0 to use the maximum value avaliable.') .' '. t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))),
 218      '#field_suffix' => t('MB'),
 219    );
 220    $form['quota'] = array(
 221      '#type' => 'textfield',
 222      '#title' => t('Directory quota'),
 223      '#default_value' => $profile['quota'],
 224      '#description' => t('Define the upload quota per directory. Total user quota is proportional to the number of directories that the user has upload access to.') .' '. t('Set to 0 to use the maximum value avaliable.'),
 225      '#field_suffix' => t('MB'),
 226    );
 227    $form['tuquota'] = array(
 228      '#type' => 'textfield',
 229      '#title' => t('Total user quota'),
 230      '#default_value' => $profile['tuquota'],
 231      '#description' => t('You can force total user quota to be a value independent of directory quota. <strong>This quota is calculated using the files table in the database, so that it will not include the files uploaded via FTP or by previous versions of IMCE(4.7.x and 5.x)</strong>. You can either use both quotations together or safely ignore this by setting the value to 0.'),
 232      '#field_suffix' => t('MB'),
 233    );
 234    $form['extensions'] = array(
 235      '#type' => 'textfield',
 236      '#title' => t('Permitted file extensions'),
 237      '#default_value' => $profile['extensions'],
 238      '#maxlength' => 255,
 239      '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.') .' '. t('Set to * to remove the restriction.'),
 240    );
 241    $form['dimensions'] = array(
 242      '#type' => 'textfield',
 243      '#title' => t('Maximum image resolution'),
 244      '#default_value' => $profile['dimensions'],
 245      '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0 for no restriction. If an <a href="!image-toolkit-link">image toolkit</a> is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/settings/image-toolkit'))),
 246      '#field_suffix' => '<kbd>'. t('WIDTHxHEIGHT') .'</kbd>'
 247    );
 248    $form['filenum'] = array(
 249      '#type' => 'textfield',
 250      '#title' => t('Maximum number of files per operation'),
 251      '#default_value' => $profile['filenum'],
 252      '#description' => t('You can allow users to select multiple files for operations such as delete, resize, etc. Entire batch file operation is executed in a single drupal load, which may be good. However there will be an increase in script execution time, cpu load and memory consumption possibly exceeding the limits of your server, which is really bad. For unlimited number of file handling, set this to 0.'),
 253    );
 254  
 255    //Directories
 256    $form['directories']['#theme'] = 'imce_directories';
 257    $form['directories']['#weight'] = 1;
 258    for ($i = 0; $i < count($profile['directories']); $i++) {
 259      $form['directories'][$i] = imce_directory_form($profile['directories'][$i]);
 260    }
 261    $form['directories'][$i] = imce_directory_form();
 262    $form['directories'][$i+1] = imce_directory_form();
 263  
 264    //Thumbnails
 265    $form['thumbnails']['#theme'] = 'imce_thumbnails';
 266    $form['thumbnails']['#weight'] = 2;
 267    for ($i = 0; $i < count($profile['thumbnails']); $i++) {
 268      $form['thumbnails'][$i] = imce_thumbnail_form($profile['thumbnails'][$i]);
 269    }
 270    $form['thumbnails'][$i] = imce_thumbnail_form();
 271    $form['thumbnails'][$i+1] = imce_thumbnail_form();
 272  
 273    $form = array('profile' => $form);
 274    $form['pid'] = array('#type' => 'hidden', '#value' => $pid);
 275    $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
 276    $form['#submit'][] = 'imce_profile_submit';
 277    return $form;
 278  }
 279  
 280  /**
 281   * Profile form submit.
 282   */
 283  function imce_profile_submit($form, &$form_state) {
 284    $profile = $form_state['values']['profile'];
 285    $pid = $form_state['values']['pid'];
 286    $message = $pid > 0 ? t('The changes have been saved.') : t('Profile has been added.');
 287  
 288    //unset empty fields of directories and thumbnails.
 289    imce_clean_profile_fields($profile);
 290  
 291    //save profile.
 292    $pid = imce_update_profiles($pid, $profile);
 293  
 294    drupal_set_message($message);
 295    $form_state['redirect'] = 'admin/settings/imce/profile/edit/'. $pid;
 296  }
 297  
 298  /**
 299   * directory settings form
 300   */
 301  function imce_directory_form($directory = array()) {
 302    if (empty($directory)) {
 303      $directory = array('name' => '', 'subnav' => 0, 'browse' => 0, 'upload' => 0, 'thumb' => 0, 'delete' => 0, 'resize' => 0);
 304    }
 305    $form['name'] = array(
 306      '#type' => 'textfield',
 307      '#default_value' => $directory['name'],
 308      '#size' => 24,
 309      '#maxlength' => NULL,
 310    );
 311    $form['subnav'] = array(
 312      '#type' => 'checkbox',
 313      '#title' => t('Including subdirectories'),
 314      '#default_value' => $directory['subnav'],
 315    );
 316    $form['browse'] = array(
 317      '#type' => 'checkbox',
 318      '#title' => t('Browse'),
 319      '#default_value' => $directory['browse'],
 320    );
 321    $form['upload'] = array(
 322      '#type' => 'checkbox',
 323      '#title' => t('Upload'),
 324      '#default_value' => $directory['upload'],
 325    );
 326    $form['thumb'] = array(
 327      '#type' => 'checkbox',
 328      '#title' => t('Thumbnails'),
 329      '#default_value' => $directory['thumb'],
 330    );
 331    $form['delete'] = array(
 332      '#type' => 'checkbox',
 333      '#title' => t('Delete'),
 334      '#default_value' => $directory['delete'],
 335    );
 336    $form['resize'] = array(
 337      '#type' => 'checkbox',
 338      '#title' => t('Resize'),
 339      '#default_value' => $directory['resize'],
 340    );
 341    return $form;
 342  }
 343  
 344  /**
 345   * Directorys form themed.
 346   */
 347  function imce_directories_theme($form = array()) {
 348    $rows = array();
 349    $root = file_directory_path();
 350  
 351    foreach (element_children($form) as $key) {
 352      //directory path
 353      $row = array('<div class="container-inline">'. $root .'/'. drupal_render($form[$key]['name']) .'</div>'. drupal_render($form[$key]['subnav']));
 354      unset($form[$key]['name'], $form[$key]['subnav']);
 355  
 356      //permissions
 357      $header = array();
 358      foreach (element_children($form[$key]) as $perm) {
 359        $header[] = $form[$key][$perm]['#title'];
 360        unset($form[$key][$perm]['#title']);
 361        $row[] = drupal_render($form[$key][$perm]);
 362      }
 363  
 364      $rows[] = $row;
 365    }
 366  
 367    array_unshift($header, t('Directory path'));
 368  
 369    $output = '<h3 class="title">'. t('Directories') .'</h3>';
 370    $output .= theme('table', $header, $rows);
 371    $output .= '<div class="form-item"><div class="description">'. t('Define directories that users of this profile can access.
 372  <ul>
 373      <li>Use alphanumeric characters as directory paths.</li>
 374      <li>To specify file system root, just enter <strong>.</strong>(dot) character.</li>
 375      <li>Use <strong>%uid</strong> as a placeholder for user ID. Ex: <em>users/user%uid</em> creates directories such as <em>users/user1</em>, <em>users/user42</em>, etc.</li>
 376    <li>To remove a directory from the list, leave the directory path blank.</li>
 377    <li>If you want more flexibility in directory paths you can execute php to return a directory path.<br />
 378    For php execution your directory path must start with <strong>php:</strong> and the rest must be a valid php code that is expected to return the actual directory path. <br />Ex: <strong>php: return \'users/\'.$user->name;</strong> defines <strong>users/USER-NAME</strong> as the directory path.<br />
 379    A multi-level directory example <strong>php: return date(\'Y\', $user->created).\'/\'.date(\'m\', $user->created).\'/\'.$user->uid;</strong> defines <strong>MEMBERSHIP-YEAR/MONTH/USER-ID</strong> as the directory path, resulting in self-categorized user directories based on membership date.<br />
 380    Note that you should use the $user variable instead of $GLOBALS[\'user\'] since they are not always the same object.</li>
 381  </ul>
 382  <p>Note that thumbnails permission does not affect thumbnail creation on upload. See thumbnails decription below.</p>
 383  <p>If you need more fields, just fill all and save, and you will get two more on the next page.</p>') .'</div></div>';
 384    $output .= drupal_render($form);
 385    return $output;
 386  }
 387  
 388  /**
 389   * thumbnail settings form
 390   */
 391  function imce_thumbnail_form($thumb = array()) {
 392    if (empty($thumb)) {
 393      $thumb = array('name' => '', 'dimensions' => '', 'prefix' => '', 'suffix' => '');
 394    }
 395    $form['name'] = array(
 396      '#type' => 'textfield',
 397      '#default_value' => $thumb['name'],
 398      '#size' => 20,
 399    );
 400    $form['dimensions'] = array(
 401      '#type' => 'textfield',
 402      '#default_value' => $thumb['dimensions'],
 403      '#size' => 20,
 404    );
 405    $form['prefix'] = array(
 406      '#type' => 'textfield',
 407      '#default_value' => $thumb['prefix'],
 408      '#size' => 20,
 409    );
 410    $form['suffix'] = array(
 411      '#type' => 'textfield',
 412      '#default_value' => $thumb['suffix'],
 413      '#size' => 20,
 414    );
 415    return $form;
 416  }
 417  
 418  /**
 419   * Thumbnails form themed.
 420   */
 421  function imce_thumbnails_theme($form = array()) {
 422    $header = array(t('Name'), t('Dimensions'), t('Prefix'), t('Suffix'));
 423    $rows = array();
 424  
 425    foreach (element_children($form) as $key) {
 426      $rows[] = array(
 427        drupal_render($form[$key]['name']),
 428        drupal_render($form[$key]['dimensions']),
 429        drupal_render($form[$key]['prefix']),
 430        drupal_render($form[$key]['suffix']),
 431      );
 432    }
 433  
 434    $output = '<h3 class="title">'. t('Thumbnails') .'</h3>';
 435    $output .= theme('table', $header, $rows);
 436    $output .= '<div class="form-item"><div class="description">'. t('You may create a list of thumbnail options that users can choose from.
 437  <ul>
 438    <li>Use alphanumeric characters as thumbnail names.</li>
 439    <li>Specify dimensions as <strong>WidthxHeight</strong>.</li>
 440    <li>Prefix and suffix are strings that are added to original file name to create the thumbnail name.</li>
 441    <li>An example thumbnail: Name = <strong>Small</strong>, Dimensions = <strong>80x80</strong>, Prefix = <strong>small_</strong></li>
 442  </ul>
 443  <p>Note that users will always be able to create thumbnails on file upload no matter what the thumbnail permission is. To disable thumbnail creation on file upload you should not define any thumbnails here.</p>
 444  <p>If you need more fields, just fill all and save, and you will get two more on the next page.</p>') .'</div></div>';
 445    $output .= drupal_render($form);
 446    return $output;
 447  }
 448  
 449  /**
 450   * Role-profile form
 451   */
 452  function imce_role_form($role, $weight = TRUE, $core = TRUE) {
 453    $form['name'] = array(
 454      '#type' => 'markup',
 455      '#value' => $role['name'],
 456    );
 457    if ($weight) {
 458      $form['weight'] = $core ? array(
 459        '#type' => 'textfield',
 460        '#value' => $role['weight'],
 461        '#attributes' => array('readonly' => 'readonly', 'style' => 'border: none; width: 2em; background-color: transparent;'),
 462      ) : array(
 463        '#type' => 'weight',
 464        '#default_value' => $role['weight'],
 465      );
 466    }
 467    $form['pid'] = array(
 468      '#type' => 'select',
 469      '#options' => imce_profile_options(),
 470      '#default_value' => $role['pid'],
 471    );
 472    return $form;
 473  }
 474  
 475  /**
 476   * Profile delete form
 477   */
 478  function imce_profile_delete_form(&$form_state, $pid) {
 479    if ($pid > 1 && $profile = imce_load_profile($pid)) {
 480      $form['#submit'][] = 'imce_profile_delete_submit';
 481      $form['pid'] = array('#type' => 'hidden', '#value' => $pid);
 482      return confirm_form($form,
 483        t('Are you sure you want to delete the profile %name?',
 484        array('%name' => $profile['name'])),
 485        'admin/settings/imce',
 486        '',
 487        t('Delete'),
 488        t('Cancel')
 489      );
 490    }
 491    drupal_goto('admin/settings/imce');
 492  }
 493  
 494  /**
 495   * Profile delete form submit
 496   */
 497  function imce_profile_delete_submit($form, &$form_state) {
 498    imce_update_profiles($form_state['values']['pid'], NULL);
 499    drupal_set_message(t('Profile has been deleted.'));
 500    $form_state['redirect'] = 'admin/settings/imce';
 501  }
 502  
 503  /**
 504   * Profile options.
 505   */
 506  function imce_profile_options() {
 507    $options = array(t('none'));
 508    foreach (variable_get('imce_profiles', array()) as $pid => $profile) {
 509      $options[$pid] = $profile['name'];
 510    }
 511    return $options;
 512  }
 513  
 514  /**
 515   * Profile import links.
 516   */
 517  function imce_profile_import_html($pid = 0) {
 518    $output = '';
 519    $links = array();
 520  
 521    foreach (variable_get('imce_profiles', array()) as $id => $profile) {
 522      if ($pid != $id) {
 523        $links[] = l($profile['name'], $_GET['q'], array('query' => 'import='. $id));
 524      }
 525    }
 526  
 527    if (!empty($links)) {
 528      $output = '<p><strong>'. t('Import settings from other profiles') .'</strong>: ';
 529      $output .= implode(', ', $links) .'</p>';
 530    }
 531  
 532    return $output;
 533  }
 534  
 535  /**
 536   * Update role-profile assignments.
 537   */
 538  function imce_update_roles($pid) {
 539    $roles = variable_get('imce_roles_profiles', array());
 540    foreach ($roles as $rid => $role) {
 541      if ($role['pid'] == $pid) {
 542        $roles[$rid]['pid'] = 0;
 543      }
 544      elseif ($role['pid'] > $pid) {
 545        $roles[$rid]['pid']--;
 546      }
 547    }
 548    variable_set('imce_roles_profiles', $roles);
 549  }
 550  
 551  /**
 552   * Add, update or delete a profile.
 553   */
 554  function imce_update_profiles($pid, $profile = NULL) {
 555    $profiles = variable_get('imce_profiles', array());
 556  
 557    //add or update
 558    if (isset($profile)) {
 559      $pid = isset($profiles[$pid]) ? $pid : count($profiles)+1;
 560      $profiles[$pid] = $profile;
 561    }
 562  
 563    //delete
 564    elseif (isset($profiles[$pid]) && $pid > 1) {
 565      unset($profiles[$pid]);
 566      for ($i = $pid+1; isset($profiles[$i]); $i++) {
 567        $profiles[$i-1] = $profiles[$i];
 568        unset($profiles[$i]);
 569      }
 570      imce_update_roles($pid);
 571    }
 572  
 573    variable_set('imce_profiles', $profiles);
 574    return $pid;
 575  }
 576  
 577  /**
 578   * Unset empty fields in thumbnails and directory paths.
 579   */
 580  function imce_clean_profile_fields(&$profile) {
 581    $clean = array();
 582    foreach ($profile['thumbnails'] as $thumb) {
 583      if (trim($thumb['name']) != '' && preg_match('/^\d+x\d+$/', $thumb['dimensions'])) {
 584        $clean[] = $thumb;
 585      }
 586    }
 587    $profile['thumbnails'] = $clean;
 588  
 589    $clean = array();
 590    $names = array();
 591    foreach ($profile['directories'] as $dir) {
 592      $dir['name'] = trim($dir['name'], '/ ');
 593      if ($dir['name'] == '') {
 594        continue;
 595      }
 596      if (isset($names[$dir['name']])) {
 597        drupal_set_message(t('Duplicate directory paths are not allowed.'), 'error');
 598        continue;
 599      }
 600      if (!imce_reg_dir($dir['name'])) {
 601        drupal_set_message(t('%dirname is not accepted as a proper directory name.', array('%dirname' => $dir['name'])), 'error');
 602        continue;
 603      }
 604      $clean[] = $dir;
 605      $names[$dir['name']] = 1;
 606    }
 607    $profile['directories'] = $clean;
 608  }
 609  
 610  /**
 611   * Profile load.
 612   */
 613  function imce_load_profile($pid) {
 614    $profiles = variable_get('imce_profiles', array());
 615    return isset($profiles[$pid]) ? $profiles[$pid] : NULL;
 616  }
 617  
 618  /**
 619   * Sort roles according to their weights.
 620   */
 621  function imce_sorted_roles() {
 622    static $sorted;
 623    if (!isset($sorted)) {
 624      $sorted = array();
 625      $roles = user_roles();
 626      $profiles = variable_get('imce_profiles', array());
 627      $irp = variable_get('imce_roles_profiles', array());
 628      $irp[DRUPAL_ANONYMOUS_RID]['weight'] = 12;
 629      $irp[DRUPAL_AUTHENTICATED_RID]['weight'] = 11;
 630      foreach ($roles as $rid => $rname) {
 631        $sorted[$rid] = array(
 632          'name' => $rname,
 633          'weight' => isset($irp[$rid]['weight']) ? $irp[$rid]['weight'] : 0,
 634          'pid' => isset($irp[$rid]['pid']) && isset($profiles[$irp[$rid]['pid']]) ? $irp[$rid]['pid'] : 0,
 635        );
 636      }
 637      uasort($sorted, 'imce_rolesort');
 638    }
 639    return $sorted;
 640  }
 641  
 642  /**
 643   * Sorting function for roles.
 644   */
 645  function imce_rolesort($r1, $r2) {
 646    return $r1['weight']-$r2['weight'];
 647  }
 648  
 649  //Include core profile functions.
 650  module_load_include('inc', 'imce', 'inc/imce.core.profiles');


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7