editors.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Allows admin to configure editors.
  4. */
  5. require_once('../config.php');
  6. require_once($CFG->libdir.'/adminlib.php');
  7. require_once($CFG->libdir.'/tablelib.php');
  8. $action = required_param('action', PARAM_ALPHANUMEXT);
  9. $editor = required_param('editor', PARAM_PLUGIN);
  10. $confirm = optional_param('confirm', 0, PARAM_BOOL);
  11. $PAGE->set_url('/admin/editors.php', array('action'=>$action, 'editor'=>$editor));
  12. $PAGE->set_context(context_system::instance());
  13. require_login();
  14. require_capability('moodle/site:config', context_system::instance());
  15. $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageeditors";
  16. // get currently installed and enabled auth plugins
  17. $available_editors = editors_get_available();
  18. if (!empty($editor) and empty($available_editors[$editor])) {
  19. redirect ($returnurl);
  20. }
  21. $active_editors = explode(',', $CFG->texteditors);
  22. foreach ($active_editors as $key=>$active) {
  23. if (empty($available_editors[$active])) {
  24. unset($active_editors[$key]);
  25. }
  26. }
  27. ////////////////////////////////////////////////////////////////////////////////
  28. // process actions
  29. if (!confirm_sesskey()) {
  30. redirect($returnurl);
  31. }
  32. $return = true;
  33. switch ($action) {
  34. case 'disable':
  35. // remove from enabled list
  36. $key = array_search($editor, $active_editors);
  37. unset($active_editors[$key]);
  38. break;
  39. case 'enable':
  40. // add to enabled list
  41. if (!in_array($editor, $active_editors)) {
  42. $active_editors[] = $editor;
  43. $active_editors = array_unique($active_editors);
  44. }
  45. break;
  46. case 'down':
  47. $key = array_search($editor, $active_editors);
  48. // check auth plugin is valid
  49. if ($key !== false) {
  50. // move down the list
  51. if ($key < (count($active_editors) - 1)) {
  52. $fsave = $active_editors[$key];
  53. $active_editors[$key] = $active_editors[$key + 1];
  54. $active_editors[$key + 1] = $fsave;
  55. }
  56. }
  57. break;
  58. case 'up':
  59. $key = array_search($editor, $active_editors);
  60. // check auth is valid
  61. if ($key !== false) {
  62. // move up the list
  63. if ($key >= 1) {
  64. $fsave = $active_editors[$key];
  65. $active_editors[$key] = $active_editors[$key - 1];
  66. $active_editors[$key - 1] = $fsave;
  67. }
  68. }
  69. break;
  70. default:
  71. break;
  72. }
  73. // at least one editor must be active
  74. if (empty($active_editors)) {
  75. $active_editors = array('textarea');
  76. }
  77. set_config('texteditors', implode(',', $active_editors));
  78. core_plugin_manager::reset_caches();
  79. if ($return) {
  80. redirect ($returnurl);
  81. }