' && !_ckeditor_requirements_isinstalled()) {
drupal_set_message(t(
'Checking for !filename or !file.', array(
'!filename' => '' . $ckconfig_file . '
',
'!file' => 'sites/all/libraries/ckeditor/ckeditor.js
'
)
));
drupal_set_message(t(
'The CKEditor component is not installed correctly. Please go to the !ckeditorlink in order to download the latest version. After that you must extract the files to the !ckeditorpath or !librarypath directory and make sure that the !ckeditorfile or !ckeditorlibrary file exists. Refer to the !readme file for more information.', array(
'!ckeditorlink' => l(t('CKEditor homepage'), 'http://ckeditor.com/download'),
'!readme' => l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array('absolute' => TRUE)),
'!ckeditorpath' => 'sites/all/modules/ckeditor/ckeditor
',
'!ckeditorfile' => 'sites/all/modules/ckeditor/ckeditor/ckeditor.js
',
'!ckeditorlibrary' => 'sites/all/libraries/ckeditor/ckeditor.js
',
'!librarypath' => 'sites/all/libraries/ckeditor
'
)
), 'error');
drupal_set_message(t(
'If you have CKEditor already installed, edit the !editg and update the CKEditor path.', array(
'!editg' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg')
)
), 'warning');
return '';
}
if (module_exists('wysiwyg')) {
drupal_set_message(t(
'The WYSIWYG module was detected. Using both modules at the same time may cause problems. It is recommended to turn the WYSIWYG module off (!wysiwygdisablelink).', array(
'!wysiwygdisablelink' => l(t('click here to disable'), 'ckeditor/disable/wysiwyg/' . drupal_get_token('ckeditorDisableWysiwyg'))
)
), 'warning');
}
//find profile other than Global
$result = db_select('ckeditor_settings', 's')->fields('s', array('name'))->condition('name', 'CKEditor Global Profile', '<>')->range(0, 1)->execute()->fetchAssoc();
if (!$result) {
drupal_set_message(t('No CKEditor profiles found. Right now nobody is able to use CKEditor. Create a new profile below.'), 'error');
}
return ckeditor_profile_overview();
}
/**
* Controller for CKEditor profiles.
*/
function ckeditor_profile_overview() {
$output = '';
$skins = ckeditor_load_skin_options();
$global_profile = ckeditor_profile_load('CKEditor Global Profile');
if (isset($global_profile->settings['skin']) && !array_key_exists($global_profile->settings['skin'], $skins)) {
drupal_set_message(t('The CKEditor Global Profile profile is using %skin skin which cannot be found. Please update your settings.', array('%skin' => $global_profile->settings['skin'], '@profile_settings' => url('admin/config/content/ckeditor/editg'))), 'warning');
}
$profiles = ckeditor_profile_load();
if ($profiles) {
$access_ckeditor_roles = user_roles(FALSE, 'access ckeditor');
$header = array(t('Profile'), t('Input format'), t('Operations'));
$plugins = ckeditor_load_plugins();
$disabled_plugins = array();
foreach ($profiles as $p) {
if ($p->name !== "CKEditor Global Profile") {
if (isset($p->settings['loadPlugins']) && is_array($p->settings['loadPlugins']) && count($p->settings['loadPlugins']) > 0) {
$changed = FALSE;
foreach ($p->settings['loadPlugins'] as $plugin_name => $plugin_settings) {
if (!array_key_exists($plugin_name, $plugins)) {
if (isset($plugin_settings['active']) && $plugin_settings['active'] == 0) {
continue;
}
if (!isset($disabled_plugins[$p->name])) {
$disabled_plugins[$p->name] = array();
}
$p->settings['loadPlugins'][$plugin_name]['active'] = 0;
$disabled_plugins[$p->name][] = $plugin_name;
$changed = TRUE;
}
}
if ($changed === TRUE) {
db_update('ckeditor_settings')
->fields(array(
'settings' => serialize($p->settings)
))
->condition('name', $p->name, '=')
->execute();
}
}
$rows[] = array(
array('data' => $p->name, 'valign' => 'top'),
array('data' => implode("
\n", $p->input_formats)),
array(
'data' =>
l(t('edit'), 'admin/config/content/ckeditor/edit/' . urlencode($p->name)) . ' ' .
l(t('clone'), 'admin/config/content/ckeditor/clone/' . urlencode($p->name)) . ' ' .
l(t('delete'), 'admin/config/content/ckeditor/delete/' . urlencode($p->name)),
'valign' => 'top'
)
);
}
}
if (count($disabled_plugins) > 0) {
$msg = t("The following plugins could not be found and were automatically disabled in CKEditor profiles:");
foreach ($disabled_plugins as $profile_name => $profile_plugins) {
$msg .= "
";
$msg .= t("Profile: %profile_name", array("%profile_name" => $profile_name));
$msg .= "
";
$msg .= t("Plugins: %profile_plugins", array("%profile_plugins" => implode(', ', $profile_plugins)));
}
drupal_set_message($msg, 'warning');
}
$output .= '
' . l(t('Create a new profile'), 'admin/config/content/ckeditor/add') . '
'; } else { drupal_set_message(t( 'No profiles found. Click here to !create.', array( '!create' => l(t('create a new profile'), 'admin/config/content/ckeditor/add') ) ), 'warning'); } $rows = array(); if (!isset($profiles['CKEditor Global Profile'])) { drupal_set_message(t( 'The global profile can not be found. Click here to !create.', array( '!create' => l(t('create the global profile'), 'admin/config/content/ckeditor/addg') ) ), 'warning'); } else { $output .= "%b
',
'!m' => '%m
',
'!l' => '%l
',
'!base' => '' . $drupal_base_path . '
',
'!module' => '' . $module_drupal_path . '
',
'!library' => '' . $drupal_library_path . '
',
)
) .
'' . $current_path . '
'
)
),
'#required' => TRUE
);
$local_path = ckeditor_path('local');
if ($local_path == 'index.php
'
)
) .
'' . $local_path . '
'
)
)
);
$form['ckeditor_advanced_settings']['ckeditor_plugins_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to the CKEditor plugins directory'),
'#default_value' => !empty($profile->settings['ckeditor_plugins_path']) ? $profile->settings['ckeditor_plugins_path'] : '%m/plugins',
'#size' => 40,
'#maxlength' => 128,
'#description' => t('Path to the CKEditor plugins directory relative to the document root.') .
'%b
',
'!m' => '%m
',
'!l' => '%l
',
'!base' => '' . $drupal_base_path . '
',
'!module' => '' . $module_drupal_path . '
',
'!library' => '' . $drupal_library_path . '
',
)
) .
'' . ckeditor_plugins_path('relative') . '
'
)
)
);
$form['ckeditor_advanced_settings']['ckeditor_plugins_local_path'] = array(
'#type' => 'textfield',
'#title' => t('Local path to the CKEditor plugins directory'),
'#default_value' => isset($profile->settings['ckeditor_plugins_local_path']) ? $profile->settings['ckeditor_plugins_local_path'] : '',
'#size' => 40,
'#maxlength' => 128,
'#description' => t(
'The path to the local directory (on the server) that points to the path defined above. Enter either an absolute server path or a path relative to the !indexphp file. If left empty, the CKEditor module will try to find the right path.', array(
'!indexphp' => 'index.php
'
)
) .
'' . ckeditor_plugins_path('local') . '
'
)
)
);
$form['ckeditor_advanced_settings']['ckfinder_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to CKFinder'),
'#default_value' => !empty($profile->settings['ckfinder_path']) ? $profile->settings['ckfinder_path'] : '%m/ckfinder',
'#size' => 40,
'#maxlength' => 128,
'#description' => t(
'The path to CKFinder (AJAX based file manager downloaded from !ckfindercom) relative to the document root.', array(
'!ckfindercom' => l(t('ckfinder.com'), 'http://cksource.com/ckfinder')
)
) .
'%b
',
'!m' => '%m
',
'!l' => '%l
',
'!base' => '' . $drupal_base_path . '
',
'!module' => '' . $module_drupal_path . '
',
'!library' => '' . $drupal_library_path . '
'
)
) .
'' . ckfinder_path('relative') . '
'
)
)
);
$form['ckeditor_advanced_settings']['ckfinder_local_path'] = array(
'#type' => 'textfield',
'#title' => t('Local path to CKFinder'),
'#default_value' => isset($profile->settings['ckfinder_local_path']) ? $profile->settings['ckfinder_local_path'] : '',
'#size' => 40,
'#maxlength' => 128,
'#description' => t(
'The path to the local directory (on the server) that points to the path defined above. Enter either an absolute server path or a path relative to the !indexphp file. If left empty, the CKEditor module will try to find the right path.', array(
'!indexphp' => 'index.php
'
)
) .
'' . ckfinder_path('local') . '
'
)
)
);
//@todo DOWNLOAD API
if (variable_get('file_default_scheme', '') == 'private') {
$form['ckeditor_advanced_settings']['ckeditor_allow_download_private_files'] = array(
'#type' => 'checkbox',
'#title' => t('Enable access to files located in the private folder'),
'#default_value' => !empty($profile->settings['ckeditor_allow_download_private_files']),
'#return_value' => 't',
'#description' => t(
'Use this option with care. If checked, CKEditor will allow anyone knowing the URL to view a file located inside of the private path (!private_path), but only if there is no information about the file in the Drupal database. If the path below is specified, anyone will have access only to that location.', array(
'!private_path' => '' . variable_get('file_private_path', '') . '
'
)
),
'#required' => FALSE
);
$current_private_dir = !empty($profile->settings['private_dir']) ? $profile->settings['private_dir'] : '';
$form['ckeditor_advanced_settings']['private_dir'] = array(
'#type' => 'textfield',
'#title' => t('Location of files uploaded with CKEditor to the private folder'),
'#default_value' => !empty($profile->settings['private_dir']) ? $profile->settings['private_dir'] : '',
'#size' => 40,
'#maxlength' => 255,
'#description' => t('The path relative to the location of the private directory where CKEditor should store uploaded files.') .
'%u
',
'!n' => '%n
'
)
) .
'' . realpath(variable_get('file_private_path', conf_path() . '/files')) . DIRECTORY_SEPARATOR . '
'
)
)
);
}
if (function_exists('linktocontent_node_menu') && function_exists('pathfilter_filter')) {
$form['ckeditor_advanced_settings']['linktoc'] = array(
'#type' => 'select',
'#options' => array('p' => t('Link to paths only'), 'n' => t('Link using internal: links'), 'pn' => t('Allow the user to select between paths and internal links')),
'#title' => t('Path Filter & Link To Content integration'),
'#default_value' => empty($profile->settings['linktoc']) ? 'p' : $profile->settings['linktoc'],
'#description' => t(
'With the !plink extension it is possible to use internal: links. By default the !link extension is linking to nodes using paths.', array(
'!plink' => l(t('Path Filter'), 'http://drupal.org/project/pathfilter'),
'!link' => l(t('Link To Content'), 'http://drupal.org/project/linktocontent')
)
)
);
}
$form['ckeditor_advanced_settings']['ckeditor_aggregate'] = array(
'#type' => 'radios',
'#title' => t('Aggregate ckeditor.js
'),
'#default_value' => !empty($profile->settings['ckeditor_aggregate']) ? $profile->settings['ckeditor_aggregate'] : 'f',
'#options' => array(
't' => t('Enabled'),
'f' => t('Disabled')
),
'#description' => t('When enabled, ckeditor.js
will be aggregated if JavaScript aggregation is enabled. Not recommended.'),
);
$form['ckeditor_advanced_settings']['toolbar_wizard'] = array(
'#type' => 'radios',
'#title' => t('Use toolbar Drag&Drop feature'),
'#default_value' => !empty($profile->settings['toolbar_wizard']) ? $profile->settings['toolbar_wizard'] : 't',
'#options' => array(
't' => t('Enabled'),
'f' => t('Disabled')
),
'#description' => t('When enabled, the toolbar can be built by using the drag-and-drop feature. Otherwise you will need to enter the toolbar configuration manually to the text box.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $btn
);
return $form;
}
/**
* Form validation for a global profile
*/
function ckeditor_admin_global_profile_form_validate($form, &$form_state) {
}
/**
* Submit form for a global profile
*/
function ckeditor_admin_global_profile_form_submit($form, &$form_state) {
module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
$edit = & $form_state['values'];
$edit['name'] = 'CKEditor Global Profile';
if (isset($edit['_profile'])) {
ckeditor_profile_delete($edit['_profile']->name);
}
//strip whitespaces
if (empty($edit['ckeditor_local_path'])) {
$edit['ckeditor_local_path'] = '';
}
else {
$edit['ckeditor_local_path'] = trim($edit['ckeditor_local_path']);
}
//strip slash from the end
if (empty($edit['ckeditor_path'])) {
$edit['ckeditor_path'] = '';
}
$edit['ckeditor_path'] = trim(rtrim($edit['ckeditor_path'], "/"));
if ($edit['ckeditor_path'] && 0 !== strpos($edit['ckeditor_path'], "/") && 0 !== strpos($edit['ckeditor_path'], "%") && !preg_match("|^http(s)?://|i", $edit['ckeditor_path'])) {
//ensure that slash is at the beginning
$edit['ckeditor_path'] = "/" . $edit['ckeditor_path'];
}
//no slash at the end
$edit['ckeditor_local_path'] = trim(rtrim($edit['ckeditor_local_path'], "/"));
//strip whitespaces
if (empty($edit['ckeditor_plugins_local_path'])) {
$edit['ckeditor_plugins_local_path'] = '';
}
else {
$edit['ckeditor_plugins_local_path'] = trim($edit['ckeditor_plugins_local_path']);
}
//strip slash from the end
if (empty($edit['ckeditor_plugins_path'])) {
$edit['ckeditor_plugins_path'] = '';
}
$edit['ckeditor_plugins_path'] = trim(rtrim($edit['ckeditor_plugins_path'], "/"));
if ($edit['ckeditor_plugins_path'] && 0 !== strpos($edit['ckeditor_plugins_path'], "/") && 0 !== strpos($edit['ckeditor_plugins_path'], "%")) {
//ensure that slash is at the beginning
$edit['ckeditor_plugins_path'] = "/" . $edit['ckeditor_plugins_path'];
}
//no slash at the end
$edit['ckeditor_plugins_path'] = trim(rtrim($edit['ckeditor_plugins_path'], "/"));
//strip slash from the end
if (empty($edit['ckfinder_path'])) {
$edit['ckfinder_path'] = '';
}
$edit['ckfinder_path'] = trim(rtrim($edit['ckfinder_path'], "/"));
if ($edit['ckfinder_path'] && 0 !== strpos($edit['ckfinder_path'], "/") && 0 !== strpos($edit['ckfinder_path'], "%")) {
//ensure that slash is at the beginning
$edit['ckfinder_path'] = "/" . $edit['ckfinder_path'];
}
//no slash at the end
$edit['ckfinder_local_path'] = trim(rtrim($edit['ckfinder_local_path'], "/"));
$settings = ckeditor_admin_values_to_settings($edit);
db_insert('ckeditor_settings')
->fields(array(
"name" => $edit["name"],
"settings" => $settings
))
->execute();
drupal_set_message(t('The CKEditor global profile was saved.'));
$form_state['redirect'] = 'admin/config/content/ckeditor';
}
/**
* Form builder for a profile
*/
function ckeditor_admin_profile_form($form, $form_state, $task, $profile = NULL) {
global $theme;
if ($profile != NULL) {
$form['_profile'] = array(
'#type' => 'value',
'#value' => $profile,
);
}
else {
$profile = new stdClass();
}
module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
$editor_path = ckeditor_path('relative');
$editor_local_path = ckeditor_path('local');
$editor_url_path = ckeditor_path('url');
$module_drupal_path = ckeditor_module_path('relative');
$module_drupal_url_path = ckeditor_module_path('url');
drupal_add_js(array('ckeditor_version' => ckeditor_get_version()), 'setting');
$lang_options = ckeditor_load_lang_options();
// Attach the administration CSS.
$form['#attached'] = array(
'css' => array(
drupal_get_path('module', 'ckeditor') . '/css/ckeditor.admin.css',
),
);
$form['basic'] = array(
'#type' => 'fieldset',
'#title' => t('Basic setup'),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
switch ($task) {
case 'clone':
//load all profiles to check their names
$profiles = ckeditor_profile_load();
$oldname = $profile->name;
$maxsize = 128; //default max name length
$res = array();
$pat = "/^(.*?)_([0-9]+)$/";
if (preg_match($pat, $oldname, $res)) { // oldname like 'name_nr'
$name = $res[1];
$num = $res[2] + 1;
}
else {
$name = $oldname;
$num = 2;
}
$newname = substr($name, 0, $maxsize - 3) . '_' . $num; // +limit
while (isset($profiles[$newname])) { //find next free number
$num++;
$newname = substr($name, 0, $maxsize - 3) . '_' . $num;
}
break;
case 'edit':
$newname = $profile->name;
break;
}
$global_profile = ckeditor_profile_load('CKEditor Global Profile');
$toolbar_wizard = !empty($global_profile->settings['toolbar_wizard']) ? $global_profile->settings['toolbar_wizard'] : 't';
drupal_add_js(array('ckeditor_toolbar_wizard' => $toolbar_wizard), 'setting');
$form['basic']['name'] = array(
'#type' => 'textfield',
'#title' => t('Profile name'),
'#default_value' => !empty($profile->name) ? $newname : '',
'#size' => 40,
'#maxlength' => 128,
'#description' => t('Enter a name for this profile. This name is only visible within the CKEditor administration page.'),
'#required' => TRUE
);
$orig_formats = filter_formats();
if ($task == 'edit' && !empty($profile->name)) {
$used_formats = db_select('ckeditor_input_format', 'f')->fields('f', array("format"))->distinct()->condition("f.name", array($profile->name), 'NOT IN')->execute()->fetchAllAssoc('format');
}
else {
$profile->input_formats = array();
$used_formats = db_select('ckeditor_input_format', 'f')->fields('f', array("format"))->distinct()->execute()->fetchAllAssoc('format');
}
$formats = array();
$input_format_config_links = array();
foreach ($orig_formats AS $format) {
if (($task == 'edit' && !empty($profile->input_formats) && array_key_exists($format->format, $profile->input_formats)) || !array_key_exists($format->format, $used_formats)) {
$formats[$format->format] = $format->name;
$input_format_config_links[$format->format] = array("name" => $format->name, "config_url" => url("admin/config/content/formats/" . $format->format));
}
}
$form['basic']['input_formats'] = array(
'#id' => 'input-formats',
'#type' => 'checkboxes',
'#title' => t('Text formats'),
'#default_value' => !empty($profile->input_formats) ? array_keys((array) $profile->input_formats) : array(),
'#options' => $formats,
'#description' => t('Choose the text formats where you want to load CKEditor.')
);
$form['security'] = array(
'#type' => 'fieldset',
'#title' => t('Security'),
'#description' => '' . t('The CKEditor security system protects you from executing malicious code that is already in your database. In plain textareas database content is harmless because it is not executed, but the CKEditor WYSIWYG editor interprets HTML like a web browser and thus the content needs to be filtered before it is loaded.') . '
', '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['security']['filters'] = array( '#id' => 'security-filters', '#type' => 'container' ); $form['security']['filters']['__header'] = array( '#type' => 'item', '#title' => t('Security filters'), '#description' => t( 'Below is a list of security filters along with their status for each text format.div
instead of iframe
.")
);
}
$form['appearance']['width'] = array(
'#type' => 'textfield',
'#title' => t('Editor width'),
'#default_value' => !empty($profile->settings['width']) ? $profile->settings['width'] : '100%',
'#description' => t("Editor interface width in pixels or percent. Examples: 400, 100%."),
'#size' => 40,
'#maxlength' => 128,
);
$form['appearance']['lang'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#default_value' => !empty($profile->settings['lang']) ? $profile->settings['lang'] : 'en',
'#options' => $lang_options,
'#description' => t('The language for the CKEditor user interface.')
);
$form['appearance']['auto_lang'] = array(
'#type' => 'radios',
'#title' => t('Auto-detect language'),
'#default_value' => !empty($profile->settings['auto_lang']) ? $profile->settings['auto_lang'] : 't',
'#options' => array(
't' => t('Enabled'),
'f' => t('Disabled')
),
'#description' => t('Automatically detect the user language.')
);
$form['appearance']['language_direction'] = array(
'#type' => 'select',
'#title' => t('Language direction'),
'#default_value' => !empty($profile->settings['language_direction']) ? $profile->settings['language_direction'] : 'default',
'#options' => array(
'default' => t('Get from current locale (default)'),
'ltr' => t('Left-To-Right'), // language like English
'rtl' => t('Right-To-Left') // languages like Arabic
),
'#description' => t(
'Choose the language direction used in the editing area. Even when CKEditor automatically detects the user language and adjusts its user interface, the editing area is not automatically changed into the LTR or RTL mode. To be able to type LTR (like English) and RTL (like Arabic, Hebrew, Persian) content at the same time, please make sure that the !bidiltr and !bidirtl buttons are enabled in the toolbar.', array(
'!bidiltr' => 'BidiLtr',
'!bidirtl' => 'BidiRtl'
)
)
);
$form['acf'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced content filter'),
'#description' => t('Configure input data filtering in CKEditor. See !link for more information about ACF.', array(
'!link' => l(t('this blog post'), 'http://ckeditor.com/blog/Upgrading-to-CKEditor-4.1')
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$form['acf']['allowed_content'] = array(
'#type' => 'radios',
'#title' => t('Advanced content filter'),
'#description' => t('Example: if only Bold and Link buttons are enabled, only !strong and !a tags will be allowed. Any !b tags will automatically be converted into !strong. The !img tag will not be allowed, unless the Image button is added to the toolbar.', array(
'!strong' => '<strong>
',
'!a' => '<a>
',
'!img' => '<img>
',
'!b' => '<b>
'
)).''.
t('Example: !rules', array(
'!rules' => "object[width,height];param[name,value];embed[*];
"
)).'
',
'br' => '
',
'div' => '
',
'br' => '
',
'div' => '
p;div;pre;address;h1;h2;h3;h4;h5;h6
'
)
)
);
if (!empty($profile->settings['formatting']['custom_formatting_options'])) {
foreach ($profile->settings['formatting']['custom_formatting_options'] as $k => $v) {
if ($v === 0) {
unset($profile->settings['formatting']['custom_formatting_options'][$k]);
}
}
}
$form['output']['custom_formatting'] = array(
'#type' => 'radios',
'#title' => t('Use custom formatting options'),
'#default_value' => !empty($profile->settings['custom_formatting']) ? $profile->settings['custom_formatting'] : 'f',
'#options' => array(
't' => t('Yes'),
'f' => t('No'),
),
);
$form['output']['formatting'] = array(
'#type' => 'fieldset',
'#title' => t('Custom formatting options'),
'#tree' => TRUE,
);
$form['output']['formatting']['custom_formatting_options'] = array(
'#type' => 'checkboxes',
'#default_value' => isset($profile->settings['formatting']['custom_formatting_options']) ? array_keys((array) $profile->settings['formatting']['custom_formatting_options']) : array('indent' => 'indent', 'breakBeforeOpen' => 'breakBeforeOpen', 'breakAfterOpen' => 'breakAfterOpen', 'breakAfterClose' => 'breakAfterClose'),
'#options' => array(
'indent' => t('Indent the element contents.'),
'breakBeforeOpen' => t('Break line before the opening tag.'),
'breakAfterOpen' => t('Break line after the opening tag.'),
'breakBeforeClose' => t('Break line before the closing tag.'),
'breakAfterClose' => t('Break line after the closing tag.'),
'pre_indent' => t('Indent the <pre>
element contents.'),
),
);
$form['css'] = array(
'#type' => 'fieldset',
'#title' => t('CSS'),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$current_theme = variable_get('theme_default', $theme);
$theme_path = drupal_get_path('theme', $current_theme);
$form['css']['css_mode'] = array(
'#type' => 'select',
'#title' => t('Editor CSS'),
'#default_value' => !empty($profile->settings['css_mode']) ? $profile->settings['css_mode'] : 'theme',
'#options' => array(
'theme' => t('Use theme CSS'),
'self' => t('Define CSS'),
'none' => t('CKEditor default')
),
'#description' => t(
'Defines the CSS to be used in the editor area.!title_theme_css – load the !style_css file from the current site theme.!title_define_css – enter the CSS file path below.!title_ckeditor_default – use the default editor CSS.', array(
'!title_theme_css' => 'style.css
'
)
)
);
$form['css']['css_path'] = array(
'#type' => 'textfield',
'#title' => t('CSS file path'),
'#default_value' => !empty($profile->settings['css_path']) ? $profile->settings['css_path'] : "",
'#size' => 40,
'#maxlength' => 255,
'#description' => t(
'Enter the path to the CSS file (Example: !example1) or a list of CSS files separated with a comma (Example: !example2). Make sure you select the !title_define_css option above.', array(
'!example1' => '"css/editor.css"
',
'!example2' => '"/themes/garland/style.css,http://example.com/style.css"
',
'!title_define_css' => '' . t('Define CSS') . ''
)
) .
'%h
',
'!t' => '%t
',
'!host' => '' . base_path() . '
',
'!theme' => '' . base_path() . $theme_path . '/
'
)
)
);
$form['css']['css_style'] = array(
'#type' => 'select',
'#title' => t('Predefined styles'),
'#default_value' => !empty($profile->settings['css_style']) ? $profile->settings['css_style'] : 'theme',
'#options' => array(
'theme' => t('Use theme ckeditor.styles.js'),
'self' => t('Define path to ckeditor.styles.js'),
'default' => t('CKEditor default')
),
'#description' => t(
'Define the location of the !ckeditor_styles_js_file file. It is used by the Style drop-down list available in the default toolbar. Copy the !ckeditor_styles_js_path file into your theme directory (!theme) and adjust it to your needs.', array(
'!ckeditor_styles_js_file' => 'ckeditor.styles.js
',
'!ckeditor_styles_js_path' => '' . drupal_get_path('module', 'ckeditor') . '/ckeditor.styles.js
',
'!theme' => '' . $theme_path . '/ckeditor.styles.js' . '
'
)
)
);
$form['css']['styles_path'] = array(
'#type' => 'textfield',
'#title' => t('Predefined styles path'),
'#default_value' => !empty($profile->settings['styles_path']) ? $profile->settings['styles_path'] : "",
'#size' => 40,
'#maxlength' => 255,
'#description' => t(
'Enter the path to a file with predefined styles (Example: !example1). Make sure you select the !style_define_path option above.', array(
'!style_define_path' => '' . t('Define path to ckeditor.styles.js') . '',
'!ckeditor_styles_js_file' => 'ckeditor.styles.js
',
'!example1' => '/ckeditor.styles.js
'
)
) .
'%h
',
'!t' => '%t
',
'!m' => '%m
',
'!host' => '' . base_path() . '
',
'!theme' => '' . base_path() . $theme_path . '/
',
'!module' => '' . drupal_get_path('module', 'ckeditor') . '
'
)
)
);
$form['ckeditor_upload_settings'] = array(
'#type' => 'fieldset',
'#title' => t('File browser settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t(
'Set the file browser settings. A file browser will allow you to browse the files stored on the server and embed them as links, images, or Flash movies. CKEditor is compatible with such Drupal modules as !imce or !elfinder. CKEditor can be also integrated with !ckfinder, an advanced Ajax file manager.', array(
'!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'),
'!elfinder' => l(t('elFinder'), 'http://drupal.org/project/elfinder'),
'!ckfinder' => l(t('CKFinder'), 'http://cksource.com/ckfinder')
)
)
);
$filebrowsers = array(
'none' => t('None'),
'ckfinder' => t('CKFinder'),
);
$filebrowsers_dialogs = array(
'' => t('Same as in the Link dialog window'),
'ckfinder' => t('CKFinder'),
);
if (module_exists('imce')) {
$filebrowsers['imce'] = t('IMCE');
$filebrowsers_dialogs['imce'] = t('IMCE');
}
if (module_exists('elfinder')) {
$filebrowsers['elfinder'] = t('elFinder');
$filebrowsers_dialogs['elfinder'] = t('elFinder');
}
/* MODULES NOT PORTED TO D7
if (module_exists('tinybrowser')) {
$filebrowsers['tinybrowser'] = t('TinyBrowser');
$filebrowsers_dialogs['tinybrowser'] = t('TinyBrowser');
}
if (module_exists('imagebrowser')) {
$filebrowsers['ib'] = t('Image Browser');
$filebrowsers_dialogs['ib'] = t('Image Browser');
}
if (module_exists('webfm_popup')) {
$filebrowsers['webfm'] = t('Web File Manager');
$filebrowsers_dialogs['webfm'] = t('Web File Manager');
}
*/
$form['ckeditor_upload_settings']['filebrowser'] = array(
'#type' => 'select',
'#title' => t('File browser type (Link dialog window)'),
'#default_value' => !empty($profile->settings['filebrowser']) ? $profile->settings['filebrowser'] : 'none',
'#options' => $filebrowsers,
'#description' => t('Select the file browser that you would like to use to upload files.'),
);
$form['ckeditor_upload_settings']['filebrowser_image'] = array(
'#type' => 'select',
'#title' => t('File browser type (Image dialog window)'),
'#default_value' => !empty($profile->settings['filebrowser_image']) ? $profile->settings['filebrowser_image'] : 'none',
'#options' => $filebrowsers_dialogs,
'#description' => t('Select the file browser that you would like to use to upload images.'),
);
$form['ckeditor_upload_settings']['filebrowser_flash'] = array(
'#type' => 'select',
'#title' => t('File browser type (Flash dialog window)'),
'#default_value' => !empty($profile->settings['filebrowser_flash']) ? $profile->settings['filebrowser_flash'] : 'none',
'#options' => $filebrowsers_dialogs,
'#description' => t('Select the file browser that you would like to use to upload Flash movies.'),
);
if (variable_get('file_default_scheme', '') != 'private') {
$current_user_files_path = empty($profile->settings['UserFilesPath']) ? "%b%f/" : $profile->settings['UserFilesPath'];
$current_user_files_path = strtr($current_user_files_path, array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => "UID", "%b" => base_path(), "%n" => "UNAME"));
$current_user_files_absolute_path = empty($profile->settings['UserFilesAbsolutePath']) ? "%d%b%f/" : $profile->settings['UserFilesAbsolutePath'];
$current_user_files_absolute_path = strtr($current_user_files_absolute_path, array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => "UID", "%b" => base_path(), "%d" => ckeditor_get_document_root_full_path(), "%n" => "UNAME"));
$form['ckeditor_upload_settings']['UserFilesPath'] = array(
'#type' => 'textfield',
'#prefix' => '',
'#description' => t('The path to the local directory (on the server) which points to the path defined above. If left empty, CKEditor will try to discover the right path.') .
'%u
',
'!n' => '%n
',
'!d' => '%d
',
'!b' => '%b
',
'!f' => '%f
',
'!files' => '' . variable_get('file_public_path', conf_path() . '/files') . '
',
'!base' => '' . base_path() . '
',
'!root' => '' . ckeditor_get_document_root_full_path() . '
'
)
) .
'' . $current_user_files_absolute_path . '
'
)
)
);
}
if (variable_get('file_default_scheme', '') == 'private') {
$form['ckeditor_upload_settings']['private_path_descrption'] = array(
'#markup' => 'ckeditor_basic.js
'
)
)
);
$form['advanced']['ckeditor_load_time_out'] = array(
'#type' => 'textfield',
'#title' => t('Loading timeout'),
'#default_value' => !empty($profile->settings['ckeditor_load_time_out']) ? $profile->settings['ckeditor_load_time_out'] : "0",
'#size' => 40,
'#maxlength' => 255,
'#description' => t('The time to wait (in seconds) to load the full editor code after the page is loaded, if the !ckeditor_basic_js file is used. If set to zero, the editor is loaded on demand.', array(
'!ckeditor_basic_js' => 'ckeditor_basic.js
'
)
)
);
}
$form['advanced']['forcePasteAsPlainText'] = array(
'#type' => 'select',
'#title' => t('Force pasting as plain text'),
'#default_value' => !empty($profile->settings['forcePasteAsPlainText']) ? $profile->settings['forcePasteAsPlainText'] : "f",
'#options' => array(
't' => t('Enabled'),
'f' => t('Disabled')
),
'#description' => t('If enabled, HTML content will be automatically changed to plain text when pasting.'),
);
$form['advanced']['html_entities'] = array(
'#type' => 'radios',
'#title' => t('HTML Entities'),
'#default_value' => !empty($profile->settings['html_entities']) ? $profile->settings['html_entities'] : 'f',
'#description' => t('Convert all applicable characters to HTML entities.'),
'#options' => array(
'f' => t('No'),
't' => t('Yes')
),
);
$form['advanced']['scayt_autoStartup'] = array(
'#type' => 'radios',
'#title' => t('Spellchecker'),
'#default_value' => !empty($profile->settings['scayt_autoStartup']) ? $profile->settings['scayt_autoStartup'] : 'f',
'#description' => t('If enabled, turns on SCAYT (Spell Check As You Type) automatically after loading the editor.'),
'#options' => array(
'f' => t('No'),
't' => t('Yes')
),
);
$form['advanced']['theme_config_js'] = array(
'#type' => 'radios',
'#title' => t('Load !ckeditor_config_js from the theme path', array(
'!ckeditor_config_js' => 'ckeditor.config.js
'
)
),
'#default_value' => !empty($profile->settings['theme_config_js']) ? $profile->settings['theme_config_js'] : 'f',
'#options' => array(
't' => t('Yes'),
'f' => t('No')
),
'#description' => t('When enabled, the editor will try to load the !ckeditor_config_js file from the theme directory.', array(
'!ckeditor_config_js' => 'ckeditor.config.js
'
)
)
);
$form['advanced']['js_conf'] = array(
'#type' => 'textarea',
'#title' => t('Custom JavaScript configuration'),
'#default_value' => !empty($profile->settings['js_conf']) ? $profile->settings['js_conf'] : "",
'#cols' => 60,
'#rows' => 5,
'#description' => t(
'In order to change CKEditor configuration globally, you should modify the !ckeditor_config configuration file. Sometimes it is required to change the CKEditor configuration for a single profile only. Use this box to define settings that are unique for this profile. Available options are listed in the !docs. Add the following code snippet to change the fonts available in the CKEditor Font and Size drop-down lists: @codeWarning: If you make a mistake here, CKEditor may not load correctly.', array( '!ckeditor_config' => '
' . drupal_get_path('module', 'ckeditor') . "/ckeditor.config.js
",
'!docs' => l(t('CKEditor documentation'), 'http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html'),
'@code' => "config.font_names = 'Arial;Times New Roman;Verdana';\nconfig.fontSize_sizes = '16/16px;24/24px;48/48px;';"
)
),
'#wysiwyg' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save')
);
return $form;
}
/**
* Form validation for a profile.
*/
function ckeditor_admin_profile_form_validate($form, &$form_state) {
$edit = & $form_state['values'];
/*
if ($edit['default'] == 't' && $edit['popup'] == 't') {
form_set_error('popup', t('If CKEditor is enabled by default, the popup window must be disabled.'));
}
if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
form_set_error('popup', t('If toggle is enabled, the popup window must be disabled.'));
}
*/
if (!$edit['name']) {
form_set_error('name', t('You must give a profile name.'));
}
elseif (!preg_match('/^[A-Za-z0-9_]+$/', $edit['name'])) {
form_set_error('name', t('Enter a valid profile name. Only alphanumeric and underscore characters are allowed.'));
}
elseif ($edit['name'] == 'CKEditor Global Profile') {
form_set_error('name', t('This profile name is reserved. Please choose a different name.'));
}
elseif (!isset($edit['_profile']) || ($edit['_profile']->name != $edit['name'])) {
$result = ckeditor_profile_load($edit['name']);
if (!empty($result)) {
form_set_error('name', t('The profile name must be unique. A profile with this name already exists.'));
}
}
if (!preg_match('/^\d+%?$/', $edit['width'])) {
form_set_error('width', t('Enter a valid width value. Examples: 400, 100%.'));
}
if (!empty($edit['css_path'])) {
if ($edit['css_mode'] != 'self') {
form_set_error('css_path', t('The CSS path is not empty. Please set the Editor CSS option to the Define CSS mode.'));
}
elseif (FALSE !== strpos($edit['css_path'], '"')) {
form_set_error('css_path', t('Double quotes are not allowed in the CSS path.'));
}
elseif (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") {
form_set_error('css_path', t('Enter a valid CSS path, do not surround it with quotes.'));
}
}
if (!empty($edit['styles_path'])) {
if ($edit['css_style'] != 'self') {
form_set_error('styles_path', t('The path to predefined styles is not empty. Please set the Predefined styles option to the Define path to ckeditor.styles.js mode.'));
}
elseif (FALSE !== strpos($edit['styles_path'], '"')) {
form_set_error('styles_path', t('Double quotes are not allowed in the styles path.'));
}
elseif (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
form_set_error('styles_path', t('Enter a valid styles path, do not surround it with quotes.'));
}
}
if (!empty($edit['font_format'])) {
if (!preg_match("/^((p|div|pre|address|h1|h2|h3|h4|h5|h6);)*(p|div|pre|address|h1|h2|h3|h4|h5|h6)$/", $edit['font_format'])) {
form_set_error('font_format', t('Enter a valid, semicolon-separated list of HTML font formats (no semicolon at the end of the list is expected).'));
}
}
// @todo DOWNLOAD API
if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) {
form_set_error('UserFilesPath', t('The path to uploaded files is required.'));
}
if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) {
form_set_error('UserFilesPath', t('An absolute path to uploaded files is required.'));
}
if (ckeditor_get_version(TRUE) == 3) {
$load_methods = _ckeditor_load_methods();
if (!isset($load_methods[$edit['ckeditor_load_method']])) {
form_set_error('ckeditor_load_method', t('Set a valid loading method.'));
}
if (!preg_match('#\d+#', $edit['ckeditor_load_time_out'])) {
form_set_error('ckeditor_load_time_out', t('Enter a valid loading timeout in seconds.'));
}
}
$toolbar = $edit['toolbar'];
$toolbar = str_replace("'", '"', $toolbar);
$toolbar = preg_replace('/(\w*)\s*\:/', '"${1}":', $toolbar);
if (strpos($toolbar, 'CodeSnippet') !== false && empty($edit['loadPlugins']['codesnippet'])) {
form_set_error('loadPlugins][codesnippet', t('The Code Snippet plugin must be enabled if the CodeSnippet button is enabled in the toolbar.'));
}
if (strpos($toolbar, 'Mathjax') !== false && empty($edit['loadPlugins']['mathjax'])) {
form_set_error('loadPlugins][mathjax', t('The Mathjax plugin must be enabled if the Mathjax button is enabled in the toolbar.'));
}
if (!json_decode($toolbar)) {
form_set_error('toolbar', t('Enter a valid toolbar configuration.'));
}
}
/**
* Form submit for a profile
*/
function ckeditor_admin_profile_form_submit($form, &$form_state) {
$edit = & $form_state['values'];
if (isset($edit['_profile'])) {
ckeditor_profile_delete($edit['_profile']->name);
drupal_set_message(t('Your CKEditor profile was updated.'));
}
else {
drupal_set_message(t('Your CKEditor profile was created.'));
}
$settings = ckeditor_admin_values_to_settings($edit);
db_insert('ckeditor_settings')
->fields(array(
"name" => $edit['name'],
"settings" => $settings
))
->execute();
if (!empty($edit['input_formats'])) {
foreach (array_keys($edit['input_formats']) as $format) {
if ($edit['input_formats'][$format] != '0') {
db_insert('ckeditor_input_format')->fields(array("name" => $edit['name'], "format" => $format))->execute();
}
}
}
$form_state['redirect'] = 'admin/config/content/ckeditor';
}
/**
* Form builder for a clone profile
*/
function ckeditor_admin_profile_clone_form($form, $form_state, $task, $oldprofile) {
return ckeditor_admin_profile_form($form, $form_state, $task, $oldprofile);
}
/**
* Form validation for a clone profile
*/
function ckeditor_admin_profile_clone_form_validate($form_state, $oldprofile) {
ckeditor_admin_profile_form_validate($form_state, $oldprofile);
}
/**
* Form submit for a clone profile
*/
function ckeditor_admin_profile_clone_form_submit($form, &$form_state) {
$edit = & $form_state['values'];
drupal_set_message(t('Your CKEditor profile was created.'));
$settings = ckeditor_admin_values_to_settings($edit);
db_insert('ckeditor_settings')
->fields(array(
"name" => $edit['name'],
"settings" => $settings
))
->execute();
if (!empty($edit['input_formats'])) {
foreach (array_keys($edit['input_formats']) as $format) {
if ($edit['input_formats'][$format] != 0) {
db_insert('ckeditor_input_format')->fields(array("name" => $edit['name'], "format" => $format))->execute();
}
}
}
$form_state['redirect'] = 'admin/config/content/ckeditor';
}
/**
* Form builder for a profile delete
*/
function ckeditor_admin_profile_delete_form($form, $form_state, $profile) {
$form = array();
$form['_profile'] = array(
'#type' => 'value',
'#value' => $profile,
);
$form['question'] = array(
'#type' => 'item',
'#markup' => t(
'Are you sure that you want to delete the CKEditor profile %profile?', array(
'%profile' => $profile->name
)
),
);
$form['delete'] = array(
'#type' => 'submit',
'#id' => 'delete',
'#value' => t('Delete'),
);
$form['back'] = array(
'#type' => 'submit',
'#id' => 'back',
'#value' => t('Cancel'),
);
return $form;
}
/**
* Submit form for a profile delete
*/
function ckeditor_admin_profile_delete_form_submit($form, &$form_state) {
$v = & $form_state['values'];
if ($form_state['clicked_button']['#id'] == 'delete') {
ckeditor_profile_delete($v['_profile']->name);
drupal_set_message(t('The CKEditor profile was deleted.'));
}
$form_state['redirect'] = 'admin/config/content/ckeditor';
}
/**
* Converts an array of form values to a serialized array that does not
* contain Drupal Form API values
*/
function ckeditor_admin_values_to_settings($values) {
$plugins = array();
if (isset($values['loadPlugins'])) {
$plugins = $values['loadPlugins'];
}
unset($values['name'], $values['input_formats'], $values['_profile'], $values['op'], $values['submit'], $values['form_build_id'], $values['form_token'], $values['form_id'], $values['loadPlugins']);
// Replace CRLF with LF in toolbar settings
if(isset($values['toolbar'])){
$values['toolbar'] = str_replace("\r\n", "\n", $values['toolbar']);
}
module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
$plugin_list = ckeditor_load_plugins();
$values['loadPlugins'] = array();
if (!empty($plugins)) {
foreach (array_keys($plugins) as $plugin) {
if ($plugins[$plugin] != '0') {
$values['loadPlugins'][$plugin] = $plugin_list[$plugin];
}
}
}
return serialize($values);
}
/**
* Remove a profile from the database.
*/
function ckeditor_profile_delete($name) {
db_delete('ckeditor_settings')
->condition('name', $name)
->execute();
db_delete('ckeditor_input_format')
->condition('name', $name)
->execute();
}
/*
* List of CKEditor librares to load
*/
function _ckeditor_load_methods() {
$result = array('ckeditor.js' => 'ckeditor.js');
$ckeditor_local_path = ckeditor_path('local');
if ($ckeditor_local_path == '