imce_mkdir.module 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Implements hook_form_formID_alter().
  4. */
  5. function imce_mkdir_form_imce_profile_form_alter(&$form, &$form_state) {
  6. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'imce_mkdir') . '/imce_mkdir.inc';
  7. return _imce_mkdir_form_imce_profile_form_alter($form, $form_state);
  8. }
  9. /**
  10. * Custom profile process. Redefines mkdir permission based on some other parameters.
  11. */
  12. function imce_mkdir_process_profile(&$imce) {
  13. if (!$imce['error']) {
  14. $imce['mkdirnum'] = (int) $imce['mkdirnum'];
  15. $imce['perm']['mkdir'] = $imce['perm']['mkdir'] && (!$imce['mkdirnum'] || ($imce['direct'] && $imce['mkdirnum'] > count($imce['subdirectories'])));
  16. $imce['perm']['rmdir'] = $imce['perm']['rmdir'] && (!$imce['mkdirnum'] || $imce['direct']);
  17. }
  18. }
  19. /**
  20. * Custom content. Returns directory creation form
  21. */
  22. function imce_mkdir_content(&$imce) {
  23. if (!$imce['error'] && (imce_perm_exists($imce, 'mkdir') || imce_perm_exists($imce, 'rmdir'))) {
  24. $path = drupal_get_path('module', 'imce_mkdir');
  25. drupal_add_js($path . '/imce_mkdir.js');
  26. drupal_add_css($path . '/imce_mkdir.css');
  27. $form = drupal_get_form('imce_mkdir_form', array('imce' => &$imce));
  28. return drupal_render($form);
  29. }
  30. }
  31. /**
  32. * Mkdir form.
  33. */
  34. function imce_mkdir_form($form, &$form_state, $ref) {
  35. $imce =& $ref['imce'];
  36. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'imce_mkdir') . '/imce_mkdir.inc';
  37. return _imce_mkdir_form($form, $form_state, $imce);
  38. }
  39. /**
  40. * Ajax operation: mkdir
  41. */
  42. function imce_js_mkdir(&$imce) {
  43. if ($imce['perm']['mkdir']) {
  44. $_POST['op'] = t('Add');
  45. drupal_get_form('imce_mkdir_form', array('imce' => &$imce));
  46. return array('diradded' => array_map('rawurlencode', $imce['diradded']));
  47. }
  48. }
  49. /**
  50. * Ajax operation: rmdir
  51. */
  52. function imce_js_rmdir(&$imce) {
  53. if ($imce['perm']['rmdir']) {
  54. $_POST['op'] = t('Remove');
  55. drupal_get_form('imce_mkdir_form', array('imce' => &$imce));
  56. return array('dirremoved' => array_map('rawurlencode', $imce['dirremoved']));
  57. }
  58. }