Index: enabled_modules.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/enabled_modules/enabled_modules.module,v retrieving revision 1.1 diff -u -r1.1 enabled_modules.module --- enabled_modules.module 9 Apr 2008 17:18:43 -0000 1.1 +++ enabled_modules.module 2 Apr 2009 23:35:12 -0000 @@ -1,210 +1,362 @@ - 'enabled_modules', - 'title' => t('Enabled modules'), - 'access' => user_access('view enabled modules'), - 'callback' => 'enabled_modules_list', - 'type' => MENU_NORMAL_ITEM, - ); - // OPTIONAL: Fill in additional static menu items - } - // OPTIONAL: Put in else statement for dynamic menu items that can't be cached. - - return $items; -} - - -/** - * Implementation of hook_watchdog(). - */ -function enabled_modules_watchdog($log_msg) { - -} - - -// Helper functions - -/** - * - */ -function enabled_modules_list() { - $modules = enabled_modules_fetch_enabled(); - return theme('enabled_modules_list', $modules); -} - -/** - * List all enabled modules. - * - * @return - * An array of system table objects of type module and status 1. - */ -function enabled_modules_fetch_enabled() { - static $modules = array(); - if (!isset($modules) || empty($modules)) { - // @TODO maybe implement our own cache, flushed each time module page saved - $result = db_query("SELECT filename, name, description, throttle, bootstrap, schema_version FROM {system} WHERE type = 'module' AND status = '1' ORDER BY name"); - while ($module = db_fetch_object($result)) { - if (file_exists($module->filename)) { - $module->exists = 'present'; - $module->tasks = enabled_modules_module_admin_tasks($module->name); - } - else { - $module->exists = 'missing'; - $module->tasks = ''; - } - $modules[] = $module; - } - } - return $modules; -} - -/** - * adapted from http://api.drupal.org/api/function/system_admin_by_module/5 - */ -function enabled_modules_module_admin_tasks($module) { - $admin_tasks = system_get_module_admin_tasks($module); - - // Check for help links. - if (module_invoke($module, 'help', "admin/help#$module")) { - $admin_tasks[100] = l(t('Get help'), "admin/help/$module"); - } - - // Only display a section if there are any available tasks. - if (count($admin_tasks)) { - // Sort. - ksort($admin_tasks); - return $admin_tasks; - } - else { - return array(); - } -} - - -function theme_enabled_modules_module_admin_tasks($admin_tasks = array()) { - // Output links - if (count($admin_tasks)) { - return theme('item_list', $admin_tasks); - } - else { - return theme('item_list', array(t('No tasks'))); - } -} - - -function theme_enabled_modules_list($modules) { - $output = ''; -// @TODO - for table sorting to work, the table must be built directly with SQL -// it will not sort data in an array. We may need our own table anyway, so -// we can track when modules are enabled and disabled, so could redo that way. - $header = array( - array( - 'data' => t('Name'), - - ), - array( - 'data' => t('Description'), - ), - array( - 'data' => t('Installed'), - ), - ); - if (user_access('administer site configuration')) { - $header[] = array('data' => t('Administer')); - } - - $rows = array(); - foreach ($modules as $module) { - $row = array(); - $row[] = array( - 'class' => 'enabled-module-name', - 'data' => $module->name, - ); - $row[] = array( - 'class' => 'enabled-module-description', - 'data' => $module->description, - ); - $row[] = array( - 'class' => 'enabled-module-installed', - 'data' => $module->exists, - ); - if (user_access('administer site configuration')) { - $row[] = array( - 'class' => 'enabled-module-administer', - 'data' => theme('enabled_modules_module_admin_tasks', $module->tasks), - ); - } - $rows[] = $row; - } - - $output .= theme('table', $header, $rows, array('class' => 'enabled-modules-list')); - - return $output; + 'checkboxes', + '#title' => t('Select modules to list in the block'), + '#options' => enabled_modules_fetch_names($status = 1, $reset = TRUE), + '#description' => t('Selected modules will be listed in the block.'), + '#default_value' => variable_get('enabled_modules_demo_list', ''), + ); + return $form; + + break; + } + } + else if ($op == 'save') { + switch ($delta) { + case 'demo': + variable_set('enabled_modules_demo_list', $edit['enabled_modules_demo_list']); + break; + } + } + else if ($op == 'view') { + switch ($delta) { + case 'recently_enabled': + $block['subject'] = t('Recently enabled modules'); + $block['content'] = t('TODO: Enter block content'); + break; + case 'recently_disabled': + $block['subject'] = t('Recently disabled modules'); + $block['content'] = t('TODO: Enter block content'); + break; + case 'demo': + $block['subject'] = t('Key Site Modules'); + $block['content'] = enabled_modules_block_list($status = 1); + drupal_add_js('misc/collapse.js'); + break; + } + return $block; + } +} + +/** + * Implementation of hook_help(). + */ +function enabled_modules_help($path, $arg) { + switch ($path) { + case 'admin/help#enabled_modules': + return t('Provides a page showing all enabled modules, including modules missing from the file system, and blocks showing recently enabled and recently disabled modules.'); + case 'admin/modules#description': + return t('Show enabled, missing, and recently toggled modules.'); + case 'admin/reports/enabled_modules': + case 'admin/reports/enabled_modules/list': + $help = '
'. t('All enabled modules are listed here. if a module\'s codebase is not found, the module is marked missing. The system\'s stored path to each module is available as a tooltip on placing the mouse cursor over the module name. Your overall Drupal site is presently installed in this directory:') .' '. getcwd() .'
'. t('For more information about enabled, installed modules and available modules see the Status report and the Modules page.', array('@status_report' => url('admin/reports/status'), '@modules_page' => url('admin/build/modules'))) .'
'; + } + return $help; + case 'admin/reports/enabled_modules/disabled': + $help = ''. t('Formerly enabled and now disabled modules are listed here. If a codebase is no longer found the modules is marked missing. Modules which have been properly uninstalled are not listed. The system\'s stored path to each module is available as a tooltip on placing the mouse cursor over the module name. Your overall Drupal site is presently installed in this directory:') .' '. getcwd() .'
'. t('For more information about enabled, installed modules and available modules see the Status report and the Modules page.', array('@status_report' => url('admin/reports/status'), '@modules_page' => url('admin/build/modules'))) .'
'; + } + return $help; + } + } + +/** + * Implementation of hook_perm(). + */ +function enabled_modules_perm() { + return array('view enabled modules'); +} + + +/** + * Implementation of hook_menu(). + */ +function enabled_modules_menu() { + $items = array(); + + $items['admin/reports/enabled_modules'] = array( + 'title' => t('Enabled modules'), + 'description' => t('See all modules marked as enabled, even if their code is no longer present, and see where Drupal is looking for the module on the file system.'), + 'page callback' => 'enabled_modules_list', + 'weight' => 10, + 'access arguments' => array('view enabled modules'), + ); + $items['admin/reports/enabled_modules/list'] = array( + 'title' => t('Currently enabled'), + 'page_callback' => 'enabled_modules_list', + 'access arguments' => array('view enabled modules'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + $items['admin/reports/enabled_modules/disabled'] = array( + 'title' => t('Formerly enabled'), + 'page callback' => 'enabled_modules_list', + 'page arguments' => array(0), + 'access arguments' => array('view enabled modules'), + 'type' => MENU_LOCAL_TASK, + ); + return $items; +} + + +/** + * Implementation of hook_theme(). + */ +function enabled_modules_theme() { + return array( + 'enabled_modules_list' => array( + 'arguments' => array('modules' => NULL), + ), + 'enabled_modules_block_list' => array( + 'arguments' => array('modules' => NULL), + ), + 'enabled_modules_module_admin_tasks' => array( + 'arguments' => array('arg' => NULL), + ), + ); +} + +/** + * Implementation of hook_watchdog(). + */ +function enabled_modules_watchdog($log_msg) { + +} + + +// Helper functions + +/** + * + */ +function enabled_modules_list($status = 1) { + $modules = enabled_modules_fetch_enabled($status); + $output .= theme('enabled_modules_list', $modules, $status); + return $output; +} + +/** + * + */ +function enabled_modules_block_list($status = 1) { + $module_list = variable_get('enabled_modules_demo_list', 0); + $modules = enabled_modules_fetch_demo($status); + $output .= theme('enabled_modules_block_list', $modules, $status); + return $output; +} + +/** + * List all enabled modules. + * + * @return + * An array of system table objects of type module and status 1. + */ +function enabled_modules_fetch_enabled($status = 1, $reset = TRUE) { + static $modules = array(); + if ($reset || !isset($modules) || empty($modules)) { + $result = db_query("SELECT filename, name, info, throttle, bootstrap, schema_version FROM {system} WHERE type = 'module' AND status = %d ORDER BY name", $status); + while ($module = db_fetch_object($result)) { + $module->info = unserialize($module->info); + if (file_exists($module->filename)) { + $module->exists = 'present'; + $module->tasks = enabled_modules_module_admin_tasks($module->name); + } + else { + $module->exists = 'missing'; + $module->tasks = ''; + } + $modules[] = $module; + } + } + return $modules; +} + +function enabled_modules_fetch_demo($status = 1, $reset = TRUE) { + static $modules = array(); + if ($reset || !isset($modules) || empty($modules)) { + $module_list = array_values(variable_get('enabled_modules_demo_list', 0)); + $result = db_query("SELECT filename, name, info, throttle, bootstrap, schema_version FROM {system} WHERE type = 'module' AND status = %d ORDER BY name", $status); + while ($module = db_fetch_object($result)) { + if (in_array($module->name, $module_list, TRUE)) { + $module->info = unserialize($module->info); + $modules[] = $module; + } + } + } + return $modules; +} + + +function enabled_modules_fetch_names($status = 1, $reset = TRUE) { + $module_names = array(); + if ($reset || !isset($modules) || empty($modules)) { + $result = db_query("SELECT filename, name, info, throttle, bootstrap, schema_version FROM {system} WHERE type = 'module' AND status = %d ORDER BY name", $status); + while ($module = db_fetch_object($result)) { + $module_names[$module->name] = $module->name; + } + } + return $module_names; +} + +/** + * adapted from http://api.drupal.org/api/function/system_admin_by_module/5 + */ +function enabled_modules_module_admin_tasks($module) { + $admin_tasks = system_get_module_admin_tasks($module); + + // Check for help links. + if (module_invoke($module, 'help', "admin/help#$module", array())) { + $admin_tasks[100] = l(t('Get help'), "admin/help/$module"); + } + + // Only display a section if there are any available tasks. + if (count($admin_tasks)) { + // Sort. + ksort($admin_tasks); + return $admin_tasks; + } + else { + return array(); + } +} + + +function theme_enabled_modules_module_admin_tasks($admin_tasks = array()) { + // Output links + if (count($admin_tasks)) { + return theme('item_list', $admin_tasks); + } + else { + return theme('item_list', array(t('No tasks'))); + } +} + + +function theme_enabled_modules_list($modules, $status = 1) { + $output = ''; + // @TODO - for table sorting to work, the table must be built directly with SQL + // it will not sort data in an array. We may need our own table anyway, so + // we can track when modules are enabled and disabled, so could redo that way. + $header = array( + array( + 'data' => t('Name'), + + ), + array( + 'data' => t('Description'), + ), + array( + 'data' => t('Code'), + ), + ); + if (user_access('administer site configuration') && $status == 1) { + $header[] = array('data' => t('Administer')); + } + + $rows = array(); + foreach ($modules as $module) { + $row = array(); + $row[] = array( + 'class' => 'enabled-module-name', + 'data' => $module->name, + 'title' => $module->filename, + ); + $row[] = array( + 'class' => 'enabled-module-description', + 'data' => $module->info['description'], + ); + $row[] = array( + 'class' => 'enabled-module-installed', + 'data' => $module->exists, + ); + if (user_access('administer site configuration') && $status == 1) { + $row[] = array( + 'class' => 'enabled-module-administer', + 'data' => theme('enabled_modules_module_admin_tasks', $module->tasks), + ); + } + $rows[] = $row; + } + + if ($status == 1) { + // Enabled modules + $attributes = array('class' => 'enabled-modules-list'); + $caption = t('Currently enabled modules'); + } + else { + // Disabled module + $attributes = array('class' => 'disabled-modules-list'); + $caption = t('Disabled formerly enabled modules'); + } + + $output .= theme('table', $header, $rows, $attributes, $caption); + + return $output; +} + +function theme_enabled_modules_block_list($modules, $status = 1) { + $output = ''; + // @TODO - for table sorting to work, the table must be built directly with SQL + // it will not sort data in an array. We may need our own table anyway, so + // we can track when modules are enabled and disabled, so could redo that way. + + foreach ($modules as $module) { + $output .= ''; + } + return $output; +} + +function enabled_modules_array_link($array) { + foreach($array as $key => $link){ + $output .= l($link, 'http://drupal.org/project/'. $link, $options = array('html => TRUE')); + $output .= '