From fcf35ebfbf88fd338b94b9dc8762240070603eec Mon Sep 17 00:00:00 2001 From: Damian Czepierga Date: Wed, 21 Mar 2012 14:29:31 +0100 Subject: [PATCH] by dczepierga: CKeditor is not working in Views header and footer text areas --- ckeditor.module | 62 +++++++++++++++++--------------------------- includes/ckeditor.utils.js | 12 +++++--- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/ckeditor.module b/ckeditor.module index 925cf30..3e720b9 100644 --- a/ckeditor.module +++ b/ckeditor.module @@ -360,15 +360,16 @@ function ckeditor_menu() { * Implementation of hook_init(). */ function ckeditor_init() { + global $user; drupal_add_css(drupal_get_path('module', 'ckeditor') .'/ckeditor.css'); - // Added for support [#1288664] Views if (module_exists('views') && preg_match('/admin\/build\/views/', $_GET['q'])) { $module_drupal_path = drupal_get_path('module', 'ckeditor'); $editor_local_path = ckeditor_path(TRUE); drupal_add_js($editor_local_path . '/ckeditor.js', 'module', 'footer', FALSE, TRUE, FALSE); drupal_add_js($module_drupal_path .'/includes/ckeditor.utils.js', 'module', 'footer' ); - drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'), 'settings' => array('edit-footer', 'edit-header'))), 'setting'); + $themes = list_themes(); + drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'), 'theme' => !empty($user->theme) && !empty($themes[$user->theme]->status) ? $user->theme : variable_get('theme_default', 'garland'), 'settings' => array('edit-footer', 'edit-header'))), 'setting'); } } @@ -441,7 +442,7 @@ function ckeditor_profile_load($name = '', $clear = FALSE) { * @return * The same $element with extra CKEditor markup and initialization. */ -function ckeditor_process_textarea($element) { +function ckeditor_process_textarea($element, $url = NULL) { static $is_running = FALSE; static $num = 1; static $processed_ids=array(); @@ -450,6 +451,10 @@ function ckeditor_process_textarea($element) { $enabled = TRUE; $suffix = ""; $class = ""; + //if query not set read it + if (is_null($url)) { + $url = $_GET['q']; + } //hack for module developers that want to disable ckeditor on their textareas if (key_exists('#wysiwyg', $element) && !$element['#wysiwyg']) { return $element; @@ -495,11 +500,11 @@ function ckeditor_process_textarea($element) { if ($global_profile) { $global_conf = $global_profile->settings; if ($global_conf) { - $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $element['#id'], $_GET['q']); + $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $element['#id'], $url); } } if ($enabled) { - $profile = ckeditor_user_get_profile($user, $element['#id']); + $profile = ckeditor_user_get_profile($user, $element['#id'], $url); if ($profile) { $conf = array(); $conf = $profile->settings; @@ -611,16 +616,16 @@ function ckeditor_process_textarea($element) { } drupal_add_js(array('ckeditor' => array('module_path' => $module_full_path, 'editor_path' => $editor_path)), 'setting'); drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'))), 'setting'); - drupal_add_js(array('ckeditor' => array('query' => $_GET['q'])), 'setting'); + drupal_add_js(array('ckeditor' => array('query' => $url)), 'setting'); $is_running = TRUE; } $toolbar = $conf['toolbar']; //$height += 100; // for larger toolbars - $force_simple_toolbar = ckeditor_is_enabled('1', empty($conf['simple_incl_regex']) ? '' : $conf['simple_incl_regex'], $element['#id'], $_GET['q']); + $force_simple_toolbar = ckeditor_is_enabled('1', empty($conf['simple_incl_regex']) ? '' : $conf['simple_incl_regex'], $element['#id'], $url); if (!$force_simple_toolbar) { - $force_simple_toolbar = ckeditor_is_enabled('1', empty($global_conf['simple_incl_regex']) ? '' : $global_conf['simple_incl_regex'], $element['#id'], $_GET['q']); + $force_simple_toolbar = ckeditor_is_enabled('1', empty($global_conf['simple_incl_regex']) ? '' : $global_conf['simple_incl_regex'], $element['#id'], $url); } if ($force_simple_toolbar) { $toolbar = "[ [ 'Format', 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ] ]"; @@ -1084,7 +1089,7 @@ function ckeditor_process_textarea($element) { // display the field id for administrators if (user_access('administer ckeditor') && (!isset($global_conf['show_fieldnamehint']) || $global_conf['show_fieldnamehint'] == 't')) { module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin'); - $suffix .= '
'. t('CKEditor: the ID for excluding or including this element is %fieldname.', array('!excluding' => url('admin/settings/ckeditor'), '%fieldname' => ckeditor_rule_to_string(ckeditor_rule_create(ckeditor_get_nodetype($_GET['q']), $_GET['q'], $element['#id'])))) .'
'; + $suffix .= '
'. t('CKEditor: the ID for excluding or including this element is %fieldname.', array('!excluding' => url('admin/settings/ckeditor'), '%fieldname' => ckeditor_rule_to_string(ckeditor_rule_create(ckeditor_get_nodetype($url), $url, $element['#id'])))) .'
'; } // Remember extra information and reuse it during "Preview" @@ -1364,39 +1369,20 @@ function _ckeditor_scayt_langcode($lang) { * Added for support [#1288664] Views */ function ckeditor_get_settings() { - global $user; + global $user, $theme; module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); - if (empty($_POST['id']) || !isset($_POST['token']) || !drupal_valid_token($_POST['token'], 'ckeditorAjaxCall')) { - echo json_encode(array()); - die(); + if (empty($_POST['id']) || !isset($_POST['url']) || !is_string($_POST['url']) || !isset($_POST['theme']) || !is_string($_POST['theme']) || !isset($_POST['token']) || !drupal_valid_token($_POST['token'], 'ckeditorAjaxCall')) { + echo json_encode(array()); + die(); } + $theme = $_POST['theme']; unset($_SESSION['cke_get_settings']); - $enabled = FALSE; - - $global_profile = ckeditor_profile_load('CKEditor Global Profile'); - if ($global_profile) { - $global_conf = $global_profile->settings; - if ($global_conf) { - $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $_POST['id'], $_POST['url']); - } + ckeditor_process_textarea(array('#id' => $_POST['id']), $_POST['url']); + if (empty($_SESSION['cke_get_settings'][$_POST['id']])) { + echo json_encode(array()); } - if ($enabled) { - $profile = ckeditor_user_get_profile($user, $_POST['#id']); - if ($profile) { - $conf = array(); - $conf = $profile->settings; - $enabled = ckeditor_is_enabled(empty($conf['excl_mode']) ? '0' : $conf['excl_mode'], empty($conf['excl_regex']) ? '' : $conf['excl_regex'], $_POST['id'], $_POST['url']); - } - else { - $enabled = FALSE; - } - } - - if (!$enabled) { - echo json_encode(array()); die(); + else { + echo json_encode($_SESSION['cke_get_settings'][$_POST['id']]); } - $element = ckeditor_process_textarea(array('#id' => $_POST['id'])); - if (empty($_SESSION['cke_get_settings'][$_POST['id']])) echo json_encode(array()); - echo json_encode($_SESSION['cke_get_settings'][$_POST['id']]); die(); } \ No newline at end of file diff --git a/includes/ckeditor.utils.js b/includes/ckeditor.utils.js index 6c93a8e..6071547 100644 --- a/includes/ckeditor.utils.js +++ b/includes/ckeditor.utils.js @@ -396,14 +396,16 @@ Drupal.behaviors.ckeditor = function (context) { }); if ($('.form-item textarea', $(context)).length == 1) { var url = document.location.pathname; - if (url.indexOf('/') == 0 ) url = url.substr(1); var path = Drupal.settings.basePath; + if (url.indexOf(path) == 0) { + url = url.substr(path.length); + } var imagefield_id = $('textarea', $(context)).attr('id'); if (!CKEDITOR.instances[imagefield_id]){ $.ajax({ url: path + 'admin/ckeditor/get_settings', dataType: 'json', - data: {'id': imagefield_id, 'url': url, 'token': Drupal.settings.ckeditor.ajaxToken}, + data: {'id': imagefield_id, 'url': url, 'token': Drupal.settings.ckeditor.ajaxToken, 'theme': Drupal.settings.ckeditor.theme}, type: 'POST', success: function( data ) { Drupal.settings.ckeditor.settings[imagefield_id] = data; @@ -436,13 +438,13 @@ Drupal.behaviors.ckeditor = function (context) { if (typeof views_textarea_id != 'undefined' && views_textarea_id != 'edit-options-alter-text'){ path = Drupal.settings.basePath; views_path = $("form", $(context)).attr('action'); - if (views_path.indexOf('/') == 0) { - views_path = views_path.substr(1) + if (views_path.indexOf(path) == 0) { + views_path = views_path.substr(path.length); } $.ajax({ url: path + 'admin/ckeditor/get_settings', dataType: 'json', - data: {'id': views_textarea_id, 'url': views_path, 'token': Drupal.settings.ckeditor.ajaxToken}, + data: {'id': views_textarea_id, 'url': views_path, 'token': Drupal.settings.ckeditor.ajaxToken, 'theme': Drupal.settings.ckeditor.theme}, type: 'POST', success: function( data ) { if ($(data).length > 0 && typeof CKEDITOR.instances[views_textarea_id] == 'undefined'){ -- 1.7.9.msysgit.0