List all enabled modules for a 'colophon' or 'about' page

I use this PHP snippet to display a list of all enabled modules on my site. Most of this code comes directly from system.module.

Because I keep all contributed modules in a subdirectory of the modules directory, i.e. /modules/contrib, I use a PHP string function to determine whether the module is core or contributed. See the commented code below.

<?php
// LIST ALL ENABLED MODULES

// Get current list of modules
$files = system_listing('\.module$', 'modules', 'name', 0);

// Extract current files from database.
system_get_files_database($files, 'module');

ksort($files);

foreach (
$files as $filename => $file) {

 
// only list the enabled modules
 
if ($file->status) {

 
drupal_get_filename('module', $file->name, $file->filename);
 
drupal_load('module', $file->name);

 
$file->description = module_invoke($file->name, 'help', 'admin/modules#description');

 
$form['name'][$file->name] = array('#value' => $file->name);
 
$form['description'][$file->name] = array('#value' => $file->description);

 
// I keep all my contrib modules in /modules/contrib/
  // use strpos to examine the filename, which tells the path to the file
  // if 'contrib' is not in the filename, we assume it is a core module
 
if(!strpos($file->filename, 'contrib')) {
   
$form['core'][$file->name] = array('#value' => 'core');
    } else {
   
$form['core'][$file->name] = array('#value' => 'contrib');
    }
  }
}

foreach (
element_children($form['name']) as $key) {
 
$row = array();
 
$row[] = form_render($form['name'][$key]);
 
$row[] = form_render($form['description'][$key]);
 
$row[] = form_render($form['core'][$key]);
 
$rows[] = $row;
}

$output = "<h3>Enabled Drupal modules</h3>";
$header = array(t('Name'), t('Description'), t('Core or Contrib'));
$output .= theme('table', $header, $rows);
$output .= form_render($form);
print
$output;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.