View source
<?php
define('IMCE_RENAME_REPLACE', 1001);
function imce_menu() {
$items = array();
$access = array(
'administer imce',
);
$items['imce'] = array(
'title' => 'File browser',
'page callback' => 'imce',
'access callback' => 'imce_access',
'access arguments' => array(
FALSE,
1,
),
'file' => 'inc/imce.page.inc',
'type' => MENU_CALLBACK,
);
$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/imce.page.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
$items['admin/config/media/imce'] = array(
'title' => 'IMCE',
'description' => 'Control how your image/file browser works.',
'page callback' => 'imce_admin',
'access arguments' => $access,
'file' => 'inc/imce.admin.inc',
);
if (variable_get('imce_settings_menu_link')) {
$items['admin/content/imce'] = array(
'title' => 'IMCE File Browser',
'description' => 'Admin File Browser',
'page callback' => 'imce_admin_file_browser',
'access arguments' => $access,
'file' => 'inc/imce.admin.inc',
);
}
$items['admin/config/media/imce/profile'] = array(
'title' => 'Add new profile',
'page callback' => 'imce_profile_operations',
'access arguments' => $access,
'type' => MENU_VISIBLE_IN_BREADCRUMB,
'file' => 'inc/imce.admin.inc',
);
return $items;
}
function imce_admin_paths() {
if (variable_get('imce_settings_admin_theme', FALSE)) {
return array(
'imce' => TRUE,
'imce/*' => TRUE,
'file/imce/*' => TRUE,
'imce-filefield/*' => TRUE,
);
}
}
function imce_permission() {
return array(
'administer imce' => array(
'title' => t('Administer IMCE'),
'restrict access' => TRUE,
),
);
}
function imce_theme() {
$path = drupal_get_path('module', 'imce') . '/tpl';
$theme['imce_admin'] = array(
'function' => 'imce_admin_theme',
'render element' => 'form',
);
$theme['imce_directories'] = array(
'function' => 'imce_directories_theme',
'render element' => 'form',
);
$theme['imce_thumbnails'] = array(
'function' => 'imce_thumbnails_theme',
'render element' => 'form',
);
$theme['imce_root_text'] = array(
'variables' => array(
'imce_ref' => NULL,
),
);
$theme['imce_user_page'] = array(
'variables' => array(
'account' => NULL,
),
);
$theme['imce_file_list'] = array(
'template' => 'imce-file-list',
'variables' => array(
'imce_ref' => NULL,
),
'path' => $path,
);
$theme['imce_content'] = array(
'template' => 'imce-content',
'variables' => array(
'tree' => NULL,
'forms' => NULL,
'imce_ref' => NULL,
),
'path' => $path,
);
$theme['imce_page'] = array(
'template' => 'imce-page',
'variables' => array(
'content' => NULL,
),
'path' => $path,
);
return $theme;
}
function imce_file_download($uri) {
$serve = file_uri_scheme($uri) == 'private' && !variable_get('imce_settings_disable_private', 1) && file_exists($uri) && strpos(basename($uri), '.');
if ($serve) {
return array(
'Content-type' => file_get_mimetype($uri),
'Content-Length' => filesize($uri),
);
}
}
function imce_element_info() {
return array(
'textarea' => array(
'#process' => array(
'imce_textarea',
),
),
);
}
function imce_textarea($element) {
static $regexp;
if (!isset($regexp)) {
$regexp = FALSE;
if (imce_access() && ($regexp = str_replace(' ', '', variable_get('imce_settings_textarea', '')))) {
$regexp = '@^(' . str_replace(',', '|', implode('.*', array_map('preg_quote', explode('*', $regexp)))) . ')$@';
}
}
if ($regexp && preg_match($regexp, $element['#id'])) {
drupal_add_js(drupal_get_path('module', 'imce') . '/js/imce_set_inline.js');
$arrayAtributtes = array(
'!image' => l(t('image'), 'imce', array(
'attributes' => array(
'name' => $element['#id'] . '-IMCE-image',
'class' => array(
'imce-inline-image',
),
),
)),
'!link' => l(t('link'), 'imce', array(
'attributes' => array(
'name' => $element['#id'] . '-IMCE-link',
'class' => array(
'imce-inline-link',
),
),
)),
);
$element['#description'] = (isset($element['#description']) ? $element['#description'] : '') . '<div class="imce-inline-wrapper" style="display:none">' . t('Insert !image or !link.', $arrayAtributtes) . '</div>';
}
return $element;
}
function imce_user_profile($user, $scheme = NULL) {
static $ups = array();
if (empty($scheme)) {
$scheme = variable_get('file_default_scheme', 'public');
}
if (isset($ups[$scheme][$user->uid])) {
return $ups[$scheme][$user->uid];
}
$ups[$scheme][$user->uid] = FALSE;
$swrappers = file_get_stream_wrappers();
if (!isset($swrappers[$scheme])) {
return FALSE;
}
$profiles = variable_get('imce_profiles', array());
$scinfo = array(
'scheme' => $scheme,
);
if ($user->uid == 1) {
return $ups[$scheme][$user->uid] = isset($profiles[1]) ? $profiles[1] + $scinfo : FALSE;
}
$roles_profiles = variable_get('imce_roles_profiles', array());
$sckey = $scheme . '_pid';
foreach ($roles_profiles as $rid => $conf) {
if (isset($user->roles[$rid]) && isset($conf[$sckey]) && isset($profiles[$conf[$sckey]])) {
return $ups[$scheme][$user->uid] = $profiles[$conf[$sckey]] + $scinfo;
}
}
return FALSE;
}
function imce_access($user = FALSE, $scheme = NULL) {
if ($user === FALSE) {
global $user;
}
return imce_user_profile($user, $scheme) ? TRUE : 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($account)) && $profile['usertab'];
}
function imce_reg_dir($dirname) {
return $dirname == '.' || is_int($dirname) || is_string($dirname) && $dirname != '' && !preg_match('@(^\\s)|(^/)|(^\\./)|(\\s$)|(/$)|(/\\.$)|(\\.\\.)|(//)|(\\\\)|(/\\./)@', $dirname);
}