ckeditor.features.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * CKEditor - The text editor for the Internet - http://ckeditor.com
  4. * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  5. *
  6. * == BEGIN LICENSE ==
  7. *
  8. * Licensed under the terms of any of the following licenses of your
  9. * choice:
  10. *
  11. * - GNU General Public License Version 2 or later (the "GPL")
  12. * http://www.gnu.org/licenses/gpl.html
  13. *
  14. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15. * http://www.gnu.org/licenses/lgpl.html
  16. *
  17. * - Mozilla Public License Version 1.1 or later (the "MPL")
  18. * http://www.mozilla.org/MPL/MPL-1.1.html
  19. *
  20. * == END LICENSE ==
  21. *
  22. * @file
  23. * CKEditor Module for Drupal 7.x
  24. *
  25. * This module allows Drupal to replace textarea fields with CKEditor.
  26. *
  27. * CKEditor is an online rich text editor that can be embedded inside web pages.
  28. * It is a WYSIWYG (What You See Is What You Get) editor which means that the
  29. * text edited in it looks as similar as possible to the results end users will
  30. * see after the document gets published. It brings to the Web popular editing
  31. * features found in desktop word processors such as Microsoft Word and
  32. * OpenOffice.org Writer. CKEditor is truly lightweight and does not require any
  33. * kind of installation on the client computer.
  34. */
  35. /**
  36. * Implementation of hook_features_export_options()
  37. */
  38. function ckeditor_profile_features_export_options() {
  39. $options = array();
  40. $profiles = (array) ckeditor_profile_load();
  41. foreach ($profiles as $name => $profile) {
  42. $options[$name] = $profile->name;
  43. }
  44. return $options;
  45. }
  46. /**
  47. * Implementation of hook_features_export()
  48. */
  49. function ckeditor_profile_features_export($data, &$export, $module_name = '') {
  50. $pipe = array();
  51. foreach ((array) $data as $name) {
  52. $profile = ckeditor_profile_load($name);
  53. if ($profile) {
  54. $export['features']['ckeditor_profile'][$name] = $name;
  55. // Write dependencies on all the roles referenced by this profile
  56. foreach ((array) $profile->input_formats as $input_format => $input_format_name) {
  57. $pipe['input_formats'][] = $input_format;
  58. }
  59. }
  60. }
  61. $export['dependencies'][] = 'ckeditor';
  62. return $pipe;
  63. }
  64. /**
  65. * Implementation of hook_features_export_render()
  66. */
  67. function ckeditor_profile_features_export_render($module_name, $data) {
  68. $profiles = array();
  69. $roles = user_roles();
  70. foreach ($data as $name) {
  71. $profile = (array) ckeditor_profile_load($name, TRUE, FALSE);
  72. $profiles[$name] = $profile;
  73. }
  74. $code = ' $data = ' . features_var_export($profiles, ' ') . ';' . PHP_EOL;
  75. $code .= ' return $data;';
  76. return array('ckeditor_profile_defaults' => $code);
  77. }
  78. /**
  79. * Implementation of hook_features_rebuild()
  80. */
  81. function ckeditor_profile_features_rebuild($module) {
  82. ckeditor_profile_features_revert($module);
  83. }
  84. /**
  85. * Implementation of hook_features_revert()
  86. */
  87. function ckeditor_profile_features_revert($module) {
  88. if ($data = features_get_default('ckeditor_profile', $module)) {
  89. $input_formats = filter_formats();
  90. foreach ($data as $name => $profile) {
  91. // Restore the profile settings
  92. db_query("DELETE FROM {ckeditor_settings} WHERE name = :name", array(':name' => $name));
  93. db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES(:name, :settings)", array(':name' => $name, ':settings' => serialize($profile['settings'])));
  94. if (empty($profile["input_formats"])) {
  95. // Remove input format if none is specified
  96. db_query("DELETE FROM {ckeditor_input_format} WHERE name = :name", array(':name' => $name));
  97. }
  98. else {
  99. // Restore the profile roles
  100. foreach ($profile["input_formats"] as $input_format => $input_format_name) {
  101. if (!db_query("SELECT name FROM {ckeditor_input_format} WHERE format = :format AND name = :name", array(':name' => $name, ':format' => $input_format))->fetchField()) {
  102. db_query("INSERT INTO {ckeditor_input_format} (name, format) VALUES(:name, :format)", array(':name' => $name, ':format' => $input_format));
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }