imce.admin.inc

  1. cis7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  2. cle7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  3. ecd7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  4. elmsmedia7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  5. harmony7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  6. icor7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  7. meedjum_blog7 sites/all/modules/ulmus/imce/inc/imce.admin.inc
  8. mooc7 sites/all/modules/ulmus/imce/inc/imce.admin.inc

Serves administration pages of IMCE.

Functions

Namesort descending Description
imce_admin Admin main page.
imce_admin_form Admin form.
imce_admin_submit Submit admin form.
imce_admin_theme Admin form themed.
imce_clean_profile_fields Unset empty fields in thumbnails and directory paths.
imce_directories_theme Directorys form themed.
imce_directory_form directory settings form
imce_load_profile Profile load.
imce_profile_delete_form Profile delete form
imce_profile_delete_submit Profile delete form submit
imce_profile_form Profile form.
imce_profile_import_html Profile import links.
imce_profile_operations Add-Edit-Delete profiles.
imce_profile_options Profile options.
imce_profile_submit Profile form submit.
imce_profile_validate Profile form validate.
imce_rolesort Sorting function for roles.
imce_role_form Role-profile form
imce_sorted_roles Sort roles according to their weights.
imce_thumbnails_theme Thumbnails form themed.
imce_thumbnail_form thumbnail settings form
imce_update_profiles Add, update or delete a profile.
imce_update_roles Update role-profile assignments.

File

sites/all/modules/ulmus/imce/inc/imce.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Serves administration pages of IMCE.
  5. */
  6. /**
  7. * Admin main page.
  8. */
  9. function imce_admin() {
  10. $profiles = variable_get('imce_profiles', array());
  11. $header = array(t('Profile name'), array('data' => t('Operations'), 'colspan' => 2));
  12. $rows = array();
  13. foreach ($profiles as $pid => $profile) {
  14. $rows[] = array(
  15. check_plain($profile['name']),
  16. l(t('Edit'), 'admin/config/media/imce/profile/edit/' . $pid),
  17. $pid == 1 ? '' : l(t('Delete'), 'admin/config/media/imce/profile/delete/' . $pid),
  18. );
  19. }
  20. $rows[] = array('', array('data' => l(t('Add new profile'), 'admin/config/media/imce/profile'), 'colspan' => 2));
  21. $output['title'] = array(
  22. '#markup' => '<h2 class="title">' . t('Configuration profiles') . '</h2>',
  23. );
  24. $output['table'] = array(
  25. '#theme' => 'table',
  26. '#header' => $header,
  27. '#rows' => $rows,
  28. '#attributes' => array('id' => 'imce-profiles-list'),
  29. );
  30. $output['form'] = drupal_get_form('imce_admin_form');
  31. return $output;
  32. }
  33. /**
  34. * Admin form.
  35. */
  36. function imce_admin_form($form, &$form_state) {
  37. //roles profiles
  38. $form['roles'] = array('#tree' => TRUE);
  39. $roles = imce_sorted_roles();
  40. $form['#weighted'] = count($roles) > 3;
  41. foreach ($roles as $rid => $role) {
  42. $core = $rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID;
  43. $form['roles'][$rid] = imce_role_form($role, $form['#weighted'], $core);
  44. }
  45. //common settings
  46. $form['common'] = array(
  47. '#type' => 'fieldset',
  48. '#title' => t('Common settings'),
  49. '#collapsible' => TRUE,
  50. '#collapsed' => TRUE,
  51. );
  52. $form['common']['textarea'] = array(
  53. '#type' => 'textfield',
  54. '#title' => t('Enable inline image/file insertion into plain textareas'),
  55. '#default_value' => variable_get('imce_settings_textarea', ''),
  56. '#maxlength' => NULL,
  57. '#description' => t('If you don\'t use any WYSIWYG editor, this feature will allow you to add your images or files as <strong>html code into any plain textarea</strong>. Enter <strong>comma separated textarea IDs</strong> under which you want to enable a link to IMCE. The * character is a wildcard. Hint: ID of Body fields in most node types starts with edit-body*.'),
  58. );
  59. $form['common']['absurls'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Absolute URLs'),
  62. '#default_value' => variable_get('imce_settings_absurls', 0),
  63. '#description' => t('Check if you want IMCE to return absolute file URLs.'),
  64. );
  65. $form['common']['replace'] = array(
  66. '#type' => 'radios',
  67. '#title' => t('Default behaviour for existing files during file uploads'),
  68. '#default_value' => variable_get('imce_settings_replace', FILE_EXISTS_RENAME),
  69. '#options' => array(
  70. FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'),
  71. FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'),
  72. FILE_EXISTS_REPLACE => t('Replace the existing file with the new one')
  73. ),
  74. );
  75. $form['common']['thumb_method'] = array(
  76. '#type' => 'radios',
  77. '#title' => t('Default method for creating thumbnails'),
  78. '#default_value' => variable_get('imce_settings_thumb_method', 'scale_and_crop'),
  79. '#options' => array(
  80. 'scale' => t('Scale the image with respect to the thumbnail dimensions.'),
  81. 'scale_and_crop' => t('First scale then crop the image to fit the thumbnail dimensions.')
  82. ),
  83. );
  84. $form['common']['disable_private'] = array(
  85. '#type' => 'checkbox',
  86. '#title' => t('Disable serving of private files'),
  87. '#default_value' => variable_get('imce_settings_disable_private', 1),
  88. '#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.'),
  89. );
  90. $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
  91. $form['#theme'] = 'imce_admin';
  92. $form['#submit'][] = 'imce_admin_submit';
  93. return $form;
  94. }
  95. /**
  96. * Admin form themed.
  97. */
  98. function imce_admin_theme($variables) {
  99. $form = $variables['form'];
  100. $profile1 = imce_user1_profile();
  101. $header = array(t('User role'));
  102. $rows = array(array(t('Site maintenance account')));
  103. $keys = array('name');
  104. //add each stream wrapper as a column
  105. $swrappers = file_get_stream_wrappers(STREAM_WRAPPERS_VISIBLE);
  106. foreach ($swrappers as $scheme => $info) {
  107. $header[] = l($info['name'], 'imce/' . $scheme);
  108. $rows[0][] = check_plain($profile1['name']);
  109. $keys[] = $scheme . '_pid';
  110. }
  111. //in case we need profile weights.
  112. $weight_info = '';
  113. if ($form['#weighted']) {
  114. $header[] = t('Weight');
  115. $rows[0][] = t('n/a');
  116. $keys[] = 'weight';
  117. $weight_info = t('For users who have <strong>multiple roles</strong>, the <strong>weight</strong> property will determine the assigned profile. Lighter roles that are placed upper will take the precedence. So, an administrator role should be placed over other roles by having a smaller weight, ie. -10.');
  118. }
  119. foreach (element_children($form['roles']) as $rid) {
  120. $cells = array();
  121. foreach ($keys as $key) {
  122. $cells[] = drupal_render($form['roles'][$rid][$key]);
  123. }
  124. $rows[] = $cells;
  125. }
  126. $output = '<h2 class="title">' . t('Role-profile assignments') . '</h2>';
  127. $output .= theme('table', array('header' => $header, 'rows' => $rows));
  128. $output .= '<div class="form-item"><div class="description">' . t('Assign profiles to user roles for available file systems. Your default file system is %name.', array('%name' => $swrappers[variable_get('file_default_scheme', 'public')]['name'])) . ' ' . $weight_info . '</div></div>';
  129. $output .= drupal_render($form['common']);
  130. $output .= drupal_render_children($form);
  131. return $output;
  132. }
  133. /**
  134. * Submit admin form.
  135. */
  136. function imce_admin_submit($form, &$form_state) {
  137. $roles = $form_state['values']['roles'];
  138. if (count($roles) > 3) {
  139. uasort($roles, 'imce_rolesort');
  140. }
  141. variable_set('imce_roles_profiles', $roles);
  142. variable_set('imce_settings_textarea', $form_state['values']['textarea']);
  143. variable_set('imce_settings_absurls', $form_state['values']['absurls']);
  144. variable_set('imce_settings_replace', $form_state['values']['replace']);
  145. variable_set('imce_settings_thumb_method', $form_state['values']['thumb_method']);
  146. variable_set('imce_settings_disable_private', $form_state['values']['disable_private']);
  147. drupal_set_message(t('Changes have been saved.'));
  148. }
  149. /**
  150. * Add-Edit-Delete profiles.
  151. */
  152. function imce_profile_operations($op = 'add', $pid = 0) {
  153. //delete
  154. if ($op == 'delete') {
  155. drupal_set_title(t('Delete configuration profile'));
  156. return drupal_get_form('imce_profile_delete_form', $pid);
  157. }
  158. //add-edit
  159. if ($pid != 1 || $GLOBALS['user']->uid == 1) {
  160. return drupal_get_form('imce_profile_form', $pid);
  161. }
  162. drupal_access_denied();
  163. }
  164. /**
  165. * Profile form.
  166. */
  167. function imce_profile_form($form, &$form_state, $pid = 0) {
  168. if ($pid && $profile = imce_load_profile($pid)) {
  169. drupal_set_title($profile['name']);
  170. }
  171. else {
  172. $pid = 0;
  173. $profile = imce_sample_profile();
  174. $profile['name'] = '';
  175. }
  176. //import profile
  177. if (isset($_GET['import']) && $imported = imce_load_profile($_GET['import'])) {
  178. if (empty($form_state['post'])) {
  179. drupal_set_message(t('Settings were imported from the profile %name', array('%name' => $imported['name'])));
  180. }
  181. $imported['name'] = $profile['name']; //preserve the original name.
  182. $profile = $imported;
  183. }
  184. $form_state['profile'] = $profile;//store the original profile just in case.
  185. $form = array('#tree' => TRUE);
  186. $form['name'] = array(
  187. '#type' => 'textfield',
  188. '#title' => t('Profile name'),
  189. '#default_value' => $profile['name'],
  190. '#description' => t('Give a name to this profile.'),
  191. '#required' => TRUE,
  192. );
  193. $form['import'] = array(
  194. '#markup' => imce_profile_import_html($pid),
  195. );
  196. $form['usertab'] = array(
  197. '#type' => 'checkbox',
  198. '#title' => t('Display file browser tab in user profile pages.'),
  199. '#default_value' => $profile['usertab'],
  200. );
  201. $form['filesize'] = array(
  202. '#type' => 'textfield',
  203. '#title' => t('Maximum file size per upload'),
  204. '#default_value' => $profile['filesize'],
  205. '#description' => t('Set to 0 to use the maximum value avaliable.') . ' ' . t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))),
  206. '#field_suffix' => t('MB'),
  207. );
  208. $form['quota'] = array(
  209. '#type' => 'textfield',
  210. '#title' => t('Directory quota'),
  211. '#default_value' => $profile['quota'],
  212. '#description' => t('Define the upload quota per directory.') . ' ' . t('Set to 0 to use the maximum value avaliable.'),
  213. '#field_suffix' => t('MB'),
  214. );
  215. $form['tuquota'] = array(
  216. '#type' => 'textfield',
  217. '#title' => t('Total user quota'),
  218. '#default_value' => $profile['tuquota'],
  219. '#description' => t('This quota measures the size of all user uploaded files in the database and does not include FTP files. You can either use both quotations together or safely ignore this by setting the value to 0.'),
  220. '#field_suffix' => t('MB'),
  221. );
  222. $form['extensions'] = array(
  223. '#type' => 'textfield',
  224. '#title' => t('Permitted file extensions'),
  225. '#default_value' => $profile['extensions'],
  226. '#maxlength' => 255,
  227. '#description' => t('Specify the allowed file extensions for uploaded files. Separate extensions with a space and do not include the leading dot.') . ' ' . t('Set to * to remove the restriction.'),
  228. );
  229. $form['dimensions'] = array(
  230. '#type' => 'textfield',
  231. '#title' => t('Maximum image dimensions'),
  232. '#default_value' => $profile['dimensions'],
  233. '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0 for no restriction. If an <a href="!image-toolkit-link">image toolkit</a> is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/config/media/image-toolkit'))),
  234. '#field_suffix' => '<kbd>' . t('WIDTHxHEIGHT') . '</kbd>',
  235. );
  236. $form['filenum'] = array(
  237. '#type' => 'textfield',
  238. '#title' => t('Maximum number of files per operation'),
  239. '#default_value' => $profile['filenum'],
  240. '#description' => t('You can allow users to select multiple files for operations such as delete, resize, etc. Entire batch file operation is executed in a single drupal load, which may be good. However there will be an increase in script execution time, cpu load and memory consumption possibly exceeding the limits of your server, which is really bad. For unlimited number of file handling, set this to 0.'),
  241. );
  242. //Directories
  243. $form['directories']['#theme'] = 'imce_directories';
  244. $form['directories']['#weight'] = 1;
  245. for ($i = 0; $i < count($profile['directories']); $i++) {
  246. $form['directories'][$i] = imce_directory_form($profile['directories'][$i]);
  247. }
  248. $form['directories'][$i] = imce_directory_form();
  249. $form['directories'][$i+1] = imce_directory_form();
  250. //Thumbnails
  251. $form['thumbnails']['#theme'] = 'imce_thumbnails';
  252. $form['thumbnails']['#weight'] = 2;
  253. for ($i = 0; $i < count($profile['thumbnails']); $i++) {
  254. $form['thumbnails'][$i] = imce_thumbnail_form($profile['thumbnails'][$i]);
  255. }
  256. $form['thumbnails'][$i] = imce_thumbnail_form();
  257. $form['thumbnails'][$i+1] = imce_thumbnail_form();
  258. $form = array('profile' => $form);
  259. $form['pid'] = array('#type' => 'hidden', '#value' => $pid);
  260. $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
  261. $form['#validate'][] = 'imce_profile_validate';
  262. $form['#submit'][] = 'imce_profile_submit';
  263. return $form;
  264. }
  265. /**
  266. * Profile form validate.
  267. */
  268. function imce_profile_validate($form, &$form_state) {
  269. $profile = &$form_state['values']['profile'];
  270. $dim_re = '/^\d+x\d+$/';
  271. $dim_error = t('Dimensions must be specified in <kbd>WIDTHxHEIGHT</kbd> format.');
  272. // Check max image dimensions
  273. if ($profile['dimensions'] && !preg_match($dim_re, $profile['dimensions'])) {
  274. return form_set_error('profile][dimensions', $dim_error);
  275. }
  276. // Check thumbnails dimensions
  277. foreach ($profile['thumbnails'] as $i => $thumb) {
  278. if (trim($thumb['name']) != '' && !preg_match($dim_re, $thumb['dimensions'])) {
  279. return form_set_error("profile][thumbnails][$i][dimensions", $dim_error);
  280. }
  281. }
  282. }
  283. /**
  284. * Profile form submit.
  285. */
  286. function imce_profile_submit($form, &$form_state) {
  287. $profile = $form_state['values']['profile'];
  288. $pid = $form_state['values']['pid'];
  289. $message = $pid > 0 ? t('The changes have been saved.') : t('Profile has been added.');
  290. //unset empty fields of directories and thumbnails.
  291. imce_clean_profile_fields($profile);
  292. //save profile.
  293. $pid = imce_update_profiles($pid, $profile);
  294. drupal_set_message($message);
  295. $form_state['redirect'] = 'admin/config/media/imce/profile/edit/' . $pid;
  296. }
  297. /**
  298. * directory settings form
  299. */
  300. function imce_directory_form($directory = array()) {
  301. if (empty($directory)) {
  302. $directory = array('name' => '', 'subnav' => 0, 'browse' => 0, 'upload' => 0, 'thumb' => 0, 'delete' => 0, 'resize' => 0);
  303. }
  304. $form['name'] = array(
  305. '#type' => 'textfield',
  306. '#default_value' => $directory['name'],
  307. '#size' => 24,
  308. '#maxlength' => NULL,
  309. );
  310. $form['subnav'] = array(
  311. '#type' => 'checkbox',
  312. '#title' => t('Including subdirectories'),
  313. '#default_value' => $directory['subnav'],
  314. );
  315. $form['browse'] = array(
  316. '#type' => 'checkbox',
  317. '#title' => t('Browse'),
  318. '#default_value' => $directory['browse'],
  319. );
  320. $form['upload'] = array(
  321. '#type' => 'checkbox',
  322. '#title' => t('Upload'),
  323. '#default_value' => $directory['upload'],
  324. );
  325. $form['thumb'] = array(
  326. '#type' => 'checkbox',
  327. '#title' => t('Thumbnails'),
  328. '#default_value' => $directory['thumb'],
  329. );
  330. $form['delete'] = array(
  331. '#type' => 'checkbox',
  332. '#title' => t('Delete'),
  333. '#default_value' => $directory['delete'],
  334. );
  335. $form['resize'] = array(
  336. '#type' => 'checkbox',
  337. '#title' => t('Resize'),
  338. '#default_value' => $directory['resize'],
  339. );
  340. return $form;
  341. }
  342. /**
  343. * Directorys form themed.
  344. */
  345. function imce_directories_theme($variables) {
  346. $form = $variables['form'];
  347. $rows = array();
  348. $root = t('root');
  349. foreach (element_children($form) as $key) {
  350. //directory path
  351. $row = array('<div class="container-inline">&lt;' . $root . '&gt;' . '/' . drupal_render($form[$key]['name']) . '</div>' . drupal_render($form[$key]['subnav']));
  352. unset($form[$key]['name'], $form[$key]['subnav']);
  353. //permissions
  354. $header = array();
  355. foreach (element_children($form[$key]) as $perm) {
  356. $header[] = $form[$key][$perm]['#title'];
  357. unset($form[$key][$perm]['#title']);
  358. $row[] = drupal_render($form[$key][$perm]);
  359. }
  360. $rows[] = $row;
  361. }
  362. array_unshift($header, t('Directory path'));
  363. $output = '<h3 class="title">' . t('Directories') . '</h3>';
  364. $output .= theme('table', array('header' => $header, 'rows' => $rows));
  365. $output .= '<div class="form-item"><div class="description">' . t('Define directories that users of this profile can access.
  366. <ul>
  367. <li>Use alphanumeric characters as directory paths.</li>
  368. <li>To specify file system root, just enter <strong>.</strong>(dot) character.</li>
  369. <li>Use <strong>%uid</strong> as a placeholder for user ID. Ex: <em>users/user%uid</em> creates directories such as <em>users/user1</em>, <em>users/user42</em>, etc.</li>
  370. <li>To remove a directory from the list, leave the directory path blank.</li>
  371. <li>If you want more flexibility in directory paths you can execute php to return a directory path.<br />
  372. For php execution your directory path must start with <strong>php:</strong> and the rest must be a valid php code that is expected to return the actual directory path. <br />Ex: <strong>php: return \'users/\'.$user->name;</strong> defines <strong>users/USER-NAME</strong> as the directory path.<br />
  373. A multi-level directory example <strong>php: return date(\'Y\', $user->created).\'/\'.date(\'m\', $user->created).\'/\'.$user->uid;</strong> defines <strong>MEMBERSHIP-YEAR/MONTH/USER-ID</strong> as the directory path, resulting in self-categorized user directories based on membership date.<br />
  374. Note that you should use the $user variable instead of $GLOBALS[\'user\'] since they are not always the same object.</li>
  375. </ul>
  376. <p>Note that thumbnails permission does not affect thumbnail creation on upload. See thumbnails decription below.</p>
  377. <p>If you need more fields, just fill all and save, and you will get two more on the next page.</p>') . '</div></div>';
  378. $output .= drupal_render_children($form);
  379. return $output;
  380. }
  381. /**
  382. * thumbnail settings form
  383. */
  384. function imce_thumbnail_form($thumb = array()) {
  385. if (empty($thumb)) {
  386. $thumb = array('name' => '', 'dimensions' => '', 'prefix' => '', 'suffix' => '');
  387. }
  388. $form['name'] = array(
  389. '#type' => 'textfield',
  390. '#default_value' => $thumb['name'],
  391. '#size' => 20,
  392. );
  393. $form['dimensions'] = array(
  394. '#type' => 'textfield',
  395. '#default_value' => $thumb['dimensions'],
  396. '#size' => 20,
  397. );
  398. $form['prefix'] = array(
  399. '#type' => 'textfield',
  400. '#default_value' => $thumb['prefix'],
  401. '#size' => 20,
  402. );
  403. $form['suffix'] = array(
  404. '#type' => 'textfield',
  405. '#default_value' => $thumb['suffix'],
  406. '#size' => 20,
  407. );
  408. return $form;
  409. }
  410. /**
  411. * Thumbnails form themed.
  412. */
  413. function imce_thumbnails_theme($variables) {
  414. $form = $variables['form'];
  415. $header = array(t('Name'), t('Dimensions'), t('Prefix'), t('Suffix'));
  416. $rows = array();
  417. foreach (element_children($form) as $key) {
  418. $rows[] = array(
  419. drupal_render($form[$key]['name']),
  420. drupal_render($form[$key]['dimensions']),
  421. drupal_render($form[$key]['prefix']),
  422. drupal_render($form[$key]['suffix']),
  423. );
  424. }
  425. $output = '<h3 class="title">' . t('Thumbnails') . '</h3>';
  426. $output .= theme('table', array('header' => $header, 'rows' => $rows));
  427. $output .= '<div class="form-item"><div class="description">' . t('You may create a list of thumbnail options that users can choose from.
  428. <ul>
  429. <li>Use alphanumeric characters as thumbnail names.</li>
  430. <li>Specify dimensions as <strong>WidthxHeight</strong>.</li>
  431. <li>Prefix and suffix are strings that are added to original file name to create the thumbnail name.</li>
  432. <li>An example thumbnail: Name = <strong>Small</strong>, Dimensions = <strong>80x80</strong>, Prefix = <strong>small_</strong></li>
  433. </ul>
  434. <p>Note that users will always be able to create these thumbnails on file upload no matter what the thumbnail permission is.</p>
  435. <p>If you need more fields, just fill all and save, and you will get two more on the next page.</p>') . '</div></div>';
  436. $output .= drupal_render_children($form);
  437. return $output;
  438. }
  439. /**
  440. * Role-profile form
  441. */
  442. function imce_role_form($role, $weight = TRUE, $core = TRUE) {
  443. $form['name'] = array(
  444. '#markup' => check_plain($role['name']),
  445. );
  446. if ($weight) {
  447. $form['weight'] = $core ? array(
  448. '#type' => 'textfield',
  449. '#value' => $role['weight'],
  450. '#attributes' => array('readonly' => 'readonly', 'style' => 'border: none; width: 2em; background-color: transparent;'),
  451. ) : array(
  452. '#type' => 'weight',
  453. '#default_value' => $role['weight'],
  454. );
  455. }
  456. foreach (array_keys(file_get_stream_wrappers(STREAM_WRAPPERS_VISIBLE)) as $scheme) {
  457. $form[$scheme . '_pid'] = array(
  458. '#type' => 'select',
  459. '#options' => imce_profile_options(),
  460. '#default_value' => $role[$scheme . '_pid'],
  461. '#empty_value' => 0,
  462. );
  463. }
  464. return $form;
  465. }
  466. /**
  467. * Profile delete form
  468. */
  469. function imce_profile_delete_form($form, &$form_state, $pid) {
  470. if ($pid > 1 && $profile = imce_load_profile($pid)) {
  471. $form['#submit'][] = 'imce_profile_delete_submit';
  472. $form['pid'] = array('#type' => 'hidden', '#value' => $pid);
  473. return confirm_form($form,
  474. t('Are you sure you want to delete the profile %name?',
  475. array('%name' => $profile['name'])),
  476. 'admin/config/media/imce',
  477. '',
  478. t('Delete'),
  479. t('Cancel')
  480. );
  481. }
  482. drupal_goto('admin/config/media/imce');
  483. }
  484. /**
  485. * Profile delete form submit
  486. */
  487. function imce_profile_delete_submit($form, &$form_state) {
  488. imce_update_profiles($form_state['values']['pid'], NULL);
  489. drupal_set_message(t('Profile has been deleted.'));
  490. $form_state['redirect'] = 'admin/config/media/imce';
  491. }
  492. /**
  493. * Profile options.
  494. */
  495. function imce_profile_options() {
  496. $options = array();
  497. foreach (variable_get('imce_profiles', array()) as $pid => $profile) {
  498. $options[$pid] = $profile['name'];
  499. }
  500. return $options;
  501. }
  502. /**
  503. * Profile import links.
  504. */
  505. function imce_profile_import_html($pid = 0) {
  506. $output = '';
  507. $links = array();
  508. foreach (variable_get('imce_profiles', array()) as $id => $profile) {
  509. if ($pid != $id) {
  510. $links[] = l($profile['name'], $_GET['q'], array('query' => array('import' => $id)));
  511. }
  512. }
  513. if (!empty($links)) {
  514. $output = '<p><strong>' . t('Import settings from other profiles') . '</strong>: ';
  515. $output .= implode(', ', $links) . '</p>';
  516. }
  517. return $output;
  518. }
  519. /**
  520. * Update role-profile assignments.
  521. */
  522. function imce_update_roles($pid) {
  523. $roles = variable_get('imce_roles_profiles', array());
  524. foreach ($roles as $rid => $role) {
  525. foreach ($role as $key => $value) {
  526. if (substr($key, -4) == '_pid') {
  527. if ($value == $pid) {
  528. $roles[$rid][$key] = 0;
  529. }
  530. elseif ($value > $pid) {
  531. $roles[$rid][$key]--;
  532. }
  533. }
  534. }
  535. }
  536. variable_set('imce_roles_profiles', $roles);
  537. }
  538. /**
  539. * Add, update or delete a profile.
  540. */
  541. function imce_update_profiles($pid, $profile = NULL) {
  542. $profiles = variable_get('imce_profiles', array());
  543. //add or update
  544. if (isset($profile)) {
  545. $pid = isset($profiles[$pid]) ? $pid : count($profiles)+1;
  546. $profiles[$pid] = $profile;
  547. }
  548. //delete
  549. elseif (isset($profiles[$pid]) && $pid > 1) {
  550. unset($profiles[$pid]);
  551. for ($i = $pid+1; isset($profiles[$i]); $i++) {
  552. $profiles[$i-1] = $profiles[$i];
  553. unset($profiles[$i]);
  554. }
  555. imce_update_roles($pid);
  556. }
  557. variable_set('imce_profiles', $profiles);
  558. return $pid;
  559. }
  560. /**
  561. * Unset empty fields in thumbnails and directory paths.
  562. */
  563. function imce_clean_profile_fields(&$profile) {
  564. $clean = array();
  565. foreach ($profile['thumbnails'] as $thumb) {
  566. if (trim($thumb['name']) != '') {
  567. $clean[] = $thumb;
  568. }
  569. }
  570. $profile['thumbnails'] = $clean;
  571. $clean = array();
  572. $names = array();
  573. foreach ($profile['directories'] as $dir) {
  574. $dir['name'] = trim($dir['name'], '/ ');
  575. if ($dir['name'] == '') {
  576. continue;
  577. }
  578. if (isset($names[$dir['name']])) {
  579. drupal_set_message(t('Duplicate directory paths are not allowed.'), 'error');
  580. continue;
  581. }
  582. if (!imce_reg_dir($dir['name'])) {
  583. drupal_set_message(t('%dirname is not accepted as a proper directory name.', array('%dirname' => $dir['name'])), 'error');
  584. continue;
  585. }
  586. $clean[] = $dir;
  587. $names[$dir['name']] = 1;
  588. }
  589. $profile['directories'] = $clean;
  590. }
  591. /**
  592. * Profile load.
  593. */
  594. function imce_load_profile($pid) {
  595. $profiles = variable_get('imce_profiles', array());
  596. return isset($profiles[$pid]) ? $profiles[$pid] : NULL;
  597. }
  598. /**
  599. * Sort roles according to their weights.
  600. */
  601. function imce_sorted_roles() {
  602. static $sorted;
  603. if (!isset($sorted)) {
  604. $sorted = array();
  605. $roles = user_roles();
  606. $profiles = variable_get('imce_profiles', array());
  607. $roles_profiles = variable_get('imce_roles_profiles', array());
  608. $roles_profiles[DRUPAL_ANONYMOUS_RID]['weight'] = 12;
  609. $roles_profiles[DRUPAL_AUTHENTICATED_RID]['weight'] = 11;
  610. $schemes = array_keys(file_get_stream_wrappers(STREAM_WRAPPERS_VISIBLE));
  611. foreach ($roles as $rid => $name) {
  612. $sorted[$rid] = array(
  613. 'name' => $name,
  614. 'weight' => isset($roles_profiles[$rid]['weight']) ? $roles_profiles[$rid]['weight'] : 0
  615. );
  616. foreach ($schemes as $scheme) {
  617. $key = $scheme . '_pid';
  618. $sorted[$rid][$key] = isset($roles_profiles[$rid][$key]) && isset($profiles[$roles_profiles[$rid][$key]]) ? $roles_profiles[$rid][$key] : 0;
  619. }
  620. }
  621. uasort($sorted, 'imce_rolesort');
  622. }
  623. return $sorted;
  624. }
  625. /**
  626. * Sorting function for roles.
  627. */
  628. function imce_rolesort($r1, $r2) {
  629. return $r1['weight']-$r2['weight'];
  630. }
  631. //Include core profile functions.
  632. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'imce') . '/inc/imce.core.profiles.inc';
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.