wysiwyg.install 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. /**
  3. * @file
  4. * Installation functions for Wysiwyg module.
  5. */
  6. /**
  7. * Implementation of hook_schema().
  8. */
  9. function wysiwyg_schema() {
  10. $schema['wysiwyg'] = array(
  11. 'description' => 'Stores Wysiwyg profiles.',
  12. 'fields' => array(
  13. 'format' => array(
  14. 'description' => 'The {filter_format}.format of the text format.',
  15. 'type' => 'varchar',
  16. 'length' => 255,
  17. // Primary keys are implicitly not null.
  18. 'not null' => TRUE,
  19. ),
  20. 'editor' => array(
  21. 'description' => 'Internal name of the editor attached to the text format.',
  22. 'type' => 'varchar',
  23. 'length' => 128,
  24. 'not null' => TRUE,
  25. 'default' => '',
  26. ),
  27. 'settings' => array(
  28. 'description' => 'Configuration settings for the editor.',
  29. 'type' => 'text',
  30. 'size' => 'normal',
  31. ),
  32. ),
  33. 'primary key' => array('format'),
  34. 'foreign keys' => array(
  35. 'format' => array(
  36. 'table' => 'filter_format',
  37. 'columns' => array('format' => 'format'),
  38. ),
  39. ),
  40. );
  41. $schema['wysiwyg_user'] = array(
  42. 'description' => 'Stores user preferences for wysiwyg profiles.',
  43. 'fields' => array(
  44. 'uid' => array(
  45. 'description' => 'The {users}.uid of the user.',
  46. 'type' => 'int',
  47. 'unsigned' => TRUE,
  48. 'not null' => TRUE,
  49. 'default' => 0,
  50. ),
  51. 'format' => array(
  52. 'description' => 'The {filter_format}.format of the text format.',
  53. 'type' => 'varchar',
  54. 'length' => 255,
  55. 'not null' => FALSE,
  56. ),
  57. 'status' => array(
  58. 'description' => 'Boolean indicating whether the format is enabled by default.',
  59. 'type' => 'int',
  60. 'unsigned' => TRUE,
  61. 'not null' => TRUE,
  62. 'default' => 0,
  63. 'size' => 'tiny',
  64. ),
  65. ),
  66. 'indexes' => array(
  67. 'uid' => array('uid'),
  68. 'format' => array('format'),
  69. ),
  70. 'foreign keys' => array(
  71. 'uid' => array(
  72. 'table' => 'users',
  73. 'columns' => array('uid' => 'uid'),
  74. ),
  75. 'format' => array(
  76. 'table' => 'filter_format',
  77. 'columns' => array('format' => 'format'),
  78. ),
  79. ),
  80. );
  81. return $schema;
  82. }
  83. /**
  84. * Implementation of hook_enable().
  85. */
  86. function wysiwyg_enable() {
  87. // Disable conflicting, obsolete editor integration modules whenever this
  88. // module is enabled. This is crude, but the only way to ensure no conflicts.
  89. module_disable(array(
  90. 'ckeditor',
  91. 'editarea',
  92. 'editonpro',
  93. 'editor',
  94. 'fckeditor',
  95. 'freerte',
  96. 'htmlarea',
  97. 'htmlbox',
  98. 'jwysiwyg',
  99. 'markitup',
  100. 'nicedit',
  101. 'openwysiwyg',
  102. 'pegoeditor',
  103. 'quicktext',
  104. 'tinymce',
  105. 'tinymce_autoconf',
  106. 'tinytinymce',
  107. 'whizzywig',
  108. 'widgeditor',
  109. 'wymeditor',
  110. 'xstandard',
  111. 'yui_editor',
  112. ));
  113. }
  114. /**
  115. * Implements hook_update_dependencies().
  116. */
  117. function wysiwyg_update_dependencies() {
  118. // Ensure that format columns are only changed after Filter module has changed
  119. // the primary records.
  120. $dependencies['wysiwyg'][7000] = array(
  121. 'filter' => 7010,
  122. );
  123. return $dependencies;
  124. }
  125. /**
  126. * Retrieve a list of input formats to associate profiles to.
  127. */
  128. function _wysiwyg_install_get_formats() {
  129. $formats = array();
  130. $result = db_query("SELECT format, name FROM {filter_formats}");
  131. while ($format = db_fetch_object($result)) {
  132. // Build a list of all formats.
  133. $formats[$format->format] = $format->name;
  134. // Fetch filters.
  135. $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format);
  136. while ($filter = db_fetch_object($result2)) {
  137. // If PHP filter is enabled, remove this format.
  138. if ($filter->module == 'php') {
  139. unset($formats[$format->format]);
  140. break;
  141. }
  142. }
  143. }
  144. return $formats;
  145. }
  146. /**
  147. * Associate Wysiwyg profiles with input formats.
  148. *
  149. * Since there was no association yet, we can only assume that there is one
  150. * profile only, and that profile must be duplicated and assigned to all input
  151. * formats (except PHP code format). Also, input formats already have
  152. * titles/names, so Wysiwyg profiles do not need an own.
  153. *
  154. * Because input formats are already granted to certain user roles only, we can
  155. * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
  156. * input formats and permissions makes plugin_count obsolete, too.
  157. *
  158. * Since the resulting table is completely different, a new schema is installed.
  159. */
  160. function wysiwyg_update_6001() {
  161. $ret = array();
  162. if (db_table_exists('wysiwyg')) {
  163. return $ret;
  164. }
  165. // Install new schema.
  166. db_create_table($ret, 'wysiwyg', array(
  167. 'fields' => array(
  168. 'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
  169. 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
  170. 'settings' => array('type' => 'text', 'size' => 'normal'),
  171. ),
  172. 'primary key' => array('format'),
  173. ));
  174. // Fetch all input formats.
  175. $formats = _wysiwyg_install_get_formats();
  176. // Fetch all profiles.
  177. $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
  178. while ($profile = db_fetch_object($result)) {
  179. $profile->settings = unserialize($profile->settings);
  180. // Extract editor name from profile settings.
  181. $profile->editor = $profile->settings['editor'];
  182. // Clean-up.
  183. unset($profile->settings['editor']);
  184. unset($profile->settings['old_name']);
  185. unset($profile->settings['name']);
  186. unset($profile->settings['rids']);
  187. // Sorry. There Can Be Only One. ;)
  188. break;
  189. }
  190. if ($profile) {
  191. // Rebuild profiles and associate with input formats.
  192. foreach ($formats as $format => $name) {
  193. // Insert profiles.
  194. // We can't use update_sql() here because of curly braces in serialized
  195. // array.
  196. db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor, serialize($profile->settings));
  197. $ret[] = array(
  198. 'success' => TRUE,
  199. 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name), '%format' => check_plain($name))),
  200. );
  201. }
  202. }
  203. // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
  204. db_drop_table($ret, 'wysiwyg_profile');
  205. db_drop_table($ret, 'wysiwyg_role');
  206. return $ret;
  207. }
  208. /**
  209. * Clear JS/CSS caches to ensure that clients load fresh copies.
  210. */
  211. function wysiwyg_update_6200() {
  212. $ret = array();
  213. // Change query-strings on css/js files to enforce reload for all users.
  214. _drupal_flush_css_js();
  215. drupal_clear_css_cache();
  216. drupal_clear_js_cache();
  217. // Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
  218. menu_rebuild();
  219. // Flush content caches.
  220. cache_clear_all();
  221. $ret[] = array(
  222. 'success' => TRUE,
  223. 'query' => 'Caches have been flushed.',
  224. );
  225. return $ret;
  226. }
  227. /**
  228. * Change {wysiwyg}.format into a string.
  229. */
  230. function wysiwyg_update_7000() {
  231. db_drop_primary_key('wysiwyg');
  232. db_change_field('wysiwyg', 'format', 'format', array(
  233. 'type' => 'varchar',
  234. 'length' => 255,
  235. 'not null' => TRUE,
  236. ));
  237. db_add_primary_key('wysiwyg', array('format'));
  238. }
  239. /**
  240. * Create the {wysiwyg_user} table.
  241. */
  242. function wysiwyg_update_7200() {
  243. if (!db_table_exists('wysiwyg_user')) {
  244. db_create_table('wysiwyg_user', array(
  245. 'description' => 'Stores user preferences for wysiwyg profiles.',
  246. 'fields' => array(
  247. 'uid' => array(
  248. 'description' => 'The {users}.uid of the user.',
  249. 'type' => 'int',
  250. 'unsigned' => TRUE,
  251. 'not null' => TRUE,
  252. 'default' => 0,
  253. ),
  254. 'format' => array(
  255. 'description' => 'The {filter_format}.format of the text format.',
  256. 'type' => 'varchar',
  257. 'length' => 255,
  258. 'not null' => FALSE,
  259. ),
  260. 'status' => array(
  261. 'description' => 'Boolean indicating whether the format is enabled by default.',
  262. 'type' => 'int',
  263. 'unsigned' => TRUE,
  264. 'not null' => TRUE,
  265. 'default' => 0,
  266. 'size' => 'tiny',
  267. ),
  268. ),
  269. 'indexes' => array(
  270. 'uid' => array('uid'),
  271. 'format' => array('format'),
  272. ),
  273. 'foreign keys' => array(
  274. 'uid' => array(
  275. 'table' => 'users',
  276. 'columns' => array('uid' => 'uid'),
  277. ),
  278. 'format' => array(
  279. 'table' => 'filter_format',
  280. 'columns' => array('format' => 'format'),
  281. ),
  282. ),
  283. ));
  284. }
  285. else {
  286. db_change_field('wysiwyg_user', 'format', 'format', array(
  287. 'description' => 'The {filter_format}.format of the text format.',
  288. 'type' => 'varchar',
  289. 'length' => 255,
  290. 'not null' => FALSE,
  291. ));
  292. }
  293. }