View source
<?php
function ckeditor_install() {
module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
$ckeditor_path = _ckeditor_script_path();
db_insert('ckeditor_input_format')
->fields(array(
"name" => "Advanced",
"format" => 'filtered_html',
))
->execute();
db_insert('ckeditor_input_format')
->fields(array(
"name" => "Full",
"format" => 'full_html',
))
->execute();
$arr = array();
$arr['filebrowser'] = 'none';
$arr['quickupload'] = 'f';
$arr['ss'] = "2";
$arr['filters']['filter_html'] = 1;
$arr['default'] = "t";
$arr['show_toggle'] = "t";
$arr['popup'] = variable_get('ckeditor_popup', 0) ? "t" : "f";
$arr['toolbar'] = "\n[\n ['Source'],\n ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],\n ['Undo','Redo','Find','Replace','-','SelectAll'],\n ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar'],\n ['Maximize', 'ShowBlocks'],\n '/',\n ['Format'],\n ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],\n ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],\n ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],\n ['Link','Unlink','Anchor','Linkit']\n]\n ";
$arr['expand'] = variable_get('ckeditor_toolbar_start_expanded', 1) ? "t" : "f";
$arr['width'] = variable_get("ckeditor_width", "100%");
$arr['lang'] = "en";
$arr['auto_lang'] = "t";
$arr['language_direction'] = "default";
$arr['enter_mode'] = "p";
$arr['shift_enter_mode'] = "br";
$arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
$arr['format_source'] = "t";
$arr['format_output'] = "t";
$arr['custom_formatting'] = "f";
$arr['formatting']['custom_formatting_options'] = array(
'indent' => 'indent',
'breakBeforeOpen' => 'breakBeforeOpen',
'breakAfterOpen' => 'breakAfterOpen',
'breakAfterClose' => 'breakAfterClose',
);
$arr['css_mode'] = "none";
$arr['css_path'] = variable_get("ckeditor_stylesheet", "");
$arr['config_js'] = "none";
$arr['config_js_path'] = "";
$arr['filebrowser'] = "none";
$arr['user_choose'] = "f";
$arr['ckeditor_load_method'] = "ckeditor.js";
$arr['ckeditor_load_time_out'] = 0;
$arr['scayt_autoStartup'] = "f";
$arr['html_entities'] = "f";
db_insert('ckeditor_settings')
->fields(array(
"name" => "Advanced",
"settings" => serialize($arr),
))
->execute();
$arr['toolbar'] = "\n[\n ['Source'],\n ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],\n ['Undo','Redo','Find','Replace','-','SelectAll'],\n ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar','Iframe'],\n '/',\n ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],\n ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],\n ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl','-','Language'],\n ['Link','Unlink','Anchor','Linkit'],\n ['DrupalBreak'],\n '/',\n ['Format','Font','FontSize'],\n ['TextColor','BGColor'],\n ['Maximize', 'ShowBlocks']\n]\n ";
$arr['filters'] = array();
db_insert('ckeditor_settings')
->fields(array(
"name" => "Full",
"settings" => serialize($arr),
))
->execute();
$arr = array();
if (!empty($ckeditor_path)) {
$arr['ckeditor_path'] = $ckeditor_path;
}
else {
$arr['ckeditor_path'] = '//cdn.ckeditor.com/' . CKEDITOR_LATEST . '/full-all';
}
db_insert('ckeditor_settings')
->fields(array(
"name" => "CKEditor Global Profile",
"settings" => serialize($arr),
))
->execute();
module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin');
}
function ckeditor_schema() {
$schema['ckeditor_settings'] = array(
'description' => 'Stores CKEditor profile settings',
'fields' => array(
'name' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 128,
'description' => 'Name of the CKEditor profile',
),
'settings' => array(
'type' => 'text',
'description' => 'Profile settings',
),
),
'primary key' => array(
'name',
),
);
$schema['ckeditor_input_format'] = array(
'description' => 'Stores CKEditor input format assignments',
'fields' => array(
'name' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 128,
'description' => 'Name of the CKEditor role',
),
'format' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 128,
'description' => 'Drupal filter format ID',
),
),
'primary key' => array(
'name',
'format',
),
);
return $schema;
}
function ckeditor_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
module_load_include('module', 'ckeditor');
module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
$requirements['ckeditor'] = array(
'title' => t('CKEditor'),
'value' => t('Unknown'),
);
$requirements['ckeditor']['severity'] = REQUIREMENT_OK;
if (!_ckeditor_requirements_isinstalled()) {
$sourcepath = ckeditor_path('local');
$requirements['ckeditor']['description'] = t('CKEditor was not found in <code>%sourcepath</code>.', array(
'%sourcepath' => $sourcepath,
));
$requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
}
elseif (($installed_version = _ckeditor_requirements_getinstalledversion()) === NULL) {
$requirements['ckeditor']['description'] = t('CKEditor version could not be determined.');
$requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
}
else {
$profile_name = _ckeditor_requirements_ckfinder_filebrowser_enabled();
if ($profile_name !== FALSE) {
if (!_ckeditor_requirements_cookiedomainset()) {
$requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
$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)),
));
}
elseif ($error = _ckeditor_requirements_ckfinder_config_check($profile_name)) {
$requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
$requirements['ckeditor']['description'] = $error;
}
}
}
if (($installed_version = _ckeditor_requirements_getinstalledversion()) !== NULL && $installed_version != '%VERSION%' && $installed_version != '<URL>' && -1 == version_compare($installed_version, '3.1 SVN')) {
$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).');
$requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
}
if (!empty($installed_version)) {
if ($installed_version == '%VERSION%') {
$requirements['ckeditor']['value'] = 'GIT version';
}
else {
if ($installed_version == '<URL>') {
$requirements['ckeditor']['value'] = 'Unknown version. CKEditor is loaded from a remote URL.';
$requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
}
else {
$requirements['ckeditor']['value'] = $installed_version;
}
}
}
else {
$requirements['ckeditor']['value'] = t('Not found');
}
}
return $requirements;
}
function _ckeditor_requirements_getinstalledversion() {
module_load_include('module', 'ckeditor');
$editor_path = ckeditor_path('local', TRUE);
if ($editor_path == '<URL>') {
$url = ckeditor_path('url', TRUE);
$matches = array();
if (preg_match("|cdn.ckeditor.com/(\\d(\\.\\d+)+.*)/|i", $url, $matches)) {
return $matches[1];
}
return '<URL>';
}
$jspath = $editor_path . '/ckeditor.js';
$configcontents = @file_get_contents($jspath);
if (!$configcontents) {
return NULL;
}
$matches = array();
if (preg_match('#,version:[\'\\"]{1}(.*?)[\'\\"]{1},#', $configcontents, $matches)) {
return $matches[1];
}
return NULL;
}
function _ckeditor_requirements_ckfinder_config_check($profile_name) {
global $base_url;
module_load_include('module', 'ckeditor');
$config_path = ckfinder_path('local') . '/config.php';
if (!file_exists($config_path)) {
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(
'!config' => $config_path,
'!ckfinder' => '<a href="http://cksource.com/ckfinder">CKFinder</a>',
'!global' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg'),
));
}
if (!is_readable($config_path)) {
return t('CKEditor needs read permission to the <code>!config</code> file.', array(
'!config' => $config_path,
));
}
$config_contents = file($config_path);
$require_once_found = FALSE;
$require_once_line = 0;
$userfiles_absolute_path_line = 0;
$force_single_extension_line = 0;
if ($config_contents) {
foreach ($config_contents as $line_num => $line) {
if (!$require_once_found && strpos($line, "filemanager.config.php") !== FALSE && !preg_match(",^(?://|\\#|\\*|/\\*),", trim($line))) {
$require_once_found = TRUE;
$require_once_line = $line_num;
}
if (!$userfiles_absolute_path_line && strpos($line, '$Config[\'UserFilesAbsolutePath\']') !== FALSE && !preg_match(",^(?://|\\#|\\*|/\\*),", trim($line))) {
$userfiles_absolute_path_line = $line_num;
}
if (!$force_single_extension_line && strpos($line, '$Config[\'ForceSingleExtension\']') !== FALSE && !preg_match(",^(?://|\\#|\\*|/\\*),", trim($line))) {
$force_single_extension_line = $line_num;
}
}
}
if (!$require_once_found) {
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,
)),
));
}
if ($userfiles_absolute_path_line && $force_single_extension_line && ($require_once_line < $userfiles_absolute_path_line || $require_once_line > $force_single_extension_line)) {
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,
));
}
return FALSE;
}
function _ckeditor_requirements_ckfinder_filebrowser_enabled() {
module_load_include('module', 'ckeditor');
$profiles = ckeditor_profile_load();
foreach ($profiles as $profile) {
if (isset($profile->settings['filebrowser']) && $profile->settings['filebrowser'] == 'ckfinder') {
return $profile->name;
}
}
return FALSE;
}
function _ckeditor_requirements_cookiedomainset() {
if (file_exists('./' . conf_path() . '/settings.php')) {
$settings = file_get_contents('./' . conf_path() . '/settings.php');
if (preg_match('#^\\s*\\$cookie_domain#m', $settings)) {
return TRUE;
}
}
return FALSE;
}
function ckeditor_update_7000() {
_ckeditor_d6_to_d7_migration();
$result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(
':name' => 'Full',
))
->fetchField();
$settings = unserialize($result);
$settings['toolbar'] = "\n[\n ['Source'],\n ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],\n ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],\n ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],\n '/',\n ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],\n ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],\n ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],\n ['Link','Unlink','Anchor'],\n ['DrupalBreak'],\n '/',\n ['Format','Font','FontSize'],\n ['TextColor','BGColor'],\n ['Maximize', 'ShowBlocks']\n]\n ";
$settings = serialize($settings);
$update = db_update('ckeditor_settings')
->fields(array(
'settings' => $settings,
))
->condition('name', 'Full', '=')
->execute();
}
function ckeditor_update_7001() {
$result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(
':name' => 'Advanced',
))
->fetchField();
$settings = unserialize($result);
$settings['toolbar'] = "\n[\n ['Source'],\n ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],\n ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],\n ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],\n ['Maximize', 'ShowBlocks'],\n '/',\n ['Format'],\n ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],\n ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],\n ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],\n ['Link','Unlink','Anchor']\n]\n ";
$settings = serialize($settings);
$update = db_update('ckeditor_settings')
->fields(array(
'settings' => $settings,
))
->condition('name', 'Advanced', '=')
->execute();
}
function ckeditor_update_7002() {
$result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(
':name' => 'CKEditor Global Profile',
))
->fetchField();
$settings = unserialize($result);
if ($settings['ckeditor_path'] == '%b/sites/all/libraries/ckeditor') {
$settings['ckeditor_path'] = '%l/ckeditor';
}
else {
$settings['ckeditor_path'] = str_replace('%b/', '', $settings['ckeditor_path']);
$settings['ckeditor_path'] = str_replace('%b', '', $settings['ckeditor_path']);
}
$settings = serialize($settings);
$update = db_update('ckeditor_settings')
->fields(array(
'settings' => $settings,
))
->condition('name', 'CKEditor Global Profile', '=')
->execute();
}
function ckeditor_update_7003() {
module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
module_load_include('module', 'ckeditor');
_ckeditor_d6_to_d7_migration();
$render = array();
$render["%base_path%"] = base_path();
$render["%editor_path%"] = ckeditor_path('relative') . '/';
$render["%ckeditor_path%"] = ckeditor_module_path('relative');
$render["%plugin_dir%"] = $render["%module_path%"] . '/plugins/';
$result = db_query("SELECT * FROM {ckeditor_settings} WHERE name <> :name", array(
':name' => 'CKEditor Global Profile',
))
->fetchAllAssoc('name');
foreach ((array) $result as $profile) {
$name = $profile->name;
$settings = unserialize($profile->settings);
foreach ((array) $settings['loadPlugins'] as $i => $plugin) {
$settings['loadPlugins'][$i]['path'] = str_replace(array_values($render), array_keys($render), $plugin['path']);
}
$settings = serialize($settings);
$update = db_update('ckeditor_settings')
->fields(array(
'settings' => $settings,
))
->condition('name', $name, '=')
->execute();
}
}
function ckeditor_update_7004() {
return _ckeditor_d6_to_d7_migration();
}
function ckeditor_update_7005() {
$result = db_query("SELECT * FROM {ckeditor_settings} WHERE name <> :name", array(
':name' => 'CKEditor Global Profile',
))
->fetchAllAssoc('name');
foreach ((array) $result as $profile) {
$name = $profile->name;
$settings = unserialize($profile->settings);
$replace = array(
"%base_path%%editor_path%" => "%editor_path%",
"%base_path%%module_path%" => "%module_path%",
"%base_path%%plugin_dir%" => "%plugin_dir%",
"%base_path%%plugin_dir_extra%" => "%plugin_dir_extra%",
);
foreach ((array) $settings['loadPlugins'] as $i => $plugin) {
$settings['loadPlugins'][$i]['path'] = str_replace(array_keys($replace), array_values($replace), $plugin['path']);
}
$settings = serialize($settings);
db_update('ckeditor_settings')
->fields(array(
'settings' => $settings,
))
->condition('name', $name, '=')
->execute();
}
}
function ckeditor_update_7006() {
if (!module_exists('locale') || !db_table_exists('locales_source')) {
return t('No translations to fix as the locale system is not enabled.');
}
$module_path = ckeditor_module_path('url');
$javascript = [
[
'type' => 'file',
'data' => $module_path . '/includes/ckeditor.utils.js',
],
[
'type' => 'file',
'data' => $module_path . '/plugins/drupalbreaks/plugin.js',
],
[
'type' => 'file',
'data' => $module_path . '/plugins/mediaembed/dialogs/mediaembed.js',
],
];
if (function_exists('locale_js_alter')) {
locale_js_alter($javascript);
}
}
function _ckeditor_d6_to_d7_migration() {
if (db_table_exists('ckeditor_role')) {
db_drop_table('ckeditor_role');
}
if (!db_table_exists('ckeditor_input_format')) {
$ckeditor_input_format = array(
'description' => 'Stores CKEditor input format assignments',
'fields' => array(
'name' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 128,
'description' => 'Name of the CKEditor role',
),
'format' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 128,
'description' => 'Drupal filter format ID',
),
),
'primary key' => array(
'name',
'format',
),
);
db_create_table('ckeditor_input_format', $ckeditor_input_format);
}
}