? .cvsignore
? .project
Index: libraries.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.module,v
retrieving revision 1.16
diff -u -p -r1.16 libraries.module
--- libraries.module 15 Dec 2010 21:09:52 -0000 1.16
+++ libraries.module 1 Jan 2011 23:56:02 -0000
@@ -268,7 +268,7 @@ function libraries_detect_library(&$libr
}
if (!file_exists($library['library path'])) {
$library['error'] = 'not found';
- $library['error message'] = t('%library could not be found.', array(
+ $library['error message'] = t('The %library library could not be found.', array(
'%library' => $library['name'],
));
return;
@@ -498,3 +498,273 @@ function libraries_get_version($library,
}
fclose($file);
}
+
+/**
+ * Implements hook_help().
+ */
+function libraries_help($path, $arg) {
+ switch ($path) {
+ case 'admin/reports/libraries':
+ return t('Click on a library for a status report or, in case the library is not installed, detailed installation instructions.');
+ }
+}
+
+/**
+ * Implements hook_menu().
+ */
+function libraries_menu() {
+ $items = array();
+ $items['admin/reports/libraries'] = array(
+ 'title' => 'Libraries',
+ 'description' => 'An overview of libraries installed on this site.',
+ 'page callback' => 'libraries_admin_overview',
+ 'access arguments' => array('access site reports'),
+ );
+ $items['admin/reports/libraries/%'] = array(
+ 'title' => 'Library status report',
+ 'description' => 'Status overview for a single library',
+ 'page callback' => 'libraries_admin_library_status',
+ 'page arguments' => array(3),
+ 'access arguments' => array('access site reports'),
+ );
+ return $items;
+}
+
+/**
+ * Page callback for the libraries overview table.
+ */
+function libraries_admin_overview() {
+ $libraries = libraries_detect(libraries_info());
+ ksort($libraries);
+ $header = array(t('Name'), t('Status'), t('Version'), t('Variants'));
+ $rows[] = array();
+ foreach ($libraries as $machine_name => $library) {
+ // Link the library name to the library-specific status page.
+ $name = t('@name [Homepage|Download]', array(
+ '@library-status-url' => url("admin/reports/libraries/$machine_name"),
+ '@name' => $library['name'],
+ '@vendor-url' => $library['vendor url'],
+ '@download-url' => $library['download url'],
+ ));
+ $rows[] = array(
+ 'data' => array(
+ $name,
+ ($library['installed'] ? t('OK') : drupal_ucfirst($library['error'])),
+ (isset($library['version']) ? $library['version'] : ''),
+ (!empty($library['variants']) ? implode(', ', array_keys($library['variants'])) : ''),
+ ),
+ 'class' => ($library['installed'] ? array('ok') : array('error')),
+ );
+ }
+ return theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'empty' => t('There are currently no libraries installed'),
+ ));
+}
+
+/**
+ * Page callback for the status overview for a single library.
+ */
+function libraries_admin_library_status($name) {
+ $library = libraries_info($name);
+ if (!$library) {
+ return libraries_admin_overview();
+ }
+ libraries_detect_library($library);
+ drupal_set_title(t('Status report for library %library', array('%library' => $library['name'])), PASS_THROUGH);
+ $output = '';
+ if ($library['installed']) {
+ drupal_set_message(t('The %name library is installed correctly.', array('%name' => $library['name'])));
+ $header = array(array('data' => '' . t('General information') . '', 'colspan' => 2, 'class' => 'table-heading', 'no_striping' => TRUE));
+ $rows = array();
+ $rows[] = array('' . t('Name (machine name)') . '', t('@name (@machine_name)', array('@name' => $library['name'], '@machine_name' => $library['machine name'])));
+ $rows[] = array('' . t('Vendor URL') . '', l($library['vendor url'], $library['vendor url']));
+ $rows[] = array('' . t('Download URL') . '', l($library['download url'], $library['download url']));
+ $rows[] = array('' . t('Location') . '', $library['library path']);
+ $rows[] = array('' . t('Version') . '', $library['version']);
+
+ $output = theme('table', array('header' => $header, 'rows' => $rows));
+ }
+ else {
+ drupal_set_message($library['error message'], 'error');
+ switch ($library['error']) {
+ case 'not found':
+ $output .= t('Follow the following steps to install the library:');
+ $items = array();
+ // 1. Download the library.
+ // If no supported versions are specified, the latest version is
+ // recommended.
+ if (empty($library['versions'])) {
+ $items[] = t('Download the latest version of the library here.', array(
+ '@download-url' => $library['download url'],
+ ));
+ }
+ // Otherwise, the latest supported version is recommended.
+ else {
+ $versions = array_keys($library['versions']);
+ usort($versions, 'version_compare');
+ $versions = array_reverse($versions);
+ $version = $versions[0];
+ $items[] = t('Download version %version of the library here.', array(
+ '%version' => $version,
+ '@download-url' => $library['download url'],
+ ));
+ }
+ // 2. Unpack it.
+ $items[] = t('If the library is an archive, i.e. if the file ending is for example .tar.gz or .zip, unpack it.');
+ // 3. Create the libraries folder.
+ $items[] = t('In the %library-directory directory of your Drupal installation create a %library directory.', array(
+ '%library-directory' => 'sites/all/libraries',
+ '%library' => $library['machine name'],
+ ));
+ // 4. Upload it.
+ // If the library has variant-independent files, give the user the
+ // location of an example file to check his filesystem against.
+ if (empty($library['files'])) {
+ $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created %library-path directory.', array(
+ '%library-path' => 'sites/all/libraries/' . $library['machine name'],
+ ));
+ }
+ else {
+ foreach (array('js', 'css', 'php') as $type) {
+ if (!empty($library['files'][$type])) {
+ $files = array_keys($library['files'][$type]);
+ $filepath = $files[0];
+ $parts = array_reverse(explode('/', $filepath));
+ $file = $parts[0];
+ $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath);
+ $filepath = 'sites/all/libraries/' . $library['machine name'] . '/' . $filepath;
+ }
+ }
+ $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created directory (%library-path). For example, the %file file, should be located at following filepath: %filepath', array(
+ '%library-path' => 'sites/all/libraries/' . $library['machine name'],
+ '%file' => $file,
+ '%filepath' => $filepath,
+ ));
+ }
+ // 5. Reload.
+ $items[] = t('Reload the page. If successful, you should see status information about this library.');
+
+ $output .= theme('item_list', array(
+ 'items' => $items,
+ 'type' => 'ol'
+ ));
+ break;
+
+ case 'not detected':
+ // Re-check location.
+ // If the library has variant-independent files, give the user the
+ // location of an example file to check his filesystem against.
+ if (empty($library['files'])) {
+ $output .= t('Check that the whole library is located at %library-path.', array(
+ '%library-path' => $library['library path'],
+ )) . '
';
+ }
+ else {
+ foreach (array('js', 'css', 'php') as $type) {
+ if (!empty($library['files'][$type])) {
+ $files = array_keys($library['files'][$type]);
+ $filepath = $files[0];
+ $parts = array_reverse(explode('/', $filepath));
+ $file = $parts[0];
+ $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath);
+ $filepath = 'sites/all/libraries/' . $library['machine name'] . '/' . $filepath;
+ }
+ }
+ $output .= t('Check that the whole library is located at %library-path. For example, the %file file, should be located at following filepath: %filepath', array(
+ '%library-path' => $library['library path'],
+ '%file' => $file,
+ '%filepath' => $filepath,
+ )) . '
';
+ }
+ // If the library information was provided by a module, contact the maintainer.
+ if (!empty($library['module'])) {
+ $output .= t('If yes, the library information is corrupted. Contact the maintainer of the %module module with the following information:', array(
+ '%module' => $library['module'],
+ )) . '
';
+ }
+ // Otherwise contact the author of the info file.
+ elseif (!empty($library['info file'])) {
+ $output .= t("If yes, the library's info file (%info-file) is corrupted. Contact the author of this file with the following information:", array(
+ '%info-file' => $library['info file'],
+ )) . '
';
+ }
+ $output .= '
' . t('The version detection of the @name library failed. Library information:
@information', array( + '@name' => $library['machine name'], + '@information' => '' . var_export($library, TRUE) . '
', + )) . ''; + break; + + case 'not supported': + // Either download a different version of the library... + $versions = array_keys($library['versions']); + usort($versions, 'version_compare'); + $versions = array_reverse($versions); + $version = $versions[0]; + $output .= t('Please install version %version of the library by following the following steps:', array( + '%version' => $version, + )); + // 1. Delete the old library. + $items[] = t('Delete the entire contents of the %library-path directory.', array( + '%library-path' => $library['library path'], + )); + // 2. Download the new library. + $items[] = t('Download version %version of the library here.', array( + '%version' => $version, + '@download-url' => $library['download url'], + )); + // 3. Unpack it. + $items[] = t('If the library is an archive, i.e. if the file ending is for example .tar.gz or .zip, unpack it.'); + // 4. Upload the new library. + // If the library has variant-independent files, give the user the + // location of an example file to check his filesystem against. + if (empty($library['files'])) { + $items[] = t('Upload the new files into the %library-path directory.', array( + '%library-path' => $library['library path'], + )); + } + else { + foreach (array('js', 'css', 'php') as $type) { + if (!empty($library['files'][$type])) { + $files = array_keys($library['files'][$type]); + $filepath = $files[0]; + $parts = array_reverse(explode('/', $filepath)); + $file = $parts[0]; + $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath); + $filepath = $library['library path'] . '/' . $filepath; + } + } + $items[] = t('Upload the new files into the %library-path directory. For example, the %file file, should be located at following filepath: %filepath', array( + '%library-path' => $library['library path'], + '%file' => $file, + '%filepath' => $filepath, + )); + } + // 5. Reload. + $items[] = t('Reload the page. If successful, you should see status information about this library.'); + $output .= theme('item_list', array( + 'items' => $items, + 'type' => 'ol' + )); + // ...or contact the maintainer of the library information. + // If the library information was provided by a module, contact the maintainer. + if (!empty($library['module'])) { + $output .= t('If you are bound to the current version of the library, ask the maintainer of the %module module to provide support for version %version.', array( + '%module' => $library['module'], + '%version' => $library['version'], + )) . '
'; + } + // Otherwise contact the author of the info file. + elseif (!empty($library['info file'])) { + $output .= t("If you are bound to the current version of the library, ask the author of this library's info file (%info-file) to provide support for version %version", array( + '%info-file' => $library['info file'], + '%version' => $library['version'], + )) . '
'; + } + break; + } + } + return $output; +} + Index: tests/libraries_test.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries_test.module,v retrieving revision 1.7 diff -u -p -r1.7 libraries_test.module --- tests/libraries_test.module 3 Nov 2010 22:22:42 -0000 1.7 +++ tests/libraries_test.module 1 Jan 2011 23:56:02 -0000 @@ -57,7 +57,7 @@ function libraries_test_libraries_info() // Test a multiple-parameter version callback. $libraries['example_multiple_parameter_version_callback'] = array( - 'name' => 'Example_multiple_parameter_version_callback', + 'name' => 'Example multiple parameter version callback', 'library path' => drupal_get_path('module', 'libraries') . '/tests/example', // Version 2 'version callback' => '_libraries_test_get_version',