From 673ead9a0ee083d4df2bcaeef68e40e0a237e604 Mon Sep 17 00:00:00 2001
From: michal <michal_cksource@922884.no-reply.drupal.org>
Date: Fri, 23 Sep 2011 09:36:08 +0200
Subject: [PATCH] [#1288084] Drupal Media Module selection Prevents Edit forms from loading when module is not installed

---
 includes/ckeditor.lib.inc |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/includes/ckeditor.lib.inc b/includes/ckeditor.lib.inc
index da2d0da..347e756 100644
--- a/includes/ckeditor.lib.inc
+++ b/includes/ckeditor.lib.inc
@@ -332,7 +332,7 @@ function ckeditor_load_plugins($render = FALSE) {
             'default' => 't'
         );
     }
-    
+
     if (module_exists('ckeditor_link') && file_exists(drupal_get_path('module', 'ckeditor_link') . '/plugins/link/plugin.js')) {
         $arr['ckeditor_link'] = array(
             'name' => 'drupal_path',
@@ -408,7 +408,7 @@ function ckeditor_load_plugins($render = FALSE) {
                             }
                         }
                     }
-                }              
+                }
                 if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
                     $arr[$file] = array(
                         'name' => $file,
@@ -482,7 +482,7 @@ function ckeditor_load_plugins($render = FALSE) {
 
         closedir($handle);
     }
-    
+
     /*
      * CKEditor plugins registered by hook
      */
@@ -521,12 +521,17 @@ function ckeditor_load_plugins($render = FALSE) {
     }
     $arr = array_merge($arr, $plugins);
 
+    if (isset($arr['media']))
+    {
+      if (module_exists('media') == FALSE)
+      {
+        unset($arr['media']);
+      }
+    }
     ksort($arr);
-    
     if ($render === TRUE) {
         $arr = ckeditor_plugins_render($arr);
     }
-    
     return $arr;
 }
 
@@ -544,7 +549,6 @@ function ckeditor_plugins_render($plugins) {
     foreach ((array) $plugins as $i => $plugin) {
         $plugins[$i]['path'] = str_replace(array_keys($render), array_values($render), $plugin['path']);
     }
-    
     return $plugins;
 }
 
@@ -600,7 +604,7 @@ function ckeditor_get_profile($input_format) {
     $select = db_select('ckeditor_settings', 's');
     $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
     $result = $select->fields('s', array("name"))->condition('f.format', $input_format)->condition('f.name', 'CKEditor Global Profile', '<>')->range(0, 1)->execute()->fetchAssoc();
-    
+
     if ($result && $profile = ckeditor_profile_load($result['name'])) {
         return $profile;
     }
@@ -724,8 +728,8 @@ function ckeditor_profiles_compile( $input_format = FALSE, $clear = FALSE ) {
 function ckeditor_profile_settings_compile( $global_profile, $profile ) {
     global $user, $language, $theme;
 
-    $current_theme = variable_get('theme_default', $theme); 
-    
+    $current_theme = variable_get('theme_default', $theme);
+
     $settings = array();
     $conf = array();
     $conf = $profile->settings;
@@ -779,7 +783,7 @@ function ckeditor_profile_settings_compile( $global_profile, $profile ) {
     $settings['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode']));
     $settings['toolbarStartupExpanded'] = ( $conf['expand'] == 't' );
     $settings['width'] = $conf['width'];
-    $settings['skin'] = $conf['skin']; 
+    $settings['skin'] = $conf['skin'];
     $settings['format_tags'] = $conf['font_format'];
     //$settings['popup'] = $conf['popup'];
     $settings['show_toggle'] = $conf['show_toggle'];
@@ -799,11 +803,11 @@ function ckeditor_profile_settings_compile( $global_profile, $profile ) {
                 break;
         }
     }
-    
+
     if (isset($conf['loadPlugins'])) {
         $settings['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']);
-        
-        if (array_key_exists('media', $settings['loadPlugins'])) {
+
+        if (array_key_exists('media', $settings['loadPlugins']) && module_exists('media')) {
             module_load_include('inc', 'media', 'includes/media.browser');
             $javascript = media_browser_js();
             foreach ($javascript as $key => $definitions) {
@@ -848,7 +852,7 @@ function ckeditor_profile_settings_compile( $global_profile, $profile ) {
     else {
         $settings['textformat_filters'] = FALSE;
     }
-    
+
     if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') {
         foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) {
             if ($v === 0) {
@@ -1262,7 +1266,7 @@ function ckeditor_load_by_field( $field, $format, $show_toggle = TRUE, $add_fiel
     static $is_running = FALSE;
     $enabled = TRUE;
     $suffix = '';
-    
+
     if (!isset($field['#id'])) {
         return $field;
     }
@@ -1286,7 +1290,7 @@ function ckeditor_load_by_field( $field, $format, $show_toggle = TRUE, $add_fiel
     if (isset($field['#attributes']['disabled']) && $field['#attributes']['disabled'] == 'disabled') {
         return $field;
     }
-    
+
     if (!isset($processed_ids[$field['#id']])) {
         $processed_ids[$field['#id']] = array();
     }
@@ -1354,7 +1358,7 @@ function ckeditor_load_by_field( $field, $format, $show_toggle = TRUE, $add_fiel
         $editor_local_path = ckeditor_path(TRUE);
         // get the default drupal files path
         $files_path = $host . variable_get('file_private_path', conf_path() . '/files');
-        
+
         if (!$is_running) {
             drupal_add_js($module_drupal_path . '/includes/ckeditor.utils.js', array('type' => 'file', 'scope' => 'footer') );
             //if ($settings['popup'] != 't') {
-- 
1.7.4.msysgit.0

