Index: wysiwyg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.module,v
retrieving revision 1.28
diff -u -p -r1.28 wysiwyg.module
--- wysiwyg.module	17 May 2009 02:41:39 -0000	1.28
+++ wysiwyg.module	17 May 2009 21:19:50 -0000
@@ -288,13 +288,14 @@ function wysiwyg_load_editor($profile) {
       'enable' => t('Enable rich-text'),
     )), 'setting');
 
+    $path = drupal_get_path('module', 'wysiwyg');
     // Initialize our namespaces in the *header* to do not force editor
     // integration scripts to check and define Drupal.wysiwyg on its own.
-    drupal_add_js(wysiwyg_get_path('wysiwyg.init.js'), 'core');
+    drupal_add_js($path . '/wysiwyg.init.js', 'core');
 
     // The 'none' editor is a special editor implementation, allowing us to
     // attach and detach regular Drupal behaviors just like any other editor.
-    drupal_add_js(wysiwyg_get_path('editors/js/none.js'));
+    drupal_add_js($path . '/editors/js/none.js');
 
     // Add wysiwyg.js to the footer to ensure it's executed after the
     // Drupal.settings array has been rendered and populated. Also, since editor
@@ -302,7 +303,7 @@ function wysiwyg_load_editor($profile) {
     // and Drupal.wysiwygInit() must be executed AFTER editors registered
     // their callbacks and BEFORE Drupal.behaviors are applied, this must come
     // last.
-    drupal_add_js(wysiwyg_get_path('wysiwyg.js'), 'module', 'footer');
+    drupal_add_js($path . '/wysiwyg.js', 'module', 'footer');
 
     $settings_added = TRUE;
   }
@@ -631,8 +632,8 @@ function wysiwyg_get_all_editors() {
       'title' => '',
       'vendor url' => '',
       'download url' => '',
-      'editor path' => wysiwyg_get_path($properties['name']),
-      'library path' => wysiwyg_get_path($properties['name']),
+      'editor path' => wysiwyg_get_path($editors[$editor]['name']),
+      'library path' => wysiwyg_get_path($editors[$editor]['name']),
       'libraries' => array(),
       'version callback' => NULL,
       'themes callback' => NULL,
@@ -640,16 +641,16 @@ function wysiwyg_get_all_editors() {
       'plugin callback' => NULL,
       'plugin settings callback' => NULL,
       'versions' => array(),
-      'js path' => $properties['path'] .'/js',
-      'css path' => $properties['path'] .'/css',
+      'js path' => $editors[$editor]['path'] . '/js',
+      'css path' => $editors[$editor]['path'] . '/css',
     );
     // Check whether library is present.
-    if (!($editors[$editor]['installed'] = file_exists($properties['library path']))) {
+    if (!($editors[$editor]['installed'] = file_exists($editors[$editor]['library path']))) {
       continue;
     }
     // Detect library version.
     if (function_exists($editors[$editor]['version callback'])) {
-      $editors[$editor]['installed version'] = $editors[$editor]['version callback']($properties);
+      $editors[$editor]['installed version'] = $editors[$editor]['version callback']($editors[$editor]);
     }
     if (empty($editors[$editor]['installed version'])) {
       $editors[$editor]['error'] = t('The version of %editor could not be detected.', array('%editor' => $properties['title']));
@@ -665,7 +666,7 @@ function wysiwyg_get_all_editors() {
       }
     }
     if (!$version) {
-      $editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array('%version' => $editors[$editor]['installed version'], '%editor' => $properties['title']));
+      $editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array('%version' => $editors[$editor]['installed version'], '%editor' => $editors[$editor]['title']));
       $editors[$editor]['installed'] = FALSE;
       continue;
     }
@@ -731,7 +732,7 @@ function wysiwyg_get_all_plugins() {
 function wysiwyg_load_includes($type = 'editors', $hook = 'editor', $file = NULL) {
   // Determine implementations.
   $directories = wysiwyg_get_directories($type);
-  $directories['wysiwyg_'] = wysiwyg_get_path($type);
+  $directories['wysiwyg_'] = drupal_get_path('module', 'wysiwyg') . '/' . $type;
   $file_list = array();
   foreach ($directories as $module => $path) {
     $file_list[$module] = drupal_system_listing("$file" . '.inc$', $path, 'name', 0);
@@ -752,21 +753,101 @@ function wysiwyg_load_includes($type = '
 }
 
 /**
- * Helper function to build module/file paths.
+ * Helper function to build paths to libraries.
  *
- * @param $file
- *   A file or directory in a module to return.
+ * @param $library
+ *   The external library name to return the path for.
  * @param $base_path
  *   Whether to prefix the resulting path with base_path().
- * @param $module
- *   The module name to use as prefix.
  *
  * @return
- *   The path to the specified file in a module.
+ *   The path to the specified library.
+ *
+ * @ingroup libraries
+ */
+function wysiwyg_get_path($library, $base_path = FALSE) {
+  static $libraries;
+
+  if (!isset($libraries)) {
+    $libraries = wysiwyg_get_libraries();
+  }
+  if (!isset($libraries[$library])) {
+    // Most often, external libraries can be shared across multiple sites.
+    return 'sites/all/libraries/' . $library;
+  }
+
+  $path = ($base_path ? base_path() : '');
+  $path .= $libraries[$library];
+
+  return $path;
+}
+
+/**
+ * Return an array of library directories.
+ *
+ * Returns an array of library directories from the all-sites directory
+ * (i.e. sites/all/libraries/), the profiles directory, and site-specific
+ * directory (i.e. sites/somesite/libraries/). The returned array will be keyed
+ * by the library name. Site-specific libraries are prioritized over libraries
+ * in the default directories. That is, if a library with the same name appears
+ * in both the site-wide directory and site-specific directory, only the
+ * site-specific version will be listed.
+ *
+ * @return
+ *   A list of library directories.
+ *
+ * @ingroup libraries
  */
-function wysiwyg_get_path($file = '', $base_path = FALSE, $module = 'wysiwyg') {
-  $base_path = ($base_path ? base_path() : '');
-  return $base_path . drupal_get_path('module', $module) . '/' . $file;
+function wysiwyg_get_libraries() {
+  global $profile;
+
+  // When this function is called during Drupal's initial installation process,
+  // the name of the profile that is about to be installed is stored in the
+  // global $profile variable. At all other times, the regular system variable
+  // contains the name of the current profile, and we can call variable_get()
+  // to determine the profile.
+  if (!isset($profile)) {
+    $profile = variable_get('install_profile', 'default');
+  }
+
+  $directory = 'libraries';
+  $searchdir = array();
+  $config = conf_path();
+
+  // The 'profiles' directory contains pristine collections of modules and
+  // themes as organized by a distribution.  It is pristine in the same way
+  // that /modules is pristine for core; users should avoid changing anything
+  // there in favor of sites/all or sites/<domain> directories.
+  if (file_exists("profiles/$profile/$directory")) {
+    $searchdir[] = "profiles/$profile/$directory";
+  }
+
+  // Always search sites/all/*.
+  $searchdir[] = 'sites/all/'. $directory;
+
+  // Also search sites/<domain>/*.
+  if (file_exists("$config/$directory")) {
+    $searchdir[] = "$config/$directory";
+  }
+
+  // Retrieve list of directories.
+  // @todo Core: Allow to scan for directories.
+  $directories = array();
+  $nomask = array('CVS');
+  foreach ($searchdir as $dir) {
+    if (is_dir($dir) && $handle = opendir($dir)) {
+      while (FALSE !== ($file = readdir($handle))) {
+        if (!in_array($file, $nomask) && $file[0] != '.') {
+          if (is_dir("$dir/$file")) {
+            $directories[$file] = "$dir/$file";
+          }
+        }
+      }
+      closedir($handle);
+    }
+  }
+
+  return $directories;
 }
 
 /**
Index: editors/fckeditor.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/fckeditor.inc,v
retrieving revision 1.12
diff -u -p -r1.12 fckeditor.inc
--- editors/fckeditor.inc	21 Mar 2009 23:16:15 -0000	1.12
+++ editors/fckeditor.inc	17 May 2009 21:11:06 -0000
@@ -16,7 +16,6 @@ function wysiwyg_fckeditor_editor() {
     'title' => 'FCKeditor',
     'vendor url' => 'http://www.fckeditor.net',
     'download url' => 'http://www.fckeditor.net/download',
-    'library path' => wysiwyg_get_path('fckeditor'),
     'libraries' => array(
       '' => array(
         'title' => 'Default',
@@ -54,7 +53,7 @@ function wysiwyg_fckeditor_editor() {
  *   The installed editor version.
  */
 function wysiwyg_fckeditor_version($editor) {
-  $library = $editor['library path'] .'/fckeditor.js';
+  $library = $editor['library path'] . '/fckeditor.js';
   $library = fopen($library, 'r');
   $max_lines = 100;
   while ($max_lines && $line = fgets($library, 60)) {
@@ -115,7 +114,7 @@ function wysiwyg_fckeditor_settings($edi
 
   if (!empty($config['buttons'])) {
     // Use our custom toolbar set.
-    $settings['CustomConfigurationsPath'] = wysiwyg_get_path('editors/js/fckeditor.config.js', TRUE);
+    $settings['CustomConfigurationsPath'] = base_path() . drupal_get_path('module', 'wysiwyg') . '/editors/js/fckeditor.config.js';
     $settings['ToolbarSet'] = 'Wysiwyg';
     // Populate our custom toolbar set for fckeditor.config.js.
     $settings['buttons'] = array();
Index: editors/jwysiwyg.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/jwysiwyg.inc,v
retrieving revision 1.2
diff -u -p -r1.2 jwysiwyg.inc
--- editors/jwysiwyg.inc	29 Oct 2008 10:13:15 -0000	1.2
+++ editors/jwysiwyg.inc	17 May 2009 21:07:22 -0000
@@ -11,7 +11,6 @@ function wysiwyg_jwysiwyg_editor() {
     'title' => 'jWYSIWYG',
     'vendor url' => 'http://code.google.com/p/jwysiwyg/',
     'download url' => 'http://code.google.com/p/jwysiwyg/downloads/list',
-    'library path' => wysiwyg_get_path('jwysiwyg'),
     'libraries' => array(
       '' => array(
         'title' => 'Source',
@@ -23,6 +22,7 @@ function wysiwyg_jwysiwyg_editor() {
       ),
     ),
     'version callback' => 'wysiwyg_jwysiwyg_version',
+    // @todo Wrong property; add separate properties for editor requisites.
     'css path' => wysiwyg_get_path('jwysiwyg'),
     'versions' => array(
       '0.5' => array(
@@ -44,7 +44,7 @@ function wysiwyg_jwysiwyg_editor() {
  *   The installed editor version.
  */
 function wysiwyg_jwysiwyg_version($editor) {
-  $script = wysiwyg_get_path('jwysiwyg') . '/jquery.wysiwyg.js';
+  $script = $editor['library path'] . '/jquery.wysiwyg.js';
   $script = fopen($script, 'r');
   fgets($script);
   $line = fgets($script);
Index: editors/markitup.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/markitup.inc,v
retrieving revision 1.2
diff -u -p -r1.2 markitup.inc
--- editors/markitup.inc	6 Mar 2009 02:48:30 -0000	1.2
+++ editors/markitup.inc	17 May 2009 18:18:59 -0000
@@ -16,7 +16,7 @@ function wysiwyg_markitup_editor() {
     'title' => 'markItUp',
     'vendor url' => 'http://markitup.jaysalvat.com',
     'download url' => 'http://markitup.jaysalvat.com/downloads',
-    'library path' => wysiwyg_get_path('markitup/markitup'),
+    'library path' => wysiwyg_get_path('markitup') . '/markitup',
     'libraries' => array(
       '' => array(
         'title' => 'Source',
@@ -51,7 +51,7 @@ function wysiwyg_markitup_editor() {
  *   The installed editor version.
  */
 function wysiwyg_markitup_version($editor) {
-  $changelog = wysiwyg_get_path('markitup/markitup') . '/readme.txt';
+  $changelog = $editor['library path'] . '/readme.txt';
   $changelog = fopen($changelog, 'r');
   $line = fgets($changelog);
   if (preg_match('@([0-9\.]+)@', $line, $version)) {
@@ -81,7 +81,7 @@ function wysiwyg_markitup_settings($edit
   drupal_add_css($editor['library path'] . '/skins/' . $theme . '/style.css', 'theme');
   
   $settings = array(
-    'root' => wysiwyg_get_path('markitup/markitup', TRUE) . '/',
+    'root' => base_path() . $editor['library path'] . '/',
     'nameSpace' => $theme,
     'markupSet' => array(),
   );
Index: editors/nicedit.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/nicedit.inc,v
retrieving revision 1.4
diff -u -p -r1.4 nicedit.inc
--- editors/nicedit.inc	5 Dec 2008 15:35:23 -0000	1.4
+++ editors/nicedit.inc	17 May 2009 18:19:54 -0000
@@ -11,7 +11,6 @@ function wysiwyg_nicedit_editor() {
     'title' => 'NicEdit',
     'vendor url' => 'http://nicedit.com',
     'download url' => 'http://nicedit.com/download.php',
-    'library path' => wysiwyg_get_path('nicedit'),
     'libraries' => array(
       '' => array(
         'title' => 'Source',
@@ -60,7 +59,7 @@ function wysiwyg_nicedit_version($editor
  */
 function wysiwyg_nicedit_settings($editor, $config, $theme) {
   $settings = array(
-    'iconsPath' => wysiwyg_get_path('nicedit', TRUE) . '/nicEditorIcons.gif',
+    'iconsPath' => base_path() . $editor['library path'] . '/nicEditorIcons.gif',
   );
 
   // Add configured buttons or all available.
Index: editors/tinymce.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/tinymce.inc,v
retrieving revision 1.29
diff -u -p -r1.29 tinymce.inc
--- editors/tinymce.inc	20 Mar 2009 23:55:51 -0000	1.29
+++ editors/tinymce.inc	17 May 2009 18:04:29 -0000
@@ -70,10 +70,6 @@ function wysiwyg_tinymce_editor() {
         ),
       ),
     ),
-    // Optional properties
-    // 'editor path' => wysiwyg_get_path('tinymce'), // Assumed by default.
-    // 'js path' => wysiwyg_get_path('editors/js'), // Assumed by default.
-    // 'css path' => wysiwyg_get_path('editors/css'), // Assumed by default.
   );
   return $editor;
 }
Index: editors/whizzywig.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/whizzywig.inc,v
retrieving revision 1.1
diff -u -p -r1.1 whizzywig.inc
--- editors/whizzywig.inc	17 Nov 2008 00:06:33 -0000	1.1
+++ editors/whizzywig.inc	17 May 2009 18:20:11 -0000
@@ -11,7 +11,6 @@ function wysiwyg_whizzywig_editor() {
     'title' => 'Whizzywig',
     'vendor url' => 'http://www.unverse.net',
     'download url' => 'http://www.unverse.net/whizzywig-download.html',
-    'library path' => wysiwyg_get_path('whizzywig'),
     'libraries' => array(
       '' => array(
         'title' => 'Default',
@@ -40,7 +39,7 @@ function wysiwyg_whizzywig_editor() {
  *   The installed editor version.
  */
 function wysiwyg_whizzywig_version($editor) {
-  $script = wysiwyg_get_path('whizzywig') . '/whizzywig.js';
+  $script = $editor['library path'] . '/whizzywig.js';
   $script = fopen($script, 'r');
   $line = fgets($script, 43);
   if (preg_match('@Whizzywig v([0-9]+)@', $line, $version)) {
@@ -67,8 +66,8 @@ function wysiwyg_whizzywig_settings($edi
   $settings = array();
 
   // Add path to button images, if available.
-  if (is_dir(wysiwyg_get_path('whizzywig') . '/btn')) {
-    $settings['buttonPath'] = wysiwyg_get_path('whizzywig', TRUE) . '/btn/';
+  if (is_dir($editor['library path'] . '/btn')) {
+    $settings['buttonPath'] = base_path() . $editor['library path'] . '/btn/';
   }
 
   // Add configured buttons or all available.
Index: plugins/break.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/plugins/break.inc,v
retrieving revision 1.2
diff -u -p -r1.2 break.inc
--- plugins/break.inc	1 Feb 2009 10:06:21 -0000	1.2
+++ plugins/break.inc	17 May 2009 18:05:04 -0000
@@ -17,8 +17,6 @@ function wysiwyg_break_plugin() {
     'icon file' => 'break.gif',
     'icon title' => t('Separate the teaser and body of this content'),
     'settings' => array(
-      // Path is set by default.
-      // 'path' => wysiwyg_get_path('plugins/break', TRUE),
     ),
   );
   return $plugins;
