wysiwyg.features.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. db_merge('wysiwyg')
  69. ->key(array('format' => $profile['format']))
  70. ->fields(array(
  71. 'editor' => $profile['editor'],
  72. 'settings' => serialize($profile['settings']),
  73. ))
  74. ->execute();
  75. }
  76. wysiwyg_profile_cache_clear();
  77. }
  78. }