View source
<?php
function imce_menu() {
$items = array();
$access = array(
'administer imce(execute PHP)',
);
$items['imce'] = array(
'title' => 'File browser',
'page callback' => 'imce_page',
'access callback' => 'imce_access',
'file' => 'inc/page.inc',
'type' => MENU_CALLBACK,
);
$items['admin/settings/imce'] = array(
'title' => 'IMCE',
'description' => 'Control how your image/file browser works.',
'page callback' => 'imce_admin',
'access arguments' => $access,
'file' => 'inc/admin.inc',
);
$items['admin/settings/imce/profiles'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/settings/imce/subdirectory'] = array(
'title' => 'Directory creation tool',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'imce_form_subdirectory',
),
'access arguments' => $access,
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'file' => 'inc/subdir.inc',
);
$items['admin/settings/imce/profile'] = array(
'title' => 'Add new profile',
'page callback' => 'imce_profile_operations',
'access arguments' => $access,
'type' => MENU_CALLBACK,
'file' => 'inc/admin.inc',
);
$items['user/%user/imce'] = array(
'title' => 'File browser',
'page callback' => 'imce_user_page',
'page arguments' => array(
1,
),
'access callback' => 'imce_user_page_access',
'access arguments' => array(
1,
),
'file' => 'inc/page.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
return $items;
}
function imce_perm() {
return array(
'administer imce(execute PHP)',
);
}
function imce_theme() {
$path = drupal_get_path('module', 'imce') . '/tpl';
$theme['imce_admin']['function'] = 'imce_admin_theme';
$theme['imce_directories']['function'] = 'imce_directories_theme';
$theme['imce_thumbnails']['function'] = 'imce_thumbnails_theme';
$theme['imce_file_list'] = array(
'template' => 'imce-file-list',
'arguments' => array(
'imce_ref' => NULL,
),
'path' => $path,
);
$theme['imce_content'] = array(
'template' => 'imce-content',
'arguments' => array(
'tree' => NULL,
'forms' => NULL,
'imce_ref' => NULL,
),
'path' => $path,
);
$theme['imce_page'] = array(
'template' => 'imce-page',
'arguments' => array(
'content' => NULL,
),
'path' => $path,
);
return $theme;
}
function imce_file_download($file) {
$serve = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE && !variable_get('imce_settings_disable_private', 0) && ($path = file_create_path($file)) && file_exists($path);
if ($serve) {
if ($result = db_result(db_query("SELECT filemime FROM {files} WHERE filepath = '%s'", $path))) {
$type = $result;
}
elseif (function_exists('file_get_mimetype')) {
$type = file_get_mimetype($path);
}
else {
$type = 'application/x-download';
}
return array(
'Content-type: ' . $type,
'Content-Length: ' . filesize($path),
);
}
}
function imce_elements() {
return array(
'textarea' => array(
'#process' => array(
'imce_textarea',
),
),
);
}
function imce_textarea($element) {
static $ids;
if (!isset($ids)) {
$ids = FALSE;
if (imce_access() && ($setting = str_replace(' ', '', variable_get('imce_settings_textarea', '')))) {
$ids = array();
foreach (explode(',', $setting) as $id) {
$ids[$id] = 1;
}
}
}
if ($ids && isset($ids[$element['#id']])) {
drupal_add_js(drupal_get_path('module', 'imce') . '/js/imce_set_inline.js');
$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>';
}
return $element;
}
function imce_user_profile($user) {
$profiles = variable_get('imce_profiles', array());
if ($user->uid == 1 && isset($profiles[1])) {
return $profiles[1];
}
else {
foreach (variable_get('imce_roles_profiles', array()) as $rid => $role) {
if (isset($user->roles[$rid]) && isset($profiles[$role['pid']])) {
return $profiles[$role['pid']];
}
}
}
return FALSE;
}
function imce_access($user = FALSE) {
if ($user === FALSE) {
global $user;
}
if ($user->uid == 1) {
return TRUE;
}
$roles_profiles = variable_get('imce_roles_profiles', array());
foreach ($user->roles as $rid => $name) {
if (isset($roles_profiles[$rid]['pid']) && $roles_profiles[$rid]['pid']) {
return TRUE;
}
}
return FALSE;
}
function imce_user_page_access($account, $user = FALSE) {
if ($user === FALSE) {
global $user;
}
return $user->uid == 1 || $account->uid == $user->uid && ($profile = imce_user_profile($user)) && $profile['usertab'];
}
function imce_reg_dir($dirname) {
return $dirname == '.' || is_string($dirname) && $dirname != '' && !preg_match('@(^\\s)|(^/)|(^\\./)|(\\s$)|(/$)|(/\\.$)|(\\.\\.)|(//)|(\\\\)|(/\\./)@', $dirname);
}