[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/imce/ -> imce.module (source)

   1  <?php
   2  // $Id: imce.module,v 1.24.2.8 2010/06/02 08:33:21 ufku Exp $
   3  
   4  /**
   5   * @file
   6   * Implements the necessary hooks for the file browser to work properly.
   7   */
   8  
   9  /**
  10   * Implementation of hook_menu().
  11   */
  12  function imce_menu() {
  13    $items = array();
  14    $access = array('administer imce(execute PHP)');
  15    $items['imce'] = array(
  16      'title' => 'File browser',
  17      'page callback' => 'imce',
  18      'access callback' => 'imce_access',
  19      'file' => 'inc/imce.page.inc',
  20      'type' => MENU_CALLBACK,
  21    );
  22    $items['user/%user/imce'] = array(
  23      'title' => 'File browser',
  24      'page callback' => 'imce_user_page',
  25      'page arguments' => array(1),
  26      'access callback' => 'imce_user_page_access',
  27      'access arguments' => array(1),
  28      'file' => 'inc/imce.page.inc',
  29      'type' => MENU_LOCAL_TASK,
  30      'weight' => 10,
  31    );
  32    $items['admin/settings/imce'] = array(
  33      'title' => 'IMCE',
  34      'description' => 'Control how your image/file browser works.',
  35      'page callback' => 'imce_admin',
  36      'access arguments' => $access,
  37      'file' => 'inc/imce.admin.inc',
  38    );
  39    $items['admin/settings/imce/profile'] = array(
  40      'title' => 'Add new profile',
  41      'page callback' => 'imce_profile_operations',
  42      'access arguments' => $access,
  43      'type' => MENU_CALLBACK,
  44      'file' => 'inc/imce.admin.inc',
  45    );
  46    return $items;
  47  }
  48  
  49  /**
  50   * Implementation of hook_perm().
  51   */
  52  function imce_perm() {
  53    return array('administer imce(execute PHP)');
  54  }
  55  
  56  /**
  57   * Implementation of hook_theme().
  58   */
  59  function imce_theme() {
  60    $path = drupal_get_path('module', 'imce') .'/tpl';
  61    $theme['imce_admin']['function'] = 'imce_admin_theme';
  62    $theme['imce_directories']['function'] = 'imce_directories_theme';
  63    $theme['imce_thumbnails']['function'] = 'imce_thumbnails_theme';
  64    $theme['imce_root_text'] = array(
  65      'arguments' => array('imce_ref' => NULL),
  66    );
  67    $theme['imce_user_page'] = array(
  68      'arguments' => array('account' => NULL),
  69    );
  70    $theme['imce_file_list'] = array(
  71      'template' => 'imce-file-list',
  72      'arguments' => array('imce_ref' => NULL),
  73      'path' => $path,
  74    );
  75    $theme['imce_content'] = array(
  76      'template' => 'imce-content',
  77      'arguments' => array('tree' => NULL, 'forms' => NULL, 'imce_ref' => NULL),
  78      'path' => $path,
  79    );
  80    $theme['imce_page'] = array(
  81      'template' => 'imce-page',
  82      'arguments' => array('content' => NULL),
  83      'path' => $path,
  84    );
  85    return $theme;
  86  }
  87  
  88  /**
  89   * Implementation of hook_file_download().
  90   */
  91  function imce_file_download($file) {
  92    $serve = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE && !variable_get('imce_settings_disable_private', 0) && ($path = file_create_path($file)) && file_exists($path) && strpos(basename($path), '.');
  93    if ($serve) {
  94      if ($result = db_result(db_query("SELECT filemime FROM {files} WHERE filepath = '%s'", $path))) {
  95        $type = $result;
  96      }
  97      elseif (function_exists('file_get_mimetype')) {
  98        $type = file_get_mimetype($path);
  99      }
 100      else {
 101        $type = 'application/x-download';
 102      }
 103      return array('Content-type: '. $type, 'Content-Length: '. filesize($path));
 104    }
 105  }
 106  
 107  /**
 108   * Implementation of hook_file_delete().
 109   */
 110  function imce_file_delete($file) {
 111    db_query('DELETE FROM {imce_files} WHERE fid = %d', $file->fid);
 112  }
 113  
 114  /**
 115   * Implementation of hook_file_references().
 116   */
 117  function imce_file_references($file) {
 118    //do not report reference count on internal file deletion
 119    if (isset($file->imce_noref) && $file->imce_noref) {
 120      return;
 121    }
 122    if (db_fetch_array(db_query('SELECT 1 FROM {imce_files} WHERE fid = %d', $file->fid))) {
 123      return array('imce' => 1);
 124    }
 125  }
 126  
 127  /**
 128   * Implementation of hook_elements().
 129   */
 130  function imce_elements() {
 131    return array('textarea' => array('#process' => array('imce_textarea')));
 132  }
 133  
 134  /**
 135   * Inline image/link insertion to textareas.
 136   */
 137  function imce_textarea($element) {
 138    static $ids;
 139    if (!isset($ids)) {
 140      $ids = FALSE;
 141      if (imce_access() && $setting = str_replace(' ', '', variable_get('imce_settings_textarea', ''))) {
 142        $ids = array();
 143        foreach (explode(',', $setting) as $id) {
 144          $ids[$id] = 1;
 145        }
 146      }
 147    }
 148    if ($ids && isset($ids[$element['#id']])) {
 149      drupal_add_js(drupal_get_path('module', 'imce') .'/js/imce_set_inline.js');
 150      $element['#description'] .= '<div class="imce-inline-wrapper" style="display:none">'. t('Insert !image or !link.', array('!image' => l(t('image'), 'imce', array('attributes' => array('name' => $element['#id'] .'-IMCE-image', 'class' => 'imce-inline-image'))), '!link' => l(t('link'), 'imce', array('attributes' => array('name' => $element['#id'] .'-IMCE-link', 'class' => 'imce-inline-link'))))) .'</div>';
 151    }
 152    return $element;
 153  }
 154  
 155  /**
 156   * Get the profile for the user.
 157   */
 158  function imce_user_profile($user) {
 159    $profiles = variable_get('imce_profiles', array());
 160    if ($user->uid == 1 && isset($profiles[1])) {
 161      return $profiles[1];
 162    }
 163    else {
 164      foreach (variable_get('imce_roles_profiles', array()) as $rid => $role) {
 165        if (isset($user->roles[$rid]) && isset($profiles[$role['pid']])) {
 166          return $profiles[$role['pid']];
 167        }
 168      }
 169    }
 170    return FALSE;
 171  }
 172  
 173  /**
 174   * Checks if the user has access to imce.
 175   */
 176  function imce_access($user = FALSE) {
 177    if ($user === FALSE) {
 178      global $user;
 179    }
 180  
 181    if ($user->uid == 1) {
 182      return TRUE;
 183    }
 184  
 185    $roles_profiles = variable_get('imce_roles_profiles', array());
 186    foreach ($user->roles as $rid => $name) {
 187      if (isset($roles_profiles[$rid]['pid']) && $roles_profiles[$rid]['pid']) {
 188        return TRUE;
 189      }
 190    }
 191  
 192    return FALSE;
 193  }
 194  
 195  /**
 196   * Checks access to user/{$account->uid}/imce for the $user.
 197   */
 198  function imce_user_page_access($account, $user = FALSE) {
 199    if ($user === FALSE) {
 200      global $user;
 201    }
 202  
 203    return ($user->uid == 1 || $account->uid == $user->uid) && ($profile = imce_user_profile($account)) && $profile['usertab'];
 204  }
 205  
 206  /**
 207   * Check if the directory name is regular.
 208   */
 209  function imce_reg_dir($dirname) {
 210    return $dirname == '.' || (is_string($dirname) && $dirname != '' && !preg_match('@(^\s)|(^/)|(^\./)|(\s$)|(/$)|(/\.$)|(\.\.)|(//)|(\\\\)|(/\./)@', $dirname));
 211  }


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