--- a/imce.module
+++ b/imce.module
@@ -19,16 +19,30 @@ function imce_menu() {
'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,
- );
+ if (0 === variable_get('imce_settings_link_custom', 0)) {
+ // Default menu link
+ $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,
+ );
+ }
+ else {
+ // Custom menu link
+ $items[variable_get('imce_settings_link_path', 'admin/content/imce')] = array(
+ 'title' => variable_get('imce_settings_link_title', 'File browser'),
+ 'page callback' => 'imce_user_page',
+ 'access callback' => 'imce_user_page_access',
+ 'file' => 'inc/imce.page.inc',
+ 'type' => variable_get('imce_settings_link_type', MENU_LOCAL_TASK),
+ 'weight' => 10,
+ );
+ }
$items['admin/config/media/imce'] = array(
'title' => 'IMCE',
'description' => 'Control how your image/file browser works.',
@@ -186,10 +200,13 @@ function imce_access($user = FALSE, $sch
/**
* Checks access to user/{$account->uid}/imce for the $user.
*/
-function imce_user_page_access($account, $user = FALSE) {
+function imce_user_page_access($account = FALSE, $user = FALSE) {
if ($user === FALSE) {
global $user;
}
+ if ($account === FALSE) {
+ $account = $user;
+ }
return ($user->uid == 1 || $account->uid == $user->uid) && ($profile = imce_user_profile($account)) && $profile['usertab'];
}
--- a/inc/imce.admin.inc
+++ b/inc/imce.admin.inc
@@ -96,6 +96,42 @@ function imce_admin_form($form, &$form_s
'#default_value' => variable_get('imce_settings_disable_private', 1),
'#description' => t('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 feature.'),
);
+ $form['common']['link_custom'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use a custom menu link'),
+ '#description' => t('Replaces user/%user/imce
with a custom link. Note: when using a custom menu link, there is no way for a user to access the file browser in another account.'),
+ '#default_value' => variable_get('imce_settings_link_custom', 0),
+ );
+ $form['common']['link'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Custom link'),
+ '#states' => array(
+ 'enabled' => array(
+ ':input[name="link_custom"]' => array('checked' => true),
+ ),
+ ),
+ );
+ $form['common']['link']['link_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Menu link title'),
+ '#description' => t('Defaults to "File browser".'),
+ '#default_value' => variable_get('imce_settings_link_title', ''),
+ );
+ $form['common']['link']['link_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Menu link placement'),
+ '#description' => t('Defaults to admin/content/imce
.'),
+ '#default_value' => variable_get('imce_settings_link_path', ''),
+ );
+ $form['common']['link']['link_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Menu link type'),
+ '#options' => array(
+ MENU_LOCAL_TASK => t('Menu tab'),
+ MENU_CALLBACK => t('Menu link'),
+ ),
+ '#default_value' => variable_get('imce_settings_link_type', MENU_LOCAL_TASK),
+ );
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
$form['#theme'] = 'imce_admin';
@@ -159,7 +195,12 @@ function imce_admin_submit($form, &$form
variable_set('imce_settings_replace', $form_state['values']['replace']);
variable_set('imce_settings_thumb_method', $form_state['values']['thumb_method']);
variable_set('imce_settings_disable_private', $form_state['values']['disable_private']);
+ variable_set('imce_settings_link_custom', $form_state['values']['link_custom']);
+ variable_set('imce_settings_link_title', $form_state['values']['link_title']);
+ variable_set('imce_settings_link_path', $form_state['values']['link_path']);
+ variable_set('imce_settings_link_type', $form_state['values']['link_type']);
drupal_set_message(t('Changes have been saved.'));
+ menu_cache_clear_all();
}
/**
--- a/inc/imce.page.inc
+++ b/inc/imce.page.inc
@@ -19,7 +19,11 @@ function imce($scheme = NULL) {
/**
* q = user/x/imce.
*/
-function imce_user_page($account) {
+function imce_user_page($account = FALSE) {
+ if ($account === FALSE) {
+ global $user;
+ $account = $user;
+ }
return theme('imce_user_page', array('account' => $account));
}