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	3 Apr 2010 13:16:34 -0000
@@ -0,0 +1,95 @@
+<?php
+/*
+ * @file
+ * Documents API functions for Libraries module.
+ */
+
+/*
+ * Declares 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. Upon detection of the library the path is used to fill a
+ *     'library path' key containing the actual path to the library from the
+ *     Drupal root directory.
+ *   - 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: An associated array of arguments to pass to the
+ *     version callback keyed by the names of the arguments. 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'. Note that for this example all variant-independent files must be
+ *     redeclared in each variant because the base value is overwritten.
+ *   - 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'. Note that for this example all variant-independent files must be
+ *     redeclared in each variant because the base value is overwritten.
+ *   - integration files: (optional) An array of module files to load along with
+ *     the library keyed by the module name, where each value is in turn an
+ *     array of file names. File names should be declared relative to the
+ *     module's directory.
+ *   Additional top-level properties can be implemented as needed.
+ */
+function hook_libraries_info() {
+  // This makes Libraries API search e.g. the 'sites/all/libraries/ex_lib' directory.
+  $libraries['ex_lib'] = array(
+    '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(
+      'example_library_integration_module' => array('ex_lib.inc'),
+    ),
+  );
+
+  return $libraries;
+}
Index: libraries.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.module,v
retrieving revision 1.3
diff -u -p -r1.3 libraries.module
--- libraries.module	2 Apr 2010 15:38:38 -0000	1.3
+++ libraries.module	3 Apr 2010 13:16:35 -0000
@@ -112,3 +112,95 @@ function libraries_get_libraries() {
   return $directories;
 }
 
+/*
+ * Gather library information from modules
+ */
+function libraries_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,
+      );
+
+    }
+
+  }
+
+}
+
+/*
+ * Detect libraries and their versions
+ *
+ * @param $libraries
+ *   An array of libraries to detect as from libraries_info.
+ *
+ * @see libraries_info()
+ */
+libraries_detect(&$libraries) {
+
+  foreach ($libraries as $library => $properties) {
+
+    // Check whether library is present.
+    $libraries[$library]['library path'] = libraries_get_path($library, $library['path']);
+    if (!($libraries[$library]['installed'] = file_exists($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']);
+    }
+
+  }
+
+}
+
