'.t('You can enable automatic thumbnail creation from newly uploaded images. To disable leave the fields blank.').'
',
);
$form['shared'] = array('#type' => 'textfield', '#title' => t('Your upload directory'), '#default_value' => $set->shared ? $set->shared : 'u1', '#description' => t('This directory must be relative to !filepath directory. So if you want to use !filepath/foldername, just enter foldername here. You may also enter / to use the file system root. If you leave it blank, u1 will be used.', array('!filepath' => file_directory_path())),
);
$form['extras'] = array('#type' => 'checkbox', '#title' => ''.t('Enable extras').'', '#default_value' => $set->extras, '#description' => t('This javascript package includes browsing enhancements like file sorting, keyboard shortcuts, file filtering, etc.'),
);
return $form;
}
$set = (object) imce_settings_role($rid);
$form['delete'] = array('#type' => 'checkbox',
'#title' => t('delete files'),
'#default_value' => $set->delete,
'#prefix' => '
'.t('Enable/disable access for file upload and deletion in user directories. Limitless upload disables controlling filesize, image dimensions and quota.').'
'.t('You can enable automatic thumbnail creation from newly uploaded images. To disable leave the fields blank.').'
',
);
$form['resize'] = array('#type' => 'checkbox',
'#title' => ''.t('Enable custom resizing.').'',
'#default_value' => $set->resize,
'#description' => t('Users will be able to resize their images to any size up to allowed dimensions.'),
);
$form['filesize'] = array('#type' => 'textfield',
'#title' => t('File size'),
'#default_value' => $set->filesize,
'#description' => t('Define the maximum file size(KB) for an image to be uploaded.'),
);
$form['quota'] = array('#type' => 'textfield',
'#title' => t('Upload quota'),
'#default_value' => $set->quota,
'#description' => t('Define the total upload quota(KB) per user.'),
);
$form['prefix'] = array('#type' => 'textfield',
'#title' => t('Prefix for personal folder names'),
'#default_value' => $set->prefix,
'#description' => t('Define the prefix that user IDs will be appended in order to create personal folders. Ex: entering "u" will result in folder names like u1, u14 etc. If you leave it blank, user IDs will be used as folder names.'),
);
$form['shared'] = array('#type' => 'textfield',
'#title' => t('Use a shared folder'),
'#default_value' => $set->shared,
'#description' => t('If you want all your users to use a common folder instead of personal folders, here you can define that folder name (ex. images). Notice that shared upload means shared quota. If you are happy with personal folders leave this field blank.'),
);
$form['subnav'] = array('#type' => 'checkbox',
'#title' => ''.t('Enable sub-folder navigation.').'',
'#default_value' => $set->subnav,
'#description' => t('This option allows users to manage multiple folders under their main folder. Only the users who have at least one sub-folder can use this feature.'),
);
$form['subdirs'] = array('#type' => 'textfield',
'#title' => t('Default sub-folder names'),
'#default_value' => $set->subdirs,
'#description' => t('Enter comma separated sub-folder names that will be created automatically, if the sub-folder navigation is enabled. Each user of this role will have these folders in their main folder by default. Additional folders can be created using !subfoldertool. You should note that total user quota increases with every new sub-folder because the quotation is per folder basis.', array('!subfoldertool' => l(t('Sub-folder tool'), 'admin/settings/imce/subfolder'))),
);
$form['extensions'] = array('#type' => 'textfield',
'#title' => t('Non-image file support'),
'#default_value' => $set->extensions,
'#description' => t('Although IMCE is mainly designed to browse images, it supports uploading and browsing of any file type. If you like to use this feature, define your allowed non-image file extensions here with a comma between them. Ex .doc, .pdf, .zip. Note that, image upload limits also apply for these files. For a pure image browser leave this field blank.'),
);
$form['extras'] = array('#type' => 'checkbox',
'#title' => ''.t('Enable extras').'',
'#default_value' => $set->extras,
'#description' => t('This javascript package includes browsing enhancements like file sorting, keyboard shortcuts, file filtering, etc.'),
);
return $form;
}
/**
* return the form for admin/settings/imce
*/
function imce_form_admin_form() {
$roles = imce_sorted_roles();
$form['#tree'] = TRUE;
$form['common'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#title' => t('Common settings'),);
$form['common']['tinymce'] = module_exists('tinymce') ? array('#type' => 'checkbox',//tinymce support
'#title' => ''.t('Enable tinyMCE support').'',
'#default_value' => variable_get('imce_settings_tinymce', 1),
'#description' => t('Make IMCE the default image/file browser for tinyMCE.'),
) : NULL;
$form['common']['fck'] = module_exists('fckeditor') ? array('#type' => 'checkbox',//fck support
'#title' => ''.t('Enable FCKEditor support').'',
'#default_value' => variable_get('imce_settings_fck', 0),
'#description' => t('Replace the built-in file browser of FCKeditor with IMCE.'),
) : NULL;
$form['common']['textarea'] = array('#type' => 'textfield',//plain textarea support
'#title' => t('Enable inline image/file insertion into plain textareas'),
'#default_value' => variable_get('imce_settings_textarea', ''),
'#maxlength' => 255,
'#description' => t('This feature allows you to add your images or files as html code into any plain textarea. This is useful especially when you dont use a wysiwyg editor such as tinyMCE or FCKeditor. Enter comma separated textarea IDs if you want to enable this feature. Otherwise, leave it blank. Hint: ID of Body fields in most node types is edit-body.'),
);
if (count($roles)>1) {//role precedence settings appear if there is more than 1 role.
$rids = $rtext = array();
foreach ($roles as $rid=>$name) {
$rids[] = $rid;
$rtext[] = ''.$rid.'-)'.$name;
}
$form['common']['rank'] = array('#type' => 'textfield',
'#title' => t('Role precedence'),
'#default_value' => implode('>', $rids),
'#description' => t('A user having multiple roles gets the permissions of the highest one. Sort role IDs according to their precedence from higher to lower by putting > in between. Here is the id-name pairs of roles having access to IMCE:').'
'.implode(', ', $rtext).'
',
);
}
if ($GLOBALS['user']->uid==1) {//user #1 settings.
$form['user1'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#title' => t('Settings for user #1'),) + imce_form_template('user1');
}
foreach ($roles as $rid=>$name) {//role settings
$form['roles'][$rid] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Settings for the role: !role', array('!role' => $name)),) + imce_form_template($rid);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'),);
return $form;
}
/**
* return the form for admin/settings/imce
*/
function imce_form_admin() {
return drupal_get_form('imce_form_admin_form');
}
/**
* Save settings. (Forms API -> formID_submit)
*/
function imce_form_admin_form_submit($form_id, $edit) {
if (isset($edit['common']['tinymce'])) {
variable_set('imce_settings_tinymce', $edit['common']['tinymce']);
}
if (isset($edit['common']['fck'])) {
variable_set('imce_settings_fck', $edit['common']['fck']);
}
if (isset($edit['common']['textarea'])) {
variable_set('imce_settings_textarea', $edit['common']['textarea']);
}
if (isset($edit['common']['rank'])) {
variable_set('imce_settings_rank', explode('>', str_replace(' ', '', $edit['common']['rank'])));
}
if (isset($edit['user1'])) {
variable_set('imce_settings_user1', $edit['user1']);
}
if (isset($edit['roles'])) {
variable_set('imce_settings_roles', $edit['roles']);
}
drupal_set_message(t('The changes have been saved.'));
}
/**
* Implementation of hook_file_download(). support for private downloads.
*/
function imce_file_download($file) {
$roles = variable_get('imce_settings_roles', array());
$roles += array('user1' => variable_get('imce_settings_user1', array()));
$roles += array('default' => imce_settings_default());
$imcefile = FALSE;
foreach ($roles as $rid=>$set) {
if ($set['shared']) {
if ($set['shared'] == '/' || strpos($file, $set['shared'].'/') === 0) {
$imcefile = TRUE;
break;
}
}
else {
if (preg_match("/^".str_replace(array('/', '-'), array('\/', '\-'), $set['prefix'])."[0-9]+\//", $file)) {
$imcefile = TRUE;
break;
}
}
}
if ($imcefile && ($path = file_create_path($file))) {
$ctype = ($info = @getimagesize($path)) ? $info['mime'] : (function_exists('mime_content_type') ? mime_content_type($path) : 'application/x-download');
return array('Content-type: '. $ctype);
}
}
/**
* Implementation of hook_elements().
*/
function imce_elements() {
$type = array();
if (($ids=str_replace(' ', '', variable_get('imce_settings_textarea', ''))) && user_access('access imce')) {
$type['textarea'] = array('#process' => array('imce_process_textarea' => array(explode(',', $ids))),);
}
return $type;
}
/**
* Inline image/link insertion to textareas.
*/
function imce_process_textarea($element, $edit=NULL, $ids=array()) {
if (in_array($element['#id'], $ids)) {
drupal_add_js(drupal_get_path('module', 'imce').'/imce_set_inline.js');
$element['#description'] .= '
'. t('Browse this user\'s files using !yours or !his', array('!yours' => l(t('your privileges'), 'imce/login/'.$acc->uid, array('target' => 'imce-frame')), '!his' => l(t('his/her privileges'), 'imce/login/'.$acc->uid.'/own', array('target' => 'imce-frame')))) .'
';
}
drupal_set_title($acc->name);
return $output;
}
/*
* Convert absolute paths to relative paths. return new path relative to the root.
*/
function imce_relative_path($path, $root=NULL) {
$abs = str_replace('\\', '/', realpath($path));
$root = str_replace('\\', '/', ($root ? realpath($root) : dirname(realpath($_SERVER['SCRIPT_FILENAME']))));
return strpos($abs, $root)===0 ? trim(substr($abs, strlen($root)), '/') : substr($abs, (($pos=strpos($abs, '/')) ? $pos : 0));
}
/*
* convert file path to relative url.
*/
function imce_relative_url($path='') {
if (variable_get('file_downloads', '')==FILE_DOWNLOADS_PRIVATE) {
$file = trim(substr($path, strlen(file_directory_path())), '\\/');
return url('system/files').(strlen($file) ? '/'.$file : '');
}
return base_path().$path;
}
/**
* return sub folder creation form
*/
function imce_form_subfolder_form() {
$form['help'] = array('#value' => t('
Here you can create sub-folders for your users. Multiple folder creation is possible at a time with the * character. For example, specifying user*/foo will create foo named folders under each folder starting with user. */foo*/bar will create bar named folders under folders starting with foo in each folder of file system path.