wysiwyg.features.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Implements hook_features_export_options().
  4. */
  5. function wysiwyg_features_export_options() {
  6. $profiles = array();
  7. // Get human-readable name from filter module.
  8. $formats = filter_formats();
  9. foreach (array_keys(wysiwyg_profile_load_all()) as $format) {
  10. // Text format may vanish without deleting the wysiwyg profile.
  11. if (isset($formats[$format])) {
  12. $profiles[$format] = $formats[$format]->name;
  13. }
  14. }
  15. return $profiles;
  16. }
  17. /**
  18. * Implements hook_features_export().
  19. */
  20. function wysiwyg_features_export($data, &$export, $module_name = '') {
  21. $pipe = array();
  22. // The wysiwyg_default_formats() hook integration is provided by the
  23. // features module so we need to add it as a dependency.
  24. $export['dependencies']['features'] = 'features';
  25. $export['dependencies']['wysiwyg'] = 'wysiwyg';
  26. foreach ($data as $name) {
  27. if ($profile = wysiwyg_get_profile($name)) {
  28. // Add profile to exports.
  29. $export['features']['wysiwyg'][$profile->format] = $profile->format;
  30. // Chain filter format for export.
  31. $pipe['filter'][] = $profile->format;
  32. }
  33. }
  34. return $pipe;
  35. }
  36. /**
  37. * Implements hook_features_export_render().
  38. */
  39. function wysiwyg_features_export_render($module, $data, $export = NULL) {
  40. $code = array();
  41. $code[] = ' $profiles = array();';
  42. $code[] = '';
  43. foreach ($data as $name) {
  44. if ($profile = wysiwyg_get_profile($name)) {
  45. $profile_export = features_var_export($profile, ' ');
  46. $profile_identifier = features_var_export($profile->format);
  47. $code[] = " // Exported profile: {$profile->format}";
  48. $code[] = " \$profiles[{$profile_identifier}] = {$profile_export};";
  49. $code[] = "";
  50. }
  51. }
  52. $code[] = ' return $profiles;';
  53. $code = implode("\n", $code);
  54. return array('wysiwyg_default_profiles' => $code);
  55. }
  56. /**
  57. * Implements hook_features_revert().
  58. */
  59. function wysiwyg_features_revert($module) {
  60. return wysiwyg_features_rebuild($module);
  61. }
  62. /**
  63. * Implements hook_features_rebuild().
  64. */
  65. function wysiwyg_features_rebuild($module) {
  66. if ($defaults = features_get_default('wysiwyg', $module)) {
  67. foreach ($defaults as $profile) {
  68. if (empty($profile['settings']['_profile_preferences'])) {
  69. $settings = &$profile['settings'];
  70. // Importing an older profile, move state to its own section.
  71. $preferences = array(
  72. 'add_to_summaries' => $settings['add_to_summaries'],
  73. 'default' => $settings['default'],
  74. 'show_toggle' => $settings['show_toggle'],
  75. 'user_choose' => $settings['user_choose'],
  76. 'version' => NULL,
  77. );
  78. unset($settings['add_to_summaries'], $settings['default'], $settings['show_toggle'], $settings['user_choose']);
  79. if (!empty($settings['library'])) {
  80. $prefereces['library'] = $settings['library'];
  81. unset($settings['library']);
  82. }
  83. $editor = wysiwyg_get_editor($profile->editor);
  84. if ($editor['installed']) {
  85. $preferences['version'] = $editor['installed version'];
  86. }
  87. $settings['_profile_preferences'] = $preferences;
  88. }
  89. db_merge('wysiwyg')
  90. ->key(array('format' => $profile['format']))
  91. ->fields(array(
  92. 'editor' => $profile['editor'],
  93. 'settings' => serialize($profile['settings']),
  94. ))
  95. ->execute();
  96. // Clear the editing caches.
  97. if (module_exists('ctools')) {
  98. ctools_include('object-cache');
  99. ctools_object_cache_clear_all('wysiwyg_profile', 'format' . $profile['format']);
  100. }
  101. cache_clear_all('wysiwyg_profile:format' . $profile['format'], 'cache');
  102. }
  103. wysiwyg_profile_cache_clear();
  104. }
  105. }