Index: libraries.api.php
===================================================================
RCS file: libraries.api.php
diff -N libraries.api.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libraries.api.php	24 Mar 2010 18:26:05 -0000
@@ -0,0 +1,75 @@
+<?php
+/*
+ * @file
+ * Documents API functions for Libraries module.
+
+/*
+ * Declare information about required external libraries
+ *
+ * @return
+ *   An associative array containing library information. The key is the name of the
+ *   library, which  must be the name of the directory the library should be
+ *   contained in within a 'libraries' directory. The values are themselves
+ *   associative arrays containing following key-value pairs:
+ *     'title' => The human-readable name of the block.
+ *     'vendor url' => The homepage of the library.
+ *     'download url' => The website where the current version of the library can be obtained.
+ *     'path' => (optional) Path inside the library's directory to the actual library.
+ *     'version_callback' => (optional) A function that returns the full version string of the library.
+ *       Defaults to 'libraries_get_version', a helper function which takes two arguments:
+ *         $file The file to use for the version check.
+ *         $line_number The line number in the specified file which contains the version information.
+ *     'version_arguments' => Arguments to pass to the version callback. Can usually
+ *       be omitted when using a custom version callback.
+ *     'files' => An array of files to include. Keys of the array are 'css', 'js' and 'php', each again
+ *       an array containing a list of files of the specific type.
+ *     'variants' => (optional) An array of different library variants. A typical example is a minified
+ *       version of the library and a source code version. The variants array is keyed by the names of
+ *       the variants. The values are in turn arrays which contain a replica of the top-level array
+ *       containing variant-specific information they need to override. A typical value is 'files'.
+ *     'versions' => (optional) An array of different library versions contained in the library. Depending
+ *       on the existing version, some libraries require different files to be loaded. The versions array
+ *       is keyed by the version strings or numbers that need to be differentiated. The values are in turn
+ *       arrays which contain a replica of the top-level array containing version-specific information they
+ *       need to override. A typical value is 'files'.
+ *     'integration files' => (optional) Module files to load along with the library. File names should be
+ *       declared relative to the module directory.
+ *     Additional top-level properties can be implemented as needed.
+ */
+function hook_libraries_info() {
+  $libraries['ex_lib'] = array( // This makes Libraries API search e.g. the 'sites/all/libraries/ex_lib' directory.
+    'title' => 'Example library',
+    'vendor url' => 'http://example.com',
+    'download url' => 'http://example.com/download',
+    'path' => 'exlib/files',
+    'version arguments' => array('../docs/CHANGELOG.txt', '5'),
+    'files' => array(
+      'css' => array('lib_style.css', 'example_1.css', 'example_2.css'),
+      'js' => array('exlib.js', 'js_gadget_1.js'),
+      'php' => array('exlib.php', 'exlib.inc'),
+    ),
+    'variants' => array(
+      'minified' => array(
+        'files' => array(
+          'css' => array('exlib_min.css'),
+          'js' => array('exlib_min.js'),
+        ),
+      ),
+    ),
+    'versions' => array(
+      '2' => array(
+        'files' => array(
+          'php' => array('api_old.php'),
+        ),
+      ),
+      '3' => array(
+        'files' => array(
+          'php' => array('api_new.php'),
+        ),
+      ),
+    ),
+    'integration files' => array('ex_lib.inc'),
+  );
+
+  return $libraries;
+}
Index: libraries.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.module,v
retrieving revision 1.2
diff -u -p -r1.2 libraries.module
--- libraries.module	4 Jun 2009 00:01:55 -0000	1.2
+++ libraries.module	24 Mar 2010 18:26:05 -0000
@@ -107,3 +107,77 @@ function libraries_get_libraries() {
   return $directories;
 }
 
+/*
+ * Gather library information from modules
+ */
+function libraries_get_info() {
+
+  static $libraries;
+
+  if (isset($libraries)) {
+    return $libraries;
+  }
+
+  $modules = module_implements('libraries_info');
+  $libraries = array();
+
+  foreach ($modules as $module) {
+    $module_libraries = module_invoke($module, 'libraries_info');
+
+    foreach ($module_libraries as $library => $properties) {
+      $libraries[$library] = $properties;
+
+      // Fill in required and default properties.
+      $libraries[$library] += array(
+        'title' => '',
+        'vendor url' => '',
+        'download url' => '',
+        'path' => '',
+        'version callback' => 'libraries_get_version',
+        'version arguments' => NULL,
+        'variants' => NULL,
+        'versions' => NULL,
+        'integration files' => NULL,
+      );
+
+      // Check whether library is present.
+      if (!($libraries[$library]['installed'] = file_exists(libraries_get_path($library, $library['path'])))) {
+        continue;
+      }
+
+      // Detect library version.
+      $arguments = '';
+      if ($libraries[$library]['version arguments']) {
+        $arguments = implode(', ', $libraries[$library]['version arguments']);
+      }
+      $libraries[$library]['installed version'] = $libraries[$library]['version callback']($arguments);
+      if (empty($libraries[$library]['installed version'])) {
+        $libraries[$library]['error'] = t('The version of %library could not be detected.', array('%library' => $properties['title']));
+        $libraries[$library]['installed'] = FALSE;
+        continue;
+      }
+
+      // Determine to which supported version the installed version maps.
+      if (ksort($libraries[$library]['versions'])) {
+        $version = 0;
+        foreach ($libraries[$library]['versions'] as $supported_version => $version_properties) {
+          if (version_compare($libraries[$library]['installed version'], $supported_version, '>=')) {
+            $version = $supported_version;
+          }
+        }
+        if (!$version) {
+        $libraries[$library]['error'] = t('The installed version %version of %library is not supported.', array('%version' => $libraries[$library]['installed version'], '%library' => $libraries[$library]['title']));
+        $libraries[$library]['installed'] = FALSE;
+        continue;
+        }
+
+        // Apply version specific definitions and overrides.
+        $libraries[$library] = array_merge($libraries[$library], $libraries[$library]['versions'][$version]);
+        unset($libraries[$library]['versions']);
+      }
+    }
+  }
+
+  return $libraries;
+
+}
