Show all modules used on a drupal site

From Web3us, LLC
Jump to: navigation, search

This is the php snippet, copy and past into your body on Drupal 5 sites, make sure to select input format of "php code" to see the results.

Note that the last part of this reports the database size only on Drupal 5 and does not work on Drupal 6.

<?php
  // CONFIGURATION
  // Use the following variables to customize how the colophon is displayed:
  $show_modules_list = TRUE; // Set to TRUE to show the list of modules (Default is TRUE)
  $show_themes_list = TRUE;  // Set to TRUE to show the list of themes (Default is TRUE)

  // CONTENT
  echo 'The ' . variable_get(site_name, '') . ' Website is proudly
  powered by Drupal ' . VERSION . '. Drupal can be extended
  using many different themes and modules. Below are all of the
  modules and themes enabled on this site:<br />';

  // Modules
  if ($show_modules_list) {
    $modules = module_list(FALSE, FALSE, TRUE);
    echo '<h3 style="text-align: center;">Modules:</h3>';
    echo '<table><thead><th>Name</th><th>Version</th><th>Description</th><th>URL</th></thead><tbody>';
    foreach ($modules as $item) {
      if (module_exists($item)) { // Only list the module if it's enabled
        $module_loc = drupal_get_filename('module', $item); // The location of the Module
        $info = parse_ini_file(dirname($module_loc) . '/' . $item . '.info'); // Location of the info file
        $name = $info['name'];
        $description = $info['description'];
        $version = $info['version'];
        $project = $info['project'];
        $package = $info['package'];

        echo '<tr><td>' . $name;
        if ($package) {
          echo '<br /><small>(Part of ' . $package . ')';
        }
        echo '</td><td>' . $version . '</td><td>' . $description . '</td><td><a href="http://drupal.org/project/' . $project . '">http://drupal.org/project/' . $project . '</a></td></tr>';
      }
    }
    echo '</table>';
  }

  // Themes
  if ($show_themes_list) {
    $themes = list_themes();
    echo '<h3 style="text-align: center">Themes:</h3>';
    echo '<table><thead><th>Screenshot</th><th>Name</th></thead>';
    foreach ($themes as $item) {
      // Only lists the theme if the theme is enabled
      $list = get_object_vars($item); // Drupal's list_themes() function returns an array of objects, so we extract an array from each of the objects
      if ($list['status']) {  // Only list the theme if it is enabled
        $name = $list['name'];
        if (file_exists(dirname($list['filename']) . '/screenshot-drupal.org.png')) { // List the screenshot intended for drupal.or, if available
          $screenshot = dirname($list['filename']) . '/screenshot-drupal.org.png';
        } else {
          $screenshot = dirname($list['filename']) . '/screenshot.png';
        }
        echo '<td><img src="' . $screenshot . '" alt="' . $name . ' screenshot" /></td><td>' . $name . '</td></tr>';
      }
    }
    echo '</table>';
  }
?>
<br />
// ********************************************************
// Note: this database size report does NOT work on Drupal 6
<?php 
 echo '<h3 style="text-align: center;">Database Size:</h3>';
function db_size_info($dbsize) {
$bytes = array('KB', 'KB', 'MB', 'GB', 'TB'); 
if ($dbsize < 1024) $dbsize = 1;             
for ($i = 0; $dbsize > 1024; $i++) $dbsize /= 1024;
$db_size_info['size'] = ceil($dbsize);
$db_size_info['type'] = $bytes[$i];
return $db_size_info;
}

// Database size = table size + index size:

$rows = db_query("SHOW TABLE STATUS");
$dbssize = 0;
while ($row = mysql_fetch_array($rows)) {
$dbssize += $row['Data_length'] + $row['Index_length'];

More on Drupal in this wiki.