PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/editor/tinymce/db/upgrade.php

https://github.com/raymanuk/moodle
PHP | 182 lines | 101 code | 38 blank | 43 comment | 20 complexity | c558e675aa6dbec7ac378a757244b4ef MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * TinyMCE editor integration upgrade.
  18. *
  19. * @package editor_tinymce
  20. * @copyright 2012 Petr Skoda {@link http://skodak.org}
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. function xmldb_editor_tinymce_upgrade($oldversion) {
  25. global $CFG, $DB;
  26. $dbman = $DB->get_manager();
  27. if ($oldversion < 2012083100) {
  28. // Reset redesigned editor toolbar setting.
  29. unset_config('customtoolbar', 'editor_tinymce');
  30. upgrade_plugin_savepoint(true, 2012083100, 'editor', 'tinymce');
  31. }
  32. // Moodle v2.4.0 release upgrade line
  33. // Put any upgrade step following this
  34. // Moodle v2.5.0 release upgrade line.
  35. // Put any upgrade step following this.
  36. if ($oldversion < 2013061400) {
  37. // Reset redesigned editor toolbar setting.
  38. $oldorder = "fontselect,fontsizeselect,formatselect,|,undo,redo,|,search,replace,|,fullscreen
  39. bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl
  40. bullist,numlist,outdent,indent,|,link,unlink,|,image,nonbreaking,charmap,table,|,code";
  41. $neworder = "formatselect,bold,italic,|,bullist,numlist,|,link,unlink,|,image
  42. undo,redo,|,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,outdent,indent,|,forecolor,backcolor,|,ltr,rtl,|,nonbreaking,charmap,table
  43. fontselect,fontsizeselect,code,search,replace,|,cleanup,removeformat,pastetext,pasteword,|,fullscreen";
  44. $currentorder = get_config('editor_tinymce', 'customtoolbar');
  45. if ($currentorder == $oldorder) {
  46. unset_config('customtoolbar', 'editor_tinymce');
  47. set_config('customtoolbar', $neworder, 'editor_tinymce');
  48. }
  49. upgrade_plugin_savepoint(true, 2013061400, 'editor', 'tinymce');
  50. }
  51. if ($oldversion < 2013070500) {
  52. // Insert wrap plugin to nicely wrap the toolbars on small screens.
  53. $oldorder = "formatselect,bold,italic,|,bullist,numlist,|,link,unlink,|,image
  54. undo,redo,|,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,outdent,indent,|,forecolor,backcolor,|,ltr,rtl,|,nonbreaking,charmap,table
  55. fontselect,fontsizeselect,code,search,replace,|,cleanup,removeformat,pastetext,pasteword,|,fullscreen";
  56. $neworder = "formatselect,bold,italic,wrap,bullist,numlist,|,link,unlink,|,image
  57. undo,redo,|,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,wrap,outdent,indent,|,forecolor,backcolor,|,ltr,rtl,|,nonbreaking,charmap,table
  58. fontselect,fontsizeselect,wrap,code,search,replace,|,cleanup,removeformat,pastetext,pasteword,|,fullscreen";
  59. $currentorder = get_config('editor_tinymce', 'customtoolbar');
  60. if ($currentorder == $oldorder) {
  61. unset_config('customtoolbar', 'editor_tinymce');
  62. set_config('customtoolbar', $neworder, 'editor_tinymce');
  63. } else {
  64. // Simple auto conversion algorithm.
  65. $toolbars = explode("\n", $oldorder);
  66. $newtoolbars = array();
  67. foreach ($toolbars as $toolbar) {
  68. $sepcount = substr_count($toolbar, '|');
  69. if ($sepcount > 0) {
  70. // We assume the middle separator (rounding down).
  71. $divisionindex = round($sepcount / 2, 0, PHP_ROUND_HALF_DOWN);
  72. $buttons = explode(',', $toolbar);
  73. $index = 0;
  74. foreach ($buttons as $key => $button) {
  75. if ($button === "|") {
  76. if ($index == $divisionindex) {
  77. $buttons[$key] = 'wrap';
  78. break;
  79. } else {
  80. $index += 1;
  81. }
  82. }
  83. }
  84. $toolbar = implode(',', $buttons);
  85. }
  86. array_push($newtoolbars, $toolbar);
  87. }
  88. $neworder = implode("\n", $newtoolbars);
  89. // Set the new config.
  90. unset_config('customtoolbar', 'editor_tinymce');
  91. set_config('customtoolbar', $neworder, 'editor_tinymce');
  92. }
  93. upgrade_plugin_savepoint(true, 2013070500, 'editor', 'tinymce');
  94. }
  95. if ($oldversion < 2013102900) {
  96. // Reset redesigned editor toolbar setting.
  97. $currentorder = get_config('editor_tinymce', 'customtoolbar');
  98. // Start with a wrap.
  99. $neworder = "wrap,". $currentorder;
  100. // Replace all separators with wraps to allow for proper display of groups.
  101. $neworder = preg_replace('/\|\|*/', "wrap", $neworder);
  102. // Insert a wrap between the format selector and the bold button.
  103. $neworder = str_replace("formatselect,bold", "formatselect,wrap,bold", $neworder);
  104. set_config('customtoolbar', $neworder, 'editor_tinymce');
  105. upgrade_plugin_savepoint(true, 2013102900, 'editor', 'tinymce');
  106. }
  107. if ($oldversion < 2013110600) {
  108. // Reset redesigned editor toolbar setting.
  109. $currentorder = get_config('editor_tinymce', 'customtoolbar');
  110. $olddefaultorder = "wrap,formatselect,wrap,bold,italic,wrap,bullist,numlist,wrap,link,unlink,wrap,image
  111. undo,redo,wrap,underline,strikethrough,sub,sup,wrap,justifyleft,justifycenter,justifyright,wrap,outdent,indent,wrap,forecolor,backcolor,wrap,ltr,rtl,wrap,nonbreaking,charmap,table
  112. fontselect,fontsizeselect,wrap,code,search,replace,wrap,cleanup,removeformat,pastetext,pasteword,wrap,fullscreen";
  113. $neworder = "wrap,formatselect,wrap,bold,italic,wrap,bullist,numlist,wrap,link,unlink,wrap,image
  114. undo,redo,wrap,underline,strikethrough,sub,sup,wrap,justifyleft,justifycenter,justifyright,wrap,outdent,indent,wrap,forecolor,backcolor,wrap,ltr,rtl
  115. fontselect,fontsizeselect,wrap,code,search,replace,wrap,nonbreaking,charmap,table,wrap,cleanup,removeformat,pastetext,pasteword,wrap,fullscreen";
  116. if ($currentorder == $olddefaultorder) {
  117. set_config('customtoolbar', $neworder, 'editor_tinymce');
  118. }
  119. upgrade_plugin_savepoint(true, 2013110600, 'editor', 'tinymce');
  120. }
  121. // Moodle v2.6.0 release upgrade line.
  122. // Put any upgrade step following this.
  123. // Moodle v2.7.0 release upgrade line.
  124. // Put any upgrade step following this.
  125. if ($oldversion < 2014062900) {
  126. // We only want to delete DragMath from the customtoolbar setting if the directory no longer exists. If
  127. // the directory is present then it means it has been restored, so do not remove any settings.
  128. if (!check_dir_exists($CFG->libdir . '/editor/tinymce/plugins/dragmath', false)) {
  129. // Remove the DragMath plugin from the 'customtoolbar' setting (if it exists) as it has been removed.
  130. $currentorder = get_config('editor_tinymce', 'customtoolbar');
  131. $newtoolbarrows = array();
  132. $currenttoolbarrows = explode("\n", $currentorder);
  133. foreach ($currenttoolbarrows as $currenttoolbarrow) {
  134. $currenttoolbarrow = implode(',', array_diff(str_getcsv($currenttoolbarrow), array('dragmath')));
  135. $newtoolbarrows[] = $currenttoolbarrow;
  136. }
  137. $neworder = implode("\n", $newtoolbarrows);
  138. unset_config('customtoolbar', 'editor_tinymce');
  139. set_config('customtoolbar', $neworder, 'editor_tinymce');
  140. }
  141. upgrade_plugin_savepoint(true, 2014062900, 'editor', 'tinymce');
  142. }
  143. return true;
  144. }