wysiwyg.install 8.7 KB

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