ckeditor.install 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?php
  2. /*
  3. * CKEditor - The text editor for the Internet - http://ckeditor.com
  4. * Copyright (c) 2003-2011, 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_install().
  37. *
  38. * This will automatically install the database tables for the CKEditor module for both MySQL and PostgreSQL databases.
  39. *
  40. * If you are using another database, you will have to install the tables manually, using the queries below as a reference.
  41. *
  42. * Note that the curly braces around table names are a Drupal-specific feature to allow for automatic database table prefixing,
  43. * and will need to be removed.
  44. */
  45. function ckeditor_install() {
  46. module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  47. //searching ckeditor.js
  48. $ckeditor_path = _ckeditor_script_path();
  49. //insert default input formats to profiles
  50. db_insert('ckeditor_input_format')->fields(array("name" => "Advanced", "format" => 'filtered_html'))->execute();
  51. db_insert('ckeditor_input_format')->fields(array("name" => "Full", "format" => 'full_html'))->execute();
  52. //insert settings for default role
  53. $arr = array();
  54. $arr['filebrowser'] = 'none';
  55. $arr['quickupload'] = 'f';
  56. //security
  57. $arr['ss'] = "2";
  58. $arr['filters']['filter_html'] = 1;
  59. //appearance
  60. $arr['default'] = "t";
  61. $arr['show_toggle'] = "t";
  62. $arr['popup'] = variable_get('ckeditor_popup', 0) ? "t" : "f";
  63. // <!--break--> does not work in Filtered HTML, so DrupalBreak does not make sense here
  64. // https://drupal.org/node/881006
  65. $arr['toolbar'] = "
  66. [
  67. ['Source'],
  68. ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
  69. ['Undo','Redo','Find','Replace','-','SelectAll'],
  70. ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
  71. ['Maximize', 'ShowBlocks'],
  72. '/',
  73. ['Format'],
  74. ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],
  75. ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
  76. ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
  77. ['Link','Unlink','Anchor','Linkit']
  78. ]
  79. ";
  80. $arr['expand'] = variable_get('ckeditor_toolbar_start_expanded', 1) ? "t" : "f";
  81. $arr['width'] = variable_get("ckeditor_width", "100%");
  82. $arr['lang'] = "en";
  83. $arr['auto_lang'] = "t";
  84. $arr['language_direction'] = "default";
  85. //output
  86. $arr['enter_mode'] = "p";
  87. $arr['shift_enter_mode'] = "br";
  88. $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
  89. $arr['format_source'] = "t";
  90. $arr['format_output'] = "t";
  91. $arr['custom_formatting'] = "f";
  92. $arr['formatting']['custom_formatting_options'] = array('indent' => 'indent', 'breakBeforeOpen' => 'breakBeforeOpen', 'breakAfterOpen' => 'breakAfterOpen', 'breakAfterClose' => 'breakAfterClose');
  93. //css
  94. $arr['css_mode'] = "none";
  95. $arr['css_path'] = variable_get("ckeditor_stylesheet", "");
  96. //upload
  97. //get permissions here like in _update_role_permissions
  98. $arr['filebrowser'] = "none";
  99. $arr['user_choose'] = "f";
  100. $arr['ckeditor_load_method'] = "ckeditor.js";
  101. $arr['ckeditor_load_time_out'] = 0;
  102. $arr['scayt_autoStartup'] = "f";
  103. //advanced options
  104. $arr['html_entities'] = "f";
  105. db_insert('ckeditor_settings')->fields(array("name" => "Advanced", "settings" => serialize($arr)))->execute();
  106. //insert settings for advanced role
  107. $arr['toolbar'] = "
  108. [
  109. ['Source'],
  110. ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
  111. ['Undo','Redo','Find','Replace','-','SelectAll'],
  112. ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar','Iframe'],
  113. '/',
  114. ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],
  115. ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
  116. ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl','-','Language'],
  117. ['Link','Unlink','Anchor','Linkit'],
  118. ['DrupalBreak'],
  119. '/',
  120. ['Format','Font','FontSize'],
  121. ['TextColor','BGColor'],
  122. ['Maximize', 'ShowBlocks']
  123. ]
  124. ";
  125. $arr['filters'] = array();
  126. db_insert('ckeditor_settings')->fields(array("name" => "Full", "settings" => serialize($arr)))->execute();
  127. $arr = array();
  128. if (!empty($ckeditor_path)) {
  129. $arr['ckeditor_path'] = $ckeditor_path;
  130. }
  131. else {
  132. $arr['ckeditor_path'] = '//cdn.ckeditor.com/4.4.3/full-all';
  133. }
  134. db_insert('ckeditor_settings')->fields(array("name" => "CKEditor Global Profile", "settings" => serialize($arr)))->execute();
  135. module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin');
  136. }
  137. /**
  138. * Implementation of hook_schema().
  139. */
  140. function ckeditor_schema() {
  141. $schema['ckeditor_settings'] = array(
  142. 'description' => 'Stores CKEditor profile settings',
  143. 'fields' => array(
  144. 'name' => array(
  145. 'type' => 'varchar',
  146. 'not null' => TRUE,
  147. 'default' => '',
  148. 'length' => 128,
  149. 'description' => 'Name of the CKEditor profile',
  150. ),
  151. 'settings' => array(
  152. 'type' => 'text',
  153. 'description' => 'Profile settings',
  154. ),
  155. ),
  156. 'primary key' => array('name')
  157. );
  158. $schema['ckeditor_input_format'] = array(
  159. 'description' => 'Stores CKEditor input format assignments',
  160. 'fields' => array(
  161. 'name' => array(
  162. 'type' => 'varchar',
  163. 'not null' => TRUE,
  164. 'default' => '',
  165. 'length' => 128,
  166. 'description' => 'Name of the CKEditor role',
  167. ),
  168. 'format' => array(
  169. 'type' => 'varchar',
  170. 'not null' => TRUE,
  171. 'default' => '',
  172. 'length' => 128,
  173. 'description' => 'Drupal filter format ID',
  174. )
  175. ),
  176. 'primary key' => array('name', 'format'),
  177. );
  178. return $schema;
  179. }
  180. /**
  181. * Implementation of hook_requirements().
  182. *
  183. * This hook will issue warnings if:
  184. * - The CKEditor source files are not found.
  185. * - The CKEditor source files are out of date.
  186. * - Quick upload and/or the built-in file browser are used and $cookie_domain is not set.
  187. */
  188. function ckeditor_requirements($phase) {
  189. $requirements = array();
  190. if ($phase == 'runtime') {
  191. module_load_include('module', 'ckeditor');
  192. module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  193. $requirements['ckeditor'] = array(
  194. 'title' => t('CKEditor'),
  195. 'value' => t('Unknown'),
  196. );
  197. $requirements['ckeditor']['severity'] = REQUIREMENT_OK;
  198. if (!_ckeditor_requirements_isinstalled()) {
  199. $sourcepath = ckeditor_path('local');
  200. $requirements['ckeditor']['description'] = t('CKEditor was not found in <code>%sourcepath</code>.', array('%sourcepath' => $sourcepath));
  201. $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
  202. }
  203. elseif (($installed_version = _ckeditor_requirements_getinstalledversion()) === NULL) {
  204. $requirements['ckeditor']['description'] = t('CKEditor version could not be determined.');
  205. $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
  206. }
  207. else {
  208. $profile_name = _ckeditor_requirements_ckfinder_filebrowser_enabled();
  209. if ($profile_name !== FALSE) {
  210. if (!_ckeditor_requirements_cookiedomainset()) {
  211. $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
  212. $requirements['ckeditor']['description'] = t('You are using a feature that requires <code>$cookie_domain</code> to be set, but it is not set in your <code>settings.php</code> file (CKFinder is enabled in the !profile profile).', array('!profile' => l($profile_name, 'admin/config/content/ckeditor/edit/' . urlencode($profile_name))));
  213. }
  214. elseif ($error = _ckeditor_requirements_ckfinder_config_check($profile_name)) {
  215. $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
  216. $requirements['ckeditor']['description'] = $error;
  217. }
  218. }
  219. }
  220. if ((($installed_version = _ckeditor_requirements_getinstalledversion()) !== NULL) && $installed_version != '%VERSION%' && $installed_version != '<URL>' && (-1 == version_compare($installed_version, '3.1 SVN'))) {
  221. $requirements['ckeditor']['description'] = t('Some features are disabled because you are using an older version of CKEditor. Please upgrade to CKEditor 3.1 (or higher).');
  222. $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
  223. }
  224. if (!empty($installed_version)) {
  225. if ($installed_version == '%VERSION%') {
  226. $requirements['ckeditor']['value'] = 'GIT version';
  227. }
  228. else if ($installed_version == '<URL>') {
  229. $requirements['ckeditor']['value'] = 'Unknown version. CKEditor is loaded from a remote URL.';
  230. $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
  231. }
  232. else {
  233. $requirements['ckeditor']['value'] = $installed_version;
  234. }
  235. }
  236. else {
  237. $requirements['ckeditor']['value'] = t('Not found');
  238. }
  239. }
  240. return $requirements;
  241. }
  242. /**
  243. * Fetches the version of the installed CKEditor sources.
  244. *
  245. * It tries to locate the version of the CKEditor sources in
  246. * ckeditor.js.
  247. *
  248. * Releases have a version number such as "3.0.1".
  249. * SVN nightly releases have a minor version number with SVN appended: "3.0 SVN".
  250. * SVN checkouts have the string "[Development]".
  251. *
  252. * This function is used by ckeditor_requirements().
  253. *
  254. * @return string Version number (eg. 3.0) of CKEditor. Null if not found in ckeditor_basic.js.
  255. */
  256. function _ckeditor_requirements_getinstalledversion() {
  257. module_load_include('module', 'ckeditor');
  258. $editor_path = ckeditor_path('local', TRUE);
  259. if ($editor_path == '<URL>') {
  260. $url = ckeditor_path('url', TRUE);
  261. $matches = array();
  262. if (preg_match("|cdn.ckeditor.com/(\d(\.\d+)+.*)/|i", $url, $matches)) {
  263. return $matches[1];
  264. }
  265. return '<URL>';
  266. }
  267. $jspath = $editor_path . '/ckeditor.js';
  268. $configcontents = @file_get_contents($jspath);
  269. if (!$configcontents) {
  270. return NULL;
  271. }
  272. $matches = array();
  273. if (preg_match('#,version:[\'\"]{1}(.*?)[\'\"]{1},#', $configcontents, $matches)) {
  274. return $matches[1];
  275. }
  276. return NULL;
  277. }
  278. /**
  279. * Executed when the built-in file browser is enabled.
  280. * Returns FALSE if no errors are found in the config.php file, otherwise it returns an error message.
  281. *
  282. * @return string|boolean
  283. */
  284. function _ckeditor_requirements_ckfinder_config_check($profile_name) {
  285. global $base_url;
  286. module_load_include('module', 'ckeditor');
  287. $config_path = ckfinder_path('local') . '/config.php';
  288. if (!file_exists($config_path)) {
  289. return t('!ckfinder is not installed correctly: <code>!config</code> not found. Make sure that you uploaded all files and did not accidentally remove the configuration file. If you installed CKFinder in other location (e.g. in the libraries folder), make sure to update the path to CKFinder in !global.', array(
  290. '!config' => $config_path,
  291. '!ckfinder' => '<a href="http://cksource.com/ckfinder">CKFinder</a>',
  292. '!global' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg')
  293. ));
  294. }
  295. if (!is_readable($config_path)) {
  296. return t('CKEditor needs read permission to the <code>!config</code> file.', array('!config' => $config_path));
  297. }
  298. $config_contents = file($config_path);
  299. //not a 100% valid check, but well... let's have at least some error checking
  300. $require_once_found = FALSE;
  301. $require_once_line = 0;
  302. $userfiles_absolute_path_line = 0;
  303. $force_single_extension_line = 0;
  304. if ($config_contents) {
  305. foreach ($config_contents as $line_num => $line) {
  306. //make sure it doesn't start with a comment, unfortunately we're not protected if code is commented with /* */
  307. if (!$require_once_found && strpos($line, "filemanager.config.php") !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
  308. $require_once_found = TRUE;
  309. $require_once_line = $line_num;
  310. }
  311. /**
  312. * @todo Finish this
  313. */
  314. if (!$userfiles_absolute_path_line && strpos($line, '$Config[\'UserFilesAbsolutePath\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
  315. $userfiles_absolute_path_line = $line_num;
  316. }
  317. if (!$force_single_extension_line && strpos($line, '$Config[\'ForceSingleExtension\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
  318. $force_single_extension_line = $line_num;
  319. }
  320. }
  321. }
  322. if (!$require_once_found) {
  323. return t('You are using a feature that requires manual integration in the <code>config.php</code> file. Please read the "Installing CKFinder" section in the <code>!readme</code> file carefully and add a <code>require_once ...</code> statement to the <code>%ckfconfig</code> file.', array('%ckfconfig' => $config_path, '!readme' => l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array('absolute' => TRUE))));
  324. }
  325. if ($userfiles_absolute_path_line && $force_single_extension_line && (
  326. $require_once_line < $userfiles_absolute_path_line || $require_once_line > $force_single_extension_line)) {
  327. return t('You are using a feature that requires manual integration in the <code>config.php</code> file. You have added a <code>require_once ...</code> statement to the <code>%ckfconfig</code> file, but in the wrong line.', array('%ckfconfig' => $config_path));
  328. }
  329. return FALSE;
  330. }
  331. /**
  332. * Checks if any profile requires an explicit setting of $cookie_domain
  333. * in settings.php.
  334. *
  335. * %cookie_domain is required when the internal file browser or quick upload is used.
  336. *
  337. * This function is used by ckeditor_requirements().
  338. *
  339. * @return boolean True if any profile requires $cookie_domain.
  340. */
  341. function _ckeditor_requirements_ckfinder_filebrowser_enabled() {
  342. module_load_include('module', 'ckeditor');
  343. $profiles = ckeditor_profile_load();
  344. foreach ($profiles as $profile) {
  345. if ((isset($profile->settings['filebrowser']) && $profile->settings['filebrowser'] == 'ckfinder')) {
  346. return $profile->name;
  347. }
  348. }
  349. return FALSE;
  350. }
  351. /**
  352. * Checks if $cookie_domain was set.
  353. *
  354. * It has to include settings.php again because conf_init() sets
  355. * $cookie_domain regardless of its presence in settings.php, so
  356. * simply checking $GLOBALS['cookie_domain'] is not possible.
  357. *
  358. * This function is used by ckeditor_requirements().
  359. *
  360. * @return boolean True if $cookie_domain was set in settings.php.
  361. */
  362. function _ckeditor_requirements_cookiedomainset() {
  363. if (file_exists('./' . conf_path() . '/settings.php')) {
  364. $settings = file_get_contents('./' . conf_path() . '/settings.php');
  365. if (preg_match('#^\s*\$cookie_domain#m', $settings)) {
  366. return TRUE;
  367. }
  368. }
  369. return FALSE;
  370. }
  371. /**
  372. * Updates broken settings for the 'Full' profile. (Resets toolbar to default)
  373. */
  374. function ckeditor_update_7000() {
  375. _ckeditor_d6_to_d7_migration();
  376. $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'Full'))->fetchField();
  377. $settings = unserialize($result);
  378. $settings['toolbar'] = "
  379. [
  380. ['Source'],
  381. ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
  382. ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
  383. ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
  384. '/',
  385. ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
  386. ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
  387. ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
  388. ['Link','Unlink','Anchor'],
  389. ['DrupalBreak'],
  390. '/',
  391. ['Format','Font','FontSize'],
  392. ['TextColor','BGColor'],
  393. ['Maximize', 'ShowBlocks']
  394. ]
  395. ";
  396. $settings = serialize($settings);
  397. $update = db_update('ckeditor_settings')
  398. ->fields(array(
  399. 'settings' => $settings,
  400. ))
  401. ->condition('name', 'Full', '=')
  402. ->execute();
  403. }
  404. /**
  405. * Removes the 'DrupalBreak' button from the 'Advanced' profile. (Resets toolbar to default)
  406. */
  407. function ckeditor_update_7001() {
  408. $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'Advanced'))->fetchField();
  409. $settings = unserialize($result);
  410. $settings['toolbar'] = "
  411. [
  412. ['Source'],
  413. ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
  414. ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
  415. ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
  416. ['Maximize', 'ShowBlocks'],
  417. '/',
  418. ['Format'],
  419. ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
  420. ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
  421. ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
  422. ['Link','Unlink','Anchor']
  423. ]
  424. ";
  425. $settings = serialize($settings);
  426. $update = db_update('ckeditor_settings')
  427. ->fields(array(
  428. 'settings' => $settings,
  429. ))
  430. ->condition('name', 'Advanced', '=')
  431. ->execute();
  432. }
  433. /**
  434. * Rewrites 'Path to CKEditor' to new flags.
  435. */
  436. function ckeditor_update_7002() {
  437. $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'CKEditor Global Profile'))->fetchField();
  438. $settings = unserialize($result);
  439. if ($settings['ckeditor_path'] == '%b/sites/all/libraries/ckeditor') {
  440. $settings['ckeditor_path'] = '%l/ckeditor';
  441. }
  442. else {
  443. $settings['ckeditor_path'] = str_replace('%b/', '', $settings['ckeditor_path']);
  444. $settings['ckeditor_path'] = str_replace('%b', '', $settings['ckeditor_path']);
  445. }
  446. $settings = serialize($settings);
  447. $update = db_update('ckeditor_settings')
  448. ->fields(array(
  449. 'settings' => $settings,
  450. ))
  451. ->condition('name', 'CKEditor Global Profile', '=')
  452. ->execute();
  453. }
  454. /**
  455. * Fixes static paths to plugin files.
  456. */
  457. function ckeditor_update_7003() {
  458. module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  459. module_load_include('module', 'ckeditor');
  460. _ckeditor_d6_to_d7_migration();
  461. $render = array();
  462. $render["%base_path%"] = base_path();
  463. $render["%editor_path%"] = ckeditor_path('relative') . '/';
  464. $render["%ckeditor_path%"] = ckeditor_module_path('relative');
  465. $render["%plugin_dir%"] = $render["%module_path%"] . '/plugins/';
  466. $result = db_query("SELECT * FROM {ckeditor_settings} WHERE name <> :name", array(':name' => 'CKEditor Global Profile'))->fetchAllAssoc('name');
  467. foreach ((array) $result as $profile) {
  468. $name = $profile->name;
  469. $settings = unserialize($profile->settings);
  470. foreach ((array) $settings['loadPlugins'] as $i => $plugin) {
  471. $settings['loadPlugins'][$i]['path'] = str_replace(array_values($render), array_keys($render), $plugin['path']);
  472. }
  473. $settings = serialize($settings);
  474. $update = db_update('ckeditor_settings')
  475. ->fields(array(
  476. 'settings' => $settings,
  477. ))
  478. ->condition('name', $name, '=')
  479. ->execute();
  480. }
  481. }
  482. /**
  483. * Minor update for those who have run update.php with problems.
  484. * @see http://drupal.org/node/1347682 for a better explanation.
  485. */
  486. function ckeditor_update_7004() {
  487. return _ckeditor_d6_to_d7_migration();
  488. }
  489. /**
  490. * Fixes plugin paths stored in database.
  491. * @see http://drupal.org/node/1864760 for more information
  492. */
  493. function ckeditor_update_7005() {
  494. $result = db_query("SELECT * FROM {ckeditor_settings} WHERE name <> :name", array(':name' => 'CKEditor Global Profile'))->fetchAllAssoc('name');
  495. foreach ((array) $result as $profile) {
  496. $name = $profile->name;
  497. $settings = unserialize($profile->settings);
  498. $replace = array(
  499. "%base_path%%editor_path%" => "%editor_path%",
  500. "%base_path%%module_path%" => "%module_path%",
  501. "%base_path%%plugin_dir%" => "%plugin_dir%",
  502. "%base_path%%plugin_dir_extra%" => "%plugin_dir_extra%"
  503. );
  504. foreach ((array) $settings['loadPlugins'] as $i => $plugin) {
  505. $settings['loadPlugins'][$i]['path'] = str_replace(array_keys($replace), array_values($replace), $plugin['path']);
  506. }
  507. $settings = serialize($settings);
  508. db_update('ckeditor_settings')
  509. ->fields(array(
  510. 'settings' => $settings,
  511. ))
  512. ->condition('name', $name, '=')
  513. ->execute();
  514. }
  515. }
  516. /**
  517. * Adapts D6 table structure to D7 schema.
  518. */
  519. function _ckeditor_d6_to_d7_migration() {
  520. if (db_table_exists('ckeditor_role')) {
  521. db_drop_table('ckeditor_role');
  522. }
  523. if (!db_table_exists('ckeditor_input_format')) {
  524. $ckeditor_input_format = array(
  525. 'description' => 'Stores CKEditor input format assignments',
  526. 'fields' => array(
  527. 'name' => array(
  528. 'type' => 'varchar',
  529. 'not null' => TRUE,
  530. 'default' => '',
  531. 'length' => 128,
  532. 'description' => 'Name of the CKEditor role',
  533. ),
  534. 'format' => array(
  535. 'type' => 'varchar',
  536. 'not null' => TRUE,
  537. 'default' => '',
  538. 'length' => 128,
  539. 'description' => 'Drupal filter format ID',
  540. )
  541. ),
  542. 'primary key' => array('name', 'format'),
  543. );
  544. db_create_table('ckeditor_input_format', $ckeditor_input_format);
  545. }
  546. }